1996-05-17 05:07:47 +04:00
|
|
|
/* $NetBSD: getoldopt.c,v 1.4 1996/05/17 01:07:47 jtc 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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1996-05-17 05:07:47 +04:00
|
|
|
static char rcsid[] = "$NetBSD: getoldopt.c,v 1.4 1996/05/17 01:07:47 jtc Exp $";
|
1994-06-14 05:16:02 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1994-12-04 10:11:37 +03:00
|
|
|
#include <unistd.h>
|
1994-06-14 05:16:02 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
getoldopt(argc, argv, optstring)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
char *optstring;
|
|
|
|
{
|
|
|
|
extern char *optarg; /* Points to next arg */
|
|
|
|
extern int optind; /* Global argv index */
|
|
|
|
static char *key; /* Points to next keyletter */
|
|
|
|
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 EOF;
|
|
|
|
key = argv[1];
|
|
|
|
if (*key == '-')
|
|
|
|
use_getopt++;
|
|
|
|
else
|
|
|
|
optind = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_getopt)
|
|
|
|
return getopt(argc, argv, optstring);
|
|
|
|
|
|
|
|
c = *key++;
|
|
|
|
if (c == '\0') {
|
|
|
|
key--;
|
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|