This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: getopt.c 138 2008-03-17 13:57:46Z baconevi $
|
||||
* $Id: getopt.c 142 2008-03-18 06:29:25Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -40,19 +40,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if 0
|
||||
/* declarations to provide consistent linkage */
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
extern int opterr;
|
||||
|
||||
int opterr = 1, /* if error message should be printed */
|
||||
optind = 1, /* index into parent argv vector */
|
||||
optopt, /* character checked for validity */
|
||||
optreset; /* reset getopt */
|
||||
char *optarg; /* argument associated with option */
|
||||
#endif
|
||||
|
||||
#define BADCH ASE_T('?')
|
||||
#define BADARG ASE_T(':')
|
||||
#define EMSG ASE_T("")
|
||||
@ -67,7 +54,11 @@ ase_cint_t ase_getopt (int argc, ase_char_t* const* argv, ase_opt_t* opt)
|
||||
{
|
||||
ase_char_t* oli; /* option letter list index */
|
||||
|
||||
if (place == ASE_NULL) place = EMSG;
|
||||
if (place == ASE_NULL)
|
||||
{
|
||||
place = EMSG;
|
||||
optind = 1;
|
||||
}
|
||||
|
||||
if (*place == ASE_T('\0'))
|
||||
{
|
||||
@ -85,7 +76,7 @@ ase_cint_t ase_getopt (int argc, ase_char_t* const* argv, ase_opt_t* opt)
|
||||
place = EMSG;
|
||||
return ASE_CHAR_EOF;
|
||||
}
|
||||
} /* option letter okay? */
|
||||
} /* option letter okay? */
|
||||
|
||||
if ((optopt = *place++) == ASE_T(':') ||
|
||||
(oli = ase_strchr(optstr, optopt)) == ASE_NULL)
|
||||
@ -96,11 +87,6 @@ ase_cint_t ase_getopt (int argc, ase_char_t* const* argv, ase_opt_t* opt)
|
||||
*/
|
||||
if (optopt == (int)'-') return ASE_CHAR_EOF;
|
||||
if (*place == ASE_T('\0')) ++optind;
|
||||
#if 0
|
||||
if (opterr && *optstr != ASE_T(':'))
|
||||
(void)fprintf(stderr,
|
||||
"%s: illegal option -- %c\n", __FILE__, optopt);
|
||||
#endif
|
||||
return BADCH;
|
||||
}
|
||||
|
||||
@ -114,25 +100,24 @@ ase_cint_t ase_getopt (int argc, ase_char_t* const* argv, ase_opt_t* opt)
|
||||
{
|
||||
/* need an argument */
|
||||
|
||||
if (*place != ASE_T('\0')) optarg = place; /* no white space */
|
||||
if (*place != ASE_T('\0'))
|
||||
{
|
||||
/* no white space */
|
||||
optarg = place;
|
||||
}
|
||||
else if (argc <= ++optind)
|
||||
{
|
||||
/* no arg */
|
||||
place = EMSG;
|
||||
if (*optstr == ASE_T(':')) return BADARG;
|
||||
#if 0
|
||||
if (opterr)
|
||||
(void)fprintf(stderr,
|
||||
"%s: option requires an argument -- %c\n",
|
||||
__FILE__, optopt);
|
||||
#endif
|
||||
return BADCH;
|
||||
/*if (*optstr == ASE_T(':'))*/ return BADARG;
|
||||
/*return BADCH;*/
|
||||
}
|
||||
else
|
||||
{
|
||||
/* white space */
|
||||
optarg = argv[optind];
|
||||
}
|
||||
|
||||
place = EMSG;
|
||||
++optind;
|
||||
}
|
||||
|
Reference in New Issue
Block a user