Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#8664) gettext and const char *'s
Home

[Freeciv-Dev] (PR#8664) gettext and const char *'s

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8664) gettext and const char *'s
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 6 May 2004 14:53:07 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8664 >

> [jdorje - Tue May 04 04:56:57 2004]:
> 
> We should probably treat every gettext-returned string as a const char * 
>   rather than a char *.  (This may or may not relate to PR#8661.)

Here's a patch for server/.

jason

Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.257
diff -u -r1.257 citytools.c
--- server/citytools.c  22 Mar 2004 20:58:13 -0000      1.257
+++ server/citytools.c  6 May 2004 21:51:22 -0000
@@ -282,6 +282,9 @@
 
   static const int num_tiles = MAP_MAX_WIDTH * MAP_MAX_HEIGHT; 
 
+  /* tempname must be static because it's returned below. */
+  static char tempname[MAX_LEN_NAME];
+
   /* This function follows a straightforward algorithm to look through
    * nations to find a city name.
    *
@@ -369,9 +372,6 @@
   }
 
   for (i = 1; i <= num_tiles; i++ ) {
-    /* tempname must be static because it's returned below. */
-    static char tempname[MAX_LEN_NAME];
-
     my_snprintf(tempname, MAX_LEN_NAME, _("City no. %d"), i);
     if (!game_find_city_by_name(tempname)) {
       return tempname;
@@ -380,7 +380,8 @@
   
   /* This had better be impossible! */
   assert(FALSE);
-  return _("A poorly-named city");
+  sz_strlcpy(tempname, _("A poorly-named city"));
+  return tempname;
 }
 
 /****************************************************************
Index: server/connecthand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/connecthand.c,v
retrieving revision 1.20
diff -u -r1.20 connecthand.c
--- server/connecthand.c        19 Apr 2004 21:41:17 -0000      1.20
+++ server/connecthand.c        6 May 2004 21:51:23 -0000
@@ -60,7 +60,7 @@
 #endif
 
 static void establish_new_connection(struct connection *pconn);
-static void reject_new_connection(char *msg, struct connection *pconn);
+static void reject_new_connection(const char *msg, struct connection *pconn);
 
 #ifdef AUTHENTICATION_ENABLED
 static bool is_guest_name(const char *name);
@@ -189,7 +189,7 @@
 /**************************************************************************
   send the rejection packet to the client.
 **************************************************************************/
-static void reject_new_connection(char *msg, struct connection *pconn)
+static void reject_new_connection(const char *msg, struct connection *pconn)
 {
   struct packet_server_join_reply packet;
 
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.309
diff -u -r1.309 plrhand.c
--- server/plrhand.c    20 Apr 2004 17:21:57 -0000      1.309
+++ server/plrhand.c    6 May 2004 21:51:23 -0000
@@ -767,7 +767,7 @@
   }
   maxrate=get_government_max_rate (pplayer->government);
   if (tax > maxrate || luxury > maxrate || science > maxrate) {
-    char *rtype;
+    const char *rtype;
 
     if (tax > maxrate)
       rtype = _("Tax");
Index: server/report.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/report.c,v
retrieving revision 1.49
diff -u -r1.49 report.c
--- server/report.c     28 Nov 2003 17:37:22 -0000      1.49
+++ server/report.c     6 May 2004 21:51:23 -0000
@@ -655,7 +655,7 @@
   Verify that a given demography string is valid.  See
   game.demography.
 *************************************************************************/
-bool is_valid_demography(const char *demography, char **error_string)
+bool is_valid_demography(const char *demography, const char **error_string)
 {
   int len = strlen(demography), i;
 
Index: server/report.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/report.h,v
retrieving revision 1.7
diff -u -r1.7 report.h
--- server/report.h     15 Sep 2003 19:40:53 -0000      1.7
+++ server/report.h     6 May 2004 21:51:23 -0000
@@ -24,7 +24,7 @@
 void make_history_report(void);
 void report_wonders_of_the_world(struct conn_list *dest);
 void report_top_five_cities(struct conn_list *dest);
-bool is_valid_demography(const char *demographics, char **error_message);
+bool is_valid_demography(const char *demography, const char **error_message);
 void report_demographics(struct connection *pconn);
 void report_progress_scores(void);
 void report_final_scores(void);
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.315
diff -u -r1.315 stdinhand.c
--- server/stdinhand.c  24 Apr 2004 17:32:47 -0000      1.315
+++ server/stdinhand.c  6 May 2004 21:51:25 -0000
@@ -184,30 +184,31 @@
   /*** bool part ***/
   bool *bool_value;
   bool bool_default_value;
-  bool (*bool_validate)(bool, char **);
+  bool (*bool_validate)(bool, const char **);
 
   /*** int part ***/
   int *int_value;
   int int_default_value;
-  bool (*int_validate)(int, char **);
+  bool (*int_validate)(int, const char **);
   int int_min_value, int_max_value;
 
   /*** string part ***/
   char *string_value;
   const char *string_default_value;
-  bool (*string_validate)(const char *, char **);
+  bool (*string_validate)(const char *, const char **);
   size_t string_value_size;    /* max size we can write into string_value */
 };
 
 /*
  * Triggers used in settings_s.
  */
-static bool valid_notradesize(int value, char **reject_message);
-static bool valid_fulltradesize(int value, char **reject_message);
-static bool autotoggle(bool value, char **reject_message);
-static bool is_valid_allowtake(const char *allow_take, char **error_string);
+static bool valid_notradesize(int value, const char **reject_message);
+static bool valid_fulltradesize(int value, const char **reject_message);
+static bool autotoggle(bool value, const char **reject_message);
+static bool is_valid_allowtake(const char *allow_take,
+                              const char **error_string);
 
-static bool valid_max_players(int v, char **r_m)
+static bool valid_max_players(int v, const char **r_m)
 {
   static char buffer[MAX_LEN_CONSOLE_LINE];
 
@@ -2748,7 +2749,8 @@
   int i, c;
   char buffer[4096];
   char title[128];
-  char *caption;
+  const char *caption;
+
   buffer[0] = 0;
   my_snprintf(title, sizeof(title), _("%-20svalue  (min , max)"), _("Option"));
   caption = (which == 1) ?
@@ -3208,8 +3210,8 @@
   char buf[MAX_LEN_CONSOLE_LINE];
   char *arg[3];
   int ntokens = 0, i;
-  char *usage = _("Undefined arguments. Usage: vote new <command> "
-                  "  or   vote yes|no [vote number].");
+  const char *usage = _("Undefined arguments. Usage: vote new <command> "
+                       "  or   vote yes|no [vote number].");
   int idx;
   bool res = FALSE;
 
@@ -3303,8 +3305,9 @@
   char buf[MAX_LEN_CONSOLE_LINE];
   char *arg[3];
   int ntokens = 0, i;
-  char *usage = _("Undefined arguments. Usage: debug <player "
-                  "<player> | city <x> <y> | units <x> <y> | unit <id>>.");
+  const char *usage = _("Undefined arguments. Usage: debug <player "
+                       "<player> | city <x> <y> | units <x> <y> | "
+                       "unit <id>>.");
 
   if (server_state != RUN_GAME_STATE) {
     cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
@@ -3500,7 +3503,7 @@
                _("Value out of range (minimum: 0, maximum: 1)."));
       return FALSE;
     } else {
-      char *reject_message = NULL;
+      const char *reject_message = NULL;
       bool b_val = (val != 0);
 
       if (settings[cmd].bool_validate
@@ -3526,7 +3529,7 @@
                op->int_min_value, op->int_max_value);
       return FALSE;
     } else {
-      char *reject_message = NULL;
+      const char *reject_message = NULL;
 
       if (settings[cmd].int_validate
          && !settings[cmd].int_validate(val, &reject_message)) {
@@ -3548,7 +3551,7 @@
                _("String value too long.  Usage: set <option> <value>."));
       return FALSE;
     } else {
-      char *reject_message = NULL;
+      const char *reject_message = NULL;
 
       if (settings[cmd].string_validate
          && !settings[cmd].string_validate(arg, &reject_message)) {
@@ -4910,7 +4913,7 @@
 /**************************************************************************
   Verify that notradesize is always smaller than fulltradesize
 **************************************************************************/
-static bool valid_notradesize(int value, char **reject_message)
+static bool valid_notradesize(int value, const char **reject_message)
 {
   if (value < game.fulltradesize)
     return TRUE;
@@ -4923,7 +4926,7 @@
 /**************************************************************************
   Verify that fulltradesize is always bigger than notradesize
 **************************************************************************/
-static bool valid_fulltradesize(int value, char **reject_message)
+static bool valid_fulltradesize(int value, const char **reject_message)
 {
   if (value > game.notradesize)
     return TRUE;
@@ -4933,7 +4936,7 @@
   return FALSE;
 }
 
-static bool autotoggle(bool value, char **reject_message)
+static bool autotoggle(bool value, const char **reject_message)
 {
   if (!value)
     return TRUE;
@@ -4953,7 +4956,8 @@
   Verify that a given allowtake string is valid.  See
   game.allow_take.
 *************************************************************************/
-static bool is_valid_allowtake(const char *allow_take, char **error_string)
+static bool is_valid_allowtake(const char *allow_take,
+                              const char **error_string)
 {
   int len = strlen(allow_take), i;
   bool havecharacter_state = FALSE;

[Prev in Thread] Current Thread [Next in Thread]