100 inStream = Argc = Aloc = 0; vopts = curopt = 0; endopts = 1;
101 optp = 0; eDest = erp;
102 epfx = strdup(etxt ? etxt :
"");
106 if (StdOpts && *StdOpts ==
':') {missarg =
':'; StdOpts++;}
108 vopts = strdup(StdOpts ? StdOpts :
"");
115 {minl = va_arg(ap,
int);
116 optm = va_arg(ap,
const char *);
118 optw = va_arg(ap,
const char *);
153 char optbuff[3] = {
'-',
'x',
'\0'}, *optspec, *arglist, *optname = 0;
157 if (endopts)
return -1;
161 if (curopt && *curopt) curopt++;
163 {
if ((optname = curopt = arg_stream.GetToken(&arglist)))
164 {
if (*curopt !=
'-') {arg_stream.RetToken(); curopt = 0;}
168 else if (Aloc >= Argc || *Argv[Aloc] !=
'-') curopt = 0;
169 else optname = curopt = Argv[Aloc++]+1;
173 if (!curopt) {endopts = 1;
return -1;}
175 {
if (eDest) eDest->Say(epfx,
"Option letter missing after '-'.");
182 if (*curopt ==
':' || *curopt ==
'.') optspec = 0;
183 else {
if (optp) {optspec = *optp%curopt; curopt = 0;}
184 else {optspec = index(vopts,
int(*curopt));
185 optbuff[1] = *curopt; optname = optbuff; curopt++;
191 {sprintf(buff,
"Invalid option, '%s'.", optname);
192 eDest->Say(epfx, buff);
200 if (optspec[1] !=
':' && optspec[1] !=
'.')
return *optspec;
204 if (inStream)
argval = arg_stream.GetToken();
205 else argval = (Aloc < Argc ? Argv[Aloc++] : 0);
211 else if (*
argval !=
'-')
return *optspec;
216 if (optspec[1] ==
'.')
218 {
if (inStream) arg_stream.RetToken();
227 if (eDest) eDest->Say(epfx,
"Value not specified for '", optname,
"'.");