1 /* $NetBSD: getoldopt.c,v 1.23 2012/08/09 11:05:59 christos 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.23 2012/08/09 11:05:59 christos Exp $");
21 #if HAVE_NBTOOL_CONFIG_H
22 #include "compat_getopt.h"
36 getoldopt(int argc
, char **argv
, const char *optstring
,
37 struct option
*longopts
, int *idx
)
39 static char *key
; /* Points to next keyletter */
40 static char use_getopt
; /* !=0 if argv[1][0] was '-' */
46 if (key
== NULL
) { /* First time */
47 if (argc
< 2) return -1;
64 if (longopts
!= NULL
) {
65 return getopt_long(argc
, argv
, optstring
,
68 return getopt(argc
, argv
, optstring
);
72 place
= strchr(optstring
, c
);
74 if (place
== NULL
|| c
== ':') {
75 fprintf(stderr
, "%s: unknown option %c\n", argv
[0], c
);
82 optarg
= argv
[optind
];
85 fprintf(stderr
, "%s: %c argument missing\n",