Fixes for w-format-truncation. Also, export of zones work again on linux

This commit is contained in:
Thomas Arp
2020-01-11 01:05:32 +01:00
parent b028d60749
commit 29f19f9ce5
8 changed files with 60 additions and 34 deletions

View File

@@ -278,39 +278,44 @@ int sprintascii(char *out, bitvector_t bits)
}
/* converts illegal filename chars into appropriate equivalents */
static char *fix_filename(char *str)
static void fix_filename(const char *str, char *outbuf, size_t maxlen)
{
static char good_file_name[MAX_STRING_LENGTH];
char *cindex = good_file_name;
while(*str) {
switch(*str) {
case ' ': *cindex = '_'; cindex++; break;
case '(': *cindex = '{'; cindex++; break;
case ')': *cindex = '}'; cindex++; break;
const char *in = str;
char *out = outbuf;
int count = 0;
while (*in) {
switch(*in) {
case ' ': *out = '_'; out++; break;
case '(': *out = '{'; out++; break;
case ')': *out = '}'; out++; break;
/* skip the following */
case '\'': break;
case '"': break;
/* Legal character */
default: *cindex = *str; cindex++;break;
default: *out = *in; out++;break;
}
str++;
}
*cindex = '\0';
return good_file_name;
in++;
count++;
if (count == maxlen - 1) break;
}
*out = '\0';
}
/* Export command by Kyle */
ACMD(do_export_zone)
{
#ifdef CIRCLE_WINDOWS
/* tar and gzip are usually not available */
send_to_char(ch, "Sorry, that is not available in the windows port.\r\n");
#else /* all other configurations */
zone_rnum zrnum;
zone_vnum zvnum;
char sysbuf[MAX_INPUT_LENGTH];
char zone_name[MAX_INPUT_LENGTH], *f;
int success;
char zone_name[READ_SIZE], fixed_file_name[READ_SIZE];
int success, errorcode = 0;
/* system command locations are relative to where the binary IS, not where it
* was run from, thus we act like we are in the bin folder, because we are*/
@@ -336,9 +341,14 @@ ACMD(do_export_zone)
/* If we fail, it might just be because the directory didn't exist. Can't
* hurt to try again. Do it silently though ( no logs ). */
if (!export_info_file(zrnum)) {
sprintf(sysbuf, "mkdir %s", path);
sprintf(sysbuf, "mkdir %s", path);
errorcode = system(sysbuf);
}
if (errorcode) {
send_to_char(ch, "Failed to create export directory.\r\n");
return;
}
if (!(success = export_info_file(zrnum)))
send_to_char(ch, "Info file not saved!\r\n");
if (!(success = export_save_shops(zrnum)))
@@ -363,18 +373,34 @@ ACMD(do_export_zone)
return;
}
/* Make sure the name of the zone doesn't make the filename illegal. */
f = fix_filename(zone_name);
fix_filename(zone_name, fixed_file_name, sizeof(fixed_file_name));
/* Remove the old copy. */
snprintf(sysbuf, MAX_INPUT_LENGTH, "rm %s%s.tar.gz", path, f);
snprintf(sysbuf, sizeof(sysbuf), "rm %s%s.tar.gz", path, fixed_file_name);
errorcode = system(sysbuf);
if (errorcode) {
send_to_char(ch, "Failed to delete previous zip file. This is usually benign.\r\n");
}
/* Tar the new copy. */
snprintf(sysbuf, MAX_INPUT_LENGTH, "tar -cf %s%s.tar %sqq.info %sqq.wld %sqq.zon %sqq.mob %sqq.obj %sqq.trg %sqq.shp", path, f, path, path, path, path, path, path, path);
snprintf(sysbuf, sizeof(sysbuf), "tar -cf %s%s.tar %sqq.info %sqq.wld %sqq.zon %sqq.mob %sqq.obj %sqq.trg %sqq.shp", path, fixed_file_name, path, path, path, path, path, path, path);
errorcode = system(sysbuf);
if (errorcode) {
send_to_char(ch, "Failed to tar files.\r\n");
return;
}
/* Gzip it. */
snprintf(sysbuf, MAX_INPUT_LENGTH, "gzip %s%s.tar", path, f);
snprintf(sysbuf, sizeof(sysbuf), "gzip %s%s.tar", path, fixed_file_name);
errorcode = system(sysbuf);
if (errorcode) {
send_to_char(ch, "Failed to gzip tar file.\r\n");
return;
}
send_to_char(ch, "Files tar'ed to \"%s%s.tar.gz\"\r\n", path, f);
send_to_char(ch, "Files tar'ed to \"%s%s.tar.gz\"\r\n", path, fixed_file_name);
#endif /* platform specific part */
}
static int export_info_file(zone_rnum zrnum)