diff options
-rw-r--r-- | AUTHORS | 2 | ||||
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | THANKS | 1 | ||||
-rwxr-xr-x | bootstrap | 4 | ||||
-rw-r--r-- | gnulib.modules | 2 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/copyin.c | 6 | ||||
-rw-r--r-- | src/copyout.c | 7 | ||||
-rw-r--r-- | src/extern.h | 5 | ||||
-rw-r--r-- | src/global.c | 4 | ||||
-rw-r--r-- | src/main.c | 88 | ||||
-rw-r--r-- | src/mt.c | 283 | ||||
-rw-r--r-- | tests/version.at | 4 |
13 files changed, 192 insertions, 217 deletions
@@ -3,4 +3,4 @@ Authors of GNU cpio Phil Nelson <phil@cs.wwu.edu> David MacKenzie <djm@gnu.ai.mit.edu> John Oleynick <juo@klinzhai.rutgers.edu> -Sergey Poznyakoff <gray@mirddin.farlep.net>
\ No newline at end of file +Sergey Poznyakoff <gray@gnu.org>
\ No newline at end of file diff --git a/Makefile.am b/Makefile.am index d742d17..4931db1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,8 @@ AUTOMAKE_OPTIONS = gnits 1.8 dist-bzip2 std-options SUBDIRS = doc headers gnu lib rmt src po tests +AM_DISTCHECK_CONFIGURE_FLAGS = --enable-mt + gen_start_date = 2008-03-07 prev_change_log = ChangeLog.cvs changelog_dir = . @@ -19,6 +19,7 @@ Ladislav Michnovič <ladislav.michnovic@gmail.com> Matthew Braithwaite <mab@cnet.com> Mike Frysinger <vapier@gentoo.org> Mitsuru Chinen <mchinen@yamato.ibm.com> +Peter Breitenlohner <peb@mppmu.mpg.de> Peter Vrabec <pvrabec@redhat.com> Robert Millan <rmh@aybabtu.com> @@ -742,4 +742,8 @@ if test $with_gettext = yes; then fi fi +echo "$0: patching Makefile.in" +mv Makefile.in Makefile.in~ +sed 's/\$(DISTCHECK_CONFIGURE_FLAGS)/$(AM_DISTCHECK_CONFIGURE_FLAGS) $(DISTCHECK_CONFIGURE_FLAGS)/' Makefile.in~ > Makefile.in + echo "$0: done. Now you can run './configure'." diff --git a/gnulib.modules b/gnulib.modules index d7bf055..335cd2a 100644 --- a/gnulib.modules +++ b/gnulib.modules @@ -4,6 +4,7 @@ alloca argmatch argp +argp-version-etc dirname error fileblocks @@ -15,6 +16,7 @@ gitlog-to-changelog hash inttypes lchown +progname safe-read savedir stdbool diff --git a/src/Makefile.am b/src/Makefile.am index 70b2563..63f99d2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -50,4 +50,3 @@ noinst_HEADERS =\ LDADD=../lib/libpax.a ../gnu/libgnu.a @INTLLIBS@ -mt.o main.o: ../lib/rmt-command.h diff --git a/src/copyin.c b/src/copyin.c index 70d507c..59483da 100644 --- a/src/copyin.c +++ b/src/copyin.c @@ -1,6 +1,6 @@ /* copyin.c - extract or list a cpio archive - Copyright (C) 1990,1991,1992,2001,2002,2003,2004, - 2005, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 1990, 1991, 1992, 2001, 2002, 2003, 2004, + 2005, 2006, 2007, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -843,7 +843,7 @@ long_format (struct cpio_file_stat *file_hdr, char *link_name) } tbuf[16] = '\0'; - printf ("%s %3lu ", mbuf, file_hdr->c_nlink); + printf ("%s %3lu ", mbuf, (unsigned long) file_hdr->c_nlink); if (numeric_uid) printf ("%-8u %-8u ", (unsigned int) file_hdr->c_uid, diff --git a/src/copyout.c b/src/copyout.c index 98f3895..dd9bac2 100644 --- a/src/copyout.c +++ b/src/copyout.c @@ -1,6 +1,6 @@ /* copyout.c - create a cpio archive Copyright (C) 1990, 1991, 1992, 2001, 2003, 2004, - 2006, 2007 Free Software Foundation, Inc. + 2006, 2007, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,10 +33,10 @@ /* Read FILE_SIZE bytes of FILE_NAME from IN_FILE_DES and compute and return a checksum for them. */ -static unsigned int +static unsigned long read_for_checksum (int in_file_des, int file_size, char *file_name) { - unsigned int crc; + unsigned long crc; char buf[BUFSIZ]; int bytes_left; int bytes_read; @@ -595,7 +595,6 @@ assign_string (char **pvar, char *value) void process_copy_out () { - int res; /* Result of functions. */ dynamic_string input_name; /* Name of file read from stdin. */ struct stat file_stat; /* Stat record for file. */ struct cpio_file_stat file_hdr; /* Output header information. */ diff --git a/src/extern.h b/src/extern.h index 4c4bf5c..a03508b 100644 --- a/src/extern.h +++ b/src/extern.h @@ -1,6 +1,6 @@ /* extern.h - External declarations for cpio. Requires system.h. Copyright (C) 1990, 1991, 1992, 2001, 2006, - 2007 Free Software Foundation, Inc. + 2007, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -75,7 +75,7 @@ extern char *new_media_message_after_number; extern int archive_des; extern char *archive_name; extern char *rsh_command_option; -extern unsigned int crc; +extern unsigned long crc; extern int delayed_seek_count; #ifdef DEBUG_CPIO extern int debug_flag; @@ -95,7 +95,6 @@ extern char input_is_special; extern char output_is_special; extern char input_is_seekable; extern char output_is_seekable; -extern char *program_name; extern int (*xstat) (); extern void (*copy_function) (); diff --git a/src/global.c b/src/global.c index 5c8a7fb..b700c17 100644 --- a/src/global.c +++ b/src/global.c @@ -1,6 +1,6 @@ /* global.c - global variables and initial values for cpio. Copyright (C) 1990, 1991, 1992, 2001, 2006, - 2007 Free Software Foundation, Inc. + 2007, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -144,7 +144,7 @@ char *archive_name = NULL; char *rsh_command_option = NULL; /* CRC checksum. */ -unsigned int crc; +unsigned long crc; /* Input and output buffers. */ char *input_buffer, *output_buffer; @@ -1,6 +1,6 @@ /* main.c - main program and argument processing for cpio. Copyright (C) 1990, 1991, 1992, 2001, 2003, 2004, 2005, 2006, - 2007 Free Software Foundation, Inc. + 2007, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,14 +20,14 @@ /* Written by Phil Nelson <phil@cs.wwu.edu>, David MacKenzie <djm@gnu.ai.mit.edu>, John Oleynick <juo@klinzhai.rutgers.edu>, - and Sergey Poznyakoff <gray@mirddin.farlep.net> */ + and Sergey Poznyakoff <gray@gnu.org> */ #include <system.h> #include <paxlib.h> #include <stdio.h> -#include <getopt.h> #include <argp.h> +#include <argp-version-etc.h> #include <sys/types.h> #include <sys/stat.h> @@ -35,6 +35,8 @@ # include <locale.h> #endif +#include <progname.h> + #include "filetypes.h" #include "cpiohdr.h" #include "dstring.h" @@ -63,7 +65,15 @@ enum cpio_options { VERSION_OPTION }; -const char *argp_program_version = "cpio (" PACKAGE_NAME ") " VERSION; +const char *program_authors[] = + { + "Phil Nelson", + "David MacKenzie", + "John Oleynick", + "Sergey Poznyakoff", + NULL + }; + const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; static char doc[] = N_("GNU `cpio' copies files to and from archives\n\ \n\ @@ -223,47 +233,12 @@ static struct argp_option options[] = { N_("Write files with large blocks of zeros as sparse files"), GRID+1 }, #undef GRID - /* ********** */ -#define GRID 800 - {NULL, 0, NULL, 0, - N_("Informative options:"), GRID }, - - {"help", '?', 0, 0, N_("Give this help list"), -1}, - {"usage", USAGE_OPTION, 0, 0, N_("Give a short usage message"), -1}, - {"license", LICENSE_OPTION, 0, 0, N_("Print license and exit"), -1}, - {"version", VERSION_OPTION, 0, 0, N_("Print program version"), -1}, - /* FIXME -V (--dot) conflicts with the default short option for - --version */ - {"HANG", HANG_OPTION, "SECS", OPTION_ARG_OPTIONAL | OPTION_HIDDEN, - N_("hang for SECS seconds (default 3600)"), 0}, -#undef GRID {0, 0, 0, 0} }; static char *input_archive_name = 0; static char *output_archive_name = 0; -static void -license () -{ - printf ("%s (%s) %s\n%s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION, - "Copyright (C) 2004 Free Software Foundation, Inc.\n"); - printf (_(" GNU cpio is free software; you can redistribute it and/or modify\n" - " it under the terms of the GNU General Public License as published by\n" - " the Free Software Foundation; either version 3 of the License, or\n" - " (at your option) any later version.\n" - "\n" - " GNU cpio is distributed in the hope that it will be useful,\n" - " but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - " GNU General Public License for more details.\n" - "\n" - " You should have received a copy of the GNU General Public License\n" - " along with GNU cpio; if not, write to the Free Software Foundation,\n" - " Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n\n")); - exit (0); -} - static int warn_control (char *arg) { @@ -305,7 +280,6 @@ warn_control (char *arg) static error_t parse_opt (int key, char *arg, struct argp_state *state) { - static volatile int _argp_hang; switch (key) { case '0': /* Read null-terminated filenames. */ @@ -550,29 +524,6 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg); to_stdout_option = true; break; - case HANG_OPTION: - _argp_hang = atoi (arg ? arg : "3600"); - while (_argp_hang-- > 0) - sleep (1); - break; - - case '?': - argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP); - break; - - case USAGE_OPTION: - argp_state_help (state, state->out_stream, - ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK); - break; - - case VERSION_OPTION: - fprintf (state->out_stream, "%s\n", argp_program_version); - exit (0); - - case LICENSE_OPTION: - license (); - break; - default: return ARGP_ERR_UNKNOWN; } @@ -599,14 +550,9 @@ process_args (int argc, char *argv[]) void (*copy_out) (); int index; - if (argc < 2) - error (PAXEXIT_FAILURE, 0, - _("You must specify one of -oipt options.\nTry `%s --help' or `%s --usage' for more information.\n"), - program_name, program_name); - xstat = lstat; - if (argp_parse (&argp, argc, argv, ARGP_IN_ORDER|ARGP_NO_HELP, &index, NULL)) + if (argp_parse (&argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) exit (PAXEXIT_FAILURE); /* Do error checking and look at other args. */ @@ -787,8 +733,8 @@ main (int argc, char *argv[]) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - program_name = argv[0]; - + set_program_name (argv[0]); + argp_version_setup ("cpio", program_authors); process_args (argc, argv); initialize_buffers (); @@ -69,46 +69,39 @@ #include <sys/file.h> #include <fcntl.h> #include <errno.h> -#include <getopt.h> #include <stdbool.h> +#include <argp.h> +#include <argp-version-etc.h> +#include <progname.h> #ifdef HAVE_LOCALE_H -# include <locale.h> +# include <locale.h> #endif #include <rmt-command.h> -#if defined(HAVE_UNISTD_H) -#include <unistd.h> -#endif #include <rmt.h> -#if defined(HAVE_STRING_H) || defined(STDC_HEADERS) -#include <string.h> -#else -#include <strings.h> -#endif - -#if defined(HAVE_STDLIB_H) -# include <stdlib.h> -#endif +#include <argmatch.h> +#include <paxlib.h> +#include "configmake.h" -#if !HAVE_DECL_ERRNO -extern int errno; -#endif -#if !HAVE_DECL_GETENV -char *getenv (); -#endif -#if !HAVE_DECL_ATOI -int atoi (); -#endif -#if !HAVE_DECL_EXIT -void exit (); -#endif +#define MT_EXIT_SUCCESS 0 +#define MT_EXIT_INVOP 1 +#define MT_EXIT_FAILURE 2 -char *opnames[] = +char const * const opnames[] = { - "eof", "weof", "fsf", "bsf", "fsr", "bsr", - "rewind", "offline", "rewoffl", "eject", "status", + "eof", + "weof", + "fsf", + "bsf", + "fsr", + "bsr", + "rewind", + "offline", + "rewoffl", + "eject", + "status", #ifdef MTBSFM "bsfm", #endif @@ -134,8 +127,17 @@ char *opnames[] = #define MTASF 600 /* Random unused number. */ short operations[] = { - MTWEOF, MTWEOF, MTFSF, MTBSF, MTFSR, MTBSR, - MTREW, MTOFFL, MTOFFL, MTOFFL, MTNOP, + MTWEOF, + MTWEOF, + MTFSF, + MTBSF, + MTFSR, + MTBSR, + MTREW, + MTOFFL, + MTOFFL, + MTOFFL, + MTNOP, #ifdef MTBSFM MTBSFM, #endif @@ -155,20 +157,105 @@ short operations[] = #ifdef MTSEEK MTSEEK, #endif - 0 }; -struct option longopts[] = -{ - {"file", 1, NULL, 'f'}, - {"rsh-command", 1, NULL, 1}, - {"version", 0, NULL, 'V'}, - {"help", 0, NULL, 'H'}, - {NULL, 0, NULL, 0} +ARGMATCH_VERIFY (opnames, operations); + +const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; +static char doc[] = N_("control magnetic tape drive operation"); +const char *program_authors[] = + { + "David MacKenzie", + "Sergey Poznyakoff", + NULL + }; + +enum + { + RSH_COMMAND_OPTION = 256 + }; + +static struct argp_option options[] = { + { "file", 'f', N_("DEVICE"), 0, + N_("use device as the file name of the tape drive to operate on") }, + { "rsh-command", RSH_COMMAND_OPTION, N_("COMMAND"), 0, + N_("use remote COMMAND instead of rsh") }, + { NULL } }; -/* The name this program was run with. */ -char *program_name; +char *tapedev; /* tape device */ +char *rsh_command_option = NULL; /* rsh command */ +short operation; /* operation code */ +int count = 1; /* count */ + +int argcnt = 0; /* number of command line arguments + processed so far */ + +static error_t +parse_opt (int key, char *arg, struct argp_state *state) +{ + switch (key) + { + case ARGP_KEY_ARG: + switch (argcnt++) + { + case 0: + operation = XARGMATCH (N_("operation"), arg, opnames, operations); + break; + + case 1: + { + char *p; + long val = strtol (arg, &p, 0); + if (*p || (count = val) != count) + error (MT_EXIT_INVOP, 0, _("invalid count value")); + } + break; + + default: + argp_usage (state); + } + break; + + case ARGP_KEY_FINI: + if (argcnt == 0) + argp_usage (state); + if (tapedev == NULL) + { + tapedev = getenv ("TAPE"); + if (tapedev == NULL) +#ifdef DEFTAPE /* From sys/mtio.h. */ + tapedev = DEFTAPE; +#else + error (MT_EXIT_INVOP, 0, _("no tape device specified")); +#endif + } + break; + + case 'f': + case 't': + tapedev = arg; + break; + + case RSH_COMMAND_OPTION: + rsh_command_option = arg; + break; + + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +static struct argp argp = { + options, + parse_opt, + N_("operation [count]"), + doc, + NULL, + NULL, + NULL +}; void check_type (char *dev, int desc) @@ -180,8 +267,9 @@ check_type (char *dev, int desc) if (fstat (desc, &stats) == -1) stat_error (dev); if ((stats.st_mode & S_IFMT) != S_IFCHR) - error (1, 0, _("%s is not a character special file"), dev); + error (MT_EXIT_INVOP, 0, _("%s is not a character special file"), dev); } + void perform_operation (char *dev, int desc, short op, int count) { @@ -189,11 +277,8 @@ perform_operation (char *dev, int desc, short op, int count) control.mt_op = op; control.mt_count = count; - /* Debian hack: The rmtioctl function returns -1 in case of an - error, not 0. This bug has been reported to - "bug-gnu-utils@prep.ai.mit.edu". (96/7/10) -BEM */ if (rmtioctl (desc, MTIOCTOP, (char*)&control) == -1) - error (2, errno, _("%s: rmtioctl failed"), dev); + error (MT_EXIT_FAILURE, errno, _("%s: rmtioctl failed"), dev); } void @@ -202,7 +287,7 @@ print_status (char *dev, int desc) struct mtget status; if (rmtioctl (desc, MTIOCGET, (char*)&status) == -1) - error (2, errno, _("%s: rmtioctl failed"), dev); + error (MT_EXIT_FAILURE, errno, _("%s: rmtioctl failed"), dev); printf ("drive type = %d\n", (int) status.mt_type); #if defined(hpux) || defined(__hpux) @@ -220,104 +305,42 @@ print_status (char *dev, int desc) } void -usage (FILE *fp,int status) +fatal_exit () { - fprintf (fp, _("\ -Usage: %s [-V] [-f device] [--file=device] [--rsh-command=command]\n\ -\t[--help] [--version] operation [count]\n"), - program_name); - exit (status); + exit (MT_EXIT_INVOP); } int main (int argc, char **argv) { - short operation; - int count; - char *tapedev; int tapedesc; - int i; - char *rsh_command_option = NULL; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - program_name = argv[0]; - tapedev = NULL; - count = 1; - - /* Debian hack: Fixed a bug in the -V flag. This bug has been - reported to "bug-gnu-utils@prep.ai.mit.edu". -BEM */ - while ((i = getopt_long (argc, argv, "f:t:VH", longopts, (int *) 0)) != -1) + set_program_name (argv[0]); + argp_version_setup ("mt", program_authors); + argmatch_die = fatal_exit; + argp_err_exit_status = MT_EXIT_INVOP; + if (argp_parse (&argp, argc, argv, ARGP_IN_ORDER, NULL, NULL)) + exit (MT_EXIT_INVOP); + + switch (operation) { - switch (i) - { - case 'f': - case 't': - tapedev = optarg; - break; - - case 1: - rsh_command_option = optarg; - break; - - case 'V': - printf ("mt (%s)\n", PACKAGE_STRING); - exit (0); - break; - - case 'H': - default: - usage (stdout, 0); - } - } - - if (optind == argc) - usage (stderr, 1); - - i = argmatch (argv[optind], opnames); - if (i < 0) - { - argmatch_invalid ("tape operation", argv[optind], i); - exit (1); - } - operation = operations[i]; - - if (++optind < argc) - /* Debian hack: Replaced the atoi function call with strtol so - that hexidecimal values can be used for the count parameter. - This bug has been reported to "bug-gnu-utils@prep.ai.mit.edu". - (97/12/5) -BEM */ -#if defined(STDC_HEADERS) - count = (int) strtol (argv[optind], NULL, 0); -#else - count = atoi (argv[optind]); + case MTWEOF: +#ifdef MTERASE + case MTERASE: #endif - if (++optind < argc) - usage (stderr, 1); + tapedesc = rmtopen (tapedev, O_WRONLY, 0, rsh_command_option); + break; - if (tapedev == NULL) - { - tapedev = getenv ("TAPE"); - if (tapedev == NULL) -#ifdef DEFTAPE /* From sys/mtio.h. */ - tapedev = DEFTAPE; -#else - error (1, 0, _("no tape device specified")); -#endif + default: + tapedesc = rmtopen (tapedev, O_RDONLY, 0, rsh_command_option); } - - if ( (operation == MTWEOF) -#ifdef MTERASE - || (operation == MTERASE) -#endif - ) - tapedesc = rmtopen (tapedev, O_WRONLY, 0, rsh_command_option); - else - tapedesc = rmtopen (tapedev, O_RDONLY, 0, rsh_command_option); + if (tapedesc == -1) - error (1, errno, _("%s: rmtopen failed"), tapedev); + error (MT_EXIT_INVOP, errno, _("%s: rmtopen failed"), tapedev); check_type (tapedev, tapedesc); if (operation == MTASF) @@ -330,8 +353,8 @@ main (int argc, char **argv) print_status (tapedev, tapedesc); if (rmtclose (tapedesc) == -1) - error (2, errno, _("%s: rmtclose failed"), tapedev); + error (MT_EXIT_FAILURE, errno, _("%s: rmtclose failed"), tapedev); - exit (0); + exit (MT_EXIT_SUCCESS); } diff --git a/tests/version.at b/tests/version.at index 08a9889..52a1773 100644 --- a/tests/version.at +++ b/tests/version.at @@ -1,5 +1,5 @@ # Checking cpio version -*- Autotest -*- -# Copyright (C) 2004, 2007 Free Software Foundation, Inc. +# Copyright (C) 2004, 2007, 2009 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ AT_SETUP([cpio version]) -AT_CHECK([cpio --version], +AT_CHECK([cpio --version | sed 1q], [0], [AT_PACKAGE_TARNAME (AT_PACKAGE_NAME) AT_PACKAGE_VERSION ], |