1 /* $NetBSD: getoldopt.c,v 1.21 2005/06/05 19:08:28 chs Exp $ */
4 * Plug-compatible replacement for getopt() for parsing tar-like
5 * arguments. If the first argument begins with "-", it uses getopt;
6 * otherwise, it uses the old rules used by tar, dump, and ps.
8 * Written 25 August 1985 by John Gilmore (ihnp4!hoptoad!gnu) and placed
9 * in the Public Domain for your edification and enjoyment.
12 #if HAVE_NBTOOL_CONFIG_H
13 #include "nbtool_config.h"
16 #include <sys/cdefs.h>
18 __RCSID("$NetBSD: getoldopt.c,v 1.21 2005/06/05 19:08:28 chs Exp $");
21 #if HAVE_NBTOOL_CONFIG_H
22 #include "compat_getopt.h"
35 getoldopt(int argc
, char **argv
, const char *optstring
,
36 struct option
*longopts
, int *idx
)
38 static char *key
; /* Points to next keyletter */
39 static char use_getopt
; /* !=0 if argv[1][0] was '-' */
45 if (key
== NULL
) { /* First time */
46 if (argc
< 2) return -1;
63 if (longopts
!= NULL
) {
64 return getopt_long(argc
, argv
, optstring
,
67 return getopt(argc
, argv
, optstring
);
71 place
= strchr(optstring
, c
);
73 if (place
== NULL
|| c
== ':') {
74 fprintf(stderr
, "%s: unknown option %c\n", argv
[0], c
);
81 optarg
= argv
[optind
];
84 fprintf(stderr
, "%s: %c argument missing\n",