|
|
/* Position for first file in the shar file. */ | /* Position for first file in the shar file. */ |
static off_t first_file_position; | static off_t first_file_position; |
| |
/* Base for output filename. FIXME: No fix limit in GNU... */ |
/* Base for output filename. */ |
static char output_base_name[50]; |
static char *output_base_name; |
| |
/* Actual output filename. FIXME: No fix limit in GNU... */ |
/* Actual output filename. */ |
static char output_filename[50]; |
static char *output_filename; |
| |
static char *submitter_address = NULL; | static char *submitter_address = NULL; |
| |
|
|
static void | static void |
open_output () | open_output () |
{ | { |
sprintf (output_filename, output_base_name, ++part_number); |
size_t l; |
|
l = strlen(output_base_name) + 128; |
|
if (output_filename) |
|
free(output_filename); |
|
output_filename = xmalloc(l); |
|
snprintf(output_filename, l, output_base_name, ++part_number); |
output = fopen (output_filename, "w"); | output = fopen (output_filename, "w"); |
if (!output) | if (!output) |
error (EXIT_FAILURE, errno, _("Opening `%s'"), output_filename); | error (EXIT_FAILURE, errno, _("Opening `%s'"), output_filename); |
|
|
file_size_limit = lim; | file_size_limit = lim; |
} | } |
| |
|
|
|
char *parse_output_base_name(char *arg) |
|
{ |
|
int c; |
|
int hadarg = 0; |
|
char *fmt, *p; |
|
|
|
for (p = arg ; (c = *p++) != 0; ) |
|
{ |
|
if (c != '%') |
|
continue; |
|
c = *p++; |
|
if (c == '%') |
|
continue; |
|
if (hadarg) |
|
return 0; |
|
while (c != 0 && strchr("#0+- 'I", c) != 0) |
|
c = *p++; |
|
while (c != 0 && c >= '0' && c <= '9') |
|
c = *p++; |
|
if (c == '.') |
|
c = *p++; |
|
while (c != 0 && c >= '0' && c <= '9') |
|
c = *p++; |
|
if (c == 0 || strchr("diouxX", c) == 0) |
|
return 0; |
|
hadarg = 1; |
|
} |
|
fmt = xmalloc(strlen(arg) + (hadarg ? 1 : 6)); |
|
strcpy(fmt, arg); |
|
if (!hadarg) |
|
strcat(fmt, ".%02d"); |
|
return fmt; |
|
} |
|
|
|
|
/*---. | /*---. |
| ? | | | ? | |
`---*/ | `---*/ |
|
|
break; | break; |
| |
case 'o': | case 'o': |
strcpy (output_base_name, optarg); |
if (output_base_name) |
if (!strchr (output_base_name, '%')) |
free (output_base_name); |
strcat (output_base_name, ".%02d"); |
output_base_name = parse_output_base_name(optarg); |
|
if (!output_base_name) |
|
{ |
|
fprintf (stderr, _("illegal output prefix\n")); |
|
exit (EXIT_FAILURE); |
|
} |
part_number = 0; | part_number = 0; |
open_output (); | open_output (); |
break; | break; |