summaryrefslogtreecommitdiff
path: root/archivers/pax
diff options
context:
space:
mode:
authorgrant <grant@pkgsrc.org>2003-06-30 11:45:40 +0000
committergrant <grant@pkgsrc.org>2003-06-30 11:45:40 +0000
commitdb7225537987e771f26e73b50767a5ec331f6f39 (patch)
tree98e02d8cde7683ae06c58f1339febdf51a7973d2 /archivers/pax
parent1fd933d3d9d742ed36d04c46017a1d93f4399d05 (diff)
downloadpkgsrc-db7225537987e771f26e73b50767a5ec331f6f39.tar.gz
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
Diffstat (limited to 'archivers/pax')
-rw-r--r--archivers/pax/files/getoldopt.c57
1 files changed, 46 insertions, 11 deletions
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 <getopt.h>
@@ -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);
}