This commit is contained in:
parent
925bc6a30a
commit
fc76fa2967
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: getopt.c 135 2008-03-17 10:44:28Z baconevi $
|
||||
* $Id: getopt.c 137 2008-03-17 12:35:02Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -60,17 +60,16 @@ char *optarg; /* argument associated with option */
|
||||
#define optarg opt->arg
|
||||
#define optind opt->ind
|
||||
#define optopt opt->opt
|
||||
#define place opt->cur
|
||||
|
||||
ase_cint_t ase_getopt (int argc, ase_char_t* const *nargv, ase_opt_t* opt)
|
||||
ase_cint_t ase_getopt (int argc, ase_char_t* const* argv, ase_opt_t* opt)
|
||||
{
|
||||
static char *place = EMSG; /* option letter processing */
|
||||
ase_char_t* oli; /* option letter list index */
|
||||
|
||||
if (optreset || !*place)
|
||||
if (!*place)
|
||||
{
|
||||
/* update scanning pointer */
|
||||
optreset = 0;
|
||||
if (optind >= argc || *(place = nargv[optind]) != '-')
|
||||
if (optind >= argc || *(place = argv[optind]) != ASE_T('-'))
|
||||
{
|
||||
place = EMSG;
|
||||
return ASE_CHAR_EOF;
|
||||
@ -93,10 +92,12 @@ ase_cint_t ase_getopt (int argc, ase_char_t* const *nargv, ase_opt_t* opt)
|
||||
*/
|
||||
if (optopt == (int)'-') return ASE_CHAR_EOF;
|
||||
if (!*place) ++optind;
|
||||
#if 0
|
||||
if (opterr && *optstr != ASE_T(':'))
|
||||
(void)fprintf(stderr,
|
||||
"%s: illegal option -- %c\n", __FILE__, optopt);
|
||||
return ASE_CHAR_BADCH;
|
||||
#endif
|
||||
return BADCH;
|
||||
}
|
||||
|
||||
if (*++oli != ASE_T(':'))
|
||||
@ -115,16 +116,18 @@ ase_cint_t ase_getopt (int argc, ase_char_t* const *nargv, ase_opt_t* opt)
|
||||
/* 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;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* white space */
|
||||
optarg = nargv[optind];
|
||||
optarg = argv[optind];
|
||||
}
|
||||
place = EMSG;
|
||||
++optind;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: getopt.h 136 2008-03-17 12:23:56Z baconevi $
|
||||
* $Id: getopt.h 137 2008-03-17 12:35:02Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -24,13 +24,16 @@ struct ase_opt_t
|
||||
|
||||
/* input + output */
|
||||
int ind; /* index into parent argv vector */
|
||||
|
||||
/* internal */
|
||||
ase_char_t* cur;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ase_cint_t ase_getopt (int argc, ase_char_t* argv[], ase_opt_t* opt);
|
||||
ase_cint_t ase_getopt (int argc, ase_char_t* const* argv, ase_opt_t* opt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ OBJ_FILES = \
|
||||
$(TMP_DIR)/ctype.o \
|
||||
$(TMP_DIR)/stdio.o \
|
||||
$(TMP_DIR)/http.o \
|
||||
$(TMP_DIR)/getopt.o
|
||||
|
||||
lib: $(OUT_FILE)
|
||||
|
||||
@ -42,6 +43,9 @@ $(TMP_DIR)/stdio.o: stdio.c
|
||||
$(TMP_DIR)/http.o: http.c
|
||||
$(CC) $(CFLAGS) -o $@ -c http.c
|
||||
|
||||
$(TMP_DIR)/getopt.o: getopt.c
|
||||
$(CC) $(CFLAGS) -o $@ -c getopt.c
|
||||
|
||||
$(OUT_DIR):
|
||||
mkdir -p $(OUT_DIR)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user