2003-10-27 03:12:41 +03:00
|
|
|
/* $NetBSD: getoldopt.c,v 1.19 2003/10/27 00:12:41 lukem Exp $ */
|
1995-03-21 12:01:59 +03:00
|
|
|
|
1994-06-14 05:16:02 +04:00
|
|
|
/*
|
|
|
|
* Plug-compatible replacement for getopt() for parsing tar-like
|
|
|
|
* arguments. If the first argument begins with "-", it uses getopt;
|
|
|
|
* otherwise, it uses the old rules used by tar, dump, and ps.
|
|
|
|
*
|
|
|
|
* Written 25 August 1985 by John Gilmore (ihnp4!hoptoad!gnu) and placed
|
1996-05-17 05:07:47 +04:00
|
|
|
* in the Public Domain for your edification and enjoyment.
|
1994-06-14 05:16:02 +04:00
|
|
|
*/
|
|
|
|
|
2003-10-27 03:12:41 +03:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
1997-07-21 00:32:15 +04:00
|
|
|
#include <sys/cdefs.h>
|
2003-10-27 03:12:41 +03:00
|
|
|
#if !defined(lint)
|
|
|
|
__RCSID("$NetBSD: getoldopt.c,v 1.19 2003/10/27 00:12:41 lukem Exp $");
|
1994-06-14 05:16:02 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
2002-02-01 01:43:33 +03:00
|
|
|
#include <getopt.h>
|
1994-06-14 05:16:02 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2002-10-12 19:39:29 +04:00
|
|
|
#include <stdlib.h>
|
1994-12-04 10:11:37 +03:00
|
|
|
#include <unistd.h>
|
1997-07-21 00:32:15 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include "pax.h"
|
|
|
|
#include "extern.h"
|
1994-06-14 05:16:02 +04:00
|
|
|
|
|
|
|
int
|
2001-10-25 09:33:32 +04:00
|
|
|
getoldopt(int argc, char **argv, const char *optstring,
|
2001-11-03 15:49:31 +03:00
|
|
|
struct option *longopts, int *idx)
|
1994-06-14 05:16:02 +04:00
|
|
|
{
|
|
|
|
static char *key; /* Points to next keyletter */
|
2003-06-24 20:23:31 +04:00
|
|
|
static char use_getopt; /* !=0 if argv[1][0] was '-' */
|
|
|
|
char c;
|
|
|
|
char *place;
|
|
|
|
|
|
|
|
optarg = NULL;
|
2000-02-17 06:12:22 +03:00
|
|
|
|
1994-06-14 05:16:02 +04:00
|
|
|
if (key == NULL) { /* First time */
|
1997-09-14 18:54:32 +04:00
|
|
|
if (argc < 2) return -1;
|
1994-06-14 05:16:02 +04:00
|
|
|
key = argv[1];
|
2003-06-24 20:23:31 +04:00
|
|
|
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);
|
|
|
|
}
|
1994-06-14 05:16:02 +04:00
|
|
|
}
|
|
|
|
|
2003-06-24 20:23:31 +04:00
|
|
|
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('?');
|
|
|
|
}
|
1994-06-14 05:16:02 +04:00
|
|
|
}
|
2003-06-24 20:23:31 +04:00
|
|
|
|
|
|
|
return(c);
|
1994-06-14 05:16:02 +04:00
|
|
|
}
|