00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <sys/types.h>
00015 #include <sys/stat.h>
00016 #include <stdio.h>
00017 #include <string.h>
00018 #include <unistd.h>
00019
00020 #include "pax.h"
00021 #include "extern.h"
00022
00023 int
00024 getoldopt(int argc, char **argv, const char *optstring)
00025 {
00026 static char *key;
00027 static char use_getopt;
00028 char c;
00029 char *place;
00030
00031 optarg = NULL;
00032
00033 if (key == NULL) {
00034 if (argc < 2) return EOF;
00035 key = argv[1];
00036 if (*key == '-')
00037 use_getopt++;
00038 else
00039 optind = 2;
00040 }
00041
00042 if (use_getopt)
00043 return getopt(argc, argv, optstring);
00044
00045 c = *key++;
00046 if (c == '\0') {
00047 key--;
00048 return EOF;
00049 }
00050 place = strchr(optstring, c);
00051
00052 if (place == NULL || c == ':') {
00053 fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
00054 return('?');
00055 }
00056
00057 place++;
00058 if (*place == ':') {
00059 if (optind < argc) {
00060 optarg = argv[optind];
00061 optind++;
00062 } else {
00063 fprintf(stderr, "%s: %c argument missing\n",
00064 argv[0], c);
00065 return('?');
00066 }
00067 }
00068
00069 return(c);
00070 }