Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12663) Replace my_snprintf with cat_snprintf
Home

[Freeciv-Dev] (PR#12663) Replace my_snprintf with cat_snprintf

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12663) Replace my_snprintf with cat_snprintf
From: "Raimar Falke" <i-freeciv-lists@xxxxxxxxxxxxx>
Date: Sat, 26 Mar 2005 05:30:31 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12663 >


Replace 
  my_snprintf(buf + strlen(buf), x - strlen(buf),
with
  cat_snprintf(buf, x,

The patch will be applied soon.

        Raimar

-- 
 email: i-freeciv-lists@xxxxxxxxxxxxx
 "The two rules for success in life are:
  1) Never tell them everything you know."

Index: client/cityrepdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.c,v
retrieving revision 1.48
diff -u -u -r1.48 cityrepdata.c
--- client/cityrepdata.c        9 Feb 2005 15:45:53 -0000       1.48
+++ client/cityrepdata.c        26 Mar 2005 13:13:53 -0000
@@ -155,11 +155,10 @@
   buf[0] = '\0';
   for (i = 0; i < 3; i++) {
     if (attack_best[i] >= 0) {
-      my_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-                 "%s%d", (i > 0) ? "/" : "", attack_best[i]);
+      cat_snprintf(buf, sizeof(buf), "%s%d", (i > 0) ? "/" : "",
+                  attack_best[i]);
     } else {
-      my_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-                 "%s-", (i > 0) ? "/" : "");
+      cat_snprintf(buf, sizeof(buf), "%s-", (i > 0) ? "/" : "");
     }
   }
 
@@ -188,11 +187,10 @@
   buf[0] = '\0';
   for (i = 0; i < 3; i++) {
     if (defense_best[i] >= 0) {
-      my_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-                 "%s%d", (i > 0) ? "/" : "", defense_best[i]);
+      cat_snprintf(buf, sizeof(buf), "%s%d", (i > 0) ? "/" : "",
+                  defense_best[i]);
     } else {
-      my_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-                 "%s-", (i > 0) ? "/" : "");
+      cat_snprintf(buf, sizeof(buf), "%s-", (i > 0) ? "/" : "");
     }
   }
 
Index: client/helpdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/helpdata.c,v
retrieving revision 1.97
diff -u -u -r1.97 helpdata.c
--- client/helpdata.c   26 Mar 2005 12:53:18 -0000      1.97
+++ client/helpdata.c   26 Mar 2005 13:13:54 -0000
@@ -532,16 +532,15 @@
   imp = &improvement_types[which];
   
   if (imp->helptext && imp->helptext[0] != '\0') {
-    my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
-               "%s\n\n", _(imp->helptext));
+    cat_snprintf(buf, bufsz, "%s\n\n", _(imp->helptext));
   }
 
   if (tech_exists(improvement_types[which].obsolete_by)) {
-    my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
-               _("* The discovery of %s will make %s obsolete.\n"),
-               get_tech_name(game.player_ptr,
-                       improvement_types[which].obsolete_by),
-               improvement_types[which].name);
+    cat_snprintf(buf, bufsz,
+                _("* The discovery of %s will make %s obsolete.\n"),
+                get_tech_name(game.player_ptr,
+                              improvement_types[which].obsolete_by),
+                improvement_types[which].name);
   }
 
   if (building_has_effect(which, EFT_ENABLE_NUKE)
@@ -554,11 +553,11 @@
     t = get_unit_type(u)->tech_requirement;
     assert(t < game.num_tech_types);
 
-    my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
-               _("* Allows all players with knowledge of %s "
-                 "to build %s units.\n"),
-               get_tech_name(game.player_ptr, t), get_unit_type(u)->name);
-    my_snprintf(buf + strlen(buf), bufsz - strlen(buf), "  ");
+    cat_snprintf(buf, bufsz,
+                _("* Allows all players with knowledge of %s "
+                  "to build %s units.\n"),
+                get_tech_name(game.player_ptr, t), get_unit_type(u)->name);
+    cat_snprintf(buf, bufsz, "  ");
   }
 
   impr_type_iterate(impr) {
@@ -570,9 +569,7 @@
 
 #define req_append(s)                                                      \
       (req_buf[0] != '\0'                                                  \
-       ? my_snprintf(req_buf + strlen(req_buf),                                
    \
-                    sizeof(req_buf) - strlen(req_buf),                     \
-                    ", %s", (s))                                           \
+       ? cat_snprintf(req_buf, sizeof(req_buf),        ", %s", (s))            
    \
        : sz_strlcpy(req_buf, (s)))
 
       if (b->tech_req != A_NONE) {
@@ -588,11 +585,10 @@
 #undef req_append
 
       if (req_buf[0] != '\0') {
-       my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
-                   _("* Allows %s (with %s).\n"), b->name, req_buf);
+       cat_snprintf(buf, bufsz, _("* Allows %s (with %s).\n"), b->name,
+                    req_buf);
       } else {
-       my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
-                   _("* Allows %s.\n"), b->name);
+       cat_snprintf(buf, bufsz, _("* Allows %s.\n"), b->name);
       }
     }
   } impr_type_iterate_end;
@@ -602,18 +598,16 @@
 
     if (u->impr_requirement == which) {
       if (u->tech_requirement != A_LAST) {
-       my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
-                   _("* Allows %s (with %s).\n"), u->name,
-                   get_tech_name(game.player_ptr, u->tech_requirement));
+       cat_snprintf(buf, bufsz, _("* Allows %s (with %s).\n"), u->name,
+                    get_tech_name(game.player_ptr, u->tech_requirement));
       } else {
-       my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
-                   _("* Allows %s.\n"), u->name);
+       cat_snprintf(buf, bufsz, _("* Allows %s.\n"), u->name);
       }
     }
   } unit_type_iterate_end;
 
   if (user_text && user_text[0] != '\0') {
-    my_snprintf(buf + strlen(buf), bufsz - strlen(buf), "\n\n%s", user_text);
+    cat_snprintf(buf, bufsz, "\n\n%s", user_text);
   }
 
   wordwrap_string(buf, 68);
@@ -646,9 +640,9 @@
     const char *name = get_tech_name(NULL, tech_id);
 
     if (buf[0] == '\0') {
-      my_snprintf(buf, bufsz, "%s", name);
+      cat_snprintf(buf, bufsz, "%s", name);
     } else {
-      my_snprintf(buf + strlen(buf), bufsz - strlen(buf), ", %s", name);
+      cat_snprintf(buf, bufsz, ", %s", name);
     }
     count++;
   } techs_with_flag_iterate_end;
Index: client/gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.92
diff -u -u -r1.92 citydlg.c
--- client/gui-mui/citydlg.c    21 Mar 2005 16:37:53 -0000      1.92
+++ client/gui-mui/citydlg.c    26 Mar 2005 13:13:55 -0000
@@ -2041,17 +2041,15 @@
       } else {
        my_snprintf(cityname, sizeof(cityname), _("%s"), _("Unknown"));
       }
-      my_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-                 _("Trade with %s gives %d trade.\n"),
+      cat_snprintf(buf, sizeof(buf), _("Trade with %s gives %d trade.\n"),
                  cityname, pdialog->pcity->trade_value[i]);
     }
   }
   if (!x) {
-    my_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-               _("No trade routes exist."));
+    cat_snprintf(buf, sizeof(buf), _("No trade routes exist."));
   } else {
-    my_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-               _("Total trade from trade routes: %d"), total);
+    cat_snprintf(buf, sizeof(buf), _("Total trade from trade routes: %d"),
+                total);
   }
   settext(pdialog->trade_text,buf);
 }
Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.98
diff -u -u -r1.98 citydlg.c
--- client/gui-win32/citydlg.c  23 Mar 2005 22:27:10 -0000      1.98
+++ client/gui-win32/citydlg.c  26 Mar 2005 13:13:56 -0000
@@ -1257,17 +1257,15 @@
       } else {
         my_snprintf(cityname, sizeof(cityname), _("%s"), _("Unknown"));
       }
-      my_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-                  _("Trade with %s gives %d trade.\n"),
-                  cityname, pdialog->pcity->trade_value[i]);
+      cat_snprintf(buf, sizeof(buf), _("Trade with %s gives %d trade.\n"),
+                  cityname, pdialog->pcity->trade_value[i]);
     }
   }
   if (!x) {
-    my_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-                _("No trade routes exist."));
+    cat_snprintf(buf, sizeof(buf), _("No trade routes exist."));
   } else {
-    my_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-                _("Total trade from trade routes: %d"), total);
+    cat_snprintf(buf, sizeof(buf), _("Total trade from trade routes: %d"),
+                total);
   }
   SetWindowText(pdialog->trade_label,buf);
 }
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.321
diff -u -u -r1.321 city.c
--- common/city.c       26 Mar 2005 05:59:14 -0000      1.321
+++ common/city.c       26 Mar 2005 13:13:57 -0000
@@ -2426,15 +2426,14 @@
 **************************************************************************/
 const char *specialists_string(const int *specialists)
 {
-  size_t len = 0;
   static char buf[5 * SP_MAX];
 
+  buf[0] = '\0';
+
   specialist_type_iterate(sp) {
-    char *separator = (len == 0) ? "" : "/";
+    char *separator = (buf[0] == '\0') ? "" : "/";
 
-    my_snprintf(buf + len, sizeof(buf) - len,
-               "%s%d", separator, specialists[sp]);
-    len += strlen(buf + len);
+    cat_snprintf(buf, sizeof(buf), "%s%d", separator, specialists[sp]);
   } specialist_type_iterate_end;
 
   return buf;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12663) Replace my_snprintf with cat_snprintf, Raimar Falke <=