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}
|
* {License}
|
||||||
*/
|
*/
|
||||||
@ -60,17 +60,16 @@ char *optarg; /* argument associated with option */
|
|||||||
#define optarg opt->arg
|
#define optarg opt->arg
|
||||||
#define optind opt->ind
|
#define optind opt->ind
|
||||||
#define optopt opt->opt
|
#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 */
|
ase_char_t* oli; /* option letter list index */
|
||||||
|
|
||||||
if (optreset || !*place)
|
if (!*place)
|
||||||
{
|
{
|
||||||
/* update scanning pointer */
|
/* update scanning pointer */
|
||||||
optreset = 0;
|
if (optind >= argc || *(place = argv[optind]) != ASE_T('-'))
|
||||||
if (optind >= argc || *(place = nargv[optind]) != '-')
|
|
||||||
{
|
{
|
||||||
place = EMSG;
|
place = EMSG;
|
||||||
return ASE_CHAR_EOF;
|
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 (optopt == (int)'-') return ASE_CHAR_EOF;
|
||||||
if (!*place) ++optind;
|
if (!*place) ++optind;
|
||||||
|
#if 0
|
||||||
if (opterr && *optstr != ASE_T(':'))
|
if (opterr && *optstr != ASE_T(':'))
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
"%s: illegal option -- %c\n", __FILE__, optopt);
|
"%s: illegal option -- %c\n", __FILE__, optopt);
|
||||||
return ASE_CHAR_BADCH;
|
#endif
|
||||||
|
return BADCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*++oli != ASE_T(':'))
|
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 */
|
/* no arg */
|
||||||
place = EMSG;
|
place = EMSG;
|
||||||
if (*optstr == ASE_T(':')) return BADARG;
|
if (*optstr == ASE_T(':')) return BADARG;
|
||||||
|
#if 0
|
||||||
if (opterr)
|
if (opterr)
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
"%s: option requires an argument -- %c\n",
|
"%s: option requires an argument -- %c\n",
|
||||||
__FILE__, optopt);
|
__FILE__, optopt);
|
||||||
|
#endif
|
||||||
return BADCH;
|
return BADCH;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* white space */
|
/* white space */
|
||||||
optarg = nargv[optind];
|
optarg = argv[optind];
|
||||||
}
|
}
|
||||||
place = EMSG;
|
place = EMSG;
|
||||||
++optind;
|
++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}
|
* {License}
|
||||||
*/
|
*/
|
||||||
@ -24,13 +24,16 @@ struct ase_opt_t
|
|||||||
|
|
||||||
/* input + output */
|
/* input + output */
|
||||||
int ind; /* index into parent argv vector */
|
int ind; /* index into parent argv vector */
|
||||||
|
|
||||||
|
/* internal */
|
||||||
|
ase_char_t* cur;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ OBJ_FILES = \
|
|||||||
$(TMP_DIR)/ctype.o \
|
$(TMP_DIR)/ctype.o \
|
||||||
$(TMP_DIR)/stdio.o \
|
$(TMP_DIR)/stdio.o \
|
||||||
$(TMP_DIR)/http.o \
|
$(TMP_DIR)/http.o \
|
||||||
|
$(TMP_DIR)/getopt.o
|
||||||
|
|
||||||
lib: $(OUT_FILE)
|
lib: $(OUT_FILE)
|
||||||
|
|
||||||
@ -42,6 +43,9 @@ $(TMP_DIR)/stdio.o: stdio.c
|
|||||||
$(TMP_DIR)/http.o: http.c
|
$(TMP_DIR)/http.o: http.c
|
||||||
$(CC) $(CFLAGS) -o $@ -c http.c
|
$(CC) $(CFLAGS) -o $@ -c http.c
|
||||||
|
|
||||||
|
$(TMP_DIR)/getopt.o: getopt.c
|
||||||
|
$(CC) $(CFLAGS) -o $@ -c getopt.c
|
||||||
|
|
||||||
$(OUT_DIR):
|
$(OUT_DIR):
|
||||||
mkdir -p $(OUT_DIR)
|
mkdir -p $(OUT_DIR)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user