1 /* $OpenBSD: getoldopt.c,v 1.3 1997/09/01 18:29:52 deraadt Exp $ */
2 /* $NetBSD: getoldopt.c,v 1.3 1995/03/21 09:07:28 cgd Exp $ */
5 * Plug-compatible replacement for getopt() for parsing tar-like
6 * arguments. If the first argument begins with "-", it uses getopt;
7 * otherwise, it uses the old rules used by tar, dump, and ps.
9 * Written 25 August 1985 by John Gilmore (ihnp4!hoptoad!gnu) and placed
10 * in the Pubic Domain for your edification and enjoyment.
14 static char rcsid[] = "$OpenBSD: getoldopt.c,v 1.3 1997/09/01 18:29:52 deraadt Exp $";
22 getoldopt(argc, argv, optstring)
27 extern char *optarg; /* Points to next arg */
28 extern int optind; /* Global argv index */
29 static char *key; /* Points to next keyletter */
30 static char use_getopt; /* !=0 if argv[1][0] was '-' */
36 if (key == NULL) { /* First time */
37 if (argc < 2) return EOF;
46 return getopt(argc, argv, optstring);
53 place = strchr(optstring, c);
55 if (place == NULL || c == ':') {
56 fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
63 optarg = argv[optind];
66 fprintf(stderr, "%s: %c argument missing\n",