|
Revision 2, 2.6 kB
(checked in by nextime, 2 years ago)
|
Initial import, branching from morphix svn
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
#if HAVE_CONFIG_H |
|---|
| 22 |
#include <config.h> |
|---|
| 23 |
#endif |
|---|
| 24 |
|
|---|
| 25 |
#if !HAVE_GETOPT |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
#define unconst(var, type) ((type)(var)) |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
#include <string.h> |
|---|
| 33 |
#include <stdio.h> |
|---|
| 34 |
|
|---|
| 35 |
int opterr = 1, optind = 1, optopt = 0; |
|---|
| 36 |
char *optarg = 0; |
|---|
| 37 |
|
|---|
| 38 |
#define BADCH (int)'?' |
|---|
| 39 |
#define EMSG "" |
|---|
| 40 |
|
|---|
| 41 |
int getopt(int nargc, char *const nargv[], const char *ostr) |
|---|
| 42 |
{ |
|---|
| 43 |
static const char *place = EMSG; |
|---|
| 44 |
char *oli; |
|---|
| 45 |
char *p; |
|---|
| 46 |
|
|---|
| 47 |
if (!*place) |
|---|
| 48 |
{ |
|---|
| 49 |
if (optind >= nargc || *(place = nargv[optind]) != '-') |
|---|
| 50 |
{ |
|---|
| 51 |
place = EMSG; |
|---|
| 52 |
return(EOF); |
|---|
| 53 |
} |
|---|
| 54 |
if (place[1] && *++place == '-') |
|---|
| 55 |
{ |
|---|
| 56 |
++optind; |
|---|
| 57 |
place = EMSG; |
|---|
| 58 |
return(EOF); |
|---|
| 59 |
} |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
if ((optopt = (int)*place++) == (int)':' |
|---|
| 63 |
|| !(oli = strchr(ostr, optopt))) |
|---|
| 64 |
{ |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
if (optopt == (int)'-') |
|---|
| 70 |
return EOF; |
|---|
| 71 |
if (!*place) |
|---|
| 72 |
++optind; |
|---|
| 73 |
if (opterr) |
|---|
| 74 |
{ |
|---|
| 75 |
if (!(p = strrchr(*nargv, '/'))) |
|---|
| 76 |
p = *nargv; |
|---|
| 77 |
else |
|---|
| 78 |
++p; |
|---|
| 79 |
fprintf(stderr, "%s: illegal option -- %c\n", p, optopt); |
|---|
| 80 |
} |
|---|
| 81 |
return BADCH; |
|---|
| 82 |
} |
|---|
| 83 |
if (*++oli != ':') |
|---|
| 84 |
{ |
|---|
| 85 |
optarg = NULL; |
|---|
| 86 |
if (!*place) |
|---|
| 87 |
++optind; |
|---|
| 88 |
} |
|---|
| 89 |
else |
|---|
| 90 |
{ |
|---|
| 91 |
if (*place) |
|---|
| 92 |
optarg = unconst(place, char *); |
|---|
| 93 |
else if (nargc <= ++optind) |
|---|
| 94 |
{ |
|---|
| 95 |
place = EMSG; |
|---|
| 96 |
if (!(p = strrchr(*nargv, '/'))) |
|---|
| 97 |
p = *nargv; |
|---|
| 98 |
else |
|---|
| 99 |
++p; |
|---|
| 100 |
if (opterr) |
|---|
| 101 |
fprintf(stderr, "%s: option requires an argument -- %c\n", p, optopt); |
|---|
| 102 |
return BADCH; |
|---|
| 103 |
} |
|---|
| 104 |
else |
|---|
| 105 |
optarg = nargv[optind]; |
|---|
| 106 |
place = EMSG; |
|---|
| 107 |
++optind; |
|---|
| 108 |
} |
|---|
| 109 |
return optopt; |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
#endif |
|---|
| 113 |
|
|---|