X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Ftar.c;h=68c8801b1dd07be662e6e16d5ab26058f832a406;hb=c930802f313aa29b479edc6f9782897db608ce64;hp=84b89034640d2e4b4339f02ebe89c58c7d19121f;hpb=0680ad4d42e23f09d19b464143f8f2d0127d88cd;p=chaz%2Ftar diff --git a/src/tar.c b/src/tar.c index 84b8903..68c8801 100644 --- a/src/tar.c +++ b/src/tar.c @@ -41,10 +41,11 @@ #include #include +#include #include #include -#include #include +#include #include #include #include @@ -320,17 +321,16 @@ enum const char *argp_program_version = "tar (" PACKAGE_NAME ") " VERSION; const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; -static char const doc0[] = N_("\ +static char const doc[] = N_("\ GNU `tar' saves many files together into a single tape or disk archive, \ and can restore individual files from the archive.\n\ \n\ Examples:\n\ tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.\n\ tar -tvf archive.tar # List all files in archive.tar verbosely.\n\ - tar -xf archive.tar # Extract all files from archive.tar.\n\ -"); -static char const doc1[] = N_("\ -The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\ + tar -xf archive.tar # Extract all files from archive.tar.\n") +"\v" +N_("The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\ The version control may be set with --backup or VERSION_CONTROL, values are:\n\n\ none, off never make backups\n\ t, numbered make numbered backups\n\ @@ -407,7 +407,7 @@ static struct argp_option options[] = { #define GRID 30 {NULL, 0, NULL, 0, - N_("Overwrite control:"), GRID+1 }, + N_("Overwrite control:"), GRID }, {"verify", 'W', 0, 0, N_("attempt to verify the archive after writing it"), GRID+1 }, @@ -489,7 +489,7 @@ static struct argp_option options[] = { #define GRID 60 {NULL, 0, NULL, 0, - N_("Device selection and switching:\n"), GRID+1 }, + N_("Device selection and switching:"), GRID }, {"file", 'f', N_("ARCHIVE"), 0, N_("use archive file or device ARCHIVE"), GRID+1 }, @@ -528,7 +528,7 @@ static struct argp_option options[] = { #define GRID 70 {NULL, 0, NULL, 0, - N_("Device blocking:"), GRID+1 }, + N_("Device blocking:"), GRID }, {"blocking-factor", 'b', N_("BLOCKS"), 0, N_("BLOCKS x 512 bytes per record"), GRID+1 }, @@ -954,7 +954,8 @@ enum read_file_list_state /* Result of reading file name from the list file */ { file_list_success, /* OK, name read successfully */ file_list_end, /* End of list file */ - file_list_zero /* Zero separator encountered where it should not */ + file_list_zero, /* Zero separator encountered where it should not */ + file_list_skip /* Empty (zero-length) entry encountered, skip it */ }; /* Read from FP a sequence of characters up to FILENAME_TERMINATOR and put them @@ -972,13 +973,15 @@ read_name_from_file (FILE *fp, struct obstack *stk) { /* We have read a zero separator. The file possibly is zero-separated */ - /* FATAL_ERROR((0, 0, N_("file name contains null character"))); */ return file_list_zero; } obstack_1grow (stk, c); counter++; } + if (counter == 0 && c != EOF) + return file_list_skip; + obstack_1grow (stk, 0); return (counter == 0 && c == EOF) ? file_list_end : file_list_success; @@ -1059,31 +1062,42 @@ update_argv (const char *filename, struct argp_state *state) open_fatal (filename); } - while ((read_state = read_name_from_file (fp, &argv_stk)) == file_list_success) - count++; - - if (read_state == file_list_zero) + while ((read_state = read_name_from_file (fp, &argv_stk)) != file_list_end) { - size_t size; + switch (read_state) + { + case file_list_success: + count++; + break; - WARN ((0, 0, N_("%s: file name read contains nul character"), - quotearg_colon (filename))); + case file_list_end: /* won't happen, just to pacify gcc */ + break; - /* Prepare new stack contents */ - size = obstack_object_size (&argv_stk); - p = obstack_finish (&argv_stk); - for (; size > 0; size--, p++) - if (*p) - obstack_1grow (&argv_stk, *p); - else - obstack_1grow (&argv_stk, '\n'); - obstack_1grow (&argv_stk, 0); - count = 1; - - /* Read rest of files using new filename terminator */ - filename_terminator = 0; - while (read_name_from_file (fp, &argv_stk) == file_list_success) - count++; + case file_list_zero: + { + size_t size; + + WARN ((0, 0, N_("%s: file name read contains nul character"), + quotearg_colon (filename))); + + /* Prepare new stack contents */ + size = obstack_object_size (&argv_stk); + p = obstack_finish (&argv_stk); + for (; size > 0; size--, p++) + if (*p) + obstack_1grow (&argv_stk, *p); + else + obstack_1grow (&argv_stk, '\n'); + obstack_1grow (&argv_stk, 0); + count = 1; + /* Read rest of files using new filename terminator */ + filename_terminator = 0; + break; + } + + case file_list_skip: + break; + } } if (!is_stdin) @@ -1862,27 +1876,12 @@ static struct argp argp = { options, parse_opt, N_("[FILE]..."), - NULL, + doc, NULL, NULL, NULL }; -/* Initialize the argp documentation. gettext 0.15 dislikes doc - strings containing '\v', so insert '\v' after translation. */ - -static void -initialize_argp_doc (void) -{ - char const *xdoc0 = _(doc0); size_t xlen0 = strlen (xdoc0); - char const *xdoc1 = _(doc1); size_t xlen1 = strlen (xdoc1); - char *doc = xmalloc (xlen0 + 1 + xlen1 + 1); - memcpy (doc, xdoc0, xlen0); - doc[xlen0] = '\v'; - memcpy (doc + xlen0 + 1, doc1, xlen1 + 1);; - argp.doc = doc; -} - void usage (int status) { @@ -1939,8 +1938,6 @@ decode_options (int argc, char **argv) owner_option = -1; group_option = -1; - initialize_argp_doc (); - /* Convert old-style tar call by exploding option element and rearranging options accordingly. */ @@ -2345,13 +2342,14 @@ main (int argc, char **argv) free (archive_name_array); name_term (); - if (stdlis == stdout) - close_stdout (); - if (exit_status == TAREXIT_FAILURE) error (0, 0, _("Error exit delayed from previous errors")); - if (ferror (stderr) || fclose (stderr) != 0) + + if (stdlis == stdout) + close_stdout (); + else if (ferror (stderr) || fclose (stderr) != 0) exit_status = TAREXIT_FAILURE; + return exit_status; }