From d98a683a579dd90ddaaf67f06a08c1c788698e83 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 19 Mar 2008 00:29:25 +0000 Subject: [PATCH] --- ase/cmn/str.h | 29 ++++++++++++- ase/cmn/str_cnv.c | 94 +++++++++++++++++++++++++++++++++++++--- ase/test/lsp/lsp.c | 15 ++++++- ase/test/lsp/makefile.in | 2 +- ase/utl/getopt.c | 45 +++++++------------ 5 files changed, 147 insertions(+), 38 deletions(-) diff --git a/ase/cmn/str.h b/ase/cmn/str.h index 6f591009..0ac4a22b 100644 --- a/ase/cmn/str.h +++ b/ase/cmn/str.h @@ -1,5 +1,5 @@ /* - * $Id: str.h 140 2008-03-18 04:08:36Z baconevi $ + * $Id: str.h 142 2008-03-18 06:29:25Z baconevi $ * * {License} */ @@ -81,6 +81,9 @@ struct ase_str_t extern "C" { #endif +/* + * basic string functions + */ ase_size_t ase_strlen (const ase_char_t* str); ase_size_t ase_strcpy ( @@ -126,11 +129,35 @@ ase_char_t* ase_strxchr (const ase_char_t* str, ase_size_t len, ase_cint_t c); ase_char_t* ase_strrchr (const ase_char_t* str, ase_cint_t c); ase_char_t* ase_strxrchr (const ase_char_t* str, ase_size_t len, ase_cint_t c); + +/* + * string conversion + */ +int ase_strtoi (const ase_char_t* str); +long ase_strtol (const ase_char_t* str); +unsigned int ase_strtoui (const ase_char_t* str); +unsigned long ase_strtoul (const ase_char_t* str); + +int ase_strxtoi (const ase_char_t* str, ase_size_t len); +long ase_strxtol (const ase_char_t* str, ase_size_t len); +unsigned int ase_strxtoui (const ase_char_t* str, ase_size_t len); +unsigned long ase_strxtoul (const ase_char_t* str, ase_size_t len); + ase_int_t ase_strtoint (const ase_char_t* str); ase_long_t ase_strtolong (const ase_char_t* str); ase_uint_t ase_strtouint (const ase_char_t* str); ase_ulong_t ase_strtoulong (const ase_char_t* str); +ase_int_t ase_strxtoint (const ase_char_t* str, ase_size_t len); +ase_long_t ase_strxtolong (const ase_char_t* str, ase_size_t len); +ase_uint_t ase_strxtouint (const ase_char_t* str, ase_size_t len); +ase_ulong_t ase_strxtoulong (const ase_char_t* str, ase_size_t len); + + +/* + * dynamic string + */ + ase_str_t* ase_str_open (ase_str_t* str, ase_size_t capa, ase_mmgr_t* mmgr); void ase_str_close (ase_str_t* str); void ase_str_clear (ase_str_t* str); diff --git a/ase/cmn/str_cnv.c b/ase/cmn/str_cnv.c index 4fa7e811..6c395d64 100644 --- a/ase/cmn/str_cnv.c +++ b/ase/cmn/str_cnv.c @@ -1,5 +1,5 @@ /* - * $Id: str_cnv.c 141 2008-03-18 04:09:04Z baconevi $ + * $Id: str_cnv.c 142 2008-03-18 06:29:25Z baconevi $ * * {License} */ @@ -7,30 +7,114 @@ #include #include +int ase_strtoi (const ase_char_t* str) +{ + int v; + ASE_STRTONUM (v, str, ASE_NULL, 10); + return v; +} + +long ase_strtol (const ase_char_t* str) +{ + long v; + ASE_STRTONUM (v, str, ASE_NULL, 10); + return v; +} + +unsigned int ase_strtoui (const ase_char_t* str) +{ + unsigned int v; + ASE_STRTONUM (v, str, ASE_NULL, 10); + return v; +} + +unsigned long ase_strtoul (const ase_char_t* str) +{ + unsigned long v; + ASE_STRTONUM (v, str, ASE_NULL, 10); + return v; +} + +int ase_strxtoi (const ase_char_t* str, ase_size_t len) +{ + int v; + ASE_STRXTONUM (v, str, len, ASE_NULL, 10); + return v; +} + +long ase_strxtol (const ase_char_t* str, ase_size_t len) +{ + long v; + ASE_STRXTONUM (v, str, len, ASE_NULL, 10); + return v; +} + +unsigned int ase_strxtoui (const ase_char_t* str, ase_size_t len) +{ + unsigned int v; + ASE_STRXTONUM (v, str, len, ASE_NULL, 10); + return v; +} + +unsigned long ase_strxtoul (const ase_char_t* str, ase_size_t len) +{ + unsigned long v; + ASE_STRXTONUM (v, str, len, ASE_NULL, 10); + return v; +} + ase_int_t ase_strtoint (const ase_char_t* str) { ase_int_t v; - ASE_STRTOI (v, str, ASE_NULL, 10); + ASE_STRTONUM (v, str, ASE_NULL, 10); return v; } ase_long_t ase_strtolong (const ase_char_t* str) { ase_long_t v; - ASE_STRTOI (v, str, ASE_NULL, 10); + ASE_STRTONUM (v, str, ASE_NULL, 10); return v; } ase_uint_t ase_strtouint (const ase_char_t* str) { ase_uint_t v; - ASE_STRTOI (v, str, ASE_NULL, 10); + ASE_STRTONUM (v, str, ASE_NULL, 10); return v; } ase_ulong_t ase_strtoulong (const ase_char_t* str) { ase_ulong_t v; - ASE_STRTOI (v, str, ASE_NULL, 10); + ASE_STRTONUM (v, str, ASE_NULL, 10); + return v; +} + +ase_int_t ase_strxtoint (const ase_char_t* str, ase_size_t len) +{ + ase_int_t v; + ASE_STRXTONUM (v, str, len, ASE_NULL, 10); + return v; +} + +ase_long_t ase_strxtolong (const ase_char_t* str, ase_size_t len) +{ + ase_long_t v; + ASE_STRXTONUM (v, str, len, ASE_NULL, 10); + return v; +} + +ase_uint_t ase_strxtouint (const ase_char_t* str, ase_size_t len) +{ + ase_uint_t v; + ASE_STRXTONUM (v, str, len, ASE_NULL, 10); + return v; +} + +ase_ulong_t ase_strxtoulong (const ase_char_t* str, ase_size_t len) +{ + ase_ulong_t v; + ASE_STRXTONUM (v, str, len, ASE_NULL, 10); return v; } diff --git a/ase/test/lsp/lsp.c b/ase/test/lsp/lsp.c index cb252467..7202c771 100644 --- a/ase/test/lsp/lsp.c +++ b/ase/test/lsp/lsp.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -283,11 +284,24 @@ static int handle_args (int argc, ase_char_t* argv[]) break; case ASE_T('?'): + ase_fprintf (ASE_STDERR, ASE_T("Error: illegal option - %c\n"), opt.opt); + print_usage (argv[0]); + return -1; + + case ASE_T(':'): + ase_fprintf (ASE_STDERR, ASE_T("Error: missing argument for %c\n"), opt.opt); print_usage (argv[0]); return -1; } } + if (opt.ind < argc) + { + ase_printf (ASE_T("Error: redundant argument - %s\n"), argv[opt.ind]); + print_usage (argv[0]); + return -1; + } + if (opt_memsize <= 0) { ase_printf (ASE_T("Error: invalid memory size given\n")); @@ -305,7 +319,6 @@ int lsp_main (int argc, ase_char_t* argv[]) prmfns_data_t prmfns_data; #endif - if (handle_args (argc, argv) == -1) return -1; ase_memset (&prmfns, 0, ASE_SIZEOF(prmfns)); diff --git a/ase/test/lsp/makefile.in b/ase/test/lsp/makefile.in index 9d4d9b93..7888302f 100644 --- a/ase/test/lsp/makefile.in +++ b/ase/test/lsp/makefile.in @@ -12,7 +12,7 @@ OUT_DIR = ../../$(MODE)/bin all: $(OUT_DIR)/aselsp -$(OUT_DIR)/aselsp: $(OUT_DIR) +$(OUT_DIR)/aselsp: $(OUT_DIR) lsp.c $(CC) $(CFLAGS) -o $@ lsp.c $(LDFLAGS) $(LIBS) $(OUT_DIR): diff --git a/ase/utl/getopt.c b/ase/utl/getopt.c index 03ed4548..a2313c5f 100644 --- a/ase/utl/getopt.c +++ b/ase/utl/getopt.c @@ -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 #include -#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; }