From db7225537987e771f26e73b50767a5ec331f6f39 Mon Sep 17 00:00:00 2001 From: grant Date: Mon, 30 Jun 2003 11:45:40 +0000 Subject: sync with -current: ---------------------------- revision 1.18 date: 2003/06/24 16:23:31; author: christos; state: Exp; lines: +44 -9 Revert previous change, and fix the -T problem differently: When the options of the second argument are exhausted, call the appropriate getopt() routine to process the rest of the arguments instead of finishing option processing. Fixes: tar cf - -T foo --- archivers/pax/files/getoldopt.c | 57 +++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 11 deletions(-) (limited to 'archivers/pax') diff --git a/archivers/pax/files/getoldopt.c b/archivers/pax/files/getoldopt.c index 9f595ff984c..21af930b81d 100644 --- a/archivers/pax/files/getoldopt.c +++ b/archivers/pax/files/getoldopt.c @@ -1,4 +1,4 @@ -/* $NetBSD: getoldopt.c,v 1.2 2003/06/23 13:39:01 grant Exp $ */ +/* $NetBSD: getoldopt.c,v 1.3 2003/06/30 11:45:40 grant Exp $ */ /* * Plug-compatible replacement for getopt() for parsing tar-like @@ -16,7 +16,7 @@ #endif #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: getoldopt.c,v 1.2 2003/06/23 13:39:01 grant Exp $"); +__RCSID("$NetBSD: getoldopt.c,v 1.3 2003/06/30 11:45:40 grant Exp $"); #endif /* not lint */ #include @@ -33,20 +33,55 @@ getoldopt(int argc, char **argv, const char *optstring, struct option *longopts, int *idx) { static char *key; /* Points to next keyletter */ - static char argv1[64]; + static char use_getopt; /* !=0 if argv[1][0] was '-' */ + char c; + char *place; + + optarg = NULL; if (key == NULL) { /* First time */ if (argc < 2) return -1; key = argv[1]; - if (*key != '-') - (void)snprintf(argv[1] = argv1, sizeof(argv1), "-%s", - key); + if (*key == '-') + use_getopt++; + else + optind = 2; + } + + if (!use_getopt) { + c = *key++; + if (c == '\0') { + key--; + use_getopt = 1; + } + } + if (use_getopt) { + if (longopts != NULL) { + return getopt_long(argc, argv, optstring, + longopts, idx); + } else { + return getopt(argc, argv, optstring); + } } - if (longopts != NULL) { - return getopt_long(argc, argv, optstring, - longopts, idx); - } else { - return getopt(argc, argv, optstring); + place = strchr(optstring, c); + + if (place == NULL || c == ':') { + fprintf(stderr, "%s: unknown option %c\n", argv[0], c); + return('?'); + } + + place++; + if (*place == ':') { + if (optind < argc) { + optarg = argv[optind]; + optind++; + } else { + fprintf(stderr, "%s: %c argument missing\n", + argv[0], c); + return('?'); + } } + + return(c); } -- cgit v1.2.3