[Freeciv-Dev] (PR#40681) [Patch] Include turn number in generated save name

2009-02-06 Thread Madeline Book

http://bugs.freeciv.org/Ticket/Display.html?id=40681 >

> [book - Tue Jan 27 23:58:42 2009]:
> 
> > [dmarks - Tue Jan 27 00:38:35 2009]:
> > 
> > How about a prefix for the year part too?
> > 
> > _T_Y.sav.gz
> 
> Ok.
> 
> On second look the underscores do seem uglier than
> dashes, so I also changed the format to:
> 
> -T-Y.sav.gz
> 
> with 'year' being unsigned. So for example:
> civgame-T001-Y3950BC.sav.gz

Version 3 fixes a a mistake in an NB comment: it said
"savegame" instead of "savename" when referring to
the setting help text.


--
練習の回数が増える。
diff --git a/server/settings.c b/server/settings.c
index f13b13b..2713bda 100644
--- a/server/settings.c
+++ b/server/settings.c
@@ -1014,7 +1014,7 @@ struct settings_s settings[] = {
 	 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_SERVER_ONLY,
 	 N_("Auto-save name prefix"),
 	 N_("Automatically saved games will have name "
-		"\".sav\". This setting sets "
+		"\"-T-Y.sav\". This setting sets "
 		"the  part."), NULL,
 	 GAME_DEFAULT_SAVE_NAME)
 
diff --git a/server/srv_main.c b/server/srv_main.c
index b386a40..037de2f 100644
--- a/server/srv_main.c
+++ b/server/srv_main.c
@@ -866,6 +866,40 @@ static void end_turn(void)
 }
 
 /**
+  Generate a default save file name and place it in the provided buffer.
+  The name will be of the form "-T-Y" where:
+
+ = game.save_name
+   = game.info.turn (zero padded to 3 places)
+   = game.info.year (not padded and no sign)
+ = "BC" or "AD" for negative or positive year resp.
+  = "m" (for "manual save") if 'is_auto_save' is FALSE
+
+  Returns the number of characters written, or the number of characters
+  that would have been written if truncation occurs.
+**/
+static int generate_save_name(char *buf, int buflen, bool is_auto_save)
+{
+  int nb, year;
+  const char *year_suffix;
+
+  if (game.info.year < 0) {
+year = -game.info.year;
+year_suffix = "BC";
+  } else {
+year = game.info.year;
+year_suffix = "AD";
+  }
+
+  /* NB: If you change the format here, be sure to update the above
+   * function comment and the help text for the 'savename' setting. */
+  nb = my_snprintf(buf, buflen, "%s-T%03d-Y%d%s%s",
+   game.save_name, game.info.turn, year,
+   year_suffix, is_auto_save ? "" : "m");
+  return nb;
+}
+
+/**
 Unconditionally save the game, with specified filename.
 Always prints a message: either save ok, or failed.
 
@@ -890,10 +924,9 @@ void save_game(char *orig_filename, const char *save_reason)
 *dot = '\0';
   }
 
-  /* If orig_filename is NULL or empty, use "civgame.info.year>m". */
+  /* If orig_filename is NULL or empty, use a generated default name. */
   if (filename[0] == '\0'){
-my_snprintf(filename, sizeof(filename),
-	"%s%+05dm", game.save_name, game.info.year);
+generate_save_name(filename, sizeof(filename), FALSE);
   }
   
   timer_cpu = new_timer_start(TIMER_CPU, TIMER_ACTIVE);
@@ -947,8 +980,7 @@ void save_game_auto(const char *save_reason)
 
   assert(strlen(game.save_name)<256);
   
-  my_snprintf(filename, sizeof(filename),
-	  "%s%+05d.sav", game.save_name, game.info.year);
+  generate_save_name(filename, sizeof(filename), TRUE);
   save_game(filename, save_reason);
   save_ppm();
 }
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#40681) [Patch] Include turn number in generated save name

2009-01-27 Thread Madeline Book

http://bugs.freeciv.org/Ticket/Display.html?id=40681 >

> [dmarks - Tue Jan 27 00:38:35 2009]:
> 
> How about a prefix for the year part too?
> 
> _T_Y.sav.gz

Ok.

On second look the underscores do seem uglier than
dashes, so I also changed the format to:

-T-Y.sav.gz

with 'year' being unsigned. So for example:
civgame-T001-Y3950BC.sav.gz

Or maybe now the 'Y' is unneeded?


Probably in the near future someone will just have to
make the 'savename' setting a fully printf-style format
string encompassing the entire generated name... :|


---
この状況では洗濯できませんよ。
diff --git a/server/settings.c b/server/settings.c
index f13b13b..2713bda 100644
--- a/server/settings.c
+++ b/server/settings.c
@@ -1014,7 +1014,7 @@ struct settings_s settings[] = {
 	 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_SERVER_ONLY,
 	 N_("Auto-save name prefix"),
 	 N_("Automatically saved games will have name "
-		"\".sav\". This setting sets "
+		"\"-T-Y.sav\". This setting sets "
 		"the  part."), NULL,
 	 GAME_DEFAULT_SAVE_NAME)
 
diff --git a/server/srv_main.c b/server/srv_main.c
index b386a40..d986dbc 100644
--- a/server/srv_main.c
+++ b/server/srv_main.c
@@ -866,6 +866,40 @@ static void end_turn(void)
 }
 
 /**
+  Generate a default save file name and place it in the provided buffer.
+  The name will be of the form "-T-Y" where:
+
+ = game.save_name
+   = game.info.turn (zero padded to 3 places)
+   = game.info.year (not padded and no sign)
+ = "BC" or "AD" for negative or positive year resp.
+  = "m" (for "manual save") if 'is_auto_save' is FALSE
+
+  Returns the number of characters written, or the number of characters
+  that would have been written if truncation occurs.
+**/
+static int generate_save_name(char *buf, int buflen, bool is_auto_save)
+{
+  int nb, year;
+  const char *year_suffix;
+
+  if (game.info.year < 0) {
+year = -game.info.year;
+year_suffix = "BC";
+  } else {
+year = game.info.year;
+year_suffix = "AD";
+  }
+
+  /* NB: If you change the format here, be sure to update the above
+   * function comment and the help text for the savegame setting. */
+  nb = my_snprintf(buf, buflen, "%s-T%03d-Y%d%s%s",
+   game.save_name, game.info.turn, year,
+   year_suffix, is_auto_save ? "" : "m");
+  return nb;
+}
+
+/**
 Unconditionally save the game, with specified filename.
 Always prints a message: either save ok, or failed.
 
@@ -890,10 +924,9 @@ void save_game(char *orig_filename, const char *save_reason)
 *dot = '\0';
   }
 
-  /* If orig_filename is NULL or empty, use "civgame.info.year>m". */
+  /* If orig_filename is NULL or empty, use a generated default name. */
   if (filename[0] == '\0'){
-my_snprintf(filename, sizeof(filename),
-	"%s%+05dm", game.save_name, game.info.year);
+generate_save_name(filename, sizeof(filename), FALSE);
   }
   
   timer_cpu = new_timer_start(TIMER_CPU, TIMER_ACTIVE);
@@ -947,8 +980,7 @@ void save_game_auto(const char *save_reason)
 
   assert(strlen(game.save_name)<256);
   
-  my_snprintf(filename, sizeof(filename),
-	  "%s%+05d.sav", game.save_name, game.info.year);
+  generate_save_name(filename, sizeof(filename), TRUE);
   save_game(filename, save_reason);
   save_ppm();
 }
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#40681) [Patch] Include turn number in generated save name

2009-01-26 Thread Daniel Markstedt

http://bugs.freeciv.org/Ticket/Display.html?id=40681 >

How about a prefix for the year part too?

_T_Y.sav.gz

Daniel

On Mon, 26 Jan 2009 13:18:15 +0900, Madeline Book  
 wrote:

>
> http://bugs.freeciv.org/Ticket/Display.html?id=40681 >
>
> The attached patch factors out duplicate save name generating
> code into a new function generate_save_name(). This function
> also adds the current turn number to savefile names it
> generates, so that save files become:
>
>   _T_.sav.gz
>
> e.g. "civgame_T001_-3950.sav.gz".
>
>
> Requested in the forums:
> http://forum.freeciv.org/viewtopic.php?p=23039#23039
>
>
> ---
> どのやり方が一番いいですか?靴下で?




___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#40681) [Patch] Include turn number in generated save name

2009-01-25 Thread Madeline Book

http://bugs.freeciv.org/Ticket/Display.html?id=40681 >

The attached patch factors out duplicate save name generating
code into a new function generate_save_name(). This function
also adds the current turn number to savefile names it
generates, so that save files become:

  _T_.sav.gz

e.g. "civgame_T001_-3950.sav.gz".


Requested in the forums:
http://forum.freeciv.org/viewtopic.php?p=23039#23039


---
どのやり方が一番いいですか?靴下で?
diff --git a/server/settings.c b/server/settings.c
index f13b13b..32c9224 100644
--- a/server/settings.c
+++ b/server/settings.c
@@ -1014,7 +1014,7 @@ struct settings_s settings[] = {
 	 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_SERVER_ONLY,
 	 N_("Auto-save name prefix"),
 	 N_("Automatically saved games will have name "
-		"\".sav\". This setting sets "
+		"\"_T_.sav\". This setting sets "
 		"the  part."), NULL,
 	 GAME_DEFAULT_SAVE_NAME)
 
diff --git a/server/srv_main.c b/server/srv_main.c
index b386a40..f7dcef7 100644
--- a/server/srv_main.c
+++ b/server/srv_main.c
@@ -866,6 +866,30 @@ static void end_turn(void)
 }
 
 /**
+  Generate a default save file name and place it in the provided buffer.
+  The name will be of the form "_T_" where:
+
+ = game.save_name
+ = game.info.turn (zero padded to 3 places)
+ = game.info.year (zero padded to 5 places with 1 sign character)
+  = "m" (for "manual save") if 'is_auto_save' is FALSE
+
+  Returns the number of characters written, or the number of characters
+  that would have been written if truncation occurs.
+**/
+static int generate_save_name(char *buf, int buflen, bool is_auto_save)
+{
+  int nb;
+
+  /* NB: If you change the format here, be sure to update the above
+   * function comment and the help text for the savegame setting. */
+  nb = my_snprintf(buf, buflen, "%s_T%03d_%+05d%s",
+   game.save_name, game.info.turn, game.info.year,
+   is_auto_save ? "" : "m");
+  return nb;
+}
+
+/**
 Unconditionally save the game, with specified filename.
 Always prints a message: either save ok, or failed.
 
@@ -890,10 +914,9 @@ void save_game(char *orig_filename, const char *save_reason)
 *dot = '\0';
   }
 
-  /* If orig_filename is NULL or empty, use "civgame.info.year>m". */
+  /* If orig_filename is NULL or empty, use a generated default name. */
   if (filename[0] == '\0'){
-my_snprintf(filename, sizeof(filename),
-	"%s%+05dm", game.save_name, game.info.year);
+generate_save_name(filename, sizeof(filename), FALSE);
   }
   
   timer_cpu = new_timer_start(TIMER_CPU, TIMER_ACTIVE);
@@ -947,8 +970,7 @@ void save_game_auto(const char *save_reason)
 
   assert(strlen(game.save_name)<256);
   
-  my_snprintf(filename, sizeof(filename),
-	  "%s%+05d.sav", game.save_name, game.info.year);
+  generate_save_name(filename, sizeof(filename), TRUE);
   save_game(filename, save_reason);
   save_ppm();
 }
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev