[Freeciv-Dev] (PR#7326) [RfP] expansion in filenames
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=7326 >
> [kauf - Mon Sep 06 14:54:48 2004]:
>
> tilde is spelled as so.
>
> -mike
>
Corrected
--
mateusz
? advdiplomacy.c
? client/civgame-2400.sav.gz
? client/civgame-2500.sav.gz
? client/civgame-3000.sav.gz
? client/civgame-3500.sav.gz
? client/civgame-3950.sav.gz
? server/civgame-1550.sav.gz
? server/civgame-2000.sav.gz
? server/civgame-2500.sav.gz
? server/civgame-3000.sav.gz
? server/civgame-3350.sav.gz
? server/civgame-3500.sav.gz
? server/civgame-3700.sav.gz
? server/civgame-3800.sav.gz
? server/civgame-3850.sav.gz
? server/civgame-3900.sav.gz
? server/civgame-3950.sav.gz
? server/load
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.343
diff -u -r1.343 stdinhand.c
--- server/stdinhand.c 4 Sep 2004 20:36:10 -0000 1.343
+++ server/stdinhand.c 6 Sep 2004 13:19:54 -0000
@@ -881,11 +881,14 @@
bool read_init_script(struct connection *caller, char *script_filename)
{
FILE *script_file;
+ char real_filename[1024];
freelog(LOG_NORMAL, _("Loading script file: %s"), script_filename);
+
+ interpret_tilde(real_filename, sizeof(real_filename), script_filename);
- if (is_reg_file_for_access(script_filename, FALSE)
- && (script_file = fopen(script_filename, "r"))) {
+ if (is_reg_file_for_access(real_filename, FALSE)
+ && (script_file = fopen(real_filename, "r"))) {
char buffer[MAX_LEN_CONSOLE_LINE];
/* the size is set as to not overflow buffer in handle_stdin_input */
while(fgets(buffer,MAX_LEN_CONSOLE_LINE-1,script_file))
@@ -894,9 +897,9 @@
return TRUE;
} else {
cmd_reply(CMD_READ_SCRIPT, caller, C_FAIL,
- _("Cannot read command line scriptfile '%s'."), script_filename);
+ _("Cannot read command line scriptfile '%s'."), real_filename);
freelog(LOG_ERROR,
- _("Could not read script file '%s'."), script_filename);
+ _("Could not read script file '%s'."), real_filename);
return FALSE;
}
}
@@ -919,10 +922,13 @@
**************************************************************************/
static void write_init_script(char *script_filename)
{
+ char real_filename[1024];
FILE *script_file;
+
+ interpret_tilde(real_filename, sizeof(real_filename), script_filename);
- if (is_reg_file_for_access(script_filename, TRUE)
- && (script_file = fopen(script_filename, "w"))) {
+ if (is_reg_file_for_access(real_filename, TRUE)
+ && (script_file = fopen(real_filename, "w"))) {
int i;
@@ -985,7 +991,7 @@
} else {
freelog(LOG_ERROR,
- _("Could not write script file '%s'."), script_filename);
+ _("Could not write script file '%s'."), real_filename);
}
}
Index: utility/registry.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/registry.c,v
retrieving revision 1.66
diff -u -r1.66 registry.c
--- utility/registry.c 22 Jul 2004 19:04:33 -0000 1.66
+++ utility/registry.c 6 Sep 2004 13:19:59 -0000
@@ -584,9 +584,13 @@
bool section_file_load(struct section_file *my_section_file,
const char *filename)
{
- struct inputfile *inf = inf_from_file(filename, datafilename);
+ char real_filename[1024];
+ struct inputfile *inf;
- return section_file_read_dup(my_section_file, filename, inf, TRUE);
+ interpret_tilde(real_filename, sizeof(real_filename), filename);
+ inf = inf_from_file(real_filename, datafilename);
+
+ return section_file_read_dup(my_section_file, real_filename, inf, TRUE);
}
/**************************************************************************
@@ -595,9 +599,13 @@
bool section_file_load_nodup(struct section_file *my_section_file,
const char *filename)
{
- struct inputfile *inf = inf_from_file(filename, datafilename);
+ char real_filename[1024];
+ struct inputfile *inf;
+
+ interpret_tilde(real_filename, sizeof(real_filename), filename);
+ inf = inf_from_file(real_filename, datafilename);
- return section_file_read_dup(my_section_file, filename, inf, FALSE);
+ return section_file_read_dup(my_section_file, real_filename, inf, FALSE);
}
/**************************************************************************
@@ -630,14 +638,18 @@
Below simply specifies FZ_ZLIB method, since fz_fromFile() automatically
changes to FZ_PLAIN method when level==0.
**************************************************************************/
-bool section_file_save(struct section_file *my_section_file, const char
*filename,
- int compression_level)
+bool section_file_save(struct section_file *my_section_file,
+ const char *filename,
+ int compression_level)
{
- fz_FILE *fs = fz_from_file(filename, "w", FZ_ZLIB, compression_level);
-
+ char real_filename[1024];
+ fz_FILE *fs;
struct genlist_link *ent_iter, *save_iter, *col_iter;
struct entry *pentry, *col_pentry;
int i;
+
+ interpret_tilde(real_filename, sizeof(real_filename), filename);
+ fs = fz_from_file(real_filename, "w", FZ_ZLIB, compression_level);
if (!fs)
return FALSE;
@@ -721,7 +733,7 @@
if((!pentry) || (strcmp(pentry->name, expect) != 0)) {
if(icol != 0) {
freelog(LOG_ERROR, "unexpected exit from tabular at %s (%s)",
- pentry->name, filename);
+ pentry->name, real_filename);
fz_fprintf(fs, "\n");
}
fz_fprintf(fs, "}\n");
@@ -774,13 +786,13 @@
(void) moutstr(NULL); /* free internal buffer */
if (fz_ferror(fs) != 0) {
- freelog(LOG_ERROR, "Error before closing %s: %s", filename,
+ freelog(LOG_ERROR, "Error before closing %s: %s", real_filename,
fz_strerror(fs));
fz_fclose(fs);
return FALSE;
}
if (fz_fclose(fs) != 0) {
- freelog(LOG_ERROR, "Error closing %s", filename);
+ freelog(LOG_ERROR, "Error closing %s", real_filename);
return FALSE;
}
Index: utility/shared.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/shared.c,v
retrieving revision 1.115
diff -u -r1.115 shared.c
--- utility/shared.c 20 Jul 2004 14:34:32 -0000 1.115
+++ utility/shared.c 6 Sep 2004 13:19:59 -0000
@@ -1320,3 +1320,18 @@
}
return group;
}
+
+/***************************************************************************
+ Interpret ~/ in filename as home dir
+ New path is returned in buf of size buf_size
+***************************************************************************/
+void interpret_tilde(char* buf, size_t buf_size, const char* filename)
+{
+ if (filename[0] == '~' && filename[1] == '/') {
+ my_snprintf(buf, buf_size, "%s/%s", user_home_dir(), filename + 2);
+ } else if (filename[0] == '~' && filename[1] == '\0') {
+ strncpy(buf, user_home_dir(), buf_size);
+ } else {
+ strncpy(buf, filename, buf_size);
+ }
+}
Index: utility/shared.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/shared.h,v
retrieving revision 1.131
diff -u -r1.131 shared.h
--- utility/shared.h 24 Aug 2004 20:27:11 -0000 1.131
+++ utility/shared.h 6 Sep 2004 13:20:00 -0000
@@ -243,5 +243,5 @@
int *ind_result);
char *get_multicast_group(void);
-
+void interpret_tilde(char* buf, size_t buf_size, const char* filename);
#endif /* FC__SHARED_H */
|
|