| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include <sys/types.h> |
| 16 |
#include <sys/stat.h> |
| 17 |
#include <stdio.h> |
| 18 |
#include <string.h> |
| 19 |
#if HAVE_STRINGS_H |
| 20 |
#include <strings.h> |
| 21 |
#endif |
| 22 |
#include <unistd.h> |
| 23 |
|
| 24 |
#include "pax.h" |
| 25 |
#include "extern.h" |
| 26 |
|
| 27 |
__RCSID("$MirOS: src/bin/pax/getoldopt.c,v 1.7 2019/02/10 22:00:06 tg Exp $"); |
| 28 |
|
| 29 |
int |
| 30 |
getoldopt(int argc, char **argv, const char *optstring) |
| 31 |
{ |
| 32 |
static char *key; |
| 33 |
static char use_getopt; |
| 34 |
char c; |
| 35 |
char *place; |
| 36 |
|
| 37 |
optarg = NULL; |
| 38 |
|
| 39 |
if (key == NULL) { |
| 40 |
if (argc < 2) |
| 41 |
return (-1); |
| 42 |
key = argv[1]; |
| 43 |
if (*key == '-') |
| 44 |
use_getopt++; |
| 45 |
else |
| 46 |
optind = 2; |
| 47 |
} |
| 48 |
|
| 49 |
if (use_getopt) |
| 50 |
return (getopt(argc, argv, optstring)); |
| 51 |
|
| 52 |
c = *key++; |
| 53 |
if (c == '\0') { |
| 54 |
key--; |
| 55 |
return (-1); |
| 56 |
} |
| 57 |
place = strchr(optstring, c); |
| 58 |
|
| 59 |
if (place == NULL || c == ':') { |
| 60 |
fprintf(stderr, "%s: unknown option %c\n", argv[0], c); |
| 61 |
return ('?'); |
| 62 |
} |
| 63 |
|
| 64 |
place++; |
| 65 |
if (*place == ':') { |
| 66 |
if (optind < argc) { |
| 67 |
optarg = argv[optind]; |
| 68 |
optind++; |
| 69 |
} else { |
| 70 |
fprintf(stderr, "%s: %c argument missing\n", |
| 71 |
argv[0], c); |
| 72 |
return ('?'); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
return (c); |
| 77 |
} |