X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fgetoldopt.c;h=27511b94b342197604b91c6d663484f8206e4223;hb=05ba292a938a6450cc0a4e1dbf778159de2f5868;hp=e7d45234f17608e3199a26cf7cc5a1dbcd9ff870;hpb=db2eecfb4b8b2de30a78f89a366ccb07a2fdb429;p=chaz%2Ftar diff --git a/src/getoldopt.c b/src/getoldopt.c index e7d4523..27511b9 100644 --- a/src/getoldopt.c +++ b/src/getoldopt.c @@ -28,60 +28,69 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include "getopt.h" #include "tar.h" /* For msg() declaration if STDC_MSG. */ +#include +#include "port.h" int -getoldopt(argc, argv, optstring, long_options, opt_index) - int argc; - char **argv; - char *optstring; - struct option *long_options; - int *opt_index; +getoldopt (argc, argv, optstring, long_options, opt_index) + int argc; + char **argv; + char *optstring; + struct option *long_options; + int *opt_index; { - 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 '-' */ - extern char *index(); - char c; - char *place; + 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 == '-') || (*key == '+')) - use_getopt++; - else - optind = 2; - } + optarg = NULL; - if (use_getopt) - return getopt_long(argc, argv, optstring, - long_options, opt_index); + if (key == NULL) + { /* First time */ + if (argc < 2) + return EOF; + key = argv[1]; + if ((*key == '-') || (*key == '+')) + use_getopt++; + else + optind = 2; + } - c = *key++; - if (c == '\0') { - key--; - return EOF; - } - place = index(optstring, c); + if (use_getopt) + return getopt_long (argc, argv, optstring, + long_options, opt_index); - if (place == NULL || c == ':') { - msg("unknown option %c", c); - return('?'); - } + c = *key++; + if (c == '\0') + { + key--; + return EOF; + } + place = index (optstring, c); - place++; - if (*place == ':') { - if (optind < argc) { - optarg = argv[optind]; - optind++; - } else { - msg("%c argument missing", c); - return('?'); - } + if (place == NULL || c == ':') + { + msg ("unknown option %c", c); + return ('?'); + } + + place++; + if (*place == ':') + { + if (optind < argc) + { + optarg = argv[optind]; + optind++; + } + else + { + msg ("%c argument missing", c); + return ('?'); } + } - return(c); + return (c); }