Author: pepeto
Date: Mon Aug 25 17:52:33 2014
New Revision: 26037

URL: http://svn.gna.org/viewcvs/freeciv?rev=26037&view=rev
Log:
Build internationalized and-list strings in miscellaneous locations.

See gna patch #5045

Modified:
    trunk/client/helpdata.c
    trunk/client/text.c
    trunk/common/effects.c
    trunk/common/effects.h
    trunk/server/techtools.c

Modified: trunk/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/helpdata.c?rev=26037&r1=26036&r2=26037&view=diff
==============================================================================
--- trunk/client/helpdata.c     (original)
+++ trunk/client/helpdata.c     Mon Aug 25 17:52:33 2014
@@ -2403,6 +2403,12 @@
 static void insert_allows(struct universal *psource,
                          char *buf, size_t bufsz)
 {
+  struct strvec *coreqs = strvec_new();
+  struct strvec *conoreqs = strvec_new();
+  struct astring coreqstr = ASTRING_INIT;
+  struct astring conoreqstr = ASTRING_INIT;
+  char buf2[bufsz];
+
   buf[0] = '\0';
 
   /* FIXME: show other data like range and survives. */
@@ -2413,40 +2419,32 @@
         if (req->present) {
           /* This source enables a building, but other sources may
            * also be required (or required to be absent). */
-          char coreq_buf[512] = "", conoreq_buf[512] = "";
+          strvec_clear(coreqs);
+          strvec_clear(conoreqs);
 
           requirement_vector_iterate(&pimprove->reqs, coreq) {
             if (!are_universals_equal(psource, &coreq->source)) {
-              char buf2[512] = "";
-              char *rbuf = coreq->present ? coreq_buf : conoreq_buf;
-
-              universal_name_translation(&coreq->source,
-                                         buf2, sizeof(buf2));
-              fc_assert_action(sizeof(coreq_buf) == sizeof(conoreq_buf), 
break);
-              if (rbuf[0] == '\0') {
-                fc_strlcpy(rbuf, buf2, sizeof(coreq_buf));
-              } else {
-                cat_snprintf(rbuf, sizeof(coreq_buf),
-                             Q_("?clistmore:, %s"), buf2);
-              }
+              universal_name_translation(&coreq->source, buf2, sizeof(buf2));
+              strvec_append(coreq->present ? coreqs : conoreqs, buf2);
             }
           } requirement_vector_iterate_end;
 
-          if (coreq_buf[0] != '\0') {
-            if (conoreq_buf[0] != '\0') {
+          if (0 < strvec_size(coreqs)) {
+            if (0 < strvec_size(conoreqs)) {
               cat_snprintf(buf, bufsz, _("Allows %s (with %s but no %s)."),
                            improvement_name_translation(pimprove),
-                           coreq_buf, conoreq_buf);
+                           strvec_to_and_list(coreqs, &coreqstr),
+                           strvec_to_and_list(conoreqs, &conoreqstr));
             } else {
               cat_snprintf(buf, bufsz, _("Allows %s (with %s)."),
                            improvement_name_translation(pimprove),
-                           coreq_buf);
+                           strvec_to_and_list(coreqs, &coreqstr));
             }
           } else {
-            if (conoreq_buf[0] != '\0') {
+            if (0 < strvec_size(conoreqs)) {
               cat_snprintf(buf, bufsz, _("Allows %s (absent %s)."),
                            improvement_name_translation(pimprove),
-                           conoreq_buf);
+                           strvec_to_and_list(conoreqs, &conoreqstr));
             } else {
               cat_snprintf(buf, bufsz, _("Allows %s."),
                            improvement_name_translation(pimprove));
@@ -2461,6 +2459,11 @@
       }
     } requirement_vector_iterate_end;
   } improvement_iterate_end;
+
+  strvec_destroy(coreqs);
+  strvec_destroy(conoreqs);
+  astr_free(&coreqstr);
+  astr_free(&conoreqstr);
 }
 
 /****************************************************************

Modified: trunk/client/text.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/text.c?rev=26037&r1=26036&r2=26037&view=diff
==============================================================================
--- trunk/client/text.c (original)
+++ trunk/client/text.c Mon Aug 25 17:52:33 2014
@@ -1566,33 +1566,20 @@
 ****************************************************************************/
 const char *text_happiness_buildings(const struct city *pcity)
 {
-  char buf[512];
-  int faces = 0;
   struct effect_list *plist = effect_list_new();
   static struct astring str = ASTRING_INIT;
 
-  astr_clear(&str);
-
-  astr_add_line(&str, _("Buildings: "));
-
   get_city_bonus_effects(plist, pcity, NULL, EFT_MAKE_CONTENT);
-
-  effect_list_iterate(plist, peffect) {
-    get_effect_req_text(peffect, buf, sizeof(buf));
-    if (faces++ > 0) {
-      /* only one comment to translators needed. */
-      astr_add(&str, Q_("?clistmore:, %s"), buf);
-    } else {
-      astr_add(&str, "%s", buf);
-    }
-  } effect_list_iterate_end;
+  if (0 < effect_list_size(plist)) {
+    struct astring effects = ASTRING_INIT;
+
+    get_effect_list_req_text(plist, &effects);
+    astr_set(&str, _("Buildings: %s."), astr_str(&effects));
+    astr_free(&effects);
+  } else {
+    astr_set(&str, _("Buildings: None."));
+  }
   effect_list_destroy(plist);
-
-  if (faces == 0) {
-    astr_add(&str, _("None. "));
-  } else {
-    astr_add(&str, "%s", Q_("?clistend:."));
-  }
 
   /* Add line breaks after 80 characters. */
   astr_break_lines(&str, 80);
@@ -1643,34 +1630,20 @@
 ****************************************************************************/
 const char *text_happiness_wonders(const struct city *pcity)
 {
-  char buf[512];
-  int faces = 0;
   struct effect_list *plist = effect_list_new();
   static struct astring str = ASTRING_INIT;
 
-  astr_clear(&str);
-
-  astr_add_line(&str, _("Wonders: "));
   get_city_bonus_effects(plist, pcity, NULL, EFT_MAKE_HAPPY);
   get_city_bonus_effects(plist, pcity, NULL, EFT_FORCE_CONTENT);
   get_city_bonus_effects(plist, pcity, NULL, EFT_NO_UNHAPPY);
-
-  effect_list_iterate(plist, peffect) {
-    get_effect_req_text(peffect, buf, sizeof(buf));
-    if (faces++ > 0) {
-      /* only one comment to translators needed. */
-      astr_add(&str, Q_("?clistmore:, %s"), buf);
-    } else {
-      astr_add(&str, "%s", buf);
-    }
-  } effect_list_iterate_end;
-
-  effect_list_destroy(plist);
-
-  if (faces == 0) {
-    astr_add(&str, _("None. "));
-  } else {
-    astr_add(&str, "%s",  Q_("?clistend:."));
+  if (0 < effect_list_size(plist)) {
+    struct astring effects = ASTRING_INIT;
+
+    get_effect_list_req_text(plist, &effects);
+    astr_set(&str, _("Wonders: %s."), astr_str(&effects));
+    astr_free(&effects);
+  } else {
+    astr_set(&str, _("Wonders: None."));
   }
 
   /* Add line breaks after 80 characters. */

Modified: trunk/common/effects.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/effects.c?rev=26037&r1=26036&r2=26037&view=diff
==============================================================================
--- trunk/common/effects.c      (original)
+++ trunk/common/effects.c      Mon Aug 25 17:52:33 2014
@@ -18,11 +18,13 @@
 #include <string.h>
 
 /* utility */
+#include "astring.h"
 #include "fcintl.h"
 #include "log.h"
 #include "mem.h"
 #include "support.h"
 #include "shared.h" /* ARRAY_SIZE */
+#include "string_vector.h"
 
 /* common */
 #include "city.h"
@@ -869,7 +871,8 @@
   Make user-friendly text for the source.  The text is put into a user
   buffer.
 **************************************************************************/
-void get_effect_req_text(struct effect *peffect, char *buf, size_t buf_len)
+void get_effect_req_text(const struct effect *peffect,
+                         char *buf, size_t buf_len)
 {
   buf[0] = '\0';
 
@@ -880,12 +883,31 @@
       continue;
     }
     if (buf[0] != '\0') {
-      fc_strlcat(buf, "+", buf_len);
+      fc_strlcat(buf, Q_("?req-list-separator:+"), buf_len);
     }
 
     universal_name_translation(&preq->source,
                        buf + strlen(buf), buf_len - strlen(buf));
   } requirement_vector_iterate_end;
+}
+
+/****************************************************************************
+  Make user-friendly text for an effect list. The text is put into a user
+  astring.
+****************************************************************************/
+void get_effect_list_req_text(const struct effect_list *plist,
+                              struct astring *astr)
+{
+  struct strvec *psv = strvec_new();
+  char req_text[512];
+
+  effect_list_iterate(plist, peffect) {
+    get_effect_req_text(peffect, req_text, sizeof(req_text));
+    strvec_append(psv, req_text);
+  } effect_list_iterate_end;
+
+  strvec_to_and_list(psv, astr);
+  strvec_destroy(psv);
 }
 
 /**************************************************************************

Modified: trunk/common/effects.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/effects.h?rev=26037&r1=26036&r2=26037&view=diff
==============================================================================
--- trunk/common/effects.h      (original)
+++ trunk/common/effects.h      Mon Aug 25 17:52:33 2014
@@ -295,7 +295,11 @@
 struct effect *effect_new(enum effect_type type, int value);
 void effect_req_append(struct effect *peffect, struct requirement *preq);
 
-void get_effect_req_text(struct effect *peffect, char *buf, size_t buf_len);
+struct astring;
+void get_effect_req_text(const struct effect *peffect,
+                         char *buf, size_t buf_len);
+void get_effect_list_req_text(const struct effect_list *plist,
+                              struct astring *astr);
 
 /* ruleset cache creation and communication functions */
 struct packet_ruleset_effect;

Modified: trunk/server/techtools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/techtools.c?rev=26037&r1=26036&r2=26037&view=diff
==============================================================================
--- trunk/server/techtools.c    (original)
+++ trunk/server/techtools.c    Mon Aug 25 17:52:33 2014
@@ -15,6 +15,7 @@
 #endif
 
 /* utility */
+#include "astring.h"
 #include "fcintl.h"
 #include "log.h"
 #include "mem.h"
@@ -145,15 +146,9 @@
    * much worse effect. */
   if ((mod = get_player_bonus_effects(plist, pplayer,
                                      EFT_TECH_PARASITE)) > 0) {
-    char buf[512];
-
-    buf[0] = '\0';
-    effect_list_iterate(plist, peffect) {
-      if (buf[0] != '\0') {
-       sz_strlcat(buf, ", ");
-      }
-      get_effect_req_text(peffect, buf, sizeof(buf));
-    } effect_list_iterate_end;
+    struct astring effects = ASTRING_INIT;
+
+    get_effect_list_req_text(plist, &effects);
 
     advance_index_iterate(A_FIRST, i) {
       if (research_invention_gettable(presearch, i,
@@ -174,18 +169,18 @@
           notify_player(pplayer, NULL, E_TECH_GAIN, ftc_server,
                         _("%s acquired from %s!"),
                         research_advance_name_translation(presearch, i),
-                        buf);
+                        astr_str(&effects));
           notify_research(presearch, pplayer, E_TECH_GAIN, ftc_server,
                           _("%s acquired from %s's %s!"),
                           research_advance_name_translation(presearch, i),
                           player_name(pplayer),
-                          buf);
+                          astr_str(&effects));
           notify_research_embassies
               (presearch, NULL, E_TECH_GAIN, ftc_server,
                _("The %s have acquired %s from %s."),
                research_name,
                research_advance_name_translation(presearch, i),
-               buf);
+               astr_str(&effects));
 
          do_free_cost(pplayer, i);
           found_new_tech(presearch, i, FALSE, TRUE);
@@ -201,6 +196,7 @@
        }
       }
     } advance_index_iterate_end;
+    astr_free(&effects);
   }
   effect_list_destroy(plist);
 }


_______________________________________________
Freeciv-commits mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to