From fc76fa2967df25bb6721020f6114e37542540ab5 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 18 Mar 2008 06:35:02 +0000 Subject: [PATCH] --- ase/utl/getopt.c | 19 +++++++++++-------- ase/utl/getopt.h | 7 +++++-- ase/utl/makefile.in | 4 ++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ase/utl/getopt.c b/ase/utl/getopt.c index 99f83f1b..fbf81b0f 100644 --- a/ase/utl/getopt.c +++ b/ase/utl/getopt.c @@ -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; diff --git a/ase/utl/getopt.h b/ase/utl/getopt.h index e685304c..4364adbe 100644 --- a/ase/utl/getopt.h +++ b/ase/utl/getopt.h @@ -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 } diff --git a/ase/utl/makefile.in b/ase/utl/makefile.in index 6b09229e..8f915ee2 100644 --- a/ase/utl/makefile.in +++ b/ase/utl/makefile.in @@ -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)