From 40d8800dabaa175a81a8bb05aba24a8d63faabcb Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 18 Dec 2019 08:16:34 +0000 Subject: [PATCH] refactoring --- hawk/bin/Makefile.am | 2 +- hawk/bin/Makefile.in | 2 +- hawk/bin/main.c | 109 ++++++++++++++++++++++++---------------- hawk/configure | 2 +- hawk/configure.ac | 2 +- hawk/lib/fio.c | 19 ++++--- hawk/lib/gem.c | 37 +++++++++++--- hawk/lib/hawk-cfg.h.in | 6 +++ hawk/lib/hawk-cmn.h | 3 -- hawk/lib/hawk-gem.h | 8 +++ hawk/lib/hawk-htb.h | 4 +- hawk/lib/hawk-pio.h | 4 +- hawk/lib/hawk-rbt.h | 4 +- hawk/lib/hawk-std.h | 2 +- hawk/lib/hawk-utl.h | 28 ++++++----- hawk/lib/hawk.h | 4 ++ hawk/lib/mod-math.c | 40 ++++++++++++--- hawk/lib/pio.c | 102 ++++++++++++++++++------------------- hawk/lib/sio.c | 2 +- hawk/lib/std.c | 21 +++----- hawk/lib/tre-match-bt.c | 4 +- hawk/lib/utl-str.c | 50 +++++++++++++----- 22 files changed, 278 insertions(+), 177 deletions(-) diff --git a/hawk/bin/Makefile.am b/hawk/bin/Makefile.am index e3e3c57b..ad56666f 100644 --- a/hawk/bin/Makefile.am +++ b/hawk/bin/Makefile.am @@ -21,6 +21,6 @@ bin_PROGRAMS = hawk hawk_SOURCES = main.c hawk_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) hawk_LDFLAGS = $(LDFLAGS_ALL_COMMON) -hawk_LDADD = $(LIBADD_BIN_COMMON) -lhawk +hawk_LDADD = $(LIBADD_BIN_COMMON) $(SOCKET_LIBS) -lhawk hawk_DEPENDENCIES = ../lib/libhawk.la diff --git a/hawk/bin/Makefile.in b/hawk/bin/Makefile.in index ff2cefec..142ee005 100644 --- a/hawk/bin/Makefile.in +++ b/hawk/bin/Makefile.in @@ -353,7 +353,7 @@ LIBADD_BIN_COMMON = $(LIBM) hawk_SOURCES = main.c hawk_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) hawk_LDFLAGS = $(LDFLAGS_ALL_COMMON) -hawk_LDADD = $(LIBADD_BIN_COMMON) -lhawk +hawk_LDADD = $(LIBADD_BIN_COMMON) $(SOCKET_LIBS) -lhawk hawk_DEPENDENCIES = ../lib/libhawk.la all: all-am diff --git a/hawk/bin/main.c b/hawk/bin/main.c index 4b276e43..dcc24e45 100644 --- a/hawk/bin/main.c +++ b/hawk/bin/main.c @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -134,48 +135,55 @@ static void dprint (const hawk_ooch_t* fmt, ...) /* ---------------------------------------------------------------------- */ -#if defined(HAVE_SIGACTION) - typedef struct sig_state_t sig_state_t; struct sig_state_t { - hawk_oow_t handler; - hawk_oow_t old_handler; + hawk_uintptr_t handler; + hawk_uintptr_t old_handler; +#if defined(HAVE_SIGACTION) sigset_t old_sa_mask; int old_sa_flags; +#endif }; typedef void (*sig_handler_t) (int sig); static sig_state_t g_sig_state[HAWK_NSIG]; +static int is_signal_handler_set (int sig) +{ + return !!g_sig_state[sig].handler; +} + +#if defined(HAVE_SIGACTION) static void dispatch_siginfo (int sig, siginfo_t* si, void* ctx) { - if (g_sig_state[sig].handler != (hawk_oow_t)SIG_IGN && - g_sig_state[sig].handler != (hawk_oow_t)SIG_DFL) + if (g_sig_state[sig].handler != (hawk_uintptr_t)SIG_IGN && + g_sig_state[sig].handler != (hawk_uintptr_t)SIG_DFL) { ((sig_handler_t)g_sig_state[sig].handler) (sig); } if (g_sig_state[sig].old_handler && - g_sig_state[sig].old_handler != (hawk_oow_t)SIG_IGN && - g_sig_state[sig].old_handler != (hawk_oow_t)SIG_DFL) + g_sig_state[sig].old_handler != (hawk_uintptr_t)SIG_IGN && + g_sig_state[sig].old_handler != (hawk_uintptr_t)SIG_DFL) { ((void(*)(int, siginfo_t*, void*))g_sig_state[sig].old_handler) (sig, si, ctx); } } +#endif static void dispatch_signal (int sig) { - if (g_sig_state[sig].handler != (hawk_oow_t)SIG_IGN && - g_sig_state[sig].handler != (hawk_oow_t)SIG_DFL) + if (g_sig_state[sig].handler != (hawk_uintptr_t)SIG_IGN && + g_sig_state[sig].handler != (hawk_uintptr_t)SIG_DFL) { ((sig_handler_t)g_sig_state[sig].handler) (sig); } if (g_sig_state[sig].old_handler && - g_sig_state[sig].old_handler != (hawk_oow_t)SIG_IGN && - g_sig_state[sig].old_handler != (hawk_oow_t)SIG_DFL) + g_sig_state[sig].old_handler != (hawk_uintptr_t)SIG_IGN && + g_sig_state[sig].old_handler != (hawk_uintptr_t)SIG_DFL) { ((sig_handler_t)g_sig_state[sig].old_handler) (sig); } @@ -186,11 +194,12 @@ static int set_signal_handler (int sig, sig_handler_t handler, int extra_flags) if (g_sig_state[sig].handler) { /* already set - allow handler change. ignore extra_flags. */ - if (g_sig_state[sig].handler == (hawk_oow_t)handler) return -1; - g_sig_state[sig].handler = (hawk_oow_t)handler; + if (g_sig_state[sig].handler == (hawk_uintptr_t)handler) return -1; + g_sig_state[sig].handler = (hawk_uintptr_t)handler; } else { + #if defined(HAVE_SIGACTION) struct sigaction sa, oldsa; if (sigaction(sig, HAWK_NULL, &oldsa) == -1) return -1; @@ -213,14 +222,18 @@ static int set_signal_handler (int sig, sig_handler_t handler, int extra_flags) if (sigaction(sig, &sa, HAWK_NULL) == -1) return -1; - g_sig_state[sig].handler = (hawk_oow_t)handler; + g_sig_state[sig].handler = (hawk_uintptr_t)handler; if (oldsa.sa_flags & SA_SIGINFO) - g_sig_state[sig].old_handler = (hawk_oow_t)oldsa.sa_sigaction; + g_sig_state[sig].old_handler = (hawk_uintptr_t)oldsa.sa_sigaction; else - g_sig_state[sig].old_handler = (hawk_oow_t)oldsa.sa_handler; + g_sig_state[sig].old_handler = (hawk_uintptr_t)oldsa.sa_handler; g_sig_state[sig].old_sa_mask = oldsa.sa_mask; g_sig_state[sig].old_sa_flags = oldsa.sa_flags; + #else + g_sig_state[sig].old_handler = (hawk_uintptr_t)signal(sig, handler); + g_sig_state[sig].handler = (hawk_uintptr_t)dispatch_signal; + #endif } return 0; @@ -228,10 +241,13 @@ static int set_signal_handler (int sig, sig_handler_t handler, int extra_flags) static int unset_signal_handler (int sig) { +#if defined(HAVE_SIGACTION) struct sigaction sa; +#endif if (!g_sig_state[sig].handler) return -1; /* not set */ +#if defined(HAVE_SIGACTION) HAWK_MEMSET (&sa, 0, HAWK_SIZEOF(sa)); sa.sa_mask = g_sig_state[sig].old_sa_mask; sa.sa_flags = g_sig_state[sig].old_sa_flags; @@ -246,6 +262,9 @@ static int unset_signal_handler (int sig) } if (sigaction(sig, &sa, HAWK_NULL) == -1) return -1; +#else + signal (sig, (sig_handler_t)g_sig_state[sig].old_handler); +#endif g_sig_state[sig].handler = 0; /* keep other fields untouched */ @@ -253,14 +272,6 @@ static int unset_signal_handler (int sig) return 0; } -static int is_signal_handler_set (int sig) -{ - return !!g_sig_state[sig].handler; -} - -#endif - - /* ---------------------------------------------------------------------- */ static void stop_run (int signo) @@ -282,9 +293,15 @@ static void do_nothing (int unused) static void set_intr_run (void) { +#if defined(SIGTERM) set_signal_handler (SIGTERM, stop_run, 0); +#endif +#if defined(SIGHUP) set_signal_handler (SIGHUP, stop_run, 0); +#endif +#if defined(SIGINT) set_signal_handler (SIGINT, stop_run, 0); +#endif #if !defined(_WIN32) && !defined(__OS2__) && !defined(__DOS__) && defined(SIGPIPE) set_signal_handler (SIGPIPE, do_nothing, 0); #endif @@ -292,9 +309,15 @@ static void set_intr_run (void) static void unset_intr_run (void) { +#if defined(SIGTERM) unset_signal_handler (SIGTERM); +#endif +#if defined(SIGHUP) unset_signal_handler (SIGHUP); +#endif +#if defined(SIGINT) unset_signal_handler (SIGINT); +#endif #if !defined(_WIN32) && !defined(__OS2__) && !defined(__DOS__) && defined(SIGPIPE) unset_signal_handler (SIGPIPE); #endif @@ -915,39 +938,36 @@ static void freearg (struct arg_t* arg) if (arg->gvm.ptr) free (arg->gvm.ptr); } -static void print_hawk_error (hawk_t* awk) +static void print_hawk_error (hawk_t* hawk) { - const hawk_loc_t* loc = hawk_geterrloc(awk); + const hawk_loc_t* loc = hawk_geterrloc(hawk); - hawk_logfmt (awk, HAWK_LOG_STDERR, + hawk_logfmt (hawk, HAWK_LOG_STDERR, HAWK_T("ERROR: CODE %d LINE %zu COLUMN %zu %js%js%js- %js\n"), - (int)hawk_geterrnum(awk), + (int)hawk_geterrnum(hawk), (hawk_oow_t)loc->line, (hawk_oow_t)loc->colm, ((loc->file == HAWK_NULL)? HAWK_T(""): HAWK_T("FILE ")), ((loc->file == HAWK_NULL)? HAWK_T(""): loc->file), ((loc->file == HAWK_NULL)? HAWK_T(""): HAWK_T(" ")), - hawk_geterrmsg(awk) + hawk_geterrmsg(hawk) ); } static void print_hawk_rtx_error (hawk_rtx_t* rtx) { - const hawk_loc_t* loc = hawk_rtx_geterrloc (rtx); + const hawk_loc_t* loc = hawk_rtx_geterrloc(rtx); -/* TODO: proper logging mask */ -printf ("print_hawk_rtx_error... TODO: \n"); -/* - hawk_logfmt (hawk_rtx_gethawk(rtx), 0, - HAWK_T("ERROR: CODE %d LINE %zu COLUMN %zu %s%s%s- %s\n"), - hawk_rtx_geterrnum(rtx), + hawk_logfmt (hawk_rtx_gethawk(rtx), HAWK_LOG_STDERR, + HAWK_T("ERROR: CODE %d LINE %zu COLUMN %zu %js%js%js- %js\n"), + (int)hawk_rtx_geterrnum(rtx), (hawk_oow_t)loc->line, (hawk_oow_t)loc->colm, ((loc->file == HAWK_NULL)? HAWK_T(""): HAWK_T("FILE ")), ((loc->file == HAWK_NULL)? HAWK_T(""): loc->file), ((loc->file == HAWK_NULL)? HAWK_T(""): HAWK_T(" ")), hawk_rtx_geterrmsg(rtx) - );*/ + ); } hawk_htb_walk_t add_global (hawk_htb_t* map, hawk_htb_pair_t* pair, void* arg) @@ -1092,7 +1112,7 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[]) xma_mmgr.ctx = hawk_xma_open(HAWK_MMGR_GETDFL(), 0, arg.memlimit); if (xma_mmgr.ctx == HAWK_NULL) { - hawk_printf (HAWK_T("ERROR: cannot open memory heap\n")); + print_error ("cannot open memory heap\n"); goto oops; } mmgr = &xma_mmgr; @@ -1195,6 +1215,7 @@ oops: freearg (&arg); #if defined(HAWK_BUILD_DEBUG) + /* if (arg.failmalloc > 0) { hawk_fprintf (HAWK_STDERR, HAWK_T("\n")); @@ -1204,7 +1225,7 @@ oops: (unsigned long)debug_mmgr_free_count, (unsigned long)debug_mmgr_realloc_count); hawk_fprintf (HAWK_STDERR, HAWK_T("-------------------------------------------------------\n")); - } + }*/ #endif return ret; @@ -1232,12 +1253,12 @@ int main (int argc, hawk_bch_t* argv[]) if (codepage == CP_UTF8) { /*SetConsoleOUtputCP (CP_UTF8);*/ - hawk_setdflcmgrbyid (HAWK_CMGR_UTF8); + /*hawk_setdflcmgrbyid (HAWK_CMGR_UTF8);*/ } else { /* .codepage */ - hawk_fmt_uintmax_to_bcstr (locale, HAWK_COUNTOF(locale), codepage, 10, -1, HAWK_MT('\0'), HAWK_MT(".")); + hawk_fmt_uintmax_to_bcstr (locale, HAWK_COUNTOF(locale), codepage, 10, -1, '\0', "."); setlocale (LC_ALL, locale); /* hawk_setdflcmgrbyid (HAWK_CMGR_SLMB); */ } @@ -1250,7 +1271,7 @@ int main (int argc, hawk_bch_t* argv[]) #if defined(_WIN32) if (WSAStartup (MAKEWORD(2,0), &wsadata) != 0) { - print_error (HAWK_T("Failed to start up winsock\n")); + print_error ("Failed to start up winsock\n"); ret = -1; goto oops; } @@ -1258,7 +1279,7 @@ int main (int argc, hawk_bch_t* argv[]) /* TODO: add an option to skip watt-32 */ _watt_do_exit = 0; /* prevent sock_init from exiting upon failure */ if (sock_init() != 0) - print_warning (HAWK_T("Failed to initialize watt-32\n")); + print_warning ("Failed to initialize watt-32\n"); else sock_inited = 1; #endif diff --git a/hawk/configure b/hawk/configure index 5a8975fd..e8f9abc0 100755 --- a/hawk/configure +++ b/hawk/configure @@ -18734,7 +18734,7 @@ _ACEOF fi done -for ac_func in snprintf _vsnprintf _vsnwprintf strerror_r +for ac_func in snprintf _vsnprintf _vsnwprintf strerror_r random_r random do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/hawk/configure.ac b/hawk/configure.ac index 697160a2..ebc27d2e 100644 --- a/hawk/configure.ac +++ b/hawk/configure.ac @@ -202,7 +202,7 @@ AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext]) AC_CHECK_FUNCS([clock_nanosleep nanosleep usleep]) AC_CHECK_FUNCS([localtime_r gmtime_r]) AC_CHECK_FUNCS([sigaction signal]) -AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf strerror_r]) +AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf strerror_r random_r random]) AC_CHECK_FUNCS([accept4 pipe2 epoll_create epoll_create1 kqueue kqueue1]) AC_CHECK_FUNCS([isatty mmap munmap]) AC_CHECK_FUNCS([readdir64 dirfd faccessat]) diff --git a/hawk/lib/fio.c b/hawk/lib/fio.c index dd2b8e08..18f4aa55 100644 --- a/hawk/lib/fio.c +++ b/hawk/lib/fio.c @@ -1278,28 +1278,27 @@ static int get_devname_from_handle ( return 0; } -static int get_volname_from_handle ( - hawk_fio_t* fio, hawk_ooch_t* buf, hawk_oow_t len) +static int get_volname_from_handle (hawk_fio_t* fio, hawk_ooch_t* buf, hawk_oow_t len) { if (get_devname_from_handle (fio, buf, len) == -1) return -1; - if (hawk_strcasebeg (buf, HAWK_T("\\Device\\LanmanRedirector\\"))) + if (hawk_comp_oocstr_limited(buf, HAWK_T("\\Device\\LanmanRedirector\\"), 25, 1) == 0) { /*buf[0] = HAWK_T('\\');*/ - hawk_strcpy (&buf[1], &buf[24]); + hawk_copy_oocstr_unlimited (&buf[1], &buf[24]); } else { DWORD n; hawk_ooch_t drives[128]; - n = GetLogicalDriveStrings (HAWK_COUNTOF(drives), drives); + n = GetLogicalDriveStrings(HAWK_COUNTOF(drives), drives); if (n == 0 /* error */ || n > HAWK_COUNTOF(drives) /* buffer small */) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, syserr_to_errnum(GetLastError())); - return -1; + return -1; } while (n > 0) @@ -1312,14 +1311,14 @@ static int get_volname_from_handle ( drv[2] = HAWK_T('\0'); if (QueryDosDevice (drv, path, HAWK_COUNTOF(path))) { - hawk_oow_t pl = hawk_strlen(path); - hawk_oow_t bl = hawk_strlen(buf); + hawk_oow_t pl = hawk_count_oocstr(path); + hawk_oow_t bl = hawk_count_oocstr(buf); if (bl > pl && buf[pl] == HAWK_T('\\') && - hawk_strxncasecmp(buf, pl, path, pl) == 0) + hawk_comp_oochars(buf, pl, path, pl, 1) == 0) { buf[0] = drv[0]; buf[1] = HAWK_T(':'); - hawk_strcpy (&buf[2], &buf[pl]); + hawk_copy_oocstr_unlimited (&buf[2], &buf[pl]); break; } } diff --git a/hawk/lib/gem.c b/hawk/lib/gem.c index 5fd3a164..7972816f 100644 --- a/hawk/lib/gem.c +++ b/hawk/lib/gem.c @@ -384,15 +384,40 @@ hawk_bch_t* hawk_gem_duputobcharswithcmgr (hawk_gem_t* gem, const hawk_uch_t* uc return bcs; } +hawk_uch_t* hawk_gem_dupbcstrarrtoucstr (hawk_gem_t* gem, const hawk_bch_t* bcs[], hawk_oow_t* ucslen, int all) +{ + hawk_oow_t bl, ul, capa, pos, i; + hawk_uch_t* ucs; + + for (capa = 0, i = 0; bcs[i]; i++) + { + if (hawk_gem_convbtoucstr(gem, bcs[i], &bl, HAWK_NULL, &ul, all) <= -1) return HAWK_NULL; + capa += ul; + } + + ucs = (hawk_uch_t*)hawk_gem_allocmem(gem, (capa + 1) * HAWK_SIZEOF(*ucs)); + if (!ucs) return HAWK_NULL; + + for (pos = 0, i = 0; bcs[i]; i++) + { + ul = capa - pos + 1; + hawk_gem_convbtoucstr (gem, bcs[i], &bl, &ucs[pos], &ul, all); + pos += ul; + } + + if (ucslen) *ucslen = capa; + return ucs; +} + hawk_bch_t* hawk_gem_dupucstrarrtobcstr (hawk_gem_t* gem, const hawk_uch_t* ucs[], hawk_oow_t* bcslen) { - hawk_oow_t wl, ml, capa, pos, i; + hawk_oow_t ul, bl, capa, pos, i; hawk_bch_t* bcs; for (capa = 0, i = 0; ucs[i]; i++) { - if (hawk_gem_convutobcstr(gem, ucs[i], &wl, HAWK_NULL, &ml) <= -1) return HAWK_NULL; - capa += ml; + if (hawk_gem_convutobcstr(gem, ucs[i], &ul, HAWK_NULL, &bl) <= -1) return HAWK_NULL; + capa += bl; } bcs = (hawk_bch_t*)hawk_gem_allocmem(gem, (capa + 1) * HAWK_SIZEOF(*bcs)); @@ -400,9 +425,9 @@ hawk_bch_t* hawk_gem_dupucstrarrtobcstr (hawk_gem_t* gem, const hawk_uch_t* ucs[ for (pos = 0, i = 0; ucs[i]; i++) { - ml = capa - pos + 1; - hawk_gem_convutobcstr (gem, ucs[i], &wl, &bcs[pos], &ml); - pos += ml; + bl = capa - pos + 1; + hawk_gem_convutobcstr (gem, ucs[i], &ul, &bcs[pos], &bl); + pos += bl; } if (bcslen) *bcslen = capa; diff --git a/hawk/lib/hawk-cfg.h.in b/hawk/lib/hawk-cfg.h.in index e276b28c..13e99eeb 100644 --- a/hawk/lib/hawk-cfg.h.in +++ b/hawk/lib/hawk-cfg.h.in @@ -343,6 +343,12 @@ /* Define to 1 if you have the `quadmath_snprintf' function. */ #undef HAVE_QUADMATH_SNPRINTF +/* Define to 1 if you have the `random' function. */ +#undef HAVE_RANDOM + +/* Define to 1 if you have the `random_r' function. */ +#undef HAVE_RANDOM_R + /* Define to 1 if you have the `readdir64' function. */ #undef HAVE_READDIR64 diff --git a/hawk/lib/hawk-cmn.h b/hawk/lib/hawk-cmn.h index 40a4e294..363e4b9e 100644 --- a/hawk/lib/hawk-cmn.h +++ b/hawk/lib/hawk-cmn.h @@ -1258,9 +1258,6 @@ typedef enum hawk_log_mask_t hawk_log_mask_t; */ #if (HAWK_SIZEOF_UCH_T == HAWK_SIZEOF_BCH_T) # define HAWK_UT(txt) (txt) -#elif defined(HAWK_UCH_IS_CHAR16_T) && (HAWK_SIZEOF_WCHAR_T == 2) - /* prefer L to u as u is not supported by some compiers despite char16_t support */ -# define HAWK_UT(txt) (L ## txt) #elif defined(HAWK_UCH_IS_CHAR16_T) # define HAWK_UT(txt) (u ## txt) #else diff --git a/hawk/lib/hawk-gem.h b/hawk/lib/hawk-gem.h index 3eec2c4b..1e8ee27f 100644 --- a/hawk/lib/hawk-gem.h +++ b/hawk/lib/hawk-gem.h @@ -218,12 +218,20 @@ HAWK_EXPORT hawk_bch_t* hawk_gem_duputobcharswithcmgr ( hawk_cmgr_t* cmgr ); +HAWK_EXPORT hawk_uch_t* hawk_gem_dupbcstrarrtoucstr ( + hawk_gem_t* gem, + const hawk_bch_t* bcs[], + hawk_oow_t* ucslen, + int all +); + HAWK_EXPORT hawk_bch_t* hawk_gem_dupucstrarrtobcstr ( hawk_gem_t* gem, const hawk_uch_t* ucs[], hawk_oow_t* bcslen ); + /* ----------------------------------------------------------------------- */ hawk_oow_t hawk_gem_vfmttoucstr ( diff --git a/hawk/lib/hawk-htb.h b/hawk/lib/hawk-htb.h index 4eead573..b467a20e 100644 --- a/hawk/lib/hawk-htb.h +++ b/hawk/lib/hawk-htb.h @@ -547,9 +547,9 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_update ( * for (i = 0; i < HAWK_COUNTOF(vals); i++) * { * hawk_cstr_t ctx; - * ctx.ptr = vals[i]; ctx.len = hawk_strlen(vals[i]); + * ctx.ptr = vals[i]; ctx.len = hawk_count_oocstr(vals[i]); * hawk_htb_cbsert (s1, - * keys[i%HAWK_COUNTOF(keys)], hawk_strlen(keys[i%HAWK_COUNTOF(keys)]), + * keys[i%HAWK_COUNTOF(keys)], hawk_count_oocstr(keys[i%HAWK_COUNTOF(keys)]), * cbserter, &ctx * ); // note error check is skipped * } diff --git a/hawk/lib/hawk-pio.h b/hawk/lib/hawk-pio.h index 709d6cf9..798b0a04 100644 --- a/hawk/lib/hawk-pio.h +++ b/hawk/lib/hawk-pio.h @@ -52,7 +52,7 @@ enum hawk_pio_flag_t /** indicate that the command to hawk_pio_open() is a multi-byte string. * it is useful if #HAWK_OOCH_IS_UCH is defined. */ - HAWK_PIO_MBSCMD = (1 << 4), + HAWK_PIO_BCSTRCMD = (1 << 4), /** don't attempt to close open file descriptors unknown to pio. * it is useful only on a unix-like systems where file descriptors @@ -202,7 +202,7 @@ extern "C" { * On *nix systems, a full path to the command is needed if it is not specified. * If \a env is #HAWK_NULL, the environment of \a cmd inherits that of the * calling process. If you want to pass an empty environment, you can pass - * an empty \a env object with no items inserted. If #HAWK_PIO_MBSCMD is + * an empty \a env object with no items inserted. If #HAWK_PIO_BCSTRCMD is * specified in \a flags, \a cmd is treated as a multi-byte string whose * character type is #hawk_bch_t. * \return #hawk_pio_t object on success, #HAWK_NULL on failure diff --git a/hawk/lib/hawk-rbt.h b/hawk/lib/hawk-rbt.h index 761fbdf3..382ee943 100644 --- a/hawk/lib/hawk-rbt.h +++ b/hawk/lib/hawk-rbt.h @@ -500,9 +500,9 @@ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_update ( * for (i = 0; i < HAWK_COUNTOF(vals); i++) * { * hawk_cstr_t ctx; - * ctx.ptr = vals[i]; ctx.len = hawk_strlen(vals[i]); + * ctx.ptr = vals[i]; ctx.len = hawk_count_oocstr(vals[i]); * hawk_rbt_cbsert (s1, - * keys[i%HAWK_COUNTOF(keys)], hawk_strlen(keys[i%HAWK_COUNTOF(keys)]), + * keys[i%HAWK_COUNTOF(keys)], hawk_count_oocstr(keys[i%HAWK_COUNTOF(keys)]), * cbserter, &ctx * ); // note error check is skipped * } diff --git a/hawk/lib/hawk-std.h b/hawk/lib/hawk-std.h index cb8866cf..740af300 100644 --- a/hawk/lib/hawk-std.h +++ b/hawk/lib/hawk-std.h @@ -156,7 +156,7 @@ HAWK_EXPORT hawk_t* hawk_openstdwithmmgr ( * * in[0].type = HAWK_PARSESTD_OOCS; * in[0].u.str.ptr = HAWK_T("BEGIN { print 10; }"); - * in[0].u.str.len = hawk_strlen(in.u.str.ptr); + * in[0].u.str.len = hawk_count_oocstr(in.u.str.ptr); * in[1].type = HAWK_PARSESTD_NULL; * out.type = HAWK_PARSESTD_OOCS; * n = hawk_parsestd (awk, in, &out); diff --git a/hawk/lib/hawk-utl.h b/hawk/lib/hawk-utl.h index 480e7fa9..f4d9f7f4 100644 --- a/hawk/lib/hawk-utl.h +++ b/hawk/lib/hawk-utl.h @@ -463,13 +463,15 @@ HAWK_EXPORT int hawk_comp_bcstr ( HAWK_EXPORT int hawk_comp_ucstr_limited ( const hawk_uch_t* str1, const hawk_uch_t* str2, - hawk_oow_t maxlen + hawk_oow_t maxlen, + int ignorecase ); HAWK_EXPORT int hawk_comp_bcstr_limited ( const hawk_bch_t* str1, const hawk_bch_t* str2, - hawk_oow_t maxlen + hawk_oow_t maxlen, + int ignorecase ); HAWK_EXPORT int hawk_comp_ucstr_bcstr ( @@ -729,12 +731,13 @@ HAWK_EXPORT int hawk_split_bcstr ( # define hawk_comp_oochars_ucstr hawk_comp_uchars_ucstr # define hawk_comp_oochars_oocstr hawk_comp_uchars_ucstr # define hawk_comp_oocstr hawk_comp_ucstr +# define hawk_comp_oocstr_limited hawk_comp_ucstr_limited -# define hawk_copy_oochars(dst,src,len) hawk_copy_uchars(dst,src,len) -# define hawk_copy_bchars_to_oochars(dst,src,len) hawk_copy_bchars_to_uchars(dst,src,len) -# define hawk_copy_oochars_to_bchars(dst,src,len) hawk_copy_uchars_to_bchars(dst,src,len) -# define hawk_copy_uchars_to_oochars(dst,src,len) hawk_copy_uchars(dst,src,len) -# define hawk_copy_oochars_to_uchars(dst,src,len) hawk_copy_uchars(dst,src,len) +# define hawk_copy_oochars hawk_copy_uchars +# define hawk_copy_bchars_to_oochars hawk_copy_bchars_to_uchars +# define hawk_copy_oochars_to_bchars hawk_copy_uchars_to_bchars +# define hawk_copy_uchars_to_oochars hawk_copy_uchars +# define hawk_copy_oochars_to_uchars hawk_copy_uchars # define hawk_copy_oochars_to_oocstr(dst,dlen,src,slen) hawk_copy_uchars_to_ucstr(dst,dlen,src,slen) # define hawk_copy_oochars_to_oocstr_unlimited(dst,src,len) hawk_copy_uchars_to_ucstr_unlimited(dst,src,len) @@ -765,12 +768,13 @@ HAWK_EXPORT int hawk_split_bcstr ( # define hawk_comp_oochars_ucstr hawk_comp_bchars_ucstr # define hawk_comp_oochars_oocstr hawk_comp_bchars_bcstr # define hawk_comp_oocstr hawk_comp_bcstr +# define hawk_comp_oocstr_limited hawk_comp_bcstr_limited -# define hawk_copy_oochars(dst,src,len) hawk_copy_bchars(dst,src,len) -# define hawk_copy_bchars_to_oochars(dst,src,len) hawk_copy_bchars(dst,src,len) -# define hawk_copy_oochars_to_bchars(dst,src,len) hawk_copy_bchars(dst,src,len) -# define hawk_copy_uchars_to_oochars(dst,src,len) hawk_copy_uchars_to_bchars(dst,src,len) -# define hawk_copy_oochars_to_uchars(dst,src,len) hawk_copy_bchars_to_uchars(dst,src,len) +# define hawk_copy_oochars hawk_copy_bchars +# define hawk_copy_bchars_to_oochars hawk_copy_bchars +# define hawk_copy_oochars_to_bchars hawk_copy_bchars +# define hawk_copy_uchars_to_oochars hawk_copy_uchars_to_bchars +# define hawk_copy_oochars_to_uchars hawk_copy_bchars_to_uchars # define hawk_copy_oochars_to_oocstr(dst,dlen,src,slen) hawk_copy_bchars_to_bcstr(dst,dlen,src,slen) # define hawk_copy_oochars_to_oocstr_unlimited(dst,src,len) hawk_copy_bchars_to_bcstr_unlimited(dst,src,len) diff --git a/hawk/lib/hawk.h b/hawk/lib/hawk.h index e1c945e9..29f28dbb 100644 --- a/hawk/lib/hawk.h +++ b/hawk/lib/hawk.h @@ -1926,6 +1926,7 @@ static HAWK_INLINE hawk_uch_t* hawk_dupbtoucstr (hawk_t* hawk, const hawk_bch_t* static HAWK_INLINE hawk_bch_t* hawk_duputobcstr (hawk_t* hawk, const hawk_uch_t* ucs, hawk_oow_t* _bcslen) { return hawk_gem_duputobcstr(hawk_getgem(hawk), ucs, _bcslen); } static HAWK_INLINE hawk_uch_t* hawk_dupbtoucharswithcmgr (hawk_t* hawk, const hawk_bch_t* bcs, hawk_oow_t _bcslen, hawk_oow_t* _ucslen, hawk_cmgr_t* cmgr, int all) { return hawk_gem_dupbtoucharswithcmgr(hawk_getgem(hawk), bcs, _bcslen, _ucslen, cmgr, all); } static HAWK_INLINE hawk_bch_t* hawk_duputobcharswithcmgr (hawk_t* hawk, const hawk_uch_t* ucs, hawk_oow_t _ucslen, hawk_oow_t* _bcslen, hawk_cmgr_t* cmgr) { return hawk_gem_duputobcharswithcmgr(hawk_getgem(hawk), ucs, _ucslen, _bcslen, cmgr); } +static HAWK_INLINE hawk_uch_t* hawk_dupbcstrarrtoucstr (hawk_t* hawk, const hawk_bch_t* bcsarr[], hawk_oow_t* ucslen, int all) { return hawk_gem_dupbcstrarrtoucstr(hawk_getgem(hawk), bcsarr, ucslen, all); } static HAWK_INLINE hawk_bch_t* hawk_dupucstrarrtobcstr (hawk_t* hawk, const hawk_uch_t* ucsarr[], hawk_oow_t* bcslen) { return hawk_gem_dupucstrarrtobcstr(hawk_getgem(hawk), ucsarr, bcslen); } #else #define hawk_dupbtouchars(hawk, bcs, _bcslen, _ucslen, all) hawk_gem_dupbtouchars(hawk_getgem(hawk), bcs, _bcslen, _ucslen, all) @@ -1936,6 +1937,7 @@ static HAWK_INLINE hawk_bch_t* hawk_dupucstrarrtobcstr (hawk_t* hawk, const hawk #define hawk_duputobcstr(hawk, ucs, _bcslen) hawk_gem_duputobcstr(hawk_getgem(hawk), ucs, _bcslen) #define hawk_dupbtoucharswithcmgr(hawk, bcs, _bcslen, _ucslen, cmgr, all) hawk_gem_dupbtoucharswithcmgr(hawk_getgem(hawk), bcs, _bcslen, _ucslen, cmgr, all) #define hawk_duputobcharswithcmgr(hawk, ucs, _ucslen, _bcslen, cmgr) hawk_gem_duputobcharswithcmgr(hawk_getgem(hawk), ucs, _ucslen, _bcslen, cmgr) +#define hawk_dupbcstrarrtoucstr(hawk, bcsarr, ucslen, all) hawk_gem_dupbcstrarrtoucstr(hawk_getgem(hawk), bcsarr, ucslen, all) #define hawk_dupucstrarrtobcstr(hawk, ucsarr, bcslen) hawk_gem_dupucstrarrtobcstr(hawk_getgem(hawk), ucsarr, bcslen) #endif @@ -3169,6 +3171,7 @@ static HAWK_INLINE hawk_uch_t* hawk_rtx_dupbtoucstr (hawk_rtx_t* rtx, const hawk static HAWK_INLINE hawk_bch_t* hawk_rtx_duputobcstr (hawk_rtx_t* rtx, const hawk_uch_t* ucs, hawk_oow_t* _bcslen) { return hawk_gem_duputobcstr(hawk_rtx_getgem(rtx), ucs, _bcslen); } static HAWK_INLINE hawk_uch_t* hawk_rtx_dupbtoucharswithcmgr (hawk_rtx_t* rtx, const hawk_bch_t* bcs, hawk_oow_t _bcslen, hawk_oow_t* _ucslen, hawk_cmgr_t* cmgr, int all) { return hawk_gem_dupbtoucharswithcmgr(hawk_rtx_getgem(rtx), bcs, _bcslen, _ucslen, cmgr, all); } static HAWK_INLINE hawk_bch_t* hawk_rtx_duputobcharswithcmgr (hawk_rtx_t* rtx, const hawk_uch_t* ucs, hawk_oow_t _ucslen, hawk_oow_t* _bcslen, hawk_cmgr_t* cmgr) { return hawk_gem_duputobcharswithcmgr(hawk_rtx_getgem(rtx), ucs, _ucslen, _bcslen, cmgr); } +static HAWK_INLINE hawk_uch_t* hawk_rtx_dupbcstrarrtoucstr (hawk_rtx_t* rtx, const hawk_bch_t* bcsarr[], hawk_oow_t* ucslen, int all) { return hawk_gem_dupbcstrarrtoucstr(hawk_rtx_getgem(rtx), bcsarr, ucslen, all); } static HAWK_INLINE hawk_bch_t* hawk_rtx_dupucstrarrtobcstr (hawk_rtx_t* rtx, const hawk_uch_t* ucsarr[], hawk_oow_t* bcslen) { return hawk_gem_dupucstrarrtobcstr(hawk_rtx_getgem(rtx), ucsarr, bcslen); } #else #define hawk_rtx_dupbtouchars(rtx, bcs, _bcslen, _ucslen, all) hawk_gem_dupbtouchars(hawk_rtx_getgem(rtx), bcs, _bcslen, _ucslen, all) @@ -3179,6 +3182,7 @@ static HAWK_INLINE hawk_bch_t* hawk_rtx_dupucstrarrtobcstr (hawk_rtx_t* rtx, con #define hawk_rtx_duputobcstr(rtx, ucs, _bcslen) hawk_gem_duputobcstr(hawk_rtx_getgem(rtx), ucs, _bcslen) #define hawk_rtx_dupbtoucharswithcmgr(rtx, bcs, _bcslen, _ucslen, cmgr, all) hawk_gem_dupbtoucharswithcmgr(hawk_rtx_getgem(rtx), bcs, _bcslen, _ucslen, cmgr, all) #define hawk_rtx_duputobcharswithcmgr(rtx, ucs, _ucslen, _bcslen, cmgr) hawk_gem_duputobcharswithcmgr(hawk_rtx_getgem(rtx), ucs, _ucslen, _bcslen, cmgr) +#define hawk_rtx_dupbcstrarrtoucstr(rtx, bcsarr, ucslen, all) hawk_gem_dupbcstrarrtoucstr(hawk_rtx_getgem(hawk), bcsarr, ucslen, all) #define hawk_rtx_dupucstrarrtobcstr(rtx, ucsarr, bcslen) hawk_gem_dupucstrarrtobcstr(hawk_rtx_getgem(rtx), ucsarr, bcslen) #endif diff --git a/hawk/lib/mod-math.c b/hawk/lib/mod-math.c index 32c83c0f..220e015a 100644 --- a/hawk/lib/mod-math.c +++ b/hawk/lib/mod-math.c @@ -36,7 +36,7 @@ # error QUADMATH.H NOT AVAILABLE or NOT COMPILABLE #endif -#if !defined(HAWK_HAVE_CONFIG_H) +#if !defined(HAWK_HAVE_CFG_H) # if defined(_WIN32) || defined(__OS2__) || defined(__DOS__) # define HAVE_CEIL # define HAVE_FLOOR @@ -64,7 +64,9 @@ typedef struct modctx_t { unsigned int seed; +#if defined(HAVE_RANDOM_R) struct random_data prand; +#endif } modctx_t; static int fnc_math_1 (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, hawk_math1_t f) @@ -534,7 +536,13 @@ static int fnc_rand (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) modctx_t* modctx; modctx = (modctx_t*)fi->mod->ctx; +#if defined(HAVE_RANDOM_R) random_r (&modctx->prand, &randv); +#elif defined(HAVE_RANDOM) + randv = random(); +#else + randv = rand(); +#endif r = hawk_rtx_makefltval(rtx, (hawk_flt_t)randv / RANDV_MAX); if (r == HAWK_NULL) return -1; @@ -562,17 +570,29 @@ static int fnc_srand (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) if (nargs <= 0) { - struct timeval tv; - gettimeofday (&tv, HAWK_NULL); - modctx->seed = tv.tv_sec * tv.tv_usec; + hawk_ntime_t tv; + hawk_get_time (&tv); + modctx->seed = tv.sec + tv.nsec; + #if defined(HAVE_RANDOM_R) srandom_r (modctx->seed, &modctx->prand); + #elif defined(HAVE_RANDOM) + srandom (modctx->seed); + #else + srand (modctx->seed); + #endif } else { a0 = hawk_rtx_getarg(rtx, 0); n = hawk_rtx_valtoint(rtx, a0, &lv); if (n <= -1) return -1; + #if defined(HAVE_RANDOM_R) srandom_r (lv, &modctx->prand); + #elif defined(HAVE_RANDOM) + srandom (lv); + #else + srand (lv); + #endif } r = hawk_rtx_makeintval (rtx, prev); @@ -685,16 +705,22 @@ static void unload (hawk_mod_t* mod, hawk_t* awk) int hawk_mod_math (hawk_mod_t* mod, hawk_t* awk) { modctx_t* modctx; - struct timeval tv; + hawk_ntime_t tv; modctx = hawk_allocmem(awk, HAWK_SIZEOF(*modctx)); if (modctx == HAWK_NULL) return -1; HAWK_MEMSET (modctx, 0, HAWK_SIZEOF(*modctx)); - gettimeofday (&tv, HAWK_NULL); - modctx->seed = tv.tv_sec * tv.tv_usec; + hawk_get_time (&tv); + modctx->seed = tv.sec + tv.nsec; +#if defined(HAVE_RANDOM_R) srandom_r (modctx->seed, &modctx->prand); +#elif defined(HAVE_RANDOM) + srandom (modctx->seed); +#else + srand (modctx->seed); +#endif mod->query = query; mod->unload = unload; diff --git a/hawk/lib/pio.c b/hawk/lib/pio.c index e26d4e51..2cb8e4c4 100644 --- a/hawk/lib/pio.c +++ b/hawk/lib/pio.c @@ -257,23 +257,19 @@ static int make_param (hawk_pio_t* pio, const hawk_ooch_t* cmd, int flags, param if (flags & HAWK_PIO_SHELL) mcmd = (hawk_ooch_t*)cmd; else { - mcmd = hawk_strdup (cmd, pio->mmgr); - if (mcmd == HAWK_NULL) - { - pio->errnum = HAWK_PIO_ENOMEM; - goto oops; - } + mcmd = hawk_gem_dupoocstr(pio->gem, cmd, HAWK_NULL); + if (mcmd == HAWK_NULL) goto oops; fcnt = hawk_split_oocstr(mcmd, HAWK_T(""), HAWK_T('\"'), HAWK_T('\"'), HAWK_T('\\')); if (fcnt <= 0) { /* no field or an error */ - pio->errnum = HAWK_PIO_EINVAL; + hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_EINVAL); goto oops; } } #else - if (flags & HAWK_PIO_MBSCMD) + if (flags & HAWK_PIO_BCSTRCMD) { /* the cmd is flagged to be of hawk_bch_t * while the default character type is hawk_uch_t. */ @@ -898,28 +894,30 @@ create_process: }; #if defined(HAWK_OOCH_IS_UCH) - if (flags & HAWK_PIO_MBSCMD) + if (flags & HAWK_PIO_BCSTRCMD) { const hawk_bch_t* x[3]; x[0] = mcmdname[create_retried]; x[1] = (const hawk_bch_t*)cmd; x[2] = HAWK_NULL; - dupcmd = hawk_mbsatowcsdup(x, HAWK_NULL, mmgr); + dupcmd = hawk_gem_dupbcstrarrtoucstr(pio->gem, x, HAWK_NULL, 0); } else + #endif { - #endif - dupcmd = hawk_strdup2(cmdname[create_retried], cmd, mmgr); - #if defined(HAWK_OOCH_IS_UCH) + const hawk_ooch_t* x[3]; + x[0] = cmdname[create_retried]; + x[1] = cmd; + x[2] = HAWK_NULL; + dupcmd = hawk_gem_dupoocstrarr(pio->gem, x, HAWK_NULL); } - #endif } else { #if defined(HAWK_OOCH_IS_UCH) - if (flags & HAWK_PIO_MBSCMD) + if (flags & HAWK_PIO_BCSTRCMD) { - dupcmd = hawk_dupbtoucstr (pio->gem, (const hawk_bch_t*)cmd, HAWK_NULL, 0); + dupcmd = hawk_gem_dupbtoucstr(pio->gem, (const hawk_bch_t*)cmd, HAWK_NULL, 0); } else { @@ -1079,7 +1077,7 @@ create_process: if (maxidx == -1) { - pio->errnum = HAWK_PIO_EINVAL; + hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_EINVAL); goto oops; } @@ -1195,46 +1193,38 @@ create_process: hawk_oow_t n, mn; #if defined(HAWK_OOCH_IS_BCH) - mn = hawk_strlen(cmd); + mn = hawk_count_oocstr(cmd); #else - if (flags & HAWK_PIO_MBSCMD) + if (flags & HAWK_PIO_BCSTRCMD) { - mn = hawk_mbslen((const hawk_bch_t*)cmd); + mn = hawk_count_bcstr((const hawk_bch_t*)cmd); } else { - if (hawk_wcstombs (cmd, &n, HAWK_NULL, &mn) <= -1) - { - pio->errnum = HAWK_PIO_EINVAL; - goto oops; /* illegal sequence found */ - } + if (hawk_gem_convutobcstr(pio->gem, cmd, &n, HAWK_NULL, &mn) <= -1) goto oops; /* illegal sequence found */ } #endif - cmd_line = hawk_allocmem(hawk, ((11+mn+1+1) * HAWK_SIZEOF(*cmd_line))); - if (cmd_line == HAWK_NULL) - { - pio->errnum = HAWK_PIO_ENOMEM; - goto oops; - } + cmd_line = hawk_gem_allocmem(pio->gem, ((11+mn+1+1) * HAWK_SIZEOF(*cmd_line))); + if (cmd_line == HAWK_NULL) goto oops; - hawk_mbscpy (cmd_line, HAWK_BT("cmd.exe")); /* cmd.exe\0/c */ - hawk_mbscpy (&cmd_line[8], HAWK_BT("/c ")); + hawk_copy_bcstr_unlimited (cmd_line, "cmd.exe"); /* cmd.exe\0/c */ + hawk_copy_bcstr_unlimited (&cmd_line[8], "/c "); #if defined(HAWK_OOCH_IS_BCH) - hawk_mbscpy (&cmd_line[11], cmd); + hawk_copy_bcstr_unlimited (&cmd_line[11], cmd); #else - if (flags & HAWK_PIO_MBSCMD) + if (flags & HAWK_PIO_BCSTRCMD) { - hawk_mbscpy (&cmd_line[11], (const hawk_bch_t*)cmd); + hawk_copy_bcstr_unlimited (&cmd_line[11], (const hawk_bch_t*)cmd); } else { mn = mn + 1; /* update the buffer size */ - hawk_wcstombs (cmd, &n, &cmd_line[11], &mn); + hawk_gem_convutobcstr (pio->gem, cmd, &n, &cmd_line[11], &mn); } #endif - cmd_line[11+mn+1] = HAWK_BT('\0'); /* additional \0 after \0 */ + cmd_line[11+mn+1] = '\0'; /* additional \0 after \0 */ - cmd_file = HAWK_BT("cmd.exe"); + cmd_file = "cmd.exe"; } else { @@ -1242,23 +1232,27 @@ create_process: hawk_oow_t mn; #if defined(HAWK_OOCH_IS_BCH) + const hawk_ooch_t* strarr[3]; + + strarr[0] = cmd; + strarr[1] = HAWK_T(" "); + strarr[2] = HAWK_NULL; + mn = hawk_count_oocstr(cmd); - cmd_line = hawk_strdup2 (cmd, HAWK_T(" "), pio->mmgr); - if (cmd_line == HAWK_NULL) - { - pio->errnum = HAWK_PIO_ENOMEM; - goto oops; - } - #else - if (flags & HAWK_PIO_MBSCMD) + cmd_line = hawk_dupucstrarr(pio->gem, strarr HAWK_NULL); + if (cmd_line == HAWK_NULL) goto oops; + #else + if (flags & HAWK_PIO_BCSTRCMD) { + const hawk_bch_t* mbsarr[3]; + + mbsarr[0] = (const hawk_bch_t*)cmd; + mbsarr[1] = " "; + mbsarr[2] = HAWK_NULL; + mn = hawk_count_bcstr((const hawk_bch_t*)cmd); - cmd_line = hawk_mbsdup2 ((const hawk_bch_t*)cmd, HAWK_BT(" "), pio->mmgr); - if (cmd_line == HAWK_NULL) - { - pio->errnum = HAWK_PIO_ENOMEM; - goto oops; - } + cmd_line = hawk_dupbcstrarr(pio->gem, mbsarr, HAWK_NULL); + if (cmd_line == HAWK_NULL) goto oops; } else { @@ -1315,7 +1309,7 @@ create_process: #elif defined(__DOS__) /* DOS not multi-processed. can't support pio */ - pio->errnum = HAWK_PIO_ENOIMPL; + hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_ENOIMPL); return -1; #else diff --git a/hawk/lib/sio.c b/hawk/lib/sio.c index 6a2752c0..0d3937a2 100644 --- a/hawk/lib/sio.c +++ b/hawk/lib/sio.c @@ -457,7 +457,7 @@ hawk_ooi_t hawk_sio_putucstr (hawk_sio_t* sio, const hawk_uch_t* str) if (hawk_sio_flush (sio) <= -1) return -1; /* can't do buffering */ - for (cur = str, left = hawk_wcslen(str); left > 0; cur += count, left -= count) + for (cur = str, left = hawk_count_ucstr(str); left > 0; cur += count, left -= count) { if (WriteConsoleW(sio->file.handle, cur, left, &count, HAWK_NULL) == FALSE) { diff --git a/hawk/lib/std.c b/hawk/lib/std.c index dfb4ccfe..b2166b77 100644 --- a/hawk/lib/std.c +++ b/hawk/lib/std.c @@ -41,10 +41,11 @@ #if defined(_WIN32) # include # include -# if defined(HAWK_HAVE_CONFIG_H) && defined(HAWK_ENABLE_LIBLTDL) +# if defined(HAWK_HAVE_CFG_H) && defined(HAWK_ENABLE_LIBLTDL) # include # define USE_LTDL # endif +# include #elif defined(__OS2__) # define INCL_DOSMODULEMGR # define INCL_DOSPROCESS @@ -65,7 +66,7 @@ # endif #endif -#if !defined(HAWK_HAVE_CONFIG_H) +#if !defined(HAWK_HAVE_CFG_H) # if defined(_WIN32) || defined(__OS2__) || defined(__DOS__) # define HAVE_POW # define HAVE_FMOD @@ -137,8 +138,6 @@ typedef struct xtn_t int gbl_argc; int gbl_argv; int gbl_environ; - int gbl_errno; - int gbl_errstr; hawk_ecb_t ecb; int stdmod_up; @@ -355,12 +354,8 @@ void* hawk_stdmodopen (hawk_t* awk, const hawk_mod_spec_t* spec) if (spec->postfix) tmp[count++] = spec->postfix; tmp[count] = HAWK_NULL; - modpath = hawk_stradup (tmp, HAWK_NULL, hawk_getmmgr(awk)); - if (!modpath) - { - hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL); - return HAWK_NULL; - } + modpath = hawk_dupoocstrarr(awk, tmp, HAWK_NULL); + if (!modpath) return HAWK_NULL; h = LoadLibrary (modpath); @@ -3030,14 +3025,10 @@ static int add_globals (hawk_t* awk) xtn->gbl_argc = hawk_addgbl(awk, HAWK_T("ARGC")); xtn->gbl_argv = hawk_addgbl(awk, HAWK_T("ARGV")); xtn->gbl_environ = hawk_addgbl(awk, HAWK_T("ENVIRON")); - xtn->gbl_errno = hawk_addgbl(awk, HAWK_T("ERRNO")); - xtn->gbl_errstr = hawk_addgbl(awk, HAWK_T("ERRSTR")); return (xtn->gbl_argc <= -1 || xtn->gbl_argv <= -1 || - xtn->gbl_environ <= -1 || - xtn->gbl_errno <= -1 || - xtn->gbl_errstr <= -1)? -1: 0; + xtn->gbl_environ <= -1)? -1: 0; } struct fnctab_t diff --git a/hawk/lib/tre-match-bt.c b/hawk/lib/tre-match-bt.c index 27bf2cbc..3e228940 100644 --- a/hawk/lib/tre-match-bt.c +++ b/hawk/lib/tre-match-bt.c @@ -446,10 +446,10 @@ retry: { #ifdef TRE_WCHAR if (type == STR_WIDE) - result = hawk_comp_ucstr_limited((const hawk_uch_t*)string + so, str_wide - 1, (size_t)bt_len); + result = hawk_comp_ucstr_limited((const hawk_uch_t*)string + so, str_wide - 1, (size_t)bt_len, 0); else #endif /* TRE_WCHAR */ - result = hawk_comp_bcstr_limited((const char*)string + so, str_byte - 1, (size_t)bt_len); + result = hawk_comp_bcstr_limited((const char*)string + so, str_byte - 1, (size_t)bt_len, 0); } else if (len - pos < bt_len) result = 1; diff --git a/hawk/lib/utl-str.c b/hawk/lib/utl-str.c index 8da448f9..0dfa0c84 100644 --- a/hawk/lib/utl-str.c +++ b/hawk/lib/utl-str.c @@ -195,30 +195,56 @@ int hawk_comp_bcstr (const hawk_bch_t* str1, const hawk_bch_t* str2, int ignorec } -int hawk_comp_ucstr_limited (const hawk_uch_t* str1, const hawk_uch_t* str2, hawk_oow_t maxlen) +int hawk_comp_ucstr_limited (const hawk_uch_t* str1, const hawk_uch_t* str2, hawk_oow_t maxlen, int ignorecase) { if (maxlen == 0) return 0; - while (*str1 == *str2) + if (ignorecase) { - if (*str1 == '\0' || maxlen == 1) return 0; - str1++; str2++; maxlen--; - } + while (hawk_to_uch_lower(*str1) == hawk_to_uch_lower(*str2)) + { + if (*str1 == '\0' || maxlen == 1) return 0; + str1++; str2++; maxlen--; + } - return ((hawk_uchu_t)*str1 > (hawk_uchu_t)*str2)? 1: -1; + return ((hawk_uchu_t)hawk_to_uch_lower(*str1) > (hawk_uchu_t)hawk_to_uch_lower(*str2))? 1: -1; + } + else + { + while (*str1 == *str2) + { + if (*str1 == '\0' || maxlen == 1) return 0; + str1++; str2++; maxlen--; + } + + return ((hawk_uchu_t)*str1 > (hawk_uchu_t)*str2)? 1: -1; + } } -int hawk_comp_bcstr_limited (const hawk_bch_t* str1, const hawk_bch_t* str2, hawk_oow_t maxlen) +int hawk_comp_bcstr_limited (const hawk_bch_t* str1, const hawk_bch_t* str2, hawk_oow_t maxlen, int ignorecase) { if (maxlen == 0) return 0; - while (*str1 == *str2) + if (ignorecase) { - if (*str1 == '\0' || maxlen == 1) return 0; - str1++; str2++; maxlen--; - } + while (hawk_to_uch_lower(*str1) == hawk_to_uch_lower(*str2)) + { + if (*str1 == '\0' || maxlen == 1) return 0; + str1++; str2++; maxlen--; + } - return ((hawk_bchu_t)*str1 > (hawk_bchu_t)*str2)? 1: -1; + return ((hawk_bchu_t)hawk_to_uch_lower(*str1) > (hawk_bchu_t)hawk_to_uch_lower(*str2))? 1: -1; + } + else + { + while (*str1 == *str2) + { + if (*str1 == '\0' || maxlen == 1) return 0; + str1++; str2++; maxlen--; + } + + return ((hawk_bchu_t)*str1 > (hawk_bchu_t)*str2)? 1: -1; + } } int hawk_comp_ucstr_bcstr (const hawk_uch_t* str1, const hawk_bch_t* str2)