diff --git a/README.md b/README.md index 08aabb9e..54be32d8 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ Assuming the above sample code is stored in `hawk02.c` and the built Hawk librar $ gcc -Wall -O2 -o hawk02 hawk02.c -lhawk ``` -The acutal command may vary depending on the compiler used and the library `configure` options used. +The actual command may vary depending on the compiler used and the library `configure` options used. # Embedding Hawk in C++ Applications @@ -253,7 +253,7 @@ In this example, the `sum.hawk` file contains the Hawk script that sums up the n It's important to note that if there is no action-pattern block or `END` block present in the Hawk script, the interpreter will not wait for input records. In this case, the script will execute only the `BEGIN` block (if present) and then immediately terminate. -However, if an action-pattern block or an END block is present in the script, even if there is no action-pattern block, Hawk (and awk) will wait for input records or lines. This behavior is consistent with the way awk was designed to operate: it expects input data to process unless the script explicitly indicates that no input is required. +However, if an action-pattern block or an END block is present in the script, even if there is no action-pattern block, Hawk will wait for input records or lines. This behavior is consistent with the way awk was designed to operate: it expects input data to process unless the script explicitly indicates that no input is required. For example, consider the following command: @@ -275,8 +275,8 @@ The `@pragma` keyword enables you to modify Hawk’s behavior. You can place a p | implicit | file | on, off | on | allow undeclared variables | | multilinestr | file | on, off | off | allow a multiline string literal without continuation | | striprecspc | global | on, off | off | removes leading and trailing blank fields in splitting a record if FS is a regular expression mathcing all spaces | -| stripstrspc | global | on, off | on | trim leading and trailing spaces when convering a string to a number | -| numstrdetect | global | on, off | on | trim leading and trailing spaces when convering a string to a number | +| stripstrspc | global | on, off | on | trim leading and trailing spaces when converting a string to a number | +| numstrdetect | global | on, off | on | trim leading and trailing spaces when converting a string to a number | | stack_limit | global | number | 5120 | specify the runtime stack size measured in the number of values | ### @pragma entry @@ -295,7 +295,7 @@ In this example, the `main` function is set as the entry point for script execut You can also pass arguments to the entry point function by defining it with parameters: ```awk -@pragma entry main; +@pragma entry main function main(arg1, arg2) { print "Arguments:", arg1, arg2 } @@ -316,10 +316,10 @@ This flexibility in specifying the entry point can be useful in various scenario - Testing and Debugging: When working on specific parts of your script, you can temporarily set the entry point to a different function, making it easier to test and debug that particular functionality. - Integration with Other Systems: If you need to embed Hawk scripts within a larger application or system, you can use the `@pragma entry` feature to specify the function that should be executed as the entry point, enabling better integration and control over the script execution flow. -If you don't know the number of arguments in advance, you can use the ellipsis `...` in the parameter list and access the varidic arguments using `@argv()` and `@argc()`. +If you don't know the number of arguments in advance, you can use the ellipsis `...` in the parameter list and access the variadic arguments using `@argv()` and `@argc()`. ```awk -@pragma entry main; +@pragma entry main function main(...) { @local i for (i = 0; i < @argc(); i++) printf("%d:", @argv(i)) @@ -449,7 +449,7 @@ BEGIN { ## Comments -`Hawk` supports a single-line commnt that begins with a hash sign # and the C-style multi-line comment. +`Hawk` supports a single-line comment that begins with a hash sign # and the C-style multi-line comment. ```awk x = y; # assign y to x. @@ -492,11 +492,11 @@ The following words are reserved and cannot be used as a variable name, a parame - return - while -However, these words can be used as normal names in the context of a module call. For example, mymod::break. In practice, the predefined names used for built-in commands, functions, and variables are treated as if they are reserved since you can't create another denifition with the same name. +However, these words can be used as normal names in the context of a module call. For example, mymod::break. In practice, the predefined names used for built-in commands, functions, and variables are treated as if they are reserved since you can't create another definition with the same name. ## Values -- unitialized value +- uninitialized value - character - integer - floating-point number @@ -532,26 +532,26 @@ BEGIN { - hawk::VAL_REF - hawk::VAL_REX -A regular expression literal is special in that it never appears as an indendent value and still entails a match operation against $0 without an match operator. +A regular expression literal is special in that it never appears as an independent value and still entails a match operation against $0 without an match operator. ```awk BEGIN { $0="ab"; print /ab/, hawk::typename(/ab/); } ``` -For this reason, there is no way to get the type name of a regular expressin literal. +For this reason, there is no way to get the type name of a regular expression literal. ### Numbers An integer begins with a numeric digit between 0 and 9 inclusive and can be followed by more numeric digits. If an integer is immediately followed by a floating point, and optionally a series of numeric digits without whitespaces, -it becomes a floting-point number. An integer or a simple floating-point number +it becomes a floating-point number. An integer or a simple floating-point number can be followed by e or E, and optionally a series of numeric digits with a -optional single sign letter. A floating-point number may begin with a floting -point with a preceeding number. +optional single sign letter. A floating-point number may begin with a floating +point with a preceding number. - `369` # integer -- `3.69` # floating-pointe number +- `3.69` # floating-point number - `13.` # 13.0 - `.369` # 0.369 - `34e-2` # 34 * (10 ** -2) @@ -561,7 +561,7 @@ point with a preceeding number. An integer can be prefixed with 0x, 0, 0b for a hexa-decimal number, an octal number, and a binary number respectively. For a hexa-decimal number, letters -from A to F can form a number case-insenstively in addition to numeric digits. +from A to F can form a number case-insensitively in addition to numeric digits. - `0xA1` # 161 - `0xB0b0` # 45232 @@ -626,7 +626,7 @@ BEGIN { - +, -, *, % - &&, ||, &, | -## Control Strucutres +## Control Structures Hawk supports various control structures for flow control and iteration, similar to those found in awk. @@ -970,7 +970,7 @@ The `str` module provides an extensive set of string manipulation functions. - str::isxdigit - str::length - equivalent to length - str::ltrim -- str::match - similar to match. the optional third argument is the search start index. the optional fourth argument is equivalent to the thrid argument to match(). +- str::match - similar to match. the optional third argument is the search start index. the optional fourth argument is equivalent to the third argument to match(). - str::normspace - str::printf - equivalent to sprintf - str::rindex @@ -980,7 +980,7 @@ The `str` module provides an extensive set of string manipulation functions. - str::substr - equivalent to substr - str::tocharcode - get the numeric value of the first character - str::tolower - equivalent to tolower -- str::tonum - convert a string to a number. a numeric value passed as a parameter is returned as it is. the leading prefix of 0b, 0, and 0x specifies the radix of 2, 8, 16 repectively. conversion stops when the end of the string is reached or the first invalid character for conversion is encountered. +- str::tonum - convert a string to a number. a numeric value passed as a parameter is returned as it is. the leading prefix of 0b, 0, and 0x specifies the radix of 2, 8, 16 respectively. conversion stops when the end of the string is reached or the first invalid character for conversion is encountered. - str::toupper - equivalent to toupper - str::trim diff --git a/bin/hawk.c b/bin/hawk.c index 2de8b308..4d68cc5e 100644 --- a/bin/hawk.c +++ b/bin/hawk.c @@ -162,7 +162,7 @@ static void dispatch_siginfo (int sig, siginfo_t* si, void* ctx) ((sig_handler_t)g_sig_state[sig].handler) (sig); } - if (g_sig_state[sig].old_handler && + if (g_sig_state[sig].old_handler && g_sig_state[sig].old_handler != (hawk_uintptr_t)SIG_IGN && g_sig_state[sig].old_handler != (hawk_uintptr_t)SIG_DFL) { @@ -179,7 +179,7 @@ static void dispatch_signal (int sig) ((sig_handler_t)g_sig_state[sig].handler) (sig); } - if (g_sig_state[sig].old_handler && + if (g_sig_state[sig].old_handler && g_sig_state[sig].old_handler != (hawk_uintptr_t)SIG_IGN && g_sig_state[sig].old_handler != (hawk_uintptr_t)SIG_DFL) { @@ -398,7 +398,7 @@ static int apply_fs_and_gvs_to_rtx (hawk_rtx_t* rtx, arg_t* arg) if (arg->gvm.capa > 0) { - /* set the value of user-defined global variables + /* set the value of user-defined global variables * to a runtime context */ hawk_oow_t i; @@ -416,19 +416,19 @@ static int apply_fs_and_gvs_to_rtx (hawk_rtx_t* rtx, arg_t* arg) } } - for (i = 0; arg->psin[i].type != HAWK_PARSESTD_NULL; i++) + for (i = 0; arg->psin[i].type != HAWK_PARSESTD_NULL; i++) { - if (arg->psin[i].type == HAWK_PARSESTD_FILE) + if (arg->psin[i].type == HAWK_PARSESTD_FILE) { if (hawk_rtx_setscriptnamewithoochars(rtx, arg->psin[i].u.file.path, hawk_count_oocstr(arg->psin[i].u.file.path)) <= -1) return -1; break; } - else if (arg->psin[i].type == HAWK_PARSESTD_FILEB) + else if (arg->psin[i].type == HAWK_PARSESTD_FILEB) { if (hawk_rtx_setscriptnamewithbchars(rtx, arg->psin[i].u.fileb.path, hawk_count_bcstr(arg->psin[i].u.fileb.path)) <= -1) return -1; break; } - else if (arg->psin[i].type == HAWK_PARSESTD_FILEU) + else if (arg->psin[i].type == HAWK_PARSESTD_FILEU) { if (hawk_rtx_setscriptnamewithuchars(rtx, arg->psin[i].u.fileu.path, hawk_count_ucstr(arg->psin[i].u.fileu.path)) <= -1) return -1; break; @@ -443,7 +443,7 @@ static void dprint_return (hawk_rtx_t* rtx, hawk_val_t* ret) hawk_t* hawk = hawk_rtx_gethawk(rtx); hawk_oow_t len; hawk_ooch_t* str; - + if (hawk_rtx_isnilval(rtx, ret)) { @@ -471,7 +471,7 @@ static void dprint_return (hawk_rtx_t* rtx, hawk_val_t* ret) #if defined(ENABLE_CALLBACK) static void on_statement (hawk_rtx_t* rtx, hawk_nde_t* nde) { - + hawk_logfmt (hawk_rtx_gethawk(rtx), HAWK_LOG_STDERR, HAWK_T("running %d at line %zu\n"), (int)nde->type, (hawk_oow_t)nde->loc.line); } #endif @@ -549,7 +549,7 @@ static void print_usage (FILE* out, const hawk_bch_t* argv0) fprintf (out, " -v/--assign var=value add a global variable with a value\n"); fprintf (out, " -m/--memory-limit number limit the memory usage (bytes)\n"); fprintf (out, " -w expand datafile wildcards\n"); - + #if defined(HAWK_BUILD_DEBUG) fprintf (out, " -X number fail the number'th memory allocation\n"); #endif @@ -650,7 +650,7 @@ static int expand_wildcard (int argc, hawk_bch_t* argv[], int do_glob, xarg_t* x static int process_argv (int argc, hawk_bch_t* argv[], struct arg_t* arg) { - static hawk_bcli_lng_t lng[] = + static hawk_bcli_lng_t lng[] = { { ":implicit", '\0' }, { ":multilinestr", '\0' }, @@ -688,10 +688,10 @@ static int process_argv (int argc, hawk_bch_t* argv[], struct arg_t* arg) { "version", '\0' }, { "help", 'h' }, - { HAWK_NULL, '\0' } + { HAWK_NULL, '\0' } }; - static hawk_bcli_t opt = + static hawk_bcli_t opt = { #if defined(HAWK_BUILD_DEBUG) "hDc:f:d:t:F:v:m:I:wX:", @@ -770,7 +770,7 @@ static int process_argv (int argc, hawk_bch_t* argv[], struct arg_t* arg) hawk_bcs_t tmp; tmp.ptr = opt.arg; tmp.len = hawk_count_bcstr(opt.arg); - if (collect_into_xarg(&tmp, &arg->ocf) <= -1) + if (collect_into_xarg(&tmp, &arg->ocf) <= -1) { print_error ("out of memory\n"); goto oops; @@ -790,7 +790,7 @@ static int process_argv (int argc, hawk_bch_t* argv[], struct arg_t* arg) hawk_bch_t* eq; eq = hawk_find_bchar_in_bcstr(opt.arg, HAWK_T('=')); - if (eq == HAWK_NULL) + if (eq == HAWK_NULL) { if (opt.lngopt) print_error ("no value for '%s' in '%s'\n", opt.arg, opt.lngopt); @@ -921,7 +921,7 @@ static int process_argv (int argc, hawk_bch_t* argv[], struct arg_t* arg) } break; } - + case '?': { if (opt.lngopt) @@ -964,7 +964,7 @@ static int process_argv (int argc, hawk_bch_t* argv[], struct arg_t* arg) isfl++; } - for (i = 0; i < isfl ; i++) + for (i = 0; i < isfl ; i++) { if (isf[i].type == HAWK_PARSESTD_FILE) isf[i].u.file.cmgr = arg->script_cmgr; } @@ -972,7 +972,7 @@ static int process_argv (int argc, hawk_bch_t* argv[], struct arg_t* arg) isf[isfl].type = HAWK_PARSESTD_NULL; arg->psin = isf; - if (opt.ind < argc) + if (opt.ind < argc) { /* the remaining arguments are input console file names */ if (expand_wildcard(argc - opt.ind, &argv[opt.ind], do_glob, &arg->icf) <= -1) @@ -988,7 +988,7 @@ oops: if (arg->gvm.ptr) free (arg->gvm.ptr); purge_xarg (&arg->icf); purge_xarg (&arg->ocf); - if (isf) + if (isf) { if (arg->incl_conv) free (isf[0].u.bcs.ptr); free (isf); @@ -998,7 +998,7 @@ oops: static void freearg (struct arg_t* arg) { - if (arg->psin) + if (arg->psin) { if (arg->incl_conv) free (arg->psin[0].u.bcs.ptr); free (arg->psin); @@ -1015,7 +1015,7 @@ static void print_hawk_error (hawk_t* hawk) const hawk_loc_t* loc = hawk_geterrloc(hawk); hawk_logfmt (hawk, HAWK_LOG_STDERR, - HAWK_T("ERROR: CODE %d LINE %zu COLUMN %zu %js%js%js- %js\n"), + HAWK_T("ERROR: CODE %d LINE %zu COLUMN %zu %js%js%js- %js\n"), (int)hawk_geterrnum(hawk), (hawk_oow_t)loc->line, (hawk_oow_t)loc->colm, @@ -1031,7 +1031,7 @@ static void print_hawk_rtx_error (hawk_rtx_t* rtx) const hawk_loc_t* loc = hawk_rtx_geterrloc(rtx); hawk_logfmt (hawk_rtx_gethawk(rtx), HAWK_LOG_STDERR, - HAWK_T("ERROR: CODE %d LINE %zu COLUMN %zu %js%js%js- %js\n"), + 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, @@ -1057,7 +1057,7 @@ static void xma_free (hawk_mmgr_t* mmgr, void* ptr) hawk_xma_free (mmgr->ctx, ptr); } -static hawk_mmgr_t xma_mmgr = +static hawk_mmgr_t xma_mmgr = { xma_alloc, xma_realloc, @@ -1069,7 +1069,7 @@ static void xma_dumper_without_hawk (void* ctx, const hawk_bch_t* fmt, ...) { va_list ap; va_start (ap, fmt); - vfprintf (stderr, fmt, ap); + vfprintf (stderr, fmt, ap); va_end (ap); } @@ -1165,7 +1165,7 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[]) debug_mmgr.ctx = &arg; mmgr = &debug_mmgr; } - else + else #endif if (arg.memlimit > 0) { @@ -1207,7 +1207,7 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[]) hawk_setopt (hawk, HAWK_OPT_DEPTH_INCLUDE, &tmp); } - if (arg.includedirs) + if (arg.includedirs) { #if defined(HAWK_OOCH_IS_UCH) hawk_ooch_t* tmp; @@ -1225,7 +1225,7 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[]) #endif } - if (arg.modlibdirs) + if (arg.modlibdirs) { #if defined(HAWK_OOCH_IS_UCH) hawk_ooch_t* tmp; @@ -1272,7 +1272,7 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[]) print_hawk_rtx_error (rtx); goto oops; } - + app_rtx = rtx; #if defined(ENABLE_CALLBACK) hawk_rtx_pushecb (rtx, &rtx_ecb); @@ -1286,7 +1286,7 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[]) hawk_rtx_loop(rtx); /* this doesn't support @pragma startup ... */ #else /* note about @pragma entry ... - * hawk_rtx_execwithbcstrarr() invokes the specified function if '@pragma entry' is set + * hawk_rtx_execwithbcstrarr() invokes the specified function if '@pragma entry' is set * in the source code. because arg.icf.ptr has been passed to hawk_rtx_openstdwithbcstr() when * arg.call is HAWK_NULL, arg.icf.ptr serves as parameters to the startup function and * affects input consoles */ @@ -1319,7 +1319,7 @@ oops: unset_intr_pipe (); - if (xma_mmgr.ctx) + if (xma_mmgr.ctx) { if (app_debug) hawk_xma_dump (xma_mmgr.ctx, xma_dumper_without_hawk, HAWK_NULL); hawk_xma_close (xma_mmgr.ctx); @@ -1332,7 +1332,7 @@ oops: { hawk_fprintf (HAWK_STDERR, HAWK_T("\n")); hawk_fprintf (HAWK_STDERR, HAWK_T("-[MALLOC COUNTS]---------------------------------------\n")); - hawk_fprintf (HAWK_STDERR, HAWK_T("ALLOC: %lu FREE: %lu: REALLOC: %lu\n"), + hawk_fprintf (HAWK_STDERR, HAWK_T("ALLOC: %lu FREE: %lu: REALLOC: %lu\n"), (unsigned long)debug_mmgr_alloc_count, (unsigned long)debug_mmgr_free_count, (unsigned long)debug_mmgr_realloc_count); @@ -1417,7 +1417,7 @@ recv () {} setsockopt () {} send () {} bind () {} -shutdown () {} +shutdown () {} void* memmove (void* x, void* y, size_t z) {} #endif diff --git a/bin/sed.c b/bin/sed.c index 5cb5a1e4..99e55a9a 100644 --- a/bin/sed.c +++ b/bin/sed.c @@ -63,7 +63,7 @@ static struct hawk_sed_iostd_t* io; hawk_oow_t capa; hawk_oow_t size; -} g_script = +} g_script = { HAWK_NULL, 0, @@ -113,7 +113,7 @@ static void xma_free (hawk_mmgr_t* mmgr, void* ptr) hawk_xma_free (mmgr->ctx, ptr); } -static hawk_mmgr_t xma_mmgr = +static hawk_mmgr_t xma_mmgr = { xma_alloc, xma_realloc, @@ -243,7 +243,7 @@ static int add_script (const hawk_bch_t* str, int mem) hawk_sed_iostd_t* tmp; tmp = (hawk_sed_iostd_t*)realloc(g_script.io, HAWK_SIZEOF(*g_script.io) * (g_script.capa + 16 + 1)); - if (tmp == HAWK_NULL) + if (tmp == HAWK_NULL) { print_error ("out of memory while processing %s\n", str); return -1; @@ -251,13 +251,13 @@ static int add_script (const hawk_bch_t* str, int mem) g_script.io = tmp; g_script.capa += 16; - } + } if (mem) { /* string */ g_script.io[g_script.size].type = HAWK_SED_IOSTD_BCS; - /* though its type is not qualified to be const, + /* though its type is not qualified to be const, * u.mem.ptr is actually const when used for input */ g_script.io[g_script.size].u.bcs.ptr = (hawk_bch_t*)str; g_script.io[g_script.size].u.bcs.len = hawk_count_bcstr(str); @@ -286,7 +286,7 @@ static void free_scripts (void) static int handle_args (int argc, hawk_bch_t* argv[], struct arg_t* arg) { - static hawk_bcli_lng_t lng[] = + static hawk_bcli_lng_t lng[] = { #if defined(HAWK_OOCH_IS_UCH) { ":script-encoding", '\0' }, @@ -296,9 +296,9 @@ static int handle_args (int argc, hawk_bch_t* argv[], struct arg_t* arg) { "version", '\0' }, { "help", 'h' }, - { HAWK_NULL, '\0' } + { HAWK_NULL, '\0' } }; - static hawk_bcli_t opt = + static hawk_bcli_t opt = { #if defined(HAWK_BUILD_DEBUG) "hne:f:o:rRisabxytm:wX:", @@ -387,7 +387,7 @@ static int handle_args (int argc, hawk_bch_t* argv[], struct arg_t* arg) print_usage (stderr, argc, argv); goto oops; #endif - + case 'm': arg->memlimit = strtoul(opt.arg, HAWK_NULL, 10); break; @@ -442,7 +442,7 @@ static int handle_args (int argc, hawk_bch_t* argv[], struct arg_t* arg) } } - if (opt.ind < argc && g_script.size <= 0) + if (opt.ind < argc && g_script.size <= 0) { if (add_script(argv[opt.ind++], 1) <= -1) goto oops; } @@ -511,7 +511,7 @@ static void dispatch_siginfo (int sig, siginfo_t* si, void* ctx) ((sig_handler_t)g_sig_state[sig].handler) (sig); } - if (g_sig_state[sig].old_handler && + if (g_sig_state[sig].old_handler && g_sig_state[sig].old_handler != (hawk_uintptr_t)SIG_IGN && g_sig_state[sig].old_handler != (hawk_uintptr_t)SIG_DFL) { @@ -528,7 +528,7 @@ static void dispatch_signal (int sig) ((sig_handler_t)g_sig_state[sig].handler) (sig); } - if (g_sig_state[sig].old_handler && + if (g_sig_state[sig].old_handler && g_sig_state[sig].old_handler != (hawk_uintptr_t)SIG_IGN && g_sig_state[sig].old_handler != (hawk_uintptr_t)SIG_DFL) { @@ -687,16 +687,16 @@ static void trace_exec (hawk_sed_t* sed, hawk_sed_tracer_op_t op, const hawk_sed /* TODO: use function to get hold space and pattern space and print them */ case HAWK_SED_TRACER_MATCH: - hawk_fprintf (HAWK_STDERR, HAWK_T("%s:%lu [%c] MA\n"), - ((cmd->lid && cmd->lid[0])? cmd->lid: HAWK_T("<>")), + hawk_fprintf (HAWK_STDERR, HAWK_T("%s:%lu [%c] MA\n"), + ((cmd->lid && cmd->lid[0])? cmd->lid: HAWK_T("<>")), (unsigned long)cmd->loc.line, cmd->type ); break; case HAWK_SED_TRACER_EXEC: - hawk_fprintf (HAWK_STDERR, HAWK_T("%s:%lu [%c] EC\n"), - ((cmd->lid && cmd->lid[0])? cmd->lid: HAWK_T("<>")), + hawk_fprintf (HAWK_STDERR, HAWK_T("%s:%lu [%c] EC\n"), + ((cmd->lid && cmd->lid[0])? cmd->lid: HAWK_T("<>")), (unsigned long)cmd->loc.line, cmd->type ); @@ -845,12 +845,12 @@ static HAWK_INLINE int execute_hawk_sed (int argc, hawk_bch_t* argv[]) hawk_bch_t exprbuf[128]; errloc = hawk_sed_geterrloc(sed); - + if (g_script.io[script_count].type == HAWK_SED_IOSTD_FILEB) { target = g_script.io[script_count].u.fileb.path; } - else + else { /* i dont' use HAWK_SED_IOSTD_SIO for input */ HAWK_ASSERT (g_script.io[script_count].type == HAWK_SED_IOSTD_BCS); @@ -925,7 +925,7 @@ static HAWK_INLINE int execute_hawk_sed (int argc, hawk_bch_t* argv[]) { hawk_sed_iostd_t in[2]; hawk_bch_t* tmpl_tmpfile; - + in[0].type = HAWK_SED_IOSTD_FILEB; in[0].u.fileb.path = xarg.ptr[inpos]; in[0].u.fileb.cmgr = g_infile_cmgr; @@ -963,7 +963,7 @@ static HAWK_INLINE int execute_hawk_sed (int argc, hawk_bch_t* argv[]) ); if (out_inplace.u.sio == HAWK_NULL) { - if (retried) + if (retried) { print_error ("cannot open %s\n", tmpl_tmpfile); hawk_sed_freemem (sed, tmpl_tmpfile); @@ -991,7 +991,7 @@ static HAWK_INLINE int execute_hawk_sed (int argc, hawk_bch_t* argv[]) { if (output) hawk_sio_close (output->u.sio); - if (tmpl_tmpfile) + if (tmpl_tmpfile) { unlink (tmpl_tmpfile); hawk_sed_freemem (sed, tmpl_tmpfile); @@ -1069,7 +1069,7 @@ static HAWK_INLINE int execute_hawk_sed (int argc, hawk_bch_t* argv[]) else { /* arrange to be able to specify cmgr. - * if not for cmgr, i could simply pass HAWK_NULL + * if not for cmgr, i could simply pass HAWK_NULL * to hawk_sed_execstd() below like * xx = hawk_sed_execstd (sed, in, HAWK_NULL); */ out.type = HAWK_SED_IOSTD_FILEB; diff --git a/lib/arr.c b/lib/arr.c index 310f2adb..58dacea6 100644 --- a/lib/arr.c +++ b/lib/arr.c @@ -52,7 +52,7 @@ int hawk_arr_dflcomp (hawk_arr_t* arr, const void* dptr1, hawk_oow_t dlen1, cons min = (dlen1 < dlen2)? dlen1: dlen2; n = HAWK_MEMCMP(dptr1, dptr2, TOB(arr,min)); - if (n == 0 && dlen1 != dlen2) + if (n == 0 && dlen1 != dlen2) { n = (dlen1 > dlen2)? 1: -1; } @@ -73,7 +73,7 @@ static HAWK_INLINE slot_t* alloc_slot (hawk_arr_t* arr, void* dptr, hawk_oow_t d else if (arr->style->copier == HAWK_ARR_COPIER_INLINE) { n = (slot_t*)hawk_gem_allocmem(arr->gem, HAWK_SIZEOF(slot_t) + TOB(arr,dlen)); - if (HAWK_UNLIKELY(!n)) return HAWK_NULL; + if (HAWK_UNLIKELY(!n)) return HAWK_NULL; HAWK_MEMCPY (n + 1, dptr, TOB(arr,dlen)); /* copy data contents */ DPTR(n) = n + 1; @@ -83,14 +83,14 @@ static HAWK_INLINE slot_t* alloc_slot (hawk_arr_t* arr, void* dptr, hawk_oow_t d n = (slot_t*)hawk_gem_allocmem(arr->gem, HAWK_SIZEOF(slot_t)); if (HAWK_UNLIKELY(!n)) return HAWK_NULL; DPTR(n) = arr->style->copier(arr, dptr, dlen); /* call the custom copier */ - if (HAWK_UNLIKELY(!DPTR(n))) + if (HAWK_UNLIKELY(!DPTR(n))) { hawk_gem_freemem (arr->gem, n); return HAWK_NULL; } } - DLEN(n) = dlen; + DLEN(n) = dlen; return n; } @@ -180,7 +180,7 @@ int hawk_arr_getscale (hawk_arr_t* arr) void hawk_arr_setscale (hawk_arr_t* arr, int scale) { - /* The scale should be larger than 0 and less than or equal to the + /* The scale should be larger than 0 and less than or equal to the * maximum value that the hawk_uint8_t type can hold */ HAWK_ASSERT (scale > 0 && scale <= HAWK_TYPE_MAX(hawk_uint8_t)); @@ -224,12 +224,12 @@ hawk_arr_t* hawk_arr_setcapa (hawk_arr_t* arr, hawk_oow_t capa) HAWK_ASSERT (arr->size <= capa); } - if (capa > 0) + if (capa > 0) { tmp = (slot_t**)hawk_gem_reallocmem(arr->gem, arr->slot, HAWK_SIZEOF(*arr->slot) * capa); if (HAWK_UNLIKELY(!tmp)) return HAWK_NULL; } - else + else { if (arr->slot) { @@ -245,7 +245,7 @@ hawk_arr_t* hawk_arr_setcapa (hawk_arr_t* arr, hawk_oow_t capa) arr->slot = tmp; arr->capa = capa; - + return arr; } @@ -253,7 +253,7 @@ hawk_oow_t hawk_arr_search (hawk_arr_t* arr, hawk_oow_t pos, const void* dptr, h { hawk_oow_t i; - for (i = pos; i < arr->size; i++) + for (i = pos; i < arr->size; i++) { if (arr->slot[i] == HAWK_NULL) continue; if (arr->style->comper(arr, DPTR(arr->slot[i]), DLEN(arr->slot[i]), dptr, dlen) == 0) return i; @@ -271,7 +271,7 @@ hawk_oow_t hawk_arr_rsearch (hawk_arr_t* arr, hawk_oow_t pos, const void* dptr, { if (pos >= arr->size) pos = arr->size - 1; - for (i = pos + 1; i-- > 0; ) + for (i = pos + 1; i-- > 0; ) { if (arr->slot[i] == HAWK_NULL) continue; if (arr->style->comper(arr, DPTR(arr->slot[i]), DLEN(arr->slot[i]), dptr, dlen) == 0) return i; @@ -297,10 +297,10 @@ hawk_oow_t hawk_arr_insert (hawk_arr_t* arr, hawk_oow_t pos, void* dptr, hawk_oo slot = alloc_slot(arr, dptr, dlen); if (HAWK_UNLIKELY(!slot)) return HAWK_ARR_NIL; - /* do resizeing if necessary. - * resizing is performed after slot allocation because that way, it + /* do resizeing if necessary. + * resizing is performed after slot allocation because that way, it * doesn't modify arr on any errors */ - if (pos >= arr->capa || arr->size >= arr->capa) + if (pos >= arr->capa || arr->size >= arr->capa) { hawk_oow_t capa, mincapa; @@ -313,12 +313,12 @@ hawk_oow_t hawk_arr_insert (hawk_arr_t* arr, hawk_oow_t pos, void* dptr, hawk_oo } else { - if (arr->capa <= 0) + if (arr->capa <= 0) { HAWK_ASSERT (arr->size <= 0); capa = HAWK_ALIGN_POW2(pos + 1, 64); } - else + else { hawk_oow_t bound = (pos >= arr->size)? pos: arr->size; capa = HAWK_ALIGN_POW2(bound + 1, 64); @@ -338,7 +338,7 @@ hawk_oow_t hawk_arr_insert (hawk_arr_t* arr, hawk_oow_t pos, void* dptr, hawk_oo } capa--; /* let it retry after lowering the capacity */ - } + } while (1); if (pos >= arr->capa || arr->size >= arr->capa) /* can happen if the sizer() callback isn't good enough */ @@ -371,7 +371,7 @@ hawk_oow_t hawk_arr_update (hawk_arr_t* arr, hawk_oow_t pos, void* dptr, hawk_oo { slot_t* c; - if (pos >= arr->size) + if (pos >= arr->size) { hawk_gem_seterrnum (arr->gem, HAWK_NULL, HAWK_EINVAL); return HAWK_ARR_NIL; @@ -467,7 +467,7 @@ void hawk_arr_clear (hawk_arr_t* arr) { hawk_oow_t i; - for (i = 0; i < arr->size; i++) + for (i = 0; i < arr->size; i++) { slot_t* c = arr->slot[i]; if (c != HAWK_NULL) @@ -489,7 +489,7 @@ hawk_oow_t hawk_arr_walk (hawk_arr_t* arr, walker_t walker, void* ctx) if (arr->size <= 0) return 0; - while (1) + while (1) { if (arr->slot[i]) { @@ -499,12 +499,12 @@ hawk_oow_t hawk_arr_walk (hawk_arr_t* arr, walker_t walker, void* ctx) if (w == HAWK_ARR_WALK_STOP) break; - if (w == HAWK_ARR_WALK_FORWARD) + if (w == HAWK_ARR_WALK_FORWARD) { i++; if (i >= arr->size) break; } - if (w == HAWK_ARR_WALK_BACKWARD) + if (w == HAWK_ARR_WALK_BACKWARD) { if (i <= 0) break; i--; @@ -522,9 +522,9 @@ hawk_oow_t hawk_arr_rwalk (hawk_arr_t* arr, walker_t walker, void* ctx) if (arr->size <= 0) return 0; i = arr->size - 1; - while (1) + while (1) { - if (arr->slot[i] != HAWK_NULL) + if (arr->slot[i] != HAWK_NULL) { w = walker (arr, i, ctx); nwalks++; @@ -532,12 +532,12 @@ hawk_oow_t hawk_arr_rwalk (hawk_arr_t* arr, walker_t walker, void* ctx) if (w == HAWK_ARR_WALK_STOP) break; - if (w == HAWK_ARR_WALK_FORWARD) + if (w == HAWK_ARR_WALK_FORWARD) { i++; if (i >= arr->size) break; } - if (w == HAWK_ARR_WALK_BACKWARD) + if (w == HAWK_ARR_WALK_BACKWARD) { if (i <= 0) break; i--; @@ -596,7 +596,7 @@ static hawk_oow_t sift_up (hawk_arr_t* arr, hawk_oow_t index) n = arr->style->comper(arr, DPTR(tmp), DLEN(tmp), DPTR(arr->slot[parent]), DLEN(arr->slot[parent])); if (n <= 0) break; - } + } arr->slot[index] = tmp; HEAP_UPDATE_POS (arr, index); diff --git a/lib/chr.c b/lib/chr.c index c2d4c6aa..6507a321 100644 --- a/lib/chr.c +++ b/lib/chr.c @@ -108,7 +108,7 @@ int hawk_is_uch_blank (hawk_uch_t c) hawk_uch_t hawk_to_uch_upper (hawk_uch_t c) { hawk_uchu_t uc = (hawk_uchu_t)c; - if (uc >= 0 && uc <= UCH_CASE_MAX) + if (uc >= 0 && uc <= UCH_CASE_MAX) { uch_case_page_t* page; page = uch_case_map[UCH_CASE_MAP_INDEX(uc)]; @@ -120,7 +120,7 @@ hawk_uch_t hawk_to_uch_upper (hawk_uch_t c) hawk_uch_t hawk_to_uch_lower (hawk_uch_t c) { hawk_uchu_t uc = (hawk_uchu_t)c; - if (uc >= 0 && uc <= UCH_CASE_MAX) + if (uc >= 0 && uc <= UCH_CASE_MAX) { uch_case_page_t* page; page = uch_case_map[UCH_CASE_MAP_INDEX(uc)]; @@ -219,17 +219,17 @@ int hawk_ucstr_to_uch_prop (const hawk_uch_t* name, hawk_uch_prop_t* id) kwp = &prop_tab[mid]; n = hawk_comp_ucstr_bcstr(name, kwp->name, 0); - if (n > 0) + if (n > 0) { /* if left, right, mid were of hawk_oow_t, - * you would need the following line. + * you would need the following line. if (mid == 0) break; */ right = mid - 1; } else if (n < 0) left = mid + 1; else - { + { *id = kwp->class; return 0; } @@ -251,17 +251,17 @@ int hawk_uchars_to_uch_prop (const hawk_uch_t* name, hawk_oow_t len, hawk_uch_pr kwp = &prop_tab[mid]; n = hawk_comp_uchars_bcstr(name, len, kwp->name, 0); - if (n < 0) + if (n < 0) { /* if left, right, mid were of hawk_oow_t, - * you would need the following line. + * you would need the following line. if (mid == 0) break; */ right = mid - 1; } else if (n > 0) left = mid + 1; - else - { + else + { *id = kwp->class; return 0; } @@ -285,17 +285,17 @@ int hawk_bcstr_to_bch_prop (const hawk_bch_t* name, hawk_bch_prop_t* id) kwp = &prop_tab[mid]; n = hawk_comp_bcstr(name, kwp->name, 0); - if (n > 0) + if (n > 0) { /* if left, right, mid were of hawk_oow_t, - * you would need the following line. + * you would need the following line. if (mid == 0) break; */ right = mid - 1; } else if (n < 0) left = mid + 1; else - { + { *id = kwp->class; return 0; } @@ -317,17 +317,17 @@ int hawk_bchars_to_bch_prop (const hawk_bch_t* name, hawk_oow_t len, hawk_bch_pr kwp = &prop_tab[mid]; n = hawk_comp_bchars_bcstr(name, len, kwp->name, 0); - if (n < 0) + if (n < 0) { /* if left, right, mid were of hawk_oow_t, - * you would need the following line. + * you would need the following line. if (mid == 0) break; */ right = mid - 1; } else if (n > 0) left = mid + 1; else - { + { *id = kwp->class; return 0; } @@ -339,16 +339,16 @@ int hawk_bchars_to_bch_prop (const hawk_bch_t* name, hawk_oow_t len, hawk_bch_pr /* ----------------------------------------------------------------------- */ /* - * See http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c + * See http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c */ -struct interval +struct interval { int first; int last; }; /* auxiliary function for binary search in interval table */ -static int bisearch(hawk_uch_t ucs, const struct interval *table, int max) +static int bisearch(hawk_uch_t ucs, const struct interval *table, int max) { int min = 0; int mid; @@ -473,7 +473,7 @@ int hawk_get_ucwidth (hawk_uch_t uc) (uc >= 0xff00 && uc <= 0xff60) || /* Fullwidth Forms */ (uc >= 0xffe0 && uc <= 0xffe6) #if (HAWK_SIZEOF_UCH_T > 2) - || + || (uc >= 0x20000 && uc <= 0x2fffd) || (uc >= 0x30000 && uc <= 0x3fffd) #endif @@ -483,5 +483,5 @@ int hawk_get_ucwidth (hawk_uch_t uc) } } - return 1; + return 1; } diff --git a/lib/cli-imp.h b/lib/cli-imp.h index d4f96be7..f9825860 100644 --- a/lib/cli-imp.h +++ b/lib/cli-imp.h @@ -25,7 +25,7 @@ /* this file is supposed to be included by opt.c multiple times */ -/* +/* * hawk_getopt is based on BSD getopt. * -------------------------------------------------------------------------- * @@ -69,18 +69,18 @@ xci_t xgetcli (int argc, xch_t* const* argv, xcli_t* opt) opt->arg = HAWK_NULL; opt->lngopt = HAWK_NULL; - if (opt->cur == HAWK_NULL) + if (opt->cur == HAWK_NULL) { opt->cur = XEMSG; opt->ind = 1; } - if (*opt->cur == '\0') + if (*opt->cur == '\0') { /* update scanning pointer */ - if (opt->ind >= argc || *(opt->cur = argv[opt->ind]) != '-') + if (opt->ind >= argc || *(opt->cur = argv[opt->ind]) != '-') { - /* All arguments have been processed or the current + /* All arguments have been processed or the current * argument doesn't start with a dash */ opt->cur = XEMSG; return XCI_EOF; @@ -121,7 +121,7 @@ xci_t xgetcli (int argc, xch_t* const* argv, xcli_t* opt) while (*end != '\0' && *end != '=') end++; - for (o = opt->lng; o->str; o++) + for (o = opt->lng; o->str; o++) { const xch_t* str = o->str; @@ -145,10 +145,10 @@ xci_t xgetcli (int argc, xch_t* const* argv, xcli_t* opt) } else if (opt->arg == HAWK_NULL) { - /* check if it has a remaining argument + /* check if it has a remaining argument * available */ - if (argc <= ++opt->ind) return BADARG; - /* If so, the next available argument is + if (argc <= ++opt->ind) return BADARG; + /* If so, the next available argument is * taken to be an option argument */ opt->arg = argv[opt->ind]; } @@ -158,12 +158,12 @@ xci_t xgetcli (int argc, xch_t* const* argv, xcli_t* opt) } /*if (*end == HAWK_T('=')) *end = HAWK_T('\0');*/ - opt->lngopt = opt->cur; + opt->lngopt = opt->cur; return BADCH; } if ((opt->opt = *opt->cur++) == ':' || - (oli = xfindcharincstr(opt->str, opt->opt)) == HAWK_NULL) + (oli = xfindcharincstr(opt->str, opt->opt)) == HAWK_NULL) { /* * if the user didn't specify '-' as an option, @@ -174,21 +174,21 @@ xci_t xgetcli (int argc, xch_t* const* argv, xcli_t* opt) return BADCH; } - if (*++oli != ':') + if (*++oli != ':') { /* don't need argument */ if (*opt->cur == '\0') opt->ind++; } - else + else { /* need an argument */ - if (*opt->cur != '\0') + if (*opt->cur != '\0') { /* no white space */ opt->arg = opt->cur; } - else if (argc <= ++opt->ind) + else if (argc <= ++opt->ind) { /* no arg */ opt->cur = XEMSG; diff --git a/lib/dir.c b/lib/dir.c index a44e3572..6cfc012a 100644 --- a/lib/dir.c +++ b/lib/dir.c @@ -25,13 +25,13 @@ #include #include "hawk-prv.h" -#if defined(_WIN32) +#if defined(_WIN32) # include -#elif defined(__OS2__) +#elif defined(__OS2__) # define INCL_DOSFILEMGR # define INCL_ERRORS # include -#elif defined(__DOS__) +#elif defined(__DOS__) # include # include #else @@ -65,7 +65,7 @@ struct hawk_dir_t WIN32_FIND_DATA wfd; #elif defined(__OS2__) HDIR h; - #if defined(FIL_STANDARDL) + #if defined(FIL_STANDARDL) FILEFINDBUF3L ffb; #else FILEFINDBUF3 ffb; @@ -265,7 +265,7 @@ static hawk_bch_t* make_mbsdos_path (hawk_dir_t* dir, const hawk_bch_t* mpath) { hawk_oow_t len; if ((len = hawk_becs_cpy(&dir->mbuf, mpath)) == (hawk_oow_t)-1 || - (!HAWK_ISPATHMBSEP(mpath[len - 1]) && + (!HAWK_ISPATHMBSEP(mpath[len - 1]) && !hawk_ismbsdrivecurpath(mpath) && hawk_becs_ccat(&dir->mbuf, '\\') == (hawk_oow_t)-1) || hawk_becs_cat(&dir->mbuf, "*.*") == (hawk_oow_t)-1) return HAWK_NULL; @@ -284,7 +284,7 @@ static hawk_uch_t* make_wcsdos_path (hawk_dir_t* dir, const hawk_uch_t* wpath) { hawk_oow_t len; if ((len = hawk_uecs_cpy (&dir->wbuf, wpath)) == (hawk_oow_t)-1 || - (!HAWK_ISPATHWCSEP(wpath[len - 1]) && + (!HAWK_ISPATHWCSEP(wpath[len - 1]) && !hawk_iswcsdrivecurpath(wpath) && hawk_uecs_ccat (&dir->wbuf, HAWK_UT('\\')) == (hawk_oow_t)-1) || hawk_uecs_cat (&dir->wbuf, HAWK_UT("*.*")) == (hawk_oow_t)-1) return HAWK_NULL; @@ -335,7 +335,7 @@ static int reset_to_path (hawk_dir_t* dir, const hawk_ooch_t* path) if (tptr == HAWK_NULL) return -1; dh = FindFirstFile(tptr, &wfd); - if (dh == INVALID_HANDLE_VALUE) + if (dh == INVALID_HANDLE_VALUE) { hawk_gem_seterrnum (dir->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); return -1; @@ -354,7 +354,7 @@ static int reset_to_path (hawk_dir_t* dir, const hawk_ooch_t* path) APIRET rc; const hawk_bch_t* mptr; HDIR h = HDIR_CREATE; - #if defined(FIL_STANDARDL) + #if defined(FIL_STANDARDL) FILEFINDBUF3L ffb = { 0 }; #else FILEFINDBUF3 ffb = { 0 }; @@ -378,12 +378,12 @@ static int reset_to_path (hawk_dir_t* dir, const hawk_ooch_t* path) rc = DosFindFirst ( mptr, - &h, + &h, FILE_DIRECTORY | FILE_READONLY, &ffb, HAWK_SIZEOF(dir->ffb), &count, - #if defined(FIL_STANDARDL) + #if defined(FIL_STANDARDL) FIL_STANDARDL #else FIL_STANDARD @@ -432,7 +432,7 @@ static int reset_to_path (hawk_dir_t* dir, const hawk_ooch_t* path) if (mptr == HAWK_NULL) return -1; rc = _dos_findfirst(mptr, _A_NORMAL | _A_SUBDIR, &f); - if (rc != 0) + if (rc != 0) { hawk_gem_seterrnum (dir->gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -474,7 +474,7 @@ static int reset_to_path (hawk_dir_t* dir, const hawk_ooch_t* path) } } - if (dp == HAWK_NULL) + if (dp == HAWK_NULL) { hawk_gem_seterrnum (dir->gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -484,7 +484,7 @@ static int reset_to_path (hawk_dir_t* dir, const hawk_ooch_t* path) dir->dp = dp; return 0; -#endif +#endif } int hawk_dir_reset (hawk_dir_t* dir, const hawk_ooch_t* path) @@ -494,7 +494,7 @@ int hawk_dir_reset (hawk_dir_t* dir, const hawk_ooch_t* path) if (dir->flags & HAWK_DIR_SORT) { hawk_arr_clear (dir->stab); - if (read_ahead_and_sort(dir, path) <= -1) + if (read_ahead_and_sort(dir, path) <= -1) { dir->status |= STATUS_SORT_ERR; return -1; @@ -520,10 +520,10 @@ static int read_dir_to_buf (hawk_dir_t* dir, void** name) /* skip . and .. */ while (IS_CURDIR(dir->wfd.cFileName) || IS_PREVDIR(dir->wfd.cFileName)) { - if (FindNextFile(dir->h, &dir->wfd) == FALSE) + if (FindNextFile(dir->h, &dir->wfd) == FALSE) { DWORD x = GetLastError(); - if (x == ERROR_NO_MORE_FILES) + if (x == ERROR_NO_MORE_FILES) { dir->status |= STATUS_DONE; return 0; @@ -559,7 +559,7 @@ static int read_dir_to_buf (hawk_dir_t* dir, void** name) *name = HAWK_UECS_PTR(&dir->wbuf); } - if (FindNextFile (dir->h, &dir->wfd) == FALSE) + if (FindNextFile (dir->h, &dir->wfd) == FALSE) { DWORD x = GetLastError(); if (x == ERROR_NO_MORE_FILES) dir->status |= STATUS_DONE; @@ -587,7 +587,7 @@ static int read_dir_to_buf (hawk_dir_t* dir, void** name) while (IS_CURDIR(dir->ffb.achName) || IS_PREVDIR(dir->ffb.achName)) { rc = DosFindNext (dir->h, &dir->ffb, HAWK_SIZEOF(dir->ffb), &dir->count); - if (rc == ERROR_NO_MORE_FILES) + if (rc == ERROR_NO_MORE_FILES) { dir->count = 0; return 0; @@ -611,7 +611,7 @@ static int read_dir_to_buf (hawk_dir_t* dir, void** name) if (mbs_to_wbuf (dir, dir->ffb.achName, &dir->wbuf) == HAWK_NULL) return -1; *name = HAWK_UECS_PTR(&dir->wbuf); } - + rc = DosFindNext (dir->h, &dir->ffb, HAWK_SIZEOF(dir->ffb), &dir->count); if (rc == ERROR_NO_MORE_FILES) dir->count = 0; @@ -637,7 +637,7 @@ static int read_dir_to_buf (hawk_dir_t* dir, void** name) { if (_dos_findnext (&dir->f) != 0) { - if (errno == ENOENT) + if (errno == ENOENT) { dir->status |= STATUS_DONE; return 0; @@ -688,7 +688,7 @@ static int read_dir_to_buf (hawk_dir_t* dir, void** name) read: errno = 0; de = HAWK_READDIR(dir->dp); - if (de == NULL) + if (de == NULL) { if (errno == 0) return 0; hawk_gem_seterrnum (dir->gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); @@ -751,7 +751,7 @@ int hawk_dir_read (hawk_dir_t* dir, hawk_dir_ent_t* ent) { if (dir->flags & HAWK_DIR_SORT) { - if (dir->status & STATUS_SORT_ERR) + if (dir->status & STATUS_SORT_ERR) { hawk_gem_seterrnum (dir->gem, HAWK_NULL, HAWK_ESTATE); return -1; diff --git a/lib/ecs-imp.h b/lib/ecs-imp.h index 853bb71e..cb493531 100644 --- a/lib/ecs-imp.h +++ b/lib/ecs-imp.h @@ -128,7 +128,7 @@ hawk_oow_t FN(setcapa) (str_t* str, hawk_oow_t capa) hawk_oow_t FN(setlen) (str_t* str, hawk_oow_t len) { if (len == str->val.len) return len; - if (len < str->val.len) + if (len < str->val.len) { str->val.len = len; str->val.ptr[len] = '\0'; @@ -191,7 +191,7 @@ hawk_oow_t FN(ncpy) (str_t* str, const char_t* s, hawk_oow_t len) /* if the current capacity is 0 and the string len to copy is 0 * we can't simply pass 'len' as the new capapcity. * ecs_setcapa() won't do anything the current capacity of 0 - * is the same as new capacity required. note that when str->capa + * is the same as new capacity required. note that when str->capa * is 0, str->val.ptr is HAWK_NULL. However, this is copying operation. * Copying a zero-length string may indicate that str->val.ptr must * not be HAWK_NULL. so I simply pass 1 as the new capacity */ @@ -213,11 +213,11 @@ hawk_oow_t FN(cat) (str_t* str, const char_t* s) static int FN(resize_for_ncat) (str_t* str, hawk_oow_t len) { - if (len > str->capa - str->val.len) + if (len > str->capa - str->val.len) { hawk_oow_t ncapa, mincapa; - /* let the minimum capacity be as large as + /* let the minimum capacity be as large as * to fit in the new substring */ mincapa = str->val.len + len; @@ -266,7 +266,7 @@ hawk_oow_t FN(ncat) (str_t* str, const char_t* s, hawk_oow_t len) if (n <= -1) return (hawk_oow_t)-1; if (n == 0) return str->val.len; - if (len > str->capa - str->val.len) + if (len > str->capa - str->val.len) { /* copy as many characters as the number of cells available. * if the capacity has been decreased, len is adjusted here */ @@ -358,7 +358,7 @@ hawk_oow_t FN(amend) (str_t* str, hawk_oow_t pos, hawk_oow_t len, const char_t* HAWK_MEMMOVE (&str->val.ptr[pos + repl_len], &str->val.ptr[pos + len], HAWK_SIZEOF(*repl) * (old_ecs_len - (pos + len))); } - if (repl_len > 0) HAWK_MEMMOVE (&str->val.ptr[pos], repl, HAWK_SIZEOF(*repl) * repl_len); + if (repl_len > 0) HAWK_MEMMOVE (&str->val.ptr[pos], repl, HAWK_SIZEOF(*repl) * repl_len); return str->val.len; } diff --git a/lib/err-sys.c b/lib/err-sys.c index ff941c45..2c580796 100644 --- a/lib/err-sys.c +++ b/lib/err-sys.c @@ -82,7 +82,7 @@ hawk_errnum_t hawk_syserr_to_errnum (hawk_intptr_t e) /* actually APIRET */ case ERROR_INVALID_NAME: return HAWK_EINVAL; case ERROR_ACCESS_DENIED: - case ERROR_SHARING_VIOLATION: + case ERROR_SHARING_VIOLATION: return HAWK_EACCES; case ERROR_FILE_NOT_FOUND: case ERROR_PATH_NOT_FOUND: @@ -96,7 +96,7 @@ hawk_errnum_t hawk_syserr_to_errnum (hawk_intptr_t e) /* actually APIRET */ } } -#elif defined(__DOS__) +#elif defined(__DOS__) hawk_errnum_t hawk_syserr_to_errnum (hawk_intptr_t e) { @@ -108,7 +108,7 @@ hawk_errnum_t hawk_syserr_to_errnum (hawk_intptr_t e) case ENOENT: return HAWK_ENOENT; case EEXIST: return HAWK_EEXIST; default: return HAWK_ESYSERR; - } + } } #elif defined(vms) || defined(__vms) @@ -130,25 +130,25 @@ hawk_errnum_t hawk_syserr_to_errnum (hawk_intptr_t e) switch (e) { #if defined(ENOMEM) - case ENOMEM: return HAWK_ENOMEM; + case ENOMEM: return HAWK_ENOMEM; #endif #if defined(EINVAL) - case EINVAL: return HAWK_EINVAL; + case EINVAL: return HAWK_EINVAL; #endif #if defined(EBUSY) - case EBUSY: return HAWK_EBUSY; + case EBUSY: return HAWK_EBUSY; #endif #if defined(EACCES) - case EACCES: return HAWK_EACCES; + case EACCES: return HAWK_EACCES; #endif #if defined(EPERM) - case EPERM: return HAWK_EPERM; + case EPERM: return HAWK_EPERM; #endif #if defined(EISDIR) - case EISDIR: return HAWK_EISDIR; + case EISDIR: return HAWK_EISDIR; #endif #if defined(ENOTDIR) - case ENOTDIR: return HAWK_ENOTDIR; + case ENOTDIR: return HAWK_ENOTDIR; #endif #if defined(ENXIO) case ENXIO: return HAWK_ENOENT; /* ENODEV mapped to ENOENT */ @@ -157,25 +157,25 @@ hawk_errnum_t hawk_syserr_to_errnum (hawk_intptr_t e) case ENODEV: return HAWK_ENOENT; /* ENODEV mapped to ENOENT */ #endif #if defined(ENOENT) - case ENOENT: return HAWK_ENOENT; + case ENOENT: return HAWK_ENOENT; #endif #if defined(EEXIST) - case EEXIST: return HAWK_EEXIST; + case EEXIST: return HAWK_EEXIST; #endif #if defined(EINTR) - case EINTR: return HAWK_EINTR; + case EINTR: return HAWK_EINTR; #endif #if defined(EPIPE) - case EPIPE: return HAWK_EPIPE; + case EPIPE: return HAWK_EPIPE; #endif #if defined(EINPROGRESS) - case EINPROGRESS: return HAWK_EINPROG; + case EINPROGRESS: return HAWK_EINPROG; #endif #if defined(ECHILD) - case ECHILD: return HAWK_ECHILD; + case ECHILD: return HAWK_ECHILD; #endif #if defined(ETIMEDOUT) - case ETIMEDOUT: return HAWK_ETMOUT; + case ETIMEDOUT: return HAWK_ETMOUT; #endif #if defined(EBADFD) case EBADFD: return HAWK_ESTATE; @@ -185,16 +185,16 @@ hawk_errnum_t hawk_syserr_to_errnum (hawk_intptr_t e) #endif #if defined(EWOULDBLOCK) && defined(EAGAIN) && (EWOULDBLOCK == EAGAIN) - case EAGAIN: return HAWK_EAGAIN; + case EAGAIN: return HAWK_EAGAIN; #else #if defined(EWOULDBLOCK) - case EWOULDBLOCK: return HAWK_EAGAIN; + case EWOULDBLOCK: return HAWK_EAGAIN; #endif #if defined(EAGAIN) - case EAGAIN: return HAWK_EAGAIN; + case EAGAIN: return HAWK_EAGAIN; #endif #endif - default: return HAWK_ESYSERR; + default: return HAWK_ESYSERR; } } diff --git a/lib/err.c b/lib/err.c index 0499b3d3..d460cd3c 100644 --- a/lib/err.c +++ b/lib/err.c @@ -62,7 +62,7 @@ const hawk_ooch_t* hawk_dfl_errstr (hawk_errnum_t errnum) HAWK_T("cannot read"), HAWK_T("cannot write"), HAWK_T("cannot close"), - + HAWK_T("block nested too deeply"), HAWK_T("expression nested too deeply"), @@ -209,7 +209,7 @@ const hawk_ooch_t* hawk_dfl_errstr (hawk_errnum_t errnum) HAWK_T("occurrence specifier too large"), HAWK_T("no previous regular expression"), HAWK_T("cut selector not valid"), - HAWK_T("I/O error with file '${0}'") + HAWK_T("I/O error with file '${0}'") }; static const hawk_ooch_t* unknown_error = HAWK_T("unknown error"); diff --git a/lib/fio.c b/lib/fio.c index 3358f2d2..5b6c231a 100644 --- a/lib/fio.c +++ b/lib/fio.c @@ -173,14 +173,14 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in if (!(flags & (HAWK_FIO_READ | HAWK_FIO_WRITE | HAWK_FIO_APPEND | HAWK_FIO_HANDLE))) { - /* one of HAWK_FIO_READ, HAWK_FIO_WRITE, HAWK_FIO_APPEND, + /* one of HAWK_FIO_READ, HAWK_FIO_WRITE, HAWK_FIO_APPEND, * and HAWK_FIO_HANDLE must be specified */ hawk_gem_seterrnum (fio->gem, HAWK_NULL, HAWK_EINVAL); return -1; } /* Store some flags for later use */ - if (flags & HAWK_FIO_NOCLOSE) + if (flags & HAWK_FIO_NOCLOSE) fio->status |= STATUS_NOCLOSE; if (flags & HAWK_FIO_TEMPORARY) @@ -190,7 +190,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in /*if (flags & (HAWK_FIO_HANDLE | HAWK_FIO_BCSTRPATH))*/ if (flags & HAWK_FIO_HANDLE) { - /* HAWK_FIO_TEMPORARY and HAWK_FIO_HANDLE/HAWK_FIO_BCSTRPATH + /* HAWK_FIO_TEMPORARY and HAWK_FIO_HANDLE/HAWK_FIO_BCSTRPATH * are mutually exclusive */ hawk_gem_seterrnum (fio->gem, HAWK_NULL, HAWK_EINVAL); return -1; @@ -201,13 +201,13 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in if (flags & HAWK_FIO_BCSTRPATH) { - for (temp_ptr_b = (hawk_bch_t*)path; *temp_ptr_b; temp_ptr_b++) + for (temp_ptr_b = (hawk_bch_t*)path; *temp_ptr_b; temp_ptr_b++) temp_no += *temp_ptr_b; if (temp_ptr_b - (hawk_bch_t*)path < 4) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, HAWK_EINVAL); - return -1; + return -1; } temp_ptr_b -= 4; @@ -215,15 +215,15 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in else { /* if HAWK_FIO_TEMPORARY is used, the path name must be writable. */ - for (temp_ptr = (hawk_ooch_t*)path; *temp_ptr; temp_ptr++) + for (temp_ptr = (hawk_ooch_t*)path; *temp_ptr; temp_ptr++) temp_no += *temp_ptr; /* The path name template must be at least 4 characters long * excluding the terminating null. this function fails if not */ - if (temp_ptr - path < 4) + if (temp_ptr - path < 4) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, HAWK_EINVAL); - return -1; + return -1; } temp_ptr -= 4; @@ -238,17 +238,17 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in temp_tries++; /* Fails after 5000 tries. 5000 randomly chosen */ - if (temp_tries > 5000) + if (temp_tries > 5000) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, HAWK_EINVAL); - return -1; + return -1; } - /* Generate the next random number to use to make a + /* Generate the next random number to use to make a * new path name */ temp_no = hawk_rand31(temp_no); - /* + /* * You must not pass a constant string for a path name * when HAWK_FIO_TEMPORARY is set, because it changes * the path name with a random number generated @@ -257,8 +257,8 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in { hawk_fmt_uintmax_to_bcstr ( temp_ptr_b, - 4, - temp_no % 0x10000, + 4, + temp_no % 0x10000, 16 | HAWK_FMT_UINTMAX_NOTRUNC | HAWK_FMT_UINTMAX_NONULL, 4, '\0', @@ -269,8 +269,8 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in { hawk_fmt_uintmax_to_oocstr ( temp_ptr, - 4, - temp_no % 0x10000, + 4, + temp_no % 0x10000, 16 | HAWK_FMT_UINTMAX_NOTRUNC | HAWK_FMT_UINTMAX_NONULL, 4, HAWK_T('\0'), @@ -278,7 +278,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in ); } } - + #if defined(_WIN32) if (flags & HAWK_FIO_HANDLE) { @@ -339,9 +339,9 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in if (flags & HAWK_FIO_NOSHDELETE) share_mode &= ~FILE_SHARE_DELETE; - if (!(mode & HAWK_FIO_WUSR)) + if (!(mode & HAWK_FIO_WUSR)) flag_and_attr = FILE_ATTRIBUTE_READONLY; - if (flags & HAWK_FIO_SYNC) + if (flags & HAWK_FIO_SYNC) flag_and_attr |= FILE_FLAG_WRITE_THROUGH; #if defined(FILE_FLAG_OPEN_REPARSE_POINT) @@ -350,15 +350,15 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in #endif /* these two are just hints to OS */ - if (flags & HAWK_FIO_RANDOM) + if (flags & HAWK_FIO_RANDOM) flag_and_attr |= FILE_FLAG_RANDOM_ACCESS; - if (flags & HAWK_FIO_SEQUENTIAL) + if (flags & HAWK_FIO_SEQUENTIAL) flag_and_attr |= FILE_FLAG_SEQUENTIAL_SCAN; if (flags & HAWK_FIO_BCSTRPATH) { handle = CreateFileA( - (const hawk_bch_t*)path, desired_access, share_mode, + (const hawk_bch_t*)path, desired_access, share_mode, HAWK_NULL, /* set noinherit by setting no secattr */ creation_disposition, flag_and_attr, 0 ); @@ -366,15 +366,15 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in else { handle = CreateFile( - path, desired_access, share_mode, + path, desired_access, share_mode, HAWK_NULL, /* set noinherit by setting no secattr */ creation_disposition, flag_and_attr, 0 ); } - if (handle == INVALID_HANDLE_VALUE) + if (handle == INVALID_HANDLE_VALUE) { DWORD e = GetLastError(); - if (!fellback && e == ERROR_INVALID_PARAMETER && + if (!fellback && e == ERROR_INVALID_PARAMETER && ((share_mode & FILE_SHARE_DELETE) || (flags & HAWK_FIO_APPEND))) { /* old windows fails with ERROR_INVALID_PARAMETER @@ -389,11 +389,11 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in desired_access &= ~FILE_APPEND_DATA; desired_access |= GENERIC_WRITE; } - + if (flags & HAWK_FIO_BCSTRPATH) { handle = CreateFileA( - (const hawk_bch_t*)path, desired_access, share_mode, + (const hawk_bch_t*)path, desired_access, share_mode, HAWK_NULL, /* set noinherit by setting no secattr */ creation_disposition, flag_and_attr, 0 ); @@ -401,12 +401,12 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in else { handle = CreateFile( - path, desired_access, share_mode, + path, desired_access, share_mode, HAWK_NULL, /* set noinherit by setting no secattr */ creation_disposition, flag_and_attr, 0 ); } - if (handle == INVALID_HANDLE_VALUE) + if (handle == INVALID_HANDLE_VALUE) { i if (flags & HAWK_FIO_TEMPORARY) goto retry_temporary; hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); @@ -470,7 +470,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in path_mb = hawk_gem_duputobcstr(fio->gem, path, HAWK_NUL); if (path_mb == HAWK_NULL) return -1; } - else if (px <= -1) + else if (px <= -1) { return -1; } @@ -498,7 +498,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in { open_action = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW; } - else + else { open_action = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW; } @@ -517,7 +517,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in else if (flags & HAWK_FIO_WRITE) open_mode |= OPEN_ACCESS_WRITEONLY; open_attr = (mode & HAWK_FIO_WUSR)? FILE_NORMAL: FILE_READONLY; - + #if defined(FIL_STANDARDL) if (dos_open_l) { @@ -533,7 +533,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in open_attr, /* attribute */ open_action, /* action if it exists */ open_mode, /* open mode */ - 0L + 0L ); } else @@ -547,7 +547,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in open_attr, /* attribute */ open_action, /* action if it exists */ open_mode, /* open mode */ - 0L + 0L ); #if defined(FIL_STANDARDL) } @@ -559,7 +559,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in if (path_mb != path_mb_buf) hawk_gem_freemem (fio->gem, path_mb); #endif - if (ret != NO_ERROR) + if (ret != NO_ERROR) { if (flags & HAWK_FIO_TEMPORARY) goto retry_temporary; hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(ret)); @@ -599,12 +599,12 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in px = hawk_gem_convutobcstr(fio->gem, path, &wl, path_mb, &ml); if (px == -2) { - /* static buffer size not enough. + /* static buffer size not enough. * switch to dynamic allocation */ path_mb = hawk_gem_duputobcstr(fio->gem, path, HAWK_NULL); if (path_mb == HAWK_NULL) return -1; } - else if (px <= -1) + else if (px <= -1) { return -1; } @@ -630,7 +630,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in if (flags & HAWK_FIO_EXCLUSIVE) oflags |= O_EXCL; oflags |= O_BINARY | O_NOINHERIT; - + if (mode & HAWK_FIO_RUSR) permission |= S_IREAD; if (mode & HAWK_FIO_WUSR) permission |= S_IWRITE; @@ -646,7 +646,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in if (path_mb != path_mb_buf) hawk_gem_freemem (fio->gem, path_mb); #endif - if (handle <= -1) + if (handle <= -1) { if (flags & HAWK_FIO_TEMPORARY) goto retry_temporary; hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); @@ -667,7 +667,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in struct FAB* fab; struct RAB* rab; unsigned long r0; - + #if defined(HAWK_OOCH_IS_BCH) const hawk_bch_t* path_mb = path; #else @@ -692,7 +692,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in path_mb = hawk_duputobcstr(fio->gem, path, mmgr); if (path_mb == HAWK_NULL) return -1; } - else if (px <= -1) + else if (px <= -1) { return -1; } @@ -724,16 +724,16 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in fab->fab$b_fac = FAB$M_NIL; if (flags & HAWK_FIO_READ) fab->fab$b_fac |= FAB$M_GET; if (flags & (HAWK_FIO_WRITE | HAWK_FIO_APPEND)) fab->fab$b_fac |= FAB$M_PUT | FAB$M_TRN; /* put, truncate */ - + fab->fab$b_shr |= FAB$M_SHRPUT | FAB$M_SHRGET; /* FAB$M_NIL */ if (flags & HAWK_FIO_NOSHREAD) fab->fab$b_shr &= ~FAB$M_SHRGET; if (flags & HAWK_FIO_NOSHWRITE) fab->fab$b_shr &= ~FAB$M_SHRPUT; if (flags & HAWK_FIO_APPEND) rab->rab$l_rop |= RAB$M_EOF; - if (flags & HAWK_FIO_CREATE) + if (flags & HAWK_FIO_CREATE) { - if (flags & HAWK_FIO_EXCLUSIVE) + if (flags & HAWK_FIO_EXCLUSIVE) fab->fab$l_fop &= ~FAB$M_CIF; else fab->fab$l_fop |= FAB$M_CIF; @@ -814,7 +814,7 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in path_mb = hawk_gem_duputobcstr(fio->gem, path, HAWK_NULL); if (path_mb == HAWK_NULL) return -1; } - else if (px <= -1) + else if (px <= -1) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, HAWK_EINVAL); return -1; @@ -864,12 +864,12 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in #if defined(HAWK_OOCH_IS_BCH) /* nothing to do */ #else - if (path_mb != path_mb_buf && path_mb != (hawk_bch_t*)path) + if (path_mb != path_mb_buf && path_mb != (hawk_bch_t*)path) { hawk_gem_freemem (fio->gem, path_mb); } #endif - if (handle == -1) + if (handle == -1) { if (flags & HAWK_FIO_TEMPORARY) goto retry_temporary; hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); @@ -885,11 +885,11 @@ int hawk_fio_init (hawk_fio_t* fio, hawk_gem_t* gem, const hawk_ooch_t* path, in /* set some file access hints */ #if defined(POSIX_FADV_RANDOM) - if (flags & HAWK_FIO_RANDOM) + if (flags & HAWK_FIO_RANDOM) posix_fadvise (handle, 0, 0, POSIX_FADV_RANDOM); #endif #if defined(POSIX_FADV_SEQUENTIAL) - if (flags & HAWK_FIO_SEQUENTIAL) + if (flags & HAWK_FIO_SEQUENTIAL) posix_fadvise (handle, 0, 0, POSIX_FADV_SEQUENTIAL); #endif } @@ -986,7 +986,7 @@ hawk_fio_off_t hawk_fio_seek (hawk_fio_t* fio, hawk_fio_off_t offset, hawk_fio_o pos.ulHi = (ULONG)(offset>>32); ret = dos_set_file_ptr_l (fio->handle, pos, seek_map[origin], &newpos); - if (ret != NO_ERROR) + if (ret != NO_ERROR) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(ret)); return (hawk_fio_off_t)-1; @@ -1001,7 +1001,7 @@ hawk_fio_off_t hawk_fio_seek (hawk_fio_t* fio, hawk_fio_off_t offset, hawk_fio_o APIRET ret; ret = DosSetFilePtr (fio->handle, offset, seek_map[origin], &newpos); - if (ret != NO_ERROR) + if (ret != NO_ERROR) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(ret)); return (hawk_fio_off_t)-1; @@ -1015,7 +1015,7 @@ hawk_fio_off_t hawk_fio_seek (hawk_fio_t* fio, hawk_fio_off_t offset, hawk_fio_o #elif defined(__DOS__) static int seek_map[] = { - SEEK_SET, + SEEK_SET, SEEK_CUR, SEEK_END }; @@ -1029,7 +1029,7 @@ hawk_fio_off_t hawk_fio_seek (hawk_fio_t* fio, hawk_fio_off_t offset, hawk_fio_o #else static int seek_map[] = { - SEEK_SET, + SEEK_SET, SEEK_CUR, SEEK_END }; @@ -1059,7 +1059,7 @@ int hawk_fio_truncate (hawk_fio_t* fio, hawk_fio_off_t size) { #if defined(_WIN32) if (hawk_fio_seek (fio, size, HAWK_FIO_BEGIN) == (hawk_fio_off_t)-1) return -1; - if (SetEndOfFile(fio->handle) == FALSE) + if (SetEndOfFile(fio->handle) == FALSE) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); return -1; @@ -1106,7 +1106,7 @@ int hawk_fio_truncate (hawk_fio_t* fio, hawk_fio_off_t size) unsigned long r0; struct RAB* rab = (struct RAB*)fio->handle; - + if ((r0 = sys$rewind (rab, 0, 0)) != RMS$_NORMAL || (r0 = sys$truncate (rab, 0, 0)) != RMS$_NORMAL) { @@ -1135,14 +1135,14 @@ hawk_ooi_t hawk_fio_read (hawk_fio_t* fio, void* buf, hawk_oow_t size) DWORD count; - if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(DWORD))) + if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(DWORD))) size = HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(DWORD); if (ReadFile (fio->handle, buf, (DWORD)size, &count, HAWK_NULL) == FALSE) { DWORD e = GetLastError(); /* special case when ReadFile returns failure with ERROR_BROKEN_PIPE. * this happens when an anonymous pipe is a standard input for redirection. - * assuming that ERROR_BROKEN_PIPE doesn't occur with normal + * assuming that ERROR_BROKEN_PIPE doesn't occur with normal * input streams, i treat the condition as a normal EOF indicator. */ if ((fio->status & STATUS_WIN32_STDIN) && e == ERROR_BROKEN_PIPE) return 0; hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(e)); @@ -1154,10 +1154,10 @@ hawk_ooi_t hawk_fio_read (hawk_fio_t* fio, void* buf, hawk_oow_t size) APIRET ret; ULONG count; - if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(ULONG))) + if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(ULONG))) size = HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(ULONG); ret = DosRead (fio->handle, buf, (ULONG)size, &count); - if (ret != NO_ERROR) + if (ret != NO_ERROR) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(ret)); return -1; @@ -1167,7 +1167,7 @@ hawk_ooi_t hawk_fio_read (hawk_fio_t* fio, void* buf, hawk_oow_t size) #elif defined(__DOS__) int n; - if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(unsigned int))) + if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(unsigned int))) size = HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(unsigned int); n = read (fio->handle, buf, size); if (n <= -1) hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); @@ -1220,9 +1220,9 @@ hawk_ooi_t hawk_fio_write (hawk_fio_t* fio, const void* data, hawk_oow_t size) #endif } - if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(DWORD))) + if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(DWORD))) size = HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(DWORD); - if (WriteFile (fio->handle, data, (DWORD)size, &count, HAWK_NULL) == FALSE) + if (WriteFile (fio->handle, data, (DWORD)size, &count, HAWK_NULL) == FALSE) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); return -1; @@ -1255,11 +1255,11 @@ hawk_ooi_t hawk_fio_write (hawk_fio_t* fio, const void* data, hawk_oow_t size) #endif } - if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(ULONG))) + if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(ULONG))) size = HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(ULONG); - ret = DosWrite(fio->handle, + ret = DosWrite(fio->handle, (PVOID)data, (ULONG)size, &count); - if (ret != NO_ERROR) + if (ret != NO_ERROR) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(ret)); return -1; @@ -1269,7 +1269,7 @@ hawk_ooi_t hawk_fio_write (hawk_fio_t* fio, const void* data, hawk_oow_t size) #elif defined(__DOS__) int n; - if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(unsigned int))) + if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(unsigned int))) size = HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(unsigned int); n = write (fio->handle, data, size); if (n <= -1) hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); @@ -1307,7 +1307,7 @@ hawk_ooi_t hawk_fio_write (hawk_fio_t* fio, const void* data, hawk_oow_t size) #if defined(_WIN32) static int get_devname_from_handle ( - hawk_fio_t* fio, hawk_ooch_t* buf, hawk_oow_t len) + hawk_fio_t* fio, hawk_ooch_t* buf, hawk_oow_t len) { HANDLE map = NULL; void* mem = NULL; @@ -1315,10 +1315,10 @@ static int get_devname_from_handle ( HINSTANCE psapi; getmappedfilename_t getmappedfilename; - /* try to load psapi.dll dynamially for + /* try to load psapi.dll dynamially for * systems without it. direct linking to the library - * may end up with dependency failure on such systems. - * this way, the worst case is that this function simply + * may end up with dependency failure on such systems. + * this way, the worst case is that this function simply * fails. */ psapi = LoadLibrary (HAWK_T("PSAPI.DLL")); if (!psapi) @@ -1327,7 +1327,7 @@ static int get_devname_from_handle ( return -1; } - getmappedfilename = (getmappedfilename_t) + getmappedfilename = (getmappedfilename_t) GetProcAddress (psapi, HAWK_BT("GetMappedFileName")); if (!getmappedfilename) { @@ -1338,19 +1338,19 @@ static int get_devname_from_handle ( /* create a file mapping object */ map = CreateFileMapping ( - fio->handle, + fio->handle, NULL, PAGE_READONLY, - 0, + 0, 1, NULL ); - if (map == NULL) + if (map == NULL) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); FreeLibrary (psapi); return -1; - } + } /* create a file mapping to get the file name. */ mem = MapViewOfFile (map, FILE_MAP_READ, 0, 0, 1); @@ -1362,7 +1362,7 @@ static int get_devname_from_handle ( return -1; } - olen = getmappedfilename (GetCurrentProcess(), mem, buf, len); + olen = getmappedfilename (GetCurrentProcess(), mem, buf, len); if (olen == 0) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); @@ -1378,7 +1378,7 @@ 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; @@ -1394,8 +1394,8 @@ static int get_volname_from_handle (hawk_fio_t* fio, hawk_ooch_t* buf, hawk_oow_ n = GetLogicalDriveStrings(HAWK_COUNTOF(drives), drives); - if (n == 0 /* error */ || - n > HAWK_COUNTOF(drives) /* buffer small */) + if (n == 0 /* error */ || + n > HAWK_COUNTOF(drives) /* buffer small */) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); return -1; @@ -1424,7 +1424,7 @@ static int get_volname_from_handle (hawk_fio_t* fio, hawk_ooch_t* buf, hawk_oow_ } } } - + /* if the match is not found, the device name is returned * without translation */ return 0; @@ -1439,8 +1439,8 @@ int hawk_fio_chmod (hawk_fio_t* fio, int mode) hawk_ooch_t name[MAX_PATH]; /* it is a best effort implementation. if the file size is 0, - * it can't even get the file name from the handle and thus fails. - * if GENERIC_READ is not set in CreateFile, CreateFileMapping fails. + * it can't even get the file name from the handle and thus fails. + * if GENERIC_READ is not set in CreateFile, CreateFileMapping fails. * so if this fio is opened without HAWK_FIO_READ, this function fails. */ if (get_volname_from_handle (fio, name, HAWK_COUNTOF(name)) == -1) return -1; @@ -1476,7 +1476,7 @@ int hawk_fio_chmod (hawk_fio_t* fio, int mode) } if (!(mode & HAWK_FIO_WUSR)) flags = FILE_READONLY; - + stat.attrFile = flags; #if defined(FIL_STANDARDL) n = DosSetFileInfo(fio->handle, FIL_STANDARDL, &stat, size); @@ -1537,7 +1537,7 @@ int hawk_fio_sync (hawk_fio_t* fio) #elif defined(__OS2__) APIRET n; - n = DosResetBuffer (fio->handle); + n = DosResetBuffer (fio->handle); if (n != NO_ERROR) { hawk_gem_seterrnum (fio->gem, HAWK_NULL, hawk_syserr_to_errnum(n)); @@ -1572,7 +1572,7 @@ int hawk_fio_sync (hawk_fio_t* fio) int hawk_fio_lock (hawk_fio_t* fio, hawk_fio_lck_t* lck, int flags) { - /* TODO: hawk_fio_lock + /* TODO: hawk_fio_lock * struct flock fl; * fl.l_type = F_RDLCK, F_WRLCK; * HAWK_FCNTL (fio->handle, F_SETLK, &fl); @@ -1583,7 +1583,7 @@ int hawk_fio_lock (hawk_fio_t* fio, hawk_fio_lck_t* lck, int flags) int hawk_fio_unlock (hawk_fio_t* fio, hawk_fio_lck_t* lck, int flags) { - /* TODO: hawk_fio_unlock + /* TODO: hawk_fio_unlock * struct flock fl; * fl.l_type = F_UNLCK; * HAWK_FCNTL (fio->handle, F_SETLK, &fl); diff --git a/lib/fmt-imp.h b/lib/fmt-imp.h index 7323152f..aed2d502 100644 --- a/lib/fmt-imp.h +++ b/lib/fmt-imp.h @@ -23,7 +23,7 @@ */ static int fmt_uintmax ( - char_t* buf, int size, + char_t* buf, int size, hawk_uintmax_t value, int base_and_flags, int prec, char_t fillchar, char_t signchar, const char_t* prefix) { @@ -39,10 +39,10 @@ static int fmt_uintmax ( "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ": "0123456789abcdefghijklmnopqrstuvwxyz"; - if ((base_and_flags & HAWK_FMT_INTMAX_NOZERO) && value == 0) + if ((base_and_flags & HAWK_FMT_INTMAX_NOZERO) && value == 0) { - p = tmp; - if (base_and_flags & HAWK_FMT_INTMAX_ZEROLEAD) + p = tmp; + if (base_and_flags & HAWK_FMT_INTMAX_ZEROLEAD) { /* NOZERO emits no digit, ZEROLEAD emits 1 digit. * so it emits '0' */ @@ -61,7 +61,7 @@ static int fmt_uintmax ( hawk_uintmax_t v = value; /* store the resulting numeric string into 'tmp' first */ - p = tmp; + p = tmp; do { *p++ = xbasestr[v % base]; @@ -71,11 +71,11 @@ static int fmt_uintmax ( /* reslen is the length of the resulting string without padding. */ reslen = (int)(p - tmp); - + /* precision specified the minum number of digits to produce. - * so if the precision is larger that the digits produced, + * so if the precision is larger that the digits produced, * reslen should be adjusted to precision */ - if (prec > reslen) + if (prec > reslen) { /* if the precision is greater than the actual digits * made from the value, 0 is inserted in front. @@ -84,12 +84,12 @@ static int fmt_uintmax ( preczero = prec - reslen; reslen = prec; } - else + else { preczero = 0; - if ((base_and_flags & HAWK_FMT_INTMAX_ZEROLEAD) && value != 0) + if ((base_and_flags & HAWK_FMT_INTMAX_ZEROLEAD) && value != 0) { - /* if value is zero, 0 is emitted from it. + /* if value is zero, 0 is emitted from it. * so ZEROLEAD don't need to add another 0. */ preczero++; reslen++; @@ -135,10 +135,10 @@ static int fmt_uintmax ( if (prefix) while (*prefix && bp < be) *bp++ = *prefix++; /* add 0s for precision */ - while (preczero > 0 && bp < be) - { + while (preczero > 0 && bp < be) + { *bp++ = '0'; - preczero--; + preczero--; } /* copy the numeric string to the destination buffer */ @@ -167,10 +167,10 @@ static int fmt_uintmax ( if (prefix) while (*prefix && bp < be) *bp++ = *prefix++; /* add 0s for precision */ - while (preczero > 0 && bp < be) - { + while (preczero > 0 && bp < be) + { *bp++ = '0'; - preczero--; + preczero--; } /* copy the numeric string to the destination buffer */ @@ -192,10 +192,10 @@ static int fmt_uintmax ( if (prefix) while (*prefix && bp < be) *bp++ = *prefix++; /* add 0s for precision */ - while (preczero > 0 && bp < be) - { + while (preczero > 0 && bp < be) + { *bp++ = '0'; - preczero--; + preczero--; } /* copy the numeric string to the destination buffer */ @@ -211,10 +211,10 @@ static int fmt_uintmax ( if (prefix) while (*prefix && bp < be) *bp++ = *prefix++; /* add 0s for precision */ - while (preczero > 0 && bp < be) - { + while (preczero > 0 && bp < be) + { *bp++ = '0'; - preczero--; + preczero--; } /* copy the numeric string to the destination buffer */ diff --git a/lib/fmt.c b/lib/fmt.c index 4294e207..d547b96c 100644 --- a/lib/fmt.c +++ b/lib/fmt.c @@ -23,7 +23,7 @@ */ /* - * This file contains a formatted output routine derived from kvprintf() + * This file contains a formatted output routine derived from kvprintf() * of FreeBSD. It has been heavily modified and bug-fixed. */ @@ -68,7 +68,7 @@ #include /* for snrintf(). used for floating-point number formatting */ #if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200)) -# define snprintf _snprintf +# define snprintf _snprintf # if !defined(HAVE_SNPRINTF) # define HAVE_SNPRINTF # endif @@ -99,7 +99,7 @@ enum /* __float128 */ LF_QD = (1 << 8), - /* intmax or fltmax passed as a pointer - introduced to work around the issue where + /* intmax or fltmax passed as a pointer - introduced to work around the issue where * __float128 value is not passed properly via va_list. for example, the following clode * compiled with clang -O1, -O2, -O3, etc produced a wrong value instead of 9.200000 @@ -138,7 +138,7 @@ $ clang -O0 -o a a.c $ ./a 9.200000 - * the same code printed a correct value without compiler optimization. + * the same code printed a correct value without compiler optimization. * * passing a large value via a pointer is a safe way to work around this problem. * hawk_rtx_format() and hawk_rtx_formatmbs() pass 'jj' for a floating-pointer number @@ -153,7 +153,7 @@ static struct { hawk_uint16_t flag; /* for single occurrence */ hawk_uint16_t dflag; /* for double occurrence */ -} lm_tab[26] = +} lm_tab[26] = { { 0, 0 }, /* a */ { 0, 0 }, /* b */ @@ -184,7 +184,7 @@ static struct }; -enum +enum { FLAGC_DOT = (1 << 0), FLAGC_SPACE = (1 << 1), @@ -199,14 +199,14 @@ enum FLAGC_LENMOD = (1 << 10) /* length modifier */ }; -static const hawk_bch_t hex2ascii_lower[] = +static const hawk_bch_t hex2ascii_lower[] = { '0','1','2','3','4','5','6','7','8','9', 'a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z' }; -static const hawk_bch_t hex2ascii_upper[] = +static const hawk_bch_t hex2ascii_upper[] = { '0','1','2','3','4','5','6','7','8','9', 'A','B','C','D','E','F','G','H','I','J','K','L','M', @@ -233,7 +233,7 @@ static hawk_bch_t bch_nullstr[] = { '(','n','u','l','l', ')','\0' }; #include "fmt-imp.h" int hawk_fmt_intmax_to_bcstr ( - hawk_bch_t* buf, int size, + hawk_bch_t* buf, int size, hawk_intmax_t value, int base_and_flags, int prec, hawk_bch_t fillchar, const hawk_bch_t* prefix) { @@ -265,7 +265,7 @@ int hawk_fmt_intmax_to_bcstr ( } int hawk_fmt_uintmax_to_bcstr ( - hawk_bch_t* buf, int size, + hawk_bch_t* buf, int size, hawk_uintmax_t value, int base_and_flags, int prec, hawk_bch_t fillchar, const hawk_bch_t* prefix) { @@ -291,7 +291,7 @@ int hawk_fmt_uintmax_to_bcstr ( /* ==================== wide-char ===================================== */ int hawk_fmt_intmax_to_ucstr ( - hawk_uch_t* buf, int size, + hawk_uch_t* buf, int size, hawk_intmax_t value, int base_and_flags, int prec, hawk_uch_t fillchar, const hawk_uch_t* prefix) { @@ -323,7 +323,7 @@ int hawk_fmt_intmax_to_ucstr ( } int hawk_fmt_uintmax_to_ucstr ( - hawk_uch_t* buf, int size, + hawk_uch_t* buf, int size, hawk_uintmax_t value, int base_and_flags, int prec, hawk_uch_t fillchar, const hawk_uch_t* prefix) { @@ -485,10 +485,10 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) fmtptr = (const hawk_uint8_t*)fmtout->fmt_str; switch (fmtout->fmt_type) { - case HAWK_FMTOUT_FMT_TYPE_BCH: + case HAWK_FMTOUT_FMT_TYPE_BCH: fmtchsz = HAWK_SIZEOF_BCH_T; break; - case HAWK_FMTOUT_FMT_TYPE_UCH: + case HAWK_FMTOUT_FMT_TYPE_UCH: fmtchsz = HAWK_SIZEOF_UCH_T; break; } @@ -520,9 +520,9 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) { const hawk_bch_t* start, * end; start = end = (const hawk_bch_t*)fmtptr; - while ((bch = *end++) != '%' || stop) + while ((bch = *end++) != '%' || stop) { - if (bch == '\0') + if (bch == '\0') { PUT_BCS (fmtout, start, end - start - 1); goto done; @@ -538,9 +538,9 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) { const hawk_uch_t* start, * end; start = end = (const hawk_uch_t*)fmtptr; - while ((uch = *end++) != '%' || stop) + while ((uch = *end++) != '%' || stop) { - if (uch == '\0') + if (uch == '\0') { PUT_UCS (fmtout, start, end - start - 1); goto done; @@ -553,9 +553,9 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) goto handle_percent; handle_percent: - padc = ' '; + padc = ' '; width = 0; precision = 0; neg = 0; sign = 0; - lm_flag = 0; lm_dflag = 0; flagc = 0; + lm_flag = 0; lm_dflag = 0; flagc = 0; sprintn = sprintn_lower; reswitch: @@ -563,7 +563,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) * requested character type. */ switch (fmtout->fmt_type) { - case HAWK_FMTOUT_FMT_TYPE_BCH: + case HAWK_FMTOUT_FMT_TYPE_BCH: uch = *(const hawk_bch_t*)fmtptr; break; case HAWK_FMTOUT_FMT_TYPE_UCH: @@ -572,7 +572,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) } fmtptr += fmtchsz; - switch (uch) + switch (uch) { case '%': /* %% */ bch = uch; @@ -584,7 +584,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) flagc |= FLAGC_DOT; goto reswitch; - case '#': + case '#': if (flagc & (FLAGC_WIDTH | FLAGC_DOT | FLAGC_LENMOD)) goto invalid_format; flagc |= FLAGC_SHARP; goto reswitch; @@ -614,34 +614,34 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) flagc &= ~FLAGC_ZEROPAD; } } - + goto reswitch; case '*': /* take the length from the parameter */ - if (flagc & FLAGC_DOT) + if (flagc & FLAGC_DOT) { if (flagc & (FLAGC_STAR2 | FLAGC_PRECISION)) goto invalid_format; flagc |= FLAGC_STAR2; precision = va_arg(ap, hawk_ooi_t); /* this deviates from the standard printf that accepts 'int' */ - if (precision < 0) + if (precision < 0) { - /* if precision is less than 0, + /* if precision is less than 0, * treat it as if no .precision is specified */ flagc &= ~FLAGC_DOT; precision = 0; } - } - else + } + else { if (flagc & (FLAGC_STAR1 | FLAGC_WIDTH)) goto invalid_format; flagc |= FLAGC_STAR1; width = va_arg(ap, hawk_ooi_t); /* it deviates from the standard printf that accepts 'int' */ - if (width < 0) + if (width < 0) { /* - if (flagc & FLAGC_LEFTADJ) + if (flagc & FLAGC_LEFTADJ) flagc &= ~FLAGC_LEFTADJ; else */ @@ -665,12 +665,12 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) case '5': case '6': case '7': case '8': case '9': { if (flagc & FLAGC_LENMOD) goto invalid_format; - for (n = 0;; fmtptr += fmtchsz) + for (n = 0;; fmtptr += fmtchsz) { n = n * 10 + uch - '0'; switch (fmtout->fmt_type) { - case HAWK_FMTOUT_FMT_TYPE_BCH: + case HAWK_FMTOUT_FMT_TYPE_BCH: uch = *(const hawk_bch_t*)fmtptr; break; case HAWK_FMTOUT_FMT_TYPE_UCH: @@ -679,13 +679,13 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) } if (uch < '0' || uch > '9') break; } - if (flagc & FLAGC_DOT) + if (flagc & FLAGC_DOT) { if (flagc & FLAGC_STAR2) goto invalid_format; precision = n; flagc |= FLAGC_PRECISION; } - else + else { if (flagc & FLAGC_STAR1) goto invalid_format; width = n; @@ -724,7 +724,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) goto invalid_format; } } - else + else { lm_flag |= lm_tab[uch - 'a'].flag; goto reswitch; @@ -732,10 +732,10 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) break; case 'L': /* long double */ - if (flagc & FLAGC_LENMOD) + if (flagc & FLAGC_LENMOD) { /* conflict with other length modifier */ - goto invalid_format; + goto invalid_format; } flagc |= FLAGC_LENMOD; lm_flag |= LF_LD; @@ -745,7 +745,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) if (flagc & FLAGC_LENMOD) { /* conflict with other length modifier */ - goto invalid_format; + goto invalid_format; } flagc |= FLAGC_LENMOD; lm_flag |= LF_QD; @@ -767,12 +767,12 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) *(va_arg(ap, short int*)) = fmtout->count; else if (lm_flag & LF_C) /* hh */ *(va_arg(ap, char*)) = fmtout->count; - else if (flagc & FLAGC_LENMOD) + else if (flagc & FLAGC_LENMOD) goto invalid_format; else *(va_arg(ap, int*)) = fmtout->count; break; - + /* signed integer conversions */ case 'd': case 'i': /* signed conversion */ @@ -782,7 +782,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) /* end of signed integer conversions */ /* unsigned integer conversions */ - case 'o': + case 'o': base = 8; goto handle_nosign; case 'u': @@ -810,7 +810,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) case 'c': { /* zeropad must not take effect for 'c' */ - if (flagc & FLAGC_ZEROPAD) padc = ' '; + if (flagc & FLAGC_ZEROPAD) padc = ' '; if (lm_flag & LF_L) goto uppercase_c; #if defined(HAWK_OOCH_IS_UCH) if (lm_flag & (LF_J | LF_JJ)) goto uppercase_c; @@ -918,12 +918,12 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) const hawk_uint8_t* bsp; hawk_oow_t k_hex_width; - /* zeropad must not take effect for 'k' and 'K' - * + /* zeropad must not take effect for 'k' and 'K' + * * 'h' & 'l' is not used to differentiate hawk_bch_t and hawk_uch_t - * because 'k' means hawk_byte_t. - * 'l', results in uppercase hexadecimal letters. - * 'h' drops the leading \x in the output + * because 'k' means hawk_byte_t. + * 'l', results in uppercase hexadecimal letters. + * 'h' drops the leading \x in the output * -------------------------------------------------------- * hk -> \x + non-printable in lowercase hex * k -> all in lowercase hex @@ -968,9 +968,9 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (fmtout, padc, width); - while (n--) + while (n--) { - if ((lm_flag & LF_H) && BYTE_PRINTABLE(*bsp)) + if ((lm_flag & LF_H) && BYTE_PRINTABLE(*bsp)) { PUT_BCH (fmtout, *bsp, 1); } @@ -992,7 +992,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) case 'W': { /* unicode string in unicode escape sequence. - * + * * hw -> \uXXXX, \UXXXXXXXX, printable-byte(only in ascii range) * w -> \uXXXX, \UXXXXXXXX * lw -> all in \UXXXXXXXX @@ -1006,7 +1006,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) if (flagc & FLAGC_DOT) { /* if precision is specifed, it doesn't stop at the value of zero unlike 's' or 'S' */ - for (n = 0; n < precision; n++) + for (n = 0; n < precision; n++) { if ((lm_flag & LF_H) && BYTE_PRINTABLE(usp[n])) uwid = 1; else if (!(lm_flag & LF_L) && usp[n] <= 0xFFFF) uwid = 6; @@ -1027,13 +1027,13 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (fmtout, padc, width); - while (n--) + while (n--) { - if ((lm_flag & LF_H) && BYTE_PRINTABLE(*usp)) + if ((lm_flag & LF_H) && BYTE_PRINTABLE(*usp)) { PUT_OOCH(fmtout, *usp, 1); } - else if (!(lm_flag & LF_L) && *usp <= 0xFFFF) + else if (!(lm_flag & LF_L) && *usp <= 0xFFFF) { hawk_uint16_t u16 = *usp; int extra_flags = ((uch) == 'w'? HAWK_BYTE_TO_BCSTR_LOWERCASE: 0); @@ -1121,7 +1121,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) { /* limited to double or long double. use hawk_fltbas_t */ - /* precedence goes to double if sizeof(double) == sizeof(long double) + /* precedence goes to double if sizeof(double) == sizeof(long double) * for example, %Lf didn't work on some old platforms. * so i prefer the format specifier with no modifier. */ @@ -1185,18 +1185,18 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) if (flagc & FLAGC_ZEROPAD) fb.fmt.ptr[fmtlen++] = '0'; if (flagc & FLAGC_STAR1) fb.fmt.ptr[fmtlen++] = '*'; - else if (flagc & FLAGC_WIDTH) + else if (flagc & FLAGC_WIDTH) { fmtlen += hawk_fmt_uintmax_to_bcstr( - &fb.fmt.ptr[fmtlen], fb.fmt.capa - fmtlen, + &fb.fmt.ptr[fmtlen], fb.fmt.capa - fmtlen, width, 10, -1, '\0', HAWK_NULL); } if (flagc & FLAGC_DOT) fb.fmt.ptr[fmtlen++] = '.'; if (flagc & FLAGC_STAR2) fb.fmt.ptr[fmtlen++] = '*'; - else if (flagc & FLAGC_PRECISION) + else if (flagc & FLAGC_PRECISION) { fmtlen += hawk_fmt_uintmax_to_bcstr( - &fb.fmt.ptr[fmtlen], fb.fmt.capa - fmtlen, + &fb.fmt.ptr[fmtlen], fb.fmt.capa - fmtlen, precision, 10, -1, '\0', HAWK_NULL); } @@ -1213,7 +1213,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) #if defined(HAVE_SNPRINTF) /* nothing special here */ #else - /* best effort to avoid buffer overflow when no snprintf is available. + /* best effort to avoid buffer overflow when no snprintf is available. * i really can't do much if it happens. */ newcapa = precision + width + 32; if (fltout->capa < newcapa) @@ -1378,14 +1378,14 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) num = va_arg(ap, int); number: - if (sign && (hawk_intmax_t)num < 0) + if (sign && (hawk_intmax_t)num < 0) { neg = 1; num = -(hawk_intmax_t)num; } nbufp = sprintn(nbuf, num, base, &tmp); - if ((flagc & FLAGC_SHARP) && num != 0) + if ((flagc & FLAGC_SHARP) && num != 0) { if (base == 2 || base == 16) tmp += 2; /* 0b 0x */ else if (tmp == 8) tmp += 1; /* 0 */ @@ -1395,7 +1395,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) else if (flagc & FLAGC_SPACE) tmp++; numlen = (int)((const hawk_bch_t*)nbufp - (const hawk_bch_t*)nbuf); - if ((flagc & FLAGC_DOT) && precision > numlen) + if ((flagc & FLAGC_DOT) && precision > numlen) { /* extra zeros for precision specified */ tmp += (precision - numlen); @@ -1411,7 +1411,7 @@ static int fmt_outv (hawk_fmtout_t* fmtout, va_list ap) else if (flagc & FLAGC_SIGN) PUT_OOCH (fmtout, '+', 1); else if (flagc & FLAGC_SPACE) PUT_OOCH (fmtout, ' ', 1); - if ((flagc & FLAGC_SHARP) && num != 0) + if ((flagc & FLAGC_SHARP) && num != 0) { if (base == 2) { @@ -1574,11 +1574,11 @@ int hawk_ufmt_out (hawk_fmtout_t* fmtout, const hawk_uch_t* fmt, ...) return n; } -/* -------------------------------------------------------------------------- +/* -------------------------------------------------------------------------- * FORMATTED LOG OUTPUT * -------------------------------------------------------------------------- */ -/* i don't want an error raised inside the callback to override +/* i don't want an error raised inside the callback to override * the existing error number and message. */ #define log_write(hawk,mask,ptr,len) do { \ int shuterr = (hawk)->shuterr; \ @@ -1616,7 +1616,7 @@ redo: hawk_ooch_t* tmp; max = HAWK_TYPE_MAX(hawk_oow_t) - hawk->log.len; - if (len > max) + if (len > max) { /* data too big. */ rem += len - max; @@ -1636,7 +1636,7 @@ redo: /* +1 to handle line ending injection more easily */ tmp = hawk_reallocmem(hawk, hawk->log.ptr, (newcapa + 1) * HAWK_SIZEOF(*tmp)); - if (!tmp) + if (!tmp) { make_do: if (hawk->log.len > 0) @@ -1732,17 +1732,17 @@ hawk_ooi_t hawk_logbfmtv (hawk_t* hawk, hawk_bitmask_t mask, const hawk_bch_t* f int x; hawk_fmtout_t fo; - if (hawk->log.default_type_mask & HAWK_LOG_ALL_TYPES) + if (hawk->log.default_type_mask & HAWK_LOG_ALL_TYPES) { /* if a type is given, it's not untyped any more. * mask off the UNTYPED bit */ - mask &= ~HAWK_LOG_UNTYPED; + mask &= ~HAWK_LOG_UNTYPED; /* if the default_type_mask has the UNTYPED bit on, * it'll get turned back on */ mask |= (hawk->log.default_type_mask & HAWK_LOG_ALL_TYPES); } - else if (!(mask & HAWK_LOG_ALL_TYPES)) + else if (!(mask & HAWK_LOG_ALL_TYPES)) { /* no type is set in the given mask and no default type is set. * make it UNTYPED. */ @@ -1785,17 +1785,17 @@ hawk_ooi_t hawk_logufmtv (hawk_t* hawk, hawk_bitmask_t mask, const hawk_uch_t* f int x; hawk_fmtout_t fo; - if (hawk->log.default_type_mask & HAWK_LOG_ALL_TYPES) + if (hawk->log.default_type_mask & HAWK_LOG_ALL_TYPES) { /* if a type is given, it's not untyped any more. * mask off the UNTYPED bit */ - mask &= ~HAWK_LOG_UNTYPED; + mask &= ~HAWK_LOG_UNTYPED; /* if the default_type_mask has the UNTYPED bit on, * it'll get turned back on */ mask |= (hawk->log.default_type_mask & HAWK_LOG_ALL_TYPES); } - else if (!(mask & HAWK_LOG_ALL_TYPES)) + else if (!(mask & HAWK_LOG_ALL_TYPES)) { /* no type is set in the given mask and no default type is set. * make it UNTYPED. */ diff --git a/lib/fnc-prv.h b/lib/fnc-prv.h index c629db61..e2ff7a95 100644 --- a/lib/fnc-prv.h +++ b/lib/fnc-prv.h @@ -33,7 +33,7 @@ struct hawk_fnc_t hawk_oow_t len; } name; - int dfl0; /* if set, ($0) is assumed if () is missing. + int dfl0; /* if set, ($0) is assumed if () is missing. * this ia mainly for the weird length() function */ hawk_fnc_spec_t spec; diff --git a/lib/fnc.c b/lib/fnc.c index 7b8424bf..1ea244b9 100644 --- a/lib/fnc.c +++ b/lib/fnc.c @@ -1701,7 +1701,7 @@ static int __fnc_match (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int support_ n = hawk_rtx_matchvalwithoocs(rtx, a1, &tmp, &tmp, &mat.o, (nargs >= support_start_index + 3? submat.o: HAWK_NULL)); hawk_rtx_freevaloocstr (rtx, a0, str0.o); - if (n <= -1) return -1; + if (n <= -1) return -1; /* RSTART: 0 on no match */ idx = (n == 0)? 0: ((hawk_int_t)(mat.o.ptr - str0.o) + 1); diff --git a/lib/gem-glob.c b/lib/gem-glob.c index a0980e69..5c6739f4 100644 --- a/lib/gem-glob.c +++ b/lib/gem-glob.c @@ -22,11 +22,11 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* +/* * Do NOT edit glob.c. Edit glob.c.m4 instead. - * + * * Generate gem-glob.c with m4 - * $ m4 gem-glob.c.m4 > gem-glob.c + * $ m4 gem-glob.c.m4 > gem-glob.c */ #include "hawk-prv.h" @@ -261,7 +261,7 @@ static int __u_get_next_segment (__u_glob_t* g, __u_segment_t* seg) if (escaped) escaped = 0; else { - if (IS_ESC(seg->ptr[seg->len])) + if (IS_ESC(seg->ptr[seg->len])) { escaped = 1; seg->esc = 1; @@ -285,12 +285,12 @@ static int __u_get_next_segment (__u_glob_t* g, __u_segment_t* seg) seg->wild = 0; seg->esc = 0; - while (!IS_SEP_OR_NIL(seg->ptr[seg->len])) + while (!IS_SEP_OR_NIL(seg->ptr[seg->len])) { if (escaped) escaped = 0; else { - if (IS_ESC(seg->ptr[seg->len])) + if (IS_ESC(seg->ptr[seg->len])) { escaped = 1; seg->esc = 1; @@ -309,7 +309,7 @@ static int __u_get_next_segment (__u_glob_t* g, __u_segment_t* seg) seg->len = 0; seg->wild = 0; seg->esc = 0; - if (IS_NIL(seg->ptr[-1])) + if (IS_NIL(seg->ptr[-1])) { seg->type = NONE; seg->next = 0; @@ -319,12 +319,12 @@ static int __u_get_next_segment (__u_glob_t* g, __u_segment_t* seg) { int escaped = 0; seg->sep = seg->ptr[-1]; - while (!IS_SEP_OR_NIL(seg->ptr[seg->len])) + while (!IS_SEP_OR_NIL(seg->ptr[seg->len])) { if (escaped) escaped = 0; else { - if (IS_ESC(seg->ptr[seg->len])) + if (IS_ESC(seg->ptr[seg->len])) { escaped = 1; seg->esc = 1; @@ -363,7 +363,7 @@ static int __u_handle_non_wild_segments (__u_glob_t* g, __u_segment_t* seg) tmp.ptr = HAWK_UECS_PTR(&g->tbuf); tmp.len = 0; - /* the following loop drops the last character + /* the following loop drops the last character * if it is the escape character */ for (i = 0; i < seg->len; i++) { @@ -374,7 +374,7 @@ static int __u_handle_non_wild_segments (__u_glob_t* g, __u_segment_t* seg) } else { - if (IS_ESC(seg->ptr[i])) + if (IS_ESC(seg->ptr[i])) escaped = 1; else tmp.ptr[tmp.len++] = seg->ptr[i]; @@ -437,7 +437,7 @@ entry: hawk_uecs_setlen (&g->path, tmp2); x = hawk_dir_read(dp, &ent); - if (x <= -1) + if (x <= -1) { if (g->flags & HAWK_GLOB_TOLERANT) break; else goto oops; @@ -451,7 +451,7 @@ entry: if (seg->next) { #if defined(NO_RECURSION) - if (g->free) + if (g->free) { r = g->free; g->free = r->next; @@ -461,8 +461,8 @@ entry: r = hawk_gem_allocmem(g->gem, HAWK_SIZEOF(*r)); if (r == HAWK_NULL) goto oops; } - - /* push key variables that must be restored + + /* push key variables that must be restored * into the stack. */ r->tmp = tmp; r->tmp2 = tmp2; @@ -518,7 +518,7 @@ entry: dp = r->dp; *seg = r->seg; - /* link the stack node to the free list + /* link the stack node to the free list * instead of freeing it here */ r->next = g->free; g->free = r; @@ -581,15 +581,15 @@ int hawk_gem_uglob (hawk_gem_t* gem, const hawk_uch_t* pattern, hawk_gem_uglob_c if (flags & HAWK_GLOB_PERIOD) g.fnmat_flags |= HAWK_FNMAT_PERIOD; if (hawk_uecs_init(&g.path, g.gem, 512) <= -1) return -1; - if (hawk_uecs_init(&g.tbuf, g.gem, 256) <= -1) + if (hawk_uecs_init(&g.tbuf, g.gem, 256) <= -1) { hawk_uecs_fini (&g.path); return -1; } - if (HAWK_SIZEOF(hawk_uch_t) != HAWK_SIZEOF(hawk_bch_t)) + if (HAWK_SIZEOF(hawk_uch_t) != HAWK_SIZEOF(hawk_bch_t)) { - if (hawk_becs_init(&g.mbuf, g.gem, 512) <= -1) + if (hawk_becs_init(&g.mbuf, g.gem, 512) <= -1) { hawk_uecs_fini (&g.path); hawk_uecs_fini (&g.path); @@ -711,7 +711,7 @@ static int __b_get_next_segment (__b_glob_t* g, __b_segment_t* seg) if (escaped) escaped = 0; else { - if (IS_ESC(seg->ptr[seg->len])) + if (IS_ESC(seg->ptr[seg->len])) { escaped = 1; seg->esc = 1; @@ -735,12 +735,12 @@ static int __b_get_next_segment (__b_glob_t* g, __b_segment_t* seg) seg->wild = 0; seg->esc = 0; - while (!IS_SEP_OR_NIL(seg->ptr[seg->len])) + while (!IS_SEP_OR_NIL(seg->ptr[seg->len])) { if (escaped) escaped = 0; else { - if (IS_ESC(seg->ptr[seg->len])) + if (IS_ESC(seg->ptr[seg->len])) { escaped = 1; seg->esc = 1; @@ -759,7 +759,7 @@ static int __b_get_next_segment (__b_glob_t* g, __b_segment_t* seg) seg->len = 0; seg->wild = 0; seg->esc = 0; - if (IS_NIL(seg->ptr[-1])) + if (IS_NIL(seg->ptr[-1])) { seg->type = NONE; seg->next = 0; @@ -769,12 +769,12 @@ static int __b_get_next_segment (__b_glob_t* g, __b_segment_t* seg) { int escaped = 0; seg->sep = seg->ptr[-1]; - while (!IS_SEP_OR_NIL(seg->ptr[seg->len])) + while (!IS_SEP_OR_NIL(seg->ptr[seg->len])) { if (escaped) escaped = 0; else { - if (IS_ESC(seg->ptr[seg->len])) + if (IS_ESC(seg->ptr[seg->len])) { escaped = 1; seg->esc = 1; @@ -813,7 +813,7 @@ static int __b_handle_non_wild_segments (__b_glob_t* g, __b_segment_t* seg) tmp.ptr = HAWK_BECS_PTR(&g->tbuf); tmp.len = 0; - /* the following loop drops the last character + /* the following loop drops the last character * if it is the escape character */ for (i = 0; i < seg->len; i++) { @@ -824,7 +824,7 @@ static int __b_handle_non_wild_segments (__b_glob_t* g, __b_segment_t* seg) } else { - if (IS_ESC(seg->ptr[i])) + if (IS_ESC(seg->ptr[i])) escaped = 1; else tmp.ptr[tmp.len++] = seg->ptr[i]; @@ -887,7 +887,7 @@ entry: hawk_becs_setlen (&g->path, tmp2); x = hawk_dir_read(dp, &ent); - if (x <= -1) + if (x <= -1) { if (g->flags & HAWK_GLOB_TOLERANT) break; else goto oops; @@ -901,7 +901,7 @@ entry: if (seg->next) { #if defined(NO_RECURSION) - if (g->free) + if (g->free) { r = g->free; g->free = r->next; @@ -911,8 +911,8 @@ entry: r = hawk_gem_allocmem(g->gem, HAWK_SIZEOF(*r)); if (r == HAWK_NULL) goto oops; } - - /* push key variables that must be restored + + /* push key variables that must be restored * into the stack. */ r->tmp = tmp; r->tmp2 = tmp2; @@ -968,7 +968,7 @@ entry: dp = r->dp; *seg = r->seg; - /* link the stack node to the free list + /* link the stack node to the free list * instead of freeing it here */ r->next = g->free; g->free = r; @@ -1031,15 +1031,15 @@ int hawk_gem_bglob (hawk_gem_t* gem, const hawk_bch_t* pattern, hawk_gem_bglob_c if (flags & HAWK_GLOB_PERIOD) g.fnmat_flags |= HAWK_FNMAT_PERIOD; if (hawk_becs_init(&g.path, g.gem, 512) <= -1) return -1; - if (hawk_becs_init(&g.tbuf, g.gem, 256) <= -1) + if (hawk_becs_init(&g.tbuf, g.gem, 256) <= -1) { hawk_becs_fini (&g.path); return -1; } - if (HAWK_SIZEOF(hawk_bch_t) != HAWK_SIZEOF(hawk_bch_t)) + if (HAWK_SIZEOF(hawk_bch_t) != HAWK_SIZEOF(hawk_bch_t)) { - if (hawk_becs_init(&g.mbuf, g.gem, 512) <= -1) + if (hawk_becs_init(&g.mbuf, g.gem, 512) <= -1) { hawk_becs_fini (&g.path); hawk_becs_fini (&g.path); diff --git a/lib/gem-nwif.c b/lib/gem-nwif.c index c9ba9eb3..6d2a7a44 100644 --- a/lib/gem-nwif.c +++ b/lib/gem-nwif.c @@ -58,8 +58,8 @@ static int get_sco_ifconf (hawk_gem_t* gem, struct ifconf* ifc) int h, num; struct ifreq* ifr; - h = socket(AF_INET, SOCK_DGRAM, 0); - if (h <= -1) + h = socket(AF_INET, SOCK_DGRAM, 0); + if (h <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -84,7 +84,7 @@ static int get_sco_ifconf (hawk_gem_t* gem, struct ifconf* ifc) /* sco needs reboot when you add an network interface. * it should be safe not to consider the case when the interface - * is added after SIOCGIFANUM above. + * is added after SIOCGIFANUM above. * another thing to note is that SIOCGIFCONF ends with segfault * if the buffer is not large enough unlike some other OSes * like opensolaris which truncates the configuration. */ @@ -93,7 +93,7 @@ static int get_sco_ifconf (hawk_gem_t* gem, struct ifconf* ifc) ifc->ifc_buf = hawk_gem_allocmem(gem, ifc->ifc_len); if (ifc->ifc_buf == HAWK_NULL) goto oops; - if (ioctl(h, SIOCGIFCONF, ifc) <= -1) + if (ioctl(h, SIOCGIFCONF, ifc) <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); goto oops; @@ -135,7 +135,7 @@ int hawk_gem_bcstrtoifindex (hawk_gem_t* gem, const hawk_bch_t* ptr, unsigned in hawk_oow_t len; struct ifreq ifr; - h = socket(AF_INET, SOCK_DGRAM, 0); + h = socket(AF_INET, SOCK_DGRAM, 0); if (h <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); @@ -191,7 +191,7 @@ int hawk_gem_bcstrtoifindex (hawk_gem_t* gem, const hawk_bch_t* ptr, unsigned in num = ifc.ifc_len / HAWK_SIZEOF(struct ifreq); for (i = 0; i < num; i++) { - if (hawk_comp_bcstr(ptr, ifc.ifc_req[i].ifr_name, 0) == 0) + if (hawk_comp_bcstr(ptr, ifc.ifc_req[i].ifr_name, 0) == 0) { free_sco_ifconf (gem, &ifc); *index = i + 1; @@ -226,8 +226,8 @@ int hawk_gem_bcharstoifindex (hawk_gem_t* gem, const hawk_bch_t* ptr, hawk_oow_t int h, x; struct ifreq ifr; - h = socket(AF_INET, SOCK_DGRAM, 0); - if (h <= -1) + h = socket(AF_INET, SOCK_DGRAM, 0); + if (h <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -278,7 +278,7 @@ int hawk_gem_bcharstoifindex (hawk_gem_t* gem, const hawk_bch_t* ptr, hawk_oow_t num = ifc.ifc_len / HAWK_SIZEOF(struct ifreq); for (i = 0; i < num; i++) { - if (hawk_comp_bchars_bcstr(ptr, len, ifc.ifc_req[i].ifr_name, 0) == 0) + if (hawk_comp_bchars_bcstr(ptr, len, ifc.ifc_req[i].ifr_name, 0) == 0) { free_sco_ifconf (gem, &ifc); *index = i + 1; @@ -314,8 +314,8 @@ int hawk_gem_ucstrtoifindex (hawk_gem_t* gem, const hawk_uch_t* ptr, unsigned in struct ifreq ifr; hawk_oow_t wl, ml; - h = socket(AF_INET, SOCK_DGRAM, 0); - if (h <= -1) + h = socket(AF_INET, SOCK_DGRAM, 0); + if (h <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -347,7 +347,7 @@ int hawk_gem_ucstrtoifindex (hawk_gem_t* gem, const hawk_uch_t* ptr, unsigned in if (hawk_gem_convutobcstr(gem, ptr, &wl, tmp, &ml) <= -1) return -1; tmpidx = if_nametoindex(tmp); - if (tmpidx == 0) + if (tmpidx == 0) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -370,7 +370,7 @@ int hawk_gem_ucstrtoifindex (hawk_gem_t* gem, const hawk_uch_t* ptr, unsigned in num = ifc.ifc_len / HAWK_SIZEOF(struct ifreq); for (i = 0; i < num; i++) { - if (hawk_comp_bcstr(tmp, ifc.ifc_req[i].ifr_name, 0) == 0) + if (hawk_comp_bcstr(tmp, ifc.ifc_req[i].ifr_name, 0) == 0) { free_sco_ifconf (gem, &ifc); *index = i + 1; @@ -406,8 +406,8 @@ int hawk_gem_ucharstoifindex (hawk_gem_t* gem, const hawk_uch_t* ptr, hawk_oow_t struct ifreq ifr; hawk_oow_t wl, ml; - h = socket(AF_INET, SOCK_DGRAM, 0); - if (h <= -1) + h = socket(AF_INET, SOCK_DGRAM, 0); + if (h <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -441,7 +441,7 @@ int hawk_gem_ucharstoifindex (hawk_gem_t* gem, const hawk_uch_t* ptr, hawk_oow_t tmp[ml] = '\0'; tmpidx = if_nametoindex(tmp); - if (tmpidx == 0) + if (tmpidx == 0) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -464,7 +464,7 @@ int hawk_gem_ucharstoifindex (hawk_gem_t* gem, const hawk_uch_t* ptr, hawk_oow_t num = ifc.ifc_len / HAWK_SIZEOF(struct ifreq); for (i = 0; i < num; i++) { - if (hawk_comp_bcstr(gem, tmp, ifc.ifc_req[i].ifr_name) == 0) + if (hawk_comp_bcstr(gem, tmp, ifc.ifc_req[i].ifr_name) == 0) { free_sco_ifconf (gem, &ifc); *index = i + 1; @@ -501,8 +501,8 @@ int hawk_gem_ifindextobcstr (hawk_gem_t* gem, unsigned int index, hawk_bch_t* bu int h, x; struct ifreq ifr; - h = socket(AF_INET, SOCK_DGRAM, 0); - if (h <= -1) + h = socket(AF_INET, SOCK_DGRAM, 0); + if (h <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -514,7 +514,7 @@ int hawk_gem_ifindextobcstr (hawk_gem_t* gem, unsigned int index, hawk_bch_t* bu #else ifr.ifr_index = index; #endif - + x = ioctl(h, SIOCGIFNAME, &ifr); HAWK_CLOSE (h); @@ -528,7 +528,7 @@ int hawk_gem_ifindextobcstr (hawk_gem_t* gem, unsigned int index, hawk_bch_t* bu #elif defined(HAVE_IF_INDEXTONAME) hawk_bch_t tmp[IF_NAMESIZE + 1]; - if (if_indextoname (index, tmp) == HAWK_NULL) + if (if_indextoname (index, tmp) == HAWK_NULL) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -545,7 +545,7 @@ int hawk_gem_ifindextobcstr (hawk_gem_t* gem, unsigned int index, hawk_bch_t* bu if (get_sco_ifconf(gem, &ifc) <= -1) return -1; num = ifc.ifc_len / HAWK_SIZEOF(struct ifreq); - if (index > num) + if (index > num) { hawk_gem_seterrnum (gem, HAWK_NULL, HAWK_ENOENT); free_sco_ifconf (gem, &ifc); @@ -582,7 +582,7 @@ int hawk_gem_ifindextoucstr (hawk_gem_t* gem, unsigned int index, hawk_uch_t* bu struct ifreq ifr; hawk_oow_t wl, ml; - h = socket(AF_INET, SOCK_DGRAM, 0); + h = socket(AF_INET, SOCK_DGRAM, 0); if (h <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); @@ -616,7 +616,7 @@ int hawk_gem_ifindextoucstr (hawk_gem_t* gem, unsigned int index, hawk_uch_t* bu hawk_oow_t ml, wl; int x; - if (if_indextoname(index, tmp) == HAWK_NULL) + if (if_indextoname(index, tmp) == HAWK_NULL) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -637,7 +637,7 @@ int hawk_gem_ifindextoucstr (hawk_gem_t* gem, unsigned int index, hawk_uch_t* bu if (get_sco_ifconf(gem, &ifc) <= -1) return -1; num = ifc.ifc_len / HAWK_SIZEOF(struct ifreq); - if (index > num) + if (index > num) { free_sco_ifconf (gem, &ifc); return -1; diff --git a/lib/gem-nwif2.c b/lib/gem-nwif2.c index 5eda25e8..4c6e6e80 100644 --- a/lib/gem-nwif2.c +++ b/lib/gem-nwif2.c @@ -132,7 +132,7 @@ static HAWK_INLINE void copy_to_skad (struct sockaddr* sa, hawk_skad_t* skad) #ifndef SIOCGLIFHWADDR #define SIOCGLIFHWADDR _IOWR('i', 192, struct lifreq) #endif - + struct lifreq lif; memset(&lif, 0, sizeof(lif)); @@ -166,7 +166,7 @@ static int get_nwifs (hawk_gem_t* gem, int s, int f, hawk_xptl_t* nwifs) { ifn.lifn_family = f; ifn.lifn_flags = 0; - if (ioctl(s, SIOCGLIFNUM, &ifn) <= -1) + if (ioctl(s, SIOCGLIFNUM, &ifn) <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); goto oops; @@ -177,7 +177,7 @@ static int get_nwifs (hawk_gem_t* gem, int s, int f, hawk_xptl_t* nwifs) /* b.ptr won't be HAWK_NULL when retrying */ if (ifn.lifn_count <= ifcount) break; } - + /* +1 for extra space to leave empty * if SIOCGLIFCONF returns the same number of * intefaces as SIOCLIFNUM */ @@ -194,7 +194,7 @@ static int get_nwifs (hawk_gem_t* gem, int s, int f, hawk_xptl_t* nwifs) ifc.lifc_len = b.len; ifc.lifc_buf = b.ptr; - if (ioctl(s, SIOCGLIFCONF, &ifc) <= -1) + if (ioctl(s, SIOCGLIFCONF, &ifc) <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); goto oops; @@ -202,11 +202,11 @@ static int get_nwifs (hawk_gem_t* gem, int s, int f, hawk_xptl_t* nwifs) ifcount = ifc.lifc_len / HAWK_SIZEOF(struct lifreq); } - while (ifcount > ifn.lifn_count); + while (ifcount > ifn.lifn_count); /* the while condition above is for checking if * the buffer got full. when it's full, there is a chance * that there are more interfaces. */ - + nwifs->ptr = b.ptr; nwifs->len = ifcount; return 0; @@ -261,7 +261,7 @@ int hawk_gem_getifcfg (hawk_gem_t* gem, hawk_ifcfg_t* cfg) hawk_gem_seterrnum (gem, HAWK_NULL, HAWK_ENOIMPL); goto oops; #endif - + if (get_nwifs(cfg->mmgr, s4, AF_UNSPEC, &nwifs) <= -1) goto oops; ifr = nwifs.ptr; @@ -292,13 +292,13 @@ int hawk_gem_getifcfg (hawk_gem_t* gem, hawk_ifcfg_t* cfg) hawk_copy_bcstr (ifrbuf.lifr_name, HAWK_COUNTOF(ifrbuf.lifr_name), ifr->lifr_name); if (ioctl(s, SIOCGLIFFLAGS, &ifrbuf) <= -1) goto sys_oops; if (ifrbuf.lifr_flags & IFF_UP) head->flags |= HAWK_IFCFG_UP; - if (ifrbuf.lifr_flags & IFF_BROADCAST) + if (ifrbuf.lifr_flags & IFF_BROADCAST) { if (ioctl(s, SIOCGLIFBRDADDR, &ifrbuf) <= -1) goto sys_oops; copy_to_skad ((struct sockaddr*)&ifrbuf.lifr_addr, &head->bcast); head->flags |= HAWK_IFCFG_BCAST; } - if (ifrbuf.lifr_flags & IFF_POINTOPOINT) + if (ifrbuf.lifr_flags & IFF_POINTOPOINT) { if (ioctl(s, SIOCGLIFDSTADDR, &ifrbuf) <= -1) goto sys_oops; copy_to_skad ((struct sockaddr*)&ifrbuf.lifr_addr, &head->ptop); @@ -352,7 +352,7 @@ static void read_proc_net_if_inet6 (hawk_gem_t* gem, hawk_ifcfg_t* cfg, struct i * +------------------------------+ ++ ++ ++ ++ ++ * | | | | | | * 1 2 3 4 5 6 - * + * * 1. IPv6 address displayed in 32 hexadecimal chars without colons as separator * 2. Netlink device number (interface index) in hexadecimal (see “ip addr” , too) * 3. Prefix length in hexadecimal @@ -370,10 +370,10 @@ static void read_proc_net_if_inet6 (hawk_gem_t* gem, hawk_ifcfg_t* cfg, struct i /* TODO */ - sio = hawk_sio_open(gem, 0, HAWK_T("/proc/net/if_inet6"), HAWK_SIO_IGNOREECERR | HAWK_SIO_READ); + sio = hawk_sio_open(gem, 0, HAWK_T("/proc/net/if_inet6"), HAWK_SIO_IGNOREECERR | HAWK_SIO_READ); if (sio) { - + while (1) { len = hawk_sio_getbcstr(sio, line, HAWK_COUNTOF(line)); @@ -401,7 +401,7 @@ static void read_proc_net_if_inet6 (hawk_gem_t* gem, hawk_ifcfg_t* cfg, struct i skad = (hawk_skad_alt_t*)&cfg->addr; if (hawk_bchars_to_bin(tok[0].ptr, tok[0].len, (hawk_uint8_t*)&skad->in6.sin6_addr, HAWK_SIZEOF(skad->in6.sin6_addr)) <= -1) break; - /* tok[3] is the scope type, not the actual scope. + /* tok[3] is the scope type, not the actual scope. * i leave this code for reference only. skad->in6.sin6_scope_id = hawk_bchars_to_int(tok[3].ptr, tok[3].len, HAWK_OOCHARS_TO_INT_MAKE_OPTION(1, 1, 16), HAWK_NULL, HAWK_NULL); */ skad->in6.sin6_family = HAWK_AF_INET6; @@ -442,7 +442,7 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i /* opensolaris */ struct lifreq lifrbuf; hawk_oow_t ml, wl; - + HAWK_MEMSET (&lifrbuf, 0, HAWK_SIZEOF(lifrbuf)); hawk_copy_bcstr (lifrbuf.lifr_name, HAWK_SIZEOF(lifrbuf.lifr_name), ifr->ifr_name); @@ -459,17 +459,17 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i if (ioctl (s, SIOCGLIFMTU, &lifrbuf) <= -1) return -1; cfg->mtu = lifrbuf.lifr_mtu; - + hawk_clear_skad (&cfg->addr); hawk_clear_skad (&cfg->mask); hawk_clear_skad (&cfg->bcast); hawk_clear_skad (&cfg->ptop); HAWK_MEMSET (cfg->ethw, 0, HAWK_SIZEOF(cfg->ethw)); - if (ioctl (s, SIOCGLIFADDR, &lifrbuf) >= 0) + if (ioctl (s, SIOCGLIFADDR, &lifrbuf) >= 0) copy_to_skad ((struct sockaddr*)&lifrbuf.lifr_addr, &cfg->addr); - if (ioctl (s, SIOCGLIFNETMASK, &lifrbuf) >= 0) + if (ioctl (s, SIOCGLIFNETMASK, &lifrbuf) >= 0) copy_to_skad ((struct sockaddr*)&lifrbuf.lifr_addr, &cfg->mask); if ((cfg->flags & HAWK_IFCFG_BCAST) && @@ -485,7 +485,7 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i #if defined(SIOCGENADDR) { - if (ioctl(s, SIOCGENADDR, ifr) >= 0 && + if (ioctl(s, SIOCGENADDR, ifr) >= 0 && HAWK_SIZEOF(ifr->ifr_enaddr) >= HAWK_SIZEOF(cfg->ethw)) { HAWK_MEMCPY (cfg->ethw, ifr->ifr_enaddr, HAWK_SIZEOF(cfg->ethw)); @@ -499,9 +499,9 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i #elif defined(SIOCGLIFADDR) && defined(HAVE_STRUCT_IF_LADDRREQ) && !defined(SIOCGLIFINDEX) /* freebsd */ hawk_oow_t ml, wl; - + #if defined(SIOCGIFINDEX) - if (ioctl(s, SIOCGIFINDEX, ifr) <= -1) + if (ioctl(s, SIOCGIFINDEX, ifr) <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -515,7 +515,7 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i cfg->index = 0; #endif - if (ioctl(s, SIOCGIFFLAGS, ifr) <= -1) + if (ioctl(s, SIOCGIFFLAGS, ifr) <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -526,7 +526,7 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i if (ifr->ifr_flags & IFF_BROADCAST) cfg->flags |= HAWK_IFCFG_BCAST; if (ifr->ifr_flags & IFF_POINTOPOINT) cfg->flags |= HAWK_IFCFG_PTOP; - if (ioctl(s, SIOCGIFMTU, ifr) <= -1) + if (ioctl(s, SIOCGIFMTU, ifr) <= -1) { hawk_gem_seterrnum (gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -534,12 +534,12 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i #if defined(HAVE_STRUCT_IFREQ_IFR_MTU) cfg->mtu = ifr->ifr_mtu; #else - /* well, this is a bit dirty. but since all these are unions, + /* well, this is a bit dirty. but since all these are unions, * the name must not really matter. some OSes just omitts defining * the MTU field */ - cfg->mtu = ifr->ifr_metric; + cfg->mtu = ifr->ifr_metric; #endif - + hawk_clear_skad (&cfg->addr); hawk_clear_skad (&cfg->mask); hawk_clear_skad (&cfg->bcast); @@ -552,7 +552,7 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i HAWK_MEMSET (&iflrbuf, 0, HAWK_SIZEOF(iflrbuf)); hawk_copy_bcstr (iflrbuf.iflr_name, HAWK_SIZEOF(iflrbuf.iflr_name), ifr->ifr_name); - if (ioctl(s, SIOCGLIFADDR, &iflrbuf) >= 0) + if (ioctl(s, SIOCGLIFADDR, &iflrbuf) >= 0) { hawk_skad_alt_t* skad; copy_to_skad ((struct sockaddr*)&iflrbuf.addr, &cfg->addr); @@ -573,12 +573,12 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i if (ioctl(s, SIOCGIFNETMASK, ifr) >= 0) copy_to_skad ((struct sockaddr*)&ifr->ifr_addr, &cfg->mask); - if ((cfg->flags & HAWK_IFCFG_BCAST) && ioctl(s, SIOCGIFBRDADDR, ifr) >= 0) + if ((cfg->flags & HAWK_IFCFG_BCAST) && ioctl(s, SIOCGIFBRDADDR, ifr) >= 0) { copy_to_skad ((struct sockaddr*)&ifr->ifr_broadaddr, &cfg->bcast); } - if ((cfg->flags & HAWK_IFCFG_PTOP) && ioctl(s, SIOCGIFDSTADDR, ifr) >= 0) + if ((cfg->flags & HAWK_IFCFG_PTOP) && ioctl(s, SIOCGIFDSTADDR, ifr) >= 0) { copy_to_skad ((struct sockaddr*)&ifr->ifr_dstaddr, &cfg->ptop); } @@ -673,10 +673,10 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i #if defined(HAVE_STRUCT_IFREQ_IFR_MTU) cfg->mtu = ifr->ifr_mtu; #else - /* well, this is a bit dirty. but since all these are unions, + /* well, this is a bit dirty. but since all these are unions, * the name must not really matter. SCO just omits defining * the MTU field, and uses ifr_metric instead */ - cfg->mtu = ifr->ifr_metric; + cfg->mtu = ifr->ifr_metric; #endif hawk_clear_skad (&cfg->addr); @@ -709,13 +709,13 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i #if defined(SIOCGIFHWADDR) if (ioctl(s, SIOCGIFHWADDR, ifr) >= 0) if (ioctl(s, SIOCGIFHWADDR, ifr) >= 0) - { + { HAWK_MEMCPY (cfg->ethw, ifr->ifr_hwaddr.sa_data, HAWK_SIZEOF(cfg->ethw)); } #elif defined(MACIOC_GETADDR) { /* sco openserver - * use the streams interface to get the hardware address. + * use the streams interface to get the hardware address. */ int strfd; hawk_bch_t devname[HAWK_COUNTOF(ifr->ifr_name) + 5 + 1]; @@ -731,7 +731,7 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i strioc.ic_timout = -1; strioc.ic_len = HAWK_SIZEOF (buf); strioc.ic_dp = buf; - if (ioctl(strfd, I_STR, (char *) &strioc) >= 0) + if (ioctl(strfd, I_STR, (char *) &strioc) >= 0) HAWK_MEMCPY (cfg->ethw, buf, HAWK_SIZEOF(cfg->ethw)); HAWK_CLOSE (strfd); @@ -827,7 +827,7 @@ int hawk_gem_getifcfg (hawk_gem_t* gem, hawk_ifcfg_t* cfg) #endif } if (s <= -1) return -1; - + if (cfg->name[0] == HAWK_T('\0')&& cfg->index >= 1) { /* TODO: support lookup by ifindex */ diff --git a/lib/gem.c b/lib/gem.c index 6eae887b..3d1c3653 100644 --- a/lib/gem.c +++ b/lib/gem.c @@ -308,10 +308,10 @@ hawk_uch_t* hawk_gem_dupb2touchars (hawk_gem_t* gem, const hawk_bch_t* bcs1, haw inlen = bcslen2; hawk_gem_convbtouchars (gem, bcs2, &inlen, &ptr[outlen1], &outlen2, all); - /* hawk_convbtouchars() doesn't null-terminate the target. + /* hawk_convbtouchars() doesn't null-terminate the target. * but in hawk_dupbtouchars(), i allocate space. so i don't mind * null-terminating it with 1 extra character overhead */ - ptr[outlen1 + outlen2] = '\0'; + ptr[outlen1 + outlen2] = '\0'; if (ucslen) *ucslen = outlen1 + outlen2; return ptr; } @@ -382,9 +382,9 @@ hawk_uch_t* hawk_gem_dupbtoucharswithcmgr (hawk_gem_t* gem, const hawk_bch_t* bc if (!cmgr) cmgr = gem->cmgr; - bcslen = _bcslen; + bcslen = _bcslen; n = hawk_conv_bchars_to_uchars_with_cmgr(bcs, &bcslen, HAWK_NULL, &ucslen, cmgr, all); - if (n <= -1) + if (n <= -1) { /* -1: illegal character, -2: buffer too small, -3: incomplete sequence */ hawk_gem_seterrnum (gem, HAWK_NULL, (n == -2)? HAWK_EBUFFULL: HAWK_EECERR); @@ -412,7 +412,7 @@ hawk_bch_t* hawk_gem_duputobcharswithcmgr (hawk_gem_t* gem, const hawk_uch_t* uc ucslen = _ucslen; n = hawk_conv_uchars_to_bchars_with_cmgr(ucs, &ucslen, HAWK_NULL, &bcslen, cmgr); - if (n <= -1) + if (n <= -1) { /* -1: illegal character, -2: buffer too small, -3: incomplete sequence */ hawk_gem_seterrnum (gem, HAWK_NULL, (n == -2)? HAWK_EBUFFULL: HAWK_EECERR); @@ -502,9 +502,9 @@ static int fmt_put_bchars_to_uch_buf (hawk_fmtout_t* fmtout, const hawk_bch_t* p ucslen = b->capa - b->len; n = hawk_conv_bchars_to_uchars_with_cmgr(ptr, &bcslen, &b->ptr[b->len], &ucslen, b->gem->cmgr, 1); b->len += ucslen; - if (n <= -1) + if (n <= -1) { - if (n == -2) + if (n == -2) { return 0; /* buffer full. stop */ } @@ -666,7 +666,7 @@ hawk_oow_t hawk_gem_fmttobcstr (hawk_gem_t* gem, hawk_bch_t* buf, hawk_oow_t buf /* ------------------------------------------------------------------------ */ int hawk_gem_buildrex (hawk_gem_t* gem, const hawk_ooch_t* ptn, hawk_oow_t len, int nobound, hawk_tre_t** code, hawk_tre_t** icode) { - hawk_tre_t* tre = HAWK_NULL; + hawk_tre_t* tre = HAWK_NULL; hawk_tre_t* itre = HAWK_NULL; int opt = HAWK_TRE_EXTENDED; @@ -684,7 +684,7 @@ int hawk_gem_buildrex (hawk_gem_t* gem, const hawk_ooch_t* ptn, hawk_oow_t len, } } - if (icode) + if (icode) { itre = hawk_tre_open(gem, 0); if (itre == HAWK_NULL) diff --git a/lib/hawk-arr.h b/lib/hawk-arr.h index 3b2f41cf..31721333 100644 --- a/lib/hawk-arr.h +++ b/lib/hawk-arr.h @@ -28,7 +28,7 @@ #include /** @file - * This file provides a linear dynamic array. It grows dynamically as items + * This file provides a linear dynamic array. It grows dynamically as items * are added. */ @@ -68,7 +68,7 @@ typedef enum hawk_arr_walk_t hawk_arr_walk_t; * A slot is contructed when a user adds data to an array. The user can * define how the data to add can be maintained in the array. A dynamic * array not specified with any copiers stores the data pointer and - * the data length into a slot. A special copier HAWK_ARR_COPIER_INLINE copies + * the data length into a slot. A special copier HAWK_ARR_COPIER_INLINE copies * the contents of the data a user provided into the slot. * * A copier should return the pointer to the copied data. If it fails to copy @@ -93,20 +93,20 @@ typedef void (*hawk_arr_freeer_t) ( /** * The hawk_arr_comper_t type defines a key comparator that is called when * the arry needs to compare data. A linear dynamic array is created with a - * default comparator that performs bitwise comparison. + * default comparator that performs bitwise comparison. * * The default comparator compares data in a memcmp-like fashion. * It is not suitable when you want to implement a heap of numbers - * greater than a byte size. You must implement a comparator that + * greater than a byte size. You must implement a comparator that * takes the whole element and performs comparison in such a case. - * - * The comparator should return 0 if the data are the same, a negative + * + * The comparator should return 0 if the data are the same, a negative * integer if the first data is less than the second data, a positive * integer otherwise. * */ typedef int (*hawk_arr_comper_t) ( - hawk_arr_t* arr /* array */, + hawk_arr_t* arr /* array */, const void* dptr1 /* data pointer */, hawk_oow_t dlen1 /* data length */, const void* dptr2 /* data pointer */, @@ -114,7 +114,7 @@ typedef int (*hawk_arr_comper_t) ( ); /** - * The hawk_arr_keeper_t type defines a value keeper that is called when + * The hawk_arr_keeper_t type defines a value keeper that is called when * a value is retained in the context that it should be destroyed because * it is identical to a new value. Two values are identical if their beginning * pointers and their lengths are equal. @@ -122,12 +122,12 @@ typedef int (*hawk_arr_comper_t) ( typedef void (*hawk_arr_keeper_t) ( hawk_arr_t* arr /**< array */, void* vptr /**< pointer to a value */, - hawk_oow_t vlen /**< length of a value */ + hawk_oow_t vlen /**< length of a value */ ); /** * The hawk_arr_sizer_t type defines an array size claculator that is called - * when the array needs to be resized. + * when the array needs to be resized. */ typedef hawk_oow_t (*hawk_arr_sizer_t) ( hawk_arr_t* arr, /**< array */ @@ -175,7 +175,7 @@ struct hawk_arr_t hawk_gem_t* gem; const hawk_arr_style_t* style; hawk_uint8_t scale; /* scale factor */ - hawk_oow_t heap_pos_offset; /* offset in the data element where position + hawk_oow_t heap_pos_offset; /* offset in the data element where position * is stored when heap operation is performed. */ hawk_oow_t size; /* number of items */ hawk_oow_t tally; /* number of items set */ @@ -207,7 +207,7 @@ HAWK_EXPORT const hawk_arr_style_t* hawk_get_arr_style ( * The hawk_arr_open() function creates a linear dynamic array. */ HAWK_EXPORT hawk_arr_t* hawk_arr_open ( - hawk_gem_t* gem, + hawk_gem_t* gem, hawk_oow_t ext, /**< extension size in bytes */ hawk_oow_t capa /**< initial array capacity */ ); @@ -267,7 +267,7 @@ HAWK_EXPORT hawk_arr_copier_t hawk_arr_getcopier ( HAWK_EXPORT void hawk_arr_setstyle ( hawk_arr_t* arr, - const hawk_arr_style_t* style + const hawk_arr_style_t* style ); HAWK_EXPORT const hawk_arr_style_t* hawk_arr_getstyle ( @@ -303,14 +303,14 @@ HAWK_EXPORT hawk_oow_t hawk_arr_rsearch ( HAWK_EXPORT hawk_oow_t hawk_arr_upsert ( hawk_arr_t* arr, - hawk_oow_t index, + hawk_oow_t index, void* dptr, hawk_oow_t dlen ); HAWK_EXPORT hawk_oow_t hawk_arr_insert ( hawk_arr_t* arr, - hawk_oow_t index, + hawk_oow_t index, void* dptr, hawk_oow_t dlen ); @@ -323,7 +323,7 @@ HAWK_EXPORT hawk_oow_t hawk_arr_update ( ); /** - * The hawk_arr_delete() function deletes the as many data as the count + * The hawk_arr_delete() function deletes the as many data as the count * from the index. It returns the number of data deleted. */ HAWK_EXPORT hawk_oow_t hawk_arr_delete ( @@ -379,14 +379,14 @@ HAWK_EXPORT hawk_oow_t hawk_arr_rwalk ( */ HAWK_EXPORT hawk_oow_t hawk_arr_pushstack ( hawk_arr_t* arr, - void* dptr, + void* dptr, hawk_oow_t dlen ); /** * The hawk_arr_popstack() function deletes the last array data. It is a utility * function to allow stack-like operations over an array. To do so, you should - * not play with other non-stack related functions. + * not play with other non-stack related functions. * @note You must not call this function if @a arr is empty. */ HAWK_EXPORT void hawk_arr_popstack ( @@ -410,7 +410,7 @@ HAWK_EXPORT hawk_oow_t hawk_arr_pushheap ( /** * The hawk_arr_popheap() function deletes data at position 0 while keeping * the largest data at positon 0. It is a utiltiy funtion to implement a binary - * max-heap over an array. + * max-heap over an array. * @note You must not mess up the array with other non-heap related functions * to keep the heap property. */ @@ -435,7 +435,7 @@ HAWK_EXPORT hawk_oow_t hawk_arr_getheapposoffset ( ); /** - * The hawk_arr_setheapposoffset() function sets the offset to a position holding + * The hawk_arr_setheapposoffset() function sets the offset to a position holding * field within a data element. It assumes that the field is of the hawk_oow_t type. * * \code @@ -445,15 +445,15 @@ HAWK_EXPORT hawk_oow_t hawk_arr_getheapposoffset ( * hawk_oow_t pos; * }; * struct data_t d; - * hawk_arr_setheapposoffset (arr, HAWK_OFFSETOF(struct data_t, pos)); + * hawk_arr_setheapposoffset (arr, HAWK_OFFSETOF(struct data_t, pos)); * d.v = 20; * hawk_arr_pushheap (arr, &d, 1); * \endcode - * + * * In the code above, the 'pos' field of the first element in the array must be 0. - * - * If it's set to HAWK_ARR_NIL, position is not updated when heapification is - * performed. + * + * If it's set to HAWK_ARR_NIL, position is not updated when heapification is + * performed. */ HAWK_EXPORT void hawk_arr_setheapposoffset ( hawk_arr_t* arr, diff --git a/lib/hawk-chr.h b/lib/hawk-chr.h index 43bfefff..411f4d03 100644 --- a/lib/hawk-chr.h +++ b/lib/hawk-chr.h @@ -161,7 +161,7 @@ HAWK_EXPORT int hawk_is_bch_type (hawk_bch_t c, hawk_bch_prop_t type); # if __has_builtin(__builtin_tolower) # define hawk_to_bch_lower __builtin_tolower # endif -#elif (__GNUC__ >= 14) +#elif (__GNUC__ >= 14) # define hawk_is_bch_upper __builtin_isupper # define hawk_is_bch_lower __builtin_islower # define hawk_is_bch_alpha __builtin_isalpha diff --git a/lib/hawk-cli.h b/lib/hawk-cli.h index e4e14ad0..2cb072bf 100644 --- a/lib/hawk-cli.h +++ b/lib/hawk-cli.h @@ -28,8 +28,8 @@ #include /** \file - * This file defines functions and data structures to process - * command-line arguments. + * This file defines functions and data structures to process + * command-line arguments. */ typedef struct hawk_ucli_t hawk_ucli_t; @@ -52,7 +52,7 @@ struct hawk_ucli_t hawk_uch_t* arg; /* argument associated with an option */ /* output */ - const hawk_uch_t* lngopt; + const hawk_uch_t* lngopt; /* input + output */ int ind; /* index into parent argv vector */ @@ -81,7 +81,7 @@ struct hawk_bcli_t hawk_bch_t* arg; /* argument associated with an option */ /* output */ - const hawk_bch_t* lngopt; + const hawk_bch_t* lngopt; /* input + output */ int ind; /* index into parent argv vector */ @@ -96,27 +96,27 @@ extern "C" { /** * The hawk_get_cli() function processes the \a argc command-line arguments - * pointed to by \a argv as configured in \a opt. It can process two - * different option styles: a single character starting with '-', and a - * long name starting with '--'. + * pointed to by \a argv as configured in \a opt. It can process two + * different option styles: a single character starting with '-', and a + * long name starting with '--'. * * A character in \a opt.str is treated as a single character option. Should * it require a parameter, specify ':' after it. * - * Two special returning option characters indicate special error conditions. + * Two special returning option characters indicate special error conditions. * - \b ? indicates a bad option stored in the \a opt->opt field. * - \b : indicates a bad parameter for an option stored in the \a opt->opt field. * * @return an option character on success, HAWK_CHAR_EOF on no more options. */ HAWK_EXPORT hawk_uci_t hawk_get_ucli ( - int argc, /* argument count */ + int argc, /* argument count */ hawk_uch_t* const* argv, /* argument array */ hawk_ucli_t* opt /* option configuration */ ); HAWK_EXPORT hawk_bci_t hawk_get_bcli ( - int argc, /* argument count */ + int argc, /* argument count */ hawk_bch_t* const* argv, /* argument array */ hawk_bcli_t* opt /* option configuration */ ); diff --git a/lib/hawk-cmn.h b/lib/hawk-cmn.h index b0d35f28..1aae82ad 100644 --- a/lib/hawk-cmn.h +++ b/lib/hawk-cmn.h @@ -25,7 +25,7 @@ #ifndef _HAWK_CMN_H_ #define _HAWK_CMN_H_ -/* WARNING: NEVER CHANGE/DELETE THE FOLLOWING HAWK_HAVE_CFG_H DEFINITION. +/* WARNING: NEVER CHANGE/DELETE THE FOLLOWING HAWK_HAVE_CFG_H DEFINITION. * IT IS USED FOR DEPLOYMENT BY MAKEFILE.AM */ /*#define HAWK_HAVE_CFG_H*/ @@ -50,7 +50,7 @@ #if defined(EMSCRIPTEN) # if defined(HAWK_SIZEOF___INT128) -# undef HAWK_SIZEOF___INT128 +# undef HAWK_SIZEOF___INT128 # define HAWK_SIZEOF___INT128 0 # endif # if defined(HAWK_SIZEOF_LONG) && defined(HAWK_SIZEOF_INT) && (HAWK_SIZEOF_LONG > HAWK_SIZEOF_INT) @@ -90,7 +90,7 @@ #elif defined(_WIN32) || (defined(__WATCOMC__) && (__WATCOMC__ >= 1000) && !defined(__WINDOWS_386__)) # define HAWK_IMPORT __declspec(dllimport) # define HAWK_EXPORT __declspec(dllexport) -# define HAWK_PRIVATE +# define HAWK_PRIVATE #elif defined(__GNUC__) && ((__GNUC__>= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) # define HAWK_IMPORT __attribute__((visibility("default"))) # define HAWK_EXPORT __attribute__((visibility("default"))) @@ -107,12 +107,12 @@ # define HAWK_INLINE inline # define HAWK_HAVE_INLINE #elif defined(__GNUC__) && defined(__GNUC_GNU_INLINE__) - /* gcc disables inline when -std=c89 or -ansi is used. + /* gcc disables inline when -std=c89 or -ansi is used. * so use __inline__ supported by gcc regardless of the options */ # define HAWK_INLINE /*extern*/ __inline__ # define HAWK_HAVE_INLINE #else -# define HAWK_INLINE +# define HAWK_INLINE # undef HAWK_HAVE_INLINE #endif @@ -370,7 +370,7 @@ typedef hawk_int64_t hawk_intptr_t; typedef hawk_uint32_t hawk_ushortptr_t; typedef hawk_int32_t hawk_shortptr_t; -#elif defined(HAWK_HAVE_UINT128_T) && (HAWK_SIZEOF_VOID_P == 16) +#elif defined(HAWK_HAVE_UINT128_T) && (HAWK_SIZEOF_VOID_P == 16) typedef hawk_uint128_t hawk_uintptr_t; typedef hawk_int128_t hawk_intptr_t; typedef hawk_uint64_t hawk_ushortptr_t; @@ -516,7 +516,7 @@ typedef unsigned char hawk_bchu_t; /* unsigned version of hawk_bch_t f // if the library is compiled with 2-byte wchar_t, and the library user compiles a program with 4-byte wchar_t, // there will be size disparity issue on the hawk_uch_t type. - // if this assertion becomes false, you must check if the size of the wchar_t type is the same as the size used + // if this assertion becomes false, you must check if the size of the wchar_t type is the same as the size used // for this library. // gcc/g++/clang/clang++: -fshort-wchar makes wchar_t to 2 bytes. HAWK_STATIC_ASSERT (HAWK_WIDE_CHAR_SIZE == sizeof(hawk_uch_t)); @@ -755,7 +755,7 @@ struct hawk_ntime_t #endif /* make a bit mask that can mask off low n bits */ -#define HAWK_LBMASK(type,n) (~(~((type)0) << (n))) +#define HAWK_LBMASK(type,n) (~(~((type)0) << (n))) #define HAWK_LBMASK_SAFE(type,n) (((n) < HAWK_BITSOF(type))? HAWK_LBMASK(type,n): ~(type)0) /* make a bit mask that can mask off hig n bits */ @@ -779,7 +779,7 @@ struct hawk_ntime_t (value = (((type)(value)) | (((bits) & HAWK_LBMASK(type,length)) << (offset)))) -/** +/** * The HAWK_BITS_MAX() macros calculates the maximum value that the 'nbits' * bits of an unsigned integer of the given 'type' can hold. * \code @@ -794,12 +794,12 @@ struct hawk_ntime_t * ========================================================================= */ typedef struct hawk_mmgr_t hawk_mmgr_t; -/** +/** * allocate a memory chunk of the size \a n. * \return pointer to a memory chunk on success, #HAWK_NULL on failure. */ typedef void* (*hawk_mmgr_alloc_t) (hawk_mmgr_t* mmgr, hawk_oow_t n); -/** +/** * resize a memory chunk pointed to by \a ptr to the size \a n. * \return pointer to a memory chunk on success, #HAWK_NULL on failure. */ @@ -812,13 +812,13 @@ typedef void (*hawk_mmgr_free_t) (hawk_mmgr_t* mmgr, void* ptr); /** * The hawk_mmgr_t type defines the memory management interface. * As the type is merely a structure, it is just used as a single container - * for memory management functions with a pointer to user-defined data. - * The user-defined data pointer \a ctx is passed to each memory management - * function whenever it is called. You can allocate, reallocate, and free + * for memory management functions with a pointer to user-defined data. + * The user-defined data pointer \a ctx is passed to each memory management + * function whenever it is called. You can allocate, reallocate, and free * a memory chunk. * * For example, a hawk_xxx_open() function accepts a pointer of the hawk_mmgr_t - * type and the xxx object uses it to manage dynamic data within the object. + * type and the xxx object uses it to manage dynamic data within the object. */ struct hawk_mmgr_t { @@ -835,12 +835,12 @@ struct hawk_mmgr_t #define HAWK_MMGR_ALLOC(mmgr,size) ((mmgr)->alloc(mmgr,size)) /** - * The HAWK_MMGR_REALLOC() macro resizes a memory block pointed to by \a ptr + * The HAWK_MMGR_REALLOC() macro resizes a memory block pointed to by \a ptr * to the \a size bytes using the \a mmgr memory manager. */ #define HAWK_MMGR_REALLOC(mmgr,ptr,size) ((mmgr)->realloc(mmgr,ptr,size)) -/** +/** * The HAWK_MMGR_FREE() macro deallocates the memory block pointed to by \a ptr. */ #define HAWK_MMGR_FREE(mmgr,ptr) ((mmgr)->free(mmgr,ptr)) @@ -853,7 +853,7 @@ struct hawk_mmgr_t typedef struct hawk_cmgr_t hawk_cmgr_t; typedef hawk_oow_t (*hawk_cmgr_bctouc_t) ( - const hawk_bch_t* mb, + const hawk_bch_t* mb, hawk_oow_t size, hawk_uch_t* wc ); @@ -865,8 +865,8 @@ typedef hawk_oow_t (*hawk_cmgr_uctobc_t) ( ); /** - * The hawk_cmgr_t type defines the character-level interface to - * multibyte/wide-character conversion. This interface doesn't + * The hawk_cmgr_t type defines the character-level interface to + * multibyte/wide-character conversion. This interface doesn't * provide any facility to store conversion state in a context * independent manner. This leads to the limitation that it can * handle a stateless multibyte encoding only. @@ -1262,7 +1262,7 @@ typedef enum hawk_log_mask_t hawk_log_mask_t; #endif */ -#if defined(__has_builtin) +#if defined(__has_builtin) #if __has_builtin(__builtin_ctz) #define HAWK_HAVE_BUILTIN_CTZ #endif @@ -1284,41 +1284,41 @@ typedef enum hawk_log_mask_t hawk_log_mask_t; #endif #if __has_builtin(__builtin_uadd_overflow) - #define HAWK_HAVE_BUILTIN_UADD_OVERFLOW + #define HAWK_HAVE_BUILTIN_UADD_OVERFLOW #endif #if __has_builtin(__builtin_uaddl_overflow) - #define HAWK_HAVE_BUILTIN_UADDL_OVERFLOW + #define HAWK_HAVE_BUILTIN_UADDL_OVERFLOW #endif #if __has_builtin(__builtin_uaddll_overflow) - #define HAWK_HAVE_BUILTIN_UADDLL_OVERFLOW + #define HAWK_HAVE_BUILTIN_UADDLL_OVERFLOW #endif #if __has_builtin(__builtin_umul_overflow) - #define HAWK_HAVE_BUILTIN_UMUL_OVERFLOW + #define HAWK_HAVE_BUILTIN_UMUL_OVERFLOW #endif #if __has_builtin(__builtin_umull_overflow) - #define HAWK_HAVE_BUILTIN_UMULL_OVERFLOW + #define HAWK_HAVE_BUILTIN_UMULL_OVERFLOW #endif #if __has_builtin(__builtin_umulll_overflow) - #define HAWK_HAVE_BUILTIN_UMULLL_OVERFLOW + #define HAWK_HAVE_BUILTIN_UMULLL_OVERFLOW #endif #if __has_builtin(__builtin_sadd_overflow) - #define HAWK_HAVE_BUILTIN_SADD_OVERFLOW + #define HAWK_HAVE_BUILTIN_SADD_OVERFLOW #endif #if __has_builtin(__builtin_saddl_overflow) - #define HAWK_HAVE_BUILTIN_SADDL_OVERFLOW + #define HAWK_HAVE_BUILTIN_SADDL_OVERFLOW #endif #if __has_builtin(__builtin_saddll_overflow) - #define HAWK_HAVE_BUILTIN_SADDLL_OVERFLOW + #define HAWK_HAVE_BUILTIN_SADDLL_OVERFLOW #endif #if __has_builtin(__builtin_smul_overflow) - #define HAWK_HAVE_BUILTIN_SMUL_OVERFLOW + #define HAWK_HAVE_BUILTIN_SMUL_OVERFLOW #endif #if __has_builtin(__builtin_smull_overflow) - #define HAWK_HAVE_BUILTIN_SMULL_OVERFLOW + #define HAWK_HAVE_BUILTIN_SMULL_OVERFLOW #endif #if __has_builtin(__builtin_smulll_overflow) - #define HAWK_HAVE_BUILTIN_SMULLL_OVERFLOW + #define HAWK_HAVE_BUILTIN_SMULLL_OVERFLOW #endif #if __has_builtin(__builtin_expect) @@ -1358,7 +1358,7 @@ typedef enum hawk_log_mask_t hawk_log_mask_t; #endif #elif defined(__GNUC__) && defined(__GNUC_MINOR__) - #if (__GNUC__ >= 4) + #if (__GNUC__ >= 4) #define HAWK_HAVE_SYNC_LOCK_TEST_AND_SET #define HAWK_HAVE_SYNC_LOCK_RELEASE @@ -1416,7 +1416,7 @@ typedef enum hawk_log_mask_t hawk_log_mask_t; #if defined(__GNUC__) # define HAWK_PACKED __attribute__((__packed__)) #else -# define HAWK_PACKED +# define HAWK_PACKED #endif /* ========================================================================= diff --git a/lib/hawk-dir.h b/lib/hawk-dir.h index 9f103ea7..86c9a85d 100644 --- a/lib/hawk-dir.h +++ b/lib/hawk-dir.h @@ -51,7 +51,7 @@ extern "C" { HAWK_EXPORT hawk_dir_t* hawk_dir_open ( hawk_gem_t* gem, hawk_oow_t xtnsize, - const hawk_ooch_t* path, + const hawk_ooch_t* path, int flags ); diff --git a/lib/hawk-ecs.h b/lib/hawk-ecs.h index a0ab9d74..3ec4be0d 100644 --- a/lib/hawk-ecs.h +++ b/lib/hawk-ecs.h @@ -29,8 +29,8 @@ #include /** string pointer and length as a aggregate */ -#define HAWK_BECS_BCS(s) (&((s)->val)) -#define HAWK_BECS_CS(s) (&((s)->val)) +#define HAWK_BECS_BCS(s) (&((s)->val)) +#define HAWK_BECS_CS(s) (&((s)->val)) /** string length */ #define HAWK_BECS_LEN(s) ((s)->val.len) /** string pointer */ @@ -40,13 +40,13 @@ /** string capacity */ #define HAWK_BECS_CAPA(s) ((s)->capa) /** character at the given position */ -#define HAWK_BECS_CHAR(s,idx) ((s)->val.ptr[idx]) +#define HAWK_BECS_CHAR(s,idx) ((s)->val.ptr[idx]) /**< last character. unsafe if length <= 0 */ #define HAWK_BECS_LASTCHAR(s) ((s)->val.ptr[(s)->val.len-1]) /** string pointer and length as a aggregate */ -#define HAWK_UECS_UCS(s) (&((s)->val)) -#define HAWK_UECS_CS(s) (&((s)->val)) +#define HAWK_UECS_UCS(s) (&((s)->val)) +#define HAWK_UECS_CS(s) (&((s)->val)) /** string length */ #define HAWK_UECS_LEN(s) ((s)->val.len) /** string pointer */ @@ -56,7 +56,7 @@ /** string capacity */ #define HAWK_UECS_CAPA(s) ((s)->capa) /** character at the given position */ -#define HAWK_UECS_CHAR(s,idx) ((s)->val.ptr[idx]) +#define HAWK_UECS_CHAR(s,idx) ((s)->val.ptr[idx]) /**< last character. unsafe if length <= 0 */ #define HAWK_UECS_LASTCHAR(s) ((s)->val.ptr[(s)->val.len-1]) @@ -138,7 +138,7 @@ HAWK_EXPORT void hawk_becs_close ( /** * The hawk_becs_init() function initializes a dynamically resizable string - * If the parameter capa is 0, it doesn't allocate the internal buffer + * If the parameter capa is 0, it doesn't allocate the internal buffer * in advance and always succeeds. * \return 0 on success, -1 on failure. */ @@ -217,7 +217,7 @@ static HAWK_INLINE hawk_oow_t hawk_becs_getcapa (hawk_becs_t* becs) { return HAW * The hawk_becs_setcapa() function sets the new capacity. If the new capacity * is smaller than the old, the overflowing characters are removed from * from the buffer. - * \return (hawk_oow_t)-1 on failure, new capacity on success + * \return (hawk_oow_t)-1 on failure, new capacity on success */ HAWK_EXPORT hawk_oow_t hawk_becs_setcapa ( hawk_becs_t* becs, @@ -235,7 +235,7 @@ static HAWK_INLINE hawk_oow_t hawk_becs_getlen (hawk_becs_t* becs) { return HAWK /** * The hawk_becs_setlen() function changes the string length. - * \return (hawk_oow_t)-1 on failure, new length on success + * \return (hawk_oow_t)-1 on failure, new length on success */ HAWK_EXPORT hawk_oow_t hawk_becs_setlen ( hawk_becs_t* becs, @@ -312,25 +312,25 @@ HAWK_EXPORT hawk_oow_t hawk_becs_amend ( ); HAWK_EXPORT hawk_oow_t hawk_becs_vfcat ( - hawk_becs_t* str, + hawk_becs_t* str, const hawk_bch_t* fmt, va_list ap ); HAWK_EXPORT hawk_oow_t hawk_becs_fcat ( - hawk_becs_t* str, + hawk_becs_t* str, const hawk_bch_t* fmt, ... ); HAWK_EXPORT hawk_oow_t hawk_becs_vfmt ( - hawk_becs_t* str, + hawk_becs_t* str, const hawk_bch_t* fmt, va_list ap ); HAWK_EXPORT hawk_oow_t hawk_becs_fmt ( - hawk_becs_t* str, + hawk_becs_t* str, const hawk_bch_t* fmt, ... ); @@ -352,7 +352,7 @@ HAWK_EXPORT void hawk_uecs_close ( /** * The hawk_uecs_init() function initializes a dynamically resizable string - * If the parameter capa is 0, it doesn't allocate the internal buffer + * If the parameter capa is 0, it doesn't allocate the internal buffer * in advance and always succeeds. * \return 0 on success, -1 on failure. */ @@ -431,7 +431,7 @@ static HAWK_INLINE hawk_oow_t hawk_uecs_getcapa (hawk_uecs_t* uecs) { return HAW * The hawk_uecs_setcapa() function sets the new capacity. If the new capacity * is smaller than the old, the overflowing characters are removed from * from the buffer. - * \return (hawk_oow_t)-1 on failure, new capacity on success + * \return (hawk_oow_t)-1 on failure, new capacity on success */ HAWK_EXPORT hawk_oow_t hawk_uecs_setcapa ( hawk_uecs_t* uecs, @@ -449,7 +449,7 @@ static HAWK_INLINE hawk_oow_t hawk_uecs_getlen (hawk_uecs_t* uecs) { return HAWK /** * The hawk_uecs_setlen() function changes the string length. - * \return (hawk_oow_t)-1 on failure, new length on success + * \return (hawk_oow_t)-1 on failure, new length on success */ HAWK_EXPORT hawk_oow_t hawk_uecs_setlen ( hawk_uecs_t* uecs, @@ -527,25 +527,25 @@ HAWK_EXPORT hawk_oow_t hawk_uecs_amend ( ); HAWK_EXPORT hawk_oow_t hawk_uecs_vfcat ( - hawk_uecs_t* str, + hawk_uecs_t* str, const hawk_uch_t* fmt, va_list ap ); HAWK_EXPORT hawk_oow_t hawk_uecs_fcat ( - hawk_uecs_t* str, + hawk_uecs_t* str, const hawk_uch_t* fmt, ... ); HAWK_EXPORT hawk_oow_t hawk_uecs_vfmt ( - hawk_uecs_t* str, + hawk_uecs_t* str, const hawk_uch_t* fmt, va_list ap ); HAWK_EXPORT hawk_oow_t hawk_uecs_fmt ( - hawk_uecs_t* str, + hawk_uecs_t* str, const hawk_uch_t* fmt, ... ); diff --git a/lib/hawk-fio.h b/lib/hawk-fio.h index ac831d2c..74a005fd 100644 --- a/lib/hawk-fio.h +++ b/lib/hawk-fio.h @@ -29,7 +29,7 @@ enum hawk_fio_flag_t { - /* (1 << 0) to (1 << 7) reserved for hawk_sio_flag_t. + /* (1 << 0) to (1 << 7) reserved for hawk_sio_flag_t. * see . nerver use this value. */ HAWK_FIO_RESERVED = 0xFF, @@ -44,7 +44,7 @@ enum hawk_fio_flag_t HAWK_FIO_NOCLOSE = (1 << 10), /** treat the path name as a multi-byte string */ - HAWK_FIO_BCSTRPATH = (1 << 11), + HAWK_FIO_BCSTRPATH = (1 << 11), /* normal open flags */ HAWK_FIO_READ = (1 << 14), @@ -55,7 +55,7 @@ enum hawk_fio_flag_t HAWK_FIO_TRUNCATE = (1 << 18), HAWK_FIO_EXCLUSIVE = (1 << 19), HAWK_FIO_SYNC = (1 << 20), - + /* do not follow a symbolic link, only on a supported platform */ HAWK_FIO_NOFOLLOW = (1 << 23), @@ -128,7 +128,7 @@ struct hawk_fio_t { hawk_gem_t* gem; hawk_fio_hnd_t handle; - int status; + int status; }; struct hawk_fio_lck_t @@ -153,11 +153,11 @@ extern "C" { * If the #HAWK_FIO_HANDLE flag is set, the @a path parameter is interpreted * as a pointer to hawk_fio_hnd_t. * - * If the #HAWK_FIO_TEMPORARY flag is set, the @a path parameter is + * If the #HAWK_FIO_TEMPORARY flag is set, the @a path parameter is * interpreted as a path name template and an actual file name to open - * is internally generated using the template. The @a path parameter + * is internally generated using the template. The @a path parameter * is filled with the last actual path name attempted when the function - * returns. So, you must not pass a constant string to the @a path + * returns. So, you must not pass a constant string to the @a path * parameter when #HAWK_FIO_TEMPORARY is set. */ HAWK_EXPORT hawk_fio_t* hawk_fio_open ( @@ -187,7 +187,7 @@ HAWK_EXPORT int hawk_fio_init ( ); /** - * The hawk_fio_close() function finalizes a file by closing the handle + * The hawk_fio_close() function finalizes a file by closing the handle * stored in @a fio. */ HAWK_EXPORT void hawk_fio_fini ( @@ -247,7 +247,7 @@ HAWK_EXPORT hawk_ooi_t hawk_fio_write ( * The hawk_fio_chmod() function changes the file mode. * * @note - * On _WIN32, this function is implemented on the best-effort basis and + * On _WIN32, this function is implemented on the best-effort basis and * returns an error on the following conditions: * - The file size is 0. * - The file is opened without #HAWK_FIO_READ. @@ -259,15 +259,15 @@ HAWK_EXPORT int hawk_fio_chmod ( /** * The hawk_fio_sync() function synchronizes file contents into storage media - * It is useful in determining the media error, without which hawk_fio_close() + * It is useful in determining the media error, without which hawk_fio_close() * may succeed despite such an error. */ HAWK_EXPORT int hawk_fio_sync ( hawk_fio_t* fio ); -HAWK_EXPORT int hawk_fio_lock ( - hawk_fio_t* fio, +HAWK_EXPORT int hawk_fio_lock ( + hawk_fio_t* fio, hawk_fio_lck_t* lck, int flags ); diff --git a/lib/hawk-fmt.h b/lib/hawk-fmt.h index bf3d9554..981f3be9 100644 --- a/lib/hawk-fmt.h +++ b/lib/hawk-fmt.h @@ -32,7 +32,7 @@ * This file defines various formatting functions. */ -/** +/** * The hawk_fmt_intmax_flag_t type defines enumerators to change the * behavior of hawk_fmt_intmax() and hawk_fmt_uintmax(). */ @@ -161,7 +161,7 @@ typedef int (*hawk_fmtout_putobj_t) ( hawk_val_t* val ); -enum hawk_fmtout_fmt_type_t +enum hawk_fmtout_fmt_type_t { HAWK_FMTOUT_FMT_TYPE_BCH = 0, HAWK_FMTOUT_FMT_TYPE_UCH @@ -189,22 +189,22 @@ extern "C" { #endif /** - * The hawk_fmt_intmax_to_bcstr() function formats an integer \a value to a - * multibyte string according to the given base and writes it to a buffer - * pointed to by \a buf. It writes to the buffer at most \a size characters - * including the terminating null. The base must be between 2 and 36 inclusive - * and can be ORed with zero or more #hawk_fmt_intmax_to_bcstr_flag_t enumerators. - * This ORed value is passed to the function via the \a base_and_flags + * The hawk_fmt_intmax_to_bcstr() function formats an integer \a value to a + * multibyte string according to the given base and writes it to a buffer + * pointed to by \a buf. It writes to the buffer at most \a size characters + * including the terminating null. The base must be between 2 and 36 inclusive + * and can be ORed with zero or more #hawk_fmt_intmax_to_bcstr_flag_t enumerators. + * This ORed value is passed to the function via the \a base_and_flags * parameter. If the formatted string is shorter than \a bufsize, the redundant - * slots are filled with the fill character \a fillchar if it is not a null + * slots are filled with the fill character \a fillchar if it is not a null * character. The filling behavior is determined by the flags shown below: * - * - If #HAWK_FMT_INTMAX_TO_BCSTR_FILLRIGHT is set in \a base_and_flags, slots + * - If #HAWK_FMT_INTMAX_TO_BCSTR_FILLRIGHT is set in \a base_and_flags, slots * after the formatting string are filled. - * - If #HAWK_FMT_INTMAX_TO_BCSTR_FILLCENTER is set in \a base_and_flags, slots + * - If #HAWK_FMT_INTMAX_TO_BCSTR_FILLCENTER is set in \a base_and_flags, slots * before the formatting string are filled. However, if it contains the * sign character, the slots between the sign character and the digit part - * are filled. + * are filled. * - If neither #HAWK_FMT_INTMAX_TO_BCSTR_FILLRIGHT nor #HAWK_FMT_INTMAX_TO_BCSTR_FILLCENTER * , slots before the formatting string are filled. * @@ -216,26 +216,26 @@ extern "C" { * * The terminating null is not added if #HAWK_FMT_INTMAX_TO_BCSTR_NONULL is set; * The #HAWK_FMT_INTMAX_TO_BCSTR_UPPERCASE flag indicates that the function should - * use the uppercase letter for a alphabetic digit; + * use the uppercase letter for a alphabetic digit; * You can set #HAWK_FMT_INTMAX_TO_BCSTR_NOTRUNC if you require lossless formatting. - * The #HAWK_FMT_INTMAX_TO_BCSTR_PLUSSIGN flag and #HAWK_FMT_INTMAX_TO_BCSTR_EMPTYSIGN - * ensures that the plus sign and a space is added for a positive integer + * The #HAWK_FMT_INTMAX_TO_BCSTR_PLUSSIGN flag and #HAWK_FMT_INTMAX_TO_BCSTR_EMPTYSIGN + * ensures that the plus sign and a space is added for a positive integer * including 0 respectively. * The #HAWK_FMT_INTMAX_TO_BCSTR_ZEROLEAD flag ensures that the numeric string * begins with '0' before applying the prefix. * You can set the #HAWK_FMT_INTMAX_TO_BCSTR_NOZERO flag if you want the value of - * 0 to produce nothing. If both #HAWK_FMT_INTMAX_TO_BCSTR_NOZERO and + * 0 to produce nothing. If both #HAWK_FMT_INTMAX_TO_BCSTR_NOZERO and * #HAWK_FMT_INTMAX_TO_BCSTR_ZEROLEAD are specified, '0' is still produced. - * + * * If \a prefix is not #HAWK_NULL, it is inserted before the digits. - * + * * \return - * - -1 if the base is not between 2 and 36 inclusive. - * - negated number of characters required for lossless formatting + * - -1 if the base is not between 2 and 36 inclusive. + * - negated number of characters required for lossless formatting * - if \a bufsize is 0. * - if #HAWK_FMT_INTMAX_TO_BCSTR_NOTRUNC is set and \a bufsize is less than * the minimum required for lossless formatting. - * - number of characters written to the buffer excluding a terminating + * - number of characters written to the buffer excluding a terminating * null in all other cases. */ HAWK_EXPORT int hawk_fmt_intmax_to_bcstr ( @@ -249,25 +249,25 @@ HAWK_EXPORT int hawk_fmt_intmax_to_bcstr ( ); /** - * The hawk_fmt_intmax_to_ucstr() function formats an integer \a value to a - * wide-character string according to the given base and writes it to a buffer - * pointed to by \a buf. It writes to the buffer at most \a size characters - * including the terminating null. The base must be between 2 and 36 inclusive - * and can be ORed with zero or more #hawk_fmt_intmax_to_ucstr_flag_t enumerators. - * This ORed value is passed to the function via the \a base_and_flags + * The hawk_fmt_intmax_to_ucstr() function formats an integer \a value to a + * wide-character string according to the given base and writes it to a buffer + * pointed to by \a buf. It writes to the buffer at most \a size characters + * including the terminating null. The base must be between 2 and 36 inclusive + * and can be ORed with zero or more #hawk_fmt_intmax_to_ucstr_flag_t enumerators. + * This ORed value is passed to the function via the \a base_and_flags * parameter. If the formatted string is shorter than \a bufsize, the redundant - * slots are filled with the fill character \a fillchar if it is not a null + * slots are filled with the fill character \a fillchar if it is not a null * character. The filling behavior is determined by the flags shown below: * - * - If #HAWK_FMT_INTMAX_TO_UCSTR_FILLRIGHT is set in \a base_and_flags, slots + * - If #HAWK_FMT_INTMAX_TO_UCSTR_FILLRIGHT is set in \a base_and_flags, slots * after the formatting string are filled. - * - If #HAWK_FMT_INTMAX_TO_UCSTR_FILLCENTER is set in \a base_and_flags, slots + * - If #HAWK_FMT_INTMAX_TO_UCSTR_FILLCENTER is set in \a base_and_flags, slots * before the formatting string are filled. However, if it contains the * sign character, the slots between the sign character and the digit part - * are filled. + * are filled. * - If neither #HAWK_FMT_INTMAX_TO_UCSTR_FILLRIGHT nor #HAWK_FMT_INTMAX_TO_UCSTR_FILLCENTER * , slots before the formatting string are filled. - * + * * The \a precision parameter specified the minimum number of digits to * produce from the \ value. If \a value produces fewer digits than * \a precision, the actual digits are padded with '0' to meet the precision @@ -276,26 +276,26 @@ HAWK_EXPORT int hawk_fmt_intmax_to_bcstr ( * * The terminating null is not added if #HAWK_FMT_INTMAX_TO_UCSTR_NONULL is set; * The #HAWK_FMT_INTMAX_TO_UCSTR_UPPERCASE flag indicates that the function should - * use the uppercase letter for a alphabetic digit; + * use the uppercase letter for a alphabetic digit; * You can set #HAWK_FMT_INTMAX_TO_UCSTR_NOTRUNC if you require lossless formatting. - * The #HAWK_FMT_INTMAX_TO_UCSTR_PLUSSIGN flag and #HAWK_FMT_INTMAX_TO_UCSTR_EMPTYSIGN - * ensures that the plus sign and a space is added for a positive integer + * The #HAWK_FMT_INTMAX_TO_UCSTR_PLUSSIGN flag and #HAWK_FMT_INTMAX_TO_UCSTR_EMPTYSIGN + * ensures that the plus sign and a space is added for a positive integer * including 0 respectively. * The #HAWK_FMT_INTMAX_TO_UCSTR_ZEROLEAD flag ensures that the numeric string * begins with 0 before applying the prefix. * You can set the #HAWK_FMT_INTMAX_TO_UCSTR_NOZERO flag if you want the value of - * 0 to produce nothing. If both #HAWK_FMT_INTMAX_TO_UCSTR_NOZERO and + * 0 to produce nothing. If both #HAWK_FMT_INTMAX_TO_UCSTR_NOZERO and * #HAWK_FMT_INTMAX_TO_UCSTR_ZEROLEAD are specified, '0' is still produced. * * If \a prefix is not #HAWK_NULL, it is inserted before the digits. - * + * * \return - * - -1 if the base is not between 2 and 36 inclusive. - * - negated number of characters required for lossless formatting + * - -1 if the base is not between 2 and 36 inclusive. + * - negated number of characters required for lossless formatting * - if \a bufsize is 0. * - if #HAWK_FMT_INTMAX_TO_UCSTR_NOTRUNC is set and \a bufsize is less than * the minimum required for lossless formatting. - * - number of characters written to the buffer excluding a terminating + * - number of characters written to the buffer excluding a terminating * null in all other cases. */ HAWK_EXPORT int hawk_fmt_intmax_to_ucstr ( @@ -310,8 +310,8 @@ HAWK_EXPORT int hawk_fmt_intmax_to_ucstr ( /** - * The hawk_fmt_uintmax_to_bcstr() function formats an unsigned integer \a value - * to a multibyte string buffer. It behaves the same as hawk_fmt_intmax_to_bcstr() + * The hawk_fmt_uintmax_to_bcstr() function formats an unsigned integer \a value + * to a multibyte string buffer. It behaves the same as hawk_fmt_intmax_to_bcstr() * except that it handles an unsigned integer. */ HAWK_EXPORT int hawk_fmt_uintmax_to_bcstr ( @@ -325,8 +325,8 @@ HAWK_EXPORT int hawk_fmt_uintmax_to_bcstr ( ); /** - * The hawk_fmt_uintmax_to_ucstr() function formats an unsigned integer \a value - * to a unicode string buffer. It behaves the same as hawk_fmt_intmax_to_ucstr() + * The hawk_fmt_uintmax_to_ucstr() function formats an unsigned integer \a value + * to a unicode string buffer. It behaves the same as hawk_fmt_intmax_to_ucstr() * except that it handles an unsigned integer. */ HAWK_EXPORT int hawk_fmt_uintmax_to_ucstr ( diff --git a/lib/hawk-gem.h b/lib/hawk-gem.h index f62e7b29..f06b568b 100644 --- a/lib/hawk-gem.h +++ b/lib/hawk-gem.h @@ -75,7 +75,7 @@ struct hawk_ifcfg_t /* ---------------- */ - /* TODO: add hwaddr?? */ + /* TODO: add hwaddr?? */ /* i support ethernet only currently */ hawk_uint8_t ethw[6]; /* out */ }; @@ -452,8 +452,8 @@ HAWK_EXPORT int hawk_gem_getifcfg ( static HAWK_INLINE hawk_errnum_t hawk_gem_geterrnum (hawk_gem_t* gem) { return gem->errnum; } static HAWK_INLINE const hawk_loc_t* hawk_gem_geterrloc (hawk_gem_t* gem) { return &gem->errloc; } #else -#define hawk_gem_geterrnum(gem) (((hawk_gem_t*)(gem))->errnum) -#define hawk_gem_geterrloc(gem) (&((hawk_gem_t*)(gem))->errloc) +#define hawk_gem_geterrnum(gem) (((hawk_gem_t*)(gem))->errnum) +#define hawk_gem_geterrloc(gem) (&((hawk_gem_t*)(gem))->errloc) #endif HAWK_EXPORT void hawk_gem_geterror ( diff --git a/lib/hawk-glob.h b/lib/hawk-glob.h index 80fd4687..afce3042 100644 --- a/lib/hawk-glob.h +++ b/lib/hawk-glob.h @@ -51,14 +51,14 @@ enum hawk_glob_flag_t /** Match a leading period explicitly by a literal period in the pattern */ HAWK_GLOB_PERIOD = (1 << 1), - /** Perform case-insensitive matching. + /** Perform case-insensitive matching. * This option is always on in Win32/OS2/DOS. */ HAWK_GLOB_IGNORECASE = (1 << 2), /** Make the function to be more fault-resistent */ HAWK_GLOB_TOLERANT = (1 << 3), - /** Exclude special entries from matching. + /** Exclude special entries from matching. * Special entries include . and .. */ HAWK_GLOB_SKIPSPCDIR = (1 << 4), @@ -78,7 +78,7 @@ extern "C" { /** * The hawk_gem_bglob() function finds path names matchin the \a pattern. * It calls the call-back function \a cbimpl for each path name found. - * + * * \return -1 on failure, 0 on no match, 1 if matches are found. */ HAWK_EXPORT int hawk_gem_bglob ( @@ -103,7 +103,7 @@ HAWK_EXPORT int hawk_gem_uglob ( #else typedef hawk_gem_bglob_cb_t hawk_gem_glob_cb_t; # define hawk_gem_glob hawk_gem_bglob - + #endif #if defined(__cplusplus) diff --git a/lib/hawk-htb.h b/lib/hawk-htb.h index 7021d431..5bd3bd14 100644 --- a/lib/hawk-htb.h +++ b/lib/hawk-htb.h @@ -28,7 +28,7 @@ #include /**@file - * This file provides a hash table encapsulated in the #hawk_htb_t type that + * This file provides a hash table encapsulated in the #hawk_htb_t type that * maintains buckets for key/value pairs with the same key hash chained under * the same bucket. Its interface is very close to #hawk_rbt_t. * @@ -36,31 +36,31 @@ * in the randome order. * @code * #include - * + * * static hawk_htb_walk_t walk (hawk_htb_t* htb, hawk_htb_pair_t* pair, void* ctx) * { * hawk_printf (HAWK_T("key = %d, value = %d\n"), * *(int*)HAWK_HTB_KPTR(pair), *(int*)HAWK_HTB_VPTR(pair)); * return HAWK_HTB_WALK_FORWARD; * } - * + * * int main () * { * hawk_htb_t* s1; * int i; - * + * * hawk_open_stdsios (); * s1 = hawk_htb_open (HAWK_MMGR_GETDFL(), 0, 30, 75, 1, 1); // error handling skipped * hawk_htb_setstyle (s1, hawk_get_htb_style(HAWK_HTB_STYLE_INLINE_COPIERS)); - * + * * for (i = 0; i < 20; i++) * { * int x = i * 20; * hawk_htb_insert (s1, &i, HAWK_SIZEOF(i), &x, HAWK_SIZEOF(x)); // eror handling skipped * } - * + * * hawk_htb_walk (s1, walk, HAWK_NULL); - * + * * hawk_htb_close (s1); * hawk_close_stdsios (); * return 0; @@ -71,7 +71,7 @@ typedef struct hawk_htb_t hawk_htb_t; typedef struct hawk_htb_pair_t hawk_htb_pair_t; -/** +/** * The hawk_htb_walk_t type defines values that the callback function can * return to control hawk_htb_walk(). */ @@ -101,7 +101,7 @@ typedef enum hawk_htb_id_t hawk_htb_id_t; */ typedef void* (*hawk_htb_copier_t) ( hawk_htb_t* htb /* hash table */, - void* dptr /* pointer to a key or a value */, + void* dptr /* pointer to a key or a value */, hawk_oow_t dlen /* length of a key or a value */ ); @@ -124,17 +124,17 @@ typedef void (*hawk_htb_freeer_t) ( * integer otherwise. */ typedef int (*hawk_htb_comper_t) ( - const hawk_htb_t* htb, /**< hash table */ + const hawk_htb_t* htb, /**< hash table */ const void* kptr1, /**< key pointer */ - hawk_oow_t klen1, /**< key length */ - const void* kptr2, /**< key pointer */ + hawk_oow_t klen1, /**< key length */ + const void* kptr2, /**< key pointer */ hawk_oow_t klen2 /**< key length */ ); /** - * The hawk_htb_keeper_t type defines a value keeper that is called when + * The hawk_htb_keeper_t type defines a value keeper that is called when * a value is retained in the context that it should be destroyed because - * it is identical to a new value. Two values are identical if their + * it is identical to a new value. Two values are identical if their * pointers and lengths are equal. */ typedef void (*hawk_htb_keeper_t) ( @@ -145,7 +145,7 @@ typedef void (*hawk_htb_keeper_t) ( /** * The hawk_htb_sizer_t type defines a bucket size claculator that is called - * when hash table should resize the bucket. The current bucket size + 1 is + * when hash table should resize the bucket. The current bucket size + 1 is * passed as the hint. */ typedef hawk_oow_t (*hawk_htb_sizer_t) ( @@ -173,12 +173,12 @@ typedef hawk_htb_walk_t (*hawk_htb_walker_t) ( /** * The hawk_htb_cbserter_t type defines a callback function for hawk_htb_cbsert(). - * The hawk_htb_cbserter() function calls it to allocate a new pair for the + * The hawk_htb_cbserter() function calls it to allocate a new pair for the * key pointed to by @a kptr of the length @a klen and the callback context * @a ctx. The second parameter @a pair is passed the pointer to the existing * pair for the key or #HAWK_NULL in case of no existing key. The callback * must return a pointer to a new or a reallocated pair. When reallocating the - * existing pair, this callback must destroy the existing pair and return the + * existing pair, this callback must destroy the existing pair and return the * newly reallocated pair. It must return #HAWK_NULL for failure. */ typedef hawk_htb_pair_t* (*hawk_htb_cbserter_t) ( @@ -193,8 +193,8 @@ typedef hawk_htb_pair_t* (*hawk_htb_cbserter_t) ( /** * The hawk_htb_pair_t type defines hash table pair. A pair is composed of a key * and a value. It maintains pointers to the beginning of a key and a value - * plus their length. The length is scaled down with the scale factor - * specified in an owning hash table. + * plus their length. The length is scaled down with the scale factor + * specified in an owning hash table. */ struct hawk_htb_pair_t { @@ -202,7 +202,7 @@ struct hawk_htb_pair_t hawk_ptl_t val; /* management information below */ - hawk_htb_pair_t* next; + hawk_htb_pair_t* next; }; typedef struct hawk_htb_style_t hawk_htb_style_t; @@ -319,15 +319,15 @@ HAWK_EXPORT const hawk_htb_style_t* hawk_get_htb_style ( ); /** - * The hawk_htb_open() function creates a hash table with a dynamic array + * The hawk_htb_open() function creates a hash table with a dynamic array * bucket and a list of values chained. The initial capacity should be larger * than 0. The load factor should be between 0 and 100 inclusive and the load * factor of 0 disables bucket resizing. If you need extra space associated * with hash table, you may pass a non-zero value for @a xtnsize. - * The HAWK_HTB_XTN() macro and the hawk_htb_getxtn() function return the + * The HAWK_HTB_XTN() macro and the hawk_htb_getxtn() function return the * pointer to the beginning of the extension. - * The @a kscale and @a vscale parameters specify the unit of the key and - * value size. + * The @a kscale and @a vscale parameters specify the unit of the key and + * value size. * @return #hawk_htb_t pointer on success, #HAWK_NULL on failure. */ HAWK_EXPORT hawk_htb_t* hawk_htb_open ( @@ -380,7 +380,7 @@ HAWK_EXPORT const hawk_htb_style_t* hawk_htb_getstyle ( ); /** - * The hawk_htb_setstyle() function sets internal manipulation callback + * The hawk_htb_setstyle() function sets internal manipulation callback * functions for data construction, destruction, resizing, hashing, etc. * The callback structure pointed to by \a style must outlive the hash * table pointed to by \a htb as the hash table doesn't copy the contents @@ -399,7 +399,7 @@ HAWK_EXPORT hawk_oow_t hawk_htb_getsize ( ); /** - * The hawk_htb_getcapa() function gets the number of slots allocated + * The hawk_htb_getcapa() function gets the number of slots allocated * in a hash bucket. */ HAWK_EXPORT hawk_oow_t hawk_htb_getcapa ( @@ -407,10 +407,10 @@ HAWK_EXPORT hawk_oow_t hawk_htb_getcapa ( ); /** - * The hawk_htb_search() function searches a hash table to find a pair with a + * The hawk_htb_search() function searches a hash table to find a pair with a * matching key. It returns the pointer to the pair found. If it fails * to find one, it returns HAWK_NULL. - * @return pointer to the pair with a maching key, + * @return pointer to the pair with a maching key, * or #HAWK_NULL if no match is found. */ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_search ( @@ -420,12 +420,12 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_search ( ); /** - * The hawk_htb_upsert() function searches a hash table for the pair with a + * The hawk_htb_upsert() function searches a hash table for the pair with a * matching key. If one is found, it updates the pair. Otherwise, it inserts - * a new pair with the key and value given. It returns the pointer to the + * a new pair with the key and value given. It returns the pointer to the * pair updated or inserted. - * @return pointer to the updated or inserted pair on success, - * #HAWK_NULL on failure. + * @return pointer to the updated or inserted pair on success, + * #HAWK_NULL on failure. */ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_upsert ( hawk_htb_t* htb, /**< hash table */ @@ -437,9 +437,9 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_upsert ( /** * The hawk_htb_ensert() function inserts a new pair with the key and the value - * given. If there exists a pair with the key given, the function returns + * given. If there exists a pair with the key given, the function returns * the pair containing the key. - * @return pointer to a pair on success, #HAWK_NULL on failure. + * @return pointer to a pair on success, #HAWK_NULL on failure. */ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_ensert ( hawk_htb_t* htb, /**< hash table */ @@ -451,9 +451,9 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_ensert ( /** * The hawk_htb_insert() function inserts a new pair with the key and the value - * given. If there exists a pair with the key given, the function returns + * given. If there exists a pair with the key given, the function returns * #HAWK_NULL without channging the value. - * @return pointer to the pair created on success, #HAWK_NULL on failure. + * @return pointer to the pair created on success, #HAWK_NULL on failure. */ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_insert ( hawk_htb_t* htb, /**< hash table */ @@ -477,7 +477,7 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_update ( ); /** - * The hawk_htb_cbsert() function inserts a key/value pair by delegating pair + * The hawk_htb_cbsert() function inserts a key/value pair by delegating pair * allocation to a callback function. Depending on the callback function, * it may behave like hawk_htb_insert(), hawk_htb_upsert(), hawk_htb_update(), * hawk_htb_ensert(), or totally differently. The sample code below inserts @@ -494,7 +494,7 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_update ( * HAWK_HTB_VLEN(pair), HAWK_HTB_VPTR(pair), (int)HAWK_HTB_VLEN(pair)); * return HAWK_HTB_WALK_FORWARD; * } - * + * * hawk_htb_pair_t* cbserter ( * hawk_htb_t* htb, hawk_htb_pair_t* pair, * void* kptr, hawk_oow_t klen, void* ctx) @@ -502,54 +502,54 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_update ( * hawk_cstr_t* v = (hawk_cstr_t*)ctx; * if (pair == HAWK_NULL) * { - * // no existing key for the key + * // no existing key for the key * return hawk_htb_allocpair (htb, kptr, klen, v->ptr, v->len); * } * else * { - * // a pair with the key exists. - * // in this sample, i will append the new value to the old value + * // a pair with the key exists. + * // in this sample, i will append the new value to the old value * // separated by a comma * hawk_htb_pair_t* new_pair; * hawk_ooch_t comma = HAWK_T(','); * hawk_uint8_t* vptr; - * - * // allocate a new pair, but without filling the actual value. - * // note vptr is given HAWK_NULL for that purpose + * + * // allocate a new pair, but without filling the actual value. + * // note vptr is given HAWK_NULL for that purpose * new_pair = hawk_htb_allocpair ( - * htb, kptr, klen, HAWK_NULL, HAWK_HTB_VLEN(pair) + 1 + v->len); + * htb, kptr, klen, HAWK_NULL, HAWK_HTB_VLEN(pair) + 1 + v->len); * if (new_pair == HAWK_NULL) return HAWK_NULL; - * - * // fill in the value space + * + * // fill in the value space * vptr = HAWK_HTB_VPTR(new_pair); * hawk_memcpy (vptr, HAWK_HTB_VPTR(pair), HAWK_HTB_VLEN(pair)*HAWK_SIZEOF(hawk_ooch_t)); * vptr += HAWK_HTB_VLEN(pair)*HAWK_SIZEOF(hawk_ooch_t); * hawk_memcpy (vptr, &comma, HAWK_SIZEOF(hawk_ooch_t)); * vptr += HAWK_SIZEOF(hawk_ooch_t); * hawk_memcpy (vptr, v->ptr, v->len*HAWK_SIZEOF(hawk_ooch_t)); - * - * // this callback requires the old pair to be destroyed + * + * // this callback requires the old pair to be destroyed * hawk_htb_freepair (htb, pair); - * - * // return the new pair + * + * // return the new pair * return new_pair; * } * } - * + * * int main () * { * hawk_htb_t* s1; * int i; * hawk_ooch_t* keys[] = { HAWK_T("one"), HAWK_T("two"), HAWK_T("three") }; * hawk_ooch_t* vals[] = { HAWK_T("1"), HAWK_T("2"), HAWK_T("3"), HAWK_T("4"), HAWK_T("5") }; - * + * * hawk_open_stdsios (); * s1 = hawk_htb_open ( * HAWK_MMGR_GETDFL(), 0, 10, 70, * HAWK_SIZEOF(hawk_ooch_t), HAWK_SIZEOF(hawk_ooch_t) - * ); // note error check is skipped + * ); // note error check is skipped * hawk_htb_setstyle (s1, hawk_get_htb_style(HAWK_HTB_STYLE_INLINE_COPIERS)); - * + * * for (i = 0; i < HAWK_COUNTOF(vals); i++) * { * hawk_cstr_t ctx; @@ -560,7 +560,7 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_update ( * ); // note error check is skipped * } * hawk_htb_walk (s1, print_map_pair, HAWK_NULL); - * + * * hawk_htb_close (s1); * hawk_close_stdsios (); * return 0; @@ -576,7 +576,7 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_cbsert ( ); /** - * The hawk_htb_delete() function deletes a pair with a matching key + * The hawk_htb_delete() function deletes a pair with a matching key * @return 0 on success, -1 on failure */ HAWK_EXPORT int hawk_htb_delete ( @@ -615,7 +615,7 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_getfirstpair ( ); /** - * The hawk_htb_getnextpair() function returns the pointer to the next pair + * The hawk_htb_getnextpair() function returns the pointer to the next pair * to the current pair @a pair in a hash table. */ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_getnextpair ( @@ -624,11 +624,11 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_getnextpair ( ); /** - * The hawk_htb_allocpair() function allocates a pair for a key and a value + * The hawk_htb_allocpair() function allocates a pair for a key and a value * given. But it does not chain the pair allocated into the hash table @a htb. - * Use this function at your own risk. + * Use this function at your own risk. * - * Take note of he following special behavior when the copier is + * Take note of he following special behavior when the copier is * #HAWK_HTB_COPIER_INLINE. * - If @a kptr is #HAWK_NULL, the key space of the size @a klen is reserved but * not propagated with any data. @@ -637,8 +637,8 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_getnextpair ( */ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_allocpair ( hawk_htb_t* htb, - void* kptr, - hawk_oow_t klen, + void* kptr, + hawk_oow_t klen, void* vptr, hawk_oow_t vlen ); diff --git a/lib/hawk-map.h b/lib/hawk-map.h index 3806f1ef..4f22fe88 100644 --- a/lib/hawk-map.h +++ b/lib/hawk-map.h @@ -25,8 +25,8 @@ #ifndef _HAWK_MAP_H_ #define _HAWK_MAP_H_ -/* - * it is a convenience header file to switch easily between a red-black tree +/* + * it is a convenience header file to switch easily between a red-black tree * and a hash table. You must define either HAWK_MAP_IS_HTB or HAWK_MAP_IS_RBT * before including this file. */ @@ -84,10 +84,10 @@ # define HAWK_MAP_VCOPIER(map) HAWK_HTB_VCOPIER(map) # define HAWK_MAP_KFREEER(map) HAWK_HTB_KFREEER(map) # define HAWK_MAP_VFREEER(map) HAWK_HTB_VFREEER(map) -# define HAWK_MAP_COMPER(map) HAWK_HTB_COMPER(map) +# define HAWK_MAP_COMPER(map) HAWK_HTB_COMPER(map) # define HAWK_MAP_KEEPER(map) HAWK_HTB_KEEPER(map) -# define HAWK_MAP_KSCALE(map) HAWK_HTB_KSCALE(map) -# define HAWK_MAP_VSCALE(map) HAWK_HTB_VSCALE(map) +# define HAWK_MAP_KSCALE(map) HAWK_HTB_KSCALE(map) +# define HAWK_MAP_VSCALE(map) HAWK_HTB_VSCALE(map) # define HAWK_MAP_KPTL(p) HAWK_HTB_KPTL(p) # define HAWK_MAP_VPTL(p) HAWK_HTB_VPTL(p) # define HAWK_MAP_KPTR(p) HAWK_HTB_KPTR(p) @@ -147,10 +147,10 @@ # define HAWK_MAP_VCOPIER(map) HAWK_RBT_VCOPIER(map) # define HAWK_MAP_KFREEER(map) HAWK_RBT_KFREEER(map) # define HAWK_MAP_VFREEER(map) HAWK_RBT_VFREEER(map) -# define HAWK_MAP_COMPER(map) HAWK_RBT_COMPER(map) +# define HAWK_MAP_COMPER(map) HAWK_RBT_COMPER(map) # define HAWK_MAP_KEEPER(map) HAWK_RBT_KEEPER(map) -# define HAWK_MAP_KSCALE(map) HAWK_RBT_KSCALE(map) -# define HAWK_MAP_VSCALE(map) HAWK_RBT_VSCALE(map) +# define HAWK_MAP_KSCALE(map) HAWK_RBT_KSCALE(map) +# define HAWK_MAP_VSCALE(map) HAWK_RBT_VSCALE(map) # define HAWK_MAP_KPTL(p) HAWK_RBT_KPTL(p) # define HAWK_MAP_VPTL(p) HAWK_RBT_VPTL(p) # define HAWK_MAP_KPTR(p) HAWK_RBT_KPTR(p) diff --git a/lib/hawk-mtx.h b/lib/hawk-mtx.h index 36cb6722..a9c27a3a 100644 --- a/lib/hawk-mtx.h +++ b/lib/hawk-mtx.h @@ -45,7 +45,7 @@ typedef struct hawk_mtx_t hawk_mtx_t; typedef hawk_uintptr_t hawk_mtx_hnd_t; #elif defined(__BEOS__) - /* typedef int32 sem_id; + /* typedef int32 sem_id; * typedef sem_id hawk_mtx_hnd_t; */ typdef hawk_int32_t hawk_mtx_hnd_t; diff --git a/lib/hawk-pio.h b/lib/hawk-pio.h index ec761bde..335e8d65 100644 --- a/lib/hawk-pio.h +++ b/lib/hawk-pio.h @@ -28,7 +28,7 @@ #include #include -/** \file +/** \file * This file defines a piped interface to a child process. You can execute * a child process, read and write to its stdin, stdout, stderr, and terminate * it. It provides more advanced interface than popen() and pclose(). @@ -44,7 +44,7 @@ enum hawk_pio_flag_t HAWK_PIO_IGNOREECERR = (1 << 1), HAWK_PIO_NOAUTOFLUSH = (1 << 2), - /** execute the command via a system shell + /** execute the command via a system shell * (/bin/sh on unix/linux, cmd.exe on windows and os2) */ HAWK_PIO_SHELL = (1 << 3), @@ -55,13 +55,13 @@ enum hawk_pio_flag_t /** don't attempt to close open file descriptors unknown to pio. * it is useful only on a unix-like systems where file descriptors * not set with FD_CLOEXEC are inherited by a child process. - * you're advised to set this option if all normal file descriptors - * in your application are open with FD_CLOEXEC set. it can skip + * you're advised to set this option if all normal file descriptors + * in your application are open with FD_CLOEXEC set. it can skip * checking a bunch of file descriptors and arranging to close * them to prevent inheritance. */ HAWK_PIO_NOCLOEXEC = (1 << 5), - /** indidate that the command to hawk_pio_open()/hawk_pio_init() is + /** indidate that the command to hawk_pio_open()/hawk_pio_init() is * a pointer to a #hawk_pio_fnc_t structure. supported on unix/linux * only */ HAWK_PIO_FNCCMD = (1 << 6), @@ -86,14 +86,14 @@ enum hawk_pio_flag_t HAWK_PIO_OUTTONUL = (1 << 15), /** drop stdin */ - HAWK_PIO_DROPIN = (1 << 16), + HAWK_PIO_DROPIN = (1 << 16), /** drop stdout */ HAWK_PIO_DROPOUT = (1 << 17), /** drop stderr */ HAWK_PIO_DROPERR = (1 << 18), /** do not reread if read has been interrupted */ - HAWK_PIO_READNORETRY = (1 << 21), + HAWK_PIO_READNORETRY = (1 << 21), /** do not rewrite if write has been interrupted */ HAWK_PIO_WRITENORETRY = (1 << 22), /** return immediately from hawk_pio_wait() if a child has not exited */ @@ -114,7 +114,7 @@ enum hawk_pio_flag_t */ enum hawk_pio_hid_t { - HAWK_PIO_IN = 0, /**< stdin of a child process */ + HAWK_PIO_IN = 0, /**< stdin of a child process */ HAWK_PIO_OUT = 1, /**< stdout of a child process */ HAWK_PIO_ERR = 2 /**< stderr of a child process */ }; @@ -167,14 +167,14 @@ struct hawk_pio_pin_t { hawk_pio_hnd_t handle; hawk_tio_t* tio; - hawk_pio_t* self; + hawk_pio_t* self; }; /** * The hawk_pio_t type defines a structure to store status for piped I/O * to a child process. The hawk_pio_xxx() funtions are written around this - * type. Do not change the value of each field directly. + * type. Do not change the value of each field directly. */ struct hawk_pio_t { @@ -195,13 +195,13 @@ extern "C" { /** * The hawk_pio_open() function executes a command \a cmd and establishes - * pipes to it. #HAWK_PIO_SHELL causes the function to execute \a cmd via + * pipes to it. #HAWK_PIO_SHELL causes the function to execute \a cmd via * the default shell of an underlying system: /bin/sh on *nix, cmd.exe on win32. * 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 + * 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_BCSTRCMD is - * specified in \a flags, \a cmd is treated as a multi-byte string whose + * 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 */ @@ -304,9 +304,9 @@ HAWK_EXPORT hawk_ooi_t hawk_pio_readbytes ( /** - * The hawk_pio_write() function writes up \a size bytes/characters - * from the buffer pointed to by \a data. If #HAWK_PIO_TEXT is used - * and the \a size parameter is (hawk_oow_t)-1, the function treats + * The hawk_pio_write() function writes up \a size bytes/characters + * from the buffer pointed to by \a data. If #HAWK_PIO_TEXT is used + * and the \a size parameter is (hawk_oow_t)-1, the function treats * the \a data parameter as a pointer to a null-terminated string. * (hawk_oow_t)-1 into \a size is not treated specially if #HAWK_PIO_TEXT * is not set. @@ -328,7 +328,7 @@ HAWK_EXPORT hawk_ooi_t hawk_pio_writebytes ( ); /** - * The hawk_pio_flush() flushes buffered data if #HAWK_PIO_TEXT has been + * The hawk_pio_flush() flushes buffered data if #HAWK_PIO_TEXT has been * specified to hawk_pio_open() and hawk_pio_init(). */ HAWK_EXPORT hawk_ooi_t hawk_pio_flush ( @@ -337,8 +337,8 @@ HAWK_EXPORT hawk_ooi_t hawk_pio_flush ( ); /** - * The hawk_pio_drain() drops unflushed input and output data in the - * buffer. + * The hawk_pio_drain() drops unflushed input and output data in the + * buffer. */ HAWK_EXPORT void hawk_pio_drain ( hawk_pio_t* pio, /**< pio object */ @@ -355,7 +355,7 @@ HAWK_EXPORT void hawk_pio_end ( /** * The hawk_pio_wait() function waits for a child process to terminate. - * #HAWK_PIO_WAIT_NORETRY causes the function to return an error and set the + * #HAWK_PIO_WAIT_NORETRY causes the function to return an error and set the * \a pio->errnum field to #HAWK_PIO_EINTR if the underlying system call has * been interrupted. If #HAWK_PIO_WAIT_NOBLOCK is used, the return value of 256 * indicates that the child process has not terminated. Otherwise, 256 is never @@ -376,7 +376,7 @@ HAWK_EXPORT int hawk_pio_wait ( * kill a process that is not your child process if it has terminated but * there is a new process with the same process handle. * \return 0 on success, -1 on failure - */ + */ HAWK_EXPORT int hawk_pio_kill ( hawk_pio_t* pio /**< pio object */ ); diff --git a/lib/hawk-prv.h b/lib/hawk-prv.h index be0bb542..3ed59f02 100644 --- a/lib/hawk-prv.h +++ b/lib/hawk-prv.h @@ -60,7 +60,7 @@ typedef struct hawk_tree_t hawk_tree_t; * BEGIN { q[1]=x; y=q[1]; y(1,2,3); } # this works. * ----------------------------------------------------- * function __printer(a,b,c) { print a, b, c; } - * function show(printer, a,b,c) { printer(a, b, c); } + * function show(printer, a,b,c) { printer(a, b, c); } * BEGIN { show(__printer, 10, 20, 30); } ## passing the function value as an argumnet is ok. */ #define HAWK_ENABLE_FUN_AS_VALUE @@ -156,7 +156,7 @@ typedef struct hawk_tree_t hawk_tree_t; # if !defined(HAVE___BUILTIN_MEMSET) || \ !defined(HAVE___BUILTIN_MEMCPY) || \ !defined(HAVE___BUILTIN_MEMMOVE) || \ - !defined(HAVE___BUILTIN_MEMCMP) + !defined(HAVE___BUILTIN_MEMCMP) # include # endif @@ -257,7 +257,7 @@ struct hawk_t } opt; /* some temporary workspace */ - hawk_sbuf_t sbuf[HAWK_SBUF_COUNT]; + hawk_sbuf_t sbuf[HAWK_SBUF_COUNT]; /* parse tree */ hawk_tree_t tree; @@ -327,7 +327,7 @@ struct hawk_t hawk_sio_impl_t inf; hawk_sio_impl_t outf; - hawk_sio_lxc_t last; + hawk_sio_lxc_t last; hawk_oow_t nungots; hawk_sio_lxc_t ungot[5]; @@ -446,12 +446,12 @@ struct hawk_rtx_t struct { /* lists of values under gc management */ - hawk_gch_t g[HAWK_GC_NUM_GENS]; + hawk_gch_t g[HAWK_GC_NUM_GENS]; - /* + /* * Pressure imposed on each generation before gc is triggered * pressure[0] - number of allocation attempt since the last gc - * pressure[N] - nubmer of collections performed for generation N - 1. + * pressure[N] - nubmer of collections performed for generation N - 1. */ hawk_oow_t pressure[HAWK_GC_NUM_GENS + 1]; @@ -491,7 +491,7 @@ struct hawk_rtx_t struct { void* rs[2]; - void* fs[2]; + void* fs[2]; int ignorecase; int striprecspc; int stripstrspc; diff --git a/lib/hawk-rbt.h b/lib/hawk-rbt.h index d3dbb2a4..87b7feb5 100644 --- a/lib/hawk-rbt.h +++ b/lib/hawk-rbt.h @@ -29,37 +29,37 @@ /** \file * This file provides a red-black tree encapsulated in the #hawk_rbt_t type that - * implements a self-balancing binary search tree.Its interface is very close + * implements a self-balancing binary search tree.Its interface is very close * to #hawk_htb_t. * * This sample code adds a series of keys and values and print them * in descending key order. * \code * #include - * + * * static hawk_rbt_walk_t walk (hawk_rbt_t* rbt, hawk_rbt_pair_t* pair, void* ctx) * { * hawk_printf (HAWK_T("key = %d, value = %d\n"), * *(int*)HAWK_RBT_KPTR(pair), *(int*)HAWK_RBT_VPTR(pair)); * return HAWK_RBT_WALK_FORWARD; * } - * + * * int main () * { * hawk_rbt_t* s1; * int i; - * + * * s1 = hawk_rbt_open (HAWK_MMGR_GETDFL(), 0, 1, 1); // error handling skipped * hawk_rbt_setstyle (s1, hawk_get_rbt_style(HAWK_RBT_STYLE_INLINE_COPIERS)); - * + * * for (i = 0; i < 20; i++) * { * int x = i * 20; * hawk_rbt_insert (s1, &i, HAWK_SIZEOF(i), &x, HAWK_SIZEOF(x)); // eror handling skipped * } - * + * * hawk_rbt_rwalk (s1, walk, HAWK_NULL); - * + * * hawk_rbt_close (s1); * return 0; * } @@ -69,7 +69,7 @@ typedef struct hawk_rbt_t hawk_rbt_t; typedef struct hawk_rbt_pair_t hawk_rbt_pair_t; -/** +/** * The hawk_rbt_walk_t type defines values that the callback function can * return to control hawk_rbt_walk() and hawk_rbt_rwalk(). */ @@ -96,7 +96,7 @@ typedef enum hawk_rbt_id_t hawk_rbt_id_t; */ typedef void* (*hawk_rbt_copier_t) ( hawk_rbt_t* rbt /**< red-black tree */, - void* dptr /**< pointer to a key or a value */, + void* dptr /**< pointer to a key or a value */, hawk_oow_t dlen /**< length of a key or a value */ ); @@ -117,17 +117,17 @@ typedef void (*hawk_rbt_freeer_t) ( * key is greater than the second key, -1 otherwise. */ typedef int (*hawk_rbt_comper_t) ( - const hawk_rbt_t* rbt, /**< red-black tree */ + const hawk_rbt_t* rbt, /**< red-black tree */ const void* kptr1, /**< key pointer */ - hawk_oow_t klen1, /**< key length */ + hawk_oow_t klen1, /**< key length */ const void* kptr2, /**< key pointer */ hawk_oow_t klen2 /**< key length */ ); /** - * The hawk_rbt_keeper_t type defines a value keeper that is called when + * The hawk_rbt_keeper_t type defines a value keeper that is called when * a value is retained in the context that it should be destroyed because - * it is identical to a new value. Two values are identical if their + * it is identical to a new value. Two values are identical if their * pointers and lengths are equal. */ typedef void (*hawk_rbt_keeper_t) ( @@ -147,12 +147,12 @@ typedef hawk_rbt_walk_t (*hawk_rbt_walker_t) ( /** * The hawk_rbt_cbserter_t type defines a callback function for hawk_rbt_cbsert(). - * The hawk_rbt_cbserter() function calls it to allocate a new pair for the + * The hawk_rbt_cbserter() function calls it to allocate a new pair for the * key pointed to by \a kptr of the length \a klen and the callback context * \a ctx. The second parameter \a pair is passed the pointer to the existing * pair for the key or #HAWK_NULL in case of no existing key. The callback * must return a pointer to a new or a reallocated pair. When reallocating the - * existing pair, this callback must destroy the existing pair and return the + * existing pair, this callback must destroy the existing pair and return the * newly reallocated pair. It must return #HAWK_NULL for failure. */ typedef hawk_rbt_pair_t* (*hawk_rbt_cbserter_t) ( @@ -171,10 +171,10 @@ enum hawk_rbt_pair_color_t typedef enum hawk_rbt_pair_color_t hawk_rbt_pair_color_t; /** - * The hawk_rbt_pair_t type defines red-black tree pair. A pair is composed - * of a key and a value. It maintains pointers to the beginning of a key and - * a value plus their length. The length is scaled down with the scale factor - * specified in an owning tree. Use macros defined in the + * The hawk_rbt_pair_t type defines red-black tree pair. A pair is composed + * of a key and a value. It maintains pointers to the beginning of a key and + * a value plus their length. The length is scaled down with the scale factor + * specified in an owning tree. Use macros defined in the */ struct hawk_rbt_pair_t { @@ -199,8 +199,8 @@ struct hawk_rbt_pair_t typedef struct hawk_rbt_style_t hawk_rbt_style_t; /** - * The hawk_rbt_style_t type defines callback function sets for key/value - * pair manipulation. + * The hawk_rbt_style_t type defines callback function sets for key/value + * pair manipulation. */ struct hawk_rbt_style_t { @@ -354,10 +354,10 @@ HAWK_EXPORT const hawk_rbt_style_t* hawk_rbt_getstyle ( ); /** - * The hawk_rbt_setstyle() function sets internal manipulation callback + * The hawk_rbt_setstyle() function sets internal manipulation callback * functions for data construction, destruction, comparison, etc. * The callback structure pointed to by \a style must outlive the tree - * pointed to by \a htb as the tree doesn't copy the contents of the + * pointed to by \a htb as the tree doesn't copy the contents of the * structure. */ HAWK_EXPORT void hawk_rbt_setstyle ( @@ -373,10 +373,10 @@ HAWK_EXPORT hawk_oow_t hawk_rbt_getsize ( ); /** - * The hawk_rbt_search() function searches red-black tree to find a pair with a + * The hawk_rbt_search() function searches red-black tree to find a pair with a * matching key. It returns the pointer to the pair found. If it fails * to find one, it returns HAWK_NULL. - * \return pointer to the pair with a maching key, + * \return pointer to the pair with a maching key, * or HAWK_NULL if no match is found. */ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_search ( @@ -386,12 +386,12 @@ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_search ( ); /** - * The hawk_rbt_upsert() function searches red-black tree for the pair with a + * The hawk_rbt_upsert() function searches red-black tree for the pair with a * matching key. If one is found, it updates the pair. Otherwise, it inserts - * a new pair with the key and the value given. It returns the pointer to the + * a new pair with the key and the value given. It returns the pointer to the * pair updated or inserted. - * \return a pointer to the updated or inserted pair on success, - * HAWK_NULL on failure. + * \return a pointer to the updated or inserted pair on success, + * HAWK_NULL on failure. */ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_upsert ( hawk_rbt_t* rbt, /**< red-black tree */ @@ -403,9 +403,9 @@ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_upsert ( /** * The hawk_rbt_ensert() function inserts a new pair with the key and the value - * given. If there exists a pair with the key given, the function returns + * given. If there exists a pair with the key given, the function returns * the pair containing the key. - * \return pointer to a pair on success, HAWK_NULL on failure. + * \return pointer to a pair on success, HAWK_NULL on failure. */ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_ensert ( hawk_rbt_t* rbt, /**< red-black tree */ @@ -417,9 +417,9 @@ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_ensert ( /** * The hawk_rbt_insert() function inserts a new pair with the key and the value - * given. If there exists a pair with the key given, the function returns + * given. If there exists a pair with the key given, the function returns * HAWK_NULL without channging the value. - * \return pointer to the pair created on success, HAWK_NULL on failure. + * \return pointer to the pair created on success, HAWK_NULL on failure. */ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_insert ( hawk_rbt_t* rbt, /**< red-black tree */ @@ -443,7 +443,7 @@ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_update ( ); /** - * The hawk_rbt_cbsert() function inserts a key/value pair by delegating pair + * The hawk_rbt_cbsert() function inserts a key/value pair by delegating pair * allocation to a callback function. Depending on the callback function, * it may behave like hawk_rbt_insert(), hawk_rbt_upsert(), hawk_rbt_update(), * hawk_rbt_ensert(), or totally differently. The sample code below inserts @@ -458,7 +458,7 @@ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_update ( * HAWK_RBT_VLEN(pair), HAWK_RBT_VPTR(pair), (int)HAWK_RBT_VLEN(pair)); * return HAWK_RBT_WALK_FORWARD; * } - * + * * hawk_rbt_pair_t* cbserter ( * hawk_rbt_t* rbt, hawk_rbt_pair_t* pair, * void* kptr, hawk_oow_t klen, void* ctx) @@ -466,53 +466,53 @@ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_update ( * hawk_cstr_t* v = (hawk_cstr_t*)ctx; * if (pair == HAWK_NULL) * { - * // no existing key for the key + * // no existing key for the key * return hawk_rbt_allocpair (rbt, kptr, klen, v->ptr, v->len); * } * else * { - * // a pair with the key exists. - * // in this sample, i will append the new value to the old value + * // a pair with the key exists. + * // in this sample, i will append the new value to the old value * // separated by a comma * hawk_rbt_pair_t* new_pair; * hawk_ooch_t comma = HAWK_T(','); * hawk_oob_t* vptr; - * - * // allocate a new pair, but without filling the actual value. - * // note vptr is given HAWK_NULL for that purpose + * + * // allocate a new pair, but without filling the actual value. + * // note vptr is given HAWK_NULL for that purpose * new_pair = hawk_rbt_allocpair ( - * rbt, kptr, klen, HAWK_NULL, pair->vlen + 1 + v->len); + * rbt, kptr, klen, HAWK_NULL, pair->vlen + 1 + v->len); * if (new_pair == HAWK_NULL) return HAWK_NULL; - * - * // fill in the value space + * + * // fill in the value space * vptr = new_pair->vptr; * hawk_memcpy (vptr, pair->vptr, pair->vlen*HAWK_SIZEOF(hawk_ooch_t)); * vptr += pair->vlen*HAWK_SIZEOF(hawk_ooch_t); * hawk_memcpy (vptr, &comma, HAWK_SIZEOF(hawk_ooch_t)); * vptr += HAWK_SIZEOF(hawk_ooch_t); * hawk_memcpy (vptr, v->ptr, v->len*HAWK_SIZEOF(hawk_ooch_t)); - * - * // this callback requires the old pair to be destroyed + * + * // this callback requires the old pair to be destroyed * hawk_rbt_freepair (rbt, pair); - * - * // return the new pair + * + * // return the new pair * return new_pair; * } * } - * + * * int main () * { * hawk_rbt_t* s1; * int i; * hawk_ooch_t* keys[] = { HAWK_T("one"), HAWK_T("two"), HAWK_T("three") }; * hawk_ooch_t* vals[] = { HAWK_T("1"), HAWK_T("2"), HAWK_T("3"), HAWK_T("4"), HAWK_T("5") }; - * + * * s1 = hawk_rbt_open ( * HAWK_MMGR_GETDFL(), 0, * HAWK_SIZEOF(hawk_ooch_t), HAWK_SIZEOF(hawk_ooch_t) - * ); // note error check is skipped + * ); // note error check is skipped * hawk_rbt_setstyle (s1, &style1); - * + * * for (i = 0; i < HAWK_COUNTOF(vals); i++) * { * hawk_cstr_t ctx; @@ -523,7 +523,7 @@ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_update ( * ); // note error check is skipped * } * hawk_rbt_walk (s1, print_map_pair, HAWK_NULL); - * + * * hawk_rbt_close (s1); * return 0; * } @@ -538,7 +538,7 @@ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_cbsert ( ); /** - * The hawk_rbt_delete() function deletes a pair with a matching key + * The hawk_rbt_delete() function deletes a pair with a matching key * \return 0 on success, -1 on failure */ HAWK_EXPORT int hawk_rbt_delete ( @@ -582,7 +582,7 @@ HAWK_EXPORT void hawk_rbt_unprotectitr ( #endif /** - * The hawk_rbt_walk() function traverses a red-black tree in preorder + * The hawk_rbt_walk() function traverses a red-black tree in preorder * from the leftmost child. */ HAWK_EXPORT void hawk_rbt_walk ( @@ -592,7 +592,7 @@ HAWK_EXPORT void hawk_rbt_walk ( ); /** - * The hawk_rbt_walk() function traverses a red-black tree in preorder + * The hawk_rbt_walk() function traverses a red-black tree in preorder * from the rightmost child. */ HAWK_EXPORT void hawk_rbt_rwalk ( @@ -602,11 +602,11 @@ HAWK_EXPORT void hawk_rbt_rwalk ( ); /** - * The hawk_rbt_allocpair() function allocates a pair for a key and a value + * The hawk_rbt_allocpair() function allocates a pair for a key and a value * given. But it does not chain the pair allocated into the red-black tree \a rbt. - * Use this function at your own risk. + * Use this function at your own risk. * - * Take note of he following special behavior when the copier is + * Take note of he following special behavior when the copier is * #HAWK_RBT_COPIER_INLINE. * - If \a kptr is #HAWK_NULL, the key space of the size \a klen is reserved but * not propagated with any data. @@ -615,7 +615,7 @@ HAWK_EXPORT void hawk_rbt_rwalk ( */ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_allocpair ( hawk_rbt_t* rbt, - void* kptr, + void* kptr, hawk_oow_t klen, void* vptr, hawk_oow_t vlen @@ -639,7 +639,7 @@ HAWK_EXPORT int hawk_rbt_dflcomp ( const void* kptr1, hawk_oow_t klen1, const void* kptr2, - hawk_oow_t klen2 + hawk_oow_t klen2 ); #if defined(__cplusplus) diff --git a/lib/hawk-sed.h b/lib/hawk-sed.h index 10e4e65d..d3b0207d 100644 --- a/lib/hawk-sed.h +++ b/lib/hawk-sed.h @@ -31,10 +31,10 @@ /** @file * This file defines data types and functions to use for creating a custom - * stream editor commonly available on many platforms. A stream editor is - * a non-interactive text editing tool that reads text from an input stream, + * stream editor commonly available on many platforms. A stream editor is + * a non-interactive text editing tool that reads text from an input stream, * stores it to pattern space, manipulates the pattern space by applying a set - * of editing commands, and writes the pattern space to an output stream. + * of editing commands, and writes the pattern space to an output stream. * Typically, the input and output streams are a console or a file. * * @code @@ -46,7 +46,7 @@ */ /** @struct hawk_sed_t - * The hawk_sed_t type defines a stream editor. The structural details are + * The hawk_sed_t type defines a stream editor. The structural details are * hidden as it is a relatively complex data type and fragile to external * changes. To use a stream editor, you typically can: * @@ -56,7 +56,7 @@ * - destroy it with hawk_sed_close() when done. * * The input and output streams needed by hawk_sed_exec() are implemented in - * the form of callback functions. You should implement two functions + * the form of callback functions. You should implement two functions * conforming to the ::hawk_sed_io_impl_t type. */ typedef struct hawk_sed_t hawk_sed_t; @@ -72,7 +72,7 @@ struct hawk_sed_alt_t HAWK_SED_HDR; }; -typedef struct hawk_sed_adr_t hawk_sed_adr_t; +typedef struct hawk_sed_adr_t hawk_sed_adr_t; typedef struct hawk_sed_cmd_t hawk_sed_cmd_t; struct hawk_sed_adr_t @@ -88,7 +88,7 @@ struct hawk_sed_adr_t HAWK_SED_ADR_RELLINEM /* relative line in the multiples - only in second address */ } type; - union + union { hawk_oow_t lno; void* rex; @@ -131,14 +131,14 @@ struct hawk_sed_cut_sel_t #define HAWK_SED_CMD_HOLD_APPEND HAWK_T('H') #define HAWK_SED_CMD_RELEASE HAWK_T('g') #define HAWK_SED_CMD_RELEASE_APPEND HAWK_T('G') -#define HAWK_SED_CMD_EXCHANGE HAWK_T('x') +#define HAWK_SED_CMD_EXCHANGE HAWK_T('x') #define HAWK_SED_CMD_NEXT HAWK_T('n') #define HAWK_SED_CMD_NEXT_APPEND HAWK_T('N') #define HAWK_SED_CMD_READ_FILE HAWK_T('r') #define HAWK_SED_CMD_READ_FILELN HAWK_T('R') #define HAWK_SED_CMD_WRITE_FILE HAWK_T('w') #define HAWK_SED_CMD_WRITE_FILELN HAWK_T('W') -#define HAWK_SED_CMD_BRANCH HAWK_T('b') +#define HAWK_SED_CMD_BRANCH HAWK_T('b') #define HAWK_SED_CMD_BRANCH_COND HAWK_T('t') #define HAWK_SED_CMD_SUBSTITUTE HAWK_T('s') #define HAWK_SED_CMD_TRANSLATE HAWK_T('y') @@ -160,7 +160,7 @@ struct hawk_sed_cmd_t union { /* text for the a, i, c commands */ - hawk_oocs_t text; + hawk_oocs_t text; /* file name for r, w, R, W */ hawk_oocs_t file; @@ -205,7 +205,7 @@ struct hawk_sed_cmd_t hawk_oow_t fcount; hawk_oow_t ccount; } cut; - } u; + } u; struct { @@ -214,9 +214,9 @@ struct hawk_sed_cmd_t int c_ready; - /* points to the next command for fast traversal and + /* points to the next command for fast traversal and * fast random jumps */ - hawk_sed_cmd_t* next; + hawk_sed_cmd_t* next; } state; }; @@ -235,7 +235,7 @@ enum hawk_sed_opt_t }; typedef enum hawk_sed_opt_t hawk_sed_opt_t; -/** +/** * The hawk_sed_trait_t type defines various trait codes for a stream editor. * Options can be OR'ed with each other and be passed to a stream editor with * the hawk_sed_setopt() function. @@ -255,7 +255,7 @@ enum hawk_sed_trait_t typedef enum hawk_sed_trait_t hawk_sed_trait_t; /** - * The hawk_sed_io_cmd_t type defines I/O command codes. The code indicates + * The hawk_sed_io_cmd_t type defines I/O command codes. The code indicates * the action to take in an I/O handler. */ enum hawk_sed_io_cmd_t @@ -268,7 +268,7 @@ enum hawk_sed_io_cmd_t typedef enum hawk_sed_io_cmd_t hawk_sed_io_cmd_t; /** - * The hawk_sed_io_arg_t type defines a data structure required by + * The hawk_sed_io_arg_t type defines a data structure required by * an I/O handler. */ struct hawk_sed_io_arg_t @@ -278,7 +278,7 @@ struct hawk_sed_io_arg_t }; typedef struct hawk_sed_io_arg_t hawk_sed_io_arg_t; -/** +/** * The hawk_sed_io_impl_t type defines an I/O handler. I/O handlers are called by * hawk_sed_exec(). */ @@ -345,7 +345,7 @@ typedef void (*hawk_sed_tracer_t) ( /** * The hawk_sed_space_t type defines the types of - * sed bufferspaces. + * sed bufferspaces. */ enum hawk_sed_space_t { @@ -360,8 +360,8 @@ typedef enum hawk_sed_space_t hawk_sed_space_t; /** * This section defines easier-to-use helper interface for a stream editor. * If you don't care about the details of memory management and I/O handling, - * you can choose to use the helper functions provided here. It is - * a higher-level interface that is easier to use as it implements + * you can choose to use the helper functions provided here. It is + * a higher-level interface that is easier to use as it implements * default handlers for I/O and memory management. */ @@ -377,7 +377,7 @@ enum hawk_sed_iostd_type_t HAWK_SED_IOSTD_FILEU, /**< file */ HAWK_SED_IOSTD_OOCS, /**< string */ HAWK_SED_IOSTD_BCS, - HAWK_SED_IOSTD_UCS, + HAWK_SED_IOSTD_UCS, HAWK_SED_IOSTD_SIO /**< sio */ }; typedef enum hawk_sed_iostd_type_t hawk_sed_iostd_type_t; @@ -401,7 +401,7 @@ struct hawk_sed_iostd_t /** a stream created with the file path is set with this * cmgr if it is not #HAWK_NULL. */ hawk_cmgr_t* cmgr; - } file; + } file; struct { @@ -415,10 +415,10 @@ struct hawk_sed_iostd_t hawk_cmgr_t* cmgr; } fileu; - /** + /** * input string or dynamically allocated output string * - * For input, the ptr and the len field of str indicates the + * For input, the ptr and the len field of str indicates the * pointer and the length of a string to read. You must set * these two fields before calling hawk_sed_execstd(). * @@ -429,7 +429,7 @@ struct hawk_sed_iostd_t * set by hawk_sed_execstd() and valid while the relevant sed * object is alive. You must free the memory chunk pointed to by * the ptr field with hawk_sed_freemem() once you're done with it - * to avoid memory leaks. + * to avoid memory leaks. */ hawk_oocs_t oocs; hawk_bcs_t bcs; @@ -454,8 +454,8 @@ extern "C" { * data through out its lifetime. An extension area is allocated if an * extension size greater than 0 is specified. You can access it with the * hawk_sed_getxtn() function and use it to store arbitrary data associated - * with the object. When done, you should destroy the object with the - * hawk_sed_close() function to avoid any resource leaks including memory. + * with the object. When done, you should destroy the object with the + * hawk_sed_close() function to avoid any resource leaks including memory. * @return pointer to a stream editor on success, HAWK_NULL on failure */ HAWK_EXPORT hawk_sed_t* hawk_sed_open ( @@ -482,8 +482,8 @@ HAWK_EXPORT void hawk_sed_close ( static HAWK_INLINE void* hawk_sed_getxtn (hawk_sed_t* sed) { return (void*)((hawk_uint8_t*)sed + ((hawk_sed_alt_t*)sed)->_instsize); } /** - * The hawk_sed_getgem() function gets the pointer to the gem structure of the - * sed object. + * The hawk_sed_getgem() function gets the pointer to the gem structure of the + * sed object. */ static HAWK_INLINE hawk_gem_t* hawk_sed_getgem (hawk_sed_t* sed) { return &((hawk_sed_alt_t*)sed)->_gem; } @@ -521,7 +521,7 @@ HAWK_EXPORT int hawk_sed_getopt ( ); /** - * The hawk_sed_setopt() function sets the value of an option + * The hawk_sed_setopt() function sets the value of an option * specified by \a id to the value pointed to by \a value. * * The \a value field is dependent on \a id: @@ -538,18 +538,18 @@ HAWK_EXPORT int hawk_sed_setopt ( ); HAWK_EXPORT hawk_errstr_t hawk_sed_geterrstr ( - hawk_sed_t* sed + hawk_sed_t* sed ); /** - * The hawk_sed_geterrnum() function returns the number of the last error + * The hawk_sed_geterrnum() function returns the number of the last error * occurred. * \return error number */ /** - * The hawk_sed_geterror() function gets an error number, an error location, - * and an error message. The information is set to the memory area pointed + * The hawk_sed_geterror() function gets an error number, an error location, + * and an error message. The information is set to the memory area pointed * to by each parameter. */ #if defined(HAWK_HAVE_INLINE) @@ -580,7 +580,7 @@ static HAWK_INLINE void hawk_sed_geterror (hawk_sed_t* sed, hawk_errnum_t* errnu /** - * The hawk_sed_seterrnum() function sets the error information omitting + * The hawk_sed_seterrnum() function sets the error information omitting * error location. You must pass a non-NULL for \a errarg if the specified * error number \a errnum requires one or more arguments to format an * error message. @@ -656,7 +656,7 @@ HAWK_EXPORT void hawk_sed_pushecb ( /** * The hawk_sed_comp() function compiles editing commands into an internal form. - * @return 0 on success, -1 on error + * @return 0 on success, -1 on error */ HAWK_EXPORT int hawk_sed_comp ( hawk_sed_t* sed, /**< stream editor */ @@ -687,10 +687,10 @@ HAWK_EXPORT void hawk_sed_halt ( HAWK_EXPORT int hawk_sed_ishalt ( hawk_sed_t* sed /**< stream editor */ ); - + /** * The hawk_sed_getcompid() function returns the latest - * identifier successfully set with hawk_sed_setcompid(). + * identifier successfully set with hawk_sed_setcompid(). */ HAWK_EXPORT const hawk_ooch_t* hawk_sed_getcompid ( hawk_sed_t* sed @@ -699,8 +699,8 @@ HAWK_EXPORT const hawk_ooch_t* hawk_sed_getcompid ( /** * The hawk_sed_setcompid() functions duplicates a string * pointed to by @a id and stores it internally to identify - * the script currently being compiled. The lid field of the - * current command being compiled in the script is set to the + * the script currently being compiled. The lid field of the + * current command being compiled in the script is set to the * lastest identifer successfully set with this function. * If this function fails, the location set in the command * may be wrong. @@ -789,7 +789,7 @@ HAWK_EXPORT void hawk_sed_getspace ( /** * The hawk_sed_openstd() function creates a stream editor with the default - * memory manager and initializes it. + * memory manager and initializes it. * \return pointer to a stream editor on success, #HAWK_NULL on failure. */ HAWK_EXPORT hawk_sed_t* hawk_sed_openstd ( @@ -798,8 +798,8 @@ HAWK_EXPORT hawk_sed_t* hawk_sed_openstd ( ); /** - * The hawk_sed_openstdwithmmgr() function creates a stream editor with a - * user-defined memory manager. It is equivalent to hawk_sed_openstd(), + * The hawk_sed_openstdwithmmgr() function creates a stream editor with a + * user-defined memory manager. It is equivalent to hawk_sed_openstd(), * except that you can specify your own memory manager. * \return pointer to a stream editor on success, #HAWK_NULL on failure. */ @@ -814,8 +814,8 @@ HAWK_EXPORT hawk_sed_t* hawk_sed_openstdwithmmgr ( * The hawk_sed_compstd() function compiles sed scripts specified in * an array of stream resources. The end of the array is indicated * by an element whose type is #HAWK_SED_IOSTD_NULL. However, the type - * of the first element shall not be #HAWK_SED_IOSTD_NULL. The output - * parameter \a count is set to the count of stream resources + * of the first element shall not be #HAWK_SED_IOSTD_NULL. The output + * parameter \a count is set to the count of stream resources * opened on both success and failure. You can pass #HAWK_NULL to \a * count if the count is not needed. * @@ -831,26 +831,26 @@ HAWK_EXPORT int hawk_sed_compstd ( * The hawk_sed_compstdfile() function compiles a sed script from * a single file \a infile. If \a infile is #HAWK_NULL, it reads * the script from the standard input. - * When #HAWK_OOCH_IS_UCH is defined, it converts the multibyte - * sequences in the file \a infile to wide characters via the - * #hawk_cmgr_t interface \a cmgr. If \a cmgr is #HAWK_NULL, it uses + * When #HAWK_OOCH_IS_UCH is defined, it converts the multibyte + * sequences in the file \a infile to wide characters via the + * #hawk_cmgr_t interface \a cmgr. If \a cmgr is #HAWK_NULL, it uses * the default interface. It calls cmgr->mbtowc() for conversion. * \return 0 on success, -1 on failure */ HAWK_EXPORT int hawk_sed_compstdfile ( - hawk_sed_t* sed, + hawk_sed_t* sed, const hawk_ooch_t* infile, hawk_cmgr_t* cmgr ); HAWK_EXPORT int hawk_sed_compstdfileb ( - hawk_sed_t* sed, + hawk_sed_t* sed, const hawk_bch_t* infile, hawk_cmgr_t* cmgr ); HAWK_EXPORT int hawk_sed_compstdfileu ( - hawk_sed_t* sed, + hawk_sed_t* sed, const hawk_uch_t* infile, hawk_cmgr_t* cmgr ); @@ -861,17 +861,17 @@ HAWK_EXPORT int hawk_sed_compstdfileu ( * \return 0 on success, -1 on failure */ HAWK_EXPORT int hawk_sed_compstdoocstr ( - hawk_sed_t* sed, + hawk_sed_t* sed, const hawk_ooch_t* script ); /** - * The hawk_sed_compstdoocs() function compiles a sed script of the + * The hawk_sed_compstdoocs() function compiles a sed script of the * length \a script->len pointed to by \a script->ptr. * \return 0 on success, -1 on failure */ HAWK_EXPORT int hawk_sed_compstdoocs ( - hawk_sed_t* sed, + hawk_sed_t* sed, const hawk_oocs_t* script ); @@ -879,10 +879,10 @@ HAWK_EXPORT int hawk_sed_compstdoocs ( * The hawk_sed_execstd() function executes a compiled script * over input streams \a in and an output stream \a out. * - * If \a in is not #HAWK_NULL, it must point to an array of stream + * If \a in is not #HAWK_NULL, it must point to an array of stream * resources whose end is indicated by an element with #HAWK_SED_IOSTD_NULL * type. However, the type of the first element \a in[0].type show not - * be #HAWK_SED_IOSTD_NULL. It requires at least 1 valid resource to be + * be #HAWK_SED_IOSTD_NULL. It requires at least 1 valid resource to be * included in the array. * * If \a in is #HAWK_NULL, the standard console input is used. @@ -898,7 +898,7 @@ HAWK_EXPORT int hawk_sed_execstd ( /** * The hawk_sed_execstdfile() function executes a compiled script - * over a single input file \a infile and a single output file \a + * over a single input file \a infile and a single output file \a * outfile. * * If \a infile is #HAWK_NULL, the standard console input is used. diff --git a/lib/hawk-sio.h b/lib/hawk-sio.h index 38a1b1b9..d807c679 100644 --- a/lib/hawk-sio.h +++ b/lib/hawk-sio.h @@ -21,7 +21,7 @@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - + #ifndef _HAWK_SIO_H_ #define _HAWK_SIO_H_ @@ -174,9 +174,9 @@ HAWK_EXPORT hawk_sio_hnd_t hawk_sio_gethnd ( const hawk_sio_t* sio ); -/** +/** * The hawk_sio_getpath() returns the file path used to open the stream. - * It returns #HAWK_NULL if #HAWK_SIO_HANDLE was on or #HAWK_SIO_KEEPPATH + * It returns #HAWK_NULL if #HAWK_SIO_HANDLE was on or #HAWK_SIO_KEEPPATH * was off at the time of opening. */ HAWK_EXPORT const hawk_ooch_t* hawk_sio_getpath ( @@ -217,10 +217,10 @@ HAWK_EXPORT hawk_ooi_t hawk_sio_getbchars ( ); /** - * The hawk_sio_getucstr() function reads at most @a size - 1 characters + * The hawk_sio_getucstr() function reads at most @a size - 1 characters * from the stream @a sio into the buffer @a buf. If a new line or EOF * is encountered, it stops reading from the stream. It null-terminates - * the buffer if @a size is greater than 0. + * the buffer if @a size is greater than 0. */ HAWK_EXPORT hawk_ooi_t hawk_sio_getucstr ( hawk_sio_t* sio, @@ -229,9 +229,9 @@ HAWK_EXPORT hawk_ooi_t hawk_sio_getucstr ( ); /** - * The hawk_sio_getuchars() function reads at most @a size characters + * The hawk_sio_getuchars() function reads at most @a size characters * from the stream @a sio into the buffer @a buf. If a new line or EOF - * is encountered, it stops reading from the stream. + * is encountered, it stops reading from the stream. */ HAWK_EXPORT hawk_ooi_t hawk_sio_getuchars ( hawk_sio_t* sio, @@ -250,12 +250,12 @@ HAWK_EXPORT hawk_ooi_t hawk_sio_getuchars ( #endif HAWK_EXPORT hawk_ooi_t hawk_sio_putbchar ( - hawk_sio_t* sio, + hawk_sio_t* sio, hawk_bch_t c ); HAWK_EXPORT hawk_ooi_t hawk_sio_putuchar ( - hawk_sio_t* sio, + hawk_sio_t* sio, hawk_uch_t c ); @@ -271,13 +271,13 @@ HAWK_EXPORT hawk_ooi_t hawk_sio_putucstr ( HAWK_EXPORT hawk_ooi_t hawk_sio_putbchars ( - hawk_sio_t* sio, + hawk_sio_t* sio, const hawk_bch_t* str, hawk_oow_t size ); HAWK_EXPORT hawk_ooi_t hawk_sio_putuchars ( - hawk_sio_t* sio, + hawk_sio_t* sio, const hawk_uch_t* str, hawk_oow_t size ); @@ -322,7 +322,7 @@ HAWK_EXPORT int hawk_sio_truncate ( * of the file. */ HAWK_EXPORT int hawk_sio_seek ( - hawk_sio_t* sio, + hawk_sio_t* sio, hawk_sio_pos_t* pos, hawk_sio_ori_t origin ); diff --git a/lib/hawk-skad.h b/lib/hawk-skad.h index f9056a8e..951a5f94 100644 --- a/lib/hawk-skad.h +++ b/lib/hawk-skad.h @@ -71,8 +71,8 @@ typedef struct hawk_skad_t hawk_skad_t; #define HAWK_IP4AD_STRLEN (15) /* not including the terminating '\0' */ #define HAWK_IP6AD_STRLEN (45) /* not including the terminating '\0'. pure IPv6 address, not including the scope(e.g. %10, %eth0) */ -/* size large enough to hold the ip address plus port number. - * [IPV6ADDR%SCOPE]:PORT -> 9 for [] % : and PORT +/* size large enough to hold the ip address plus port number. + * [IPV6ADDR%SCOPE]:PORT -> 9 for [] % : and PORT * Let's reserve 16 for SCOPE and not include the terminting '\0' */ #define HAWK_SKAD_IP_STRLEN (HAWK_IP6AD_STRLEN + 25) @@ -86,7 +86,7 @@ typedef struct hawk_skad_t hawk_skad_t; #include struct HAWK_PACKED hawk_ethad_t { - hawk_uint8_t v[HAWK_ETHAD_LEN]; + hawk_uint8_t v[HAWK_ETHAD_LEN]; }; typedef struct hawk_ethad_t hawk_ethad_t; @@ -98,7 +98,7 @@ typedef struct hawk_ip4ad_t hawk_ip4ad_t; struct HAWK_PACKED hawk_ip6ad_t { - hawk_uint8_t v[HAWK_IP6AD_LEN]; + hawk_uint8_t v[HAWK_IP6AD_LEN]; }; typedef struct hawk_ip6ad_t hawk_ip6ad_t; #include @@ -124,7 +124,7 @@ HAWK_EXPORT void hawk_skad_init_for_ip_with_bytes ( hawk_skad_t* skad, hawk_uint16_t port, const hawk_uint8_t* bytes, - hawk_oow_t len + hawk_oow_t len ); HAWK_EXPORT void hawk_skad_init_for_eth ( diff --git a/lib/hawk-std.h b/lib/hawk-std.h index b15347fb..88e54e67 100644 --- a/lib/hawk-std.h +++ b/lib/hawk-std.h @@ -31,7 +31,7 @@ * This file defines functions and data types that help you create * an hawk interpreter with less effort. It is designed to be as close * to conventional hawk implementations as possible. - * + * * The source script handler does not evaluate a file name of the "var=val" * form as an assignment expression. Instead, it just treats it as a * normal file name. @@ -49,7 +49,7 @@ enum hawk_parsestd_type_t HAWK_PARSESTD_OOCS = 4, /**< length-bounded string */ HAWK_PARSESTD_BCS = 5, HAWK_PARSESTD_UCS = 6 - + }; typedef enum hawk_parsestd_type_t hawk_parsestd_type_t; @@ -65,37 +65,37 @@ struct hawk_parsestd_t struct { /** file path to open. #HAWK_NULL or '-' for stdin/stdout. */ - const hawk_ooch_t* path; + const hawk_ooch_t* path; /** a stream created with the file path is set with this * cmgr if it is not #HAWK_NULL. */ - hawk_cmgr_t* cmgr; + hawk_cmgr_t* cmgr; } file; struct { /** file path to open. #HAWK_NULL or '-' for stdin/stdout. */ - const hawk_bch_t* path; + const hawk_bch_t* path; /** a stream created with the file path is set with this * cmgr if it is not #HAWK_NULL. */ - hawk_cmgr_t* cmgr; + hawk_cmgr_t* cmgr; } fileb; struct { /** file path to open. #HAWK_NULL or '-' for stdin/stdout. */ - const hawk_uch_t* path; + const hawk_uch_t* path; /** a stream created with the file path is set with this * cmgr if it is not #HAWK_NULL. */ - hawk_cmgr_t* cmgr; + hawk_cmgr_t* cmgr; } fileu; - /** + /** * input string or dynamically allocated output string * - * For input, the ptr and the len field of str indicates the + * For input, the ptr and the len field of str indicates the * pointer and the length of a string to read. You must set * these fields before calling hawk_parsestd(). * @@ -105,8 +105,8 @@ struct hawk_parsestd_t * fields before calling hawk_parsestd() because they are set * by hawk_parsestd() and valid while the relevant hawk object * is alive. You must free the memory chunk pointed to by the - * ptr field with hawk_freemem() once you're done with it to - * avoid memory leaks. + * ptr field with hawk_freemem() once you're done with it to + * avoid memory leaks. */ hawk_oocs_t oocs; hawk_bcs_t bcs; @@ -121,7 +121,7 @@ extern "C" { #endif /** - * The hawk_openstd() function creates an hawk object using the default + * The hawk_openstd() function creates an hawk object using the default * memory manager and primitive functions. Besides, it adds a set of * standard intrinsic functions like atan, system, etc. Use this function * over hawk_open() if you don't need finer-grained customization. @@ -132,8 +132,8 @@ HAWK_EXPORT hawk_t* hawk_openstd ( ); /** - * The hawk_openstdwithmmgr() function creates an hawk object with a - * user-defined memory manager. It is equivalent to hawk_openstd(), + * The hawk_openstdwithmmgr() function creates an hawk object with a + * user-defined memory manager. It is equivalent to hawk_openstd(), * except that you can specify your own memory manager. */ HAWK_EXPORT hawk_t* hawk_openstdwithmmgr ( @@ -145,7 +145,7 @@ HAWK_EXPORT hawk_t* hawk_openstdwithmmgr ( /** * The hawk_parsestd() functions parses source script. - * The code below shows how to parse a literal string 'BEGIN { print 10; }' + * The code below shows how to parse a literal string 'BEGIN { print 10; }' * and deparses it out to a buffer 'buf'. * \code * int n; @@ -158,7 +158,7 @@ HAWK_EXPORT hawk_t* hawk_openstdwithmmgr ( * in[1].type = HAWK_PARSESTD_NULL; * out.type = HAWK_PARSESTD_OOCS; * n = hawk_parsestd(hawk, in, &out); - * if (n >= 0) + * if (n >= 0) * { * hawk_printf (HAWK_T("%s\n"), out.u.str.ptr); * HAWK_MMGR_FREE (out.u.str.ptr); @@ -167,7 +167,7 @@ HAWK_EXPORT hawk_t* hawk_openstdwithmmgr ( */ HAWK_EXPORT int hawk_parsestd ( hawk_t* hawk, - hawk_parsestd_t in[], + hawk_parsestd_t in[], hawk_parsestd_t* out ); @@ -204,12 +204,12 @@ HAWK_EXPORT hawk_rtx_t* hawk_rtx_openstdwithucstr ( #if defined(HAWK_OOCH_IS_BCH) # define hawk_rtx_openstd hawk_rtx_openstdwithbcstr #else -# define hawk_rtx_openstd hawk_rtx_openstdwithucstr +# define hawk_rtx_openstd hawk_rtx_openstdwithucstr #endif /** - * The hawk_rtx_getiocmgrstd() function gets the current character - * manager associated with a particular I/O target indicated by the name + * The hawk_rtx_getiocmgrstd() function gets the current character + * manager associated with a particular I/O target indicated by the name * \a ioname if #HAWK_OOCH_IS_UCH is defined. It always returns #HAWK_NULL * if #HAWK_OOCH_IS_BCH is defined. */ @@ -265,7 +265,7 @@ HAWK_EXPORT int hawk_stdplainfileexists ( ); HAWK_EXPORT const hawk_ooch_t* hawk_stdgetfileindirs ( - hawk_t* hawk, + hawk_t* hawk, const hawk_oocs_t* dirs, const hawk_ooch_t* file ); diff --git a/lib/hawk-str.h b/lib/hawk-str.h index b433f5f0..d0787634 100644 --- a/lib/hawk-str.h +++ b/lib/hawk-str.h @@ -39,7 +39,7 @@ -/* ========================================================================= +/* ========================================================================= * STRING * ========================================================================= */ @@ -639,7 +639,7 @@ HAWK_EXPORT int hawk_fnmat_bchars_i ( #define HAWK_BYTE_TO_BCSTR_LOWERCASE HAWK_BYTE_TO_OOCSTR_LOWERCASE HAWK_EXPORT hawk_oow_t hawk_byte_to_bcstr ( - hawk_uint8_t byte, + hawk_uint8_t byte, hawk_bch_t* buf, hawk_oow_t size, int flagged_radix, @@ -647,7 +647,7 @@ HAWK_EXPORT hawk_oow_t hawk_byte_to_bcstr ( ); HAWK_EXPORT hawk_oow_t hawk_byte_to_ucstr ( - hawk_uint8_t byte, + hawk_uint8_t byte, hawk_uch_t* buf, hawk_oow_t size, int flagged_radix, @@ -663,32 +663,32 @@ HAWK_EXPORT hawk_oow_t hawk_byte_to_ucstr ( /* ------------------------------------------------------------------------- */ HAWK_EXPORT hawk_oow_t hawk_int_to_ucstr ( - hawk_int_t value, - int radix, + hawk_int_t value, + int radix, const hawk_uch_t* prefix, hawk_uch_t* buf, hawk_oow_t size ); HAWK_EXPORT hawk_oow_t hawk_int_to_bcstr ( - hawk_int_t value, - int radix, + hawk_int_t value, + int radix, const hawk_bch_t* prefix, hawk_bch_t* buf, hawk_oow_t size ); HAWK_EXPORT hawk_oow_t hawk_uint_to_ucstr ( - hawk_uint_t value, - int radix, + hawk_uint_t value, + int radix, const hawk_uch_t* prefix, hawk_uch_t* buf, hawk_oow_t size ); HAWK_EXPORT hawk_oow_t hawk_uint_to_bcstr ( - hawk_uint_t value, - int radix, + hawk_uint_t value, + int radix, const hawk_bch_t* prefix, hawk_bch_t* buf, hawk_oow_t size @@ -816,7 +816,7 @@ templateINT_T int digit, negative = 0; int base = HAWK_CHARS_TO_INT_GET_OPTION_BASE(option); - p = str; + p = str; end = str + len; if (HAWK_CHARS_TO_INT_GET_OPTION_LTRIM(option)) @@ -828,7 +828,7 @@ templateINT_T /* check for a sign */ while (p < end) { - if (*p == '-') + if (*p == '-') { negative = ~negative; p++; @@ -839,9 +839,9 @@ templateINT_T /* check for a binary/octal/hexadecimal notation */ rem = end - p; - if (base == 0) + if (base == 0) { - if (rem >= 1 && *p == '0') + if (rem >= 1 && *p == '0') { p++; @@ -849,7 +849,7 @@ templateINT_T else if (*p == 'x' || *p == 'X') { p++; base = 16; - } + } else if (*p == 'b' || *p == 'B') { p++; base = 2; @@ -857,14 +857,14 @@ templateINT_T else base = 8; } else base = 10; - } + } else if (rem >= 2 && base == 16) { - if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; + if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; } else if (rem >= 2 && base == 2) { - if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; + if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; } /* process the digits */ @@ -908,7 +908,7 @@ templateINT_T /* base 8: at least a zero digit has been seen. * other case: p > pp to be able to have at least 1 meaningful digit. */ - if (is_sober) *is_sober = (base == 8 || p > pp); + if (is_sober) *is_sober = (base == 8 || p > pp); if (HAWK_CHARS_TO_INT_GET_OPTION_RTRIM(option)) { @@ -929,7 +929,7 @@ templateUINT int digit; int base = HAWK_CHARS_TO_UINT_GET_OPTION_BASE(option); - p = str; + p = str; end = str + len; if (HAWK_CHARS_TO_UINT_GET_OPTION_LTRIM(option)) @@ -947,9 +947,9 @@ templateUINT /* check for a binary/octal/hexadecimal notation */ rem = end - p; - if (base == 0) + if (base == 0) { - if (rem >= 1 && *p == '0') + if (rem >= 1 && *p == '0') { p++; @@ -957,7 +957,7 @@ templateUINT else if (*p == 'x' || *p == 'X') { p++; base = 16; - } + } else if (*p == 'b' || *p == 'B') { p++; base = 2; @@ -965,14 +965,14 @@ templateUINT else base = 8; } else base = 10; - } + } else if (rem >= 2 && base == 16) { - if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; + if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; } else if (rem >= 2 && base == 2) { - if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; + if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; } /* process the digits */ @@ -1016,7 +1016,7 @@ templateUINT /* base 8: at least a zero digit has been seen. * other case: p > pp to be able to have at least 1 meaningful digit. */ - if (is_sober) *is_sober = (base == 8 || p > pp); + if (is_sober) *is_sober = (base == 8 || p > pp); if (HAWK_CHARS_TO_UINT_GET_OPTION_RTRIM(option)) { diff --git a/lib/hawk-tio.h b/lib/hawk-tio.h index 8b704a6c..d6ea21d5 100644 --- a/lib/hawk-tio.h +++ b/lib/hawk-tio.h @@ -58,8 +58,8 @@ typedef struct hawk_tio_t hawk_tio_t; */ typedef hawk_ooi_t (*hawk_tio_io_impl_t) ( hawk_tio_t* tio, - hawk_tio_cmd_t cmd, - void* data, + hawk_tio_cmd_t cmd, + void* data, hawk_oow_t size ); @@ -117,7 +117,7 @@ HAWK_EXPORT int hawk_tio_close ( ); /** - * The hawk_tio_init() function initialize a statically declared + * The hawk_tio_init() function initialize a statically declared * text stream processor. */ HAWK_EXPORT int hawk_tio_init ( @@ -193,7 +193,7 @@ HAWK_EXPORT int hawk_tio_detachout ( ); /** - * The hawk_tio_flush() function flushes the output buffer. It returns the + * The hawk_tio_flush() function flushes the output buffer. It returns the * number of bytes written on success, -1 on failure. */ HAWK_EXPORT hawk_ooi_t hawk_tio_flush ( @@ -208,14 +208,14 @@ HAWK_EXPORT void hawk_tio_drain ( ); HAWK_EXPORT hawk_ooi_t hawk_tio_readbchars ( - hawk_tio_t* tio, - hawk_bch_t* buf, + hawk_tio_t* tio, + hawk_bch_t* buf, hawk_oow_t size ); HAWK_EXPORT hawk_ooi_t hawk_tio_readuchars ( - hawk_tio_t* tio, - hawk_uch_t* buf, + hawk_tio_t* tio, + hawk_uch_t* buf, hawk_oow_t size ); @@ -230,9 +230,9 @@ HAWK_EXPORT hawk_ooi_t hawk_tio_readuchars ( #endif /** - * The hawk_tio_writebchars() function writes the @a size characters + * The hawk_tio_writebchars() function writes the @a size characters * from a multibyte string @a str. If @a size is (hawk_oow_t)-1, - * it writes on until a terminating null is found. It doesn't + * it writes on until a terminating null is found. It doesn't * write more than HAWK_TYPE_MAX(hawk_ooi_t) characters. * @return number of characters written on success, -1 on failure. */ @@ -243,9 +243,9 @@ HAWK_EXPORT hawk_ooi_t hawk_tio_writebchars ( ); /** - * The hawk_tio_writebchars() function writes the @a size characters + * The hawk_tio_writebchars() function writes the @a size characters * from a wide-character string @a str. If @a size is (hawk_oow_t)-1, - * it writes on until a terminating null is found. It doesn't write + * it writes on until a terminating null is found. It doesn't write * more than HAWK_TYPE_MAX(hawk_ooi_t) characters. * @return number of characters written on success, -1 on failure. */ diff --git a/lib/hawk-tre.h b/lib/hawk-tre.h index ee9c5f27..a8870524 100644 --- a/lib/hawk-tre.h +++ b/lib/hawk-tre.h @@ -53,17 +53,17 @@ enum hawk_tre_cflag_t HAWK_TRE_RIGHTASSOC = (1 << 5), HAWK_TRE_UNGREEDY = (1 << 6), - /* Disable {n,m} occrrence specifier + /* Disable {n,m} occrrence specifier * in the HAWK_TRE_EXTENDED mode. * it doesn't affect the BRE's \{\}. */ HAWK_TRE_NOBOUND = (1 << 7), /* Enable non-standard extensions: * - Enable (?:text) for no submatch backreference. - * - Enable perl-like (?...) extensions like (?i) + * - Enable perl-like (?...) extensions like (?i) * if HAWK_TRE_EXTENDED is also set. */ - HAWK_TRE_NONSTDEXT = (1 << 8) + HAWK_TRE_NONSTDEXT = (1 << 8) }; enum hawk_tre_eflag_t diff --git a/lib/hawk-utl.h b/lib/hawk-utl.h index 222b50d7..9cb216bc 100644 --- a/lib/hawk-utl.h +++ b/lib/hawk-utl.h @@ -252,10 +252,10 @@ typedef enum hawk_cmgr_id_t hawk_cmgr_id_t; /** * The hawk_sort_comper_t type defines a sort callback function. * The callback function is called by sort functions for each comparison - * performed. It should return 0 if \a ptr1 and \a ptr2 are - * euqal, a positive integer if \a ptr1 is greater than \a ptr2, a negative - * if \a ptr2 is greater than \a ptr1. Both \a ptr1 and \a ptr2 are - * pointers to any two items in the array. \a ctx which is a pointer to + * performed. It should return 0 if \a ptr1 and \a ptr2 are + * euqal, a positive integer if \a ptr1 is greater than \a ptr2, a negative + * if \a ptr2 is greater than \a ptr1. Both \a ptr1 and \a ptr2 are + * pointers to any two items in the array. \a ctx which is a pointer to * user-defined data passed to a sort function is passed to the callback * with no modification. */ @@ -289,9 +289,9 @@ typedef int (*hawk_sort_comperx_t) ( * and hawk_subst_for_ucstr_to_ucstr() to substitue a new value for an identifier \a ident. */ typedef hawk_uch_t* (*hawk_subst_for_ucs_t) ( - hawk_uch_t* buf, - hawk_oow_t bsz, - const hawk_ucs_t* ident, + hawk_uch_t* buf, + hawk_oow_t bsz, + const hawk_ucs_t* ident, void* ctx ); @@ -300,9 +300,9 @@ typedef hawk_uch_t* (*hawk_subst_for_ucs_t) ( * and hawk_subst_for_bcstr_to_bcstr() to substitue a new value for an identifier \a ident. */ typedef hawk_bch_t* (*hawk_subst_for_bcs_t) ( - hawk_bch_t* buf, - hawk_oow_t bsz, - const hawk_bcs_t* ident, + hawk_bch_t* buf, + hawk_oow_t bsz, + const hawk_bcs_t* ident, void* ctx ); @@ -543,7 +543,7 @@ HAWK_EXPORT hawk_int_t hawk_bchars_to_int ( */ HAWK_EXPORT hawk_flt_t hawk_uchars_to_flt ( const hawk_uch_t* str, - hawk_oow_t len, + hawk_oow_t len, const hawk_uch_t** endptr, int stripspc ); @@ -554,19 +554,19 @@ HAWK_EXPORT hawk_flt_t hawk_uchars_to_flt ( */ HAWK_EXPORT hawk_flt_t hawk_bchars_to_flt ( const hawk_bch_t* str, - hawk_oow_t len, + hawk_oow_t len, const hawk_bch_t** endptr, int stripspc ); /** * The hawk_oochars_to_num() function converts a string to a number. - * A numeric string in the valid decimal, hexadecimal(0x), binary(0b), + * A numeric string in the valid decimal, hexadecimal(0x), binary(0b), * octal(0) notation is converted to an integer and it is stored into - * memory pointed to by \a l; A string containng '.', 'E', or 'e' is + * memory pointed to by \a l; A string containng '.', 'E', or 'e' is * converted to a floating-pointer number and it is stored into memory * pointed to by \a r. If \a strict is 0, the function takes up to the last - * valid character and never fails. If \a strict is 1, an invalid + * valid character and never fails. If \a strict is 1, an invalid * character causes the function to return an error. * * \return 0 if converted to an integer, @@ -654,7 +654,7 @@ HAWK_EXPORT hawk_cmgr_t* hawk_get_cmgr_by_ucstr ( /* ------------------------------------------------------------------------- */ /** - * The hawk_conv_uchars_to_utf8() function converts a unicode character string \a ucs + * The hawk_conv_uchars_to_utf8() function converts a unicode character string \a ucs * to a UTF8 string and writes it into the buffer pointed to by \a bcs, but * not more than \a bcslen bytes including the terminating null. * @@ -703,7 +703,7 @@ HAWK_EXPORT int hawk_conv_uchars_to_utf8 ( * n = hawk_conv_utf8_to_uchars (bcs, &bcslen, ucs, &ucslen); * if (n <= -1) { invalid/incomplenete sequence or buffer to small } * \endcode - * + * * The resulting \a ucslen can still be greater than 0 even if the return * value is negative. The value indiates the number of characters converted * before the error has occurred. @@ -860,9 +860,9 @@ static HAWK_INLINE hawk_uint32_t hawk_bswap32 (hawk_uint32_t x) ); return x; #else - return ((x >> 24)) | - ((x >> 8) & ((hawk_uint32_t)0xff << 8)) | - ((x << 8) & ((hawk_uint32_t)0xff << 16)) | + return ((x >> 24)) | + ((x >> 8) & ((hawk_uint32_t)0xff << 8)) | + ((x << 8) & ((hawk_uint32_t)0xff << 16)) | ((x << 24)); #endif } @@ -880,13 +880,13 @@ static HAWK_INLINE hawk_uint64_t hawk_bswap64 (hawk_uint64_t x) __asm__ /*volatile*/ ("rev %0, %0" : "+r"(x)); return x; #else - return ((x >> 56)) | - ((x >> 40) & ((hawk_uint64_t)0xff << 8)) | - ((x >> 24) & ((hawk_uint64_t)0xff << 16)) | - ((x >> 8) & ((hawk_uint64_t)0xff << 24)) | - ((x << 8) & ((hawk_uint64_t)0xff << 32)) | - ((x << 24) & ((hawk_uint64_t)0xff << 40)) | - ((x << 40) & ((hawk_uint64_t)0xff << 48)) | + return ((x >> 56)) | + ((x >> 40) & ((hawk_uint64_t)0xff << 8)) | + ((x >> 24) & ((hawk_uint64_t)0xff << 16)) | + ((x >> 8) & ((hawk_uint64_t)0xff << 24)) | + ((x << 8) & ((hawk_uint64_t)0xff << 32)) | + ((x << 24) & ((hawk_uint64_t)0xff << 40)) | + ((x << 40) & ((hawk_uint64_t)0xff << 48)) | ((x << 56)); #endif } @@ -898,7 +898,7 @@ static HAWK_INLINE hawk_uint128_t hawk_bswap128 (hawk_uint128_t x) #if defined(HAWK_HAVE_BUILTIN_BSWAP128) return __builtin_bswap128(x); #else - return ((x >> 120)) | + return ((x >> 120)) | ((x >> 104) & ((hawk_uint128_t)0xff << 8)) | ((x >> 88) & ((hawk_uint128_t)0xff << 16)) | ((x >> 72) & ((hawk_uint128_t)0xff << 24)) | @@ -923,7 +923,7 @@ static HAWK_INLINE hawk_uint128_t hawk_bswap128 (hawk_uint128_t x) #if defined(HAWK_HAVE_UINT16_T) # if defined(HAWK_HAVE_BUILTIN_BSWAP16) # define hawk_bswap16(x) ((hawk_uint16_t)__builtin_bswap16((hawk_uint16_t)(x))) -# else +# else # define hawk_bswap16(x) ((hawk_uint16_t)(((hawk_uint16_t)(x)) << 8) | (((hawk_uint16_t)(x)) >> 8)) # endif #endif @@ -931,7 +931,7 @@ static HAWK_INLINE hawk_uint128_t hawk_bswap128 (hawk_uint128_t x) #if defined(HAWK_HAVE_UINT32_T) # if defined(HAWK_HAVE_BUILTIN_BSWAP32) # define hawk_bswap32(x) ((hawk_uint32_t)__builtin_bswap32((hawk_uint32_t)(x))) -# else +# else # define hawk_bswap32(x) ((hawk_uint32_t)(((((hawk_uint32_t)(x)) >> 24)) | \ ((((hawk_uint32_t)(x)) >> 8) & ((hawk_uint32_t)0xff << 8)) | \ ((((hawk_uint32_t)(x)) << 8) & ((hawk_uint32_t)0xff << 16)) | \ @@ -942,7 +942,7 @@ static HAWK_INLINE hawk_uint128_t hawk_bswap128 (hawk_uint128_t x) #if defined(HAWK_HAVE_UINT64_T) # if defined(HAWK_HAVE_BUILTIN_BSWAP64) # define hawk_bswap64(x) ((hawk_uint64_t)__builtin_bswap64((hawk_uint64_t)(x))) -# else +# else # define hawk_bswap64(x) ((hawk_uint64_t)(((((hawk_uint64_t)(x)) >> 56)) | \ ((((hawk_uint64_t)(x)) >> 40) & ((hawk_uint64_t)0xff << 8)) | \ ((((hawk_uint64_t)(x)) >> 24) & ((hawk_uint64_t)0xff << 16)) | \ @@ -957,7 +957,7 @@ static HAWK_INLINE hawk_uint128_t hawk_bswap128 (hawk_uint128_t x) #if defined(HAWK_HAVE_UINT128_T) # if defined(HAWK_HAVE_BUILTIN_BSWAP128) # define hawk_bswap128(x) ((hawk_uint128_t)__builtin_bswap128((hawk_uint128_t)(x))) -# else +# else # define hawk_bswap128(x) ((hawk_uint128_t)(((((hawk_uint128_t)(x)) >> 120)) | \ ((((hawk_uint128_t)(x)) >> 104) & ((hawk_uint128_t)0xff << 8)) | \ ((((hawk_uint128_t)(x)) >> 88) & ((hawk_uint128_t)0xff << 16)) | \ @@ -1102,7 +1102,7 @@ static HAWK_INLINE int hawk_get_pos_of_msb_set_pow2 (hawk_oow_t x) : "=r"(n) /* output */ : "r"(x) /* input */ ); - return (int)(HAWK_OOW_BITS - n - 1); + return (int)(HAWK_OOW_BITS - n - 1); /* TODO: PPC - use cntlz, cntlzw, cntlzd, SPARC - use lzcnt, MIPS clz */ #else int pos = 0; @@ -1136,7 +1136,7 @@ static HAWK_INLINE int hawk_get_pos_of_msb_set (hawk_oow_t x) : "=r"(n) /* output */ : "r"(x) /* input */ ); - return (int)(HAWK_OOW_BITS - n - 1); + return (int)(HAWK_OOW_BITS - n - 1); /* TODO: PPC - use cntlz, cntlzw, cntlzd, SPARC - use lzcnt, MIPS clz */ #else int pos = 0; @@ -1166,7 +1166,7 @@ HAWK_EXPORT int hawk_qsortx ( ); /* ========================================================================= - * TIME + * TIME * ========================================================================= */ HAWK_EXPORT int hawk_get_ntime ( hawk_ntime_t* t @@ -1177,10 +1177,10 @@ HAWK_EXPORT int hawk_set_ntime ( ); /** - * The hawk_add_ntime() adds two time structures pointed to by x and y and + * The hawk_add_ntime() adds two time structures pointed to by x and y and * stores the result in z. Upon overflow, it sets z to the largest value - * the hawk_ntime_t type can represent. Upon underflow, it sets z to the - * smallest value. If you don't need this extra range check, you may use + * the hawk_ntime_t type can represent. Upon underflow, it sets z to the + * smallest value. If you don't need this extra range check, you may use * the HAWK_ADD_NTIME() macro. */ HAWK_EXPORT void hawk_add_ntime ( diff --git a/lib/hawk-xma.h b/lib/hawk-xma.h index 8386f51a..91ee7438 100644 --- a/lib/hawk-xma.h +++ b/lib/hawk-xma.h @@ -50,15 +50,15 @@ * hawk_xma_t* xma; * void* ptr1, * ptr2; * - * // create a new memory allocator obtaining a 100K byte zone + * // create a new memory allocator obtaining a 100K byte zone * // with the default memory allocator - * xma = hawk_xma_open(HAWK_NULL, 0, 100000L); + * xma = hawk_xma_open(HAWK_NULL, 0, 100000L); * * ptr1 = hawk_xma_alloc(xma, 5000); // allocate a 5K block from the zone * ptr2 = hawk_xma_alloc(xma, 1000); // allocate a 1K block from the zone * ptr1 = hawk_xma_realloc(xma, ptr1, 6000); // resize the 5K block to 6K. * - * hawk_xma_dump (xma, dumper, HAWK_NULL); // dump memory blocks + * hawk_xma_dump (xma, dumper, HAWK_NULL); // dump memory blocks * * // the following two lines are not actually needed as the allocator * // is closed after them. @@ -100,7 +100,7 @@ struct hawk_xma_t int internal; /** pointer array to free memory blocks */ - hawk_xma_fblk_t* xfree[HAWK_XMA_FIXED + HAWK_XMA_SIZE_BITS + 1]; + hawk_xma_fblk_t* xfree[HAWK_XMA_FIXED + HAWK_XMA_SIZE_BITS + 1]; /** pre-computed value for fast xfree index calculation */ hawk_oow_t bdec; @@ -148,7 +148,7 @@ HAWK_EXPORT hawk_xma_t* hawk_xma_open ( /** * The hawk_xma_close() function destroys a memory allocator. It also frees - * the memory zone obtained, which invalidates the memory blocks within + * the memory zone obtained, which invalidates the memory blocks within * the zone. Call this function to destroy a memory allocator created with * hawk_xma_open(). */ @@ -184,7 +184,7 @@ HAWK_EXPORT int hawk_xma_init ( ); /** - * The hawk_xma_fini() function finalizes a memory allocator. Call this + * The hawk_xma_fini() function finalizes a memory allocator. Call this * function to finalize a memory allocator initialized with hawk_xma_init(). */ HAWK_EXPORT void hawk_xma_fini ( diff --git a/lib/hawk.c b/lib/hawk.c index 68823cec..f91dead0 100644 --- a/lib/hawk.c +++ b/lib/hawk.c @@ -110,7 +110,7 @@ int hawk_init (hawk_t* hawk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_pr { { HAWK_HTB_COPIER_INLINE, - HAWK_HTB_COPIER_DEFAULT + HAWK_HTB_COPIER_DEFAULT }, { HAWK_HTB_FREEER_DEFAULT, @@ -126,7 +126,7 @@ int hawk_init (hawk_t* hawk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_pr { { HAWK_HTB_COPIER_INLINE, - HAWK_HTB_COPIER_DEFAULT + HAWK_HTB_COPIER_DEFAULT }, { HAWK_HTB_FREEER_DEFAULT, @@ -160,7 +160,7 @@ int hawk_init (hawk_t* hawk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_pr HAWK_ASSERT (prm != HAWK_NULL); HAWK_ASSERT (prm->math.pow != HAWK_NULL); HAWK_ASSERT (prm->math.mod != HAWK_NULL); - if (prm == HAWK_NULL || + if (prm == HAWK_NULL || prm->math.pow == HAWK_NULL || prm->math.mod == HAWK_NULL) { @@ -215,7 +215,7 @@ int hawk_init (hawk_t* hawk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_pr hawk->parse.lcls == HAWK_NULL || hawk->parse.params == HAWK_NULL || hawk->fnc.user == HAWK_NULL || - hawk->modtab == HAWK_NULL) + hawk->modtab == HAWK_NULL) { hawk_seterrnum (hawk, HAWK_NULL, HAWK_ENOMEM); goto oops; @@ -334,7 +334,7 @@ void hawk_fini (hawk_t* hawk) if (hawk->log.len > 0) { - /* flush pending log message that could be generated by the fini + /* flush pending log message that could be generated by the fini * callbacks. however, the actual logging might not be produced at * this point because one of the callbacks could arrange to stop * logging */ @@ -344,7 +344,7 @@ void hawk_fini (hawk_t* hawk) hawk->shuterr = shuterr; } - if (hawk->log.ptr) + if (hawk->log.ptr) { hawk_freemem (hawk, hawk->log.ptr); hawk->log.capa = 0; @@ -388,7 +388,7 @@ void hawk_clear (hawk_t* hawk) HAWK_ASSERT (HAWK_ARR_SIZE(hawk->parse.gbls) == hawk->tree.ngbls); /* delete all non-builtin global variables */ hawk_arr_delete ( - hawk->parse.gbls, hawk->tree.ngbls_base, + hawk->parse.gbls, hawk->tree.ngbls_base, HAWK_ARR_SIZE(hawk->parse.gbls) - hawk->tree.ngbls_base); hawk_arr_clear (hawk->parse.lcls); @@ -396,7 +396,7 @@ void hawk_clear (hawk_t* hawk) hawk_htb_clear (hawk->parse.named); hawk_htb_clear (hawk->parse.funs); - hawk->parse.nlcls_max = 0; + hawk->parse.nlcls_max = 0; hawk->parse.depth.block = 0; hawk->parse.depth.loop = 0; hawk->parse.depth.expr = 0; @@ -416,21 +416,21 @@ void hawk_clear (hawk_t* hawk) hawk->tree.cur_fun.len = 0; hawk_htb_clear (hawk->tree.funs); - if (hawk->tree.begin) + if (hawk->tree.begin) { hawk_clrpt (hawk, hawk->tree.begin); hawk->tree.begin = HAWK_NULL; hawk->tree.begin_tail = HAWK_NULL; } - if (hawk->tree.end) + if (hawk->tree.end) { hawk_clrpt (hawk, hawk->tree.end); hawk->tree.end = HAWK_NULL; hawk->tree.end_tail = HAWK_NULL; } - while (hawk->tree.chain) + while (hawk->tree.chain) { hawk_chain_t* next = hawk->tree.chain->next; if (hawk->tree.chain->pattern) hawk_clrpt (hawk, hawk->tree.chain->pattern); @@ -443,7 +443,7 @@ void hawk_clear (hawk_t* hawk) hawk->tree.chain_size = 0; /* this table must not be cleared here as there can be a reference - * to an entry of this table from errinf.loc.file when hawk_parse() + * to an entry of this table from errinf.loc.file when hawk_parse() * failed. this table is cleared in hawk_parse(). * hawk_claersionames (hawk); */ @@ -622,17 +622,17 @@ void hawk_pushecb (hawk_t* hawk, hawk_ecb_t* ecb) /* ------------------------------------------------------------------------ */ -hawk_oow_t hawk_fmttoucstr_ (hawk_t* hawk, hawk_uch_t* buf, hawk_oow_t bufsz, const hawk_uch_t* fmt, ...) +hawk_oow_t hawk_fmttoucstr_ (hawk_t* hawk, hawk_uch_t* buf, hawk_oow_t bufsz, const hawk_uch_t* fmt, ...) { va_list ap; hawk_oow_t n; va_start(ap, fmt); n = hawk_gem_vfmttoucstr(hawk_getgem(hawk), buf, bufsz, fmt, ap); va_end(ap); - return n; + return n; } -hawk_oow_t hawk_fmttobcstr_ (hawk_t* hawk, hawk_bch_t* buf, hawk_oow_t bufsz, const hawk_bch_t* fmt, ...) +hawk_oow_t hawk_fmttobcstr_ (hawk_t* hawk, hawk_bch_t* buf, hawk_oow_t bufsz, const hawk_bch_t* fmt, ...) { va_list ap; hawk_oow_t n; @@ -663,7 +663,7 @@ int hawk_findmodsymfnc_noseterr (hawk_t* hawk, hawk_mod_fnc_tab_t* fnctab, hawk_ { mid = base + (lim >> 1); n = hawk_comp_oocstr(name, fnctab[mid].name, 0); - if (n == 0) + if (n == 0) { sym->type = HAWK_MOD_FNC; sym->name = fnctab[mid].name; @@ -673,7 +673,7 @@ int hawk_findmodsymfnc_noseterr (hawk_t* hawk, hawk_mod_fnc_tab_t* fnctab, hawk_ if (n > 0) { base = mid + 1; lim--; } } - return -1; + return -1; } @@ -688,7 +688,7 @@ int hawk_findmodsymint_noseterr (hawk_t* hawk, hawk_mod_int_tab_t* inttab, hawk_ { mid = base + (lim >> 1); n = hawk_comp_oocstr(name, inttab[mid].name, 0); - if (n == 0) + if (n == 0) { sym->type = HAWK_MOD_INT; sym->name = inttab[mid].name; @@ -712,7 +712,7 @@ int hawk_findmodsymflt_noseterr (hawk_t* hawk, hawk_mod_flt_tab_t* flttab, hawk_ { mid = base + (lim >> 1); n = hawk_comp_oocstr(name, flttab[mid].name, 0); - if (n == 0) + if (n == 0) { sym->type = HAWK_MOD_FLT; sym->name = flttab[mid].name; @@ -759,7 +759,7 @@ static HAWK_INLINE int secure_space_in_sbuf (hawk_t* hawk, hawk_oow_t req, hawk_ newcapa = p->len + req + 1; newcapa = HAWK_ALIGN_POW2(newcapa, 512); /* TODO: adjust this capacity */ - tmp = (hawk_ooch_t*)hawk_reallocmem(hawk, p->ptr, newcapa * HAWK_SIZEOF(*tmp)); + tmp = (hawk_ooch_t*)hawk_reallocmem(hawk, p->ptr, newcapa * HAWK_SIZEOF(*tmp)); if (!tmp) return -1; p->ptr = tmp; diff --git a/lib/hawk.h b/lib/hawk.h index d065f73c..8e458f9d 100644 --- a/lib/hawk.h +++ b/lib/hawk.h @@ -52,24 +52,24 @@ * * In brief, you need to call APIs with user-defined handlers to run a typical * AWK script as shown below: - * + * * \code * hawk_t* hawk; * hawk_rtx_t* rtx; * hawk_sio_cbs_t sio; // need to initialize it with callback functions * hawk_rio_cbs_t rio; // need to initialize it with callback functions * - * hawk = hawk_open(mmgr, 0, prm); // create an interpreter - * hawk_parse (hawk, &sio); // parse a script - * rtx = hawk_rtx_open(hawk, 0, &rio); // create a runtime context - * retv = hawk_rtx_loop(rtx); // run a standard AWK loop + * hawk = hawk_open(mmgr, 0, prm); // create an interpreter + * hawk_parse (hawk, &sio); // parse a script + * rtx = hawk_rtx_open(hawk, 0, &rio); // create a runtime context + * retv = hawk_rtx_loop(rtx); // run a standard AWK loop * if (retv) hawk_rtx_refdownval (rtx, retv); // free return value * hawk_rtx_close (rtx); // destroy the runtime context * hawk_close (hawk); // destroy the interpreter * \endcode * - * It provides an interface to change the conventional behavior of the - * interpreter; most notably, you can call a particular function with + * It provides an interface to change the conventional behavior of the + * interpreter; most notably, you can call a particular function with * hawk_rtx_call() instead of entering the BEGIN, pattern-action blocks, END * loop. By doing this, you may utilize a script in an event-driven way. * @@ -87,15 +87,15 @@ struct hawk_alt_t }; /** \struct hawk_rtx_t - * The #hawk_rtx_t type defines a runtime context. A runtime context + * The #hawk_rtx_t type defines a runtime context. A runtime context * maintains runtime state for a running script. You can create multiple - * runtime contexts out of a single AWK interpreter; in other words, you + * runtime contexts out of a single AWK interpreter; in other words, you * can run the same script with different input and output data by providing - * customized I/O handlers when creating a runtime context with + * customized I/O handlers when creating a runtime context with * hawk_rtx_open(). * * I/O handlers are categoriezed into three kinds: console, file, pipe. - * The #hawk_rio_t type defines as a callback a set of I/O handlers + * The #hawk_rio_t type defines as a callback a set of I/O handlers * to handle runtime I/O: * - getline piped in from a command reads from a pipe. * ("ls -l" | getline line) @@ -204,7 +204,7 @@ struct hawk_val_t }; /** - * The hawk_val_nil_t type is a nil value type. The type field is + * The hawk_val_nil_t type is a nil value type. The type field is * #HAWK_VAL_NIL. */ struct hawk_val_nil_t @@ -260,7 +260,7 @@ struct hawk_val_mbs_t typedef struct hawk_val_mbs_t hawk_val_mbs_t; /** - * The hawk_val_rex_t type is a regular expression type. The type field + * The hawk_val_rex_t type is a regular expression type. The type field * is #HAWK_VAL_REX. */ struct hawk_val_rex_t @@ -272,34 +272,34 @@ struct hawk_val_rex_t typedef struct hawk_val_rex_t hawk_val_rex_t; /** - * The hawk_val_map_t type defines a map type. The type field is + * The hawk_val_map_t type defines a map type. The type field is * #HAWK_VAL_MAP. */ struct hawk_val_map_t { HAWK_VAL_HDR; - /* TODO: make val_map to array if the indices used are all - * integers switch to map dynamically once the + /* TODO: make val_map to array if the indices used are all + * integers switch to map dynamically once the * non-integral index is seen. */ - hawk_map_t* map; + hawk_map_t* map; }; typedef struct hawk_val_map_t hawk_val_map_t; /** - * The hawk_val_arr_t type defines a arr type. The type field is + * The hawk_val_arr_t type defines a arr type. The type field is * #HAWK_VAL_MAP. */ struct hawk_val_arr_t { HAWK_VAL_HDR; - /* TODO: make val_arr to array if the indices used are all - * integers switch to arr dynamically once the + /* TODO: make val_arr to array if the indices used are all + * integers switch to arr dynamically once the * non-integral index is seen. */ - hawk_arr_t* arr; + hawk_arr_t* arr; }; typedef struct hawk_val_arr_t hawk_val_arr_t; @@ -326,9 +326,9 @@ struct hawk_val_ref_t HAWK_VAL_REF_POS /**< positional variable */ } id; - /* if id is HAWK_VAL_REF_POS, adr holds the index of a + /* if id is HAWK_VAL_REF_POS, adr holds the index of a * positional variable. If id is HAWK_VAL_REF_GBL, adr hold - * the index of a global variable. Otherwise, adr points to the value + * the index of a global variable. Otherwise, adr points to the value * directly. */ hawk_val_t** adr; }; @@ -340,13 +340,13 @@ typedef struct hawk_val_ref_t hawk_val_ref_t; typedef hawk_map_itr_t hawk_val_map_itr_t; /** - * The #HAWK_VAL_MAP_ITR_KEY macro get the pointer to the key part + * The #HAWK_VAL_MAP_ITR_KEY macro get the pointer to the key part * of a map value. */ #define HAWK_VAL_MAP_ITR_KEY(itr) ((const hawk_oocs_t*)HAWK_MAP_KPTL((itr)->pair)) /** - * The #HAWK_VAL_MAP_ITR_VAL macro get the pointer to the value part + * The #HAWK_VAL_MAP_ITR_VAL macro get the pointer to the value part * of a map value. */ #define HAWK_VAL_MAP_ITR_VAL(itr) ((const hawk_val_t*)HAWK_MAP_VPTR((itr)->pair)) @@ -415,7 +415,7 @@ enum hawk_nde_type_t /* if you change the following values including their order, * you should change __evaluator of eval_expression0() * in run.c accordingly */ - HAWK_NDE_GRP, + HAWK_NDE_GRP, HAWK_NDE_ASS, HAWK_NDE_EXP_BIN, HAWK_NDE_EXP_UNR, @@ -436,7 +436,7 @@ enum hawk_nde_type_t HAWK_NDE_XARG, HAWK_NDE_FUN, - /* keep this order for the following items otherwise, you may have + /* keep this order for the following items otherwise, you may have * to change eval_incpre and eval_incpst in run.c as well as * HAWK_VAL_REF_XXX in hawk_val_ref_t. also do_assignment_map() * in run.c converts HAWK_NDE_XXXIDX to HAWK_NDE_XXX by @@ -505,7 +505,7 @@ typedef hawk_flt_t (*hawk_math1_t) ( typedef hawk_flt_t (*hawk_math2_t) ( hawk_t* hawk, - hawk_flt_t x, + hawk_flt_t x, hawk_flt_t y ); @@ -551,7 +551,7 @@ typedef void (*hawk_log_write_t) ( #if 0 typedef void* (*hawk_buildrex_t) ( hawk_t* hawk, - const hawk_ooch_t* ptn, + const hawk_ooch_t* ptn, hawk_oow_t len ); @@ -560,7 +560,7 @@ typedef int (*hawk_matchrex_t) ( void* code, int option, const hawk_ooch_t* str, - hawk_oow_t len, + hawk_oow_t len, const hawk_ooch_t** mptr, hawk_oow_t* mlen ); @@ -607,17 +607,17 @@ typedef struct hawk_sio_arg_t hawk_sio_arg_t; * The hawk_sio_arg_t type defines a structure to describe the source * stream. */ -struct hawk_sio_arg_t +struct hawk_sio_arg_t { - /** - * [IN] name of I/O object. + /** + * [IN] name of I/O object. * It is #HAWK_NULL for the top-level stream. It points to a stream name * for an included stream. */ - const hawk_ooch_t* name; + const hawk_ooch_t* name; - /** - * [OUT] I/O handle set by a handler. + /** + * [OUT] I/O handle set by a handler. * The source stream handler can set this field when it opens a stream. * All subsequent operations on the stream see this field as set * during opening. @@ -637,7 +637,7 @@ struct hawk_sio_arg_t /** * [IN] points to the includer. #HAWK_NULL for the toplevel. - * + * */ hawk_sio_arg_t* prev; @@ -661,7 +661,7 @@ struct hawk_sio_arg_t */ typedef hawk_ooi_t (*hawk_sio_impl_t) ( hawk_t* hawk, - hawk_sio_cmd_t cmd, + hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg, hawk_ooch_t* data, hawk_oow_t count @@ -679,7 +679,7 @@ enum hawk_rio_cmd_t HAWK_RIO_CMD_READ_BYTES = 4, HAWK_RIO_CMD_WRITE_BYTES = 5, HAWK_RIO_CMD_FLUSH = 6, /**< flush buffered data to a stream */ - HAWK_RIO_CMD_NEXT = 7 /**< close the current stream and + HAWK_RIO_CMD_NEXT = 7 /**< close the current stream and open the next stream (only for console) */ }; typedef enum hawk_rio_cmd_t hawk_rio_cmd_t; @@ -705,7 +705,7 @@ enum hawk_rio_mode_t typedef enum hawk_rio_mode_t hawk_rio_mode_t; /* - * The hawk_rio_rwcmode_t type defines I/O closing modes, especially for + * The hawk_rio_rwcmode_t type defines I/O closing modes, especially for * a two-way pipe. */ enum hawk_rio_rwcmode_t @@ -717,13 +717,13 @@ enum hawk_rio_rwcmode_t typedef enum hawk_rio_rwcmode_t hawk_rio_rwcmode_t; /** - * The hawk_rio_arg_t defines the data structure passed to a runtime - * I/O handler. An I/O handler should inspect the \a mode field and the - * \a name field and store an open handle to the \a handle field when + * The hawk_rio_arg_t defines the data structure passed to a runtime + * I/O handler. An I/O handler should inspect the \a mode field and the + * \a name field and store an open handle to the \a handle field when * #HAWK_RIO_CMD_OPEN is requested. For other request type, it can refer * to the \a handle field set previously. */ -struct hawk_rio_arg_t +struct hawk_rio_arg_t { /* read-only. a user handler shouldn't change any of these fields */ hawk_rio_mode_t mode; /**< opening mode */ @@ -735,7 +735,7 @@ struct hawk_rio_arg_t int uflags; /**< user-flags set by a handler */ /*-- from here down, internal use only --*/ - int type; + int type; int rwcstate; /* closing state for rwpipe */ struct @@ -791,7 +791,7 @@ struct hawk_prm_t hawk_log_write_t logwrite; #if 0 - struct + struct { /* TODO: accept regular expression handling functions */ hawk_buildrex_t build; @@ -808,7 +808,7 @@ typedef struct hawk_prm_t hawk_prm_t; /** * The hawk_sio_cbs_t type defines a script stream handler set. * The hawk_parse() function calls the input and output handler to parse - * a script and optionally deparse it. Typical input and output handlers + * a script and optionally deparse it. Typical input and output handlers * are shown below: * * \code @@ -837,7 +837,7 @@ typedef struct hawk_prm_t hawk_prm_t; * - -1 if it failed to open a stream. * - 0 if it has opened a stream but has reached the end. * - 1 if it has successfully opened a stream. - * + * * For #HAWK_SIO_CMD_CLOSE, a handler must return: * - -1 if it failed to close a stream. * - 0 if it has closed a stream. @@ -888,12 +888,12 @@ typedef int (*hawk_fnc_impl_t) ( struct hawk_fnc_marg_t { /** minimum numbers of argument for a function */ - hawk_oow_t min; + hawk_oow_t min; /** maximum numbers of argument for a function */ - hawk_oow_t max; + hawk_oow_t max; - /** + /** * if min is greater than max, spec points to an external module * name where the function is found. otherwise, spec can be #HAWK_NULL * to indicate all arguments are passed by value or point to a @@ -913,8 +913,8 @@ typedef struct hawk_fnc_marg_t hawk_fnc_marg_t; */ struct hawk_fnc_warg_t { - hawk_oow_t min; - hawk_oow_t max; + hawk_oow_t min; + hawk_oow_t max; const hawk_uch_t* spec; }; typedef struct hawk_fnc_warg_t hawk_fnc_warg_t; @@ -922,7 +922,7 @@ typedef struct hawk_fnc_warg_t hawk_fnc_warg_t; /** * The hawk_fnc_mspec_t type defines a structure to hold the specification * of an intrinsic function or a module function. - */ + */ struct hawk_fnc_mspec_t { /** argument descriptor */ @@ -931,22 +931,22 @@ struct hawk_fnc_mspec_t /** pointer to the function implementing this function */ hawk_fnc_impl_t impl; - /** - * when this field is set to a non-zero value bitwise-ORed of - * #hawk_trait_t enumerators, the function is available if + /** + * when this field is set to a non-zero value bitwise-ORed of + * #hawk_trait_t enumerators, the function is available if * this field bitwise-ANDed with the global trait option produces * this field itself. - * + * * this field doesn't take effect for a module function. */ - int trait; + int trait; }; typedef struct hawk_fnc_mspec_t hawk_fnc_mspec_t; /** * The hawk_fnc_wspec_t type defines a structure to hold the specification * of an intrinsic function or a module function. - */ + */ struct hawk_fnc_wspec_t { /** argument descriptor */ @@ -955,15 +955,15 @@ struct hawk_fnc_wspec_t /** pointer to the function implementing this function */ hawk_fnc_impl_t impl; - /** - * when this field is set to a non-zero value bitwise-ORed of - * #hawk_trait_t enumerators, the function is available if + /** + * when this field is set to a non-zero value bitwise-ORed of + * #hawk_trait_t enumerators, the function is available if * this field bitwise-ANDed with the global trait option produces * this field itself. - * + * * this field doesn't take effect for a module function. */ - int trait; + int trait; }; typedef struct hawk_fnc_wspec_t hawk_fnc_wspec_t; @@ -985,7 +985,7 @@ struct hawk_fnc_info_t hawk_oocs_t name; /** #HAWK_NULL if the function is not registered from module */ - hawk_mod_t* mod; + hawk_mod_t* mod; }; @@ -1029,7 +1029,7 @@ struct hawk_mod_t enum hawk_mod_sym_type_t { - HAWK_MOD_FNC = 0, + HAWK_MOD_FNC = 0, HAWK_MOD_INT, /* constant */ HAWK_MOD_FLT /* constant */ /*HAWK_MOD_STR, @@ -1055,7 +1055,7 @@ struct hawk_mod_sym_flt_t struct hawk_mod_sym_t { - hawk_mod_sym_type_t type; + hawk_mod_sym_type_t type; const hawk_ooch_t* name; union { @@ -1107,7 +1107,7 @@ typedef void (*hawk_ecb_close_t) ( * calls this calllback function before it performs actual clearing. */ typedef void (*hawk_ecb_clear_t) ( - hawk_t* hawk, + hawk_t* hawk, void* ctx ); @@ -1160,7 +1160,7 @@ typedef void (*hawk_rtx_ecb_stmt_t) ( ); /** - * The hawk_rtx_ecb_gblset_t type defines the callback function + * The hawk_rtx_ecb_gblset_t type defines the callback function * executed when a global variable is set with a value. It is not * called when a global variable is changed implicitly. For example, * it is not called when FNR is updated for each record read. @@ -1211,7 +1211,7 @@ struct hawk_rtx_ecb_t enum hawk_opt_t { /** trait option. 0 or bitwise-ORed of ::hawk_trait_t values */ - HAWK_OPT_TRAIT, + HAWK_OPT_TRAIT, HAWK_OPT_MODLIBDIRS, HAWK_OPT_MODPREFIX, @@ -1243,7 +1243,7 @@ typedef enum hawk_opt_t hawk_opt_t; * of #hawk_t. */ enum hawk_trait_t -{ +{ /** allows undeclared variables */ HAWK_IMPLICIT = (1 << 0), @@ -1255,7 +1255,7 @@ enum hawk_trait_t /** supports \b getline, \b print, \b printf, \b close, \b fflush, * piping, and file rediction */ - HAWK_RIO = (1 << 3), + HAWK_RIO = (1 << 3), /** enables the two-way pipe if #HAWK_RIO is on */ HAWK_RWPIPE = (1 << 4), @@ -1263,14 +1263,14 @@ enum hawk_trait_t /** a new line can terminate a statement */ HAWK_NEWLINE = (1 << 5), - /** + /** * removes leading and trailing blank fields when splitting a record if FS * is a regular expression and the match is all spaces. * * \code - * BEGIN { FS="[[:space:]]+"; } - * { - * print "NF=" NF; + * BEGIN { FS="[[:space:]]+"; } + * { + * print "NF=" NF; * for (i = 0; i < NF; i++) print i " [" $(i+1) "]"; * } * \endcode @@ -1278,14 +1278,14 @@ enum hawk_trait_t * Otherwise, it is split to [], [a], [b], [c], []. * * \code - * BEGIN { - * n=split(" oh my noodle ", x, /[ o]+/); - * for (i=1;i<=n;i++) print "[" x[i] "]"; + * BEGIN { + * n=split(" oh my noodle ", x, /[ o]+/); + * for (i=1;i<=n;i++) print "[" x[i] "]"; * } * \endcode * This example splits the string to [], [h], [my], [n], [dle] * if #HAWK_STRIPRECSPC is on. Otherwise, it results in - * [], [h], [my], [n], [dle], []. Note that the first empty field is not + * [], [h], [my], [n], [dle], []. Note that the first empty field is not * removed as the field separator is not all spaces. (space + 'o'). */ HAWK_STRIPRECSPC = (1 << 6), @@ -1293,7 +1293,7 @@ enum hawk_trait_t /** strips off leading spaces when converting a string to a number. */ HAWK_STRIPSTRSPC = (1 << 7), - /** enable implicit concatenation. + /** enable implicit concatenation. * if this is off, you need %% for concatenation. */ HAWK_BLANKCONCAT = (1 << 8), @@ -1301,8 +1301,8 @@ enum hawk_trait_t HAWK_CRLF = (1 << 10), /** treats a map value more flexibly. a function can return - * a map. you can override a map with a scalar value without - * 'delete' or '\@reset'. + * a map. you can override a map with a scalar value without + * 'delete' or '\@reset'. */ HAWK_FLEXMAP = (1 << 11), @@ -1312,7 +1312,7 @@ enum hawk_trait_t /** allows {n,m} in a regular expression. */ HAWK_REXBOUND = (1 << 13), - /** + /** * performs numeric comparison when a string convertable * to a number is compared with a number or vice versa. * @@ -1325,7 +1325,7 @@ enum hawk_trait_t /** * enables the strict naming rule. * - a parameter name can not be the same as the owning function name. - * - a local variable name can not be the same as the owning + * - a local variable name can not be the same as the owning * function name. */ HAWK_STRICTNAMING = (1 << 15), @@ -1349,13 +1349,13 @@ enum hawk_trait_t */ HAWK_NUMSTRDETECT = (1 << 18), - /** + /** * makes #hawk_t to behave compatibly with classical AWK * implementations */ - HAWK_CLASSIC = - HAWK_IMPLICIT | HAWK_RIO | - HAWK_NEWLINE | HAWK_BLANKCONCAT | HAWK_PABLOCK | + HAWK_CLASSIC = + HAWK_IMPLICIT | HAWK_RIO | + HAWK_NEWLINE | HAWK_BLANKCONCAT | HAWK_PABLOCK | HAWK_STRIPSTRSPC | HAWK_STRICTNAMING | HAWK_NUMSTRDETECT, HAWK_MODERN = @@ -1373,12 +1373,12 @@ enum hawk_gbl_id_t { /* this table should match gtab in parse.c. * - * in addition, hawk_rtx_setgbl also counts + * in addition, hawk_rtx_setgbl also counts * on the order of these values. - * - * note that set_global() in run.c contains code + * + * note that set_global() in run.c contains code * preventing these global variables from being assigned - * with a map value. if you happen to add one that can + * with a map value. if you happen to add one that can * be a map, don't forget to change code in set_global(). * but is this check really necessary??? */ @@ -1403,8 +1403,8 @@ enum hawk_gbl_id_t HAWK_GBL_STRIPSTRSPC, HAWK_GBL_SUBSEP, - /* these are not not the actual IDs and are used internally only - * Make sure you update these values properly if you add more + /* these are not not the actual IDs and are used internally only + * Make sure you update these values properly if you add more * ID definitions, however */ HAWK_MIN_GBL_ID = HAWK_GBL_CONVFMT, HAWK_MAX_GBL_ID = HAWK_GBL_SUBSEP @@ -1412,16 +1412,16 @@ enum hawk_gbl_id_t typedef enum hawk_gbl_id_t hawk_gbl_id_t; /** - * The hawk_val_type_t type defines types of AWK values. Each value + * The hawk_val_type_t type defines types of AWK values. Each value * allocated is tagged with a value type in the \a type field. * \sa hawk_val_t HAWK_VAL_HDR */ enum hawk_val_type_t { /* - the enumerators between HAWK_VAL_NIL and HAWK_VAL_ARR inclusive - * must be synchronized with an internal table of the __cmp_val + * must be synchronized with an internal table of the __cmp_val * function in run.c. - * - all enumerators must be in sync with __val_type_name in val.c + * - all enumerators must be in sync with __val_type_name in val.c * - all enumerators must be in sync with VAL_XXX defintion in mod-hawk.c */ HAWK_VAL_NIL = 0, /**< nil */ HAWK_VAL_CHAR = 1, /**< character */ @@ -1440,8 +1440,8 @@ enum hawk_val_type_t typedef enum hawk_val_type_t hawk_val_type_t; /** - * The values defined are used to set the type field of the - * #hawk_rtx_valtostr_out_t structure. The field should be one of the + * The values defined are used to set the type field of the + * #hawk_rtx_valtostr_out_t structure. The field should be one of the * following values: * * - #HAWK_RTX_VALTOSTR_CPL @@ -1453,11 +1453,11 @@ typedef enum hawk_val_type_t hawk_val_type_t; * and it can optionally be ORed with #HAWK_RTX_VALTOSTR_PRINT. */ enum hawk_rtx_valtostr_type_t -{ +{ /** use u.cpl of #hawk_rtx_valtostr_out_t */ - HAWK_RTX_VALTOSTR_CPL = 0x00, + HAWK_RTX_VALTOSTR_CPL = 0x00, /** use u.cplcpy of #hawk_rtx_valtostr_out_t */ - HAWK_RTX_VALTOSTR_CPLCPY = 0x01, + HAWK_RTX_VALTOSTR_CPLCPY = 0x01, /** use u.cpldup of #hawk_rtx_valtostr_out_t */ HAWK_RTX_VALTOSTR_CPLDUP = 0x02, /** use u.strp of #hawk_rtx_valtostr_out_t */ @@ -1465,11 +1465,11 @@ enum hawk_rtx_valtostr_type_t /** use u.strpcat of #hawk_rtx_valtostr_out_t */ HAWK_RTX_VALTOSTR_STRPCAT = 0x04, /** convert for print */ - HAWK_RTX_VALTOSTR_PRINT = 0x10 + HAWK_RTX_VALTOSTR_PRINT = 0x10 }; /** - * The hawk_rtx_valtostr() function converts a value to a string as + * The hawk_rtx_valtostr() function converts a value to a string as * indicated in a parameter of the hawk_rtx_valtostr_out_t type. */ struct hawk_rtx_valtostr_out_t @@ -1512,11 +1512,11 @@ extern "C" { #endif /** - * The hawk_open() function creates a new #hawk_t object. The object - * created can be passed to other hawk_xxx() functions and is valid until - * it is destroyed with the hawk_close() function. The function saves the - * memory manager pointer while it copies the contents of the primitive - * function structures. Therefore, you should keep the memory manager valid + * The hawk_open() function creates a new #hawk_t object. The object + * created can be passed to other hawk_xxx() functions and is valid until + * it is destroyed with the hawk_close() function. The function saves the + * memory manager pointer while it copies the contents of the primitive + * function structures. Therefore, you should keep the memory manager valid * during the whole life cycle of an hawk_t object. * * \code @@ -1525,21 +1525,21 @@ extern "C" { * hawk_mmgr_t mmgr; * hawk_prm_t prm; * return hawk_open ( - * &mmgr, // NOT OK because the contents of mmgr is - * // invalidated when dummy() returns. - * 0, - * &prm, // OK + * &mmgr, // NOT OK because the contents of mmgr is + * // invalidated when dummy() returns. + * 0, + * &prm, // OK * HAWK_NULL * ); * } * \endcode * - * Upon failure, it stores the error number to a variable pointed to + * Upon failure, it stores the error number to a variable pointed to * by \a errnum. if \a errnum is #HAWK_NULL, no error number is stored. * * \return a pointer to a hawk_t object on success, #HAWK_NULL on failure. */ -HAWK_EXPORT hawk_t* hawk_open ( +HAWK_EXPORT hawk_t* hawk_open ( hawk_mmgr_t* mmgr, /**< memory manager */ hawk_oow_t xtnsize, /**< extension size in bytes */ hawk_cmgr_t* cmgr, /**< character conversion manager */ @@ -1570,7 +1570,7 @@ static HAWK_INLINE void hawk_setcmgr (hawk_t* hawk, hawk_cmgr_t* cmgr) { ((hawk_ /** * The hawk_getprm() function retrieves primitive functions - * associated. Actual function pointers are copied into a + * associated. Actual function pointers are copied into a * structure specified by \a prm. */ HAWK_EXPORT void hawk_getprm ( @@ -1580,7 +1580,7 @@ HAWK_EXPORT void hawk_getprm ( /** * The hawk_setprm() function changes existing primitive - * functions. + * functions. */ HAWK_EXPORT void hawk_setprm ( hawk_t* hawk, @@ -1589,13 +1589,13 @@ HAWK_EXPORT void hawk_setprm ( /** * The hawk_clear() clears the internal state of \a hawk. If you want to - * reuse a hawk_t instance that finished being used, you may call + * reuse a hawk_t instance that finished being used, you may call * hawk_clear() instead of destroying and creating a new * #hawk_t instance using hawk_close() and hawk_open(). */ HAWK_EXPORT void hawk_clear ( - hawk_t* hawk + hawk_t* hawk ); /** @@ -1606,7 +1606,7 @@ HAWK_EXPORT hawk_errstr_t hawk_geterrstr ( ); /** - * The hawk_geterrnum() function returns the number of the last error + * The hawk_geterrnum() function returns the number of the last error * occurred. * \return error number */ @@ -1618,14 +1618,14 @@ HAWK_EXPORT hawk_errstr_t hawk_geterrstr ( /** * The hawk_geterrbmsg() function returns the error message describing - * the last error occurred. + * the last error occurred. * * \return error message */ /** * The hawk_geterrumsg() function returns the error message describing - * the last error occurred. + * the last error occurred. * * \return error message */ @@ -1660,7 +1660,7 @@ static HAWK_INLINE void hawk_geterruinf (hawk_t* hawk, hawk_erruinf_t* errinf) { #endif /** - * The hawk_seterrnum() function sets the error information omitting + * The hawk_seterrnum() function sets the error information omitting * error location. You must pass a non-NULL for \a errarg if the specified * error number \a errnum requires one or more arguments to format an * error message. @@ -1739,7 +1739,7 @@ HAWK_EXPORT int hawk_getopt ( ); /** - * The hawk_setopt() function sets the value of an option + * The hawk_setopt() function sets the value of an option * specified by \a id to the value pointed to by \a value. * * \return 0 on success, -1 on failure @@ -1890,10 +1890,10 @@ HAWK_EXPORT void hawk_clrfnc ( ); /** - * The hawk_parse() function parses a source script, and optionally - * deparses it back. + * The hawk_parse() function parses a source script, and optionally + * deparses it back. * - * It reads a source script by calling \a sio->in as shown in the pseudo code + * It reads a source script by calling \a sio->in as shown in the pseudo code * below: * * \code @@ -1907,11 +1907,11 @@ HAWK_EXPORT void hawk_clrfnc ( * \endcode * * A negative number returned causes hawk_parse() to return failure; - * 0 returned indicates the end of a stream; A positive number returned + * 0 returned indicates the end of a stream; A positive number returned * indicates successful opening of a stream or the length of the text read. * * If \a sio->out is not #HAWK_NULL, it deparses the internal parse tree - * composed of a source script and writes back the deparsing result by + * composed of a source script and writes back the deparsing result by * calling \a sio->out as shown below: * * \code @@ -1923,7 +1923,7 @@ HAWK_EXPORT void hawk_clrfnc ( * sio->out (hawk, HAWK_SIO_CMD_CLOSE); * } * \endcode - * + * * Unlike \a sf->in, the return value of 0 from \a sf->out is treated as * premature end of a stream; therefore, it causes hawk_parse() to return * failure. @@ -2120,10 +2120,10 @@ static HAWK_INLINE hawk_oow_t hawk_fmttobcstr (hawk_t* hawk, hawk_bch_t* buf, ha /* ----------------------------------------------------------------------- */ HAWK_EXPORT int hawk_buildrex ( - hawk_t* hawk, + hawk_t* hawk, const hawk_ooch_t* ptn, hawk_oow_t len, - hawk_tre_t** code, + hawk_tre_t** code, hawk_tre_t** icode ); @@ -2215,9 +2215,9 @@ HAWK_EXPORT int hawk_concatoochartosbuf ( /** * The hawk_rtx_open() creates a runtime context associated with \a hawk. * It also allocates an extra memory block as large as the \a xtn bytes. - * You can get the pointer to the beginning of the block with + * You can get the pointer to the beginning of the block with * hawk_rtx_getxtn(). The block is destroyed when the runtime context is - * destroyed. + * destroyed. * * \return new runtime context on success, #HAWK_NULL on failure */ @@ -2252,9 +2252,9 @@ static HAWK_INLINE void hawk_rtx_setcmgr (hawk_rtx_t* rtx, hawk_cmgr_t* cmgr) { /** * The hawk_rtx_loop() function executes the BEGIN block, pattern-action - * blocks and the END blocks in an AWK program. It returns the global return - * value of which the reference count must be decremented when not necessary. - * Multiple invocations of the function for the lifetime of a runtime context + * blocks and the END blocks in an AWK program. It returns the global return + * value of which the reference count must be decremented when not necessary. + * Multiple invocations of the function for the lifetime of a runtime context * is not desirable. * * The example shows typical usage of the function. @@ -2275,7 +2275,7 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_loop ( ); /** - * The hawk_rtx_findfunwithbcstr() function finds the function structure by + * The hawk_rtx_findfunwithbcstr() function finds the function structure by * name and returns the pointer to it if one is found. It returns #HAWK_NULL * if it fails to find a function by the \a name. */ @@ -2285,7 +2285,7 @@ HAWK_EXPORT hawk_fun_t* hawk_rtx_findfunwithbcstr ( ); /** - * The hawk_rtx_findfunwithucstr() function finds the function structure by + * The hawk_rtx_findfunwithucstr() function finds the function structure by * name and returns the pointer to it if one is found. It returns #HAWK_NULL * if it fails to find a function by the \a name. */ @@ -2313,9 +2313,9 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_callfun ( ); /** - * The hawk_rtx_callwithucstr() function invokes an AWK function named \a name. - * However, it is not able to invoke an intrinsic function such as split(). - * The #HAWK_PABLOCK option can be turned off to make illegal the BEGIN + * The hawk_rtx_callwithucstr() function invokes an AWK function named \a name. + * However, it is not able to invoke an intrinsic function such as split(). + * The #HAWK_PABLOCK option can be turned off to make illegal the BEGIN * blocks, the pattern-action blocks, and the END blocks. * * The example shows typical usage of the function. @@ -2341,9 +2341,9 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_callwithucstr ( ); /** - * The hawk_rtx_callwithbcstr() function invokes an AWK function named \a name. - * However, it is not able to invoke an intrinsic function such as split(). - * The #HAWK_PABLOCK option can be turned off to make illegal the BEGIN + * The hawk_rtx_callwithbcstr() function invokes an AWK function named \a name. + * However, it is not able to invoke an intrinsic function such as split(). + * The #HAWK_PABLOCK option can be turned off to make illegal the BEGIN * blocks, the pattern-action blocks, and the END blocks. * * The example shows typical usage of the function. @@ -2371,7 +2371,7 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_callwithbcstr ( /** * The hawk_rtx_callwithargarr() function is the same as hawk_rtx_call() * except that you pass pointers to null-terminated strings. It creates values - * from the null-terminated strings and calls hawk_rtx_call() with the + * from the null-terminated strings and calls hawk_rtx_call() with the * values created. */ HAWK_EXPORT hawk_val_t* hawk_rtx_callwithucstrarr ( @@ -2444,7 +2444,7 @@ HAWK_EXPORT void hawk_haltall ( ); /** - * The hawk_rtx_ishalt() function tests if hawk_rtx_halt() has been + * The hawk_rtx_ishalt() function tests if hawk_rtx_halt() has been * called. */ HAWK_EXPORT int hawk_rtx_ishalt ( @@ -2452,8 +2452,8 @@ HAWK_EXPORT int hawk_rtx_ishalt ( ); /** - * The hawk_rtx_halt() function causes an active runtime context \a rtx to - * be aborted. + * The hawk_rtx_halt() function causes an active runtime context \a rtx to + * be aborted. */ HAWK_EXPORT void hawk_rtx_halt ( hawk_rtx_t* rtx /**< runtime context */ @@ -2500,7 +2500,7 @@ HAWK_EXPORT void hawk_rtx_pushecb ( ); /** - * The hawk_rtx_getnargs() gets the number of arguments passed to an + * The hawk_rtx_getnargs() gets the number of arguments passed to an * intrinsic functon. */ HAWK_EXPORT hawk_oow_t hawk_rtx_getnargs ( @@ -2508,7 +2508,7 @@ HAWK_EXPORT hawk_oow_t hawk_rtx_getnargs ( ); /** - * The hawk_rtx_getarg() function gets an argument passed to an intrinsic + * The hawk_rtx_getarg() function gets an argument passed to an intrinsic * function. it doesn't touch the reference count of the value. */ HAWK_EXPORT hawk_val_t* hawk_rtx_getarg ( @@ -2527,9 +2527,9 @@ HAWK_EXPORT const hawk_oocs_t* hawk_rtx_getsubsep ( /** * The hawk_rtx_getgbl() gets the value of a global variable. - * The global variable ID \a id is one of the predefined global + * The global variable ID \a id is one of the predefined global * variable IDs or a value returned by hawk_addgbl(). - * This function never fails so long as the ID is valid. Otherwise, + * This function never fails so long as the ID is valid. Otherwise, * you may get into trouble. * * \return value pointer @@ -2543,7 +2543,7 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_getgbl ( * The hawk_rtx_setgbl() sets the value of a global variable. */ HAWK_EXPORT int hawk_rtx_setgbl ( - hawk_rtx_t* rtx, + hawk_rtx_t* rtx, int id, hawk_val_t* val ); @@ -2557,10 +2557,10 @@ HAWK_EXPORT int hawk_rtx_setgbltostrbyname ( /** * The hawk_rtx_setretval() sets the return value of a function * when called from within a function handler. The caller doesn't - * have to invoke hawk_rtx_refupval() and hawk_rtx_refdownval() - * with the value to be passed to hawk_rtx_setretval(). + * have to invoke hawk_rtx_refupval() and hawk_rtx_refdownval() + * with the value to be passed to hawk_rtx_setretval(). * The hawk_rtx_setretval() will update its reference count properly - * once the return value is set. + * once the return value is set. */ HAWK_EXPORT void hawk_rtx_setretval ( hawk_rtx_t* rtx, /**< runtime context */ @@ -2621,7 +2621,7 @@ HAWK_EXPORT int hawk_rtx_setscriptnamewithbchars ( #endif /** - * The hawk_rtx_getnvmap() gets the map of named variables + * The hawk_rtx_getnvmap() gets the map of named variables */ HAWK_EXPORT hawk_htb_t* hawk_rtx_getnvmap ( hawk_rtx_t* rtx /**< runtime context */ @@ -2635,18 +2635,18 @@ HAWK_EXPORT hawk_htb_t* hawk_rtx_getnvmap ( /** * The hawk_rtx_geterrloc() function gets the location of the last error - * occurred during runtime. The + * occurred during runtime. The * \return error location */ /** - * The hawk_rtx_geterrbmsg() function gets the string describing the last + * The hawk_rtx_geterrbmsg() function gets the string describing the last * error occurred during runtime. * \return error message */ /** - * The hawk_rtx_geterrumsg() function gets the string describing the last + * The hawk_rtx_geterrumsg() function gets the string describing the last * error occurred during runtime. * \return error message */ @@ -2657,9 +2657,9 @@ HAWK_EXPORT hawk_htb_t* hawk_rtx_getnvmap ( */ /** - * The hawk_rtx_geterror() function retrieves error information from a + * The hawk_rtx_geterror() function retrieves error information from a * runtime context \a rtx. The error number is stored into memory pointed - * to by \a errnum; the error message pointer into memory pointed to by + * to by \a errnum; the error message pointer into memory pointed to by * \a errmsg; the error line into memory pointed to by \a errlin. */ @@ -2685,7 +2685,7 @@ static HAWK_INLINE void hawk_rtx_geterror (hawk_rtx_t* rtx, hawk_errnum_t* errnu # define hawk_rtx_geterrmsg hawk_rtx_geterrumsg #endif -/** +/** * The hawk_rtx_seterrinf() function sets error information. */ #if defined(HAWK_HAVE_INLINE) @@ -2751,16 +2751,16 @@ HAWK_EXPORT void hawk_rtx_errortohawk ( ); /** - * The hawk_rtx_clrrec() function clears the input record ($0) + * The hawk_rtx_clrrec() function clears the input record ($0) * and fields ($1 to $N). */ HAWK_EXPORT int hawk_rtx_clrrec ( hawk_rtx_t* rtx, /**< runtime context */ - int skip_inrec_line + int skip_inrec_line ); /** - * The hawk_rtx_setrec() function sets the input record ($0) or + * The hawk_rtx_setrec() function sets the input record ($0) or * input fields ($1 to $N). */ HAWK_EXPORT int hawk_rtx_setrec ( @@ -2876,7 +2876,7 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_makestrvalwithucs ( HAWK_EXPORT hawk_val_t* hawk_rtx_makestrvalwithuchars2 ( hawk_rtx_t* rtx, const hawk_uch_t* str1, - hawk_oow_t len1, + hawk_oow_t len1, const hawk_uch_t* str2, hawk_oow_t len2 ); @@ -2884,7 +2884,7 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_makestrvalwithuchars2 ( HAWK_EXPORT hawk_val_t* hawk_rtx_makestrvalwithbchars2 ( hawk_rtx_t* rtx, const hawk_bch_t* str1, - hawk_oow_t len1, + hawk_oow_t len1, const hawk_bch_t* str2, hawk_oow_t len2 ); @@ -2918,8 +2918,8 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_makenstrvalwithbchars ( ); /** - * The hawk_rtx_makenstrvalwithucstr() function creates a numeric string - * value from a null-terminated string. A numeric string is a string value + * The hawk_rtx_makenstrvalwithucstr() function creates a numeric string + * value from a null-terminated string. A numeric string is a string value * whose one of the header fields \b nstr is 1. * \return value on success, #HAWK_NULL on failure */ @@ -2934,19 +2934,19 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_makenstrvalwithbcstr ( ); /** - * The hawk_rtx_makenstrvalwithucs() function creates a numeric string + * The hawk_rtx_makenstrvalwithucs() function creates a numeric string * value. A numeric string is a string value whose one of the header fields * \b nstr is 1. * \return value on success, #HAWK_NULL on failure */ HAWK_EXPORT hawk_val_t* hawk_rtx_makenstrvalwithucs ( hawk_rtx_t* rtx, - const hawk_ucs_t* str + const hawk_ucs_t* str ); HAWK_EXPORT hawk_val_t* hawk_rtx_makenstrvalwithbcs ( hawk_rtx_t* rtx, - const hawk_bcs_t* str + const hawk_bcs_t* str ); #if defined (HAWK_OOCH_IS_UCH) @@ -3114,7 +3114,7 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_getmapvalfld ( /** * The hawk_rtx_getfirstmapvalitr() returns the iterator to the - * first pair in the map. It returns #HAWK_NULL and sets the pair field of + * first pair in the map. It returns #HAWK_NULL and sets the pair field of * \a itr to #HAWK_NULL if the map contains no pair. Otherwise, it returns * \a itr pointing to the first pair. */ @@ -3126,7 +3126,7 @@ HAWK_EXPORT hawk_val_map_itr_t* hawk_rtx_getfirstmapvalitr ( /** * The hawk_rtx_getnextmapvalitr() returns the iterator to the - * next pair to \a itr in the map. It returns #HAWK_NULL and sets the pair + * next pair to \a itr in the map. It returns #HAWK_NULL and sets the pair * field of \a itr to #HAWK_NULL if \a itr points to the last pair. * Otherwise, it returns \a itr pointing to the next pair. */ @@ -3167,7 +3167,7 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_makefunval ( /** * The hawk_rtx_isstaticval() function determines if a value is static. - * A static value is allocated once and reused until a runtime context @ rtx + * A static value is allocated once and reused until a runtime context @ rtx * is closed. * \return HAWK_TRUE if \a val is static, HAWK_FALSE if \a val is false */ @@ -3192,7 +3192,7 @@ HAWK_EXPORT int hawk_rtx_getintfromval ( ); /** - * The hawk_rtx_refupval() function increments a reference count of a + * The hawk_rtx_refupval() function increments a reference count of a * value \a val. */ HAWK_EXPORT void hawk_rtx_refupval ( @@ -3211,7 +3211,7 @@ HAWK_EXPORT void hawk_rtx_refdownval ( /** * The hawk_rtx_refdownval() function decrements a reference count of - * a value \a val. It does not destroy the value if it has reached the + * a value \a val. It does not destroy the value if it has reached the * count of 0. */ HAWK_EXPORT void hawk_rtx_refdownval_nofree ( @@ -3223,7 +3223,7 @@ HAWK_EXPORT void hawk_rtx_refdownval_nofree ( #define HAWK_RTX_GC_GEN_FULL (HAWK_TYPE_MAX(int)) #define HAWK_RTX_GC_GEN_AUTO (-1) -/* +/* * The hawk_rtx_gc() function triggers garbage collection. * It returns the generation number collected and never fails */ @@ -3242,8 +3242,8 @@ HAWK_EXPORT int hawk_rtx_valtobool ( ); /** - * The hawk_rtx_valtostr() function converts a value \a val to a string as - * instructed in the parameter out. Before the call to the function, you + * The hawk_rtx_valtostr() function converts a value \a val to a string as + * instructed in the parameter out. Before the call to the function, you * should initialize a variable of the #hawk_rtx_valtostr_out_t type. * * The type field is one of the following hawk_rtx_valtostr_type_t values: @@ -3256,11 +3256,11 @@ HAWK_EXPORT int hawk_rtx_valtobool ( * * It can optionally be ORed with #HAWK_RTX_VALTOSTR_PRINT. The option * causes the function to use OFMT for real number conversion. Otherwise, - * it uses \b CONVFMT. + * it uses \b CONVFMT. * - * You should initialize or free other fields before and after the call + * You should initialize or free other fields before and after the call * depending on the type field as shown below: - * + * * If you have a static buffer, use #HAWK_RTX_VALTOSTR_CPLCPY. * the resulting string is copied to the buffer. * \code @@ -3276,7 +3276,7 @@ HAWK_EXPORT int hawk_rtx_valtobool ( * #HAWK_RTX_VALTOSTR_CPL is different from #HAWK_RTX_VALTOSTR_CPLCPY * in that it doesn't copy the string to the buffer if the type of the value * is #HAWK_VAL_STR. It copies the resulting string to the buffer if - * the value type is not #HAWK_VAL_STR. + * the value type is not #HAWK_VAL_STR. * \code * hawk_rtx_valtostr_out_t out; * hawk_ooch_t buf[100]; @@ -3286,7 +3286,7 @@ HAWK_EXPORT int hawk_rtx_valtobool ( * if (hawk_rtx_valtostr (rtx, v, &out) <= -1) goto oops; * hawk_printf (HAWK_T("%.*s\n"), ut.u.cpl.len, out.u.cpl.ptr); * \endcode - * + * * When unsure of the size of the string after conversion, you can use * #HAWK_RTX_VALTOSTR_CPLDUP. However, you should free the memory block * pointed to by the u.cpldup.ptr field after use. @@ -3310,10 +3310,10 @@ HAWK_EXPORT int hawk_rtx_valtobool ( * hawk_printf (HAWK_T("%.*s\n"), HAWK_STR_LEN(out.u.strp), HAWK_STR_PTR(out.u.strp)); * hawk_str_fini (&str); * \endcode - * - * If you want to append the converted string to an existing dynamically + * + * If you want to append the converted string to an existing dynamically * resizable string, #HAWK_RTX_VALTOSTR_STRPCAT is the answer. The usage is - * the same as #HAWK_RTX_VALTOSTR_STRP except that you have to use the + * the same as #HAWK_RTX_VALTOSTR_STRP except that you have to use the * u.strpcat field instead of the u.strp field. * * In the context where \a val is determined to be of the type @@ -3375,7 +3375,7 @@ HAWK_EXPORT hawk_uch_t* hawk_rtx_valtoucstrdupwithcmgr ( /** * The hawk_rtx_getvaloocstr() function returns a string - * pointer converted from a value \a val. If the value + * pointer converted from a value \a val. If the value * type is #HAWK_VAL_STR, it simply returns the internal * pointer without duplication. Otherwise, it calls * hawk_rtx_valtooocstrdup(). The length of the returned @@ -3391,8 +3391,8 @@ HAWK_EXPORT hawk_ooch_t* hawk_rtx_getvaloocstrwithcmgr ( #define hawk_rtx_getvaloocstr(rtx,val,len) hawk_rtx_getvaloocstrwithcmgr(rtx, val, len, hawk_rtx_getcmgr(rtx)) /** - * The hawk_rtx_freevaloocstr() function frees the memory pointed - * to by \a str if \a val is not of the #HAWK_VAL_STR type. + * The hawk_rtx_freevaloocstr() function frees the memory pointed + * to by \a str if \a val is not of the #HAWK_VAL_STR type. * This function expects a value pointer and a string pointer * passed to and returned by hawk_rtx_getvaloocstr() respectively. */ @@ -3419,9 +3419,9 @@ HAWK_EXPORT void hawk_rtx_freevalbcstr ( ); /** - * The hawk_rtx_valtonum() function converts a value to a number. + * The hawk_rtx_valtonum() function converts a value to a number. * If the value is converted to an integer, it is stored in the memory - * pointed to by l and 0 is returned. If the value is converted to a real + * pointed to by l and 0 is returned. If the value is converted to a real * number, it is stored in the memory pointed to by r and 1 is returned. * The function never fails as long as \a val points to a valid value. * @@ -3438,7 +3438,7 @@ HAWK_EXPORT void hawk_rtx_freevalbcstr ( * else if (n >= 1) print_flt (r); * \endcode * - * \return -1 on failure, 0 if converted to an integer, 1 if converted to + * \return -1 on failure, 0 if converted to an integer, 1 if converted to * a floating-point number. */ HAWK_EXPORT int hawk_rtx_valtonum ( @@ -3465,7 +3465,7 @@ HAWK_EXPORT hawk_fun_t* hawk_rtx_valtofun ( hawk_val_t* val ); -/** +/** * The hawk_rtx_valtofnc() function finds an intrinsic function by the name * pointed to by \a val. Unlike hawk_findfncwithoocstr() and the like, * it accepts a function name prefixed with a module name and find an intrinsic @@ -3475,7 +3475,7 @@ HAWK_EXPORT hawk_fun_t* hawk_rtx_valtofun ( * \return \a fnc on success, #HAWK_NULL on failure */ HAWK_EXPORT hawk_fnc_t* hawk_rtx_valtofnc ( - hawk_rtx_t* rtx, + hawk_rtx_t* rtx, hawk_val_t* val, hawk_fnc_t* fnc /**< buffer to hold the function information */ ); @@ -3505,7 +3505,7 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_getrefval ( /** * The hawk_rtx_setrefval() function changes the value - * of a variable referenced in \a ref. + * of a variable referenced in \a ref. * \return 0 on success, -1 on failure. */ HAWK_EXPORT int hawk_rtx_setrefval ( @@ -3659,10 +3659,10 @@ static HAWK_INLINE hawk_oow_t hawk_rtx_fmttobcstr (hawk_rtx_t* rtx, hawk_bch_t* HAWK_EXPORT int hawk_rtx_buildrex ( - hawk_rtx_t* rtx, + hawk_rtx_t* rtx, const hawk_ooch_t* ptn, hawk_oow_t len, - hawk_tre_t** code, + hawk_tre_t** code, hawk_tre_t** icode ); @@ -3677,7 +3677,7 @@ static HAWK_INLINE void hawk_rtx_freerex (hawk_rtx_t* rtx, hawk_tre_t* code, haw /** * The hawk_get_nil_val() function returns the pointer to the predefined - * nil value. you can call this without creating a runtime context. + * nil value. you can call this without creating a runtime context. */ HAWK_EXPORT hawk_val_t* hawk_get_nil_val ( void diff --git a/lib/htb.c b/lib/htb.c index dccd7231..acfcf9f5 100644 --- a/lib/htb.c +++ b/lib/htb.c @@ -76,7 +76,7 @@ HAWK_INLINE pair_t* hawk_htb_allocpair (hawk_htb_t* htb, void* kptr, hawk_oow_t * the actual key area */ if (kptr) HAWK_MEMCPY (KPTR(n), kptr, KTOB(htb,klen)); } - else + else { KPTR(n) = kcop(htb, kptr, klen); if (KPTR(n) == HAWK_NULL) @@ -94,13 +94,13 @@ HAWK_INLINE pair_t* hawk_htb_allocpair (hawk_htb_t* htb, void* kptr, hawk_oow_t else if (vcop == HAWK_HTB_COPIER_INLINE) { VPTR(n) = n + 1; - if (kcop == HAWK_HTB_COPIER_INLINE) + if (kcop == HAWK_HTB_COPIER_INLINE) VPTR(n) = (hawk_uint8_t*)VPTR(n) + HAWK_ALIGN_POW2(KTOB(htb,klen), HAWK_SIZEOF_VOID_P); /* if vptr is HAWK_NULL, the inline copier does not fill * the actual value area */ if (vptr) HAWK_MEMCPY (VPTR(n), vptr, VTOB(htb,vlen)); } - else + else { VPTR(n) = vcop (htb, vptr, vlen); if (VPTR(n) != HAWK_NULL) @@ -117,19 +117,19 @@ HAWK_INLINE pair_t* hawk_htb_allocpair (hawk_htb_t* htb, void* kptr, hawk_oow_t HAWK_INLINE void hawk_htb_freepair (hawk_htb_t* htb, pair_t* pair) { - if (htb->style->freeer[HAWK_HTB_KEY] != HAWK_NULL) + if (htb->style->freeer[HAWK_HTB_KEY] != HAWK_NULL) htb->style->freeer[HAWK_HTB_KEY] (htb, KPTR(pair), KLEN(pair)); if (htb->style->freeer[HAWK_HTB_VAL] != HAWK_NULL) htb->style->freeer[HAWK_HTB_VAL] (htb, VPTR(pair), VLEN(pair)); - hawk_gem_freemem (htb->gem, pair); + hawk_gem_freemem (htb->gem, pair); } static HAWK_INLINE pair_t* change_pair_val (hawk_htb_t* htb, pair_t* pair, void* vptr, hawk_oow_t vlen) { - if (VPTR(pair) == vptr && VLEN(pair) == vlen) + if (VPTR(pair) == vptr && VLEN(pair) == vlen) { /* if the old value and the new value are the same, - * it just calls the handler for this condition. + * it just calls the handler for this condition. * No value replacement occurs. */ if (htb->style->keeper != HAWK_NULL) { @@ -163,7 +163,7 @@ static HAWK_INLINE pair_t* change_pair_val (hawk_htb_t* htb, pair_t* pair, void* return p; } } - else + else { void* nvptr = vcop(htb, vptr, vlen); if (HAWK_UNLIKELY(!nvptr)) return HAWK_NULL; @@ -172,7 +172,7 @@ static HAWK_INLINE pair_t* change_pair_val (hawk_htb_t* htb, pair_t* pair, void* } /* free up the old value */ - if (htb->style->freeer[HAWK_HTB_VAL] != HAWK_NULL) + if (htb->style->freeer[HAWK_HTB_VAL] != HAWK_NULL) { htb->style->freeer[HAWK_HTB_VAL] (htb, ovptr, ovlen); } @@ -278,11 +278,11 @@ void hawk_htb_close (hawk_htb_t* htb) int hawk_htb_init (hawk_htb_t* htb, hawk_gem_t* gem, hawk_oow_t capa, int factor, int kscale, int vscale) { - /* The initial capacity should be greater than 0. + /* The initial capacity should be greater than 0. * Otherwise, it is adjusted to 1 in the release mode */ HAWK_ASSERT (capa > 0); - /* The load factor should be between 0 and 100 inclusive. + /* The load factor should be between 0 and 100 inclusive. * In the release mode, a value out of the range is adjusted to 100 */ HAWK_ASSERT (factor >= 0 && factor <= 100); @@ -351,7 +351,7 @@ pair_t* hawk_htb_search (const hawk_htb_t* htb, const void* kptr, hawk_oow_t kle hc = htb->style->hasher(htb,kptr,klen) % htb->capa; pair = htb->bucket[hc]; - while (pair != HAWK_NULL) + while (pair != HAWK_NULL) { if (htb->style->comper(htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) { @@ -374,9 +374,9 @@ static HAWK_INLINE int reorganize (hawk_htb_t* htb) { new_capa = htb->style->sizer (htb, htb->capa + 1); - /* if no change in capacity, return success + /* if no change in capacity, return success * without reorganization */ - if (new_capa == htb->capa) return 0; + if (new_capa == htb->capa) return 0; /* adjust to 1 if the new capacity is not reasonable */ if (new_capa <= 0) new_capa = 1; @@ -389,7 +389,7 @@ static HAWK_INLINE int reorganize (hawk_htb_t* htb) } new_buck = (pair_t**)hawk_gem_allocmem(htb->gem, new_capa * HAWK_SIZEOF(pair_t*)); - if (HAWK_UNLIKELY(!new_buck)) + if (HAWK_UNLIKELY(!new_buck)) { /* reorganization is disabled once it fails */ htb->threshold = 0; @@ -403,7 +403,7 @@ static HAWK_INLINE int reorganize (hawk_htb_t* htb) { pair_t* pair = htb->bucket[i]; - while (pair != HAWK_NULL) + while (pair != HAWK_NULL) { pair_t* next = NEXT(pair); @@ -439,11 +439,11 @@ static HAWK_INLINE pair_t* insert (hawk_htb_t* htb, void* kptr, hawk_oow_t klen, pair = htb->bucket[hc]; prev = HAWK_NULL; - while (pair != HAWK_NULL) + while (pair != HAWK_NULL) { next = NEXT(pair); - if (htb->style->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) + if (htb->style->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) { /* found a pair with a matching key */ switch (opt) @@ -451,25 +451,25 @@ static HAWK_INLINE pair_t* insert (hawk_htb_t* htb, void* kptr, hawk_oow_t klen, case UPSERT: case UPDATE: p = change_pair_val (htb, pair, vptr, vlen); - if (p == HAWK_NULL) + if (p == HAWK_NULL) { /* error in changing the value */ - return HAWK_NULL; + return HAWK_NULL; } - if (p != pair) + if (p != pair) { /* old pair destroyed. new pair reallocated. * relink to include the new pair but to drop * the old pair. */ if (prev == HAWK_NULL) htb->bucket[hc] = p; else NEXT(prev) = p; - NEXT(p) = next; + NEXT(p) = next; } return p; case ENSERT: /* return existing pair */ - return pair; + return pair; case INSERT: /* return failure */ @@ -482,7 +482,7 @@ static HAWK_INLINE pair_t* insert (hawk_htb_t* htb, void* kptr, hawk_oow_t klen, pair = next; } - if (opt == UPDATE) + if (opt == UPDATE) { hawk_gem_seterrnum (htb->gem, HAWK_NULL, HAWK_ENOENT); return HAWK_NULL; @@ -492,7 +492,7 @@ static HAWK_INLINE pair_t* insert (hawk_htb_t* htb, void* kptr, hawk_oow_t klen, { /* ingore reorganization error as it simply means * more bucket collision and performance penalty. */ - if (reorganize(htb) == 0) + if (reorganize(htb) == 0) { hc = htb->style->hasher(htb,kptr,klen) % htb->capa; } @@ -540,27 +540,27 @@ pair_t* hawk_htb_cbsert (hawk_htb_t* htb, void* kptr, hawk_oow_t klen, cbserter_ pair = htb->bucket[hc]; prev = HAWK_NULL; - while (pair != HAWK_NULL) + while (pair != HAWK_NULL) { next = NEXT(pair); - if (htb->style->comper(htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) + if (htb->style->comper(htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) { /* found a pair with a matching key */ p = cbserter(htb, pair, kptr, klen, ctx); - if (p == HAWK_NULL) + if (p == HAWK_NULL) { /* error returned by the callback function */ - return HAWK_NULL; + return HAWK_NULL; } - if (p != pair) + if (p != pair) { /* old pair destroyed. new pair reallocated. * relink to include the new pair but to drop * the old pair. */ if (prev == HAWK_NULL) htb->bucket[hc] = p; else NEXT(prev) = p; - NEXT(p) = next; + NEXT(p) = next; } return p; } @@ -600,11 +600,11 @@ int hawk_htb_delete (hawk_htb_t* htb, const void* kptr, hawk_oow_t klen) pair = htb->bucket[hc]; prev = HAWK_NULL; - while (pair != HAWK_NULL) + while (pair != HAWK_NULL) { - if (htb->style->comper(htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) + if (htb->style->comper(htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) { - if (prev == HAWK_NULL) + if (prev == HAWK_NULL) htb->bucket[hc] = NEXT(pair); else NEXT(prev) = NEXT(pair); @@ -627,11 +627,11 @@ void hawk_htb_clear (hawk_htb_t* htb) hawk_oow_t i; pair_t* pair, * next; - for (i = 0; i < htb->capa; i++) + for (i = 0; i < htb->capa; i++) { pair = htb->bucket[i]; - while (pair != HAWK_NULL) + while (pair != HAWK_NULL) { next = NEXT(pair); hawk_htb_freepair (htb, pair); @@ -648,11 +648,11 @@ void hawk_htb_walk (hawk_htb_t* htb, walker_t walker, void* ctx) hawk_oow_t i; pair_t* pair, * next; - for (i = 0; i < htb->capa; i++) + for (i = 0; i < htb->capa; i++) { pair = htb->bucket[i]; - while (pair != HAWK_NULL) + while (pair != HAWK_NULL) { next = NEXT(pair); if (walker(htb, pair, ctx) == HAWK_HTB_WALK_STOP) return; @@ -676,7 +676,7 @@ pair_t* hawk_htb_getfirstpair (hawk_htb_t* htb, hawk_htb_itr_t* itr) for (i = 0; i < htb->capa; i++) { pair = htb->bucket[i]; - if (pair) + if (pair) { itr->buckno = i; itr->pair = pair; @@ -693,7 +693,7 @@ pair_t* hawk_htb_getnextpair (hawk_htb_t* htb, hawk_htb_itr_t* itr) pair_t* pair; pair = NEXT(itr->pair); - if (pair) + if (pair) { /* no change in bucket number */ itr->pair = pair; @@ -703,7 +703,7 @@ pair_t* hawk_htb_getnextpair (hawk_htb_t* htb, hawk_htb_itr_t* itr) for (i = itr->buckno + 1; i < htb->capa; i++) { pair = htb->bucket[i]; - if (pair) + if (pair) { itr->buckno = i; itr->pair = pair; @@ -718,7 +718,7 @@ hawk_oow_t hawk_htb_dflhash (const hawk_htb_t* htb, const void* kptr, hawk_oow_t { hawk_oow_t h; HAWK_HASH_BYTES (h, kptr, klen); - return h ; + return h ; } int hawk_htb_dflcomp (const hawk_htb_t* htb, const void* kptr1, hawk_oow_t klen1, const void* kptr2, hawk_oow_t klen2) diff --git a/lib/idmap-imp.h b/lib/idmap-imp.h index 96b477b2..a2f65b06 100644 --- a/lib/idmap-imp.h +++ b/lib/idmap-imp.h @@ -74,7 +74,7 @@ static __IDMAP_NODE_T* __MAKE_IDMAP_NODE (hawk_rtx_t* rtx, __IDMAP_LIST_T* list) node = HAWK_NULL; #if defined(__IDMAP_AVOID_CIRCULAR_LIST) - if (list->free) + if (list->free) { node = list->free; list->free = node->next; @@ -92,7 +92,7 @@ static __IDMAP_NODE_T* __MAKE_IDMAP_NODE (hawk_rtx_t* rtx, __IDMAP_LIST_T* list) { node = hawk_rtx_callocmem(rtx, HAWK_SIZEOF(*node)); if (!node) goto oops; - + if (list->map.high <= list->map.capa) { hawk_oow_t newcapa, inc; @@ -180,7 +180,7 @@ static void __FREE_IDMAP_NODE (hawk_rtx_t* rtx, __IDMAP_LIST_T* list, __IDMAP_NO /* however, i destroy the whole free list when all the nodes are * chanined to the free list */ #if defined(__IDMAP_AVOID_CIRCULAR_LIST) - if (list->head == HAWK_NULL) + if (list->head == HAWK_NULL) { __IDMAP_NODE_T* curnode; diff --git a/lib/misc-imp.h b/lib/misc-imp.h index c8bb6b34..41998813 100644 --- a/lib/misc-imp.h +++ b/lib/misc-imp.h @@ -35,7 +35,7 @@ char_t* split_xchars_to_fields (hawk_rtx_t* rtx, char_t* str, hawk_oow_t len, ch while (p < end && is_xch_space(*p)) p++; /* initialize token pointers */ - ts = tp = xp = p; + ts = tp = xp = p; while (p < end) { @@ -65,7 +65,7 @@ char_t* split_xchars_to_fields (hawk_rtx_t* rtx, char_t* str, hawk_oow_t len, ch *tp++ = c; xp = tp; p++; } } - else + else { if (c == fs) { @@ -81,7 +81,7 @@ char_t* split_xchars_to_fields (hawk_rtx_t* rtx, char_t* str, hawk_oow_t len, ch return p; } - + if (c == lq) { quoted = 1; @@ -90,15 +90,15 @@ char_t* split_xchars_to_fields (hawk_rtx_t* rtx, char_t* str, hawk_oow_t len, ch else { *tp++ = c; p++; - if (!is_xch_space(c)) xp = tp; + if (!is_xch_space(c)) xp = tp; } } } } - if (escaped) + if (escaped) { - /* if it is still escaped, the last character must be + /* if it is still escaped, the last character must be * the escaper itself. treat it as a normal character */ *xp++ = ec; } @@ -114,7 +114,7 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const const char_t* end = s + len; const char_t* sp = HAWK_NULL, * ep = HAWK_NULL; const char_t* delim_end = delim + delim_len; - char_t c; + char_t c; int delim_mode; #define __DELIM_NULL 0 @@ -123,13 +123,13 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const #define __DELIM_NOSPACES 3 #define __DELIM_COMPOSITE 4 if (delim == HAWK_NULL) delim_mode = __DELIM_NULL; - else + else { delim_mode = __DELIM_EMPTY; - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { - if (is_xch_space(*d)) + if (is_xch_space(*d)) { if (delim_mode == __DELIM_EMPTY) delim_mode = __DELIM_SPACES; @@ -152,23 +152,23 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const } /* TODO: verify the following statement... */ - if (delim_mode == __DELIM_SPACES && - delim_len == 1 && + if (delim_mode == __DELIM_SPACES && + delim_len == 1 && delim[0] != ' ') delim_mode = __DELIM_NOSPACES; } - if (delim_mode == __DELIM_NULL) - { - /* when HAWK_NULL is given as "delim", it trims off the + if (delim_mode == __DELIM_NULL) + { + /* when HAWK_NULL is given as "delim", it trims off the * leading and trailing spaces characters off the source * string "s" eventually. */ while (p < end && is_xch_space(*p)) p++; - while (p < end) + while (p < end) { c = *p; - if (!is_xch_space(c)) + if (!is_xch_space(c)) { if (sp == HAWK_NULL) sp = p; ep = p; @@ -186,13 +186,13 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const ep = p++; } } - else if (delim_mode == __DELIM_SPACES) + else if (delim_mode == __DELIM_SPACES) { /* each token is delimited by space characters. all leading * and trailing spaces are removed. */ while (p < end && is_xch_space(*p)) p++; - while (p < end) + while (p < end) { c = *p; if (is_xch_space(c)) break; @@ -203,14 +203,14 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const } else if (delim_mode == __DELIM_NOSPACES) { - /* each token is delimited by one of charaters + /* each token is delimited by one of charaters * in the delimeter set "delim". */ if (rtx->gbl.ignorecase) { - while (p < end) + while (p < end) { c = to_xch_upper(*p); - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { if (c == to_xch_upper(*d)) goto exit_loop; } @@ -221,10 +221,10 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const } else { - while (p < end) + while (p < end) { c = *p; - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { if (c == *d) goto exit_loop; } @@ -234,7 +234,7 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const } } } - else /* if (delim_mode == __DELIM_COMPOSITE) */ + else /* if (delim_mode == __DELIM_COMPOSITE) */ { /* each token is delimited by one of non-space charaters * in the delimeter set "delim". however, all space characters @@ -242,15 +242,15 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const while (p < end && is_xch_space(*p)) p++; if (rtx->gbl.ignorecase) { - while (p < end) + while (p < end) { c = to_xch_upper(*p); - if (is_xch_space(c)) + if (is_xch_space(c)) { p++; continue; } - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { if (c == to_xch_upper(*d)) goto exit_loop; } @@ -260,15 +260,15 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const } else { - while (p < end) + while (p < end) { c = *p; - if (is_xch_space(c)) + if (is_xch_space(c)) { p++; continue; } - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { if (c == *d) goto exit_loop; } @@ -279,20 +279,20 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const } exit_loop: - if (sp == HAWK_NULL) + if (sp == HAWK_NULL) { tok->ptr = HAWK_NULL; tok->len = (hawk_oow_t)0; } - else + else { tok->ptr = (char_t*)sp; - tok->len = ep - sp + 1; + tok->len = ep - sp + 1; } /* if HAWK_NULL is returned, this function should not be called again */ if (p >= end) return HAWK_NULL; - if (delim_mode == __DELIM_EMPTY || + if (delim_mode == __DELIM_EMPTY || delim_mode == __DELIM_SPACES) return (char_t*)p; return (char_t*)++p; } @@ -324,7 +324,7 @@ char_t* tokenize_xchars_by_rex (hawk_rtx_t* rtx, const char_t* str, hawk_oow_t l hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR); /* reset HAWK_EREXNOMAT to no error */ tok->ptr = realsub.ptr; tok->len = realsub.len; - return HAWK_NULL; + return HAWK_NULL; } HAWK_ASSERT (n == 1); @@ -338,14 +338,14 @@ char_t* tokenize_xchars_by_rex (hawk_rtx_t* rtx, const char_t* str, hawk_oow_t l else if (HAWK_RTX_IS_STRIPRECSPC_ON(rtx)) { /* match at the beginning of the input string */ - if (match.ptr == substr) + if (match.ptr == substr) { for (i = 0; i < match.len; i++) { if (!is_xch_space(match.ptr[i])) goto exit_loop; } - /* the match that is all spaces at the + /* the match that is all spaces at the * beginning of the input string is skipped */ cursub.ptr += match.len; cursub.len -= match.len; @@ -367,7 +367,7 @@ exit_loop: { tok->ptr = realsub.ptr; tok->len = realsub.len; - return HAWK_NULL; + return HAWK_NULL; } tok->ptr = realsub.ptr; @@ -391,7 +391,7 @@ exit_loop: } else { - /* if the match went beyond the the last character in the input + /* if the match went beyond the the last character in the input * string, it returns HAWK_NULL to terminate tokenization. */ return (match.ptr+match.len > substr+sublen)? HAWK_NULL: ((char_t*)match.ptr+match.len); } diff --git a/lib/misc-prv.h b/lib/misc-prv.h index 32f8d98b..55993d0d 100644 --- a/lib/misc-prv.h +++ b/lib/misc-prv.h @@ -63,7 +63,7 @@ hawk_bch_t* hawk_rtx_tokbcharswithbchars ( hawk_uch_t* hawk_rtx_tokucharsbyrex ( - hawk_rtx_t* rtx, + hawk_rtx_t* rtx, const hawk_uch_t* str, hawk_oow_t len, const hawk_uch_t* substr, @@ -73,7 +73,7 @@ hawk_uch_t* hawk_rtx_tokucharsbyrex ( ); hawk_bch_t* hawk_rtx_tokbcharsbyrex ( - hawk_rtx_t* rtx, + hawk_rtx_t* rtx, const hawk_bch_t* str, hawk_oow_t len, const hawk_bch_t* substr, @@ -107,13 +107,13 @@ int hawk_rtx_matchvalwithbcs ( ); int hawk_rtx_matchrexwithucs ( - hawk_rtx_t* rtx, hawk_tre_t* code, + hawk_rtx_t* rtx, hawk_tre_t* code, const hawk_ucs_t* str, const hawk_ucs_t* substr, hawk_ucs_t* match, hawk_ucs_t submat[9] ); int hawk_rtx_matchrexwithbcs ( - hawk_rtx_t* rtx, hawk_tre_t* code, + hawk_rtx_t* rtx, hawk_tre_t* code, const hawk_bcs_t* str, const hawk_bcs_t* substr, hawk_bcs_t* match, hawk_bcs_t submat[9] ); diff --git a/lib/misc.c b/lib/misc.c index d61ea4e6..21764a88 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -93,11 +93,11 @@ static int matchtre_ucs (hawk_tre_t* tre, int opt, const hawk_ucs_t* str, hawk_u { int i; - /* you must intialize submat before you pass into this + /* you must intialize submat before you pass into this * function because it can abort filling */ for (i = 1; i < HAWK_COUNTOF(match); i++) { - if (match[i].rm_so != -1) + if (match[i].rm_so != -1) { submat[i-1].ptr = &str->ptr[match[i].rm_so]; submat[i-1].len = match[i].rm_eo - match[i].rm_so; @@ -132,11 +132,11 @@ static int matchtre_bcs (hawk_tre_t* tre, int opt, const hawk_bcs_t* str, hawk_b { int i; - /* you must intialize submat before you pass into this + /* you must intialize submat before you pass into this * function because it can abort filling */ for (i = 1; i < HAWK_COUNTOF(match); i++) { - if (match[i].rm_so != -1) + if (match[i].rm_so != -1) { submat[i-1].ptr = &str->ptr[match[i].rm_so]; submat[i-1].len = match[i].rm_eo - match[i].rm_so; @@ -160,7 +160,7 @@ int hawk_rtx_matchvalwithucs (hawk_rtx_t* rtx, hawk_val_t* val, const hawk_ucs_t { code = ((hawk_val_rex_t*)val)->code[ignorecase]; } - else + else { /* convert to a string and build a regular expression */ hawk_oocs_t tmp; @@ -180,7 +180,7 @@ int hawk_rtx_matchvalwithucs (hawk_rtx_t* rtx, hawk_val_t* val, const hawk_ucs_t substr, match, submat, hawk_rtx_getgem(rtx) ); - if (v_type == HAWK_VAL_REX) + if (v_type == HAWK_VAL_REX) { /* nothing to free */ } @@ -207,7 +207,7 @@ int hawk_rtx_matchvalwithbcs (hawk_rtx_t* rtx, hawk_val_t* val, const hawk_bcs_t { code = ((hawk_val_rex_t*)val)->code[ignorecase]; } - else + else { /* convert to a string and build a regular expression */ hawk_oocs_t tmp; @@ -226,7 +226,7 @@ int hawk_rtx_matchvalwithbcs (hawk_rtx_t* rtx, hawk_val_t* val, const hawk_bcs_t substr, match, submat, hawk_rtx_getgem(rtx) ); - if (v_type == HAWK_VAL_REX) + if (v_type == HAWK_VAL_REX) { /* nothing to free */ } diff --git a/lib/mod-hawk.c b/lib/mod-hawk.c index c50d36c0..7b9cb723 100644 --- a/lib/mod-hawk.c +++ b/lib/mod-hawk.c @@ -63,7 +63,7 @@ static hawk_oow_t push_args_from_stack (hawk_rtx_t* rtx, hawk_nde_fncall_t* call } org_stack_base = rtx->stack_base; - for (i = pasf->start_index, j = 0; i <= pasf->end_index; i++, j++) + for (i = pasf->start_index, j = 0; i <= pasf->end_index; i++, j++) { hawk_ooch_t spec; @@ -78,7 +78,7 @@ static hawk_oow_t push_args_from_stack (hawk_rtx_t* rtx, hawk_nde_fncall_t* call { if (pasf->is_fun) { - /* take out the actual value and pass it to the callee + /* take out the actual value and pass it to the callee * only if the callee is a user-defined function */ v = hawk_rtx_getrefval(rtx, (hawk_val_ref_t*)v); } @@ -113,7 +113,7 @@ static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) f_nargs = nargs - 1; fun = hawk_rtx_valtofun(rtx, hawk_rtx_getarg(rtx, 0)); - if (fun) + if (fun) { if (f_nargs > fun->nargs) { @@ -138,7 +138,7 @@ static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) md = (mod_data_t*)fi->mod->ctx; /* hawk_querymodulewithname() called by hawk_rtx_valtofnc() - * may update some shared data under the hawk object. + * may update some shared data under the hawk object. * use a mutex for shared data safety */ /* TODO: this mutex protection is wrong in that if a call to hawk_querymodulewithname() * is made outside this hawk module, the call is not protected under @@ -148,7 +148,7 @@ static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) hawk_mtx_unlock (&md->mq_mtx); if (!fncp) return -1; /* hard failure */ - if (f_nargs < fnc.spec.arg.min || f_nargs > fnc.spec.arg.max) + if (f_nargs < fnc.spec.arg.min || f_nargs > fnc.spec.arg.max) { hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EARGTM); return -1; @@ -180,7 +180,7 @@ static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) return 0; } -/* hawk::function_exists("xxxx"); +/* hawk::function_exists("xxxx"); * hawk::function_exists("sys::getpid") */ static int fnc_function_exists (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) { @@ -314,12 +314,12 @@ static int fnc_gc_set_threshold (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 1), &threshold) <= -1) threshold = -1; - if (threshold >= 0) + if (threshold >= 0) { if (threshold >= HAWK_INT_MAX) threshold = HAWK_INT_MAX; rtx->gc.threshold[gen] = threshold; /* update */ } - else + else { threshold = rtx->gc.threshold[gen]; /* no update. but retrieve the existing value */ } diff --git a/lib/mod-math.c b/lib/mod-math.c index 83bdf7a6..54aee866 100644 --- a/lib/mod-math.c +++ b/lib/mod-math.c @@ -212,12 +212,12 @@ static hawk_flt_t math_round (hawk_t* hawk, hawk_flt_t x) /* this implementation doesn't keep the signbit for -0.0. * The signbit() function defined in C99 may get used to * preserve the sign bit. but this is a fall-back rountine - * for a system without round also defined in C99. + * for a system without round also defined in C99. * don't get annoyed by the lost sign bit for the value of 0.0. */ return f; - + #endif } @@ -613,7 +613,7 @@ static int fnc_srand (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) srand (lv); #endif } - + r = hawk_rtx_makeintval (rtx, prev); if (r == HAWK_NULL) return -1; @@ -649,7 +649,7 @@ static hawk_mod_fnc_tab_t fnctab[] = }; static int query (hawk_mod_t* mod, hawk_t* hawk, const hawk_ooch_t* name, hawk_mod_sym_t* sym) -{ +{ return hawk_findmodsymfnc(hawk, fnctab, HAWK_COUNTOF(fnctab), name, sym); } diff --git a/lib/mod-str.c b/lib/mod-str.c index 8f07bb52..621b0db0 100644 --- a/lib/mod-str.c +++ b/lib/mod-str.c @@ -27,7 +27,7 @@ static int fnc_normspace (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) { - /* normalize spaces + /* normalize spaces * - trim leading and trailing spaces * - replace a series of spaces to a single space */ @@ -98,11 +98,11 @@ static int trim (hawk_rtx_t* rtx, int flags) hawk_ooch_t* npath; path.ptr = hawk_rtx_getvaloocstr(rtx, a0, &path.len); if (HAWK_UNLIKELY(!path.ptr)) return -1; - /* because hawk_trim_oochars() returns the pointer and the length without + /* because hawk_trim_oochars() returns the pointer and the length without * affecting the string given, it's safe to pass the original value. - * hawk_rtx_getvaloocstr() doesn't duplicate the value if it's of + * hawk_rtx_getvaloocstr() doesn't duplicate the value if it's of * the string type. */ - npath = hawk_trim_oochars(path.ptr, &path.len, flags); + npath = hawk_trim_oochars(path.ptr, &path.len, flags); retv = hawk_rtx_makestrvalwithoochars(rtx, npath, path.len); hawk_rtx_freevaloocstr (rtx, a0, path.ptr); break; @@ -136,7 +136,7 @@ static int fnc_ltrim (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) static int fnc_rtrim (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) { return trim(rtx, HAWK_TRIM_OOCHARS_RIGHT); -} +} static int is_class (hawk_rtx_t* rtx, hawk_ooch_prop_t ctype) { @@ -163,7 +163,7 @@ static int is_class (hawk_rtx_t* rtx, hawk_ooch_prop_t ctype) do { len0--; - if (!hawk_is_bch_type(str0[len0], ctype)) + if (!hawk_is_bch_type(str0[len0], ctype)) { tmp = 0; break; @@ -176,7 +176,7 @@ static int is_class (hawk_rtx_t* rtx, hawk_ooch_prop_t ctype) break; } - default: + default: { hawk_ooch_t* str0; hawk_oow_t len0; @@ -191,7 +191,7 @@ static int is_class (hawk_rtx_t* rtx, hawk_ooch_prop_t ctype) do { len0--; - if (!hawk_is_ooch_type(str0[len0], ctype)) + if (!hawk_is_ooch_type(str0[len0], ctype)) { tmp = 0; break; @@ -308,7 +308,7 @@ static int fnc_frombcharcode (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) hawk_int_t cc; a0 = hawk_rtx_getarg(rtx, i); - if (hawk_rtx_valtoint(rtx, a0, &cc) <= -1) + if (hawk_rtx_valtoint(rtx, a0, &cc) <= -1) { hawk_rtx_freeval (rtx, retv, 0); return -1; @@ -359,7 +359,7 @@ static int fnc_fromcharcode (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) hawk_int_t cc; a0 = hawk_rtx_getarg(rtx, i); - if (hawk_rtx_valtoint(rtx, a0, &cc) <= -1) + if (hawk_rtx_valtoint(rtx, a0, &cc) <= -1) { hawk_rtx_freeval (rtx, retv, 0); return -1; @@ -445,7 +445,7 @@ static int fnc_tocharcode (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) static int fnc_frommbs (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) { /* str::frommbs(@b"byte-string" [, "encoding-name"]) - * + * * if you use a supported encoding name, it may look like this: * a = str::frommbs(@b"\xC7\xD1\xB1\xDB", "cp949"); * printf ("%K\n", a); @@ -458,16 +458,16 @@ static int fnc_frommbs (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) hawk_val_t* a1; hawk_oocs_t enc; - + a1 = hawk_rtx_getarg(rtx, 1); enc.ptr = hawk_rtx_getvaloocstr(rtx, a1, &enc.len); if (!enc.ptr) return -1; - /* if encoding name is an empty string, hawk_findcmgr() returns the default cmgr. + /* if encoding name is an empty string, hawk_findcmgr() returns the default cmgr. * i don't want that behavior. */ cmgr = (enc.len > 0 && enc.len == hawk_count_oocstr(enc.ptr))? hawk_get_cmgr_by_name(enc.ptr): HAWK_NULL; hawk_rtx_freevaloocstr (rtx, a1, enc.ptr); - if (!cmgr) + if (!cmgr) { /* if the encoding name is not known, return a zero-length string */ r = hawk_rtx_makestrvalwithoochars(rtx, HAWK_NULL, 0); /* this never fails for length 0 */ @@ -501,11 +501,11 @@ done: static int fnc_tombs (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) { - /* str::tombs("string", [, "encoding-name"]) - * + /* str::tombs("string", [, "encoding-name"]) + * * if you use a supported encoding name, it may look like this: - * a = str::tombs("\uD55C\uAE00", "cp949"); - * printf (@b"%K\n", a); + * a = str::tombs("\uD55C\uAE00", "cp949"); + * printf (@b"%K\n", a); */ hawk_val_t* a0, * r; @@ -518,12 +518,12 @@ static int fnc_tombs (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) a1 = hawk_rtx_getarg(rtx, 1); enc.ptr = hawk_rtx_getvaloocstr(rtx, a1, &enc.len); if (!enc.ptr) return -1; - /* if encoding name is an empty string, hawk_findcmgr() returns the default cmgr. + /* if encoding name is an empty string, hawk_findcmgr() returns the default cmgr. * i don't want that behavior. */ cmgr = (enc.len > 0 && enc.len == hawk_count_oocstr(enc.ptr))? hawk_get_cmgr_by_name(enc.ptr): HAWK_NULL; hawk_rtx_freevaloocstr (rtx, a1, enc.ptr); - if (!cmgr) + if (!cmgr) { /* if the encoding name is not known, return a zero-length string */ r = hawk_rtx_makembsvalwithbchars(rtx, HAWK_NULL, 0); /* this never fails for length 0 */ @@ -542,7 +542,7 @@ static int fnc_tombs (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) if (HAWK_UNLIKELY(!r)) return -1; break; } - + case HAWK_VAL_MBS: /* no conversion */ r = a0; @@ -599,7 +599,7 @@ static int fnc_tonum (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) break; } - case HAWK_VAL_MBS: + case HAWK_VAL_MBS: { /* if the value is known to be a byte string, it supports the optional * base parameter */ @@ -715,7 +715,7 @@ static int fnc_subchar (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) hawk_rtx_freevalbcstr (rtx, a0, str); break; } - + default: { hawk_ooch_t* str; diff --git a/lib/mtx.c b/lib/mtx.c index 97ec9153..520cd796 100644 --- a/lib/mtx.c +++ b/lib/mtx.c @@ -82,7 +82,7 @@ int hawk_mtx_init (hawk_mtx_t* mtx, hawk_gem_t* gem) #if defined(_WIN32) mtx->hnd = CreateMutex(HAWK_NULL, FALSE, HAWK_NULL); - if (mtx->hnd == HAWK_NULL) + if (mtx->hnd == HAWK_NULL) { hawk_gem_seterrnum (mtx->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); return -1; @@ -95,7 +95,7 @@ int hawk_mtx_init (hawk_mtx_t* mtx, hawk_gem_t* gem) HMTX m; rc = DosCreateMutexSem(HAWK_NULL, &m, DC_SEM_SHARED, FALSE); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (mtx->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); return -1; @@ -114,7 +114,7 @@ int hawk_mtx_init (hawk_mtx_t* mtx, hawk_gem_t* gem) /* hawk_ensure (pthread_mutexattr_init (&attr) == 0); - if (pthread_mutexattr_settype (&attr, type) != 0) + if (pthread_mutexattr_settype (&attr, type) != 0) { int num = hawk_geterrno(); pthread_mutexattr_destroy (&attr); @@ -164,16 +164,16 @@ void hawk_mtx_fini (hawk_mtx_t* mtx) int hawk_mtx_lock (hawk_mtx_t* mtx, const hawk_ntime_t* waiting_time) { #if defined(_WIN32) - /* + /* * MSDN - * WAIT_ABANDONED The specified object is a mutex object that was - * not released by the thread that owned the mutex - * object before the owning thread terminated. - * Ownership of the mutex object is granted to the + * WAIT_ABANDONED The specified object is a mutex object that was + * not released by the thread that owned the mutex + * object before the owning thread terminated. + * Ownership of the mutex object is granted to the * calling thread, and the mutex is set to nonsignaled. - * WAIT_OBJECT_0 The state of the specified object is signaled. - * WAIT_TIMEOUT The time-out interval elapsed, and the object's - * state is nonsignaled. + * WAIT_OBJECT_0 The state of the specified object is signaled. + * WAIT_TIMEOUT The time-out interval elapsed, and the object's + * state is nonsignaled. * WAIT_FAILED An error occurred */ if (waiting_time) @@ -199,7 +199,7 @@ int hawk_mtx_lock (hawk_mtx_t* mtx, const hawk_ntime_t* waiting_time) } else { - if (WaitForSingleObject(mtx->hnd, INFINITE) == WAIT_FAILED) + if (WaitForSingleObject(mtx->hnd, INFINITE) == WAIT_FAILED) { hawk_gem_seterrnum (mtx->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); return -1; @@ -223,7 +223,7 @@ int hawk_mtx_lock (hawk_mtx_t* mtx, const hawk_ntime_t* waiting_time) { APIRET rc; rc = DosRequestMutexSem(mtx->hnd, SEM_INDEFINITE_WAIT); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (mtx->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); return -1; @@ -282,7 +282,7 @@ int hawk_mtx_lock (hawk_mtx_t* mtx, const hawk_ntime_t* waiting_time) int hawk_mtx_unlock (hawk_mtx_t* mtx) { #if defined(_WIN32) - if (ReleaseMutex(mtx->hnd) == FALSE) + if (ReleaseMutex(mtx->hnd) == FALSE) { hawk_gem_seterrnum (mtx->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); return -1; @@ -291,7 +291,7 @@ int hawk_mtx_unlock (hawk_mtx_t* mtx) #elif defined(__OS2__) APIRET rc; rc = DosReleaseMutexSem(mtx->hnd); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (mtx->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); return -1; @@ -308,7 +308,7 @@ int hawk_mtx_unlock (hawk_mtx_t* mtx) int n; n = pthread_mutex_unlock((pthread_mutex_t*)&mtx->hnd); - if (n != 0) + if (n != 0) { hawk_gem_seterrnum (mtx->gem, HAWK_NULL, hawk_syserr_to_errnum(n)); return -1; @@ -322,7 +322,7 @@ int hawk_mtx_unlock (hawk_mtx_t* mtx) int hawk_mtx_trylock (hawk_mtx_t* mtx) { #if defined(_WIN32) - if (WaitForSingleObject(mtx->hnd, 0) != WAIT_OBJECT_0) + if (WaitForSingleObject(mtx->hnd, 0) != WAIT_OBJECT_0) { hawk_gem_seterrnum (mtx->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); return -1; @@ -330,7 +330,7 @@ int hawk_mtx_trylock (hawk_mtx_t* mtx) #elif defined(__OS2__) APIRET rc; rc = DosRequestMutexSem(mtx->hnd, 0); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (mtx->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); return -1; diff --git a/lib/parse-prv.h b/lib/parse-prv.h index e783ad28..95bedd3a 100644 --- a/lib/parse-prv.h +++ b/lib/parse-prv.h @@ -86,7 +86,7 @@ const hawk_ooch_t* hawk_getgblname ( void hawk_getkwname ( hawk_t* hawk, - hawk_kwid_t id, + hawk_kwid_t id, hawk_oocs_t* s ); diff --git a/lib/pio.c b/lib/pio.c index b8cd1637..be8f0c27 100644 --- a/lib/pio.c +++ b/lib/pio.c @@ -67,8 +67,8 @@ static int get_highest_fd (hawk_pio_t* pio) #endif /* will getting the highest file descriptor be faster than - * attempting to close any files descriptors less than the - * system limit? */ + * attempting to close any files descriptors less than the + * system limit? */ d = HAWK_OPENDIR(HAWK_BT("/proc/self/fd")); if (!d) @@ -109,7 +109,7 @@ static int get_highest_fd (hawk_pio_t* pio) #if defined(HAVE_GETRLIMIT) if (HAWK_GETRLIMIT(RLIMIT_NOFILE, &rlim) <= -1 || - rlim.rlim_max == RLIM_INFINITY) + rlim.rlim_max == RLIM_INFINITY) { #if defined(HAVE_SYSCONF) fd = sysconf(_SC_OPEN_MAX); @@ -121,10 +121,10 @@ static int get_highest_fd (hawk_pio_t* pio) #endif if (fd <= -1) fd = 1024; /* fallback */ - /* F_MAXFD is the highest fd. but RLIMIT_NOFILE and - * _SC_OPEN_MAX returnes the maximum number of file + /* F_MAXFD is the highest fd. but RLIMIT_NOFILE and + * _SC_OPEN_MAX returnes the maximum number of file * descriptors. make adjustment */ - if (fd > 0) fd--; + if (fd > 0) fd--; return fd; } @@ -134,8 +134,8 @@ static int close_open_fds_using_proc (hawk_pio_t* pio, int* excepts, hawk_oow_t HAWK_DIR* d; /* will getting the highest file descriptor be faster than - * attempting to close any files descriptors less than the - * system limit? */ + * attempting to close any files descriptors less than the + * system limit? */ d = HAWK_OPENDIR(HAWK_BT("/proc/self/fd")); if (!d) @@ -145,7 +145,7 @@ static int close_open_fds_using_proc (hawk_pio_t* pio, int* excepts, hawk_oow_t d = HAWK_OPENDIR(buf); #if !defined(_SCO_DS) /* on SCO OpenServer, a range of file descriptors starting from 0 are - * listed under /dev/fd regardless of opening state. And some high + * listed under /dev/fd regardless of opening state. And some high * numbered descriptors are not listed. not reliable */ if (!d) d = HAWK_OPENDIR(HAWK_BT("/dev/fd")); /* Darwin, FreeBSD */ @@ -232,7 +232,7 @@ typedef struct param_t param_t; static void free_param (hawk_pio_t* pio, param_t* param) { - if (param->argv && param->argv != param->fixed_argv) + if (param->argv && param->argv != param->fixed_argv) hawk_gem_freemem (pio->gem, param->argv); if (param->mcmd) hawk_gem_freemem (pio->gem, param->mcmd); } @@ -256,18 +256,18 @@ static int make_param (hawk_pio_t* pio, const hawk_ooch_t* cmd, int flags, param 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) + fcnt = hawk_split_oocstr(mcmd, HAWK_T(""), HAWK_T('\"'), HAWK_T('\"'), HAWK_T('\\')); + if (fcnt <= 0) { /* no field or an error */ hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_EINVAL); - goto oops; + goto oops; } } #else - if (flags & HAWK_PIO_BCSTRCMD) + if (flags & HAWK_PIO_BCSTRCMD) { - /* the cmd is flagged to be of hawk_bch_t + /* the cmd is flagged to be of hawk_bch_t * while the default character type is hawk_uch_t. */ if (flags & HAWK_PIO_SHELL) mcmd = (hawk_bch_t*)cmd; @@ -276,12 +276,12 @@ static int make_param (hawk_pio_t* pio, const hawk_ooch_t* cmd, int flags, param mcmd = hawk_gem_dupbcstr(pio->gem, (const hawk_bch_t*)cmd, HAWK_NULL); if (mcmd == HAWK_NULL) goto oops; - fcnt = hawk_split_bcstr(mcmd, "", '\"', '\"', '\\'); - if (fcnt <= 0) + fcnt = hawk_split_bcstr(mcmd, "", '\"', '\"', '\\'); + if (fcnt <= 0) { /* no field or an error */ hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_EINVAL); - goto oops; + goto oops; } } } @@ -304,21 +304,21 @@ static int make_param (hawk_pio_t* pio, const hawk_ooch_t* cmd, int flags, param wcmd = hawk_gem_dupoocstr(pio->gem, cmd, HAWK_NULL); if (wcmd == HAWK_NULL) goto oops; - fcnt = hawk_split_oocstr(wcmd, HAWK_T(""), HAWK_T('\"'), HAWK_T('\"'), HAWK_T('\\')); + fcnt = hawk_split_oocstr(wcmd, HAWK_T(""), HAWK_T('\"'), HAWK_T('\"'), HAWK_T('\\')); if (fcnt <= 0) { /* no field or an error */ hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_EINVAL); goto oops; } - + /* calculate the length of the string after splitting */ for (wl = 0, n = fcnt; n > 0; ) { if (wcmd[wl++] == HAWK_T('\0')) n--; } - if (hawk_conv_uchars_to_bchars_with_cmgr(wcmd, &wl, HAWK_NULL, &mn, pio->gem->cmgr) <= -1) + if (hawk_conv_uchars_to_bchars_with_cmgr(wcmd, &wl, HAWK_NULL, &mn, pio->gem->cmgr) <= -1) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_EINVAL); goto oops; @@ -343,7 +343,7 @@ static int make_param (hawk_pio_t* pio, const hawk_ooch_t* cmd, int flags, param if (flags & HAWK_PIO_SHELL) { /*HAWK_ASSERT (wcmd == HAWK_NULL);*/ - /* hawk_wcstombs() should succeed as + /* hawk_wcstombs() should succeed as * it was successful above */ hawk_conv_ucstr_to_bcstr_with_cmgr (cmd, &wl, mcmd, &mn, pio->gem->cmgr); /* hawk_wcstombs() null-terminate mcmd */ @@ -351,7 +351,7 @@ static int make_param (hawk_pio_t* pio, const hawk_ooch_t* cmd, int flags, param else { HAWK_ASSERT (wcmd != HAWK_NULL); - /* hawk_wcsntombsn() should succeed as + /* hawk_wcsntombsn() should succeed as * it was was successful above */ hawk_conv_uchars_to_bchars_with_cmgr (wcmd, &wl, mcmd, &mn, pio->gem->cmgr); /* hawk_wcsntombsn() doesn't null-terminate mcmd */ @@ -400,7 +400,7 @@ static int make_param (hawk_pio_t* pio, const hawk_ooch_t* cmd, int flags, param #if defined(HAWK_OOCH_IS_BCH) if (mcmd && mcmd != (hawk_bch_t*)cmd) param->mcmd = mcmd; #else - if (mcmd && mcmd != (hawk_bch_t*)cmd && + if (mcmd && mcmd != (hawk_bch_t*)cmd && mcmd != param->fixed_mbuf) param->mcmd = mcmd; #endif return 0; @@ -409,7 +409,7 @@ oops: #if defined(HAWK_OOCH_IS_BCH) if (mcmd && mcmd != cmd) hawk_gem_freemem (pio->gem, mcmd); #else - if (mcmd && mcmd != (hawk_bch_t*)cmd && + if (mcmd && mcmd != (hawk_bch_t*)cmd && mcmd != param->fixed_mbuf) hawk_gem_freemem (pio->gem, mcmd); if (wcmd) hawk_gem_freemem (pio->gem, wcmd); #endif @@ -420,7 +420,7 @@ static int assert_executable (hawk_pio_t* pio, const hawk_bch_t* path) { hawk_lstat_t st; - if (HAWK_ACCESS(path, X_OK) <= -1) + if (HAWK_ACCESS(path, X_OK) <= -1) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -433,7 +433,7 @@ static int assert_executable (hawk_pio_t* pio, const hawk_bch_t* path) return -1; } - if (!S_ISREG(st.st_mode)) + if (!S_ISREG(st.st_mode)) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_EACCES); return -1; @@ -469,7 +469,7 @@ static hawk_pio_pid_t standard_fork_and_exec (hawk_pio_t* pio, int pipes[], para #endif pid = HAWK_FORK(); - if (pid <= -1) + if (pid <= -1) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); return -1; @@ -486,13 +486,13 @@ static hawk_pio_pid_t standard_fork_and_exec (hawk_pio_t* pio, int pipes[], para { int fd = get_highest_fd(pio); - /* close all other unknown open handles except + /* close all other unknown open handles except * stdin/out/err and the pipes. */ while (fd > 2) { if (fd != pipes[0] && fd != pipes[1] && fd != pipes[2] && fd != pipes[3] && - fd != pipes[4] && fd != pipes[5]) + fd != pipes[4] && fd != pipes[5]) { HAWK_CLOSE (fd); } @@ -523,14 +523,14 @@ static hawk_pio_pid_t standard_fork_and_exec (hawk_pio_t* pio, int pipes[], para if (HAWK_DUP2 (pipes[3], 2) <= -1) goto child_oops; } - HAWK_CLOSE (pipes[3]); + HAWK_CLOSE (pipes[3]); pipes[3] = HAWK_PIO_HND_NIL; } if (pio->flags & HAWK_PIO_READERR) { /* child should write */ - HAWK_CLOSE (pipes[4]); + HAWK_CLOSE (pipes[4]); pipes[4] = HAWK_PIO_HND_NIL; if (HAWK_DUP2 (pipes[5], 2) <= -1) goto child_oops; @@ -543,7 +543,7 @@ static hawk_pio_pid_t standard_fork_and_exec (hawk_pio_t* pio, int pipes[], para pipes[5] = HAWK_PIO_HND_NIL; } - if ((pio->flags & HAWK_PIO_INTONUL) || + if ((pio->flags & HAWK_PIO_INTONUL) || (pio->flags & HAWK_PIO_OUTTONUL) || (pio->flags & HAWK_PIO_ERRTONUL)) { @@ -562,9 +562,9 @@ static hawk_pio_pid_t standard_fork_and_exec (hawk_pio_t* pio, int pipes[], para if ((pio->flags & HAWK_PIO_ERRTONUL) && HAWK_DUP2(devnull,2) <= -1) goto child_oops; - if ((pio->flags & HAWK_PIO_INTONUL) || + if ((pio->flags & HAWK_PIO_INTONUL) || (pio->flags & HAWK_PIO_OUTTONUL) || - (pio->flags & HAWK_PIO_ERRTONUL)) + (pio->flags & HAWK_PIO_ERRTONUL)) { HAWK_CLOSE (devnull); devnull = -1; @@ -592,7 +592,7 @@ static hawk_pio_pid_t standard_fork_and_exec (hawk_pio_t* pio, int pipes[], para HAWK_EXECVE (param->argv[0], param->argv, environ); /* if exec fails, free 'param' parameter which is an inherited pointer */ - free_param (pio, param); + free_param (pio, param); } child_oops: @@ -623,9 +623,9 @@ static int set_pipe_nonblock (hawk_pio_t* pio, hawk_pio_hnd_t fd, int enabled) int hawk_pio_init (hawk_pio_t* pio, hawk_gem_t* gem, const hawk_ooch_t* cmd, int flags) { - hawk_pio_hnd_t handle[6] /*= - { - HAWK_PIO_HND_NIL, + hawk_pio_hnd_t handle[6] /*= + { + HAWK_PIO_HND_NIL, HAWK_PIO_HND_NIL, HAWK_PIO_HND_NIL, HAWK_PIO_HND_NIL, @@ -633,17 +633,17 @@ int hawk_pio_init (hawk_pio_t* pio, hawk_gem_t* gem, const hawk_ooch_t* cmd, int HAWK_PIO_HND_NIL }*/; - hawk_tio_t* tio[3] /*= - { - HAWK_NULL, - HAWK_NULL, - HAWK_NULL + hawk_tio_t* tio[3] /*= + { + HAWK_NULL, + HAWK_NULL, + HAWK_NULL }*/; int i, minidx = -1, maxidx = -1; #if defined(_WIN32) - SECURITY_ATTRIBUTES secattr; + SECURITY_ATTRIBUTES secattr; PROCESS_INFORMATION procinfo; STARTUPINFO startup; HANDLE windevnul = INVALID_HANDLE_VALUE; @@ -668,7 +668,7 @@ int hawk_pio_init (hawk_pio_t* pio, hawk_gem_t* gem, const hawk_ooch_t* cmd, int /* DOS not multi-processed. can't support pio */ -#elif defined(HAVE_POSIX_SPAWN) && !(defined(HAWK_SYSCALL0) && defined(SYS_vfork)) +#elif defined(HAVE_POSIX_SPAWN) && !(defined(HAWK_SYSCALL0) && defined(SYS_vfork)) posix_spawn_file_actions_t fa; int fa_inited = 0; int pserr; @@ -725,14 +725,14 @@ int hawk_pio_init (hawk_pio_t* pio, hawk_gem_t* gem, const hawk_ooch_t* cmd, int if (flags & HAWK_PIO_WRITEIN) { /* child reads, parent writes */ - if (CreatePipe(&handle[0], &handle[1], &secattr, 0) == FALSE) + if (CreatePipe(&handle[0], &handle[1], &secattr, 0) == FALSE) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); goto oops; } /* don't inherit write handle */ - if (SetHandleInformation(handle[1], HANDLE_FLAG_INHERIT, 0) == FALSE) + if (SetHandleInformation(handle[1], HANDLE_FLAG_INHERIT, 0) == FALSE) { DWORD e = GetLastError(); if (e != ERROR_CALL_NOT_IMPLEMENTED) @@ -750,14 +750,14 @@ int hawk_pio_init (hawk_pio_t* pio, hawk_gem_t* gem, const hawk_ooch_t* cmd, int if (flags & HAWK_PIO_READOUT) { /* child writes, parent reads */ - if (CreatePipe(&handle[2], &handle[3], &secattr, 0) == FALSE) + if (CreatePipe(&handle[2], &handle[3], &secattr, 0) == FALSE) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); goto oops; } /* don't inherit read handle */ - if (SetHandleInformation(handle[2], HANDLE_FLAG_INHERIT, 0) == FALSE) + if (SetHandleInformation(handle[2], HANDLE_FLAG_INHERIT, 0) == FALSE) { DWORD e = GetLastError(); if (e != ERROR_CALL_NOT_IMPLEMENTED) @@ -799,22 +799,22 @@ int hawk_pio_init (hawk_pio_t* pio, hawk_gem_t* gem, const hawk_ooch_t* cmd, int maxidx = 5; } - if (maxidx == -1) + if (maxidx == -1) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_EINVAL); goto oops; } - if ((flags & HAWK_PIO_INTONUL) || + if ((flags & HAWK_PIO_INTONUL) || (flags & HAWK_PIO_OUTTONUL) || (flags & HAWK_PIO_ERRTONUL)) { windevnul = CreateFile( HAWK_T("NUL"), GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, &secattr, OPEN_EXISTING, 0, NULL ); - if (windevnul == INVALID_HANDLE_VALUE) + if (windevnul == INVALID_HANDLE_VALUE) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); goto oops; @@ -837,13 +837,13 @@ int hawk_pio_init (hawk_pio_t* pio, hawk_gem_t* gem, const hawk_ooch_t* cmd, int startup.hStdOutput = GetStdHandle(STD_ERROR_HANDLE); if (startup.hStdInput == INVALID_HANDLE_VALUE || startup.hStdOutput == INVALID_HANDLE_VALUE || - startup.hStdError == INVALID_HANDLE_VALUE) + startup.hStdError == INVALID_HANDLE_VALUE) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); goto oops; } - if (flags & HAWK_PIO_WRITEIN) + if (flags & HAWK_PIO_WRITEIN) { startup.hStdInput = handle[0]; } @@ -876,7 +876,7 @@ int hawk_pio_init (hawk_pio_t* pio, hawk_gem_t* gem, const hawk_ooch_t* cmd, int create_retried = 0; create_process: - if (flags & HAWK_PIO_SHELL) + if (flags & HAWK_PIO_SHELL) { static const hawk_ooch_t* cmdname[] = { @@ -908,7 +908,7 @@ create_process: dupcmd = hawk_gem_dupoocstrarr(pio->gem, x, HAWK_NULL); } } - else + else { #if defined(HAWK_OOCH_IS_UCH) if (flags & HAWK_PIO_BCSTRCMD) @@ -944,14 +944,14 @@ create_process: &procinfo /* LPPROCESS_INFORMATION lpProcessInformation */ ); - hawk_gem_freemem (pio->gem, dupcmd); - if (apiret == FALSE) + hawk_gem_freemem (pio->gem, dupcmd); + if (apiret == FALSE) { DWORD e = GetLastError(); - if (create_retried == 0 && (flags & HAWK_PIO_SHELL) && + if (create_retried == 0 && (flags & HAWK_PIO_SHELL) && e == ERROR_FILE_NOT_FOUND) { - /* if it failed to exeucte cmd.exe, + /* if it failed to exeucte cmd.exe, * attempt to execute command.com. * this is provision for old windows platforms */ create_retried = 1; @@ -964,7 +964,7 @@ create_process: if (windevnul != INVALID_HANDLE_VALUE) { - CloseHandle (windevnul); + CloseHandle (windevnul); windevnul = INVALID_HANDLE_VALUE; } @@ -1002,23 +1002,23 @@ create_process: { /* child reads, parent writes */ rc = DosCreatePipe (&handle[0], &handle[1], pipe_size); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); goto oops; } - /* the parent writes to handle[1] and the child reads from + /* the parent writes to handle[1] and the child reads from * handle[0] inherited. set the flag not to inherit handle[1]. */ rc = DosSetFHState (handle[1], OPEN_FLAGS_NOINHERIT); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); goto oops; } - /* Need to do somthing like this to set the flag instead? - ULONG state; + /* Need to do somthing like this to set the flag instead? + ULONG state; DosQueryFHState (handle[1], &state); DosSetFHState (handle[1], state | OPEN_FLAGS_NOINHERIT); */ @@ -1029,16 +1029,16 @@ create_process: { /* child writes, parent reads */ rc = DosCreatePipe (&handle[2], &handle[3], pipe_size); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); goto oops; } - /* the parent reads from handle[2] and the child writes to + /* the parent reads from handle[2] and the child writes to * handle[3] inherited. set the flag not to inherit handle[2] */ rc = DosSetFHState(handle[2], OPEN_FLAGS_NOINHERIT); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); goto oops; @@ -1052,16 +1052,16 @@ create_process: { /* child writes, parent reads */ rc = DosCreatePipe(&handle[4], &handle[5], pipe_size); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); goto oops; } - /* the parent reads from handle[4] and the child writes to + /* the parent reads from handle[4] and the child writes to * handle[5] inherited. set the flag not to inherit handle[4] */ rc = DosSetFHState (handle[4], OPEN_FLAGS_NOINHERIT); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); goto oops; @@ -1071,13 +1071,13 @@ create_process: maxidx = 5; } - if (maxidx == -1) + if (maxidx == -1) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_EINVAL); goto oops; } - if ((flags & HAWK_PIO_INTONUL) || + if ((flags & HAWK_PIO_INTONUL) || (flags & HAWK_PIO_OUTTONUL) || (flags & HAWK_PIO_ERRTONUL)) { @@ -1100,7 +1100,7 @@ create_process: OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE, 0L ); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); goto oops; @@ -1108,22 +1108,22 @@ create_process: } /* duplicate the current stdin/out/err to old_in/out/err as a new handle */ - + rc = DosDupHandle(std_in, &old_in); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); goto oops; } rc = DosDupHandle(std_out, &old_out); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); DosClose (old_in); old_in = HAWK_PIO_HND_NIL; goto oops; } rc = DosDupHandle(std_err, &old_err); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); DosClose (old_out); old_out = HAWK_PIO_HND_NIL; @@ -1131,10 +1131,10 @@ create_process: goto oops; } - /* we must not let our own stdin/out/err duplicated + /* we must not let our own stdin/out/err duplicated * into old_in/out/err be inherited */ DosSetFHState (old_in, OPEN_FLAGS_NOINHERIT); - DosSetFHState (old_out, OPEN_FLAGS_NOINHERIT); + DosSetFHState (old_out, OPEN_FLAGS_NOINHERIT); DosSetFHState (old_err, OPEN_FLAGS_NOINHERIT); if (flags & HAWK_PIO_WRITEIN) @@ -1173,18 +1173,18 @@ create_process: if (os2devnul != HAWK_PIO_HND_NIL) { /* close NUL early as we've duplicated it already */ - DosClose (os2devnul); + DosClose (os2devnul); os2devnul = HAWK_PIO_HND_NIL; } - + /* at this moment, stdin/out/err are already redirected to pipes - * if proper flags have been set. we close them selectively if + * if proper flags have been set. we close them selectively if * dropping is requested */ if (flags & HAWK_PIO_DROPIN) DosClose (std_in); if (flags & HAWK_PIO_DROPOUT) DosClose (std_out); if (flags & HAWK_PIO_DROPERR) DosClose (std_err); - if (flags & HAWK_PIO_SHELL) + if (flags & HAWK_PIO_SHELL) { hawk_oow_t n, mn; @@ -1203,7 +1203,7 @@ create_process: cmd_line = hawk_gem_allocmem(pio->gem, ((11+mn+1+1) * HAWK_SIZEOF(*cmd_line))); if (cmd_line == HAWK_NULL) goto oops; - hawk_copy_bcstr_unlimited (cmd_line, "cmd.exe"); /* cmd.exe\0/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_copy_bcstr_unlimited (&cmd_line[11], cmd); @@ -1218,8 +1218,8 @@ create_process: hawk_gem_convutobcstr (pio->gem, cmd, &n, &cmd_line[11], &mn); } #endif - cmd_line[11+mn+1] = '\0'; /* additional \0 after \0 */ - + cmd_line[11+mn+1] = '\0'; /* additional \0 after \0 */ + cmd_file = "cmd.exe"; } else @@ -1263,7 +1263,7 @@ create_process: * doing better parsing of the command line. */ - /* NOTE: you must separate the command name and the parameters + /* NOTE: you must separate the command name and the parameters * with a space. "pstat.exe /c" is ok while "pstat.exe/c" * is not. */ mptr = hawk_mbspbrk(cmd_line, HAWK_BT(" \t")); @@ -1275,7 +1275,7 @@ create_process: /* execute the command line */ rc = DosExecPgm ( &load_error, - HAWK_SIZEOF(load_error), + HAWK_SIZEOF(load_error), EXEC_ASYNCRESULT, cmd_line, HAWK_NULL, @@ -1295,7 +1295,7 @@ create_process: DosDupHandle (old_err, &std_err); DosClose (old_err); old_err = HAWK_PIO_HND_NIL; - if (rc != NO_ERROR) + if (rc != NO_ERROR) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); goto oops; @@ -1312,7 +1312,7 @@ create_process: if (flags & HAWK_PIO_WRITEIN) { - if (HAWK_PIPE(&handle[0]) <= -1) + if (HAWK_PIPE(&handle[0]) <= -1) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); goto oops; @@ -1322,7 +1322,7 @@ create_process: if (flags & HAWK_PIO_READOUT) { - if (HAWK_PIPE(&handle[2]) <= -1) + if (HAWK_PIPE(&handle[2]) <= -1) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); goto oops; @@ -1333,7 +1333,7 @@ create_process: if (flags & HAWK_PIO_READERR) { - if (HAWK_PIPE(&handle[4]) <= -1) + if (HAWK_PIPE(&handle[4]) <= -1) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(errno)); goto oops; @@ -1342,7 +1342,7 @@ create_process: maxidx = 5; } - if (maxidx == -1) + if (maxidx == -1) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_EINVAL); goto oops; @@ -1360,7 +1360,7 @@ create_process: { #if defined(HAVE_POSIX_SPAWN) && !(defined(HAWK_SYSCALL0) && defined(SYS_vfork)) - if ((pserr = posix_spawn_file_actions_init(&fa)) != 0) + if ((pserr = posix_spawn_file_actions_init(&fa)) != 0) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(pserr)); goto oops; @@ -1370,7 +1370,7 @@ create_process: if (flags & HAWK_PIO_WRITEIN) { /* child should read */ - if ((pserr = posix_spawn_file_actions_addclose(&fa, handle[1])) != 0) + if ((pserr = posix_spawn_file_actions_addclose(&fa, handle[1])) != 0) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(pserr)); goto oops; @@ -1380,7 +1380,7 @@ create_process: hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(pserr)); goto oops; } - if ((pserr = posix_spawn_file_actions_addclose(&fa, handle[0])) != 0) + if ((pserr = posix_spawn_file_actions_addclose(&fa, handle[0])) != 0) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(pserr)); goto oops; @@ -1432,7 +1432,7 @@ create_process: hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(pserr)); goto oops; } - if ((pserr = posix_spawn_file_actions_addclose (&fa, handle[5])) != 0) + if ((pserr = posix_spawn_file_actions_addclose (&fa, handle[5])) != 0) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(pserr)); goto oops; @@ -1471,13 +1471,13 @@ create_process: * just on the best-effort basis. */ if ((flags & HAWK_PIO_DROPIN) && is_fd_valid(0) && - (pserr = posix_spawn_file_actions_addclose (&fa, 0)) != 0) + (pserr = posix_spawn_file_actions_addclose (&fa, 0)) != 0) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(pserr)); goto oops; } if ((flags & HAWK_PIO_DROPOUT) && is_fd_valid(1) && - (pserr = posix_spawn_file_actions_addclose (&fa, 1)) != 0) + (pserr = posix_spawn_file_actions_addclose (&fa, 1)) != 0) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(pserr)); goto oops; @@ -1496,14 +1496,14 @@ create_process: { if (fd != handle[0] && fd != handle[1] && fd != handle[2] && fd != handle[3] && - fd != handle[4] && fd != handle[5]) + fd != handle[4] && fd != handle[5]) { /* closing attempt on a best-effort basis. * posix_spawn() fails if the file descriptor added * with addclose() is closed before posix_spawn(). * addclose() if no FD_CLOEXEC is set or it's unknown. */ - if (is_fd_valid_and_nocloexec(fd) && - (pserr = posix_spawn_file_actions_addclose (&fa, fd)) != 0) + if (is_fd_valid_and_nocloexec(fd) && + (pserr = posix_spawn_file_actions_addclose (&fa, fd)) != 0) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(pserr)); goto oops; @@ -1515,12 +1515,12 @@ create_process: if (make_param (pio, cmd, flags, ¶m) <= -1) goto oops; - /* check if the command(the command requested or /bin/sh) is + /* check if the command(the command requested or /bin/sh) is * exectuable to return an error without trying to execute it * though this check alone isn't sufficient */ if (assert_executable (pio, param.argv[0]) <= -1) { - free_param (pio, ¶m); + free_param (pio, ¶m); goto oops; } @@ -1539,13 +1539,13 @@ create_process: posix_spawnattr_destroy (&psattr); #endif - free_param (pio, ¶m); - if (fa_inited) + free_param (pio, ¶m); + if (fa_inited) { posix_spawn_file_actions_destroy (&fa); fa_inited = 0; } - if (pserr != 0) + if (pserr != 0) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(pserr)); goto oops; @@ -1557,22 +1557,22 @@ create_process: if (make_param (pio, cmd, flags, ¶m) <= -1) goto oops; - /* check if the command(the command requested or /bin/sh) is + /* check if the command(the command requested or /bin/sh) is * exectuable to return an error without trying to execute it * though this check alone isn't sufficient */ if (assert_executable(pio, param.argv[0]) <= -1) { - free_param (pio, ¶m); + free_param (pio, ¶m); goto oops; } /* prepare some data before vforking for vfork limitation. - * the child in vfork should not make function calls or + * the child in vfork should not make function calls or * change data shared with the parent. */ if (!(flags & HAWK_PIO_NOCLOEXEC)) highest_fd = get_highest_fd (pio); HAWK_SYSCALL0 (pid, SYS_vfork); - if (pid <= -1) + if (pid <= -1) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_EINVAL); free_param (pio, ¶m); @@ -1594,13 +1594,13 @@ create_process: int fd = highest_fd; - /* close all other unknown open handles except + /* close all other unknown open handles except * stdin/out/err and the pipes. */ while (fd > 2) { if (fd != handle[0] && fd != handle[1] && fd != handle[2] && fd != handle[3] && - fd != handle[4] && fd != handle[5]) + fd != handle[4] && fd != handle[5]) { HAWK_SYSCALL1 (dummy, SYS_close, fd); } @@ -1701,12 +1701,12 @@ create_process: if (make_param (pio, cmd, flags, ¶m) <= -1) goto oops; - /* check if the command(the command requested or /bin/sh) is + /* check if the command(the command requested or /bin/sh) is * exectuable to return an error without trying to execute it * though this check alone isn't sufficient */ if (assert_executable (pio, param.argv[0]) <= -1) { - free_param (pio, ¶m); + free_param (pio, ¶m); goto oops; } @@ -1726,10 +1726,10 @@ create_process: if (flags & HAWK_PIO_WRITEIN) { - /* + /* * 012345 * rw---- - * X + * X * WRITE => 1 */ HAWK_CLOSE (handle[0]); @@ -1738,7 +1738,7 @@ create_process: if (flags & HAWK_PIO_READOUT) { - /* + /* * 012345 * --rw-- * X @@ -1750,10 +1750,10 @@ create_process: if (flags & HAWK_PIO_READERR) { - /* + /* * 012345 * ----rw - * X + * X * READ => 4 */ HAWK_CLOSE (handle[5]); @@ -1816,7 +1816,7 @@ oops: if (old_in != HAWK_PIO_HND_NIL) { DosDupHandle (old_in, &std_in); - DosClose (old_in); + DosClose (old_in); } if (old_out != HAWK_PIO_HND_NIL) { @@ -1831,7 +1831,7 @@ oops: if (os2devnul != HAWK_PIO_HND_NIL) DosClose (os2devnul); #endif - for (i = 0; i < HAWK_COUNTOF(tio); i++) + for (i = 0; i < HAWK_COUNTOF(tio); i++) { if (tio[i]) hawk_tio_close (tio[i]); } @@ -1839,7 +1839,7 @@ oops: #if defined(_WIN32) for (i = minidx; i < maxidx; i++) CloseHandle (handle[i]); #elif defined(__OS2__) - for (i = minidx; i < maxidx; i++) + for (i = minidx; i < maxidx; i++) { if (handle[i] != HAWK_PIO_HND_NIL) DosClose (handle[i]); } @@ -1847,22 +1847,22 @@ oops: /* DOS not multi-processed. can't support pio */ #elif defined(HAVE_POSIX_SPAWN) && !(defined(HAWK_SYSCALL0) && defined(SYS_vfork)) - if (fa_inited) + if (fa_inited) { posix_spawn_file_actions_destroy (&fa); fa_inited = 0; } - for (i = minidx; i < maxidx; i++) + for (i = minidx; i < maxidx; i++) { if (handle[i] != HAWK_PIO_HND_NIL) HAWK_CLOSE (handle[i]); } #elif defined(HAWK_SYSCALL0) && defined(SYS_vfork) - for (i = minidx; i < maxidx; i++) + for (i = minidx; i < maxidx; i++) { if (handle[i] != HAWK_PIO_HND_NIL) HAWK_CLOSE (handle[i]); } #else - for (i = minidx; i < maxidx; i++) + for (i = minidx; i < maxidx; i++) { if (handle[i] != HAWK_PIO_HND_NIL) HAWK_CLOSE (handle[i]); } @@ -1916,7 +1916,7 @@ static hawk_ooi_t pio_read (hawk_pio_t* pio, void* buf, hawk_oow_t size, hawk_pi hawk_ooi_t n; #endif - if (hnd == HAWK_PIO_HND_NIL) + if (hnd == HAWK_PIO_HND_NIL) { /* the stream is already closed */ hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_ENOHND); @@ -1928,7 +1928,7 @@ static hawk_ooi_t pio_read (hawk_pio_t* pio, void* buf, hawk_oow_t size, hawk_pi if (size > (HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(DWORD))) size = HAWK_TYPE_MAX(hawk_ooi_t) & HAWK_TYPE_MAX(DWORD); - if (ReadFile(hnd, buf, (DWORD)size, &count, HAWK_NULL) == FALSE) + if (ReadFile(hnd, buf, (DWORD)size, &count, HAWK_NULL) == FALSE) { /* ReadFile receives ERROR_BROKEN_PIPE when the write end * is closed in the child process */ @@ -1969,11 +1969,11 @@ static hawk_ooi_t pio_read (hawk_pio_t* pio, void* buf, hawk_oow_t size, hawk_pi reread: n = HAWK_READ(hnd, buf, size); - if (n <= -1) + if (n <= -1) { if (errno == EINTR) { - if (pio->flags & HAWK_PIO_READNORETRY) + if (pio->flags & HAWK_PIO_READNORETRY) hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_EINTR); else goto reread; } @@ -2015,7 +2015,7 @@ static hawk_ooi_t pio_write (hawk_pio_t* pio, const void* data, hawk_oow_t size, hawk_ooi_t n; #endif - if (hnd == HAWK_PIO_HND_NIL) + if (hnd == HAWK_PIO_HND_NIL) { /* the stream is already closed */ hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_ENOHND); @@ -2063,7 +2063,7 @@ static hawk_ooi_t pio_write (hawk_pio_t* pio, const void* data, hawk_oow_t size, rewrite: n = HAWK_WRITE(hnd, data, size); - if (n <= -1) + if (n <= -1) { if (errno == EINTR) { @@ -2135,13 +2135,13 @@ int hawk_pio_wait (hawk_pio_t* pio) DWORD ecode, w; - if (pio->child == HAWK_PIO_PID_NIL) + if (pio->child == HAWK_PIO_PID_NIL) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_ECHILD); return -1; } - w = WaitForSingleObject (pio->child, + w = WaitForSingleObject (pio->child, ((pio->flags & HAWK_PIO_WAITNOBLOCK)? 0: INFINITE) ); if (w == WAIT_TIMEOUT) @@ -2157,19 +2157,19 @@ int hawk_pio_wait (hawk_pio_t* pio) } HAWK_ASSERT (w == WAIT_OBJECT_0); - - if (GetExitCodeProcess(pio->child, &ecode) == FALSE) + + if (GetExitCodeProcess(pio->child, &ecode) == FALSE) { - /* close the handle anyway to prevent further + /* close the handle anyway to prevent further * errors when this function is called again */ hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); - CloseHandle (pio->child); + CloseHandle (pio->child); pio->child = HAWK_PIO_PID_NIL; return -1; } /* close handle here to emulate waitpid() as much as possible. */ - CloseHandle (pio->child); + CloseHandle (pio->child); pio->child = HAWK_PIO_PID_NIL; if (ecode == STILL_ACTIVE) @@ -2189,7 +2189,7 @@ int hawk_pio_wait (hawk_pio_t* pio) RESULTCODES child_rc; PID ppid; - if (pio->child == HAWK_PIO_PID_NIL) + if (pio->child == HAWK_PIO_PID_NIL) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_ECHILD); return -1; @@ -2218,7 +2218,7 @@ int hawk_pio_wait (hawk_pio_t* pio) /*DosClose (pio->child);*/ pio->child = HAWK_PIO_PID_NIL; - return (child_rc.codeTerminate == TC_EXIT)? + return (child_rc.codeTerminate == TC_EXIT)? child_rc.codeResult: (255 + 1 + child_rc.codeTerminate); #elif defined(__DOS__) @@ -2231,7 +2231,7 @@ int hawk_pio_wait (hawk_pio_t* pio) int opt = 0; int ret = -1; - if (pio->child == HAWK_PIO_PID_NIL) + if (pio->child == HAWK_PIO_PID_NIL) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_ECHILD); return -1; @@ -2248,7 +2248,7 @@ int hawk_pio_wait (hawk_pio_t* pio) { if (errno == ECHILD) { - /* most likely, the process has already been + /* most likely, the process has already been * waitpid()ed on. */ pio->child = HAWK_PIO_PID_NIL; } @@ -2261,7 +2261,7 @@ int hawk_pio_wait (hawk_pio_t* pio) break; } - if (n == 0) + if (n == 0) { /* when WNOHANG is not specified, 0 can't be returned */ /*HAWK_ASSERT (pio->flags & HAWK_PIO_WAITNOBLOCK);*/ @@ -2313,7 +2313,7 @@ int hawk_pio_kill (hawk_pio_t* pio) int n; #endif - if (pio->child == HAWK_PIO_PID_NIL) + if (pio->child == HAWK_PIO_PID_NIL) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, HAWK_ECHILD); return -1; @@ -2322,7 +2322,7 @@ int hawk_pio_kill (hawk_pio_t* pio) #if defined(_WIN32) /* 9 was chosen below to treat TerminateProcess as kill -KILL. */ n = TerminateProcess(pio->child, 255 + 1 + 9); - if (n == FALSE) + if (n == FALSE) { hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); return -1; @@ -2337,7 +2337,7 @@ int hawk_pio_kill (hawk_pio_t* pio) hawk_gem_seterrnum (pio->gem, HAWK_NULL, hawk_syserr_to_errnum(rc)); return -1; } - return 0; + return 0; #elif defined(__DOS__) @@ -2353,7 +2353,7 @@ int hawk_pio_kill (hawk_pio_t* pio) static hawk_ooi_t pio_input (hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, hawk_oow_t size) { - if (cmd == HAWK_TIO_DATA) + if (cmd == HAWK_TIO_DATA) { hawk_pio_pin_t* pin = *(hawk_pio_pin_t**)hawk_tio_getxtn(tio); HAWK_ASSERT (pin != HAWK_NULL); @@ -2368,7 +2368,7 @@ static hawk_ooi_t pio_input (hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, haw static hawk_ooi_t pio_output (hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, hawk_oow_t size) { - if (cmd == HAWK_TIO_DATA) + if (cmd == HAWK_TIO_DATA) { hawk_pio_pin_t* pin = *(hawk_pio_pin_t**)hawk_tio_getxtn(tio); HAWK_ASSERT (pin != HAWK_NULL); diff --git a/lib/rbt.c b/lib/rbt.c index 385e59e5..11b16769 100644 --- a/lib/rbt.c +++ b/lib/rbt.c @@ -525,7 +525,7 @@ static hawk_rbt_pair_t* insert (hawk_rbt_t* rbt, void* kptr, hawk_oow_t klen, vo else /* if (n < 0) */ x_cur = x_cur->left; } - if (opt == UPDATE) + if (opt == UPDATE) { hawk_gem_seterrnum (rbt->gem, HAWK_NULL, HAWK_ENOENT); return HAWK_NULL; @@ -848,7 +848,7 @@ static void delete_pair (hawk_rbt_t* rbt, hawk_rbt_pair_t* pair) hawk_rbt_itr_t* itr = rbt->_prot_itr._prot_next; do { - if (itr->pair == pair) + if (itr->pair == pair) { hawk_oow_t seqno = itr->_prot_seqno; @@ -1013,7 +1013,7 @@ hawk_rbt_pair_t* hawk_rbt_getfirstpair (hawk_rbt_t* rbt, hawk_rbt_itr_t* itr) itr->_state = 0; #if defined(HAWK_ENABLE_RBT_ITR_PROTECTION) itr->_prot_seqno = 0; - /* _prot_prev and _prot_next must be left uninitialized because of the way + /* _prot_prev and _prot_next must be left uninitialized because of the way * this function is called in delete_pair() for protection handling */ #endif diff --git a/lib/rec.c b/lib/rec.c index eda41bda..d005fff2 100644 --- a/lib/rec.c +++ b/lib/rec.c @@ -130,7 +130,7 @@ static int split_record (hawk_rtx_t* rtx, int prefer_number) fs_len = ((hawk_val_str_t*)fs)->val.len; fs_free = HAWK_NULL; } - else + else { fs_ptr = hawk_rtx_valtooocstrdup(rtx, fs, &fs_len); if (HAWK_UNLIKELY(!fs_ptr)) return -1; @@ -155,7 +155,7 @@ static int split_record (hawk_rtx_t* rtx, int prefer_number) how = (fs_len <= 1)? 0: 2; } - p = px; + p = px; len = HAWK_OOECS_LEN(&rtx->inrec.line); #if 0 @@ -173,12 +173,12 @@ static int split_record (hawk_rtx_t* rtx, int prefer_number) default: p = hawk_rtx_tokoocharsbyrex( - rtx, + rtx, HAWK_OOECS_PTR(&rtx->inrec.line), HAWK_OOECS_LEN(&rtx->inrec.line), - p, len, + p, len, rtx->gbl.fs[rtx->gbl.ignorecase], &tok - ); + ); if (p == HAWK_NULL && hawk_rtx_geterrnum(rtx) != HAWK_ENOERR) { if (fs_free) hawk_rtx_freemem (rtx, fs_free); @@ -230,7 +230,7 @@ static int split_record (hawk_rtx_t* rtx, int prefer_number) px = HAWK_OOECS_PTR(&rtx->inrec.line); } - p = px; + p = px; len = HAWK_OOECS_LEN(&rtx->inrec.line); #endif @@ -251,12 +251,12 @@ static int split_record (hawk_rtx_t* rtx, int prefer_number) default: /* all other cases */ p = hawk_rtx_tokoocharsbyrex( - rtx, + rtx, HAWK_OOECS_PTR(&rtx->inrec.line), HAWK_OOECS_LEN(&rtx->inrec.line), p, len, rtx->gbl.fs[rtx->gbl.ignorecase], &tok - ); + ); if (p == HAWK_NULL && hawk_rtx_geterrnum(rtx) != HAWK_ENOERR) { if (fs_free) hawk_rtx_freemem (rtx, fs_free); @@ -284,13 +284,13 @@ static int split_record (hawk_rtx_t* rtx, int prefer_number) else nflds = rtx->inrec.nflds * 2; tmp = hawk_rtx_allocmem(rtx, HAWK_SIZEOF(*rtx->inrec.flds) * nflds); - if (tmp == HAWK_NULL) + if (tmp == HAWK_NULL) { if (fs_free) hawk_rtx_freemem (rtx, fs_free); return -1; } - if (rtx->inrec.flds != HAWK_NULL) + if (rtx->inrec.flds != HAWK_NULL) { HAWK_MEMCPY (tmp, rtx->inrec.flds, HAWK_SIZEOF(*rtx->inrec.flds) * rtx->inrec.nflds); hawk_rtx_freemem (rtx, rtx->inrec.flds); @@ -304,7 +304,7 @@ static int split_record (hawk_rtx_t* rtx, int prefer_number) rtx->inrec.flds[rtx->inrec.nflds].ptr = tok.ptr; rtx->inrec.flds[rtx->inrec.nflds].len = tok.len; /*rtx->inrec.flds[rtx->inrec.nflds].val = hawk_rtx_makenstrvalwithoocs(rtx, &tok);*/ - rtx->inrec.flds[rtx->inrec.nflds].val = + rtx->inrec.flds[rtx->inrec.nflds].val = prefer_number? hawk_rtx_makenumorstrvalwithoochars(rtx, tok.ptr, tok.len): hawk_rtx_makestrvalwithoochars(rtx, tok.ptr, tok.len); if (HAWK_UNLIKELY(!rtx->inrec.flds[rtx->inrec.nflds].val)) @@ -326,7 +326,7 @@ static int split_record (hawk_rtx_t* rtx, int prefer_number) if (v == HAWK_NULL) return -1; hawk_rtx_refupval (rtx, v); - if (hawk_rtx_setgbl(rtx, HAWK_GBL_NF, v) <= -1) + if (hawk_rtx_setgbl(rtx, HAWK_GBL_NF, v) <= -1) { hawk_rtx_refdownval (rtx, v); return -1; @@ -350,7 +350,7 @@ int hawk_rtx_clrrec (hawk_rtx_t* rtx, int skip_inrec_line) { HAWK_ASSERT (rtx->inrec.flds != HAWK_NULL); - for (i = 0; i < rtx->inrec.nflds; i++) + for (i = 0; i < rtx->inrec.nflds; i++) { HAWK_ASSERT (rtx->inrec.flds[i].val != HAWK_NULL); hawk_rtx_refdownval (rtx, rtx->inrec.flds[i].val); @@ -359,7 +359,7 @@ int hawk_rtx_clrrec (hawk_rtx_t* rtx, int skip_inrec_line) if (hawk_rtx_setgbl(rtx, HAWK_GBL_NF, HAWK_VAL_ZERO) <= -1) { - /* first of all, this should never happen. + /* first of all, this should never happen. * if it happened, it would return an error * after all the clearance tasks */ n = -1; @@ -377,12 +377,12 @@ static int recomp_record_fields (hawk_rtx_t* rtx, hawk_oow_t lv, const hawk_oocs hawk_val_t* v; hawk_oow_t max, i, nflds; - /* recomposes the record and the fields when $N has been assigned + /* recomposes the record and the fields when $N has been assigned * a new value and recomputes NF accordingly. - * + * * BEGIN { OFS=":" } { $2 = "Q"; print $0; } * If input is abc def xxx, $0 becomes abc:Q:xxx. - * + * * We should store the value in rtx->inrec.line so that the caller * can use it to make a value for $0. */ @@ -443,7 +443,7 @@ static int recomp_record_fields (hawk_rtx_t* rtx, hawk_oow_t lv, const hawk_oocs if (hawk_ooecs_cat(&rtx->inrec.line, HAWK_T("")) == (hawk_oow_t)-1) return -1; - /* hawk_rtx_refdownval should not be called over + /* hawk_rtx_refdownval should not be called over * rtx->inrec.flds[i].val as it is not initialized * to any valid values */ /*hawk_rtx_refdownval (rtx, rtx->inrec.flds[i].val);*/ @@ -475,7 +475,7 @@ static int recomp_record_fields (hawk_rtx_t* rtx, hawk_oow_t lv, const hawk_oocs if (v == HAWK_NULL) return -1; hawk_rtx_refupval (rtx, v); - if (hawk_rtx_setgbl(rtx, HAWK_GBL_NF, v) <= -1) + if (hawk_rtx_setgbl(rtx, HAWK_GBL_NF, v) <= -1) { hawk_rtx_refdownval (rtx, v); return -1; @@ -521,7 +521,7 @@ int hawk_rtx_truncrec (hawk_rtx_t* rtx, hawk_oow_t nflds) ofs_free = ofs_ptr; } } - + if (hawk_ooecs_ncat(&tmp, rtx->inrec.flds[0].ptr, rtx->inrec.flds[0].len) == (hawk_oow_t)-1) goto oops; for (i = 1; i < nflds; i++) { diff --git a/lib/rio-prv.h b/lib/rio-prv.h index 33076c0c..a6547352 100644 --- a/lib/rio-prv.h +++ b/lib/rio-prv.h @@ -45,23 +45,23 @@ hawk_rio_type_t hawk_rtx_intoriotype (hawk_rtx_t* rtx, hawk_in_type_t in_type); hawk_rio_type_t hawk_rtx_outtoriotype (hawk_rtx_t* rtx, hawk_out_type_t out_type); int hawk_rtx_readio ( - hawk_rtx_t* rtx, hawk_in_type_t in_type, + hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* name, hawk_ooecs_t* buf); int hawk_rtx_readiobytes ( - hawk_rtx_t* rtx, hawk_in_type_t in_type, + hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* name, hawk_becs_t* buf); int hawk_rtx_writeioval ( - hawk_rtx_t* rtx, hawk_out_type_t out_type, + hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name, hawk_val_t* v); int hawk_rtx_writeiostr ( - hawk_rtx_t* rtx, hawk_out_type_t out_type, + hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name, hawk_ooch_t* str, hawk_oow_t len); int hawk_rtx_writeiobytes ( - hawk_rtx_t* rtx, hawk_out_type_t out_type, + hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name, hawk_bch_t* str, hawk_oow_t len); int hawk_rtx_flushio ( diff --git a/lib/rio.c b/lib/rio.c index 19a9d649..a57b5ae1 100644 --- a/lib/rio.c +++ b/lib/rio.c @@ -34,7 +34,7 @@ enum io_mask_t static hawk_rio_type_t in_type_map[] = { - /* the order should match the order of the + /* the order should match the order of the * HAWK_IN_XXX values in tree.h */ HAWK_RIO_PIPE, HAWK_RIO_PIPE, @@ -44,7 +44,7 @@ static hawk_rio_type_t in_type_map[] = static int in_mode_map[] = { - /* the order should match the order of the + /* the order should match the order of the * HAWK_IN_XXX values in tree.h */ HAWK_RIO_PIPE_READ, HAWK_RIO_PIPE_RW, @@ -62,7 +62,7 @@ static int in_mask_map[] = static hawk_rio_type_t out_type_map[] = { - /* the order should match the order of the + /* the order should match the order of the * HAWK_OUT_XXX values in tree.h */ HAWK_RIO_PIPE, HAWK_RIO_PIPE, @@ -73,7 +73,7 @@ static hawk_rio_type_t out_type_map[] = static int out_mode_map[] = { - /* the order should match the order of the + /* the order should match the order of the * HAWK_OUT_XXX values in tree.h */ HAWK_RIO_PIPE_WRITE, HAWK_RIO_PIPE_RW, @@ -375,7 +375,7 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* if (find_rio_in(rtx, in_type, name, 0, &p, &handler) <= -1) return -1; if (p->in.eos) return 0; /* no more streams left */ - if (p->in.mbs) + if (p->in.mbs) { if (name[0] == '\0') hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_EPERM, HAWK_T("disallowed mixed mode input")); @@ -454,12 +454,12 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* } else if (rrs.len >= 2) { - /* When RS is multiple characters, it should - * check for the match at the end of the - * input stream also because the previous + /* When RS is multiple characters, it should + * check for the match at the end of the + * input stream also because the previous * match could fail as it didn't end at the * desired position to be the longest match. - * At EOF, the match at the end is considered + * At EOF, the match at the end is considered * the longest as there are no more characters * left */ int n = match_long_rs(rtx, buf, p); @@ -490,7 +490,7 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* /* TODO: handle different line terminator */ /* separate by a new line */ - if (c == HAWK_T('\n')) + if (c == HAWK_T('\n')) { end_pos--; if (pc == HAWK_T('\r')) @@ -505,7 +505,7 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* else { /* CR must have come from the previous - * read. drop CR that must be found at + * read. drop CR that must be found at * the end of the record buffer. */ HAWK_ASSERT (end_pos == start_pos); HAWK_ASSERT (HAWK_OOECS_LEN(buf) > 0); @@ -547,8 +547,8 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* HAWK_ASSERT (line_len > 0); line_len--; - /* we don't drop CR from the record buffer - * if we're in CRLF mode. POINT-X */ + /* we don't drop CR from the record buffer + * if we're in CRLF mode. POINT-X */ if (!(rtx->hawk->opt.trait & HAWK_CRLF)) HAWK_OOECS_LEN(buf) -= 1; } @@ -772,12 +772,12 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_oo } else if (rrs.len >= 2) { - /* When RS is multiple characters, it should - * check for the match at the end of the - * input stream also because the previous + /* When RS is multiple characters, it should + * check for the match at the end of the + * input stream also because the previous * match could fail as it didn't end at the * desired position to be the longest match. - * At EOF, the match at the end is considered + * At EOF, the match at the end is considered * the longest as there are no more characters * left */ int n = match_long_brs(rtx, buf, p); @@ -808,7 +808,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_oo /* TODO: handle different line terminator */ /* separate by a new line */ - if (c == '\n') + if (c == '\n') { end_pos--; if (pc == '\r') @@ -823,7 +823,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_oo else { /* CR must have come from the previous - * read. drop CR that must be found at + * read. drop CR that must be found at * the end of the record buffer. */ HAWK_ASSERT (end_pos == start_pos); HAWK_ASSERT (HAWK_BECS_LEN(buf) > 0); @@ -865,7 +865,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_oo HAWK_ASSERT (line_len > 0); line_len--; - /* we don't drop CR from the record buffer + /* we don't drop CR from the record buffer * if we're in CRLF mode. POINT-X */ if (!(rtx->hawk->opt.trait & HAWK_CRLF)) HAWK_BECS_LEN(buf) -= 1; @@ -1068,7 +1068,7 @@ static int prepare_for_write_io_data (hawk_rtx_t* rtx, hawk_out_type_t out_type, /* look for the corresponding rio for name */ while (p) { - /* the file "1.tmp", in the following code snippets, + /* the file "1.tmp", in the following code snippets, * would be opened by the first print statement, but not by * the second print statement. this is because * both HAWK_OUT_FILE and HAWK_OUT_APFILE are @@ -1144,7 +1144,7 @@ int hawk_rtx_writeiostr (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_o n = wid.handler(rtx, HAWK_RIO_CMD_WRITE, wid.p, str, len); if (n <= -1) return -1; - if (n == 0) + if (n == 0) { wid.p->out.eof = 1; return 0; @@ -1171,7 +1171,7 @@ int hawk_rtx_writeiobytes (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk n = wid.handler(rtx, HAWK_RIO_CMD_WRITE_BYTES, wid.p, str, len); if (n <= -1) return -1; - if (n == 0) + if (n == 0) { wid.p->out.eof = 1; return 0; @@ -1217,7 +1217,7 @@ int hawk_rtx_flushio (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch * same entry since (io_type | io_mask) has the same value * for both. */ if (p->type == (io_type | io_mask) && p->mode == io_mode && - (name == HAWK_NULL || hawk_comp_oocstr(p->name, name, 0) == 0)) + (name == HAWK_NULL || hawk_comp_oocstr(p->name, name, 0) == 0)) { n = handler(rtx, HAWK_RIO_CMD_FLUSH, p, HAWK_NULL, 0); if (n <= -1) return -1; @@ -1238,7 +1238,7 @@ int hawk_rtx_nextio_read (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_oo { hawk_rio_arg_t* p = rtx->rio.chain; hawk_rio_impl_t handler; - int io_type, /*io_mode,*/ io_mask; + int io_type, /*io_mode,*/ io_mask; hawk_ooi_t n; HAWK_ASSERT (in_type >= 0 && in_type <= HAWK_COUNTOF(in_type_map)); @@ -1272,7 +1272,7 @@ int hawk_rtx_nextio_read (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_oo return -1; } - if (p->in.eos) + if (p->in.eos) { /* no more streams. */ return 0; @@ -1281,15 +1281,15 @@ int hawk_rtx_nextio_read (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_oo n = handler(rtx, HAWK_RIO_CMD_NEXT, p, HAWK_NULL, 0); if (n <= -1) return -1; - if (n == 0) + if (n == 0) { - /* the next stream cannot be opened. + /* the next stream cannot be opened. * set the EOS flags so that the next call to nextio_read * will return 0 without executing the handler */ p->in.eos = 1; return 0; } - else + else { /* as the next stream has been opened successfully, * the EOF flag should be cleared if set */ @@ -1307,7 +1307,7 @@ int hawk_rtx_nextio_write (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk { hawk_rio_arg_t* p = rtx->rio.chain; hawk_rio_impl_t handler; - int io_type, /*io_mode,*/ io_mask; + int io_type, /*io_mode,*/ io_mask; hawk_ooi_t n; HAWK_ASSERT (out_type >= 0 && out_type <= HAWK_COUNTOF(out_type_map)); @@ -1342,7 +1342,7 @@ int hawk_rtx_nextio_write (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk return -1; } - if (p->out.eos) + if (p->out.eos) { /* no more streams. */ return 0; @@ -1351,15 +1351,15 @@ int hawk_rtx_nextio_write (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk n = handler(rtx, HAWK_RIO_CMD_NEXT, p, HAWK_NULL, 0); if (n <= -1) return -1; - if (n == 0) + if (n == 0) { - /* the next stream cannot be opened. + /* the next stream cannot be opened. * set the EOS flags so that the next call to nextio_write * will return 0 without executing the handler */ p->out.eos = 1; return 0; } - else + else { /* as the next stream has been opened successfully, * the EOF flag should be cleared if set */ @@ -1393,7 +1393,7 @@ int hawk_rtx_closio_read (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_oo while (p) { - if (p->type == (io_type | io_mask) && hawk_comp_oocstr(p->name, name, 0) == 0) + if (p->type == (io_type | io_mask) && hawk_comp_oocstr(p->name, name, 0) == 0) { hawk_rio_impl_t handler; @@ -1450,7 +1450,7 @@ int hawk_rtx_closio_write (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk while (p) { - if (p->type == (io_type | io_mask) && hawk_comp_oocstr(p->name, name, 0) == 0) + if (p->type == (io_type | io_mask) && hawk_comp_oocstr(p->name, name, 0) == 0) { hawk_rio_impl_t handler; @@ -1481,7 +1481,7 @@ int hawk_rtx_closeio (hawk_rtx_t* rtx, const hawk_ooch_t* name, const hawk_ooch_ { /* it handles the first that matches the given name * regardless of the io type */ - if (hawk_comp_oocstr(p->name, name, 0) == 0) + if (hawk_comp_oocstr(p->name, name, 0) == 0) { hawk_rio_impl_t handler; hawk_rio_rwcmode_t rwcmode = HAWK_RIO_CMD_CLOSE_FULL; @@ -1490,7 +1490,7 @@ int hawk_rtx_closeio (hawk_rtx_t* rtx, const hawk_ooch_t* name, const hawk_ooch_ { if (opt[0] == HAWK_T('r')) { - if (p->type & IO_MASK_RDWR) + if (p->type & IO_MASK_RDWR) { if (p->rwcstate != HAWK_RIO_CMD_CLOSE_WRITE) { @@ -1509,7 +1509,7 @@ int hawk_rtx_closeio (hawk_rtx_t* rtx, const hawk_ooch_t* name, const hawk_ooch_ { if (p->rwcstate != HAWK_RIO_CMD_CLOSE_READ) { - /* if the read end is not + /* if the read end is not * closed, let io handler close * the write end only. */ rwcmode = HAWK_RIO_CMD_CLOSE_WRITE; @@ -1530,14 +1530,14 @@ int hawk_rtx_closeio (hawk_rtx_t* rtx, const hawk_ooch_t* name, const hawk_ooch_ } } - if (p->type & IO_MASK_RDWR) + if (p->type & IO_MASK_RDWR) { p->rwcmode = rwcmode; if (p->rwcstate == 0 && rwcmode != 0) { /* if either end has not been closed. - * return success without destroying - * the internal node. rwcstate keeps + * return success without destroying + * the internal node. rwcstate keeps * what has been successfully closed */ p->rwcstate = rwcmode; return 0; diff --git a/lib/run-prv.h b/lib/run-prv.h index bb0f13c2..a7e23e78 100644 --- a/lib/run-prv.h +++ b/lib/run-prv.h @@ -28,13 +28,13 @@ enum hawk_assop_type_t { /* if you change this, you have to change assop_str in tree.c. - * synchronize it wit: - * - binop_func in eval_assignment of run.c + * synchronize it wit: + * - binop_func in eval_assignment of run.c * - assop in assing_to_opcode of parse.c * - TOK_XXX_ASSN in tok_t in parse.c * - assop_str in tree.c */ - HAWK_ASSOP_NONE, + HAWK_ASSOP_NONE, HAWK_ASSOP_PLUS, /* += */ HAWK_ASSOP_MINUS, /* -= */ HAWK_ASSOP_MUL, /* *= */ @@ -52,8 +52,8 @@ enum hawk_assop_type_t enum hawk_binop_type_t { - /* if you change this, you have to change - * binop_str in tree.c and binop_func in run.c accordingly. */ + /* if you change this, you have to change + * binop_str in tree.c and binop_func in run.c accordingly. */ HAWK_BINOP_LOR, HAWK_BINOP_LAND, HAWK_BINOP_IN, @@ -89,8 +89,8 @@ enum hawk_binop_type_t enum hawk_unrop_type_t { - /* if you change this, you have to change - * __unrop_str in tree.c accordingly. */ + /* if you change this, you have to change + * __unrop_str in tree.c accordingly. */ HAWK_UNROP_PLUS, HAWK_UNROP_MINUS, HAWK_UNROP_LNOT, @@ -99,8 +99,8 @@ enum hawk_unrop_type_t enum hawk_incop_type_t { - /* if you change this, you have to change - * __incop_str in tree.c accordingly. */ + /* if you change this, you have to change + * __incop_str in tree.c accordingly. */ HAWK_INCOP_PLUS, HAWK_INCOP_MINUS }; @@ -111,23 +111,23 @@ extern "C" { hawk_ooch_t* hawk_rtx_format ( hawk_rtx_t* rtx, - hawk_ooecs_t* out, + hawk_ooecs_t* out, hawk_ooecs_t* fbu, - const hawk_ooch_t* fmt, - hawk_oow_t fmt_len, - hawk_oow_t nargs_on_stack, - hawk_nde_t* args, + const hawk_ooch_t* fmt, + hawk_oow_t fmt_len, + hawk_oow_t nargs_on_stack, + hawk_nde_t* args, hawk_oow_t* len ); hawk_bch_t* hawk_rtx_formatmbs ( hawk_rtx_t* rtx, - hawk_becs_t* out, + hawk_becs_t* out, hawk_becs_t* fbu, - const hawk_bch_t* fmt, - hawk_oow_t fmt_len, - hawk_oow_t nargs_on_stack, - hawk_nde_t* args, + const hawk_bch_t* fmt, + hawk_oow_t fmt_len, + hawk_oow_t nargs_on_stack, + hawk_nde_t* args, hawk_oow_t* len ); @@ -141,8 +141,8 @@ int hawk_rtx_cmpval ( hawk_val_t* hawk_rtx_evalcall ( hawk_rtx_t* rtx, - hawk_nde_fncall_t* call, - hawk_fun_t* fun, + hawk_nde_fncall_t* call, + hawk_fun_t* fun, hawk_oow_t(*argpusher)(hawk_rtx_t*,hawk_nde_fncall_t*,void*), void* apdata, /* data to argpusher */ void(*errhandler)(void*), diff --git a/lib/run.c b/lib/run.c index 357e51c6..8572e722 100644 --- a/lib/run.c +++ b/lib/run.c @@ -240,7 +240,7 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t } else if (!assign && old_vtype == vtype) { - /* when both are maps, how should this operation be + /* when both are maps, how should this operation be * interpreted? * * is it an assignment? @@ -264,7 +264,7 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t } else { - if (old_vtype == HAWK_VAL_MAP || old_vtype == HAWK_VAL_ARR) + if (old_vtype == HAWK_VAL_MAP || old_vtype == HAWK_VAL_ARR) { errnum = HAWK_ENONSCATOSCALAR; errfmt = HAWK_T("not allowed to change a nonscalar value in '%.*js' to a scalar value"); @@ -273,7 +273,7 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t if (errnum != HAWK_ENOERR) { - /* once a variable becomes a map, it cannot be assigned + /* once a variable becomes a map, it cannot be assigned * others value than another map. you can only add a member * using indexing. */ if (var) @@ -297,9 +297,9 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t { if (idx >= HAWK_MIN_GBL_ID && idx <= HAWK_MAX_GBL_ID) { - /* short-circuit check block to prevent the basic built-in + /* short-circuit check block to prevent the basic built-in * variables from being assigned a map. if you happen to add - * one and if that's allowed to be a map, you may have to + * one and if that's allowed to be a map, you may have to * change the condition here. */ /* TODO: use global variable attribute. can it be a map? can it be a scalar? is it read-only???? */ @@ -317,7 +317,7 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t * note that several inspections have been performed before this check, * mainly for consistency. anyway, this condition can be met if you execute * a statement like 'ARGV=ARGV'. */ - return 0; + return 0; } /* perform actual assignment or assignment-like operation */ @@ -359,13 +359,13 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t rtx->gbl.fnr = lv; break; } - + case HAWK_GBL_FS: { hawk_ooch_t* fs_ptr; hawk_oow_t fs_len; - /* due to the expression evaluation rule, the + /* due to the expression evaluation rule, the * regular expression can not be an assigned value */ HAWK_ASSERT (vtype != HAWK_VAL_REX); @@ -404,9 +404,9 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t vt = hawk_rtx_valtonum(rtx, val, &l, &r); if (vt <= -1) return -1; - if (vt == 0) + if (vt == 0) rtx->gbl.ignorecase = ((l > 0)? 1: (l < 0)? -1: 0); - else + else rtx->gbl.ignorecase = ((r > 0.0)? 1: (r < 0.0)? -1: 0); break; } @@ -432,7 +432,7 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t * it has to rebuil $X values with the current OFS value. * { OFS=":"; NF=NF; print $0; } * the NF=value assignment is indicated by a non-zero value in the 'assign' variable. - * 'assign' is 0 if this function is called from a different context such as + * 'assign' is 0 if this function is called from a different context such as * explicit call to hawk_rtx_setgbl(). */ @@ -451,10 +451,10 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t if (hawk_rtx_setrec(rtx, lv, &cs, 0) <= -1) return -1; } - /* for all other globals, it returns before this switch/case block is reached + /* for all other globals, it returns before this switch/case block is reached * if the same value is assigned. but NF change requires extra action to take * as coded before this switch/case block. */ - if (old == val) return 0; + if (old == val) return 0; break; } @@ -481,9 +481,9 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t vt = hawk_rtx_valtonum(rtx, val, &l, &r); if (vt <= -1) return -1; - if (vt == 0) + if (vt == 0) rtx->gbl.numstrdetect = ((l > 0)? 1: (l < 0)? -1: 0); - else + else rtx->gbl.numstrdetect = ((r > 0.0)? 1: (r < 0.0)? -1: 0); break; } @@ -527,7 +527,7 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t } case HAWK_GBL_ORS: - { + { hawk_oocs_t str; str.ptr = hawk_rtx_valtooocstrdup(rtx, val, &str.len); @@ -544,8 +544,8 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t { hawk_oocs_t rss; - /* due to the expression evaluation rule, the - * regular expression can not be an assigned + /* due to the expression evaluation rule, the + * regular expression can not be an assigned * value */ HAWK_ASSERT (vtype != HAWK_VAL_REX); @@ -587,9 +587,9 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t vt = hawk_rtx_valtonum(rtx, val, &l, &r); if (vt <= -1) return -1; - if (vt == 0) + if (vt == 0) rtx->gbl.striprecspc = ((l > 0)? 1: (l < 0)? -1: 0); - else + else rtx->gbl.striprecspc = ((r > 0.0)? 1: (r < 0.0)? -1: 0); break; } @@ -603,9 +603,9 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t vt = hawk_rtx_valtonum(rtx, val, &l, &r); if (vt <= -1) return -1; - if (vt == 0) + if (vt == 0) rtx->gbl.stripstrspc = ((l > 0)? 1: (l < 0)? -1: 0); - else + else rtx->gbl.stripstrspc = ((r > 0.0)? 1: (r < 0.0)? -1: 0); break; } @@ -827,7 +827,7 @@ static hawk_rbt_walk_t fini_module (hawk_rbt_t* rbt, hawk_rbt_pair_t* pair, void mfc = (struct module_fini_ctx_t*)ctx; - if (mfc->limit > 0 && mfc->count >= mfc->limit) + if (mfc->limit > 0 && mfc->count >= mfc->limit) return HAWK_RBT_WALK_STOP; md = (hawk_mod_data_t*)HAWK_RBT_VPTR(pair); @@ -847,7 +847,7 @@ hawk_rtx_t* hawk_rtx_open (hawk_t* hawk, hawk_oow_t xtnsize, hawk_rio_cbs_t* rio hawk_seterrnum (hawk, HAWK_NULL, HAWK_ENOERR); /* check if the code has ever been parsed */ - if (hawk->tree.ngbls == 0 && + if (hawk->tree.ngbls == 0 && hawk->tree.begin == HAWK_NULL && hawk->tree.end == HAWK_NULL && hawk->tree.chain_size == 0 && @@ -856,7 +856,7 @@ hawk_rtx_t* hawk_rtx_open (hawk_t* hawk, hawk_oow_t xtnsize, hawk_rio_cbs_t* rio hawk_seterrnum (hawk, HAWK_NULL, HAWK_EPERM); return HAWK_NULL; } - + /* allocate the storage for the rtx object */ rtx = (hawk_rtx_t*)hawk_allocmem(hawk, HAWK_SIZEOF(hawk_rtx_t) + xtnsize); if (HAWK_UNLIKELY(!rtx)) @@ -868,12 +868,12 @@ hawk_rtx_t* hawk_rtx_open (hawk_t* hawk, hawk_oow_t xtnsize, hawk_rio_cbs_t* rio /* initialize the rtx object */ HAWK_MEMSET (rtx, 0, HAWK_SIZEOF(hawk_rtx_t) + xtnsize); rtx->_instsize = HAWK_SIZEOF(hawk_rtx_t); - if (HAWK_UNLIKELY(init_rtx(rtx, hawk, rio) <= -1)) + if (HAWK_UNLIKELY(init_rtx(rtx, hawk, rio) <= -1)) { - /* because the error information is in the gem part, + /* because the error information is in the gem part, * it should be ok to copy over rtx error to hawk even if * rtx initialization fails. */ - hawk_rtx_errortohawk (rtx, hawk); + hawk_rtx_errortohawk (rtx, hawk); hawk_freemem (hawk, rtx); return HAWK_NULL; } @@ -951,7 +951,7 @@ void hawk_rtx_close (hawk_rtx_t* rtx) /* NOTE: * the close callbacks are called before data in rtx * is destroyed. if the destruction count on any data - * destroyed by the close callback, something bad + * destroyed by the close callback, something bad * will happen. */ fini_rtx (rtx, 1); @@ -1029,11 +1029,11 @@ static int init_rtx (hawk_rtx_t* rtx, hawk_t* hawk, hawk_rio_cbs_t* rio) { { HAWK_HTB_COPIER_INLINE, - HAWK_HTB_COPIER_DEFAULT + HAWK_HTB_COPIER_DEFAULT }, { HAWK_HTB_FREEER_DEFAULT, - free_namedval + free_namedval }, HAWK_HTB_COMPER_DEFAULT, same_namedval, @@ -1102,7 +1102,7 @@ static int init_rtx (hawk_rtx_t* rtx, hawk_t* hawk, hawk_rio_cbs_t* rio) *(hawk_rtx_t**)hawk_htb_getxtn(rtx->named) = rtx; hawk_htb_setstyle (rtx->named, &style_for_named); - rtx->format.tmp.ptr = (hawk_ooch_t*)hawk_rtx_allocmem(rtx, 4096 * HAWK_SIZEOF(hawk_ooch_t)); + rtx->format.tmp.ptr = (hawk_ooch_t*)hawk_rtx_allocmem(rtx, 4096 * HAWK_SIZEOF(hawk_ooch_t)); if (HAWK_UNLIKELY(!rtx->format.tmp.ptr)) goto oops_12; /* the error is set on the hawk object after this jump is made */ rtx->format.tmp.len = 4096; rtx->format.tmp.inc = 4096 * 2; @@ -1213,7 +1213,7 @@ static void fini_rtx (hawk_rtx_t* rtx, int fini_globals) rtx->gbl.convfmt.len = 0; } - if (rtx->gbl.ofmt.ptr != HAWK_NULL && + if (rtx->gbl.ofmt.ptr != HAWK_NULL && rtx->gbl.ofmt.ptr != DEFAULT_OFMT) { hawk_rtx_freemem (rtx, rtx->gbl.ofmt.ptr); @@ -1221,7 +1221,7 @@ static void fini_rtx (hawk_rtx_t* rtx, int fini_globals) rtx->gbl.ofmt.len = 0; } - if (rtx->gbl.ofs.ptr != HAWK_NULL && + if (rtx->gbl.ofs.ptr != HAWK_NULL && rtx->gbl.ofs.ptr != DEFAULT_OFS) { hawk_rtx_freemem (rtx, rtx->gbl.ofs.ptr); @@ -1229,7 +1229,7 @@ static void fini_rtx (hawk_rtx_t* rtx, int fini_globals) rtx->gbl.ofs.len = 0; } - if (rtx->gbl.ors.ptr != HAWK_NULL && + if (rtx->gbl.ors.ptr != HAWK_NULL && rtx->gbl.ors.ptr != DEFAULT_ORS && rtx->gbl.ors.ptr != DEFAULT_ORS_CRLF) { @@ -1238,7 +1238,7 @@ static void fini_rtx (hawk_rtx_t* rtx, int fini_globals) rtx->gbl.ors.len = 0; } - if (rtx->gbl.subsep.ptr != HAWK_NULL && + if (rtx->gbl.subsep.ptr != HAWK_NULL && rtx->gbl.subsep.ptr != DEFAULT_SUBSEP) { hawk_rtx_freemem (rtx, rtx->gbl.subsep.ptr); @@ -1264,7 +1264,7 @@ static void fini_rtx (hawk_rtx_t* rtx, int fini_globals) /* destroy input record. hawk_rtx_clrrec() should be called * before the stack has been destroyed because it may try * to change the value to HAWK_GBL_NF. */ - hawk_rtx_clrrec (rtx, 0); + hawk_rtx_clrrec (rtx, 0); if (rtx->inrec.flds) { hawk_rtx_freemem (rtx, rtx->inrec.flds); @@ -1367,7 +1367,7 @@ oops: return n; } -/* +/* * create global variables into the runtime stack * each variable is initialized to nil or zero. */ @@ -1410,7 +1410,7 @@ static int prepare_globals (hawk_rtx_t* rtx) /* * assign initial values to the global variables whose desired initial - * values are not nil or zero. some are handled in prepare_globals () and + * values are not nil or zero. some are handled in prepare_globals () and * update_fnr(). */ static int defaultify_globals (hawk_rtx_t* rtx) @@ -1444,12 +1444,12 @@ static int defaultify_globals (hawk_rtx_t* rtx) { tmp = hawk_val_zls; } - else + else { tmp = hawk_rtx_makestrvalwithoocstr (rtx, gtab[i].str[stridx]); if (tmp == HAWK_NULL) return -1; } - + hawk_rtx_refupval (rtx, tmp); HAWK_ASSERT (HAWK_RTX_STACK_GBL(rtx,gtab[i].idx) == hawk_val_nil); @@ -1474,7 +1474,7 @@ static int defaultify_globals (hawk_rtx_t* rtx) static void refdown_globals (hawk_rtx_t* rtx, int pop) { hawk_oow_t ngbls; - + ngbls = rtx->hawk->tree.ngbls; while (ngbls > 0) { @@ -1489,7 +1489,7 @@ static int init_globals (hawk_rtx_t* rtx) { /* the stack must be clean when this function is invoked */ HAWK_ASSERT (rtx->stack_base == 0); - HAWK_ASSERT (rtx->stack_top == 0); + HAWK_ASSERT (rtx->stack_top == 0); if (prepare_globals(rtx) <= -1) return -1; if (update_fnr(rtx, 0, 0) <= -1 || defaultify_globals(rtx) <= -1) goto oops; @@ -1527,7 +1527,7 @@ static hawk_val_t* run_bpae_loop (hawk_rtx_t* rtx) HAWK_RTX_STACK_NARGS(rtx) = (void*)nargs; /* execute the BEGIN block */ - for (nde = rtx->hawk->tree.begin; + for (nde = rtx->hawk->tree.begin; ret == 0 && nde != HAWK_NULL && rtx->exit_level < EXIT_GLOBAL; nde = nde->next) { @@ -1541,20 +1541,20 @@ static hawk_val_t* run_bpae_loop (hawk_rtx_t* rtx) if (run_block(rtx, blk) <= -1) ret = -1; } - if (ret <= -1 && hawk_rtx_geterrnum(rtx) == HAWK_ENOERR) + if (ret <= -1 && hawk_rtx_geterrnum(rtx) == HAWK_ENOERR) { /* an error is returned with no error number set. * this trait is used by eval_expression() to - * abort the evaluation when exit() is executed + * abort the evaluation when exit() is executed * during function evaluation */ ret = 0; CLRERR (rtx); /* clear it just in case */ } /* run pattern block loops */ - if (ret == 0 && + if (ret == 0 && (rtx->hawk->tree.chain != HAWK_NULL || - rtx->hawk->tree.end != HAWK_NULL) && + rtx->hawk->tree.end != HAWK_NULL) && rtx->exit_level < EXIT_GLOBAL) { if (run_pblocks(rtx) <= -1) ret = -1; @@ -1564,17 +1564,17 @@ static hawk_val_t* run_bpae_loop (hawk_rtx_t* rtx) { /* an error is returned with no error number set. * this trait is used by eval_expression() to - * abort the evaluation when exit() is executed + * abort the evaluation when exit() is executed * during function evaluation */ ret = 0; CLRERR (rtx); /* clear it just in case */ } - /* execute END blocks. the first END block is executed if the + /* execute END blocks. the first END block is executed if the * program is not explicitly aborted with hawk_rtx_halt().*/ for (nde = rtx->hawk->tree.end; ret == 0 && nde != HAWK_NULL && rtx->exit_level < EXIT_ABORT; - nde = nde->next) + nde = nde->next) { hawk_nde_blk_t* blk; @@ -1584,7 +1584,7 @@ static hawk_val_t* run_bpae_loop (hawk_rtx_t* rtx) rtx->active_block = blk; rtx->exit_level = EXIT_NONE; if (run_block(rtx, blk) <= -1) ret = -1; - else if (rtx->exit_level >= EXIT_GLOBAL) + else if (rtx->exit_level >= EXIT_GLOBAL) { /* once exit is called inside one of END blocks, * subsequent END blocks must not be executed */ @@ -1596,18 +1596,18 @@ static hawk_val_t* run_bpae_loop (hawk_rtx_t* rtx) { /* an error is returned with no error number set. * this trait is used by eval_expression() to - * abort the evaluation when exit() is executed + * abort the evaluation when exit() is executed * during function evaluation */ ret = 0; CLRERR (rtx); /* clear it just in case */ } - /* derefrence all arguments. however, there should be no arguments + /* derefrence all arguments. however, there should be no arguments * pushed to the stack as asserted below. we didn't push any arguments * for BEGIN/pattern action/END block execution.*/ nargs = (hawk_oow_t)HAWK_RTX_STACK_NARGS(rtx); HAWK_ASSERT (nargs == 0); - for (i = 0; i < nargs; i++) + for (i = 0; i < nargs; i++) hawk_rtx_refdownval (rtx, HAWK_RTX_STACK_ARG(rtx,i)); /* get the return value in the current stack frame */ @@ -1635,7 +1635,7 @@ hawk_val_t* hawk_rtx_loop (hawk_rtx_t* rtx) if (HAWK_UNLIKELY(HAWK_RTX_STACK_AVAIL(rtx) < 4)) { - /* restore the stack top in a cheesy(?) way. + /* restore the stack top in a cheesy(?) way. * it is ok to do so as the values pushed are * nils and binary numbers. */ hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ESTACK); @@ -1791,7 +1791,7 @@ hawk_val_t* hawk_rtx_callfun (hawk_rtx_t* rtx, hawk_fun_t* fun, hawk_val_t* args /* check if the number of arguments given is more than expected */ if (nargs > fun->nargs && !fun->variadic) { - /* TODO: is this correct? what if i want to + /* TODO: is this correct? what if i want to * allow arbitrary numbers of arguments? */ hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_EARGTM, HAWK_T("too many arguments to '%.*js'"), fun->name.len, fun->name.ptr); return HAWK_NULL; @@ -1872,7 +1872,7 @@ hawk_val_t* hawk_rtx_callwithucstrarr (hawk_rtx_t* rtx, const hawk_uch_t* name, ret = hawk_rtx_callwithucstr(rtx, name, v, nargs); oops: - while (i > 0) + while (i > 0) { hawk_rtx_refdownval (rtx, v[--i]); } @@ -1903,7 +1903,7 @@ hawk_val_t* hawk_rtx_callwithbcstrarr (hawk_rtx_t* rtx, const hawk_bch_t* name, ret = hawk_rtx_callwithbcstr(rtx, name, v, nargs); oops: - while (i > 0) + while (i > 0) { hawk_rtx_refdownval (rtx, v[--i]); } @@ -1934,7 +1934,7 @@ hawk_val_t* hawk_rtx_callwithooucstrarr (hawk_rtx_t* rtx, const hawk_ooch_t* nam ret = hawk_rtx_callwithoocstr(rtx, name, v, nargs); oops: - while (i > 0) + while (i > 0) { hawk_rtx_refdownval (rtx, v[--i]); } @@ -1965,7 +1965,7 @@ hawk_val_t* hawk_rtx_callwithoobcstrarr (hawk_rtx_t* rtx, const hawk_ooch_t* nam ret = hawk_rtx_callwithoocstr(rtx, name, v, nargs); oops: - while (i > 0) + while (i > 0) { hawk_rtx_refdownval (rtx, v[--i]); } @@ -1988,7 +1988,7 @@ static int run_pblocks (hawk_rtx_t* rtx) else if (rtx->hawk->tree.end != HAWK_NULL) \ { \ ADJERR_LOC (run, &rtx->hawk->tree.end->loc); \ - } + } rtx->inrec.buf_pos = 0; rtx->inrec.buf_len = 0; @@ -2000,7 +2000,7 @@ static int run_pblocks (hawk_rtx_t* rtx) rtx->exit_level = EXIT_NONE; n = read_record(rtx); - if (n <= -1) + if (n <= -1) { ADJUST_ERROR (rtx); return -1; /* error */ @@ -2160,7 +2160,7 @@ static HAWK_INLINE int run_block0 (hawk_rtx_t* rtx, hawk_nde_blk_t* nde) hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_ESTACK); return -1; } - + do { --tmp; @@ -2181,8 +2181,8 @@ static HAWK_INLINE int run_block0 (hawk_rtx_t* rtx, hawk_nde_blk_t* nde) */ hawk_oow_t tmp, end; - /* when the outer-most block has been entered, the space large enough for all local - * variables defined has been secured. nullify part of the stack to initialze local + /* when the outer-most block has been entered, the space large enough for all local + * variables defined has been secured. nullify part of the stack to initialze local * variables defined for a nested block */ end = nde->outer_nlcls + nde->org_nlcls; for (tmp = nde->outer_nlcls; tmp < end; tmp++) @@ -2262,7 +2262,7 @@ static int run_statement (hawk_rtx_t* rtx, hawk_nde_t* nde) ON_STATEMENT (rtx, nde); - switch (nde->type) + switch (nde->type) { case HAWK_NDE_NULL: /* do nothing */ @@ -2354,7 +2354,7 @@ static int run_if (hawk_rtx_t* rtx, hawk_nde_if_t* nde) hawk_val_t* test; int n = 0; - /* the test expression for the if statement cannot have + /* the test expression for the if statement cannot have * chained expressions. this should not be allowed by the * parser first of all */ HAWK_ASSERT (nde->test->next == HAWK_NULL); @@ -2382,7 +2382,7 @@ static int run_while (hawk_rtx_t* rtx, hawk_nde_while_t* nde) if (nde->type == HAWK_NDE_WHILE) { - /* no chained expressions are allowed for the test + /* no chained expressions are allowed for the test * expression of the while statement */ HAWK_ASSERT (nde->test->next == HAWK_NULL); @@ -2426,7 +2426,7 @@ static int run_while (hawk_rtx_t* rtx, hawk_nde_while_t* nde) } else if (nde->type == HAWK_NDE_DOWHILE) { - /* no chained expressions are allowed for the test + /* no chained expressions are allowed for the test * expression of the while statement */ HAWK_ASSERT (nde->test->next == HAWK_NULL); @@ -2512,7 +2512,7 @@ static int run_for (hawk_rtx_t* rtx, hawk_nde_for_t* nde) } hawk_rtx_refdownval (rtx, test); - } + } else { if (run_statement(rtx,nde->body) <= -1) return -1; @@ -2550,14 +2550,14 @@ static int run_forin (hawk_rtx_t* rtx, hawk_nde_forin_t* nde) hawk_nde_exp_t* test; hawk_val_t* rv; hawk_val_type_t rvtype; - + int ret; - + test = (hawk_nde_exp_t*)nde->test; HAWK_ASSERT (test->type == HAWK_NDE_EXP_BIN && test->opcode == HAWK_BINOP_IN); /* chained expressions should not be allowed by the parser first of all */ - HAWK_ASSERT (test->right->next == HAWK_NULL); + HAWK_ASSERT (test->right->next == HAWK_NULL); rv = eval_expression(rtx, test->right); if (HAWK_UNLIKELY(!rv)) return -1; @@ -2590,7 +2590,7 @@ static int run_forin (hawk_rtx_t* rtx, hawk_nde_forin_t* nde) newcapa = rtx->forin.size + hawk_map_getsize(map); newcapa = HAWK_ALIGN_POW2(newcapa, 128); tmp = hawk_rtx_reallocmem(rtx, rtx->forin.ptr, newcapa * HAWK_SIZEOF(*tmp)); - if (HAWK_UNLIKELY(!tmp)) + if (HAWK_UNLIKELY(!tmp)) { ADJERR_LOC (rtx, &test->left->loc); ret = -1; @@ -2610,7 +2610,7 @@ static int run_forin (hawk_rtx_t* rtx, hawk_nde_forin_t* nde) hawk_val_t* str; str = (hawk_val_t*)hawk_rtx_makenstrvalwithoochars(rtx, HAWK_HTB_KPTR(pair), HAWK_HTB_KLEN(pair)); - if (HAWK_UNLIKELY(!str)) + if (HAWK_UNLIKELY(!str)) { ADJERR_LOC (rtx, &test->left->loc); ret = -1; @@ -2641,7 +2641,7 @@ static int run_forin (hawk_rtx_t* rtx, hawk_nde_forin_t* nde) { rtx->exit_level = EXIT_NONE; } - else if (rtx->exit_level != EXIT_NONE) + else if (rtx->exit_level != EXIT_NONE) { goto done2; } @@ -2672,7 +2672,7 @@ static int run_forin (hawk_rtx_t* rtx, hawk_nde_forin_t* nde) newcapa = rtx->forin.size + hawk_arr_getsize(arr); newcapa = HAWK_ALIGN_POW2(newcapa, 128); tmp = hawk_rtx_reallocmem(rtx, rtx->forin.ptr, newcapa * HAWK_SIZEOF(*tmp)); - if (HAWK_UNLIKELY(!tmp)) + if (HAWK_UNLIKELY(!tmp)) { ADJERR_LOC (rtx, &test->left->loc); ret = -1; @@ -2693,7 +2693,7 @@ static int run_forin (hawk_rtx_t* rtx, hawk_nde_forin_t* nde) hawk_val_t* tmp; tmp = (hawk_val_t*)hawk_rtx_makeintval(rtx, i); - if (HAWK_UNLIKELY(!tmp)) + if (HAWK_UNLIKELY(!tmp)) { ADJERR_LOC (rtx, &test->left->loc); ret = -1; @@ -2723,7 +2723,7 @@ static int run_forin (hawk_rtx_t* rtx, hawk_nde_forin_t* nde) { rtx->exit_level = EXIT_NONE; } - else if (rtx->exit_level != EXIT_NONE) + else if (rtx->exit_level != EXIT_NONE) { goto done3; } @@ -2766,9 +2766,9 @@ static int run_return (hawk_rtx_t* rtx, hawk_nde_return_t* nde) { hawk_val_t* val; - /* chained expressions should not be allowed + /* chained expressions should not be allowed * by the parser first of all */ - HAWK_ASSERT (nde->val->next == HAWK_NULL); + HAWK_ASSERT (nde->val->next == HAWK_NULL); val = eval_expression(rtx, nde->val); if (HAWK_UNLIKELY(!val)) return -1; @@ -2791,9 +2791,9 @@ static int run_return (hawk_rtx_t* rtx, hawk_nde_return_t* nde) HAWK_RTX_STACK_RETVAL(rtx) = val; /* NOTE: see eval_call() for the trick */ - hawk_rtx_refupval (rtx, val); + hawk_rtx_refupval (rtx, val); } - + rtx->exit_level = EXIT_FUNCTION; return 0; } @@ -2804,9 +2804,9 @@ static int run_exit (hawk_rtx_t* rtx, hawk_nde_exit_t* nde) { hawk_val_t* val; - /* chained expressions should not be allowed + /* chained expressions should not be allowed * by the parser first of all */ - HAWK_ASSERT (nde->val->next == HAWK_NULL); + HAWK_ASSERT (nde->val->next == HAWK_NULL); val = eval_expression(rtx, nde->val); if (HAWK_UNLIKELY(!val)) return -1; @@ -2824,7 +2824,7 @@ static int run_exit (hawk_rtx_t* rtx, hawk_nde_exit_t* nde) static int run_next (hawk_rtx_t* rtx, hawk_nde_next_t* nde) { /* the parser checks if next has been called in the begin/end - * block or whereever inappropriate. so the rtxtime doesn't + * block or whereever inappropriate. so the rtxtime doesn't * check that explicitly */ if (rtx->active_block == (hawk_nde_blk_t*)rtx->hawk->tree.begin) { @@ -2872,7 +2872,7 @@ static int run_nextinfile (hawk_rtx_t* rtx, hawk_nde_nextfile_t* nde) } /* FNR resets to 0, NR remains the same */ - if (update_fnr(rtx, 0, rtx->gbl.nr) <= -1) + if (update_fnr(rtx, 0, rtx->gbl.nr) <= -1) { ADJERR_LOC (rtx, &nde->loc); return -1; @@ -2899,8 +2899,8 @@ static int run_nextoutfile (hawk_rtx_t* rtx, hawk_nde_nextfile_t* nde) if (n == 0) { - /* should it terminate the program there is no more - * output console? no. there will just be no more console + /* should it terminate the program there is no more + * output console? no. there will just be no more console * output */ /*rtx->exit_level = EXIT_GLOBAL;*/ return 0; @@ -2926,7 +2926,7 @@ static hawk_val_t* assign_newmapval_in_map (hawk_rtx_t* rtx, hawk_map_t* contain /* as this is the assignment, it needs to update the reference count of the target value. */ hawk_rtx_refupval (rtx, tmp); pair = hawk_map_upsert(container, idxptr, idxlen, tmp, 0); - if (HAWK_UNLIKELY(!pair)) + if (HAWK_UNLIKELY(!pair)) { hawk_rtx_refdownval (rtx, tmp); /* decrement upon upsert() failure */ return HAWK_NULL; @@ -2995,8 +2995,8 @@ static hawk_val_t* assign_topval_to_var (hawk_rtx_t* rtx, hawk_nde_var_t* var, h case HAWK_NDE_NAMED: case HAWK_NDE_NAMEDIDX: { - /* doesn't have to decrease the reference count - * of the previous value here as it is done by + /* doesn't have to decrease the reference count + * of the previous value here as it is done by * hawk_htb_upsert */ hawk_rtx_refupval (rtx, val); if (HAWK_UNLIKELY(hawk_htb_upsert(rtx->named, var->id.name.ptr, var->id.name.len, val, 0) == HAWK_NULL)) @@ -3016,7 +3016,7 @@ static hawk_val_t* assign_topval_to_var (hawk_rtx_t* rtx, hawk_nde_var_t* var, h hawk_rtx_refupval (rtx, val); x = hawk_rtx_setgbl(rtx, (int)var->id.idxa, val); hawk_rtx_refdownval (rtx, val); - if (HAWK_UNLIKELY(x <= -1)) + if (HAWK_UNLIKELY(x <= -1)) { ADJERR_LOC (rtx, &var->loc); return HAWK_NULL; @@ -3056,7 +3056,7 @@ static hawk_val_t* assign_newmapval_to_var (hawk_rtx_t* rtx, hawk_nde_var_t* var HAWK_ASSERT (var->type >= HAWK_NDE_NAMED && var->type <= HAWK_NDE_ARGIDX); tmp = hawk_rtx_makemapval(rtx); - if (HAWK_UNLIKELY(!tmp)) + if (HAWK_UNLIKELY(!tmp)) { ADJERR_LOC (rtx, &var->loc); return HAWK_NULL; @@ -3206,10 +3206,10 @@ static int run_delete (hawk_rtx_t* rtx, hawk_nde_delete_t* nde) /* BEGIN { @local a; - a[1] = 20; a[2] = "hello"; a[3][4][5]="ttt"; - print typename(a), length(a); - delete a; - print typename(a), length(a); + a[1] = 20; a[2] = "hello"; a[3][4][5]="ttt"; + print typename(a), length(a); + delete a; + print typename(a), length(a); } */ hawk_map_clear (((hawk_val_map_t*)val)->map); @@ -3294,7 +3294,7 @@ static hawk_val_t* io_nde_to_str(hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_oocs_t* hawk_rtx_refupval (rtx, v); dst->ptr = hawk_rtx_getvaloocstr(rtx, v, &dst->len); - if (HAWK_UNLIKELY(!dst)) + if (HAWK_UNLIKELY(!dst)) { hawk_rtx_refdownval (rtx, v); return HAWK_NULL; @@ -3313,7 +3313,7 @@ static hawk_val_t* io_nde_to_str(hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_oocs_t* { if (dst->ptr[--len] == '\0') { - hawk_rtx_seterrfmt (rtx, &nde->loc, HAWK_EIONMNL, HAWK_T("invalid I/O name of length %zu containing '\\0'"), dst->len); + hawk_rtx_seterrfmt (rtx, &nde->loc, HAWK_EIONMNL, HAWK_T("invalid I/O name of length %zu containing '\\0'"), dst->len); dst->len = 0; /* indicate that the name is not valid */ break; } @@ -3385,7 +3385,7 @@ static int run_print (hawk_rtx_t* rtx, hawk_nde_print_t* nde) if (np != head) { n = hawk_rtx_writeiostr(rtx, nde->out_type, out.ptr, rtx->gbl.ofs.ptr, rtx->gbl.ofs.len); - if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) + if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) { if (rtx->hawk->opt.trait & HAWK_TOLERANT) { @@ -3405,7 +3405,7 @@ static int run_print (hawk_rtx_t* rtx, hawk_nde_print_t* nde) n = hawk_rtx_writeioval(rtx, nde->out_type, out.ptr, v); hawk_rtx_refdownval (rtx, v); - if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) + if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) { if (rtx->hawk->opt.trait & HAWK_TOLERANT) { @@ -3433,7 +3433,7 @@ static int run_print (hawk_rtx_t* rtx, hawk_nde_print_t* nde) } } - /* unlike printf, flushio() is not needed here as print + /* unlike printf, flushio() is not needed here as print * inserts that triggers auto-flush */ if (out_v) { @@ -3527,7 +3527,7 @@ static int run_printf (hawk_rtx_t* rtx, hawk_nde_print_t* nde) break; default: - /* the remaining arguments are ignored as the format cannot + /* the remaining arguments are ignored as the format cannot * contain any % characters. e.g. printf (1, "xxxx") */ n = hawk_rtx_writeioval(rtx, nde->out_type, out.ptr, v); hawk_rtx_refdownval (rtx, v); @@ -3568,7 +3568,7 @@ oops_1: } static int output_formatted ( - hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* dst, + hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* dst, const hawk_ooch_t* fmt, hawk_oow_t fmt_len, hawk_nde_t* args) { hawk_ooch_t* ptr; @@ -3579,7 +3579,7 @@ static int output_formatted ( if (!ptr) return -1; n = hawk_rtx_writeiostr(rtx, out_type, dst, ptr, len); - if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) + if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) { return (rtx->hawk->opt.trait & HAWK_TOLERANT)? PRINT_IOERR: -1; } @@ -3588,7 +3588,7 @@ static int output_formatted ( } static int output_formatted_bytes ( - hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* dst, + hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* dst, const hawk_bch_t* fmt, hawk_oow_t fmt_len, hawk_nde_t* args) { hawk_bch_t* ptr; @@ -3599,7 +3599,7 @@ static int output_formatted_bytes ( if (!ptr) return -1; n = hawk_rtx_writeiobytes(rtx, out_type, dst, ptr, len); - if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) + if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) { return (rtx->hawk->opt.trait & HAWK_TOLERANT)? PRINT_IOERR: -1; } @@ -3613,11 +3613,11 @@ static hawk_val_t* eval_expression (hawk_rtx_t* rtx, hawk_nde_t* nde) int n; #if 0 - if (rtx->exit_level >= EXIT_GLOBAL) + if (rtx->exit_level >= EXIT_GLOBAL) { /* returns HAWK_NULL as if an error occurred but - * clears the error number. run_main will - * detect this condition and treat it as a + * clears the error number. run_main will + * detect this condition and treat it as a * non-error condition.*/ rtx->errinf.num = HAWK_ENOERR; return HAWK_NULL; @@ -3641,7 +3641,7 @@ static hawk_val_t* eval_expression (hawk_rtx_t* rtx, hawk_nde_t* nde) if (HAWK_RTX_GETVALTYPE(rtx, rtx->inrec.d0) == HAWK_VAL_NIL) { - /* the record has never been read. + /* the record has never been read. * probably, this function has been triggered * by the statements in the BEGIN block */ vs.ptr = HAWK_T(""); @@ -3650,7 +3650,7 @@ static hawk_val_t* eval_expression (hawk_rtx_t* rtx, hawk_nde_t* nde) else { #if 0 - /* the internal value representing $0 should always be of the string type + /* the internal value representing $0 should always be of the string type * once it has been set/updated. it is nil initially. */ HAWK_ASSERT (HAWK_RTX_GETVALTYPE(rtx, rtx->inrec.d0) == HAWK_VAL_STR); vs.ptr = ((hawk_val_str_t*)rtx->inrec.d0)->val.ptr; @@ -3736,8 +3736,8 @@ static hawk_val_t* eval_expression0 (hawk_rtx_t* rtx, hawk_nde_t* nde) hawk_rtx_refdownval (rtx, v); /* returns HAWK_NULL as if an error occurred but - * clears the error number. run_main will - * detect this condition and treat it as a + * clears the error number. run_main will + * detect this condition and treat it as a * non-error condition.*/ hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR); return HAWK_NULL; @@ -3759,10 +3759,10 @@ static hawk_val_t* eval_group (hawk_rtx_t* rtx, hawk_nde_t* nde) #endif /* a group can be evauluated in a normal context - * if a program is parsed with HAWK_TOLERANT on. + * if a program is parsed with HAWK_TOLERANT on. * before the introduction of this option, the grouped - * expression was valid only coerced with the 'in' - * operator. + * expression was valid only coerced with the 'in' + * operator. * */ /* when a group is evaluated in a normal context, @@ -3976,7 +3976,7 @@ static hawk_val_t* do_assignment_nonindexed (hawk_rtx_t* rtx, hawk_nde_var_t* va case HAWK_NDE_GBL: { - if (set_global(rtx, var->id.idxa, var, val, 1) == -1) + if (set_global(rtx, var->id.idxa, var, val, 1) == -1) { ADJERR_LOC (rtx, &var->loc); return HAWK_NULL; @@ -4076,7 +4076,7 @@ static hawk_val_t* do_assignment_indexed (hawk_rtx_t* rtx, hawk_nde_var_t* var, var->type == HAWK_NDE_LCLIDX || var->type == HAWK_NDE_ARGIDX) && var->idx != HAWK_NULL); #if !defined(HAWK_ENABLE_GC) - HAWK_ASSERT (HAWK_RTX_GETVALTYPE(rtx, val) != HAWK_VAL_MAP && + HAWK_ASSERT (HAWK_RTX_GETVALTYPE(rtx, val) != HAWK_VAL_MAP && HAWK_RTX_GETVALTYPE(rtx, val) != HAWK_VAL_ARR); #endif @@ -4179,7 +4179,7 @@ static hawk_val_t* do_assignment_indexed (hawk_rtx_t* rtx, hawk_nde_var_t* var, if (vtype == HAWK_VAL_MAP) { - if (HAWK_UNLIKELY(hawk_map_upsert(map, str, len, val, 0) == HAWK_NULL)) + if (HAWK_UNLIKELY(hawk_map_upsert(map, str, len, val, 0) == HAWK_NULL)) { ADJERR_LOC (rtx, &var->loc); goto oops; @@ -4195,7 +4195,7 @@ static hawk_val_t* do_assignment_indexed (hawk_rtx_t* rtx, hawk_nde_var_t* var, } hawk_rtx_refupval (rtx, val); - if (str && str != idxbuf) hawk_rtx_freemem (rtx, str); + if (str && str != idxbuf) hawk_rtx_freemem (rtx, str); return val; } @@ -4219,7 +4219,7 @@ static hawk_val_t* do_assignment_indexed (hawk_rtx_t* rtx, hawk_nde_var_t* var, } oops: - if (str && str != idxbuf) hawk_rtx_freemem (rtx, str); + if (str && str != idxbuf) hawk_rtx_freemem (rtx, str); return HAWK_NULL; } @@ -4238,13 +4238,13 @@ static hawk_val_t* do_assignment_positional (hawk_rtx_t* rtx, hawk_nde_pos_t* po n = hawk_rtx_valtoint(rtx, v, &lv); hawk_rtx_refdownval (rtx, v); - if (n <= -1) + if (n <= -1) { hawk_rtx_seterrnum (rtx, &pos->loc, HAWK_EPOSIDX); return HAWK_NULL; } - if (!IS_VALID_POSIDX(lv)) + if (!IS_VALID_POSIDX(lv)) { hawk_rtx_seterrnum (rtx, &pos->loc, HAWK_EPOSIDX); return HAWK_NULL; @@ -4268,10 +4268,10 @@ static hawk_val_t* do_assignment_positional (hawk_rtx_t* rtx, hawk_nde_pos_t* po str = out.u.cpldup; } - + n = hawk_rtx_setrec(rtx, (hawk_oow_t)lv, &str, 0); - if (vtype == HAWK_VAL_STR) + if (vtype == HAWK_VAL_STR) { /* do nothing */ } @@ -4310,7 +4310,7 @@ static hawk_val_t* eval_binary (hawk_rtx_t* rtx, hawk_nde_t* nde) eval_binop_lshift, eval_binop_rshift, - + eval_binop_plus, eval_binop_minus, eval_binop_mul, @@ -4351,7 +4351,7 @@ static hawk_val_t* eval_binary (hawk_rtx_t* rtx, hawk_nde_t* nde) case HAWK_BINOP_MA: res = eval_binop_ma(rtx, exp->left, exp->right); break; - + default: HAWK_ASSERT (exp->left->next == HAWK_NULL); left = eval_expression(rtx, exp->left); @@ -4361,7 +4361,7 @@ static hawk_val_t* eval_binary (hawk_rtx_t* rtx, hawk_nde_t* nde) HAWK_ASSERT (exp->right->next == HAWK_NULL); right = eval_expression(rtx, exp->right); - if (HAWK_UNLIKELY(!right)) + if (HAWK_UNLIKELY(!right)) { hawk_rtx_refdownval (rtx, left); return HAWK_NULL; @@ -4388,8 +4388,8 @@ static hawk_val_t* eval_binop_lor (hawk_rtx_t* rtx, hawk_nde_t* left, hawk_nde_t hawk_val_t* res = HAWK_NULL; res = hawk_rtx_makeintval ( - rtx, - hawk_rtx_valtobool(rtx,left) || + rtx, + hawk_rtx_valtobool(rtx,left) || hawk_rtx_valtobool(rtx,right) ); if (res == HAWK_NULL) @@ -4409,7 +4409,7 @@ static hawk_val_t* eval_binop_lor (hawk_rtx_t* rtx, hawk_nde_t* left, hawk_nde_t if (HAWK_UNLIKELY(!lv)) return HAWK_NULL; hawk_rtx_refupval (rtx, lv); - if (hawk_rtx_valtobool(rtx, lv)) + if (hawk_rtx_valtobool(rtx, lv)) { res = HAWK_VAL_ONE; } @@ -4424,7 +4424,7 @@ static hawk_val_t* eval_binop_lor (hawk_rtx_t* rtx, hawk_nde_t* left, hawk_nde_t } hawk_rtx_refupval (rtx, rv); - res = hawk_rtx_valtobool(rtx,rv)? + res = hawk_rtx_valtobool(rtx,rv)? HAWK_VAL_ONE: HAWK_VAL_ZERO; hawk_rtx_refdownval (rtx, rv); } @@ -4440,11 +4440,11 @@ static hawk_val_t* eval_binop_land (hawk_rtx_t* rtx, hawk_nde_t* left, hawk_nde_ hawk_val_t* res = HAWK_NULL; res = hawk_rtx_makeintval ( - rtx, + rtx, hawk_rtx_valtobool(rtx,left) && hawk_rtx_valtobool(rtx,right) ); - if (res == HAWK_NULL) + if (res == HAWK_NULL) { ADJERR_LOC (rtx, &left->loc); return HAWK_NULL; @@ -4461,7 +4461,7 @@ static hawk_val_t* eval_binop_land (hawk_rtx_t* rtx, hawk_nde_t* left, hawk_nde_ if (HAWK_UNLIKELY(!lv)) return HAWK_NULL; hawk_rtx_refupval (rtx, lv); - if (!hawk_rtx_valtobool(rtx, lv)) + if (!hawk_rtx_valtobool(rtx, lv)) { res = HAWK_VAL_ZERO; } @@ -4516,10 +4516,10 @@ static hawk_val_t* eval_binop_in (hawk_rtx_t* rtx, hawk_nde_t* left, hawk_nde_t* if (HAWK_UNLIKELY(!str)) return HAWK_NULL; /* There is no way to express a true multi-dimensional indices for the 'in' operator. - * So remidx must be NULL here. + * So remidx must be NULL here. * a[10][20] <--- no way to express the test of 20 under 10 in a. * You may use multi-level test conjoined with a logical and operator in such a case. - * ((10 in a) && (20 in a[10])) + * ((10 in a) && (20 in a[10])) * * '(10, 20) in a' is to test for a[10,20] if 'a' is a map. */ @@ -4528,7 +4528,7 @@ static hawk_val_t* eval_binop_in (hawk_rtx_t* rtx, hawk_nde_t* left, hawk_nde_t* /* evaluate the right-hand side of the operator */ HAWK_ASSERT (right->next == HAWK_NULL); ropv = eval_expression(rtx, right); - if (HAWK_UNLIKELY(!ropv)) + if (HAWK_UNLIKELY(!ropv)) { if (str != idxbuf) hawk_rtx_freemem (rtx, str); return HAWK_NULL; @@ -4545,7 +4545,7 @@ static hawk_val_t* eval_binop_in (hawk_rtx_t* rtx, hawk_nde_t* left, hawk_nde_t* case HAWK_VAL_MAP: { - + hawk_map_t* map; map = ((hawk_val_map_t*)ropv)->map; @@ -4642,7 +4642,7 @@ typedef enum cmp_op_t cmp_op_t; static HAWK_INLINE cmp_op_t inverse_cmp_op (cmp_op_t op) { - static cmp_op_t inverse_cmp_op_tab[] = + static cmp_op_t inverse_cmp_op_tab[] = { CMP_OP_NONE, CMP_OP_NE, @@ -4659,7 +4659,7 @@ static HAWK_INLINE int __cmp_ensure_not_equal (hawk_rtx_t* rtx, cmp_op_t op_hint { /* checking equality is mostly obvious. however, it is not possible * to test if one is less/greater than the other for some operands. - * this function return a number that ensures to make NE to true and + * this function return a number that ensures to make NE to true and * all other operations false */ switch (op_hint) @@ -4674,7 +4674,7 @@ static HAWK_INLINE int __cmp_ensure_not_equal (hawk_rtx_t* rtx, cmp_op_t op_hint case CMP_OP_GE: return -1; /* make GE false by claiming less */ - case CMP_OP_LE: + case CMP_OP_LE: return 1; /* make LE false by claiming greater */ default: @@ -4966,7 +4966,7 @@ static HAWK_INLINE int __cmp_int_str (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va n = hawk_oochars_to_num( HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ((hawk_val_str_t*)right)->val.ptr, - ((hawk_val_str_t*)right)->val.len, + ((hawk_val_str_t*)right)->val.len, &ll, &rr ); @@ -5005,7 +5005,7 @@ static HAWK_INLINE int __cmp_int_mbs (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va n = hawk_bchars_to_num ( HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ((hawk_val_mbs_t*)right)->val.ptr, - ((hawk_val_mbs_t*)right)->val.len, + ((hawk_val_mbs_t*)right)->val.len, &ll, &rr ); @@ -5221,13 +5221,13 @@ static HAWK_INLINE int __cmp_str_str (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va if (rs->v_nstr == 1) { hawk_int_t rr; - + rr = hawk_oochars_to_int(rs->val.ptr, rs->val.len, HAWK_OOCHARS_TO_INT_MAKE_OPTION(stripspc, stripspc, 0), HAWK_NULL, HAWK_NULL); return (ll > rr)? 1: (ll < rr)? -1: 0; } - else + else { hawk_flt_t rr; @@ -5246,17 +5246,17 @@ static HAWK_INLINE int __cmp_str_str (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va HAWK_ASSERT (ls->v_nstr == 2); ll = hawk_oochars_to_flt(ls->val.ptr, ls->val.len, HAWK_NULL, stripspc); - + if (rs->v_nstr == 1) { hawk_int_t rr; - + rr = hawk_oochars_to_int(rs->val.ptr, rs->val.len, HAWK_OOCHARS_TO_INT_MAKE_OPTION(stripspc, stripspc, 0), HAWK_NULL, HAWK_NULL); return (ll > rr)? 1: (ll < rr)? -1: 0; } - else + else { hawk_flt_t rr; @@ -5498,14 +5498,14 @@ static HAWK_INLINE int __cmp_map_map (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va { /* can't compare a map with a map */ hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EOPERAND); - return CMP_ERROR; + return CMP_ERROR; } static HAWK_INLINE int __cmp_map_arr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint) { /* can't compare a map with an array */ hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EOPERAND); - return CMP_ERROR; + return CMP_ERROR; } /* -------------------------------------------------------------------- */ @@ -5569,14 +5569,14 @@ static HAWK_INLINE int __cmp_arr_map (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va { /* can't compare a map with a map */ hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EOPERAND); - return CMP_ERROR; + return CMP_ERROR; } static HAWK_INLINE int __cmp_arr_arr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint) { /* can't compare a map with an array */ hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EOPERAND); - return CMP_ERROR; + return CMP_ERROR; } /* -------------------------------------------------------------------- */ @@ -5591,7 +5591,7 @@ static HAWK_INLINE int __cmp_val (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* static cmp_val_t func[] = { /* this table must be synchronized with the HAWK_VAL_XXX values in hawk.h */ - __cmp_nil_nil, __cmp_nil_char, __cmp_nil_bchr, __cmp_nil_int, __cmp_nil_flt, __cmp_nil_str, __cmp_nil_mbs, __cmp_nil_fun, __cmp_nil_map, __cmp_nil_arr, + __cmp_nil_nil, __cmp_nil_char, __cmp_nil_bchr, __cmp_nil_int, __cmp_nil_flt, __cmp_nil_str, __cmp_nil_mbs, __cmp_nil_fun, __cmp_nil_map, __cmp_nil_arr, __cmp_char_nil, __cmp_char_char, __cmp_char_bchr, __cmp_char_int, __cmp_char_flt, __cmp_char_str, __cmp_char_mbs, __cmp_char_fun, __cmp_char_map, __cmp_char_arr, __cmp_bchr_nil, __cmp_bchr_char, __cmp_bchr_bchr, __cmp_bchr_int, __cmp_bchr_flt, __cmp_bchr_str, __cmp_bchr_mbs, __cmp_bchr_fun, __cmp_bchr_map, __cmp_bchr_arr, __cmp_int_nil, __cmp_int_char, __cmp_int_bchr, __cmp_int_int, __cmp_int_flt, __cmp_int_str, __cmp_int_mbs, __cmp_int_fun, __cmp_int_map, __cmp_int_arr, @@ -5626,7 +5626,7 @@ static HAWK_INLINE int __cmp_val (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* * HAWK_VAL_FUN = 7 * HAWK_VAL_MAP = 8 * HAWK_VAL_ARR = 9 - * + * * op_hint indicate the operation in progress when this function is called. * this hint doesn't require the comparison function to compare using this * operation. the comparision function should return 0 if equal, -1 if less, @@ -5661,17 +5661,17 @@ static int teq_val (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right) switch (lt) { case HAWK_VAL_NIL: - n = 1; + n = 1; break; case HAWK_VAL_CHAR: - /* since a CHAR value is only reprensented in the value pointer, + /* since a CHAR value is only reprensented in the value pointer, * n is guaranteed to be 0 here. so the following check isn't needed */ n = (HAWK_RTX_GETCHARFROMVAL(rtx, left) == HAWK_RTX_GETCHARFROMVAL(rtx, right)); break; case HAWK_VAL_BCHR: - /* since a BCHR value is only reprensented in the value pointer, + /* since a BCHR value is only reprensented in the value pointer, * n is guaranteed to be 0 here. so the following check isn't needed */ n = (HAWK_RTX_GETBCHRFROMVAL(rtx, left) == HAWK_RTX_GETBCHRFROMVAL(rtx, right)); break; @@ -5709,7 +5709,7 @@ static int teq_val (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right) default: /* map-x and map-y are always different regardless of * their contents. however, if they are pointing to the - * same map value, it won't reach here but will be + * same map value, it won't reach here but will be * handled by the first check in this function */ n = 0; break; @@ -5886,7 +5886,7 @@ static hawk_val_t* eval_binop_div (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t n1 = hawk_rtx_valtonum (rtx, left, &l1, &r1); n2 = hawk_rtx_valtonum (rtx, right, &l2, &r2); - if (n1 <= -1 || n2 <= -1) + if (n1 <= -1 || n2 <= -1) { hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EOPERAND); return HAWK_NULL; @@ -5896,7 +5896,7 @@ static hawk_val_t* eval_binop_div (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t switch (n3) { case 0: - if (l2 == 0) + if (l2 == 0) { hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EDIVBY0); return HAWK_NULL; @@ -5943,7 +5943,7 @@ static hawk_val_t* eval_binop_idiv (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_ n1 = hawk_rtx_valtonum (rtx, left, &l1, &r1); n2 = hawk_rtx_valtonum (rtx, right, &l2, &r2); - if (n1 <= -1 || n2 <= -1) + if (n1 <= -1 || n2 <= -1) { hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EOPERAND); return HAWK_NULL; @@ -5953,7 +5953,7 @@ static hawk_val_t* eval_binop_idiv (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_ switch (n3) { case 0: - if (l2 == 0) + if (l2 == 0) { hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EDIVBY0); return HAWK_NULL; @@ -6004,7 +6004,7 @@ static hawk_val_t* eval_binop_mod (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t switch (n3) { case 0: - if (l2 == 0) + if (l2 == 0) { hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EDIVBY0); return HAWK_NULL; @@ -6038,7 +6038,7 @@ static hawk_val_t* eval_binop_exp (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t n1 = hawk_rtx_valtonum (rtx, left, &l1, &r1); n2 = hawk_rtx_valtonum (rtx, right, &l2, &r2); - if (n1 <= -1 || n2 <= -1) + if (n1 <= -1 || n2 <= -1) { hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EOPERAND); return HAWK_NULL; @@ -6094,7 +6094,7 @@ static hawk_val_t* eval_binop_exp (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t case 2: /* left - int, right - real */ res = hawk_rtx_makefltval ( - rtx, + rtx, rtx->hawk->prm.math.pow(hawk_rtx_gethawk(rtx), (hawk_flt_t)l1, (hawk_flt_t)r2) ); break; @@ -6126,7 +6126,7 @@ static hawk_val_t* eval_binop_concat (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va if (HAWK_UNLIKELY(!l.ptr)) return HAWK_NULL; r.ptr = hawk_rtx_getvalbcstr(rtx, right, &r.len); - if (HAWK_UNLIKELY(!r.ptr)) + if (HAWK_UNLIKELY(!r.ptr)) { hawk_rtx_freevalbcstr (rtx, left, l.ptr); return HAWK_NULL; @@ -6147,7 +6147,7 @@ static hawk_val_t* eval_binop_concat (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va if (HAWK_UNLIKELY(!l.ptr)) return HAWK_NULL; r.ptr = hawk_rtx_getvaloocstr(rtx, right, &r.len); - if (HAWK_UNLIKELY(!r.ptr)) + if (HAWK_UNLIKELY(!r.ptr)) { hawk_rtx_freevaloocstr (rtx, left, l.ptr); return HAWK_NULL; @@ -6178,14 +6178,14 @@ static hawk_val_t* eval_binop_match0 ( n = hawk_rtx_matchvalwithoocs(rtx, right, &out, &out, HAWK_NULL, HAWK_NULL); hawk_rtx_freevaloocstr (rtx, left, out.ptr); - if (HAWK_UNLIKELY(n <= -1)) + if (HAWK_UNLIKELY(n <= -1)) { ADJERR_LOC (rtx, lloc); return HAWK_NULL; } res = hawk_rtx_makeintval(rtx, (n == ret)); - if (HAWK_UNLIKELY(!res)) + if (HAWK_UNLIKELY(!res)) { ADJERR_LOC (rtx, lloc); return HAWK_NULL; @@ -6347,7 +6347,7 @@ static hawk_val_t* eval_incpre (hawk_rtx_t* rtx, hawk_nde_t* nde) return HAWK_NULL; } - if (exp->opcode == HAWK_INCOP_PLUS) + if (exp->opcode == HAWK_INCOP_PLUS) { inc_val_int = 1; inc_val_flt = 1.0; @@ -6413,7 +6413,7 @@ static hawk_val_t* eval_incpre (hawk_rtx_t* rtx, hawk_nde_t* nde) return HAWK_NULL; } - if (n == 0) + if (n == 0) { res = hawk_rtx_makeintval (rtx, v1 + inc_val_int); } @@ -6466,7 +6466,7 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde) return HAWK_NULL; } - if (exp->opcode == HAWK_INCOP_PLUS) + if (exp->opcode == HAWK_INCOP_PLUS) { inc_val_int = 1; inc_val_flt = 1.0; @@ -6553,7 +6553,7 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde) return HAWK_NULL; } - if (n == 0) + if (n == 0) { res = hawk_rtx_makeintval(rtx, v1); if (HAWK_UNLIKELY(!res)) @@ -6630,8 +6630,8 @@ static hawk_val_t* eval_fncall_fnc (hawk_rtx_t* rtx, hawk_nde_t* nde) { /* intrinsic function */ hawk_nde_fncall_t* call = (hawk_nde_fncall_t*)nde; - /* the parser must make sure that the number of arguments is proper */ - HAWK_ASSERT (call->nargs >= call->u.fnc.spec.arg.min && call->nargs <= call->u.fnc.spec.arg.max); + /* the parser must make sure that the number of arguments is proper */ + HAWK_ASSERT (call->nargs >= call->u.fnc.spec.arg.min && call->nargs <= call->u.fnc.spec.arg.max); return hawk_rtx_evalcall(rtx, call, HAWK_NULL, push_arg_from_nde, (void*)call->u.fnc.spec.arg.spec, HAWK_NULL, HAWK_NULL); } @@ -6651,7 +6651,7 @@ static HAWK_INLINE hawk_val_t* eval_fncall_fun (hawk_rtx_t* rtx, hawk_nde_t* nde * i don't mind each instance performs a search duplicately for a short while */ pair = hawk_htb_search(rtx->hawk->tree.funs, call->u.fun.name.ptr, call->u.fun.name.len); - if (!pair) + if (!pair) { hawk_rtx_seterrfmt (rtx, &nde->loc, HAWK_EFUNNF, HAWK_T("function '%.*js' not found"), call->u.fun.name.len, call->u.fun.name.ptr); return HAWK_NULL; @@ -6671,7 +6671,7 @@ static HAWK_INLINE hawk_val_t* eval_fncall_fun (hawk_rtx_t* rtx, hawk_nde_t* nde if (call->nargs > fun->nargs && !fun->variadic) { - /* TODO: is this correct? what if i want to + /* TODO: is this correct? what if i want to * allow arbitarary numbers of arguments? */ hawk_rtx_seterrfmt (rtx, &nde->loc, HAWK_EARGTM, HAWK_T("too many arguments to '%.*js'"), fun->name.len, fun->name.ptr); return HAWK_NULL; @@ -6680,9 +6680,9 @@ static HAWK_INLINE hawk_val_t* eval_fncall_fun (hawk_rtx_t* rtx, hawk_nde_t* nde /* push_arg_from_nde() has special handling for references when the function * argument spec contains 'r' or 'R'. * a reference is passed to a built-in function as a reference value - * but its evaluation result is passed to user-defined function. + * but its evaluation result is passed to user-defined function. * I pass HAWK_NULL to prevent special handling. - * the value change for a reference variable inside a user-defined function is + * the value change for a reference variable inside a user-defined function is * reflected by hawk_rtx_evalcall() specially whereas a built-in function must * call hawk_rtx_setrefval() to update the reference. */ @@ -6709,7 +6709,7 @@ static hawk_val_t* eval_fncall_var (hawk_rtx_t* rtx, hawk_nde_t* nde) } else if (call->nargs > fun->nargs && !fun->variadic) { - /* TODO: is this correct? what if i want to + /* TODO: is this correct? what if i want to * allow arbitarary numbers of arguments? */ hawk_rtx_seterrfmt (rtx, &nde->loc, HAWK_EARGTM, HAWK_T("too many arguments to '%.*js'"), fun->name.len, fun->name.ptr); rv = HAWK_NULL; @@ -6726,7 +6726,7 @@ static hawk_val_t* eval_fncall_var (hawk_rtx_t* rtx, hawk_nde_t* nde) } hawk_val_t* hawk_rtx_evalcall ( - hawk_rtx_t* rtx, hawk_nde_fncall_t* call, hawk_fun_t* fun, + hawk_rtx_t* rtx, hawk_nde_fncall_t* call, hawk_fun_t* fun, hawk_oow_t(*argpusher)(hawk_rtx_t*,hawk_nde_fncall_t*,void*), void* apdata, void(*errhandler)(void*), void* eharg) { @@ -6735,7 +6735,7 @@ hawk_val_t* hawk_rtx_evalcall ( hawk_val_t* v; int n; - /* + /* * --------------------- * lcln <- stack top * --------------------- @@ -6743,15 +6743,15 @@ hawk_val_t* hawk_rtx_evalcall ( * --------------------- * lcl0 local variables are pushed by run_block * ===================== - * argn + * argn * --------------------- * .... * --------------------- * arg1 * --------------------- - * arg0 + * arg0 * --------------------- - * nargs + * nargs * --------------------- * return value * --------------------- @@ -6786,7 +6786,7 @@ hawk_val_t* hawk_rtx_evalcall ( /* make a new stack frame */ stack_req = 4 + call->nargs; - if (fun) + if (fun) { HAWK_ASSERT (fun->nargs >= call->nargs); /* the compiler must guarantee this */ stack_req += fun->nargs - call->nargs; @@ -6855,7 +6855,7 @@ hawk_val_t* hawk_rtx_evalcall ( /* refdown args in the rtx.stack */ nargs = (hawk_oow_t)HAWK_RTX_STACK_NARGS(rtx); #if defined(DEBUG_RUN) - hawk_logbfmt (hawk_rtx_gethawk(rtx), "block rtx complete nargs = %d\n", (int)nargs); + hawk_logbfmt (hawk_rtx_gethawk(rtx), "block rtx complete nargs = %d\n", (int)nargs); #endif i = 0; @@ -6892,11 +6892,11 @@ hawk_val_t* hawk_rtx_evalcall ( av = HAWK_RTX_STACK_ARG(rtx, i); if (HAWK_RTX_GETVALTYPE(rtx, av) == HAWK_VAL_REF) { - /* the argument still has the reference type. - * this means, the argument has not been set. - * - * function f1(&a, &b) { b = 20 } - * + /* the argument still has the reference type. + * this means, the argument has not been set. + * + * function f1(&a, &b) { b = 20 } + * * since a is not set in f1, the value for a is still the pushed value which is a reference */ @@ -6906,7 +6906,7 @@ hawk_val_t* hawk_rtx_evalcall ( { /* if an argument passed is a local variable or a parameter to the previous caller, * the argument node information stored is relative to the previous stack frame. - * i revert rtx->stack_base to the previous stack frame base before calling + * i revert rtx->stack_base to the previous stack frame base before calling * get_reference() and restors it back to the current base. this tactic * is very ugly because the assumption for this is dependent on get_reference() * implementation */ @@ -6919,7 +6919,7 @@ hawk_val_t* hawk_rtx_evalcall ( if (HAWK_LIKELY(r >= 0)) { HAWK_RTX_INIT_REF_VAL (&refv, p->type - HAWK_NDE_NAMED, ref, 9); /* initialize a fake reference variable. 9 chosen randomly */ - if (HAWK_UNLIKELY(hawk_rtx_setrefval(rtx, &refv, av) <= -1)) + if (HAWK_UNLIKELY(hawk_rtx_setrefval(rtx, &refv, av) <= -1)) { n = -1; ADJERR_LOC (rtx, &call->loc); @@ -6940,7 +6940,7 @@ hawk_val_t* hawk_rtx_evalcall ( * * the fourth argument to hawk::call() must map to the second argument to f1(). * hawk::call() accepts the third to the last arguments as reference if possible. - * this function attempts to copy back the pass-by-reference values to + * this function attempts to copy back the pass-by-reference values to * one stack frame up. * * f1(1, 2) is an error as 2 is not referenceable. @@ -6962,7 +6962,7 @@ hawk_val_t* hawk_rtx_evalcall ( v = rtx->stack[call->arg_base + i]; /* UGLY */ if (HAWK_RTX_GETVALTYPE(rtx, v) == HAWK_VAL_REF) { - if (HAWK_UNLIKELY(hawk_rtx_setrefval(rtx, (hawk_val_ref_t*)v, av) <= -1)) + if (HAWK_UNLIKELY(hawk_rtx_setrefval(rtx, (hawk_val_ref_t*)v, av) <= -1)) { n = -1; ADJERR_LOC (rtx, &call->loc); @@ -6988,7 +6988,7 @@ hawk_val_t* hawk_rtx_evalcall ( v = HAWK_RTX_STACK_RETVAL(rtx); if (HAWK_UNLIKELY(n <= -1)) { - if (hawk_rtx_geterrnum(rtx) == HAWK_ENOERR && errhandler != HAWK_NULL) + if (hawk_rtx_geterrnum(rtx) == HAWK_ENOERR && errhandler != HAWK_NULL) { /* errhandler is passed only when hawk_rtx_evalcall() is * invoked from hawk_rtx_call(). Under this @@ -7005,7 +7005,7 @@ hawk_val_t* hawk_rtx_evalcall ( * is HAWK_ENOERR and gets HAWK_RTX_STACK_RETVAL_GBL(rtx) * to determine if it is terminated by exit(). * - * The handler capture_retval_on_exit() + * The handler capture_retval_on_exit() * increments the reference of HAWK_RTX_STACK_RETVAL(rtx) * and stores the pointer into accompanying space. * This way, the return value is preserved upon @@ -7025,7 +7025,7 @@ hawk_val_t* hawk_rtx_evalcall ( /* this trick has been mentioned in rtx_return. * adjust the reference count of the return value. * the value must not be freed even if the reference count - * reached zero because its reference has been incremented + * reached zero because its reference has been incremented * in rtx_return or directly by hawk_rtx_setretval() * regardless of its reference count. */ hawk_rtx_refdownval_nofree (rtx, v); @@ -7037,14 +7037,14 @@ hawk_val_t* hawk_rtx_evalcall ( if (rtx->exit_level == EXIT_FUNCTION) rtx->exit_level = EXIT_NONE; #if defined(DEBUG_RUN) - hawk_logbfmt (hawk_rtx_gethawk(rtx), "returning from function top=%zd, base=%zd\n", (hawk_oow_t)rtx->stack_top, (hawk_oow_t)rtx->stack_base); + hawk_logbfmt (hawk_rtx_gethawk(rtx), "returning from function top=%zd, base=%zd\n", (hawk_oow_t)rtx->stack_top, (hawk_oow_t)rtx->stack_base); #endif return (n <= -1)? HAWK_NULL: v; oops_making_stack_frame: while (rtx->stack_top > saved_arg_stack_top) { - /* call hawk_rtx_refdownval() for all arguments. + /* call hawk_rtx_refdownval() for all arguments. * it is safe because nil or quickint is immune to excessive hawk_rtx_refdownval() calls */ hawk_rtx_refdownval(rtx, rtx->stack[rtx->stack_top - 1]); HAWK_RTX_STACK_POP (rtx); @@ -7052,9 +7052,9 @@ oops_making_stack_frame: HAWK_ASSERT (rtx->stack_top - saved_stack_top == 4); while (rtx->stack_top > saved_stack_top) { - /* the stack frame prologue does not have a reference-counted value + /* the stack frame prologue does not have a reference-counted value * before being entered. so no hawk_rtx_refdownval(). - * three slots contains raw integers for internal use.. only one + * three slots contains raw integers for internal use.. only one * slot that contains the return value would be reference counted * after it is set to a reference counted value. here, it never happens */ HAWK_RTX_STACK_POP (rtx); @@ -7099,7 +7099,7 @@ static hawk_oow_t push_arg_from_vals (hawk_rtx_t* rtx, hawk_nde_fncall_t* call, } } - return nargs; + return nargs; } static hawk_oow_t push_arg_from_nde (hawk_rtx_t* rtx, hawk_nde_fncall_t* call, void* data) @@ -7135,7 +7135,7 @@ static hawk_oow_t push_arg_from_nde (hawk_rtx_t* rtx, hawk_nde_fncall_t* call, v { hawk_val_t** ref; - if (get_reference(rtx, p, &ref) <= -1) + if (get_reference(rtx, p, &ref) <= -1) { if (spec == 'R') goto normal_arg; return (hawk_oow_t)-1; /* return -1 without unwinding stack as hawk_rtx_evalcall() does it */ @@ -7200,7 +7200,7 @@ static int get_reference (hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_val_t*** ref) /* it is bad that the named variable has to be created here. * would there be any better ways to avoid this? */ pair = hawk_htb_upsert(rtx->named, tgt->id.name.ptr, tgt->id.name.len, hawk_val_nil, 0); - if (!pair) + if (!pair) { ADJERR_LOC (rtx, &nde->loc); return -1; @@ -7210,7 +7210,7 @@ static int get_reference (hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_val_t*** ref) *ref = (hawk_val_t**)&HAWK_HTB_VPTR(pair); return 0; } - + case HAWK_NDE_GBL: /* *ref = (hawk_val_t**)&HAWK_RTX_STACK_GBL(rtx,tgt->id.idxa); */ *ref = (hawk_val_t**)((hawk_oow_t)tgt->id.idxa); @@ -7238,8 +7238,8 @@ static int get_reference (hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_val_t*** ref) int n; hawk_int_t lv; hawk_val_t* v; - - /* the position number is returned for the positional + + /* the position number is returned for the positional * variable unlike other reference types. */ v = eval_expression(rtx, ((hawk_nde_pos_t*)nde)->val); if (HAWK_UNLIKELY(!v)) return -1; @@ -7254,7 +7254,7 @@ static int get_reference (hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_val_t*** ref) return -1; } - if (!IS_VALID_POSIDX(lv)) + if (!IS_VALID_POSIDX(lv)) { hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_EPOSIDX); return -1; @@ -7353,7 +7353,7 @@ static hawk_val_t** get_reference_indexed (hawk_rtx_t* rtx, hawk_nde_var_t* var) break; default: - if (vtype == HAWK_VAL_NIL /* || (rtx->hawk->opt.trait & HAWK_FLEXMAP) no flexmap because this is in a 'get' context */) + if (vtype == HAWK_VAL_NIL /* || (rtx->hawk->opt.trait & HAWK_FLEXMAP) no flexmap because this is in a 'get' context */) { if (container_vtype == HAWK_VAL_MAP) { @@ -7534,7 +7534,7 @@ static hawk_val_t* eval_fun (hawk_rtx_t* rtx, hawk_nde_t* nde) HAWK_ASSERT (fun != HAWK_NULL); } - val = hawk_rtx_makefunval(rtx, fun); + val = hawk_rtx_makefunval(rtx, fun); if (HAWK_UNLIKELY(!val)) ADJERR_LOC (rtx, &nde->loc); return val; } @@ -7724,7 +7724,7 @@ static hawk_val_t* eval_pos (hawk_rtx_t* rtx, hawk_nde_t* nde) hawk_rtx_refupval (rtx, v); n = hawk_rtx_valtoint(rtx, v, &lv); hawk_rtx_refdownval (rtx, v); - if (n <= -1) + if (n <= -1) { hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_EPOSIDX); return HAWK_NULL; @@ -7739,7 +7739,7 @@ static hawk_val_t* eval_pos (hawk_rtx_t* rtx, hawk_nde_t* nde) v = POS_VAL(rtx, lv); #if 0 if (lv == 0) v = rtx->inrec.d0; - else if (lv > 0 && lv <= (hawk_int_t)rtx->inrec.nflds) + else if (lv > 0 && lv <= (hawk_int_t)rtx->inrec.nflds) v = rtx->inrec.flds[lv-1].val; else v = hawk_val_zls; /*hawk_val_nil;*/ #endif @@ -7766,7 +7766,7 @@ static hawk_val_t* __eval_getline (hawk_rtx_t* rtx, hawk_nde_t* nde) if (p->in) { v = io_nde_to_str(rtx, p->in, &dst, 0); - if (!v || dst.len <= 0) + if (!v || dst.len <= 0) { hawk_rtx_freevaloocstr (rtx, v, dst.ptr); hawk_rtx_refdownval (rtx, v); @@ -7786,13 +7786,13 @@ read_console_again: n = hawk_rtx_readio(rtx, p->in_type, dst.ptr, buf); - if (v) + if (v) { hawk_rtx_freevaloocstr (rtx, v, dst.ptr); hawk_rtx_refdownval (rtx, v); } - if (n <= -1) + if (n <= -1) { /* make getline return -1 */ n = -1; @@ -7810,7 +7810,7 @@ read_console_again: if (update_fnr(rtx, rtx->gbl.fnr + 1, rtx->gbl.nr + 1) <= -1) return HAWK_NULL; /* this jump is a bit dirty. the 'if' block below hawk_rtx_readio() * will never be true. but this makes code confusing */ - goto read_console_again; + goto read_console_again; } } } @@ -7842,12 +7842,12 @@ read_console_again: /* update FNR & NR if reading from console */ if (p->in_type == HAWK_IN_CONSOLE && - update_fnr(rtx, rtx->gbl.fnr + 1, rtx->gbl.nr + 1) <= -1) + update_fnr(rtx, rtx->gbl.fnr + 1, rtx->gbl.nr + 1) <= -1) { return HAWK_NULL; } } - + skip_read: tmp = hawk_rtx_makeintval(rtx, n); if (!tmp) ADJERR_LOC (rtx, &nde->loc); @@ -7873,7 +7873,7 @@ static hawk_val_t* __eval_getbline (hawk_rtx_t* rtx, hawk_nde_t* nde) if (p->in) { v = io_nde_to_str(rtx, p->in, &dst, 0); - if (!v || dst.len <= 0) + if (!v || dst.len <= 0) { hawk_rtx_freevaloocstr (rtx, v, dst.ptr); hawk_rtx_refdownval (rtx, v); @@ -7893,13 +7893,13 @@ read_console_again: n = hawk_rtx_readiobytes(rtx, p->in_type, dst.ptr, buf); - if (v) + if (v) { hawk_rtx_freevaloocstr (rtx, v, dst.ptr); hawk_rtx_refdownval (rtx, v); } - if (n <= -1) + if (n <= -1) { /* make getline return -1 */ n = -1; @@ -7917,7 +7917,7 @@ read_console_again: if (update_fnr(rtx, rtx->gbl.fnr + 1, rtx->gbl.nr + 1) <= -1) return HAWK_NULL; /* this jump is a bit dirty. the 'if' block below hawk_rtx_readio() * will never be true. but this makes code confusing */ - goto read_console_again; + goto read_console_again; } } } @@ -7952,12 +7952,12 @@ read_console_again: /* update FNR & NR if reading from console */ if (p->in_type == HAWK_IN_CONSOLE && - update_fnr(rtx, rtx->gbl.fnr + 1, rtx->gbl.nr + 1) <= -1) + update_fnr(rtx, rtx->gbl.fnr + 1, rtx->gbl.nr + 1) <= -1) { return HAWK_NULL; } } - + skip_read: tmp = hawk_rtx_makeintval(rtx, n); if (!tmp) ADJERR_LOC (rtx, &nde->loc); @@ -7995,7 +7995,7 @@ read_again: buf = &rtx->inrec.line; n = hawk_rtx_readio(rtx, HAWK_IN_CONSOLE, HAWK_T(""), buf); - if (n <= -1) + if (n <= -1) { hawk_rtx_clrrec (rtx, 0); return -1; @@ -8004,7 +8004,7 @@ read_again: #if defined(DEBUG_RUN) hawk_logbfmt (hawk_rtx_gethawk(rtx), "record len = %d str=[%.*js]\n", (int)HAWK_OOECS_LEN(buf), HAWK_OOECS_LEN(buf), HAWK_OOECS_PTR(buf)); #endif - if (n == 0) + if (n == 0) { HAWK_ASSERT (HAWK_OOECS_LEN(buf) == 0); return 0; @@ -8072,7 +8072,7 @@ static hawk_ooch_t* idxnde_to_str (hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_ooch_t if (!str) { - /* if no fixed-size buffer was given or the fixed-size + /* if no fixed-size buffer was given or the fixed-size * conversion failed, switch to the dynamic mode */ out.type = HAWK_RTX_VALTOSTR_CPLDUP; if (hawk_rtx_valtostr(rtx, idx, &out) <= -1) @@ -8101,7 +8101,7 @@ static hawk_ooch_t* idxnde_to_str (hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_ooch_t out.type = HAWK_RTX_VALTOSTR_STRPCAT; out.u.strpcat = &idxstr; - if (hawk_ooecs_init(&idxstr, hawk_rtx_getgem(rtx), DEF_BUF_CAPA) <= -1) + if (hawk_ooecs_init(&idxstr, hawk_rtx_getgem(rtx), DEF_BUF_CAPA) <= -1) { ADJERR_LOC (rtx, &nde->loc); return HAWK_NULL; @@ -8115,7 +8115,7 @@ static hawk_ooch_t* idxnde_to_str (hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_ooch_t #endif { idx = eval_expression(rtx, nde); - if (HAWK_UNLIKELY(!idx)) + if (HAWK_UNLIKELY(!idx)) { hawk_ooecs_fini (&idxstr); return HAWK_NULL; @@ -8195,7 +8195,7 @@ static hawk_ooi_t idxnde_to_int (hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_nde_t** return -1; } - if (v < 0 || v > HAWK_INT_MAX) + if (v < 0 || v > HAWK_INT_MAX) { /* array index out of permitted range */ hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_EARRIDXRANGE); @@ -8210,7 +8210,7 @@ static hawk_ooi_t idxnde_to_int (hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_nde_t** hawk_ooch_t* hawk_rtx_format ( hawk_rtx_t* rtx, hawk_ooecs_t* out, hawk_ooecs_t* fbu, - const hawk_ooch_t* fmt, hawk_oow_t fmt_len, + const hawk_ooch_t* fmt, hawk_oow_t fmt_len, hawk_oow_t nargs_on_stack, hawk_nde_t* args, hawk_oow_t* len) { hawk_oow_t i; @@ -8258,13 +8258,13 @@ hawk_ooch_t* hawk_rtx_format ( /* run->format.tmp.ptr should have been assigned a pointer to a block of memory before this function has been called */ HAWK_ASSERT (rtx->format.tmp.ptr != HAWK_NULL); - if (nargs_on_stack == (hawk_oow_t)-1) + if (nargs_on_stack == (hawk_oow_t)-1) { /* dirty hack to support a single value argument instead of a tree node */ val = (hawk_val_t*)args; nargs_on_stack = 2; /* indicate 2 arguments of a formatting specifier and the given value */ } - else + else { val = HAWK_NULL; } @@ -8292,12 +8292,12 @@ hawk_ooch_t* hawk_rtx_format ( if (HAWK_OOECS_LEN(fbu) == 0) { /* format specifier is empty */ - if (fmt[i] == HAWK_T('%')) + if (fmt[i] == HAWK_T('%')) { /* add % to format specifier (fbu) */ FMT_CHAR (fmt[i]); } - else + else { /* normal output */ OUT_CHAR (fmt[i]); @@ -8358,7 +8358,7 @@ wp_mod_main: } else { - if (val) + if (val) { if (stack_arg_idx >= nargs_on_stack) { @@ -8367,7 +8367,7 @@ wp_mod_main: } v = val; } - else + else { v = eval_expression(rtx, args); if (HAWK_UNLIKELY(!v)) return HAWK_NULL; @@ -8377,14 +8377,14 @@ wp_mod_main: hawk_rtx_refupval (rtx, v); n = hawk_rtx_valtoint(rtx, v, &wp[wp_idx]); hawk_rtx_refdownval (rtx, v); - if (HAWK_UNLIKELY(n <= -1)) return HAWK_NULL; + if (HAWK_UNLIKELY(n <= -1)) return HAWK_NULL; do { n = hawk_fmt_intmax_to_oocstr( rtx->format.tmp.ptr, rtx->format.tmp.len, - wp[wp_idx], + wp[wp_idx], 10 | HAWK_FMT_INTMAX_NOTRUNC | HAWK_FMT_INTMAX_NONULL, -1, HAWK_T('\0'), @@ -8439,7 +8439,7 @@ wp_mod_main: flags |= FLAG_MINUS; } - if (fmt[i] == 'd' || fmt[i] == 'i' || + if (fmt[i] == 'd' || fmt[i] == 'i' || fmt[i] == 'x' || fmt[i] == 'X' || fmt[i] == 'b' || fmt[i] == 'B' || fmt[i] == 'o' || fmt[i] == 'u') @@ -8465,7 +8465,7 @@ wp_mod_main: } else { - if (val) + if (val) { if (stack_arg_idx >= nargs_on_stack) { @@ -8474,7 +8474,7 @@ wp_mod_main: } v = val; } - else + else { v = eval_expression(rtx, args); if (HAWK_UNLIKELY(!v)) return HAWK_NULL; @@ -8484,7 +8484,7 @@ wp_mod_main: hawk_rtx_refupval (rtx, v); n = hawk_rtx_valtoint(rtx, v, &l); hawk_rtx_refdownval (rtx, v); - if (HAWK_UNLIKELY(n <= -1)) return HAWK_NULL; + if (HAWK_UNLIKELY(n <= -1)) return HAWK_NULL; fmt_flags = HAWK_FMT_INTMAX_NOTRUNC | HAWK_FMT_INTMAX_NONULL; @@ -8502,7 +8502,7 @@ wp_mod_main: { if (flags & FLAG_MINUS) { - /* FLAG_MINUS wins if both FLAG_ZERO + /* FLAG_MINUS wins if both FLAG_ZERO * and FLAG_MINUS are specified. */ fmt_fill = HAWK_T(' '); if (flags & FLAG_MINUS) @@ -8515,7 +8515,7 @@ wp_mod_main: { if (wp_idx != WP_PRECISION) /* if precision is not specified, wp_idx is at WP_WIDTH */ { - /* precision not specified. + /* precision not specified. * FLAG_ZERO can take effect */ fmt_fill = HAWK_T('0'); fmt_flags |= HAWK_FMT_INTMAX_FILLCENTER; @@ -8543,7 +8543,7 @@ wp_mod_main: case 'b': fmt_flags |= 2; fmt_uint = 1; - if (l && (flags & FLAG_HASH)) + if (l && (flags & FLAG_HASH)) { /* A nonzero value is prefixed with 0b */ fmt_prefix = HAWK_T("0b"); @@ -8555,7 +8555,7 @@ wp_mod_main: case 'x': fmt_flags |= 16; fmt_uint = 1; - if (l && (flags & FLAG_HASH)) + if (l && (flags & FLAG_HASH)) { /* A nonzero value is prefixed with 0x */ fmt_prefix = HAWK_T("0x"); @@ -8579,7 +8579,7 @@ wp_mod_main: fmt_uint = 1; default: fmt_flags |= 10; - if (flags & FLAG_PLUS) + if (flags & FLAG_PLUS) fmt_flags |= HAWK_FMT_INTMAX_PLUSSIGN; if (flags & FLAG_SPACE) fmt_flags |= HAWK_FMT_INTMAX_EMPTYSIGN; @@ -8594,19 +8594,19 @@ wp_mod_main: fmt_width = wp[WP_WIDTH]; } else fmt_width = rtx->format.tmp.len; - + do { if (fmt_uint) { - /* Explicit type-casting for 'l' from hawk_int_t - * to hawk_uint_t is needed before passing it to - * hawk_fmt_uintmax_to_oocstr(). + /* Explicit type-casting for 'l' from hawk_int_t + * to hawk_uint_t is needed before passing it to + * hawk_fmt_uintmax_to_oocstr(). * - * Consider a value of -1 for example. - * -1 is a value with all bits set. + * Consider a value of -1 for example. + * -1 is a value with all bits set. * If hawk_int_t is 4 bytes and hawk_uintmax_t - * is 8 bytes, the value is shown below for + * is 8 bytes, the value is shown below for * each type respectively . * -1 - 0xFFFFFFFF (hawk_int_t) * -1 - 0xFFFFFFFFFFFFFFFF (hawk_uintmax_t) @@ -8617,7 +8617,7 @@ wp_mod_main: n = hawk_fmt_uintmax_to_oocstr ( rtx->format.tmp.ptr, fmt_width, - (hawk_uint_t)l, + (hawk_uint_t)l, fmt_flags, wp[WP_PRECISION], fmt_fill, @@ -8654,7 +8654,7 @@ wp_mod_main: fmt[i] == HAWK_T('g') || fmt[i] == HAWK_T('G') || fmt[i] == HAWK_T('f')) { - + hawk_val_t* v; hawk_flt_t r; int n; @@ -8670,7 +8670,7 @@ wp_mod_main: } else { - if (val) /* nargs_on_stack == (hawk_oow_t)-1 */ + if (val) /* nargs_on_stack == (hawk_oow_t)-1 */ { if (stack_arg_idx >= nargs_on_stack) { @@ -8679,7 +8679,7 @@ wp_mod_main: } v = val; } - else + else { v = eval_expression(rtx, args); if (HAWK_UNLIKELY(!v)) return HAWK_NULL; @@ -8703,7 +8703,7 @@ wp_mod_main: if (hawk_ooecs_fcat(out, HAWK_OOECS_PTR(fbu), r) == (hawk_oow_t)-1) return HAWK_NULL; #endif } - else if (fmt[i] == HAWK_T('c')) + else if (fmt[i] == HAWK_T('c')) { hawk_ooch_t ch; hawk_oow_t ch_len; @@ -8721,7 +8721,7 @@ wp_mod_main: } else { - if (val) + if (val) { if (stack_arg_idx >= nargs_on_stack) { @@ -8730,7 +8730,7 @@ wp_mod_main: } v = val; } - else + else { v = eval_expression(rtx, args); if (HAWK_UNLIKELY(!v)) return HAWK_NULL; @@ -8783,7 +8783,7 @@ wp_mod_main: return HAWK_NULL; } - if (wp[WP_PRECISION] <= 0 || wp[WP_PRECISION] > (hawk_int_t)ch_len) + if (wp[WP_PRECISION] <= 0 || wp[WP_PRECISION] > (hawk_int_t)ch_len) { wp[WP_PRECISION] = (hawk_int_t)ch_len; } @@ -8793,43 +8793,43 @@ wp_mod_main: if (!(flags & FLAG_MINUS)) { /* right align */ - while (wp[WP_WIDTH] > wp[WP_PRECISION]) + while (wp[WP_WIDTH] > wp[WP_PRECISION]) { - if (hawk_ooecs_ccat(out, HAWK_T(' ')) == (hawk_oow_t)-1) - { + if (hawk_ooecs_ccat(out, HAWK_T(' ')) == (hawk_oow_t)-1) + { hawk_rtx_refdownval (rtx, v); - return HAWK_NULL; - } + return HAWK_NULL; + } wp[WP_WIDTH]--; } } if (wp[WP_PRECISION] > 0) { - if (hawk_ooecs_ccat(out, ch) == (hawk_oow_t)-1) - { + if (hawk_ooecs_ccat(out, ch) == (hawk_oow_t)-1) + { hawk_rtx_refdownval (rtx, v); - return HAWK_NULL; - } + return HAWK_NULL; + } } if (flags & FLAG_MINUS) { /* left align */ - while (wp[WP_WIDTH] > wp[WP_PRECISION]) + while (wp[WP_WIDTH] > wp[WP_PRECISION]) { - if (hawk_ooecs_ccat (out, HAWK_T(' ')) == (hawk_oow_t)-1) - { + if (hawk_ooecs_ccat (out, HAWK_T(' ')) == (hawk_oow_t)-1) + { hawk_rtx_refdownval (rtx, v); - return HAWK_NULL; - } + return HAWK_NULL; + } wp[WP_WIDTH]--; } } hawk_rtx_refdownval (rtx, v); } - else if (fmt[i] == 's' || fmt[i] == 'k' || fmt[i] == 'K' || fmt[i] == 'w' || fmt[i] == 'W') + else if (fmt[i] == 's' || fmt[i] == 'k' || fmt[i] == 'K' || fmt[i] == 'w' || fmt[i] == 'W') { hawk_val_t* v; @@ -8853,7 +8853,7 @@ wp_mod_main: } v = val; } - else + else { v = eval_expression(rtx, args); if (HAWK_UNLIKELY(!v)) return HAWK_NULL; @@ -8870,7 +8870,7 @@ wp_mod_main: * * when the first attempt to convert 98.76 to a textual form invokes this function with %s and 98.76. * it comes to this part because the format specifier is 's'. since the floating-point type is not - * specially handled, hawk_rtx_valtooocstrdup() is called below. it calls val_flt_to_str() again, + * specially handled, hawk_rtx_valtooocstrdup() is called below. it calls val_flt_to_str() again, * which eventually creates recursion and stack depletion. * * assuming only val_flt_to_str() calls it this way, i must convert the floating point number @@ -8960,10 +8960,10 @@ wp_mod_main: str_free = str_ptr; break; - + } - if (wp_idx != WP_PRECISION || wp[WP_PRECISION] <= -1 || wp[WP_PRECISION] > (hawk_int_t)str_len) + if (wp_idx != WP_PRECISION || wp[WP_PRECISION] <= -1 || wp[WP_PRECISION] > (hawk_int_t)str_len) { /* precision not specified, or specified to a negative value or greater than the actual length */ wp[WP_PRECISION] = (hawk_int_t)str_len; @@ -8973,28 +8973,28 @@ wp_mod_main: if (!(flags & FLAG_MINUS)) { /* right align */ - while (wp[WP_WIDTH] > wp[WP_PRECISION]) + while (wp[WP_WIDTH] > wp[WP_PRECISION]) { - if (hawk_ooecs_ccat(out, HAWK_T(' ')) == (hawk_oow_t)-1) - { + if (hawk_ooecs_ccat(out, HAWK_T(' ')) == (hawk_oow_t)-1) + { if (str_free) hawk_rtx_freemem (rtx, str_free); hawk_rtx_refdownval (rtx, v); - return HAWK_NULL; - } + return HAWK_NULL; + } wp[WP_WIDTH]--; } } if (fmt[i] == 'k' || fmt[i] == 'w') bytetostr_flagged_radix |= HAWK_BYTE_TO_BCSTR_LOWERCASE; - for (k = 0; k < wp[WP_PRECISION]; k++) + for (k = 0; k < wp[WP_PRECISION]; k++) { hawk_ooch_t curc; #if defined(HAWK_OOCH_IS_BCH) curc = str_ptr[k]; #else - if ((vtype == HAWK_VAL_MBS || vtype == HAWK_VAL_BCHR) && fmt[i] != HAWK_T('s')) + if ((vtype == HAWK_VAL_MBS || vtype == HAWK_VAL_BCHR) && fmt[i] != HAWK_T('s')) curc = (hawk_uint8_t)((hawk_bch_t*)str_ptr)[k]; else curc = str_ptr[k]; #endif @@ -9033,12 +9033,12 @@ wp_mod_main: } else { - if (hawk_ooecs_ccat(out, curc) == (hawk_oow_t)-1) + if (hawk_ooecs_ccat(out, curc) == (hawk_oow_t)-1) { s_fail: if (str_free) hawk_rtx_freemem (rtx, str_free); hawk_rtx_refdownval (rtx, v); - return HAWK_NULL; + return HAWK_NULL; } } } @@ -9048,13 +9048,13 @@ wp_mod_main: if (flags & FLAG_MINUS) { /* left align */ - while (wp[WP_WIDTH] > wp[WP_PRECISION]) + while (wp[WP_WIDTH] > wp[WP_PRECISION]) { - if (hawk_ooecs_ccat(out, HAWK_T(' ')) == (hawk_oow_t)-1) - { + if (hawk_ooecs_ccat(out, HAWK_T(' ')) == (hawk_oow_t)-1) + { hawk_rtx_refdownval (rtx, v); - return HAWK_NULL; - } + return HAWK_NULL; + } wp[WP_WIDTH]--; } } @@ -9062,7 +9062,7 @@ wp_mod_main: hawk_rtx_refdownval (rtx, v); } } - else + else { if (fmt[i] != HAWK_T('%')) OUT_STR (HAWK_OOECS_PTR(fbu), HAWK_OOECS_LEN(fbu)); OUT_CHAR (fmt[i]); @@ -9086,7 +9086,7 @@ wp_mod_main: hawk_bch_t* hawk_rtx_formatmbs ( hawk_rtx_t* rtx, hawk_becs_t* out, hawk_becs_t* fbu, - const hawk_bch_t* fmt, hawk_oow_t fmt_len, + const hawk_bch_t* fmt, hawk_oow_t fmt_len, hawk_oow_t nargs_on_stack, hawk_nde_t* args, hawk_oow_t* len) { hawk_oow_t i; @@ -9134,13 +9134,13 @@ hawk_bch_t* hawk_rtx_formatmbs ( /* run->format.tmp.ptr should have been assigned a pointer to a block of memory before this function has been called */ HAWK_ASSERT (rtx->formatmbs.tmp.ptr != HAWK_NULL); - if (nargs_on_stack == (hawk_oow_t)-1) + if (nargs_on_stack == (hawk_oow_t)-1) { /* dirty hack to support a single value argument instead of a tree node */ val = (hawk_val_t*)args; nargs_on_stack = 2; } - else + else { val = HAWK_NULL; } @@ -9168,12 +9168,12 @@ hawk_bch_t* hawk_rtx_formatmbs ( if (HAWK_BECS_LEN(fbu) == 0) { /* format specifier is empty */ - if (fmt[i] == HAWK_BT('%')) + if (fmt[i] == HAWK_BT('%')) { /* add % to format specifier (fbu) */ FMT_MCHAR (fmt[i]); } - else + else { /* normal output */ OUT_MCHAR (fmt[i]); @@ -9234,7 +9234,7 @@ wp_mod_main: } else { - if (val) + if (val) { if (stack_arg_idx >= nargs_on_stack) { @@ -9243,7 +9243,7 @@ wp_mod_main: } v = val; } - else + else { v = eval_expression(rtx, args); if (HAWK_UNLIKELY(!v)) return HAWK_NULL; @@ -9253,14 +9253,14 @@ wp_mod_main: hawk_rtx_refupval (rtx, v); n = hawk_rtx_valtoint(rtx, v, &wp[wp_idx]); hawk_rtx_refdownval (rtx, v); - if (HAWK_UNLIKELY(n <= -1)) return HAWK_NULL; + if (HAWK_UNLIKELY(n <= -1)) return HAWK_NULL; do { n = hawk_fmt_intmax_to_bcstr ( rtx->formatmbs.tmp.ptr, rtx->formatmbs.tmp.len, - wp[wp_idx], + wp[wp_idx], 10 | HAWK_FMT_INTMAX_NOTRUNC | HAWK_FMT_INTMAX_NONULL, -1, HAWK_BT('\0'), @@ -9316,7 +9316,7 @@ wp_mod_main: flags |= FLAG_MINUS; } - if (fmt[i] == HAWK_BT('d') || fmt[i] == HAWK_BT('i') || + if (fmt[i] == HAWK_BT('d') || fmt[i] == HAWK_BT('i') || fmt[i] == HAWK_BT('x') || fmt[i] == HAWK_BT('X') || fmt[i] == HAWK_BT('b') || fmt[i] == HAWK_BT('B') || fmt[i] == HAWK_BT('o')) @@ -9342,7 +9342,7 @@ wp_mod_main: } else { - if (val) + if (val) { if (stack_arg_idx >= nargs_on_stack) { @@ -9351,7 +9351,7 @@ wp_mod_main: } v = val; } - else + else { v = eval_expression(rtx, args); if (HAWK_UNLIKELY(!v)) return HAWK_NULL; @@ -9361,7 +9361,7 @@ wp_mod_main: hawk_rtx_refupval (rtx, v); n = hawk_rtx_valtoint(rtx, v, &l); hawk_rtx_refdownval (rtx, v); - if (HAWK_UNLIKELY(n <= -1)) return HAWK_NULL; + if (HAWK_UNLIKELY(n <= -1)) return HAWK_NULL; fmt_flags = HAWK_FMT_INTMAX_NOTRUNC | HAWK_FMT_INTMAX_NONULL; @@ -9379,7 +9379,7 @@ wp_mod_main: { if (flags & FLAG_MINUS) { - /* FLAG_MINUS wins if both FLAG_ZERO + /* FLAG_MINUS wins if both FLAG_ZERO * and FLAG_MINUS are specified. */ fmt_fill = HAWK_BT(' '); if (flags & FLAG_MINUS) @@ -9392,7 +9392,7 @@ wp_mod_main: { if (wp_idx != WP_PRECISION) /* if precision is not set, wp_idx is at WP_WIDTH */ { - /* precision not specified. + /* precision not specified. * FLAG_ZERO can take effect */ fmt_fill = HAWK_BT('0'); fmt_flags |= HAWK_FMT_INTMAX_FILLCENTER; @@ -9420,7 +9420,7 @@ wp_mod_main: case HAWK_BT('b'): fmt_flags |= 2; fmt_uint = 1; - if (l && (flags & FLAG_HASH)) + if (l && (flags & FLAG_HASH)) { /* A nonzero value is prefixed with 0b */ fmt_prefix = HAWK_BT("0b"); @@ -9432,7 +9432,7 @@ wp_mod_main: case HAWK_BT('x'): fmt_flags |= 16; fmt_uint = 1; - if (l && (flags & FLAG_HASH)) + if (l && (flags & FLAG_HASH)) { /* A nonzero value is prefixed with 0x */ fmt_prefix = HAWK_BT("0x"); @@ -9451,10 +9451,10 @@ wp_mod_main: fmt_flags |= HAWK_FMT_INTMAX_ZEROLEAD; } break; - + default: fmt_flags |= 10; - if (flags & FLAG_PLUS) + if (flags & FLAG_PLUS) fmt_flags |= HAWK_FMT_INTMAX_PLUSSIGN; if (flags & FLAG_SPACE) fmt_flags |= HAWK_FMT_INTMAX_EMPTYSIGN; @@ -9469,19 +9469,19 @@ wp_mod_main: fmt_width = wp[WP_WIDTH]; } else fmt_width = rtx->formatmbs.tmp.len; - + do { if (fmt_uint) { - /* Explicit type-casting for 'l' from hawk_int_t - * to hawk_uint_t is needed before passing it to - * hawk_fmt_uintmax_to_bcstr(). + /* Explicit type-casting for 'l' from hawk_int_t + * to hawk_uint_t is needed before passing it to + * hawk_fmt_uintmax_to_bcstr(). * - * Consider a value of -1 for example. - * -1 is a value with all bits set. + * Consider a value of -1 for example. + * -1 is a value with all bits set. * If hawk_int_t is 4 bytes and hawk_uintmax_t - * is 8 bytes, the value is shown below for + * is 8 bytes, the value is shown below for * each type respectively . * -1 - 0xFFFFFFFF (hawk_int_t) * -1 - 0xFFFFFFFFFFFFFFFF (hawk_uintmax_t) @@ -9492,7 +9492,7 @@ wp_mod_main: n = hawk_fmt_uintmax_to_bcstr ( rtx->formatmbs.tmp.ptr, fmt_width, - (hawk_uint_t)l, + (hawk_uint_t)l, fmt_flags, wp[WP_PRECISION], fmt_fill, @@ -9544,7 +9544,7 @@ wp_mod_main: } else { - if (val) + if (val) { if (stack_arg_idx >= nargs_on_stack) { @@ -9553,7 +9553,7 @@ wp_mod_main: } v = val; } - else + else { v = eval_expression(rtx, args); if (HAWK_UNLIKELY(!v)) return HAWK_NULL; @@ -9577,7 +9577,7 @@ wp_mod_main: if (hawk_becs_fcat(out, HAWK_BECS_PTR(fbu), r) == (hawk_oow_t)-1) return HAWK_NULL; #endif } - else if (fmt[i] == HAWK_BT('c')) + else if (fmt[i] == HAWK_BT('c')) { hawk_bch_t ch; hawk_oow_t ch_len; @@ -9595,7 +9595,7 @@ wp_mod_main: } else { - if (val) + if (val) { if (stack_arg_idx >= nargs_on_stack) { @@ -9604,7 +9604,7 @@ wp_mod_main: } v = val; } - else + else { v = eval_expression(rtx, args); if (HAWK_UNLIKELY(!v)) return HAWK_NULL; @@ -9642,7 +9642,7 @@ wp_mod_main: case HAWK_VAL_STR: ch_len = ((hawk_val_str_t*)v)->val.len; - if (ch_len > 0) + if (ch_len > 0) { /* value truncation is expected */ ch = ((hawk_val_str_t*)v)->val.ptr[0]; @@ -9653,7 +9653,7 @@ wp_mod_main: case HAWK_VAL_MBS: ch_len = ((hawk_val_mbs_t*)v)->val.len; - if (ch_len > 0) + if (ch_len > 0) { ch = ((hawk_val_mbs_t*)v)->val.ptr[0]; ch_len = 1; @@ -9667,7 +9667,7 @@ wp_mod_main: return HAWK_NULL; } - if (wp[WP_PRECISION] <= 0 || wp[WP_PRECISION] > (hawk_int_t)ch_len) + if (wp[WP_PRECISION] <= 0 || wp[WP_PRECISION] > (hawk_int_t)ch_len) { wp[WP_PRECISION] = (hawk_int_t)ch_len; } @@ -9677,36 +9677,36 @@ wp_mod_main: if (!(flags & FLAG_MINUS)) { /* right align */ - while (wp[WP_WIDTH] > wp[WP_PRECISION]) + while (wp[WP_WIDTH] > wp[WP_PRECISION]) { - if (hawk_becs_ccat(out, HAWK_BT(' ')) == (hawk_oow_t)-1) - { + if (hawk_becs_ccat(out, HAWK_BT(' ')) == (hawk_oow_t)-1) + { hawk_rtx_refdownval (rtx, v); - return HAWK_NULL; - } + return HAWK_NULL; + } wp[WP_WIDTH]--; } } if (wp[WP_PRECISION] > 0) { - if (hawk_becs_ccat(out, ch) == (hawk_oow_t)-1) - { + if (hawk_becs_ccat(out, ch) == (hawk_oow_t)-1) + { hawk_rtx_refdownval (rtx, v); - return HAWK_NULL; - } + return HAWK_NULL; + } } if (flags & FLAG_MINUS) { /* left align */ - while (wp[WP_WIDTH] > wp[WP_PRECISION]) + while (wp[WP_WIDTH] > wp[WP_PRECISION]) { - if (hawk_becs_ccat(out, HAWK_BT(' ')) == (hawk_oow_t)-1) - { + if (hawk_becs_ccat(out, HAWK_BT(' ')) == (hawk_oow_t)-1) + { hawk_rtx_refdownval (rtx, v); - return HAWK_NULL; - } + return HAWK_NULL; + } wp[WP_WIDTH]--; } } @@ -9737,7 +9737,7 @@ wp_mod_main: } v = val; } - else + else { v = eval_expression(rtx, args); if (HAWK_UNLIKELY(!v)) return HAWK_NULL; @@ -9754,7 +9754,7 @@ wp_mod_main: * * when the first attempt to convert 98.76 to a textual form invokes this function with %s and 98.76. * it comes to this part because the format specifier is 's'. since the floating-point type is not - * specially handled, hawk_rtx_valtooocstrdup() is called below. it calls val_flt_to_str() again, + * specially handled, hawk_rtx_valtooocstrdup() is called below. it calls val_flt_to_str() again, * which eventually creates recursion and stack depletion. * * assuming only val_flt_to_str() calls it this way, i must convert the floating point number @@ -9847,7 +9847,7 @@ wp_mod_main: break; } - if (wp_idx != WP_PRECISION || wp[WP_PRECISION] <= -1 || wp[WP_PRECISION] > (hawk_int_t)str_len) + if (wp_idx != WP_PRECISION || wp[WP_PRECISION] <= -1 || wp[WP_PRECISION] > (hawk_int_t)str_len) { /* precision not specified, or specified to a negative value or greater than the actual length */ wp[WP_PRECISION] = (hawk_int_t)str_len; @@ -9857,21 +9857,21 @@ wp_mod_main: if (!(flags & FLAG_MINUS)) { /* right align */ - while (wp[WP_WIDTH] > wp[WP_PRECISION]) + while (wp[WP_WIDTH] > wp[WP_PRECISION]) { - if (hawk_becs_ccat(out, HAWK_BT(' ')) == (hawk_oow_t)-1) - { + if (hawk_becs_ccat(out, HAWK_BT(' ')) == (hawk_oow_t)-1) + { if (str_free) hawk_rtx_freemem (rtx, str_free); hawk_rtx_refdownval (rtx, v); - return HAWK_NULL; - } + return HAWK_NULL; + } wp[WP_WIDTH]--; } } if (fmt[i] == 'k' || fmt[i] == 'w') bytetombs_flagged_radix |= HAWK_BYTE_TO_BCSTR_LOWERCASE; - for (k = 0; k < wp[WP_PRECISION]; k++) + for (k = 0; k < wp[WP_PRECISION]; k++) { hawk_bch_t curc; @@ -9881,7 +9881,7 @@ wp_mod_main: { hawk_bch_t xbuf[3]; #if 0 /* the range check isn't needed for hawk_bch_t. it's always <= 0xFF */ - + if (curc <= 0xFF) { #endif @@ -9916,12 +9916,12 @@ wp_mod_main: } else { - if (hawk_becs_ccat(out, curc) == (hawk_oow_t)-1) + if (hawk_becs_ccat(out, curc) == (hawk_oow_t)-1) { s_fail: if (str_free) hawk_rtx_freemem (rtx, str_free); hawk_rtx_refdownval (rtx, v); - return HAWK_NULL; + return HAWK_NULL; } } } @@ -9931,13 +9931,13 @@ wp_mod_main: if (flags & FLAG_MINUS) { /* left align */ - while (wp[WP_WIDTH] > wp[WP_PRECISION]) + while (wp[WP_WIDTH] > wp[WP_PRECISION]) { - if (hawk_becs_ccat(out, HAWK_BT(' ')) == (hawk_oow_t)-1) - { + if (hawk_becs_ccat(out, HAWK_BT(' ')) == (hawk_oow_t)-1) + { hawk_rtx_refdownval (rtx, v); - return HAWK_NULL; - } + return HAWK_NULL; + } wp[WP_WIDTH]--; } } @@ -9945,7 +9945,7 @@ wp_mod_main: hawk_rtx_refdownval (rtx, v); } } - else + else { if (fmt[i] != HAWK_BT('%')) OUT_MBS (HAWK_BECS_PTR(fbu), HAWK_BECS_LEN(fbu)); OUT_MCHAR (fmt[i]); @@ -9981,17 +9981,17 @@ void hawk_rtx_getnrflt (hawk_rtx_t* rtx, hawk_nrflt_t* nrflt) /* ------------------------------------------------------------------------ */ -hawk_oow_t hawk_rtx_fmttoucstr_ (hawk_rtx_t* rtx, hawk_uch_t* buf, hawk_oow_t bufsz, const hawk_uch_t* fmt, ...) +hawk_oow_t hawk_rtx_fmttoucstr_ (hawk_rtx_t* rtx, hawk_uch_t* buf, hawk_oow_t bufsz, const hawk_uch_t* fmt, ...) { va_list ap; hawk_oow_t n; va_start(ap, fmt); n = hawk_gem_vfmttoucstr(hawk_rtx_getgem(rtx), buf, bufsz, fmt, ap); va_end(ap); - return n; + return n; } -hawk_oow_t hawk_rtx_fmttobcstr_ (hawk_rtx_t* rtx, hawk_bch_t* buf, hawk_oow_t bufsz, const hawk_bch_t* fmt, ...) +hawk_oow_t hawk_rtx_fmttobcstr_ (hawk_rtx_t* rtx, hawk_bch_t* buf, hawk_oow_t bufsz, const hawk_bch_t* fmt, ...) { va_list ap; hawk_oow_t n; diff --git a/lib/sed-prv.h b/lib/sed-prv.h index b2be7fb5..3fea2430 100644 --- a/lib/sed-prv.h +++ b/lib/sed-prv.h @@ -43,7 +43,7 @@ struct hawk_sed_app_t typedef struct hawk_sed_cmd_blk_t hawk_sed_cmd_blk_t; struct hawk_sed_cmd_blk_t { - hawk_oow_t len; + hawk_oow_t len; hawk_sed_cmd_t buf[256]; hawk_sed_cmd_blk_t* next; }; @@ -53,7 +53,7 @@ struct hawk_sed_cmd_blk_t typedef struct hawk_sed_cid_t hawk_sed_cid_t; struct hawk_sed_cid_t { - hawk_sed_cid_t* next; + hawk_sed_cid_t* next; }; /* special structure to represent an unknown cid @@ -65,16 +65,16 @@ struct hawk_sed_unknown_cid_t hawk_ooch_t buf[1]; }; -/** - * The hawk_sed_t type defines a stream editor +/** + * The hawk_sed_t type defines a stream editor */ struct hawk_sed_t { HAWK_SED_HDR; - struct + struct { - int trait; + int trait; hawk_sed_tracer_t tracer; hawk_sed_lformatter_t lformatter; @@ -83,7 +83,7 @@ struct hawk_sed_t struct { hawk_oow_t build; - hawk_oow_t match; + hawk_oow_t match; } rex; } depth; /* useful only for rex.h */ } opt; @@ -124,7 +124,7 @@ struct hawk_sed_t } grp; /** a table storing labels seen */ - hawk_map_t labs; + hawk_map_t labs; } tmp; /** compiled commands */ @@ -133,8 +133,8 @@ struct hawk_sed_t hawk_sed_cmd_blk_t fb; /**< the first block is static */ hawk_sed_cmd_blk_t* lb; /**< points to the last block */ - hawk_sed_cmd_t quit; - hawk_sed_cmd_t quit_quiet; + hawk_sed_cmd_t quit; + hawk_sed_cmd_t quit_quiet; hawk_sed_cmd_t again; hawk_sed_cmd_t over; } cmd; @@ -205,7 +205,7 @@ struct hawk_sed_t int delimited; } cutf; - /** indicates if a successful substitution has been made + /** indicates if a successful substitution has been made * since the last read on the input stream. */ int subst_done; void* last_rex; @@ -220,7 +220,7 @@ extern "C" { #endif int hawk_sed_init ( - hawk_sed_t* sed, + hawk_sed_t* sed, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr ); diff --git a/lib/sed.c b/lib/sed.c index 26dd8ede..4b9dfac5 100644 --- a/lib/sed.c +++ b/lib/sed.c @@ -112,7 +112,7 @@ int hawk_sed_init (hawk_sed_t* sed, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr) if (hawk_ooecs_init(&sed->e.txt.scratch, hawk_sed_getgem(sed), 256) <= -1) goto oops_7; /* on init, the last points to the first */ - sed->cmd.lb = &sed->cmd.fb; + sed->cmd.lb = &sed->cmd.fb; /* the block has no data yet */ sed->cmd.fb.len = 0; @@ -139,7 +139,7 @@ void hawk_sed_fini (hawk_sed_t* sed) free_all_command_blocks (sed); free_all_cids (sed); - if (sed->e.cutf.flds != sed->e.cutf.sflds) + if (sed->e.cutf.flds != sed->e.cutf.sflds) hawk_sed_freemem (sed, sed->e.cutf.flds); hawk_ooecs_fini (&sed->e.txt.scratch); @@ -243,7 +243,7 @@ int hawk_sed_getopt (hawk_sed_t* sed, hawk_sed_opt_t id, void* value) } static void* build_rex ( - hawk_sed_t* sed, const hawk_oocs_t* str, + hawk_sed_t* sed, const hawk_oocs_t* str, int ignorecase, const hawk_loc_t* loc) { hawk_tre_t* tre; @@ -257,7 +257,7 @@ static void* build_rex ( } /* ignorecase is a compile option for TRE */ - if (ignorecase) opt |= HAWK_TRE_IGNORECASE; + if (ignorecase) opt |= HAWK_TRE_IGNORECASE; if (sed->opt.trait & HAWK_SED_EXTENDEDREX) opt |= HAWK_TRE_EXTENDED; if (sed->opt.trait & HAWK_SED_NONSTDEXTREX) opt |= HAWK_TRE_NONSTDEXT; @@ -276,7 +276,7 @@ static HAWK_INLINE void free_rex (hawk_sed_t* sed, void* rex) } static int matchtre ( - hawk_sed_t* sed, hawk_tre_t* tre, int opt, + hawk_sed_t* sed, hawk_tre_t* tre, int opt, const hawk_oocs_t* str, hawk_oocs_t* mat, hawk_oocs_t submat[9], const hawk_loc_t* loc) { @@ -292,7 +292,7 @@ static int matchtre ( if (hawk_sed_geterrnum(sed) == HAWK_EREXNOMAT) return 0; ADJERR_LOC (sed, loc); - return -1; + return -1; } HAWK_ASSERT (match[0].rm_so != -1); @@ -306,11 +306,11 @@ static int matchtre ( { int i; - /* you must intialize submat before you pass into this + /* you must intialize submat before you pass into this * function because it can abort filling */ for (i = 1; i < HAWK_COUNTOF(match); i++) { - if (match[i].rm_so != -1) + if (match[i].rm_so != -1) { submat[i-1].ptr = &str->ptr[match[i].rm_so]; submat[i-1].len = match[i].rm_eo - match[i].rm_so; @@ -368,7 +368,7 @@ static int read_script_stream (hawk_sed_t* sed) hawk_ooi_t n; n = sed->src.fun ( - sed, HAWK_SED_IO_READ, &sed->src.arg, + sed, HAWK_SED_IO_READ, &sed->src.arg, sed->src.buf, HAWK_COUNTOF(sed->src.buf) ); if (n <= -1) return -1; /* error */ @@ -390,13 +390,13 @@ static int getnextsc (hawk_sed_t* sed, hawk_ooci_t* c) { /* adjust the line and column number of the next * character based on the current character */ - if (sed->src.cc == HAWK_T('\n')) + if (sed->src.cc == HAWK_T('\n')) { /* TODO: support different line end convension */ sed->src.loc.line++; sed->src.loc.colm = 1; } - else + else { /* take note that if you keep on calling getnextsc() * after HAWK_OOCI_EOF is read, this column number @@ -406,7 +406,7 @@ static int getnextsc (hawk_sed_t* sed, hawk_ooci_t* c) sed->src.loc.colm++; } - if (sed->src.cur >= sed->src.end && !sed->src.eof) + if (sed->src.cur >= sed->src.end && !sed->src.eof) { /* read in more character if buffer is empty */ if (read_script_stream (sed) <= -1) return -1; @@ -420,7 +420,7 @@ static int getnextsc (hawk_sed_t* sed, hawk_ooci_t* c) static int peepnextsc (hawk_sed_t* sed, hawk_ooci_t* c) { - if (sed->src.cur >= sed->src.end && !sed->src.eof) + if (sed->src.cur >= sed->src.end && !sed->src.eof) { /* read in more character if buffer is empty. * it is ok to fill the buffer in the peeping @@ -479,7 +479,7 @@ static void free_all_command_blocks (hawk_sed_t* sed) while (b->len > 0) free_command (sed, &b->buf[--b->len]); if (b != &sed->cmd.fb) hawk_sed_freemem (sed, b); - b = nxt; + b = nxt; } HAWK_MEMSET (&sed->cmd.fb, 0, HAWK_SIZEOF(sed->cmd.fb)); @@ -514,7 +514,7 @@ static void free_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (cmd->u.branch.label.ptr) hawk_sed_freemem (sed, cmd->u.branch.label.ptr); break; - + case HAWK_SED_CMD_SUBSTITUTE: if (cmd->u.subst.file.ptr) hawk_sed_freemem (sed, cmd->u.subst.file.ptr); @@ -533,14 +533,14 @@ static void free_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) free_all_cut_selector_blocks (sed, cmd); break; - default: + default: break; } } static void free_all_cids (hawk_sed_t* sed) { - if (sed->src.cid == (hawk_sed_cid_t*)&sed->src.unknown_cid) + if (sed->src.cid == (hawk_sed_cid_t*)&sed->src.unknown_cid) sed->src.cid = sed->src.cid->next; while (sed->src.cid) @@ -639,11 +639,11 @@ Omitted for clash with regular expression \b. } static int pickup_rex ( - hawk_sed_t* sed, hawk_ooch_t rxend, + hawk_sed_t* sed, hawk_ooch_t rxend, int replacement, const hawk_sed_cmd_t* cmd, hawk_ooecs_t* buf) { - /* - * 'replacement' indicates that this functions is called for + /* + * 'replacement' indicates that this functions is called for * 'replacement' in 's/pattern/replacement'. */ @@ -695,17 +695,17 @@ static int pickup_rex ( { /* * if 'replacement' is not set, bracket_state is alyway 0. - * so this block is never reached. + * so this block is never reached. * - * a backslashed closing bracket is seen. - * it is not :]. if bracket_state is 2, this \] + * a backslashed closing bracket is seen. + * it is not :]. if bracket_state is 2, this \] * makes an illegal regular expression. but, * let's not care.. just drop the state to 0 * as if the outer [ is closed. */ if (chars_from_opening_bracket > 1) bracket_state = 0; } - + if (nc == HAWK_T('\n')) c = nc; else { @@ -715,13 +715,13 @@ static int pickup_rex ( if (trans_escaped (sed, nc, &ec, &xamp) <= -1) return -1; if (ec == nc || (xamp && replacement)) { - /* if the character after a backslash is not special - * at the this layer, add the backslash into the - * regular expression buffer as it is. + /* if the character after a backslash is not special + * at the this layer, add the backslash into the + * regular expression buffer as it is. * - * if \x26 is found in the replacement, i also need to - * transform it to \& so that it is not treated as a - * special &. + * if \x26 is found in the replacement, i also need to + * transform it to \& so that it is not treated as a + * special &. */ if (hawk_ooecs_ccat(buf, HAWK_T('\\')) == (hawk_oow_t)-1) return -1; @@ -729,12 +729,12 @@ static int pickup_rex ( c = ec; } } - else if (!replacement) + else if (!replacement) { - /* this block sets a flag to indicate that we are in [] + /* this block sets a flag to indicate that we are in [] * of a regular expression. */ - if (c == HAWK_T('[')) + if (c == HAWK_T('[')) { if (bracket_state <= 0) { @@ -759,13 +759,13 @@ static int pickup_rex ( { if (bracket_state == 1) { - /* if it is the first character after [, + /* if it is the first character after [, * it is a normal character. */ if (chars_from_opening_bracket > 1) bracket_state--; } else if (bracket_state == 2) { - /* it doesn't really care if colon was for opening bracket + /* it doesn't really care if colon was for opening bracket * like in [[:]] */ if (HAWK_OOECS_LASTCHAR(buf) == HAWK_T(':')) bracket_state--; } @@ -774,7 +774,7 @@ static int pickup_rex ( if (hawk_ooecs_ccat(buf, c) == (hawk_oow_t)-1) return -1; chars_from_opening_bracket++; - } + } return 0; } @@ -792,7 +792,7 @@ static HAWK_INLINE void* compile_rex_address (hawk_sed_t* sed, hawk_ooch_t rxend /* handle a modifer after having handled an empty regex. * so a modifier is naturally disallowed for an empty regex. */ PEEPNXTSC (sed, peeped, HAWK_NULL); - if (peeped == HAWK_T('I')) + if (peeped == HAWK_T('I')) { ignorecase = 1; NXTSC (sed, peeped, HAWK_NULL); /* consume the character peeped */ @@ -880,7 +880,7 @@ static hawk_sed_adr_t* get_address (hawk_sed_t* sed, hawk_sed_adr_t* a, int exte /* get the text for the 'a', 'i', and 'c' commands. * POSIX: - * The argument text shall consist of one or more lines. Each embedded + * The argument text shall consist of one or more lines. Each embedded * in the text shall be preceded by a backslash. Other backslashes * in text shall be removed, and the following character shall be treated * literally. */ @@ -902,7 +902,7 @@ do { \ c = CURSC (sed); - do + do { if (sed->opt.trait & HAWK_SED_STRIPLS) { @@ -917,9 +917,9 @@ do { \ if (c == HAWK_T('\\')) { NXTSC_GOTO (sed, c, oops); - if (c == HAWK_OOCI_EOF) + if (c == HAWK_OOCI_EOF) { - if (sed->opt.trait & HAWK_SED_KEEPTBS) + if (sed->opt.trait & HAWK_SED_KEEPTBS) ADD (sed, t, HAWK_T('\\'), oops); break; } @@ -945,7 +945,7 @@ do { \ } NXTSC_GOTO (sed, c, oops); - } + } } while (c != HAWK_OOCI_EOF); @@ -998,7 +998,7 @@ static int get_label (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) while (IS_LABCHAR(c)); if (hawk_map_search ( - &sed->tmp.labs, + &sed->tmp.labs, HAWK_OOECS_PTR(&sed->tmp.lab), HAWK_OOECS_LEN(&sed->tmp.lab)) != HAWK_NULL) { @@ -1007,7 +1007,7 @@ static int get_label (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) } if (hawk_map_insert ( - &sed->tmp.labs, + &sed->tmp.labs, HAWK_OOECS_PTR(&sed->tmp.lab), HAWK_OOECS_LEN(&sed->tmp.lab), cmd, 0) == HAWK_NULL) { @@ -1019,11 +1019,11 @@ static int get_label (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) while (IS_SPACE(c)) NXTSC (sed, c, -1); - if (IS_CMDTERM(c)) + if (IS_CMDTERM(c)) { - if (c != HAWK_T('}') && + if (c != HAWK_T('}') && c != HAWK_T('#') && - c != HAWK_OOCI_EOF) NXTSC (sed, c, -1); + c != HAWK_OOCI_EOF) NXTSC (sed, c, -1); } return 0; @@ -1041,13 +1041,13 @@ static int terminate_command (hawk_sed_t* sed) return -1; } - /* if the target is terminated by #, it should let the caller + /* if the target is terminated by #, it should let the caller * to skip the comment text. so don't read in the next character. * the same goes for brackets. */ - if (c != HAWK_T('#') && + if (c != HAWK_T('#') && c != HAWK_T('{') && - c != HAWK_T('}') && - c != HAWK_OOCI_EOF) NXTSC (sed, c, -1); + c != HAWK_T('}') && + c != HAWK_OOCI_EOF) NXTSC (sed, c, -1); return 0; } @@ -1064,7 +1064,7 @@ static int get_branch_target (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (IS_CMDTERM(c)) { /* no branch target is given - - * a branch command without a target should cause + * a branch command without a target should cause * sed to jump to the end of a script. */ cmd->u.branch.label.ptr = HAWK_NULL; @@ -1097,7 +1097,7 @@ static int get_branch_target (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) cmd->u.branch.label.len = 0; cmd->u.branch.target = HAWK_MAP_VPTR(pair); } - + hawk_ooecs_close (t); return 0; @@ -1119,7 +1119,7 @@ static int get_file (hawk_sed_t* sed, hawk_oocs_t* xstr) if (IS_CMDTERM(c)) { hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EFILEM); - goto oops; + goto oops; } t = hawk_ooecs_open(hawk_sed_getgem(sed), 0, 32); @@ -1149,11 +1149,11 @@ static int get_file (hawk_sed_t* sed, hawk_oocs_t* xstr) if (c == HAWK_T('n')) c = HAWK_T('\n'); } - if (hawk_ooecs_ccat(t, c) == (hawk_oow_t)-1) + if (hawk_ooecs_ccat(t, c) == (hawk_oow_t)-1) { ADJERR_LOC (sed, &sed->src.loc); goto oops; - } + } NXTSC_GOTO (sed, c, oops); } @@ -1228,22 +1228,22 @@ static int get_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) /* get options */ do { - if (c == HAWK_T('p')) + if (c == HAWK_T('p')) { cmd->u.subst.p = 1; NXTSC_GOTO (sed, c, oops); } - else if (c == HAWK_T('i') || c == HAWK_T('I')) + else if (c == HAWK_T('i') || c == HAWK_T('I')) { cmd->u.subst.i = 1; NXTSC_GOTO (sed, c, oops); } - else if (c == HAWK_T('g')) + else if (c == HAWK_T('g')) { cmd->u.subst.g = 1; NXTSC_GOTO (sed, c, oops); } - else if (c == HAWK_T('k')) + else if (c == HAWK_T('k')) { cmd->u.subst.k = 1; NXTSC_GOTO (sed, c, oops); @@ -1261,9 +1261,9 @@ static int get_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) occ = 0; - do + do { - occ = occ * 10 + (c - HAWK_T('0')); + occ = occ * 10 + (c - HAWK_T('0')); if (occ > HAWK_TYPE_MAX(unsigned short)) { /* occurrence specifier too large */ @@ -1327,7 +1327,7 @@ static int get_transet (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) c = CURSC (sed); CHECK_CMDIC (sed, cmd, c, goto oops); - delim = c; + delim = c; if (delim == HAWK_T('\\')) { /* backspace is an illegal delimiter */ @@ -1356,7 +1356,7 @@ static int get_transet (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (hawk_ooecs_ncat(t, b, 2) == (hawk_oow_t)-1) goto oops; NXTSC_GOTO (sed, c, oops); - } + } NXTSC_GOTO (sed, c, oops); for (pos = 1; c != delim; pos += 2) @@ -1410,7 +1410,7 @@ static int add_cut_selector_block (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) b->next = HAWK_NULL; b->len = 0; - if (cmd->u.cut.fb == HAWK_NULL) + if (cmd->u.cut.fb == HAWK_NULL) { cmd->u.cut.fb = b; cmd->u.cut.lb = b; @@ -1451,7 +1451,7 @@ static int get_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) c = CURSC (sed); CHECK_CMDIC (sed, cmd, c, goto oops); - delim = c; + delim = c; if (delim == HAWK_T('\\')) { /* backspace is an illegal delimiter */ @@ -1504,13 +1504,13 @@ static int get_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (hawk_is_ooch_digit(c)) { - do - { - start = start * 10 + (c - HAWK_T('0')); + do + { + start = start * 10 + (c - HAWK_T('0')); NXTSC_GOTO (sed, c, oops); - } + } while (hawk_is_ooch_digit(c)); - + while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops); mask |= MASK_START; @@ -1525,11 +1525,11 @@ static int get_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (hawk_is_ooch_digit(c)) { - do - { - end = end * 10 + (c - HAWK_T('0')); + do + { + end = end * 10 + (c - HAWK_T('0')); NXTSC_GOTO (sed, c, oops); - } + } while (hawk_is_ooch_digit(c)); mask |= MASK_END; } @@ -1574,7 +1574,7 @@ static int get_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (c == delim) break; - if (c != HAWK_T(',')) + if (c != HAWK_T(',')) { hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_ECSLNV); goto oops; @@ -1588,11 +1588,11 @@ static int get_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) /* get options */ do { - if (c == HAWK_T('f')) + if (c == HAWK_T('f')) { cmd->u.cut.f = 1; } - else if (c == HAWK_T('w')) + else if (c == HAWK_T('w')) { cmd->u.cut.w = 1; } @@ -1655,7 +1655,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) break; case HAWK_T('{'): - /* insert a negated branch command at the beginning + /* insert a negated branch command at the beginning * of a group. this way, all the commands in a group * can be skipped. the branch target is set once a * corresponding } is met. */ @@ -1686,7 +1686,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) cmd->type = HAWK_SED_CMD_NOOP; - if (sed->tmp.grp.level <= 0) + if (sed->tmp.grp.level <= 0) { /* group not balanced */ hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EGRNBA); @@ -1732,10 +1732,10 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (c != HAWK_T('\\')) { - if ((sed->opt.trait & HAWK_SED_SAMELINE) && - c != HAWK_OOCI_EOF && c != HAWK_T('\n')) + if ((sed->opt.trait & HAWK_SED_SAMELINE) && + c != HAWK_OOCI_EOF && c != HAWK_T('\n')) { - /* allow text without a starting backslash + /* allow text without a starting backslash * on the same line as a command */ goto sameline_ok; } @@ -1749,9 +1749,9 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (c != HAWK_OOCI_EOF && c != HAWK_T('\n')) { - if (sed->opt.trait & HAWK_SED_SAMELINE) + if (sed->opt.trait & HAWK_SED_SAMELINE) { - /* allow text with a starting backslash + /* allow text with a starting backslash * on the same line as a command */ goto sameline_ok; } @@ -1759,7 +1759,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EGBABS); return -1; } - + NXTSC (sed, c, -1); /* skip the new line */ sameline_ok: @@ -1789,17 +1789,17 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) case HAWK_T('G'): case HAWK_T('x'): case HAWK_T('n'): - case HAWK_T('N'): + case HAWK_T('N'): case HAWK_T('z'): cmd->type = c; - NXTSC (sed, c, -1); + NXTSC (sed, c, -1); if (terminate_command(sed) <= -1) return -1; break; case HAWK_T('b'): case HAWK_T('t'): cmd->type = c; - NXTSC (sed, c, -1); + NXTSC (sed, c, -1); if (get_branch_target(sed, cmd) <= -1) return -1; break; @@ -1808,19 +1808,19 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) case HAWK_T('w'): case HAWK_T('W'): cmd->type = c; - NXTSC (sed, c, -1); + NXTSC (sed, c, -1); if (get_file(sed, &cmd->u.file) <= -1) return -1; break; case HAWK_T('s'): cmd->type = c; - NXTSC (sed, c, -1); + NXTSC (sed, c, -1); if (get_subst(sed, cmd) <= -1) return -1; break; case HAWK_T('y'): cmd->type = c; - NXTSC (sed, c, -1); + NXTSC (sed, c, -1); if (get_transet(sed, cmd) <= -1) return -1; break; @@ -1878,13 +1878,13 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf) /* check if the line is commented out */ if (c == HAWK_T('#')) { - do NXTSC_GOTO (sed, c, oops); + do NXTSC_GOTO (sed, c, oops); while (!IS_LINTERM(c) && c != HAWK_OOCI_EOF) ; NXTSC_GOTO (sed, c, oops); continue; } - if (c == HAWK_T(';')) + if (c == HAWK_T(';')) { /* semicolon without a address-command pair */ NXTSC_GOTO (sed, c, oops); @@ -1897,7 +1897,7 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf) /* process the first address */ a1_loc = sed->src.loc; - if (get_address(sed, &cmd->a1, 0) == HAWK_NULL) + if (get_address(sed, &cmd->a1, 0) == HAWK_NULL) { cmd = HAWK_NULL; hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EA1MOI); @@ -1917,7 +1917,7 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf) /* maybe an address range */ do { NXTSC_GOTO (sed, c, oops); } while (IS_SPACE(c)); - if (get_address (sed, &cmd->a2, (sed->opt.trait & HAWK_SED_EXTENDEDADR)) == HAWK_NULL) + if (get_address (sed, &cmd->a2, (sed->opt.trait & HAWK_SED_EXTENDEDADR)) == HAWK_NULL) { HAWK_ASSERT (cmd->a2.type == HAWK_SED_ADR_NONE); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EA2MOI); @@ -1931,20 +1931,20 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf) hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EA2MOI); goto oops; } - if (cmd->a2.type == HAWK_SED_ADR_RELLINE || + if (cmd->a2.type == HAWK_SED_ADR_RELLINE || cmd->a2.type == HAWK_SED_ADR_RELLINEM) { - if (cmd->a2.u.lno <= 0) + if (cmd->a2.u.lno <= 0) { /* tranform 'addr1,+0' and 'addr1,~0' to 'addr1' */ cmd->a2.type = HAWK_SED_ADR_NONE; } } } - else if ((sed->opt.trait & HAWK_SED_EXTENDEDADR) && + else if ((sed->opt.trait & HAWK_SED_EXTENDEDADR) && (delim == HAWK_T('~'))) { - if (cmd->a1.type != HAWK_SED_ADR_LINE || + if (cmd->a1.type != HAWK_SED_ADR_LINE || cmd->a2.type != HAWK_SED_ADR_LINE) { hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EA2MOI); @@ -1953,7 +1953,7 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf) if (cmd->a2.u.lno > 0) { - cmd->a2.type = HAWK_SED_ADR_STEP; + cmd->a2.type = HAWK_SED_ADR_STEP; } else { @@ -1969,20 +1969,20 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf) if (cmd->a1.type == HAWK_SED_ADR_LINE && cmd->a1.u.lno <= 0) { - if (cmd->a2.type == HAWK_SED_ADR_STEP || - ((sed->opt.trait & HAWK_SED_EXTENDEDADR) && + if (cmd->a2.type == HAWK_SED_ADR_STEP || + ((sed->opt.trait & HAWK_SED_EXTENDEDADR) && cmd->a2.type == HAWK_SED_ADR_REX)) { /* 0 as the first address is allowed in this two contexts. * 0~step * 0,/regex/ - * '0~0' is not allowed. but at this point '0~0' - * is already transformed to '0'. and disallowing it is + * '0~0' is not allowed. but at this point '0~0' + * is already transformed to '0'. and disallowing it is * achieved gratuitously. */ - /* nothing to do - adding negation to the condition dropped + /* nothing to do - adding negation to the condition dropped * code readability so i decided to write this part of code - * this way. + * this way. */ } else @@ -1998,10 +1998,10 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf) if (c == HAWK_T('!')) { /* allow any number of the negation indicators */ - do { - cmd->negated = !cmd->negated; + do { + cmd->negated = !cmd->negated; NXTSC_GOTO (sed, c, oops); - } + } while (c == HAWK_T('!')); while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops); @@ -2051,7 +2051,7 @@ static int read_char (hawk_sed_t* sed, hawk_ooch_t* c) if (sed->e.in.pos >= sed->e.in.len) { n = sed->e.in.fun ( - sed, HAWK_SED_IO_READ, &sed->e.in.arg, + sed, HAWK_SED_IO_READ, &sed->e.in.arg, sed->e.in.buf, HAWK_COUNTOF(sed->e.in.buf) ); if (n <= -1) return -1; @@ -2084,14 +2084,14 @@ static int read_line (hawk_sed_t* sed, int append) int n; if (!append) hawk_ooecs_clear (&sed->e.in.line); - if (sed->e.in.eof) + if (sed->e.in.eof) { #if 0 /* no more input detected in the previous read. * set eof back to 0 here so that read_char() is called * if read_line() is called again. that way, the result * of subsequent calls counts on read_char(). */ - sed->e.in.eof = 0; + sed->e.in.eof = 0; #endif return 0; } @@ -2109,7 +2109,7 @@ static int read_line (hawk_sed_t* sed, int append) } if (hawk_ooecs_ccat(&sed->e.in.line, c) == (hawk_oow_t)-1) return -1; - len++; + len++; /* TODO: support different line end convension */ if (c == HAWK_T('\n')) break; @@ -2117,7 +2117,7 @@ static int read_line (hawk_sed_t* sed, int append) sed->e.in.num++; sed->e.subst_done = 0; - return 1; + return 1; } static int flush (hawk_sed_t* sed) @@ -2193,12 +2193,12 @@ static int write_first_line ( static int write_num (hawk_sed_t* sed, hawk_oow_t x, int base, int width) { hawk_oow_t last = x % base; - hawk_oow_t y = 0; + hawk_oow_t y = 0; int dig = 0; HAWK_ASSERT (base >= 2 && base <= 36); - if (x < 0) + if (x < 0) { if (write_char(sed, HAWK_T('-')) <= -1) return -1; if (width > 0) width--; @@ -2229,9 +2229,9 @@ static int write_num (hawk_sed_t* sed, hawk_oow_t x, int base, int width) dig--; } - while (dig > 0) - { - dig--; + while (dig > 0) + { + dig--; if (write_char (sed, HAWK_T('0')) <= -1) return -1; } if (last < 0) last = -last; @@ -2309,9 +2309,9 @@ static int write_str_clearly ( } } } - } + } - if (len > 1 && end[-1] != HAWK_T('\n')) + if (len > 1 && end[-1] != HAWK_T('\n')) WRITE_STR (sed, HAWK_T("$\n"), 2); return 0; @@ -2319,7 +2319,7 @@ static int write_str_clearly ( static int write_str_to_file ( hawk_sed_t* sed, hawk_sed_cmd_t* cmd, - const hawk_ooch_t* str, hawk_oow_t len, + const hawk_ooch_t* str, hawk_oow_t len, const hawk_ooch_t* path, hawk_oow_t plen) { hawk_ooi_t n; @@ -2356,7 +2356,7 @@ static int write_str_to_file ( while (len > 0) { n = sed->e.out.fun(sed, HAWK_SED_IO_WRITE, ap, (hawk_ooch_t*)str, len); - if (n <= -1) + if (n <= -1) { sed->e.out.fun (sed, HAWK_SED_IO_CLOSE, ap, HAWK_NULL, 0); ap->handle = HAWK_NULL; @@ -2366,7 +2366,7 @@ static int write_str_to_file ( if (n == 0) { - /* eof is returned on the write stream. + /* eof is returned on the write stream. * it is also an error as it can't write any more */ sed->e.out.fun (sed, HAWK_SED_IO_CLOSE, ap, HAWK_NULL, 0); ap->handle = HAWK_NULL; @@ -2397,7 +2397,7 @@ static int write_file (hawk_sed_t* sed, hawk_sed_cmd_t* cmd, int first_line) { /*return -1;*/ /* it is ok if it is not able to open a file */ - return 0; + return 0; } while (1) @@ -2470,9 +2470,9 @@ static void free_appends (hawk_sed_t* sed) { hawk_sed_app_t* app = sed->e.append.d.head; hawk_sed_app_t* next; - + while (app) - { + { next = app->next; hawk_sed_freemem (sed, app); app = next; @@ -2480,7 +2480,7 @@ static void free_appends (hawk_sed_t* sed) sed->e.append.d.head = HAWK_NULL; sed->e.append.d.tail = HAWK_NULL; - sed->e.append.count = 0; + sed->e.append.count = 0; } static int emit_append (hawk_sed_t* sed, hawk_sed_app_t* app) @@ -2515,7 +2515,7 @@ static int emit_appends (hawk_sed_t* sed) app = sed->e.append.d.head; while (app) - { + { if (emit_append(sed, app) <= -1) return -1; app = app->next; } @@ -2531,10 +2531,10 @@ static const hawk_ooch_t* trim_line (hawk_sed_t* sed, hawk_oocs_t* str) str->len = HAWK_OOECS_LEN(&sed->e.in.line); /* TODO: support different line end convension */ - if (str->len > 0 && str->ptr[str->len-1] == HAWK_T('\n')) + if (str->len > 0 && str->ptr[str->len-1] == HAWK_T('\n')) { str->len--; - if (str->len > 0 && str->ptr[str->len-1] == HAWK_T('\r')) + if (str->len > 0 && str->ptr[str->len-1] == HAWK_T('\r')) { lineterm = HAWK_T("\r\n"); str->len--; @@ -2564,7 +2564,7 @@ static int do_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) hawk_ooecs_clear (&sed->e.txt.scratch); lineterm = trim_line(sed, &str); - + str_end = str.ptr + str.len; cur = str; @@ -2595,7 +2595,7 @@ static int do_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) return -1; } } - else + else { rex = cmd->u.subst.rex; sed->e.last_rex = rex; @@ -2610,7 +2610,7 @@ static int do_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) } else n = 0; - if (n == 0) + if (n == 0) { /* no more match found or substitution occurrence matched. * copy the remaining portion and finish */ @@ -2623,7 +2623,7 @@ static int do_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) break; } - if (mat.len == 0 && + if (mat.len == 0 && pmat.ptr && mat.ptr == pmat.ptr + pmat.len) { /* match length is 0 and the match is still at the @@ -2661,7 +2661,7 @@ static int do_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) for (i = 0; i < cmd->u.subst.rpl.len; i++) { - if ((i+1) < cmd->u.subst.rpl.len && + if ((i+1) < cmd->u.subst.rpl.len && cmd->u.subst.rpl.ptr[i] == HAWK_T('\\')) { hawk_ooch_t nc = cmd->u.subst.rpl.ptr[i+1]; @@ -2677,8 +2677,8 @@ static int do_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) else { /* Known speical characters have been escaped - * in get_subst(). so i don't call trans_escaped() here. - * It's a normal character that's escaped. + * in get_subst(). so i don't call trans_escaped() here. + * It's a normal character that's escaped. * For example, \1 is just 1. and \M is just M. */ m = hawk_ooecs_ccat(&sed->e.txt.scratch, nc); } @@ -2689,7 +2689,7 @@ static int do_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) { m = hawk_ooecs_ncat(&sed->e.txt.scratch, mat.ptr, mat.len); } - else + else { m = hawk_ooecs_ccat(&sed->e.txt.scratch, cmd->u.subst.rpl.ptr[i]); } @@ -2731,7 +2731,7 @@ static int do_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (cmd->u.subst.p) { n = write_str ( - sed, + sed, HAWK_OOECS_PTR(&sed->e.in.line), HAWK_OOECS_LEN(&sed->e.in.line) ); @@ -2770,7 +2770,7 @@ static int split_into_fields_for_cut ( hawk_ooch_t c = str->ptr[i++]; if (cmd->u.cut.w) - { + { /* the w option ignores the d specifier */ if (hawk_is_ooch_space(c)) { @@ -2804,7 +2804,7 @@ static int split_into_fields_for_cut ( nsz = sed->e.cutf.cflds; if (nsz > 50000) nsz += 50000; else nsz *= 2; - + if (sed->e.cutf.flds == sed->e.cutf.sflds) { tmp = hawk_sed_allocmem (sed, HAWK_SIZEOF(*tmp) * nsz); @@ -2825,7 +2825,7 @@ static int split_into_fields_for_cut ( sed->e.cutf.flds[x].ptr = &str->ptr[i]; /* mark that this line is delimited at least once */ - sed->e.cutf.delimited = 1; + sed->e.cutf.delimited = 1; } else xl++; } @@ -2849,13 +2849,13 @@ static int do_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (str.len <= 0) goto done; - if (cmd->u.cut.fcount > 0) + if (cmd->u.cut.fcount > 0) { if (split_into_fields_for_cut (sed, cmd, &str) <= -1) goto oops; - if (cmd->u.cut.d && !sed->e.cutf.delimited) + if (cmd->u.cut.d && !sed->e.cutf.delimited) { - /* if the 'd' option is set and the line is not + /* if the 'd' option is set and the line is not * delimited by the input delimiter, delete the pattern * space and finish the current cycle */ hawk_ooecs_clear (&sed->e.in.line); @@ -2882,7 +2882,7 @@ static int do_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) { if (e >= str.len) e = str.len - 1; if ((out_state == 2 && hawk_ooecs_ccat(&sed->e.txt.scratch, cmd->u.cut.delim[1]) == (hawk_oow_t)-1) || - hawk_ooecs_ncat(&sed->e.txt.scratch, &str.ptr[s], e - s + 1) == (hawk_oow_t)-1) + hawk_ooecs_ncat(&sed->e.txt.scratch, &str.ptr[s], e - s + 1) == (hawk_oow_t)-1) { goto oops; } @@ -2917,7 +2917,7 @@ static int do_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (e >= sed->e.cutf.nflds) e = sed->e.cutf.nflds - 1; while (s <= e) - { + { if ((out_state > 0 && hawk_ooecs_ccat(&sed->e.txt.scratch, cmd->u.cut.delim[1]) == (hawk_oow_t)-1) || hawk_ooecs_ncat(&sed->e.txt.scratch, sed->e.cutf.flds[s].ptr, sed->e.cutf.flds[s].len) == (hawk_oow_t)-1) { @@ -2936,7 +2936,7 @@ static int do_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (s >= sed->e.cutf.nflds) s = sed->e.cutf.nflds - 1; while (e <= s) - { + { if ((out_state > 0 && hawk_ooecs_ccat(&sed->e.txt.scratch, cmd->u.cut.delim[1]) == (hawk_oow_t)-1) || hawk_ooecs_ncat(&sed->e.txt.scratch, sed->e.cutf.flds[e].ptr, sed->e.cutf.flds[e].len) == (hawk_oow_t)-1) { @@ -2947,7 +2947,7 @@ static int do_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) out_state = 2; } } - } + } } } } @@ -2983,7 +2983,7 @@ static int match_a (hawk_sed_t* sed, hawk_sed_cmd_t* cmd, hawk_sed_adr_t* a) line.len = HAWK_OOECS_LEN(&sed->e.in.line); if (line.len > 0 && - line.ptr[line.len-1] == HAWK_T('\n')) + line.ptr[line.len-1] == HAWK_T('\n')) { line.len--; if (line.len > 0 && line.ptr[line.len-1] == HAWK_T('\r')) line.len--; @@ -2998,7 +2998,7 @@ static int match_a (hawk_sed_t* sed, hawk_sed_cmd_t* cmd, hawk_sed_adr_t* a) return -1; } } - else + else { rex = a->u.rex; sed->e.last_rex = rex; @@ -3036,14 +3036,14 @@ static int match_a (hawk_sed_t* sed, hawk_sed_cmd_t* cmd, hawk_sed_adr_t* a) } case HAWK_SED_ADR_RELLINE: - /* this address type should be seen only when matching + /* this address type should be seen only when matching * the second address */ HAWK_ASSERT (cmd->state.a1_matched && cmd->state.a1_match_line >= 1); return (sed->e.in.num >= cmd->state.a1_match_line + a->u.lno)? 1: 0; case HAWK_SED_ADR_RELLINEM: { - /* this address type should be seen only when matching + /* this address type should be seen only when matching * the second address */ hawk_oow_t tmp; @@ -3052,7 +3052,7 @@ static int match_a (hawk_sed_t* sed, hawk_sed_cmd_t* cmd, hawk_sed_adr_t* a) /* TODO: is it better to store this value some in the state * not to calculate this every time?? */ - tmp = (cmd->state.a1_match_line + a->u.lno) - + tmp = (cmd->state.a1_match_line + a->u.lno) - (cmd->state.a1_match_line % a->u.lno); return (sed->e.in.num >= tmp)? 1: 0; @@ -3100,15 +3100,15 @@ static int match_address (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (cmd->a2.type == HAWK_SED_ADR_LINE && sed->e.in.num > cmd->a2.u.lno) { - /* This check is needed because matching of the second + /* This check is needed because matching of the second * address could be skipped while it could match. - * + * * Consider commands like '1,3p;2N'. * '3' in '1,3p' is skipped because 'N' in '2N' triggers * reading of the third line. * * Unfortunately, I can't handle a non-line-number - * second address like this. If 'abcxyz' is given as the third + * second address like this. If 'abcxyz' is given as the third * line for command '1,/abc/p;2N', 'abcxyz' is not matched * against '/abc/'. so it doesn't exit the range. */ @@ -3116,7 +3116,7 @@ static int match_address (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) return 0; } - /* still in the range. return match + /* still in the range. return match * despite the actual mismatch */ return 1; } @@ -3126,19 +3126,19 @@ static int match_address (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) cmd->state.c_ready = 1; return 1; } - else + else { n = match_a (sed, cmd, &cmd->a1); if (n <= -1) return -1; - if (n == 0) + if (n == 0) { return 0; } if (cmd->a2.type == HAWK_SED_ADR_LINE && - sed->e.in.num >= cmd->a2.u.lno) + sed->e.in.num >= cmd->a2.u.lno) { - /* the line number specified in the second + /* the line number specified in the second * address is equal to or less than the current * line number. */ cmd->state.c_ready = 1; @@ -3174,7 +3174,7 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) { case HAWK_SED_CMD_NOOP: break; - + case HAWK_SED_CMD_QUIT: jumpto = &sed->cmd.quit; break; @@ -3206,12 +3206,12 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) ); if (n == (hawk_oow_t)-1) return HAWK_NULL; } - else - { + else + { hawk_ooecs_clear (&sed->e.in.line); } - /* move past the last command so as to start + /* move past the last command so as to start * the next cycle */ jumpto = &sed->cmd.over; break; @@ -3225,10 +3225,10 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) HAWK_OOECS_PTR(&sed->e.in.line), HAWK_OOECS_LEN(&sed->e.in.line), HAWK_T('\n')); - if (nl) + if (nl) { /* if a new line is found. delete up to it */ - hawk_ooecs_del (&sed->e.in.line, 0, nl - HAWK_OOECS_PTR(&sed->e.in.line) + 1); + hawk_ooecs_del (&sed->e.in.line, 0, nl - HAWK_OOECS_PTR(&sed->e.in.line) + 1); if (HAWK_OOECS_LEN(&sed->e.in.line) > 0) { @@ -3262,7 +3262,7 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) case HAWK_SED_CMD_PRINT: n = write_str ( - sed, + sed, HAWK_OOECS_PTR(&sed->e.in.line), HAWK_OOECS_LEN(&sed->e.in.line) ); @@ -3271,7 +3271,7 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) case HAWK_SED_CMD_PRINT_FIRSTLN: n = write_first_line ( - sed, + sed, HAWK_OOECS_PTR(&sed->e.in.line), HAWK_OOECS_LEN(&sed->e.in.line) ); @@ -3300,21 +3300,21 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) case HAWK_SED_CMD_HOLD: /* copy the pattern space to the hold space */ - if (hawk_ooecs_ncpy (&sed->e.txt.hold, + if (hawk_ooecs_ncpy (&sed->e.txt.hold, HAWK_OOECS_PTR(&sed->e.in.line), HAWK_OOECS_LEN(&sed->e.in.line)) == (hawk_oow_t)-1) { - return HAWK_NULL; + return HAWK_NULL; } break; - + case HAWK_SED_CMD_HOLD_APPEND: /* append the pattern space to the hold space */ - if (hawk_ooecs_ncat (&sed->e.txt.hold, + if (hawk_ooecs_ncat (&sed->e.txt.hold, HAWK_OOECS_PTR(&sed->e.in.line), HAWK_OOECS_LEN(&sed->e.in.line)) == (hawk_oow_t)-1) { - return HAWK_NULL; + return HAWK_NULL; } break; @@ -3324,7 +3324,7 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) HAWK_OOECS_PTR(&sed->e.txt.hold), HAWK_OOECS_LEN(&sed->e.txt.hold)) == (hawk_oow_t)-1) { - return HAWK_NULL; + return HAWK_NULL; } break; @@ -3334,7 +3334,7 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) HAWK_OOECS_PTR(&sed->e.txt.hold), HAWK_OOECS_LEN(&sed->e.txt.hold)) == (hawk_oow_t)-1) { - return HAWK_NULL; + return HAWK_NULL; } break; @@ -3349,7 +3349,7 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) /* read the next line and fill the pattern space */ n = read_line (sed, 0); if (n <= -1) return HAWK_NULL; - if (n == 0) + if (n == 0) { /* EOF is reached. */ jumpto = &sed->cmd.over; @@ -3368,7 +3368,7 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) jumpto = &sed->cmd.over; } break; - + case HAWK_SED_CMD_READ_FILE: if (link_append (sed, cmd) <= -1) return HAWK_NULL; break; @@ -3393,9 +3393,9 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) const hawk_ooch_t* ptr = HAWK_OOECS_PTR(&sed->e.in.line); hawk_oow_t i, len = HAWK_OOECS_LEN(&sed->e.in.line); for (i = 0; i < len; i++) - { + { /* TODO: handle different line end convension */ - if (ptr[i] == HAWK_T('\n')) + if (ptr[i] == HAWK_T('\n')) { i++; break; @@ -3410,7 +3410,7 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (n <= -1) return HAWK_NULL; break; } - + case HAWK_SED_CMD_BRANCH_COND: if (!sed->e.subst_done) break; sed->e.subst_done = 0; @@ -3428,13 +3428,13 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) hawk_ooch_t* ptr = HAWK_OOECS_PTR(&sed->e.in.line); hawk_oow_t i, len = HAWK_OOECS_LEN(&sed->e.in.line); - /* TODO: sort cmd->u.transset and do binary search - * when sorted, you can, before binary search, check + /* TODO: sort cmd->u.transset and do binary search + * when sorted, you can, before binary search, check * if ptr[i] < transet[0] || ptr[i] > transset[transset_size-1]. * if so, it has not mathing translation */ /* TODO: support different line end convension */ - if (len > 0 && ptr[len-1] == HAWK_T('\n')) + if (len > 0 && ptr[len-1] == HAWK_T('\n')) { len--; if (len > 0 && ptr[len-1] == HAWK_T('\r')) len--; @@ -3470,7 +3470,7 @@ static hawk_sed_cmd_t* exec_cmd (hawk_sed_t* sed, hawk_sed_cmd_t* cmd) if (jumpto == HAWK_NULL) jumpto = cmd->state.next; return jumpto; -} +} static void close_outfile (hawk_map_t* map, void* dptr, hawk_oow_t dlen) { @@ -3552,7 +3552,7 @@ static int init_command_block_for_exec (hawk_sed_t* sed, hawk_sed_cmd_blk_t* b) c->u.branch.target = HAWK_MAP_VPTR(pair); - /* free resolved label name */ + /* free resolved label name */ hawk_sed_freemem (sed, lab->ptr); lab->ptr = HAWK_NULL; lab->len = 0; @@ -3571,12 +3571,12 @@ static int init_command_block_for_exec (hawk_sed_t* sed, hawk_sed_cmd_blk_t* b) { file = &c->u.subst.file; } - + if (file) { /* call this function to an open output file */ int n = write_str_to_file ( - sed, c, HAWK_NULL, 0, + sed, c, HAWK_NULL, 0, file->ptr, file->len ); if (n <= -1) return -1; @@ -3606,7 +3606,7 @@ static int emit_output (hawk_sed_t* sed, int skipline) if (!skipline && !(sed->opt.trait & HAWK_SED_QUIET)) { /* write the pattern space */ - n = write_str (sed, + n = write_str (sed, HAWK_OOECS_PTR(&sed->e.in.line), HAWK_OOECS_LEN(&sed->e.in.line)); if (n <= -1) return -1; @@ -3615,7 +3615,7 @@ static int emit_output (hawk_sed_t* sed, int skipline) if (emit_appends (sed) <= -1) return -1; free_appends (sed); - /* flush the output stream in case it's not flushed + /* flush the output stream in case it's not flushed * in write functions */ n = flush (sed); if (n <= -1) return -1; @@ -3730,7 +3730,7 @@ int hawk_sed_exec (hawk_sed_t* sed, hawk_sed_io_impl_t inf, hawk_sed_io_impl_t o n = match_address (sed, c); if (n <= -1) { ret = -1; goto done; } - + if (c->negated) n = !n; if (n == 0) { @@ -3744,8 +3744,8 @@ int hawk_sed_exec (hawk_sed_t* sed, hawk_sed_io_impl_t inf, hawk_sed_io_impl_t o j = exec_cmd (sed, c); if (j == HAWK_NULL) { ret = -1; goto done; } if (j == &sed->cmd.quit_quiet) goto done; - if (j == &sed->cmd.quit) - { + if (j == &sed->cmd.quit) + { if (emit_output (sed, 0) <= -1) ret = -1; goto done; } @@ -3794,8 +3794,8 @@ const hawk_ooch_t* hawk_sed_setcompid (hawk_sed_t* sed, const hawk_ooch_t* id) { hawk_sed_cid_t* cid; hawk_oow_t len; - - if (sed->src.cid == (hawk_sed_cid_t*)&sed->src.unknown_cid) + + if (sed->src.cid == (hawk_sed_cid_t*)&sed->src.unknown_cid) { /* if an error has occurred in a previously, you can't set it * any more */ @@ -3806,9 +3806,9 @@ const hawk_ooch_t* hawk_sed_setcompid (hawk_sed_t* sed, const hawk_ooch_t* id) len = hawk_count_oocstr(id); cid = hawk_sed_allocmem(sed, HAWK_SIZEOF(*cid) + ((len + 1) * HAWK_SIZEOF(*id))); - if (cid == HAWK_NULL) + if (cid == HAWK_NULL) { - /* mark that an error has occurred */ + /* mark that an error has occurred */ sed->src.unknown_cid.buf[0] = HAWK_T('\0'); cid = (hawk_sed_cid_t*)&sed->src.unknown_cid; } @@ -3831,7 +3831,7 @@ const hawk_ooch_t* hawk_sed_setcompidwithbcstr (hawk_sed_t* sed, const hawk_bch_ hawk_oow_t tmplen; #endif - if (sed->src.cid == (hawk_sed_cid_t*)&sed->src.unknown_cid) + if (sed->src.cid == (hawk_sed_cid_t*)&sed->src.unknown_cid) { /* if an error has occurred in a previously, you can't set it * any more */ @@ -3846,9 +3846,9 @@ const hawk_ooch_t* hawk_sed_setcompidwithbcstr (hawk_sed_t* sed, const hawk_bch_ hawk_conv_bcstr_to_ucstr_with_cmgr(id, &tmplen, HAWK_NULL, &len, hawk_sed_getcmgr(sed), 1); #endif cid = hawk_sed_allocmem(sed, HAWK_SIZEOF(*cid) + ((len + 1) * HAWK_SIZEOF(*id))); - if (cid == HAWK_NULL) + if (cid == HAWK_NULL) { - /* mark that an error has occurred */ + /* mark that an error has occurred */ sed->src.unknown_cid.buf[0] = HAWK_T('\0'); cid = (hawk_sed_cid_t*)&sed->src.unknown_cid; } @@ -3873,8 +3873,8 @@ const hawk_ooch_t* hawk_sed_setcompidwithucstr (hawk_sed_t* sed, const hawk_uch_ #if defined(HAWK_OOCH_IS_BCH) hawk_oow_t tmplen; #endif - - if (sed->src.cid == (hawk_sed_cid_t*)&sed->src.unknown_cid) + + if (sed->src.cid == (hawk_sed_cid_t*)&sed->src.unknown_cid) { /* if an error has occurred in a previously, you can't set it * any more */ @@ -3889,9 +3889,9 @@ const hawk_ooch_t* hawk_sed_setcompidwithucstr (hawk_sed_t* sed, const hawk_uch_ len = hawk_count_oocstr(id); #endif cid = hawk_sed_allocmem(sed, HAWK_SIZEOF(*cid) + ((len + 1) * HAWK_SIZEOF(hawk_ooch_t))); - if (cid == HAWK_NULL) + if (cid == HAWK_NULL) { - /* mark that an error has occurred */ + /* mark that an error has occurred */ sed->src.unknown_cid.buf[0] = HAWK_T('\0'); cid = (hawk_sed_cid_t*)&sed->src.unknown_cid; } diff --git a/lib/sio.c b/lib/sio.c index 1d7bb5d7..21600e42 100644 --- a/lib/sio.c +++ b/lib/sio.c @@ -88,7 +88,7 @@ hawk_sio_t* hawk_sio_openstd (hawk_gem_t* gem, hawk_oow_t xtnsize, hawk_sio_std_ sio = hawk_sio_open(gem, xtnsize, (const hawk_ooch_t*)&hnd, flags | HAWK_SIO_HANDLE | HAWK_SIO_NOCLOSE); #if defined(_WIN32) - if (sio) + if (sio) { DWORD mode; if (GetConsoleMode(sio->file.handle, &mode) == TRUE && GetConsoleOutputCP() == CP_UTF8) @@ -123,9 +123,9 @@ int hawk_sio_init (hawk_sio_t* sio, hawk_gem_t* gem, const hawk_ooch_t* path, in sio->mtx = hawk_mtx_open(gem, 0); if (!sio->mtx) goto oops00; } - /* sio flag enumerators redefines most fio flag enumerators and - * compose a superset of fio flag enumerators. when a user calls - * this function, a user can specify a sio flag enumerator not + /* sio flag enumerators redefines most fio flag enumerators and + * compose a superset of fio flag enumerators. when a user calls + * this function, a user can specify a sio flag enumerator not * present in the fio flag enumerator. mask off such an enumerator. */ if (hawk_fio_init(&sio->file, gem, path, (flags & ~HAWK_FIO_RESERVED), mode) <= -1) goto oops01; @@ -192,7 +192,7 @@ int hawk_sio_initstd (hawk_sio_t* sio, hawk_gem_t* gem, hawk_sio_std_t std, int n = hawk_sio_init(sio, gem, (const hawk_ooch_t*)&hnd, flags | HAWK_SIO_HANDLE | HAWK_SIO_NOCLOSE); #if defined(_WIN32) - if (n >= 0) + if (n >= 0) { DWORD mode; if (GetConsoleMode (sio->file.handle, &mode) == TRUE && GetConsoleOutputCP() == CP_UTF8) @@ -409,7 +409,7 @@ hawk_ooi_t hawk_sio_putbcstr (hawk_sio_t* sio, const hawk_bch_t* str) LOCK_OUTPUT (sio); for (n = 0; n < HAWK_TYPE_MAX(hawk_ooi_t) && str[n] != '\0'; n++) { - if ((n = putbc_no_mutex(sio, str[n])) <= -1) + if ((n = putbc_no_mutex(sio, str[n])) <= -1) { n = -1; break; @@ -472,14 +472,14 @@ hawk_ooi_t hawk_sio_putucstr (hawk_sio_t* sio, const hawk_uch_t* str) 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) + if (WriteConsoleW(sio->file.handle, cur, left, &count, HAWK_NULL) == FALSE) { hawk_gem_seterrnum (sio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); return -1; } if (count == 0) break; - if (count > left) + if (count > left) { hawk_gem_seterrnum (sio->gem, HAWK_NULL, HAWK_ESYSERR); return -1; @@ -516,14 +516,14 @@ hawk_ooi_t hawk_sio_putuchars (hawk_sio_t* sio, const hawk_uch_t* str, hawk_oow_ #if defined(_WIN32) /* DAMN UGLY: - * WriteFile returns wrong number of bytes written if it is - * requested to write a utf8 string on utf8 console (codepage 65001). - * it seems to return a number of characters written instead. so - * i have to use an alternate API for console output for - * wide-character strings. Conversion to either an OEM codepage or + * WriteFile returns wrong number of bytes written if it is + * requested to write a utf8 string on utf8 console (codepage 65001). + * it seems to return a number of characters written instead. so + * i have to use an alternate API for console output for + * wide-character strings. Conversion to either an OEM codepage or * the utf codepage is handled by the API. This hack at least * lets you do proper utf8 output on utf8 console using wide-character. - * + * * Note that the multibyte functions hawk_sio_putbcstr() and * hawk_sio_putbchars() doesn't handle this. So you may still suffer. */ @@ -536,7 +536,7 @@ hawk_ooi_t hawk_sio_putuchars (hawk_sio_t* sio, const hawk_uch_t* str, hawk_oow_ for (cur = str, left = size; left > 0; cur += count, left -= count) { - if (WriteConsoleW(sio->file.handle, cur, left, &count, HAWK_NULL) == FALSE) + if (WriteConsoleW(sio->file.handle, cur, left, &count, HAWK_NULL) == FALSE) { hawk_gem_seterrnum (sio->gem, HAWK_NULL, hawk_syserr_to_errnum(GetLastError())); return -1; @@ -545,13 +545,13 @@ hawk_ooi_t hawk_sio_putuchars (hawk_sio_t* sio, const hawk_uch_t* str, hawk_oow_ /* Note: * WriteConsoleW() in unicosw.dll on win 9x/me returns - * the number of bytes via 'count'. If a double byte + * the number of bytes via 'count'. If a double byte * string is given, 'count' can be greater than 'left'. * this case is a miserable failure. however, i don't * think there is CP_UTF8 codepage for console on win9x/me. * so let me make this function fail if that ever happens. */ - if (count > left) + if (count > left) { hawk_gem_seterrnum (sio->gem, HAWK_NULL, HAWK_ESYSERR); return -1; @@ -560,14 +560,14 @@ hawk_ooi_t hawk_sio_putuchars (hawk_sio_t* sio, const hawk_uch_t* str, hawk_oow_ return cur - str; } -#elif defined(__OS2__) +#elif defined(__OS2__) if (sio->status & STATUS_LINE_BREAK) { if (size > HAWK_TYPE_MAX(hawk_ooi_t)) size = HAWK_TYPE_MAX(hawk_ooi_t); LOCK_OUTPUT (sio); for (n = 0; n < size; n++) { - if (put_uchar_no_mutex(sio, str[n]) <= -1) + if (put_uchar_no_mutex(sio, str[n]) <= -1) { n = -1; break; @@ -629,7 +629,7 @@ int hawk_sio_seek (hawk_sio_t* sio, hawk_sio_pos_t* pos, hawk_sio_ori_t origin) static hawk_ooi_t file_input (hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, hawk_oow_t size) { - if (cmd == HAWK_TIO_DATA) + if (cmd == HAWK_TIO_DATA) { hawk_sio_t* sio; @@ -645,7 +645,7 @@ static hawk_ooi_t file_input (hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, ha static hawk_ooi_t file_output (hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, hawk_oow_t size) { - if (cmd == HAWK_TIO_DATA) + if (cmd == HAWK_TIO_DATA) { hawk_sio_t* sio; diff --git a/lib/skad.c b/lib/skad.c index 1c92b119..5537f060 100644 --- a/lib/skad.c +++ b/lib/skad.c @@ -49,14 +49,14 @@ static int uchars_to_ipv4 (const hawk_uch_t* str, hawk_oow_t len, struct in_addr c = *str++; - if (c >= '0' && c <= '9') + if (c >= '0' && c <= '9') { if (digits > 0 && acc == 0) return -1; acc = acc * 10 + (c - '0'); if (acc > 255) return -1; digits++; } - else if (c == '.') + else if (c == '.') { if (dots >= 3 || digits == 0) return -1; addr = (addr << 8) | acc; @@ -91,14 +91,14 @@ static int bchars_to_ipv4 (const hawk_bch_t* str, hawk_oow_t len, struct in_addr c = *str++; - if (c >= '0' && c <= '9') + if (c >= '0' && c <= '9') { if (digits > 0 && acc == 0) return -1; acc = acc * 10 + (c - '0'); if (acc > 255) return -1; digits++; } - else if (c == '.') + else if (c == '.') { if (dots >= 3 || digits == 0) return -1; addr = (addr << 8) | acc; @@ -157,10 +157,10 @@ static int uchars_to_ipv6 (const hawk_uch_t* src, hawk_oow_t len, struct in6_add continue; } - if (ch == ':') + if (ch == ':') { curtok = src; - if (!saw_xdigit) + if (!saw_xdigit) { if (colonp) return -1; colonp = tp; @@ -180,23 +180,23 @@ static int uchars_to_ipv6 (const hawk_uch_t* src, hawk_oow_t len, struct in6_add } if (ch == '.' && ((tp + HAWK_SIZEOF(struct in_addr)) <= endp) && - uchars_to_ipv4(curtok, src_end - curtok, (struct in_addr*)tp) == 0) + uchars_to_ipv4(curtok, src_end - curtok, (struct in_addr*)tp) == 0) { tp += HAWK_SIZEOF(struct in_addr*); saw_xdigit = 0; - break; + break; } return -1; } - if (saw_xdigit) + if (saw_xdigit) { if (tp + HAWK_SIZEOF(hawk_uint16_t) > endp) return -1; *tp++ = (hawk_uint8_t)(val >> 8) & 0xff; *tp++ = (hawk_uint8_t)val & 0xff; } - if (colonp != HAWK_NULL) + if (colonp != HAWK_NULL) { /* * Since some memmove()'s erroneously fail to handle @@ -204,8 +204,8 @@ static int uchars_to_ipv6 (const hawk_uch_t* src, hawk_oow_t len, struct in6_add */ hawk_oow_t n = tp - colonp; hawk_oow_t i; - - for (i = 1; i <= n; i++) + + for (i = 1; i <= n; i++) { endp[-i] = colonp[n - i]; colonp[n - i] = 0; @@ -261,10 +261,10 @@ static int bchars_to_ipv6 (const hawk_bch_t* src, hawk_oow_t len, struct in6_add continue; } - if (ch == ':') + if (ch == ':') { curtok = src; - if (!saw_xdigit) + if (!saw_xdigit) { if (colonp) return -1; colonp = tp; @@ -284,23 +284,23 @@ static int bchars_to_ipv6 (const hawk_bch_t* src, hawk_oow_t len, struct in6_add } if (ch == '.' && ((tp + HAWK_SIZEOF(struct in_addr)) <= endp) && - bchars_to_ipv4(curtok, src_end - curtok, (struct in_addr*)tp) == 0) + bchars_to_ipv4(curtok, src_end - curtok, (struct in_addr*)tp) == 0) { tp += HAWK_SIZEOF(struct in_addr*); saw_xdigit = 0; - break; + break; } return -1; } - if (saw_xdigit) + if (saw_xdigit) { if (tp + HAWK_SIZEOF(hawk_uint16_t) > endp) return -1; *tp++ = (hawk_uint8_t)(val >> 8) & 0xff; *tp++ = (hawk_uint8_t)val & 0xff; } - if (colonp != HAWK_NULL) + if (colonp != HAWK_NULL) { /* * Since some memmove()'s erroneously fail to handle @@ -308,8 +308,8 @@ static int bchars_to_ipv6 (const hawk_bch_t* src, hawk_oow_t len, struct in6_add */ hawk_oow_t n = tp - colonp; hawk_oow_t i; - - for (i = 1; i <= n; i++) + + for (i = 1; i <= n; i++) { endp[-i] = colonp[n - i]; colonp[n - i] = 0; @@ -335,14 +335,14 @@ int hawk_gem_ucharstoskad (hawk_gem_t* gem, const hawk_uch_t* str, hawk_oow_t le p = str; end = str + len; - if (p >= end) + if (p >= end) { hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "blank address"); return -1; } /* use HAWK_SIZEOF(*_skad) instead of HAWK_SIZEOF(*skad) in case they are different */ - HAWK_MEMSET (skad, 0, HAWK_SIZEOF(*_skad)); + HAWK_MEMSET (skad, 0, HAWK_SIZEOF(*_skad)); if (*p == '@' || *p == '/') { @@ -357,7 +357,7 @@ int hawk_gem_ucharstoskad (hawk_gem_t* gem, const hawk_uch_t* str, hawk_oow_t le return 0; #else hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_ENOIMPL, "unix address not supported"); - return -1; + return -1; #endif } @@ -386,14 +386,14 @@ int hawk_gem_ucharstoskad (hawk_gem_t* gem, const hawk_uch_t* str, hawk_oow_t le return -1; } - if (*p >= '0' && *p <= '9') + if (*p >= '0' && *p <= '9') { /* numeric scope id */ skad->in6.sin6_scope_id = 0; do { x = skad->in6.sin6_scope_id * 10 + (*p - '0'); - if (x < skad->in6.sin6_scope_id) + if (x < skad->in6.sin6_scope_id) { hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "scope id too large"); return -1; /* overflow */ @@ -431,9 +431,9 @@ int hawk_gem_ucharstoskad (hawk_gem_t* gem, const hawk_uch_t* str, hawk_oow_t le if (uchars_to_ipv4(tmp.ptr, tmp.len, &skad->in4.sin_addr) <= -1) { #if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0) - /* check if it is an IPv6 address not enclosed in []. + /* check if it is an IPv6 address not enclosed in []. * the port number can't be specified in this format. */ - if (p >= end || *p != ':') + if (p >= end || *p != ':') { /* without :, it can't be an ipv6 address */ goto unrecog; @@ -458,14 +458,14 @@ int hawk_gem_ucharstoskad (hawk_gem_t* gem, const hawk_uch_t* str, hawk_oow_t le return -1; } - if (*p >= '0' && *p <= '9') + if (*p >= '0' && *p <= '9') { /* numeric scope id */ skad->in6.sin6_scope_id = 0; do { x = skad->in6.sin6_scope_id * 10 + (*p - '0'); - if (x < skad->in6.sin6_scope_id) + if (x < skad->in6.sin6_scope_id) { hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "scope id too large"); return -1; /* overflow */ @@ -500,7 +500,7 @@ int hawk_gem_ucharstoskad (hawk_gem_t* gem, const hawk_uch_t* str, hawk_oow_t le } #endif - if (p < end && *p == ':') + if (p < end && *p == ':') { /* port number */ hawk_uint32_t port = 0; @@ -515,8 +515,8 @@ int hawk_gem_ucharstoskad (hawk_gem_t* gem, const hawk_uch_t* str, hawk_oow_t le } tmp.len = p - tmp.ptr; - if (tmp.len <= 0 || tmp.len >= 6 || - port > HAWK_TYPE_MAX(hawk_uint16_t)) + if (tmp.len <= 0 || tmp.len >= 6 || + port > HAWK_TYPE_MAX(hawk_uint16_t)) { hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "port number blank or too large"); return -1; @@ -537,7 +537,7 @@ int hawk_gem_ucharstoskad (hawk_gem_t* gem, const hawk_uch_t* str, hawk_oow_t le unrecog: hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "unrecognized address"); return -1; - + no_rbrack: hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "missing right bracket"); return -1; @@ -555,7 +555,7 @@ int hawk_gem_bcharstoskad (hawk_gem_t* gem, const hawk_bch_t* str, hawk_oow_t le p = str; end = str + len; - if (p >= end) + if (p >= end) { hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "blank address"); return -1; @@ -573,7 +573,7 @@ int hawk_gem_bcharstoskad (hawk_gem_t* gem, const hawk_bch_t* str, hawk_oow_t le return 0; #else hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_ENOIMPL, "unix address not supported"); - return -1; + return -1; #endif } @@ -601,14 +601,14 @@ int hawk_gem_bcharstoskad (hawk_gem_t* gem, const hawk_bch_t* str, hawk_oow_t le return -1; } - if (*p >= '0' && *p <= '9') + if (*p >= '0' && *p <= '9') { /* numeric scope id */ skad->in6.sin6_scope_id = 0; do { x = skad->in6.sin6_scope_id * 10 + (*p - '0'); - if (x < skad->in6.sin6_scope_id) + if (x < skad->in6.sin6_scope_id) { hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "scope id too large"); return -1; /* overflow */ @@ -646,9 +646,9 @@ int hawk_gem_bcharstoskad (hawk_gem_t* gem, const hawk_bch_t* str, hawk_oow_t le if (bchars_to_ipv4(tmp.ptr, tmp.len, &skad->in4.sin_addr) <= -1) { #if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0) - /* check if it is an IPv6 address not enclosed in []. + /* check if it is an IPv6 address not enclosed in []. * the port number can't be specified in this format. */ - if (p >= end || *p != ':') + if (p >= end || *p != ':') { /* without :, it can't be an ipv6 address */ goto unrecog; @@ -674,14 +674,14 @@ int hawk_gem_bcharstoskad (hawk_gem_t* gem, const hawk_bch_t* str, hawk_oow_t le return -1; } - if (*p >= '0' && *p <= '9') + if (*p >= '0' && *p <= '9') { /* numeric scope id */ skad->in6.sin6_scope_id = 0; do { x = skad->in6.sin6_scope_id * 10 + (*p - '0'); - if (x < skad->in6.sin6_scope_id) + if (x < skad->in6.sin6_scope_id) { hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "scope id too large"); return -1; /* overflow */ @@ -716,7 +716,7 @@ int hawk_gem_bcharstoskad (hawk_gem_t* gem, const hawk_bch_t* str, hawk_oow_t le } #endif - if (p < end && *p == ':') + if (p < end && *p == ':') { /* port number */ hawk_uint32_t port = 0; @@ -731,8 +731,8 @@ int hawk_gem_bcharstoskad (hawk_gem_t* gem, const hawk_bch_t* str, hawk_oow_t le } tmp.len = p - tmp.ptr; - if (tmp.len <= 0 || tmp.len >= 6 || - port > HAWK_TYPE_MAX(hawk_uint16_t)) + if (tmp.len <= 0 || tmp.len >= 6 || + port > HAWK_TYPE_MAX(hawk_uint16_t)) { hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "port number blank or too large"); return -1; @@ -852,9 +852,9 @@ static hawk_oow_t ip6ad_to_ucstr (const struct in6_addr* ipad, hawk_uch_t* buf, cur.base = -1; cur.len = 0; - for (i = 0; i < IP6ADDR_NWORDS; i++) + for (i = 0; i < IP6ADDR_NWORDS; i++) { - if (words[i] == 0) + if (words[i] == 0) { if (cur.base == -1) { @@ -866,16 +866,16 @@ static hawk_oow_t ip6ad_to_ucstr (const struct in6_addr* ipad, hawk_uch_t* buf, cur.len++; } } - else + else { - if (cur.base != -1) + if (cur.base != -1) { if (best.base == -1 || cur.len > best.len) best = cur; cur.base = -1; } } } - if (cur.base != -1) + if (cur.base != -1) { if (best.base == -1 || cur.len > best.len) best = cur; } @@ -885,11 +885,11 @@ static hawk_oow_t ip6ad_to_ucstr (const struct in6_addr* ipad, hawk_uch_t* buf, * Format the result. */ tp = tmp; - for (i = 0; i < IP6ADDR_NWORDS; i++) + for (i = 0; i < IP6ADDR_NWORDS; i++) { /* Are we inside the best run of 0x00's? */ if (best.base != -1 && i >= best.base && - i < (best.base + best.len)) + i < (best.base + best.len)) { if (i == best.base) *tp++ = ':'; continue; @@ -899,7 +899,7 @@ static hawk_oow_t ip6ad_to_ucstr (const struct in6_addr* ipad, hawk_uch_t* buf, if (i != 0) *tp++ = ':'; /* Is this address an encapsulated IPv4? ipv4-compatible or ipv4-mapped */ - if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) + if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { struct in_addr ip4ad; HAWK_MEMCPY (&ip4ad.s_addr, ipad->s6_addr + 12, HAWK_SIZEOF(ip4ad.s_addr)); @@ -992,7 +992,7 @@ hawk_oow_t hawk_gem_skadtoucstr (hawk_gem_t* gem, const hawk_skad_t* _skad, hawk if (flags & HAWK_SKAD_TO_BCSTR_PORT) { - if (!(flags & HAWK_SKAD_TO_BCSTR_ADDR) || skad->in6.sin6_port != 0) + if (!(flags & HAWK_SKAD_TO_BCSTR_ADDR) || skad->in6.sin6_port != 0) { if (flags & HAWK_SKAD_TO_BCSTR_ADDR) { @@ -1101,9 +1101,9 @@ static hawk_oow_t ip6ad_to_bcstr (const struct in6_addr* ipad, hawk_bch_t* buf, cur.base = -1; cur.len = 0; - for (i = 0; i < IP6ADDR_NWORDS; i++) + for (i = 0; i < IP6ADDR_NWORDS; i++) { - if (words[i] == 0) + if (words[i] == 0) { if (cur.base == -1) { @@ -1115,16 +1115,16 @@ static hawk_oow_t ip6ad_to_bcstr (const struct in6_addr* ipad, hawk_bch_t* buf, cur.len++; } } - else + else { - if (cur.base != -1) + if (cur.base != -1) { if (best.base == -1 || cur.len > best.len) best = cur; cur.base = -1; } } } - if (cur.base != -1) + if (cur.base != -1) { if (best.base == -1 || cur.len > best.len) best = cur; } @@ -1134,11 +1134,11 @@ static hawk_oow_t ip6ad_to_bcstr (const struct in6_addr* ipad, hawk_bch_t* buf, * Format the result. */ tp = tmp; - for (i = 0; i < IP6ADDR_NWORDS; i++) + for (i = 0; i < IP6ADDR_NWORDS; i++) { /* Are we inside the best run of 0x00's? */ if (best.base != -1 && i >= best.base && - i < (best.base + best.len)) + i < (best.base + best.len)) { if (i == best.base) *tp++ = ':'; continue; @@ -1148,7 +1148,7 @@ static hawk_oow_t ip6ad_to_bcstr (const struct in6_addr* ipad, hawk_bch_t* buf, if (i != 0) *tp++ = ':'; /* Is this address an encapsulated IPv4? ipv4-compatible or ipv4-mapped */ - if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) + if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { struct in_addr ip4ad; HAWK_MEMCPY (&ip4ad.s_addr, ipad->s6_addr + 12, HAWK_SIZEOF(ip4ad.s_addr)); @@ -1242,7 +1242,7 @@ hawk_oow_t hawk_gem_skadtobcstr (hawk_gem_t* gem, const hawk_skad_t* _skad, hawk if (flags & HAWK_SKAD_TO_BCSTR_PORT) { - if (!(flags & HAWK_SKAD_TO_BCSTR_ADDR) || skad->in6.sin6_port != 0) + if (!(flags & HAWK_SKAD_TO_BCSTR_ADDR) || skad->in6.sin6_port != 0) { if (flags & HAWK_SKAD_TO_BCSTR_ADDR) { @@ -1510,7 +1510,7 @@ int hawk_equal_skads (const hawk_skad_t* addr1, const hawk_skad_t* addr2, int st #if defined(AF_INET6) && (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0) case AF_INET6: - + if (strict) { /* don't care about scope id */ @@ -1659,7 +1659,7 @@ int hawk_ipad_bytes_is_loop_back (const hawk_uint8_t* iptr, hawk_oow_t ilen) { hawk_uint32_t* x = (hawk_uint32_t*)iptr; return (x[0] == 0 && x[1] == 0 && x[2] == 0 && x[3] == HAWK_CONST_HTON32(1)) || /* TODO: is this alignment safe? */ - (hawk_ipad_bytes_is_v4_mapped(iptr, ilen) && (x[3] & HAWK_CONST_HTON32(0xFF000000u)) == HAWK_CONST_HTON32(0x7F000000u)); + (hawk_ipad_bytes_is_v4_mapped(iptr, ilen) && (x[3] & HAWK_CONST_HTON32(0xFF000000u)) == HAWK_CONST_HTON32(0x7F000000u)); } default: diff --git a/lib/std-sed.c b/lib/std-sed.c index 04612edb..2e48b0b9 100644 --- a/lib/std-sed.c +++ b/lib/std-sed.c @@ -88,13 +88,13 @@ static int int_to_str (hawk_oow_t val, hawk_ooch_t* buf, hawk_oow_t buflen) buf[rlen] = HAWK_T('\0'); t = val; - if (t == 0) buf[0] = HAWK_T('0'); + if (t == 0) buf[0] = HAWK_T('0'); else { if (t < 0) t = -t; /* fill in the buffer with digits */ - while (t > 0) + while (t > 0) { buf[--rlen] = (hawk_ooch_t)(t % 10) + HAWK_T('0'); t /= 10; @@ -133,7 +133,7 @@ static int verify_iostd_in (hawk_sed_t* sed, hawk_sed_iostd_t in[]) if (in[0].type == HAWK_SED_IOSTD_NULL) { - /* if 'in' is specified, it must contains at least one + /* if 'in' is specified, it must contains at least one * valid entry */ hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_EINVAL, "no input handler provided"); return -1; @@ -162,7 +162,7 @@ static hawk_sio_t* open_sio_file (hawk_sed_t* sed, const hawk_ooch_t* file, int hawk_sio_t* sio; sio = hawk_sio_open(hawk_sed_getgem(sed), 0, file, flags); - if (sio == HAWK_NULL) + if (sio == HAWK_NULL) { const hawk_ooch_t* bem = hawk_sed_backuperrmsg(sed); hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to open %js - %js", file, bem); @@ -262,7 +262,7 @@ static hawk_sio_t* open_sio_std (hawk_sed_t* sed, hawk_sio_std_t std, int flags) hawk_sio_t* sio; sio = hawk_sio_openstd(hawk_sed_getgem(sed), 0, std, flags); - if (sio == HAWK_NULL) + if (sio == HAWK_NULL) { const hawk_ooch_t* bem = hawk_sed_backuperrmsg(sed); hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to open %js - %js", &sio_std_names[std], bem); @@ -352,8 +352,8 @@ static int open_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_sed_ { hawk_sio_t* sio; hawk_ooch_t* path; - - if (io->u.fileb.path == HAWK_NULL || + + if (io->u.fileb.path == HAWK_NULL || (io->u.fileb.path[0] == '-' && io->u.fileb.path[1] == '\0')) { sio = open_sio_std(sed, HAWK_SIO_STDIN, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR); @@ -381,7 +381,7 @@ static int open_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_sed_ hawk_sio_t* sio; hawk_ooch_t* path; - if (io->u.fileu.path == HAWK_NULL || + if (io->u.fileu.path == HAWK_NULL || (io->u.fileu.path[0] == '-' && io->u.fileu.path[1] == '\0')) { sio = open_sio_std(sed, HAWK_SIO_STDIN, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR); @@ -448,19 +448,19 @@ static int open_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_sed_ hawk_ooch_t buf[64]; /* format an identifier to be something like M#1, S#5 */ - buf[0] = (io->type == HAWK_SED_IOSTD_OOCS || + buf[0] = (io->type == HAWK_SED_IOSTD_OOCS || io->type == HAWK_SED_IOSTD_BCS || io->type == HAWK_SED_IOSTD_UCS)? HAWK_T('M'): HAWK_T('S'); buf[1] = HAWK_T('#'); int_to_str (io - xtn->s.in.ptr, &buf[2], HAWK_COUNTOF(buf) - 2); - /* don't care about failure int_to_str() though it's not + /* don't care about failure int_to_str() though it's not * likely to happen */ - hawk_sed_setcompid (sed, buf); + hawk_sed_setcompid (sed, buf); break; } } - sed->src.loc.line = 1; + sed->src.loc.line = 1; sed->src.loc.colm = 1; } return 0; @@ -597,7 +597,7 @@ static hawk_ooi_t read_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, ha { io = base->cur; - if (base == &xtn->s.in && xtn->s.newline_squeezed) + if (base == &xtn->s.in && xtn->s.newline_squeezed) { xtn->s.newline_squeezed = 0; goto open_next; @@ -656,7 +656,7 @@ static hawk_ooi_t read_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, ha } #endif } - else + else { n = hawk_sio_getoochars(arg->handle, buf, len); if (n <= -1) @@ -666,7 +666,7 @@ static hawk_ooi_t read_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, ha } } - if (n != 0) + if (n != 0) { if (base == &xtn->s.in) { @@ -683,7 +683,7 @@ static hawk_ooi_t read_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, ha if (base == &xtn->s.in && xtn->s.last != HAWK_T('\n')) { /* TODO: different line termination convension */ - buf[0] = HAWK_T('\n'); + buf[0] = HAWK_T('\n'); n = 1; xtn->s.newline_squeezed = 1; break; @@ -691,10 +691,10 @@ static hawk_ooi_t read_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, ha open_next: next = base->cur + 1; - if (next->type == HAWK_SED_IOSTD_NULL) + if (next->type == HAWK_SED_IOSTD_NULL) { /* no next stream available - return 0 */ - break; + break; } old = arg->handle; @@ -769,7 +769,7 @@ static hawk_ooi_t x_in (hawk_sed_t* sed, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_ if (arg->path == HAWK_NULL) { /* main data stream */ - if (xtn->e.in.ptr == HAWK_NULL) + if (xtn->e.in.ptr == HAWK_NULL) { /* HAWK_NULL passed into hawk_sed_exec() for input. open stdin */ sio = open_sio_std(sed, HAWK_SIO_STDIN, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR); @@ -798,7 +798,7 @@ static hawk_ooi_t x_in (hawk_sed_t* sed, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_ if (arg->path == HAWK_NULL) { /* main data stream */ - if (xtn->e.in.ptr == HAWK_NULL) + if (xtn->e.in.ptr == HAWK_NULL) hawk_sio_close (arg->handle); else close_main_stream (sed, arg, xtn->e.in.cur); @@ -820,7 +820,7 @@ static hawk_ooi_t x_in (hawk_sed_t* sed, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_ { hawk_ooi_t n; n = hawk_sio_getoochars(arg->handle, buf, len); - if (n <= -1) + if (n <= -1) { const hawk_ooch_t* bem = hawk_sed_backuperrmsg(sed); hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to read '%js' - %js", &sio_std_names[HAWK_SIO_STDIN], bem); @@ -867,7 +867,7 @@ static hawk_ooi_t x_out ( { /* main data stream */ - if (xtn->e.out.ptr == HAWK_NULL) + if (xtn->e.out.ptr == HAWK_NULL) { /* HAWK_NULL passed into hawk_sed_execstd() for output */ sio = open_sio_std( @@ -907,7 +907,7 @@ static hawk_ooi_t x_out ( { if (arg->path == HAWK_NULL) { - if (xtn->e.out.ptr == HAWK_NULL) + if (xtn->e.out.ptr == HAWK_NULL) hawk_sio_close (arg->handle); else close_main_stream (sed, arg, xtn->e.out.ptr); @@ -982,7 +982,7 @@ static hawk_ooi_t x_out ( return n; } } - + default: HAWK_ASSERT (!"should never happen - cmd must be one of OPEN,CLOSE,WRITE"); hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINTERN); @@ -1002,7 +1002,7 @@ int hawk_sed_compstd (hawk_sed_t* sed, hawk_sed_iostd_t in[], hawk_oow_t* count) if (count) *count = 0; return -1; } - if (verify_iostd_in(sed, in) <= -1) + if (verify_iostd_in(sed, in) <= -1) { if (count) *count = 0; return -1; diff --git a/lib/std.c b/lib/std.c index ad9001bd..bc6749ee 100644 --- a/lib/std.c +++ b/lib/std.c @@ -88,7 +88,7 @@ typedef struct xtn_t { struct { - struct + struct { hawk_parsestd_t* x; hawk_oow_t xindex; @@ -97,7 +97,7 @@ typedef struct xtn_t { /* nothing to maintain here for file */ - struct + struct { const hawk_ooch_t* ptr; const hawk_ooch_t* end; @@ -124,15 +124,15 @@ typedef struct xtn_t { hawk_sio_t* sio; } file; - struct + struct { hawk_ooecs_t* buf; } oocs; - struct + struct { hawk_becs_t* buf; } bcs; - struct + struct { hawk_uecs_t* buf; } ucs; @@ -164,14 +164,14 @@ typedef struct rxtn_t { struct { - struct + struct { hawk_ooch_t** files; hawk_oow_t index; hawk_oow_t count; /* number of files opened so far */ - } in; + } in; - struct + struct { hawk_ooch_t** files; hawk_oow_t index; @@ -275,7 +275,7 @@ int hawk_stdmodstartup (hawk_t* hawk) { #if defined(USE_LTDL) - /* lt_dlinit() can be called more than once and + /* lt_dlinit() can be called more than once and * lt_dlexit() shuts down libltdl if it's called as many times as * corresponding lt_dlinit(). so it's safe to call lt_dlinit() * and lt_dlexit() at the library level. */ @@ -324,7 +324,7 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec) static hawk_ooch_t ds[] = { '/', '\0' }; count = 0; - if (spec->libdir) + if (spec->libdir) { hawk_oow_t len; @@ -380,13 +380,13 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec) static hawk_ooch_t ds[][2] = { { '\\', '\0' }, { '/', '\0' } }; count = 0; - if (spec->libdir) + if (spec->libdir) { hawk_oow_t len; tmp[count++] = spec->libdir; len = hawk_count_oocstr(spec->libdir); - if (len > 0 && (spec->libdir[len - 1] != '/' && spec->libdir[len - 1] != '\\')) + if (len > 0 && (spec->libdir[len - 1] != '/' && spec->libdir[len - 1] != '\\')) { tmp[count++] = ds[hawk_find_oochar_in_oocstr(spec->libdir, '/') != HAWK_NULL]; } @@ -428,7 +428,7 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec) static hawk_ooch_t ds[] = { '\\', '\0' }; count = 0; - if (spec->libdir) + if (spec->libdir) { hawk_oow_t len; @@ -448,10 +448,10 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec) #endif if (HAWK_UNLIKELY(!modpath)) return HAWK_NULL; - /* DosLoadModule() seems to have severe limitation on + /* DosLoadModule() seems to have severe limitation on * the file name it can load (max-8-letters.xxx) */ rc = DosLoadModule(errbuf, HAWK_COUNTOF(errbuf) - 1, modpath, &h); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { h = HAWK_NULL; hawk_seterrnum (hawk, HAWK_NULL, hawk_syserr_to_errnum(rc)); @@ -482,7 +482,7 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec) static hawk_ooch_t ds[] = { '\\', '\0' }; count = 0; - if (spec->libdir) + if (spec->libdir) { hawk_oow_t len; @@ -506,7 +506,7 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec) if (!h) hawk_seterrnum (hawk, HAWK_NULL, HAWK_ESYSERR); hawk_freemem (hawk, modpath); - + HAWK_ASSERT (HAWK_SIZEOF(h) <= HAWK_SIZEOF(void*)); return h; } @@ -528,7 +528,7 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec) static hawk_ooch_t ds[] = { '/', '\0' }; count = 0; - if (spec->libdir) + if (spec->libdir) { hawk_oow_t len; @@ -600,7 +600,7 @@ void* hawk_stdmodgetsym (hawk_t* hawk, void* handle, const hawk_ooch_t* name) #if defined(USE_LTDL) s = lt_dlsym(handle, mname); if (!s) hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ESYSERR, HAWK_T("%hs"), lt_dlerror()); - + #elif defined(_WIN32) s = GetProcAddress((HMODULE)handle, mname); if (!s) hawk_seterrnum (hawk, HAWK_NULL, hawk_syserr_to_errnum(GetLastError()); @@ -609,7 +609,7 @@ void* hawk_stdmodgetsym (hawk_t* hawk, void* handle, const hawk_ooch_t* name) { APIRET rc; rc = DosQueryProcAddr((HMODULE)handle, 0, mname, (PFN*)&s); - if (rc != NO_ERROR) + if (rc != NO_ERROR) { s = HAWK_NULL; hawk_seterrnum (hawk, HAWK_NULL, hawk_syserr_to_errnum(rc)); @@ -659,7 +659,7 @@ EM_JS(int, write_all, (int, const hawk_bch_t* ptr, hawk_oow_t len), { // Use the heap memory and pass the right portion to UTF8Decoder. //console.log ("%s", UTF8ToString(ptr, len)); console.log ("%s", UTF8Decoder.decode(HEAPU8.subarray(ptr, ptr + len))); - return 0; + return 0; }); #else @@ -781,7 +781,7 @@ static void log_write (hawk_t* hawk, hawk_bitmask_t mask, const hawk_ooch_t* msg { logfd = xtn->log.fd; #if !defined(EMSCRIPTEN) - if (logfd <= -1) + if (logfd <= -1) { return; } @@ -810,18 +810,18 @@ static void log_write (hawk_t* hawk, hawk_bitmask_t mask, const hawk_ooch_t* msg /* %z for strftime() in win32 seems to produce a long non-numeric timezone name. * i don't use strftime() for time formatting. */ GetLocalTime (&now); - if (GetTimeZoneInformation(&tzi) != TIME_ZONE_ID_INVALID) + if (GetTimeZoneInformation(&tzi) != TIME_ZONE_ID_INVALID) { tzi.Bias = -tzi.Bias; - tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d %+02.2d%02.2d ", - (int)now.wYear, (int)now.wMonth, (int)now.wDay, + tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d %+02.2d%02.2d ", + (int)now.wYear, (int)now.wMonth, (int)now.wDay, (int)now.wHour, (int)now.wMinute, (int)now.wSecond, (int)(tzi.Bias / 60), (int)(tzi.Bias % 60)); } else { tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", - (int)now.wYear, (int)now.wMonth, (int)now.wDay, + (int)now.wYear, (int)now.wMonth, (int)now.wDay, (int)now.wHour, (int)now.wMinute, (int)now.wSecond); } #elif defined(__OS2__) @@ -839,7 +839,7 @@ static void log_write (hawk_t* hawk, hawk_bitmask_t mask, const hawk_ooch_t* msg #else tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %z ", tmp); #endif - if (tslen == 0) + if (tslen == 0) { tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); } @@ -860,9 +860,9 @@ static void log_write (hawk_t* hawk, hawk_bitmask_t mask, const hawk_ooch_t* msg #if defined(HAVE_STRFTIME_SMALL_Z) tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %z ", tmp); #else - tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %Z ", tmp); + tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %Z ", tmp); #endif - if (tslen == 0) + if (tslen == 0) { tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); } @@ -889,9 +889,9 @@ static void log_write (hawk_t* hawk, hawk_bitmask_t mask, const hawk_ooch_t* msg n = hawk_conv_uchars_to_bchars_with_cmgr(&msg[msgidx], &ucslen, buf, &bcslen, hawk_getcmgr(hawk)); if (n == 0 || n == -2) { - /* n = 0: - * converted all successfully - * n == -2: + /* n = 0: + * converted all successfully + * n == -2: * buffer not sufficient. not all got converted yet. * write what have been converted this round. */ @@ -979,7 +979,7 @@ hawk_t* hawk_openstdwithmmgr (hawk_mmgr_t* mmgr, hawk_oow_t xtnsize, hawk_cmgr_t /* #if defined(USE_DLFCN) - if (hawk_setopt(hawk, HAWK_OPT_MODPOSTFIX, HAWK_T(".so")) <= -1) + if (hawk_setopt(hawk, HAWK_OPT_MODPOSTFIX, HAWK_T(".so")) <= -1) { if (errnum) *errnum = hawk_geterrnum(hawk); goto oops; @@ -993,13 +993,13 @@ hawk_t* hawk_openstdwithmmgr (hawk_mmgr_t* mmgr, hawk_oow_t xtnsize, hawk_cmgr_t reset_log_to_default (xtn); /* add intrinsic global variables and functions */ - if (add_globals(hawk) <= -1 || add_functions(hawk) <= -1) + if (add_globals(hawk) <= -1 || add_functions(hawk) <= -1) { if (errnum) *errnum = hawk_geterrnum(hawk); goto oops; } - if (hawk_stdmodstartup(hawk) <= -1) + if (hawk_stdmodstartup(hawk) <= -1) { xtn->stdmod_up = 0; /* carry on regardless of failure */ @@ -1037,7 +1037,7 @@ static hawk_sio_t* open_sio_rtx (hawk_rtx_t* rtx, const hawk_ooch_t* file, int f { hawk_sio_t* sio; sio = hawk_sio_open(hawk_rtx_getgem(rtx), 0, file, flags); - if (sio == HAWK_NULL) + if (sio == HAWK_NULL) { const hawk_ooch_t* bem = hawk_rtx_backuperrmsg(rtx); hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), file, bem); @@ -1056,7 +1056,7 @@ static hawk_sio_t* open_sio_std (hawk_t* hawk, hawk_sio_std_t std, int flags) { hawk_sio_t* sio; sio = hawk_sio_openstd(hawk_getgem(hawk), 0, std, flags); - if (sio == HAWK_NULL) + if (sio == HAWK_NULL) { const hawk_ooch_t* bem = hawk_backuperrmsg(hawk); hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), &sio_std_names[std], bem); @@ -1069,7 +1069,7 @@ static hawk_sio_t* open_sio_std_rtx (hawk_rtx_t* rtx, hawk_sio_std_t std, int fl hawk_sio_t* sio; sio = hawk_sio_openstd(hawk_rtx_getgem(rtx), 0, std, flags); - if (sio == HAWK_NULL) + if (sio == HAWK_NULL) { const hawk_ooch_t* bem = hawk_rtx_backuperrmsg(rtx); hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), &sio_std_names[std], bem); @@ -1435,7 +1435,7 @@ static hawk_ooi_t sf_in_read (hawk_t* hawk, hawk_sio_arg_t* arg, hawk_ooch_t* da const hawk_ooch_t* bem = hawk_backuperrmsg(hawk); const hawk_uch_t* path; path = xtn->s.in.x[xtn->s.in.xindex].u.fileu.path; - if (path) + if (path) hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to read %ls - %js"), path, bem); else hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to read %js - %js"), sio_std_names[HAWK_SIO_STDIN].ptr, bem); @@ -1453,7 +1453,7 @@ static hawk_ooi_t sf_in_read (hawk_t* hawk, hawk_sio_arg_t* arg, hawk_ooch_t* da const hawk_ooch_t* bem = hawk_backuperrmsg(hawk); const hawk_bch_t* path; path = xtn->s.in.x[xtn->s.in.xindex].u.fileb.path; - if (path) + if (path) hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to read %hs - %js"), path, bem); else hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to read %js - %js"), sio_std_names[HAWK_SIO_STDIN].ptr, bem); @@ -1532,7 +1532,7 @@ static hawk_ooi_t sf_in_read (hawk_t* hawk, hawk_sio_arg_t* arg, hawk_ooch_t* da { /* open the next stream if available. */ if (open_parsestd(hawk, arg, xtn, next) <= -1) n = -1; - else + else { xtn->s.in.xindex = next; /* update the next to the current */ arg->line = 0; /* reset the line number */ @@ -1557,7 +1557,7 @@ static hawk_ooi_t sf_in_read (hawk_t* hawk, hawk_sio_arg_t* arg, hawk_ooch_t* da if (n <= -1) { const hawk_ooch_t* bem = hawk_backuperrmsg(hawk); - hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to read %js - %js"), arg->name, bem); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to read %js - %js"), arg->name, bem); } return n; } @@ -1715,7 +1715,7 @@ static hawk_ooi_t sf_out (hawk_t* hawk, hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg, const hawk_ooch_t* bem = hawk_backuperrmsg(hawk); ioname = xtn->s.out.x->u.file.path; if (!ioname) ioname = sio_std_names[HAWK_SIO_STDOUT].ptr; - hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EWRITE, HAWK_T("unable to write to %js - %js"), ioname, bem); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EWRITE, HAWK_T("unable to write to %js - %js"), ioname, bem); } return n; } @@ -1742,7 +1742,7 @@ static hawk_ooi_t sf_out (hawk_t* hawk, hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg, if (hawk_becs_setlen(xtn->s.out.u.bcs.buf, orglen + mbslen) == (hawk_oow_t)-1) return -1; wcslen = size; - hawk_convutobchars (hawk, data, &wcslen, HAWK_BECS_CPTR(xtn->s.out.u.bcs.buf, orglen), &mbslen); + hawk_convutobchars (hawk, data, &wcslen, HAWK_BECS_CPTR(xtn->s.out.u.bcs.buf, orglen), &mbslen); size = wcslen; return size; @@ -1795,14 +1795,14 @@ int hawk_parsestd (hawk_t* hawk, hawk_parsestd_t in[], hawk_parsestd_t* out) xtn_t* xtn = GET_XTN(hawk); int n; - if (in == HAWK_NULL || (in[0].type != HAWK_PARSESTD_FILE && - in[0].type != HAWK_PARSESTD_FILEB && - in[0].type != HAWK_PARSESTD_FILEU && + if (in == HAWK_NULL || (in[0].type != HAWK_PARSESTD_FILE && + in[0].type != HAWK_PARSESTD_FILEB && + in[0].type != HAWK_PARSESTD_FILEU && in[0].type != HAWK_PARSESTD_OOCS && in[0].type != HAWK_PARSESTD_BCS && in[0].type != HAWK_PARSESTD_UCS)) { - /* the input is a must. at least 1 file or 1 string + /* the input is a must. at least 1 file or 1 string * must be specified */ hawk_seterrnum (hawk, HAWK_NULL, HAWK_EINVAL); return -1; @@ -1908,7 +1908,7 @@ static hawk_ooi_t nwio_handler_open (hawk_rtx_t* rtx, hawk_rio_arg_t* riod, int hawk_nwio_t* handle; handle = hawk_nwio_open ( - hawk_rtx_getmmgr(rtx), 0, nwad, + hawk_rtx_getmmgr(rtx), 0, nwad, flags | HAWK_NWIO_TEXT | HAWK_NWIO_IGNOREECERR | HAWK_NWIO_REUSEADDR | HAWK_NWIO_READNORETRY | HAWK_NWIO_WRITENORETRY, tmout @@ -2012,7 +2012,7 @@ static hawk_ooi_t pio_handler_open (hawk_rtx_t* rtx, hawk_rio_arg_t* riod) { flags = HAWK_PIO_READOUT | HAWK_PIO_ERRTOOUT | HAWK_PIO_WRITEIN; } - else + else { /* this must not happen */ hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN); @@ -2021,8 +2021,8 @@ static hawk_ooi_t pio_handler_open (hawk_rtx_t* rtx, hawk_rio_arg_t* riod) handle = hawk_pio_open( hawk_rtx_getgem(rtx), - 0, - riod->name, + 0, + riod->name, flags | HAWK_PIO_SHELL | HAWK_PIO_TEXT | HAWK_PIO_IGNOREECERR ); if (handle == HAWK_NULL) return -1; @@ -2030,7 +2030,7 @@ static hawk_ooi_t pio_handler_open (hawk_rtx_t* rtx, hawk_rio_arg_t* riod) #if defined(HAWK_OOCH_IS_UCH) { hawk_cmgr_t* cmgr = hawk_rtx_getiocmgrstd(rtx, riod->name); - if (cmgr) + if (cmgr) { hawk_pio_setcmgr (handle, HAWK_PIO_IN, cmgr); hawk_pio_setcmgr (handle, HAWK_PIO_OUT, cmgr); @@ -2109,7 +2109,7 @@ static hawk_ooi_t hawk_rio_pipe (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_a hawk_nwad_t nwad; if (riod->mode != HAWK_RIO_PIPE_RW || - parse_rwpipe_uri(riod->name, &flags, &nwad) <= -1) + parse_rwpipe_uri(riod->name, &flags, &nwad) <= -1) { return pio_handler_open (rtx, riod); } @@ -2149,7 +2149,7 @@ static hawk_ooi_t hawk_rio_pipe (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_a static void set_rio_error (hawk_rtx_t* rtx, hawk_errnum_t errnum, const hawk_ooch_t* errmsg, const hawk_ooch_t* path) { const hawk_ooch_t* bem = hawk_rtx_backuperrmsg(rtx); - hawk_rtx_seterrfmt (rtx, HAWK_NULL, errnum, HAWK_T("%js%js%js - %js"), + hawk_rtx_seterrfmt (rtx, HAWK_NULL, errnum, HAWK_T("%js%js%js - %js"), errmsg, (path? HAWK_T(" "): HAWK_T("")), (path? path: HAWK_T("")), bem); } @@ -2164,7 +2164,7 @@ static hawk_ooi_t hawk_rio_file (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_a switch (riod->mode) { - case HAWK_RIO_FILE_READ: + case HAWK_RIO_FILE_READ: flags |= HAWK_SIO_READ; break; case HAWK_RIO_FILE_WRITE: @@ -2176,7 +2176,7 @@ static hawk_ooi_t hawk_rio_file (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_a default: /* this must not happen */ hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN); - return -1; + return -1; } if (riod->name[0] == '-' && riod->name[1] == '\0') @@ -2190,7 +2190,7 @@ static hawk_ooi_t hawk_rio_file (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_a { handle = hawk_sio_open(hawk_rtx_getgem(rtx), 0, riod->name, flags); } - if (!handle) + if (!handle) { set_rio_error (rtx, HAWK_EOPEN, HAWK_T("unable to open"), riod->name); return -1; @@ -2293,17 +2293,17 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod) if (hawk_rtx_valtoint(rtx, v_argc, &i_argc) <= -1) return -1; /* handle special case when ARGV[x] has been altered. - * so from here down, the file name gotten from - * rxtn->c.in.files is not important and is overridden + * so from here down, the file name gotten from + * rxtn->c.in.files is not important and is overridden * from ARGV. - * 'BEGIN { ARGV[1]="file3"; } + * 'BEGIN { ARGV[1]="file3"; } * { print $0; }' file1 file2 */ v_argv = hawk_rtx_getgbl(rtx, xtn->gbl_argv); HAWK_ASSERT (v_argv != HAWK_NULL); if (HAWK_RTX_GETVALTYPE(rtx, v_argv) != HAWK_VAL_MAP) { - /* with flexmap on, you can change ARGV to a scalar. + /* with flexmap on, you can change ARGV to a scalar. * BEGIN { ARGV="xxx"; } * you must not do this. */ hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_EINVAL, HAWK_T("phony value in ARGV")); @@ -2332,7 +2332,7 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod) return 1; } - return 0; + return 0; } ibuflen = hawk_int_to_oocstr(rxtn->c.in.index + 1, 10, HAWK_NULL, ibuf, HAWK_COUNTOF(ibuf)); @@ -2371,8 +2371,8 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod) /* * this is different from the -v option. - * if an argument has a special form of var=val, it is treated specially - * + * if an argument has a special form of var=val, it is treated specially + * * on the command-line * hawk -f a.hawk a=20 /etc/passwd * or via ARGV @@ -2387,7 +2387,7 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod) goto nextfile; } - /* a temporary variable sio is used here not to change + /* a temporary variable sio is used here not to change * any fields of riod when the open operation fails */ sio = (file[0] == HAWK_T('-') && file[1] == HAWK_T('\0'))? open_sio_std_rtx(rtx, HAWK_SIO_STDIN, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR): @@ -2415,12 +2415,12 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod) rxtn->c.in.index++; return 1; #else - /* simple console open implementation. + /* simple console open implementation. * no var=val handling. no ARGV handling */ if (!rxtn->c.in.files) { - /* if no input files is specified, + /* if no input files is specified, * open the standard input */ HAWK_ASSERT (rxtn->c.in.index == 0); @@ -2441,7 +2441,7 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod) } else { - /* a temporary variable sio is used here not to change + /* a temporary variable sio is used here not to change * any fields of riod when the open operation fails */ const hawk_ooch_t* file; @@ -2454,7 +2454,7 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod) return 0; } - if (file[0] == '\0') + if (file[0] == '\0') { rxtn->c.in.index++; goto nextfile; @@ -2507,7 +2507,7 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod) } else { - /* a temporary variable sio is used here not to change + /* a temporary variable sio is used here not to change * any fields of riod when the open operation fails */ hawk_sio_t* sio; const hawk_ooch_t* file; @@ -2526,7 +2526,7 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod) if (sio == HAWK_NULL) return -1; if (rxtn->c.cmgr) hawk_sio_setcmgr (sio, rxtn->c.cmgr); - + if (hawk_rtx_setofilenamewithoochars(rtx, file, hawk_count_oocstr(file)) <= -1) { hawk_sio_close (sio); @@ -2567,7 +2567,7 @@ static hawk_ooi_t hawk_rio_console (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_ri n = open_rio_console(rtx, riod); if (n <= -1) return -1; - if (n == 0) + if (n == 0) { /* no more input console */ return 0; @@ -2595,7 +2595,7 @@ static hawk_ooi_t hawk_rio_console (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_ri n = open_rio_console(rtx, riod); if (n <= -1) return -1; - if (n == 0) + if (n == 0) { /* no more input console */ return 0; @@ -2648,7 +2648,7 @@ static hawk_ooi_t hawk_rio_console (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_ri n = open_rio_console (rtx, riod); if (n <= -1) return -1; - if (n == 0) + if (n == 0) { /* if there is no more file, keep the previous handle */ return 0; @@ -2713,13 +2713,13 @@ static int build_argcv (hawk_rtx_t* rtx, int argc_id, int argv_id, const hawk_oo /* make ARGV[0] */ v_tmp = hawk_rtx_makestrvalwithoocstr(rtx, id); - if (v_tmp == HAWK_NULL) + if (v_tmp == HAWK_NULL) { hawk_rtx_refdownval (rtx, v_argv); return -1; } - /* increment reference count of v_tmp in advance as if + /* increment reference count of v_tmp in advance as if * it has successfully been assigned into ARGV. */ hawk_rtx_refupval (rtx, v_tmp); @@ -2739,11 +2739,11 @@ static int build_argcv (hawk_rtx_t* rtx, int argc_id, int argv_id, const hawk_oo if (icf) { - for (argc = 1, p = icf; *p; p++, argc++) + for (argc = 1, p = icf; *p; p++, argc++) { /* the argument must compose a numeric value if possible */ /*v_tmp = hawk_rtx_makenstrvalwithoocstr(rtx, *p); */ - v_tmp = hawk_rtx_makenumorstrvalwithoochars(rtx, *p, hawk_count_oocstr(*p)); + v_tmp = hawk_rtx_makenumorstrvalwithoochars(rtx, *p, hawk_count_oocstr(*p)); if (HAWK_UNLIKELY(!v_tmp)) { hawk_rtx_refdownval (rtx, v_argv); @@ -2837,11 +2837,11 @@ static int build_environ (hawk_rtx_t* rtx, int gbl_id, env_char_t* envarr[]) *eq = '\0'; - /* dupbtoucstr() may fail for invalid encoding. as the environment - * variaables are not under control, call mbstowcsalldup() instead + /* dupbtoucstr() may fail for invalid encoding. as the environment + * variaables are not under control, call mbstowcsalldup() instead * to go on despite encoding failure */ - kptr = hawk_rtx_dupbtoucstr(rtx, envarr[count], &klen, 1); + kptr = hawk_rtx_dupbtoucstr(rtx, envarr[count], &klen, 1); vptr = hawk_rtx_dupbtoucstr(rtx, eq + 1, &vlen, 1); if (HAWK_UNLIKELY(!kptr || !vptr)) { @@ -2872,7 +2872,7 @@ static int build_environ (hawk_rtx_t* rtx, int gbl_id, env_char_t* envarr[]) #endif /* the string in ENVIRON should be a numeric value if - * it can be converted to a number. + * it can be converted to a number. *v_tmp = hawk_rtx_makenstrvalwithoocstr(rtx, vptr);*/ v_tmp = hawk_rtx_makenumorstrvalwithoochars(rtx, vptr, vlen); if (HAWK_UNLIKELY(!v_tmp)) @@ -2888,7 +2888,7 @@ static int build_environ (hawk_rtx_t* rtx, int gbl_id, env_char_t* envarr[]) return -1; } - /* increment reference count of v_tmp in advance as if + /* increment reference count of v_tmp in advance as if * it has successfully been assigned into ARGV. */ hawk_rtx_refupval (rtx, v_tmp); @@ -2990,15 +2990,15 @@ static hawk_rtx_t* open_rtx_std ( /* FILENAME can be set when the input console is opened. * so we skip setting it here even if an explicit console file - * is specified. So the value of FILENAME is empty in the - * BEGIN block unless getline is ever met. + * is specified. So the value of FILENAME is empty in the + * BEGIN block unless getline is ever met. * * However, OFILENAME is different. The output - * console is treated as if it's already open upon start-up. + * console is treated as if it's already open upon start-up. * otherwise, 'BEGIN { print OFILENAME; }' prints an empty * string regardless of output console files specified. * That's because OFILENAME is evaluated before the output - * console file is opened. + * console file is opened. */ if (ocf && ocf[0]) { @@ -3195,7 +3195,7 @@ static HAWK_INLINE void init_ioattr (ioattr_t* ioattr) { int i; HAWK_MEMSET (ioattr, 0, HAWK_SIZEOF(*ioattr)); - for (i = 0; i < HAWK_COUNTOF(ioattr->tmout); i++) + for (i = 0; i < HAWK_COUNTOF(ioattr->tmout); i++) { /* a negative number for no timeout */ ioattr->tmout[i].sec = -999; @@ -3248,7 +3248,7 @@ static int fnc_setioattr (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) { v[i] = hawk_rtx_getarg(rtx, i); ptr[i] = hawk_rtx_getvaloocstr(rtx, v[i], &len[i]); - if (ptr[i] == HAWK_NULL) + if (ptr[i] == HAWK_NULL) { ret = -1; goto done; @@ -3269,13 +3269,13 @@ static int fnc_setioattr (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) hawk_flt_t r; int x; - /* no error is returned by hawk_rtx_strnum() if the strict option + /* no error is returned by hawk_rtx_strnum() if the strict option * of the second parameter is 0. so i don't check for an error */ x = hawk_oochars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr[2], len[2], &l, &r); if (x == 0) r = (hawk_flt_t)l; ioattr = find_or_make_ioattr(rtx, &rxtn->cmgrtab, ptr[0], len[0]); - if (ioattr == HAWK_NULL) + if (ioattr == HAWK_NULL) { ret = -1; goto done; @@ -3301,14 +3301,14 @@ static int fnc_setioattr (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) ioattr_t* ioattr; hawk_cmgr_t* cmgr; - if (ptr[2][0] == HAWK_T('\0')) + if (ptr[2][0] == HAWK_T('\0')) { cmgr = HAWK_NULL; } else { cmgr = hawk_get_cmgr_by_name(ptr[2]); - if (cmgr == HAWK_NULL) + if (cmgr == HAWK_NULL) { fret = -1; goto done; @@ -3316,7 +3316,7 @@ static int fnc_setioattr (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) } ioattr = find_or_make_ioattr(rtx, &rxtn->cmgrtab, ptr[0], len[0]); - if (ioattr == HAWK_NULL) + if (ioattr == HAWK_NULL) { ret = -1; goto done; @@ -3370,7 +3370,7 @@ static int fnc_getioattr (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) { v[i] = hawk_rtx_getarg (rtx, i); ptr[i] = hawk_rtx_getvaloocstr (rtx, v[i], &len[i]); - if (ptr[i] == HAWK_NULL) + if (ptr[i] == HAWK_NULL) { ret = -1; goto done; @@ -3380,7 +3380,7 @@ static int fnc_getioattr (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) } ioattr = get_ioattr(&rxtn->cmgrtab, ptr[0], len[0]); - if (ioattr == HAWK_NULL) + if (ioattr == HAWK_NULL) { init_ioattr (&ioattr_buf); ioattr = &ioattr_buf; @@ -3392,7 +3392,7 @@ static int fnc_getioattr (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) rv = hawk_rtx_makeintval(rtx, ioattr->tmout[tmout].sec); else rv = hawk_rtx_makefltval(rtx, (hawk_flt_t)ioattr->tmout[tmout].sec + HAWK_NSEC_TO_SEC((hawk_flt_t)ioattr->tmout[tmout].nsec)); - if (rv == HAWK_NULL) + if (rv == HAWK_NULL) { ret = -1; goto done; @@ -3432,7 +3432,7 @@ done: hawk_rtx_refdownval (rtx, rv); if (ret >= 0) hawk_rtx_setretval (rtx, HAWK_VAL_ZERO); } - else + else { hawk_rtx_setretval (rtx, HAWK_VAL_NEGONE); } @@ -3467,7 +3467,7 @@ static int add_globals (hawk_t* hawk) return (HAWK_UNLIKELY(xtn->gbl_argc <= -1 || xtn->gbl_argv <= -1 || xtn->gbl_environ <= -1))? -1: 0; } -struct fnctab_t +struct fnctab_t { const hawk_ooch_t* name; hawk_fnc_spec_t spec; @@ -3478,7 +3478,7 @@ static struct fnctab_t fnctab[] = /* additional aliases to module functions */ { HAWK_T("rand"), { {1, 0, HAWK_T("math")}, HAWK_NULL, 0 } }, { HAWK_T("srand"), { {1, 0, HAWK_T("math")}, HAWK_NULL, 0 } }, - { HAWK_T("system"), { {1, 0, HAWK_T("sys")}, HAWK_NULL , 0 } }, + { HAWK_T("system"), { {1, 0, HAWK_T("sys")}, HAWK_NULL , 0 } }, /* additional functions */ { HAWK_T("setioattr"), { {3, 3, HAWK_NULL}, fnc_setioattr, HAWK_RIO } }, diff --git a/lib/syscall.h b/lib/syscall.h index b4dd1edb..518c8d2f 100644 --- a/lib/syscall.h +++ b/lib/syscall.h @@ -552,7 +552,7 @@ so it's not practical to define HAWK_GETCWD(). /* ------------------------------------------------------------------------ */ -#if defined(__linux) && defined(__GNUC__) && defined(__x86_64) +#if defined(__linux) && defined(__GNUC__) && defined(__x86_64) #include @@ -565,8 +565,8 @@ The section is informative only. A.2.1 Calling Conventions The Linux AMD64 kernel uses internally the same calling conventions as user- -level applications (see section 3.2.3 for details). User-level applications -that like to call system calls should use the functions from the C library. +level applications (see section 3.2.3 for details). User-level applications +that like to call system calls should use the functions from the C library. The interface between the C library and the Linux kernel is the same as for the user-level applications with the following differences: @@ -576,7 +576,7 @@ the user-level applications with the following differences: 2. A system-call is done via the syscall instruction. The kernel destroys registers %rcx and %r11. 3. The number of the syscall has to be passed in register %rax. -4. System-calls are limited to six arguments, no argument is passed directly +4. System-calls are limited to six arguments, no argument is passed directly on the stack. 5. Returning from the syscall, register %rax contains the result of the system-call. A value in the range between -4095 and -1 indicates an error, @@ -632,7 +632,7 @@ the user-level applications with the following differences: : "a"((hawk_uint64_t)num) \ : "memory", "cc", "%rcx", "%r11" \ ) - + #define HAWK_SYSCALL1(ret,num,arg1) \ __asm__ volatile ( \ @@ -666,7 +666,7 @@ the user-level applications with the following differences: : "memory", "cc", "%rcx", "%r11" \ ) -#elif defined(__linux) && defined(__GNUC__) && defined(__i386) +#elif defined(__linux) && defined(__GNUC__) && defined(__i386) #include diff --git a/lib/tio.c b/lib/tio.c index d9f74b7a..367f8627 100644 --- a/lib/tio.c +++ b/lib/tio.c @@ -107,7 +107,7 @@ int hawk_tio_attachin ( { hawk_bch_t* xbufptr; - if (input == HAWK_NULL || bufcapa < HAWK_TIO_MININBUFCAPA) + if (input == HAWK_NULL || bufcapa < HAWK_TIO_MININBUFCAPA) { hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EINVAL); return -1; @@ -124,13 +124,13 @@ int hawk_tio_attachin ( if (xbufptr == HAWK_NULL) return -1; } - if (input(tio, HAWK_TIO_OPEN, HAWK_NULL, 0) <= -1) + if (input(tio, HAWK_TIO_OPEN, HAWK_NULL, 0) <= -1) { if (xbufptr != bufptr) hawk_gem_freemem (tio->gem, xbufptr); return -1; } - /* if i defined tio->io[2] instead of tio->in and tio-out, + /* if i defined tio->io[2] instead of tio->in and tio-out, * i would be able to shorten code amount. but fields to initialize * are not symmetric between input and output. * so it's just a bit clumsy that i repeat almost the same code @@ -155,17 +155,17 @@ static int detach_in (hawk_tio_t* tio, int fini) if (tio->in.fun) { - if (tio->in.fun(tio, HAWK_TIO_CLOSE, HAWK_NULL, 0) <= -1) + if (tio->in.fun(tio, HAWK_TIO_CLOSE, HAWK_NULL, 0) <= -1) { /* returning with an error here allows you to retry detaching */ - if (!fini) return -1; + if (!fini) return -1; /* otherwise, you can't retry since the input handler information * is reset below */ - ret = -1; + ret = -1; } - if (tio->status & STATUS_INPUT_DYNBUF) + if (tio->status & STATUS_INPUT_DYNBUF) { hawk_gem_freemem(tio->gem, tio->in.buf.ptr); tio->status &= ~STATUS_INPUT_DYNBUF; @@ -175,7 +175,7 @@ static int detach_in (hawk_tio_t* tio, int fini) tio->in.buf.ptr = HAWK_NULL; tio->in.buf.capa = 0; } - + return ret; } @@ -185,12 +185,12 @@ int hawk_tio_detachin (hawk_tio_t* tio) } int hawk_tio_attachout ( - hawk_tio_t* tio, hawk_tio_io_impl_t output, + hawk_tio_t* tio, hawk_tio_io_impl_t output, hawk_bch_t* bufptr, hawk_oow_t bufcapa) { hawk_bch_t* xbufptr; - if (output == HAWK_NULL || bufcapa < HAWK_TIO_MINOUTBUFCAPA) + if (output == HAWK_NULL || bufcapa < HAWK_TIO_MINOUTBUFCAPA) { hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EINVAL); return -1; @@ -207,7 +207,7 @@ int hawk_tio_attachout ( if (xbufptr == HAWK_NULL) return -1; } - if (output(tio, HAWK_TIO_OPEN, HAWK_NULL, 0) <= -1) + if (output(tio, HAWK_TIO_OPEN, HAWK_NULL, 0) <= -1) { if (xbufptr != bufptr) hawk_gem_freemem (tio->gem, xbufptr); return -1; @@ -231,7 +231,7 @@ static int detach_out (hawk_tio_t* tio, int fini) { hawk_tio_flush (tio); /* don't care about the result */ - if (tio->out.fun (tio, HAWK_TIO_CLOSE, HAWK_NULL, 0) <= -1) + if (tio->out.fun (tio, HAWK_TIO_CLOSE, HAWK_NULL, 0) <= -1) { /* returning with an error here allows you to retry detaching */ if (!fini) return -1; @@ -240,8 +240,8 @@ static int detach_out (hawk_tio_t* tio, int fini) * is reset below */ ret = -1; } - - if (tio->status & STATUS_OUTPUT_DYNBUF) + + if (tio->status & STATUS_OUTPUT_DYNBUF) { hawk_gem_freemem (tio->gem, tio->out.buf.ptr); tio->status &= ~STATUS_OUTPUT_DYNBUF; @@ -275,10 +275,10 @@ hawk_ooi_t hawk_tio_flush (hawk_tio_t* tio) left = tio->outbuf_len; cur = tio->out.buf.ptr; - while (left > 0) + while (left > 0) { n = tio->out.fun(tio, HAWK_TIO_DATA, cur, left); - if (n <= -1) + if (n <= -1) { if (cur != tio->out.buf.ptr) { @@ -287,13 +287,13 @@ hawk_ooi_t hawk_tio_flush (hawk_tio_t* tio) } return -1; } - if (n == 0) + if (n == 0) { if (cur != tio->out.buf.ptr) HAWK_MEMCPY (tio->out.buf.ptr, cur, left); break; } - + left -= n; cur += n; } @@ -321,7 +321,7 @@ hawk_ooi_t hawk_tio_readbchars (hawk_tio_t* tio, hawk_bch_t* buf, hawk_oow_t siz hawk_ooi_t n; /*HAWK_ASSERT (tio->in.fun != HAWK_NULL);*/ - if (tio->in.fun == HAWK_NULL) + if (tio->in.fun == HAWK_NULL) { /* no input function */ hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EINVAL); @@ -338,7 +338,7 @@ hawk_ooi_t hawk_tio_readbchars (hawk_tio_t* tio, hawk_bch_t* buf, hawk_oow_t siz nread = 0; while (nread < size) { - if (tio->inbuf_cur >= tio->inbuf_len) + if (tio->inbuf_cur >= tio->inbuf_len) { n = tio->in.fun(tio, HAWK_TIO_DATA, tio->in.buf.ptr, tio->in.buf.capa); if (n == 0) break; @@ -368,7 +368,7 @@ static HAWK_INLINE hawk_ooi_t tio_read_uchars ( hawk_ooi_t n; int x; - if (tio->inbuf_cur >= tio->inbuf_len) + if (tio->inbuf_cur >= tio->inbuf_len) { tio->inbuf_cur = 0; tio->inbuf_len = 0; @@ -379,7 +379,7 @@ static HAWK_INLINE hawk_ooi_t tio_read_uchars ( { n = tio->in.fun(tio, HAWK_TIO_DATA, &tio->in.buf.ptr[tio->inbuf_len], tio->in.buf.capa - tio->inbuf_len); } - if (n == 0) + if (n == 0) { tio->status |= STATUS_INPUT_EOF; @@ -387,7 +387,7 @@ static HAWK_INLINE hawk_ooi_t tio_read_uchars ( { /* no more input from the underlying input handler. * but some incomplete bytes in the buffer. */ - if (tio->flags & HAWK_TIO_IGNOREECERR) + if (tio->flags & HAWK_TIO_IGNOREECERR) { goto ignore_illseq; } @@ -419,11 +419,11 @@ static HAWK_INLINE hawk_ooi_t tio_read_uchars ( /* incomplete sequence */ if (wlen <= 0) { - /* not even a single character was handled. + /* not even a single character was handled. * shift bytes in the buffer to the head. */ HAWK_ASSERT (mlen <= 0); tio->inbuf_len = tio->inbuf_len - tio->inbuf_cur; - HAWK_MEMCPY (&tio->in.buf.ptr[0], + HAWK_MEMCPY (&tio->in.buf.ptr[0], &tio->in.buf.ptr[tio->inbuf_cur], tio->inbuf_len * HAWK_SIZEOF(tio->in.buf.ptr[0])); tio->inbuf_cur = 0; @@ -436,9 +436,9 @@ static HAWK_INLINE hawk_ooi_t tio_read_uchars ( { /* buffer not large enough */ HAWK_ASSERT (wlen > 0); - + /* the wide-character buffer is not just large enough to - * hold the entire conversion result. lets's go on so long as + * hold the entire conversion result. lets's go on so long as * 1 wide-character is produced though it may be inefficient. */ } @@ -465,7 +465,7 @@ static HAWK_INLINE hawk_ooi_t tio_read_uchars ( tio->status |= STATUS_INPUT_ILLSEQ; } } - + return wlen; } @@ -475,7 +475,7 @@ hawk_ooi_t hawk_tio_readuchars (hawk_tio_t* tio, hawk_uch_t* buf, hawk_oow_t siz hawk_ooi_t n; /*HAWK_ASSERT (tio->in.fun != HAWK_NULL);*/ - if (tio->in.fun == HAWK_NULL) + if (tio->in.fun == HAWK_NULL) { /* no input handler function */ hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EINVAL); @@ -486,13 +486,13 @@ hawk_ooi_t hawk_tio_readuchars (hawk_tio_t* tio, hawk_uch_t* buf, hawk_oow_t siz while (nread < size) { - if (tio->status & STATUS_INPUT_ILLSEQ) + if (tio->status & STATUS_INPUT_ILLSEQ) { tio->status &= ~STATUS_INPUT_ILLSEQ; hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EECERR); return -1; } - + n = tio_read_uchars(tio, &buf[nread], size - nread); if (n == 0) break; if (n <= -1) return -1; @@ -508,9 +508,9 @@ hawk_ooi_t hawk_tio_readuchars (hawk_tio_t* tio, hawk_uch_t* buf, hawk_oow_t siz /* ------------------------------------------------------------- */ hawk_ooi_t hawk_tio_writebchars (hawk_tio_t* tio, const hawk_bch_t* mptr, hawk_oow_t mlen) { - if (tio->outbuf_len >= tio->out.buf.capa) + if (tio->outbuf_len >= tio->out.buf.capa) { - /* maybe, previous flush operation has failed a few + /* maybe, previous flush operation has failed a few * times previously. so the buffer is full. */ hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EBUFFULL); @@ -523,7 +523,7 @@ hawk_ooi_t hawk_tio_writebchars (hawk_tio_t* tio, const hawk_bch_t* mptr, hawk_o if (tio->flags & HAWK_TIO_NOAUTOFLUSH) { - while (mptr[pos] != '\0') + while (mptr[pos] != '\0') { tio->out.buf.ptr[tio->outbuf_len++] = mptr[pos++]; if (tio->outbuf_len >= tio->out.buf.capa && @@ -534,7 +534,7 @@ hawk_ooi_t hawk_tio_writebchars (hawk_tio_t* tio, const hawk_bch_t* mptr, hawk_o else { int nl = 0; - while (mptr[pos] != '\0') + while (mptr[pos] != '\0') { tio->out.buf.ptr[tio->outbuf_len++] = mptr[pos]; if (tio->outbuf_len >= tio->out.buf.capa) @@ -542,7 +542,7 @@ hawk_ooi_t hawk_tio_writebchars (hawk_tio_t* tio, const hawk_bch_t* mptr, hawk_o if (hawk_tio_flush(tio) <= -1) return -1; nl = 0; } - else if (mptr[pos] == '\n') nl = 1; + else if (mptr[pos] == '\n') nl = 1; /* TODO: different line terminator */ if (++pos >= HAWK_TYPE_MAX(hawk_ooi_t)) break; } @@ -585,7 +585,7 @@ hawk_ooi_t hawk_tio_writebchars (hawk_tio_t* tio, const hawk_bch_t* mptr, hawk_o /* TODO: support different line terminating characeter */ if (*xptr == '\n') { - nl = 1; + nl = 1; break; } @@ -610,9 +610,9 @@ hawk_ooi_t hawk_tio_writeuchars (hawk_tio_t* tio, const hawk_uch_t* wptr, hawk_o hawk_oow_t capa, wcnt, mcnt, xwlen; int n, nl = 0; - if (tio->outbuf_len >= tio->out.buf.capa) + if (tio->outbuf_len >= tio->out.buf.capa) { - /* maybe, previous flush operation has failed a few + /* maybe, previous flush operation has failed a few * times previously. so the buffer is full. */ hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EBUFFULL); return -1; @@ -632,14 +632,14 @@ hawk_ooi_t hawk_tio_writeuchars (hawk_tio_t* tio, const hawk_uch_t* wptr, hawk_o if (n == -2) { - /* the buffer is not large enough to + /* the buffer is not large enough to * convert more. so flush now and continue. - * note that the buffer may not be full though + * note that the buffer may not be full though * it is not large enough in this case */ if (hawk_tio_flush(tio) <= -1) return -1; nl = 0; } - else + else { if (tio->outbuf_len >= tio->out.buf.capa) { @@ -654,7 +654,7 @@ hawk_ooi_t hawk_tio_writeuchars (hawk_tio_t* tio, const hawk_uch_t* wptr, hawk_o /* an invalid wide-character is encountered. */ if (tio->flags & HAWK_TIO_IGNOREECERR) { - /* insert a question mark for an illegal + /* insert a question mark for an illegal * character. */ HAWK_ASSERT (tio->outbuf_len < tio->out.buf.capa); tio->out.buf.ptr[tio->outbuf_len++] = '?'; @@ -680,10 +680,10 @@ hawk_ooi_t hawk_tio_writeuchars (hawk_tio_t* tio, const hawk_uch_t* wptr, hawk_o { /* scan backward assuming a line terminator * is typically at the back */ - if (wptr[--i] == '\n') + if (wptr[--i] == '\n') { /* TOOD: handle different line terminator */ - nl = 1; + nl = 1; break; } } diff --git a/lib/tre-compile.c b/lib/tre-compile.c index a4d03e77..78b3acd2 100644 --- a/lib/tre-compile.c +++ b/lib/tre-compile.c @@ -285,7 +285,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, p[i] = -1; } } - + /* Add end of this submatch to regset after processing this node. */ STACK_PUSHX(stack, int, node->submatch_id); @@ -351,16 +351,16 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, tre_ast_node_t *right = cat->right; int reserved_tag = -1; DPRINT(("Catenation, next_tag = %d\n", next_tag)); - - + + /* After processing right child. */ STACK_PUSHX(stack, voidptr, node); STACK_PUSHX(stack, int, ADDTAGS_AFTER_CAT_RIGHT); - + /* Process right child. */ STACK_PUSHX(stack, voidptr, right); STACK_PUSHX(stack, int, ADDTAGS_RECURSE); - + /* After processing left child. */ STACK_PUSHX(stack, int, next_tag + left->num_tags); DPRINT((" Pushing %d for after left\n", @@ -375,7 +375,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, } STACK_PUSHX(stack, int, reserved_tag); STACK_PUSHX(stack, int, ADDTAGS_AFTER_CAT_LEFT); - + /* Process left child. */ STACK_PUSHX(stack, voidptr, left); STACK_PUSHX(stack, int, ADDTAGS_RECURSE); @@ -387,7 +387,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, { tre_iteration_t *iter = node->obj; DPRINT(("Iteration\n")); - + if (first_pass) { STACK_PUSHX(stack, int, regset[0] >= 0 || iter->minimal); @@ -399,10 +399,10 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, } STACK_PUSHX(stack, voidptr, node); STACK_PUSHX(stack, int, ADDTAGS_AFTER_ITERATION); - + STACK_PUSHX(stack, voidptr, iter->arg); STACK_PUSHX(stack, int, ADDTAGS_RECURSE); - + /* Regset is not empty, so add a tag here. */ if (regset[0] >= 0 || iter->minimal) { @@ -426,7 +426,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, } tre_purge_regset(regset, tnfa, tag); } - + DPRINT((" num_tags++\n")); regset[0] = -1; tag = next_tag; @@ -444,7 +444,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, tre_ast_node_t *right = uni->right; int left_tag; int right_tag; - + if (regset[0] >= 0) { left_tag = next_tag; @@ -455,9 +455,9 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, left_tag = tag; right_tag = next_tag; } - + DPRINT(("Union\n")); - + /* After processing right child. */ STACK_PUSHX(stack, int, right_tag); STACK_PUSHX(stack, int, left_tag); @@ -467,18 +467,18 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, STACK_PUSHX(stack, voidptr, right); STACK_PUSHX(stack, voidptr, left); STACK_PUSHX(stack, int, ADDTAGS_AFTER_UNION_RIGHT); - + /* Process right child. */ STACK_PUSHX(stack, voidptr, right); STACK_PUSHX(stack, int, ADDTAGS_RECURSE); - + /* After processing left child. */ STACK_PUSHX(stack, int, ADDTAGS_AFTER_UNION_LEFT); - + /* Process left child. */ STACK_PUSHX(stack, voidptr, left); STACK_PUSHX(stack, int, ADDTAGS_RECURSE); - + /* Regset is not empty, so add a tag here. */ if (regset[0] >= 0) { @@ -499,14 +499,14 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, } tre_purge_regset(regset, tnfa, tag); } - + DPRINT((" num_tags++\n")); regset[0] = -1; tag = next_tag; num_tags++; next_tag++; } - + if (node->num_submatches > 0) { /* The next two tags are reserved for markers. */ @@ -514,7 +514,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, tag = next_tag; next_tag++; } - + break; } } @@ -548,7 +548,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, if (minimal) minimal_tag = enter_tag; } - + DPRINT(("After iteration\n")); if (!first_pass) { @@ -561,7 +561,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, } break; } - + case ADDTAGS_AFTER_CAT_LEFT: { int new_tag = tre_stack_pop_int(stack); @@ -575,7 +575,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, } break; } - + case ADDTAGS_AFTER_CAT_RIGHT: DPRINT(("After cat right\n")); node = tre_stack_pop_voidptr(stack); @@ -583,7 +583,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, node->num_tags = ((tre_catenation_t *)node->obj)->left->num_tags + ((tre_catenation_t *)node->obj)->right->num_tags; break; - + case ADDTAGS_AFTER_UNION_LEFT: DPRINT(("After union left\n")); /* Lift the bottom of the `regset' array so that when processing @@ -593,7 +593,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, while (*regset >= 0) regset++; break; - + case ADDTAGS_AFTER_UNION_RIGHT: { int added_tags, tag_left, tag_right; @@ -611,7 +611,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, regset = tre_stack_pop_voidptr(stack); tag_left = tre_stack_pop_int(stack); tag_right = tre_stack_pop_int(stack); - + /* Add tags after both children, the left child gets a smaller tag than the right child. This guarantees that we prefer the left child over the right child. */ @@ -636,7 +636,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, direction = TRE_TAG_MAXIMIZE; break; } - + default: assert(0); break; @@ -1874,7 +1874,7 @@ __tre_ast_to_tnfa(hawk_gem_t *gem, tre_stack_t* stack, tre_ast_node_t *node, tre STACK_PUSHR(stack, voidptr, node); - while (tre_stack_num_objects(stack)) + while (tre_stack_num_objects(stack)) { node = (tre_ast_node_t*)tre_stack_pop_voidptr(stack); @@ -1908,7 +1908,7 @@ __tre_ast_to_tnfa(hawk_gem_t *gem, tre_stack_t* stack, tre_ast_node_t *node, tre if(!(iter->min == 0 || iter->min == 1)) return REG_BADBR; /* Add a transition from each last position in the iterated expression to each first position. */ errcode = tre_make_trans(gem, iter->arg->lastpos, iter->arg->firstpos, transitions, counts, offs); - if (errcode != REG_OK) return errcode; + if (errcode != REG_OK) return errcode; } STACK_PUSHR(stack, voidptr, iter->arg); break; @@ -1962,9 +1962,9 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags) /* Allocate a stack used throughout the compilation process for various purposes. */ -/* HAWK: deleted limit on the stack size +/* HAWK: deleted limit on the stack size stack = tre_stack_new(preg->gem, 512, 10240, 128); */ - stack = tre_stack_new(preg->gem, 512, -1, 128); + stack = tre_stack_new(preg->gem, 512, -1, 128); if (HAWK_UNLIKELY(!stack)) return REG_ESPACE; /* Allocate a fast memory allocator. */ mem = tre_mem_new(preg->gem); @@ -2017,7 +2017,7 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags) /* Figure out how many tags we will need. */ /*errcode = tre_add_tags(NULL, stack, tree, tnfa); */ - errcode = tre_add_tags(mem, stack, tree, tnfa, 1); + errcode = tre_add_tags(mem, stack, tree, tnfa, 1); if (errcode != REG_OK) ERROR_EXIT(errcode); #ifdef TRE_DEBUG diff --git a/lib/tre-match-pa.c b/lib/tre-match-pa.c index f3e35342..0a9ac57d 100644 --- a/lib/tre-match-pa.c +++ b/lib/tre-match-pa.c @@ -409,8 +409,8 @@ tre_tnfa_run_parallel(hawk_gem_t* gem, const tre_tnfa_t *tnfa, const void *strin /* Does this transition match the input symbol? */ if (trans_i->code_min <= (tre_cint_t)prev_c && trans_i->code_max >= (tre_cint_t)prev_c) { - if (trans_i->assertions && - (CHECK_ASSERTIONS(trans_i->assertions) || + if (trans_i->assertions && + (CHECK_ASSERTIONS(trans_i->assertions) || CHECK_CHAR_CLASSES(trans_i, tnfa, eflags))) { DPRINT(("assertion failed\n")); diff --git a/lib/tre-mem.c b/lib/tre-mem.c index dd7a5927..e3351117 100644 --- a/lib/tre-mem.c +++ b/lib/tre-mem.c @@ -112,7 +112,7 @@ hawk_tre_mem_alloc_impl(hawk_tre_mem_t mem, int provided, void *provided_block, } else { - /* HAWK */ + /* HAWK */ /* int block_size;*/ hawk_oow_t block_size; /* END HAWK */ diff --git a/lib/tre-mem.h b/lib/tre-mem.h index 54d1d5a2..ce6b8c23 100644 --- a/lib/tre-mem.h +++ b/lib/tre-mem.h @@ -79,4 +79,4 @@ void hawk_tre_mem_destroy(hawk_tre_mem_t mem); } #endif -#endif +#endif diff --git a/lib/tre-parse.c b/lib/tre-parse.c index e171008b..6c2dcb09 100644 --- a/lib/tre-parse.c +++ b/lib/tre-parse.c @@ -188,8 +188,8 @@ tre_expand_ctype(tre_mem_t mem, tre_ctype_t class, tre_ast_node_t ***items, for (j = 0; (j < 256) && (status == REG_OK); j++) { c = j; - if (tre_isctype(c, class) || - ((cflags & REG_ICASE) && (tre_isctype(tre_tolower(c), class) || + if (tre_isctype(c, class) || + ((cflags & REG_ICASE) && (tre_isctype(tre_tolower(c), class) || tre_isctype(tre_toupper(c), class)))) { if (min < 0) min = c; @@ -319,7 +319,7 @@ tre_parse_bracket_items(tre_parse_ctx_t *ctx, int negate, /* Optimize character classes for 8 bit character sets. */ #if defined(HAWK_OOCH_IS_BCH) /* HAWK: not possible to count on MB_CUR_MAX since - * this library is designed to support per-object + * this library is designed to support per-object * or per-context character encoding using hawk_cmgr_t */ /* if (status == REG_OK && TRE_MB_CUR_MAX == 1) */ /* END HAWK */ @@ -507,7 +507,7 @@ tre_parse_bracket(tre_parse_ctx_t *ctx, tre_ast_node_t **result) int k; DPRINT(("final: creating %d - %d\n", curr_min, (int)TRE_CHAR_MAX)); n = tre_ast_new_literal(ctx->mem, curr_min, TRE_CHAR_MAX, ctx->position); - if (n == NULL) + if (n == NULL) { status = REG_ESPACE; } @@ -622,11 +622,11 @@ tre_parse_bound(tre_parse_ctx_t *ctx, tre_ast_node_t **result) } /* Check that the repeat counts are sane. */ - /*if ((max >= 0 && min > max) || max > RE_DUP_MAX) return REG_BADBR; + /*if ((max >= 0 && min > max) || max > RE_DUP_MAX) return REG_BADBR; hyunghwan.chung: this original check still allows something like {100000,} - while it does not allow {1,256}. Why is RE_DUP_MAX necessary? + while it does not allow {1,256}. Why is RE_DUP_MAX necessary? */ if ((max >= 0 && min > max)) return REG_BADBR; @@ -820,7 +820,7 @@ tre_parse_bound(tre_parse_ctx_t *ctx, tre_ast_node_t **result) minimal = !(ctx->cflags & REG_UNGREEDY); r++; } -/* HAWK - commented out for minimal impact on backward compatibility. +/* HAWK - commented out for minimal impact on backward compatibility. * X{x,y}* X{x,y}+ */ #if 0 else if (*r == CHAR_STAR || *r == CHAR_PLUS) @@ -1034,7 +1034,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) STACK_PUSHX(stack, int, PARSE_PIECE); } else -#endif +#endif { /* REG_RIGHT_ASSOC */ /* Default case, left associative concatenation. */ STACK_PUSHX(stack, int, PARSE_CATENATION); @@ -1044,7 +1044,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) } break; } - + case PARSE_POST_CATENATION: { tre_ast_node_t *tree = tre_stack_pop_voidptr(stack); @@ -1055,7 +1055,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) result = tmp_node; break; } - + case PARSE_UNION: if (ctx->re >= ctx->re_end) break; #ifdef REG_LITERAL @@ -1072,16 +1072,16 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) STACK_PUSHX(stack, int, PARSE_BRANCH); ctx->re++; break; - + case CHAR_RPAREN: ctx->re++; break; - + default: break; } break; - + case PARSE_POST_UNION: { tre_ast_node_t *tmp_node; @@ -1092,7 +1092,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) result = tmp_node; break; } - + case PARSE_POSTFIX: /* Parse postfix operators. */ if (ctx->re >= ctx->re_end) @@ -1119,7 +1119,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) #ifdef TRE_DEBUG const tre_char_t *tmp_re; #endif - + if (*ctx->re == CHAR_PLUS) /* HAWK: case CHAR_PLUS fell through down here */ rep_min = 1; if (*ctx->re == CHAR_QUESTIONMARK) /* HAWK: case CHAR_QUESTIONMARK fell though down here */ @@ -1127,7 +1127,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) #ifdef TRE_DEBUG tmp_re = ctx->re; #endif - + if (ctx->re + 1 < ctx->re_end) { if (*(ctx->re + 1) == CHAR_QUESTIONMARK) /* HAWK: +?, ??, *? */ @@ -1148,7 +1148,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) } #endif } - + DPRINT(("tre_parse: %s star: '%.*" STRF "'\n", minimal ? " minimal" : "greedy", REST(tmp_re))); ctx->re++; @@ -1158,10 +1158,10 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) return REG_ESPACE; result = tmp_node; STACK_PUSHX(stack, int, PARSE_POSTFIX); - + break; } - + case CHAR_BACKSLASH: /* "\{" is special without REG_EXTENDED */ /* HAWK - also handle \+ and \? */ @@ -1178,13 +1178,13 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) */ if (!(ctx->cflags & REG_EXTENDED) && ctx->re + 1 < ctx->re_end) { - if (*(ctx->re + 1) == CHAR_LBRACE) + if (*(ctx->re + 1) == CHAR_LBRACE) { ctx->re++; goto parse_brace; } - else if (*(ctx->re + 1) == CHAR_PLUS || - *(ctx->re + 1) == CHAR_QUESTIONMARK) + else if (*(ctx->re + 1) == CHAR_PLUS || + *(ctx->re + 1) == CHAR_QUESTIONMARK) { ctx->re++; goto parse_star; @@ -1192,51 +1192,51 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) } break; /* END HAWK */ - - + + case CHAR_LBRACE: /* "{" is literal without REG_EXTENDED */ if (!(ctx->cflags & REG_EXTENDED)) break; /* HAWK */ if (ctx->cflags & REG_NOBOUND) break; /* END HAWK */ - + parse_brace: DPRINT(("tre_parse: bound: '%.*" STRF "'\n", REST(ctx->re))); ctx->re++; - + status = tre_parse_bound(ctx, &result); if (status != REG_OK) return status; STACK_PUSHX(stack, int, PARSE_POSTFIX); break; } - + break; - + case PARSE_ATOM: - + /* Parse an atom. An atom is a regular expression enclosed in `()', an empty set of `()', a bracket expression, `.', `^', `$', a `\' followed by a character, or a single character. */ - + /* End of regexp? (empty string). */ if (ctx->re >= ctx->re_end) goto parse_literal; - + #ifdef REG_LITERAL if (ctx->cflags & REG_LITERAL) goto parse_literal; #endif /* REG_LITERAL */ - + switch (*ctx->re) { case CHAR_LPAREN: /* parenthesized subexpression */ - + /* Handle "(?...)" extensions. They work in a way similar to Perls corresponding extensions. */ /* HAWK: added ctx->cflags & REG_NONSTDEXT */ if ((ctx->cflags & REG_NONSTDEXT) && - (ctx->cflags & REG_EXTENDED) && + (ctx->cflags & REG_EXTENDED) && *(ctx->re + 1) == CHAR_QUESTIONMARK) { int new_cflags = ctx->cflags; @@ -1325,7 +1325,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) else return REG_BADPAT; } - + /* Turn on the cflags changes for the rest of the enclosing group. */ STACK_PUSHX(stack, int, ctx->cflags); @@ -1334,7 +1334,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) ctx->cflags = new_cflags; break; } - + if (ctx->cflags & REG_EXTENDED || (ctx->re > ctx->re_start && *(ctx->re - 1) == CHAR_BACKSLASH)) @@ -1342,7 +1342,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) depth++; /* HAWK: added ctx->cflags & REG_NONSTDEXT */ if ((ctx->cflags & REG_NONSTDEXT) && - ctx->re + 2 < ctx->re_end && + ctx->re + 2 < ctx->re_end && *(ctx->re + 1) == CHAR_QUESTIONMARK && *(ctx->re + 2) == CHAR_COLON) { @@ -1370,7 +1370,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) else goto parse_literal; break; - + case CHAR_RPAREN: /* end of current subexpression */ /* HAWK: fixed the condition */ /* if ((ctx->cflags & REG_EXTENDED && depth > 0) @@ -1392,14 +1392,14 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) else goto parse_literal; break; - + case CHAR_LBRACKET: /* bracket expression */ DPRINT(("tre_parse: bracket: '%.*" STRF "'\n", REST(ctx->re))); ctx->re++; status = tre_parse_bracket(ctx, &result); if (status != REG_OK) return status; break; - + case CHAR_BACKSLASH: /* If this is "\(" or "\)" chew off the backslash and try again. */ @@ -1412,7 +1412,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) STACK_PUSHX(stack, int, PARSE_ATOM); break; } - + /* If a macro is used, parse the expanded macro recursively. */ { tre_char_t buf[64]; @@ -1432,13 +1432,13 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) break; } } - + if (ctx->re + 1 >= ctx->re_end) { /* Trailing backslash. */ return REG_EESCAPE; } - + #ifdef REG_LITERAL if (*(ctx->re + 1) == HAWK_T('Q')) { @@ -1451,7 +1451,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) break; } #endif /* REG_LITERAL */ - + DPRINT(("tre_parse: bleep: '%.*" STRF "'\n", REST(ctx->re))); ctx->re++; switch (*ctx->re) @@ -1483,7 +1483,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) long val; DPRINT(("tre_parse: 8 bit hex: '%.*" STRF "'\n", REST(ctx->re - 2))); - + if (tre_isxdigit(ctx->re[0]) && ctx->re < ctx->re_end) { tmp[0] = (char)ctx->re[0]; @@ -1508,7 +1508,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) val = val * 16 + tmp; ctx->re++; } - + result = tre_ast_new_literal(ctx->mem, (int)val, (int)val, ctx->position); ctx->position++; break; @@ -1541,7 +1541,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) #endif long val = 0; int tmp; - + ctx->re++; while (ctx->re_end - ctx->re >= 0) { @@ -1556,13 +1556,13 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) } return REG_EBRACE; } - + result = tre_ast_new_literal(ctx->mem, (int)val, (int)val, ctx->position); ctx->position++; break; } /*FALLTHROUGH*/ - + default: if (tre_isdigit(*ctx->re)) { @@ -1588,7 +1588,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) if (result == NULL) return REG_ESPACE; break; - + case CHAR_PERIOD: /* the any-symbol */ DPRINT(("tre_parse: any: '%.*" STRF "'\n", REST(ctx->re))); @@ -1614,7 +1614,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) } ctx->re++; break; - + case CHAR_CARET: /* beginning of line assertion */ /* '^' has a special meaning everywhere in EREs, and in the beginning of the RE and after \( is BREs. */ @@ -1633,7 +1633,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) else goto parse_literal; break; - + case CHAR_DOLLAR: /* end of line assertion. */ /* '$' is special everywhere in EREs, and in the end of the string and before \) is BREs. */ @@ -1653,10 +1653,10 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) else goto parse_literal; break; - + default: parse_literal: - + if (temporary_cflags && ctx->re + 1 < ctx->re_end && *ctx->re == CHAR_BACKSLASH && *(ctx->re + 1) == HAWK_T('E')) { @@ -1667,8 +1667,8 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) STACK_PUSHX(stack, int, PARSE_PIECE); break; } - - + + /* We are expecting an atom. If the subexpression (or the whole regexp) ends here, we interpret it as an empty expression (which matches an empty string). */ @@ -1697,7 +1697,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) if (!result) return REG_ESPACE; break; } - + DPRINT(("tre_parse: literal: '%.*" STRF "'\n", REST(ctx->re))); /* Note that we can't use an tre_isalpha() test here, since there @@ -1707,7 +1707,7 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) { tre_ast_node_t *tmp1; tre_ast_node_t *tmp2; - + /* XXX - Can there be more than one opposite-case counterpoints for some character in some locale? Or more than two characters which all should be regarded @@ -1733,11 +1733,11 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) break; } break; - + case PARSE_MARK_FOR_SUBMATCH: { int submatch_id = tre_stack_pop_int(stack); - + if (result->submatch_id >= 0) { tre_ast_node_t *n, *tmp_node; @@ -1752,24 +1752,24 @@ reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) result->num_submatches++; break; } - + case PARSE_RESTORE_CFLAGS: ctx->cflags = tre_stack_pop_int(stack); break; - + default: assert(0); break; } } - + /* Check for missing closing parentheses. */ if (depth > 0) return REG_EPAREN; - + if (status == REG_OK) ctx->result = result; - + return status; } diff --git a/lib/tre-prv.h b/lib/tre-prv.h index 5210a8e5..cf27d291 100644 --- a/lib/tre-prv.h +++ b/lib/tre-prv.h @@ -203,9 +203,9 @@ typedef hawk_ooci_t tre_cint_t; #define REG_NEWLINE HAWK_TRE_NEWLINE #define REG_NOSUB HAWK_TRE_NOSUBREG /* Extra tre_regcomp() flags. */ -#define REG_LITERAL HAWK_TRE_LITERAL +#define REG_LITERAL HAWK_TRE_LITERAL #define REG_RIGHT_ASSOC HAWK_TRE_RIGHTASSOC -#define REG_UNGREEDY HAWK_TRE_UNGREEDY +#define REG_UNGREEDY HAWK_TRE_UNGREEDY #define REG_NOBOUND HAWK_TRE_NOBOUND #define REG_NONSTDEXT HAWK_TRE_NONSTDEXT @@ -219,9 +219,9 @@ typedef hawk_ooci_t tre_cint_t; -/* use the noseterr version because various tre functions return +/* use the noseterr version because various tre functions return * REG_ESPACE upon memory shortage and the wrapper functions - * uses the returned code to set the error number on the + * uses the returned code to set the error number on the * hawk_tre_t wrapper object */ #define xmalloc(gem,size) hawk_gem_allocmem_noseterr(gem,size) #define xrealloc(gem,ptr,new_size) hawk_gem_reallocmem_noseterr(gem, ptr, new_size) @@ -276,7 +276,7 @@ typedef hawk_ooci_t tre_cint_t; * however, if int is 2 bytes long,TRE_CHAR_MAX becomes 32767 which is way too small * to represent even upper-half of the UCS-2 codepoints. */ -# if (HAWK_SIZEOF_UCH_T < HAWK_SIZEOF_INT) +# if (HAWK_SIZEOF_UCH_T < HAWK_SIZEOF_INT) # define TRE_CHAR_MAX HAWK_TYPE_MAX(hawk_uch_t) # else # define TRE_CHAR_MAX HAWK_TYPE_MAX(int) @@ -285,16 +285,16 @@ typedef hawk_ooci_t tre_cint_t; /* # ifdef TRE_MULTIBYTE # define TRE_MB_CUR_MAX (hawk_getmbcurmax()) -# else +# else # define TRE_MB_CUR_MAX 1 -# endif +# endif */ #else /* !TRE_WCHAR */ # define TRE_CHAR_MAX 255 /*# define TRE_MB_CUR_MAX 1*/ #endif /* !TRE_WCHAR */ -#define DPRINT(msg) +#define DPRINT(msg) typedef hawk_ooch_prop_t tre_ctype_t; #define tre_isctype(c,t) hawk_is_ooch_type(c,t) diff --git a/lib/tre-stack.c b/lib/tre-stack.c index 3527a0e3..aa739198 100644 --- a/lib/tre-stack.c +++ b/lib/tre-stack.c @@ -121,7 +121,7 @@ tre_stack_push(tre_stack_t *s, union tre_stack_item value) } else { -/* HAWK added check for s->max_size > 0 +/* HAWK added check for s->max_size > 0 if (s->size >= s->max_size)*/ if (s->max_size > 0 && s->size >= s->max_size) { @@ -134,9 +134,9 @@ tre_stack_push(tre_stack_t *s, union tre_stack_item value) int new_size; DPRINT(("tre_stack_push: trying to realloc more space\n")); new_size = s->size + s->increment; -/* HAWK added check for s->max_size > 0 +/* HAWK added check for s->max_size > 0 if (new_size > s->max_size) */ - if (s->max_size > 0 && new_size > s->max_size) + if (s->max_size > 0 && new_size > s->max_size) new_size = s->max_size; new_buffer = xrealloc(s->gem, s->stack, sizeof(*new_buffer) * new_size); if (new_buffer == NULL) diff --git a/lib/tre.c b/lib/tre.c index a6ed375d..ddc03309 100644 --- a/lib/tre.c +++ b/lib/tre.c @@ -57,7 +57,7 @@ int hawk_tre_init (hawk_tre_t* tre, hawk_gem_t* gem) void hawk_tre_fini (hawk_tre_t* tre) { - if (tre->TRE_REGEX_T_FIELD) + if (tre->TRE_REGEX_T_FIELD) { tre_free (tre); tre->TRE_REGEX_T_FIELD = HAWK_NULL; @@ -68,21 +68,21 @@ int hawk_tre_compx (hawk_tre_t* tre, const hawk_ooch_t* regex, hawk_oow_t n, uns { int ret; - if (tre->TRE_REGEX_T_FIELD) + if (tre->TRE_REGEX_T_FIELD) { tre_free (tre); tre->TRE_REGEX_T_FIELD = HAWK_NULL; } ret = tre_compile(tre, regex, n, cflags); - if (ret > 0) + if (ret > 0) { tre->TRE_REGEX_T_FIELD = HAWK_NULL; /* just to make sure */ hawk_gem_seterrnum (tre->gem, HAWK_NULL, ret); return -1; } - - if (nsubmat) + + if (nsubmat) { *nsubmat = ((struct tnfa*)tre->TRE_REGEX_T_FIELD)->num_submatches; } @@ -226,12 +226,12 @@ int hawk_tre_execx ( #else ret = tre_match(tre, str, len, STR_BYTE, nmatch, pmatch, eflags); #endif - if (ret > 0) + if (ret > 0) { hawk_gem_seterrnum ((errgem? errgem: tre->gem), HAWK_NULL, ret); return -1; } - + return 0; } @@ -256,12 +256,12 @@ int hawk_tre_execuchars ( return -1; } ret = tre_match(tre, str, len, STR_WIDE, nmatch, pmatch, eflags); - if (ret > 0) + if (ret > 0) { hawk_gem_seterrnum ((errgem? errgem: tre->gem), HAWK_NULL, ret); return -1; } - + return 0; } @@ -278,12 +278,12 @@ int hawk_tre_execbchars ( return -1; } ret = tre_match(tre, str, len, STR_BYTE, nmatch, pmatch, eflags); - if (ret > 0) + if (ret > 0) { hawk_gem_seterrnum ((errgem? errgem: tre->gem), HAWK_NULL, ret); return -1; } - + return 0; } diff --git a/lib/tree-prv.h b/lib/tree-prv.h index a37453f6..fbacedf0 100644 --- a/lib/tree-prv.h +++ b/lib/tree-prv.h @@ -28,7 +28,7 @@ enum hawk_in_type_t { - /* the order of these values match + /* the order of these values match * __in_type_map and __in_opt_map in rio.c */ HAWK_IN_PIPE, @@ -41,7 +41,7 @@ typedef enum hawk_in_type_t hawk_in_type_t; enum hawk_out_type_t { - /* the order of these values match + /* the order of these values match * __out_type_map and __out_opt_map in rio.c */ HAWK_OUT_PIPE, @@ -114,7 +114,7 @@ struct hawk_nde_ass_t hawk_nde_t* right; }; -/* HAWK_NDE_EXP_BIN, HAWK_NDE_EXP_UNR, +/* HAWK_NDE_EXP_BIN, HAWK_NDE_EXP_UNR, * HAWK_NDE_EXP_INCPRE, HAWK_AW_NDE_EXP_INCPST */ struct hawk_nde_exp_t { @@ -134,7 +134,7 @@ struct hawk_nde_cnd_t }; /* HAWK_NDE_POS - positional - $1, $2, $x, etc */ -struct hawk_nde_pos_t +struct hawk_nde_pos_t { HAWK_NDE_HDR; hawk_nde_t* val; @@ -160,7 +160,7 @@ struct hawk_nde_int_t { HAWK_NDE_HDR; hawk_int_t val; - hawk_ooch_t* str; + hawk_ooch_t* str; hawk_oow_t len; }; @@ -217,14 +217,14 @@ struct hawk_nde_fun_t hawk_fun_t* funptr; /* HAWK_NULL or actual pointer */ }; -/* HAWK_NDE_NAMED, HAWK_NDE_GBL, - * HAWK_NDE_LCL, HAWK_NDE_ARG - * HAWK_NDE_NAMEDIDX, HAWK_NDE_GBLIDX, +/* HAWK_NDE_NAMED, HAWK_NDE_GBL, + * HAWK_NDE_LCL, HAWK_NDE_ARG + * HAWK_NDE_NAMEDIDX, HAWK_NDE_GBLIDX, * HAWK_NDE_LCLIDX, HAWK_NDE_ARGIDX */ struct hawk_nde_var_t { HAWK_NDE_HDR; - struct + struct { hawk_oocs_t name; hawk_oow_t idxa; @@ -244,7 +244,7 @@ struct hawk_nde_fncall_t hawk_fun_t* fun; /* cache it */ } fun; - /* minimum information of an intrinsic function + /* minimum information of an intrinsic function * needed during run-time. */ struct { @@ -284,7 +284,7 @@ struct hawk_nde_if_t /* HAWK_NDE_WHILE, HAWK_NDE_DOWHILE */ struct hawk_nde_while_t { - HAWK_NDE_HDR; + HAWK_NDE_HDR; hawk_nde_t* test; hawk_nde_t* body; }; @@ -323,7 +323,7 @@ struct hawk_nde_continue_t struct hawk_nde_return_t { HAWK_NDE_HDR; - hawk_nde_t* val; /* optional (no return code if HAWK_NULL) */ + hawk_nde_t* val; /* optional (no return code if HAWK_NULL) */ }; /* HAWK_NDE_EXIT */ @@ -377,7 +377,7 @@ extern "C" { /* print the entire tree */ int hawk_prnpt (hawk_t* hawk, hawk_nde_t* tree); /* print a single top-level node */ -int hawk_prnnde (hawk_t* hawk, hawk_nde_t* node); +int hawk_prnnde (hawk_t* hawk, hawk_nde_t* node); /* print the pattern part */ int hawk_prnptnpt (hawk_t* hawk, hawk_nde_t* tree); diff --git a/lib/tree.c b/lib/tree.c index b37f4996..eaeaf2ed 100644 --- a/lib/tree.c +++ b/lib/tree.c @@ -150,7 +150,7 @@ static int print_stmts (hawk_t* hawk, hawk_nde_t* tree, int depth); static int print_tabs (hawk_t* hawk, int depth) { - while (depth > 0) + while (depth > 0) { PUT_SRCSTR (hawk, HAWK_T("\t")); depth--; @@ -163,7 +163,7 @@ static int print_printx (hawk_t* hawk, hawk_nde_print_t* px) { hawk_oocs_t kw; - if (px->type == HAWK_NDE_PRINT) + if (px->type == HAWK_NDE_PRINT) { hawk_getkwname (hawk, HAWK_KWID_PRINT, &kw); PUT_SRCSTRN (hawk, kw.ptr, kw.len); @@ -194,18 +194,18 @@ static int print_printx (hawk_t* hawk, hawk_nde_print_t* px) static int print_expr (hawk_t* hawk, hawk_nde_t* nde) { hawk_oocs_t kw; - - switch (nde->type) + + switch (nde->type) { case HAWK_NDE_GRP: - { + { hawk_nde_t* p = ((hawk_nde_grp_t*)nde)->body; PUT_SRCSTR (hawk, HAWK_T("(")); - while (p != HAWK_NULL) + while (p != HAWK_NULL) { PRINT_EXPR (hawk, p); - if (p->next != HAWK_NULL) + if (p->next != HAWK_NULL) PUT_SRCSTR (hawk, HAWK_T(",")); p = p->next; } @@ -239,12 +239,12 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) PUT_SRCSTR (hawk, binop_str[px->opcode][(hawk->opt.trait & HAWK_BLANKCONCAT)? 0: 1]); PUT_SRCSTR (hawk, HAWK_T(" ")); - if (px->right->type == HAWK_NDE_ASS) + if (px->right->type == HAWK_NDE_ASS) PUT_SRCSTR (hawk, HAWK_T("(")); PRINT_EXPR (hawk, px->right); - if (px->right->type == HAWK_NDE_ASS) + if (px->right->type == HAWK_NDE_ASS) PUT_SRCSTR (hawk, HAWK_T(")")); - HAWK_ASSERT (px->right->next == HAWK_NULL); + HAWK_ASSERT (px->right->next == HAWK_NULL); PUT_SRCSTR (hawk, HAWK_T(")")); break; } @@ -304,7 +304,7 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) case HAWK_NDE_CHAR: { hawk_ooch_t tmp = ((hawk_nde_char_t*)nde)->val; - hawk_ooch_t buf[16]; + hawk_ooch_t buf[16]; PUT_SRCSTR (hawk, HAWK_T("\'")); if (tmp == '\0') @@ -339,7 +339,7 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) case HAWK_NDE_BCHR: { hawk_bch_t tmp = ((hawk_nde_bchr_t*)nde)->val; - hawk_ooch_t buf[16]; + hawk_ooch_t buf[16]; PUT_SRCSTR (hawk, HAWK_T("@b\'")); if (tmp == '\0') @@ -369,7 +369,7 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) } else { - /* Note that the array sizing fomula is not accurate + /* Note that the array sizing fomula is not accurate * but should be good enoug consiering the followings. * * size minval digits sign @@ -379,12 +379,12 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) * 8 -9223372036854775808 19 1 * 16 -170141183460469231731687303715884105728 39 1 */ - hawk_ooch_t buf[HAWK_SIZEOF(hawk_int_t) * 3 + 2]; + hawk_ooch_t buf[HAWK_SIZEOF(hawk_int_t) * 3 + 2]; hawk_fmt_intmax_to_oocstr ( buf, HAWK_COUNTOF(buf), ((hawk_nde_int_t*)nde)->val, - 10, + 10, -1, HAWK_T('\0'), HAWK_NULL @@ -542,7 +542,7 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) { PUT_SRCSTR (hawk, HAWK_T("/")); PUT_SRCSTRN (hawk, - ((hawk_nde_rex_t*)nde)->str.ptr, + ((hawk_nde_rex_t*)nde)->str.ptr, ((hawk_nde_rex_t*)nde)->str.len); PUT_SRCSTR (hawk, HAWK_T("/")); break; @@ -570,14 +570,14 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) case HAWK_NDE_FUN: { PUT_SRCSTRN (hawk, - ((hawk_nde_fun_t*)nde)->name.ptr, + ((hawk_nde_fun_t*)nde)->name.ptr, ((hawk_nde_fun_t*)nde)->name.len); break; } case HAWK_NDE_ARG: { - hawk_ooch_t tmp[HAWK_SIZEOF(hawk_int_t)*8+2]; + hawk_ooch_t tmp[HAWK_SIZEOF(hawk_int_t)*8+2]; hawk_oow_t n; hawk_nde_var_t* px = (hawk_nde_var_t*)nde; HAWK_ASSERT (px->id.idxa != (hawk_oow_t)-1); @@ -630,46 +630,9 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) { hawk_nde_var_t* px = (hawk_nde_var_t*)nde; - if (px->id.idxa != (hawk_oow_t)-1) + if (px->id.idxa != (hawk_oow_t)-1) { - /* deparsing is global. so i can't honor hawk->parse.pragma.trait - * which can change in each input file. let me just check hawk->opt.trait */ - if (!(hawk->opt.trait & HAWK_IMPLICIT)) - { - /* no implicit(named) variable is allowed. - * use the actual name */ - PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len); - } - else if (px->id.idxa < hawk->tree.ngbls_base) - { - /* static global variables */ - PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len); - } - else - { - hawk_ooch_t tmp[HAWK_SIZEOF(hawk_int_t)*8+2]; - hawk_oow_t n; - - PUT_SRCSTR (hawk, HAWK_T("__g")); - n = hawk_int_to_oocstr(px->id.idxa, 10, HAWK_NULL, tmp, HAWK_COUNTOF(tmp)); - PUT_SRCSTRN (hawk, tmp, n); - } - } - else - { - PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len); - } - HAWK_ASSERT (px->idx == HAWK_NULL); - break; - } - - case HAWK_NDE_GBLIDX: - { - hawk_nde_var_t* px = (hawk_nde_var_t*)nde; - - if (px->id.idxa != (hawk_oow_t)-1) - { - /* deparsing is global. so i can't honor hawk->parse.pragma.trait + /* deparsing is global. so i can't honor hawk->parse.pragma.trait * which can change in each input file. let me just check hawk->opt.trait */ if (!(hawk->opt.trait & HAWK_IMPLICIT)) { @@ -684,7 +647,7 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) } else { - hawk_ooch_t tmp[HAWK_SIZEOF(hawk_int_t)*8+2]; + hawk_ooch_t tmp[HAWK_SIZEOF(hawk_int_t)*8+2]; hawk_oow_t n; PUT_SRCSTR (hawk, HAWK_T("__g")); @@ -692,7 +655,44 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) PUT_SRCSTRN (hawk, tmp, n); } } - else + else + { + PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len); + } + HAWK_ASSERT (px->idx == HAWK_NULL); + break; + } + + case HAWK_NDE_GBLIDX: + { + hawk_nde_var_t* px = (hawk_nde_var_t*)nde; + + if (px->id.idxa != (hawk_oow_t)-1) + { + /* deparsing is global. so i can't honor hawk->parse.pragma.trait + * which can change in each input file. let me just check hawk->opt.trait */ + if (!(hawk->opt.trait & HAWK_IMPLICIT)) + { + /* no implicit(named) variable is allowed. + * use the actual name */ + PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len); + } + else if (px->id.idxa < hawk->tree.ngbls_base) + { + /* static global variables */ + PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len); + } + else + { + hawk_ooch_t tmp[HAWK_SIZEOF(hawk_int_t)*8+2]; + hawk_oow_t n; + + PUT_SRCSTR (hawk, HAWK_T("__g")); + n = hawk_int_to_oocstr(px->id.idxa, 10, HAWK_NULL, tmp, HAWK_COUNTOF(tmp)); + PUT_SRCSTRN (hawk, tmp, n); + } + } + else { PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len); } @@ -707,13 +707,13 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) hawk_oow_t n; hawk_nde_var_t* px = (hawk_nde_var_t*)nde; - if (px->id.idxa != (hawk_oow_t)-1) + if (px->id.idxa != (hawk_oow_t)-1) { PUT_SRCSTR (hawk, HAWK_T("__l")); n = hawk_int_to_oocstr(px->id.idxa, 10, HAWK_NULL, hawk->tmp.fmt, HAWK_COUNTOF(hawk->tmp.fmt)); PUT_SRCSTRN (hawk, hawk->tmp.fmt, n); } - else + else { PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len); } @@ -726,13 +726,13 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) hawk_oow_t n; hawk_nde_var_t* px = (hawk_nde_var_t*)nde; - if (px->id.idxa != (hawk_oow_t)-1) + if (px->id.idxa != (hawk_oow_t)-1) { PUT_SRCSTR (hawk, HAWK_T("__l")); n = hawk_int_to_oocstr(px->id.idxa, 10, HAWK_NULL, hawk->tmp.fmt, HAWK_COUNTOF(hawk->tmp.fmt)); PUT_SRCSTRN (hawk, hawk->tmp.fmt, n); } - else + else { PUT_SRCSTRN (hawk, px->id.name.ptr, px->id.name.len); } @@ -807,7 +807,7 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde) PUT_SRCSTR (hawk, getline_inop_str[px->in_type]); PUT_SRCSTR (hawk, HAWK_T(" ")); PRINT_EXPR (hawk, px->in); - } + } PUT_SRCSTR (hawk, HAWK_T(")")); break; @@ -836,7 +836,7 @@ static int print_expr_list (hawk_t* hawk, hawk_nde_t* tree) { hawk_nde_t* p = tree; - while (p) + while (p) { PRINT_EXPR (hawk, p); p = p->next; @@ -851,13 +851,13 @@ static int print_expr_list_for_idx (hawk_t* hawk, hawk_nde_t* tree) hawk_nde_t* p = tree; PUT_SRCSTR (hawk, HAWK_T("[")); - while (p) + while (p) { PRINT_EXPR (hawk, p); p = p->next; - if (p) + if (p) { - if (p->type == HAWK_NDE_NULL) + if (p->type == HAWK_NDE_NULL) { /* the parser injects a HAWK_NDE_NULL node between the true multi-dimensional indices * if the true multi-dimensional indices are enabled(i.e. HAWK_ENABLE_GC is defined) @@ -879,7 +879,7 @@ static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth) hawk_oow_t i; hawk_oocs_t kw; - switch (p->type) + switch (p->type) { case HAWK_NDE_NULL: { @@ -898,7 +898,7 @@ static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth) PUT_SRCSTR (hawk, HAWK_T("{")); PUT_NL (hawk); - if (px->org_nlcls > 0) + if (px->org_nlcls > 0) { PRINT_TABS (hawk, depth + 1); @@ -908,7 +908,7 @@ static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth) /* though the parser pushed up all local variables to the outer-most level, * the code here restores the original declarations with org_nlcls and prv_nlcls */ - for (i = 0; i < px->org_nlcls - 1; i++) + for (i = 0; i < px->org_nlcls - 1; i++) { PUT_SRCSTR (hawk, HAWK_T("__l")); n = hawk_int_to_oocstr(px->outer_nlcls + i, 10, HAWK_NULL, hawk->tmp.fmt, HAWK_COUNTOF(hawk->tmp.fmt)); @@ -923,21 +923,21 @@ static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth) PUT_NL (hawk); } - PRINT_STMTS (hawk, px->body, depth + 1); + PRINT_STMTS (hawk, px->body, depth + 1); PRINT_TABS (hawk, depth); PUT_SRCSTR (hawk, HAWK_T("}")); PUT_NL (hawk); break; } - case HAWK_NDE_IF: + case HAWK_NDE_IF: { hawk_nde_if_t* px = (hawk_nde_if_t*)p; PRINT_TABS (hawk, depth); hawk_getkwname (hawk, HAWK_KWID_IF, &kw); PUT_SRCSTRN (hawk, kw.ptr, kw.len); - PUT_SRCSTR (hawk, HAWK_T(" (")); + PUT_SRCSTR (hawk, HAWK_T(" (")); PRINT_EXPR (hawk, px->test); PUT_SRCSTR (hawk, HAWK_T(")")); PUT_NL (hawk); @@ -948,7 +948,7 @@ static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth) else PRINT_STMTS (hawk, px->then_part, depth + 1); - if (px->else_part != HAWK_NULL) + if (px->else_part != HAWK_NULL) { PRINT_TABS (hawk, depth); hawk_getkwname (hawk, HAWK_KWID_ELSE, &kw); @@ -962,7 +962,7 @@ static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth) break; } - case HAWK_NDE_WHILE: + case HAWK_NDE_WHILE: { hawk_nde_while_t* px = (hawk_nde_while_t*)p; @@ -973,18 +973,18 @@ static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth) PRINT_EXPR (hawk, px->test); PUT_SRCSTR (hawk, HAWK_T(")")); PUT_NL (hawk); - if (px->body->type == HAWK_NDE_BLK) + if (px->body->type == HAWK_NDE_BLK) { PRINT_STMTS (hawk, px->body, depth); } - else + else { PRINT_STMTS (hawk, px->body, depth + 1); } break; } - case HAWK_NDE_DOWHILE: + case HAWK_NDE_DOWHILE: { hawk_nde_while_t* px = (hawk_nde_while_t*)p; @@ -992,11 +992,11 @@ static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth) hawk_getkwname (hawk, HAWK_KWID_DO, &kw); PUT_SRCSTRN (hawk, kw.ptr, kw.len); PUT_NL (hawk); - if (px->body->type == HAWK_NDE_BLK) + if (px->body->type == HAWK_NDE_BLK) { PRINT_STMTS (hawk, px->body, depth); } - else + else { PRINT_STMTS (hawk, px->body, depth + 1); } @@ -1019,28 +1019,28 @@ static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth) hawk_getkwname (hawk, HAWK_KWID_FOR, &kw); PUT_SRCSTRN (hawk, kw.ptr, kw.len); PUT_SRCSTR (hawk, HAWK_T(" (")); - if (px->init != HAWK_NULL) + if (px->init != HAWK_NULL) { PRINT_EXPR (hawk, px->init); } PUT_SRCSTR (hawk, HAWK_T("; ")); - if (px->test != HAWK_NULL) + if (px->test != HAWK_NULL) { PRINT_EXPR (hawk, px->test); } PUT_SRCSTR (hawk, HAWK_T("; ")); - if (px->incr != HAWK_NULL) + if (px->incr != HAWK_NULL) { PRINT_EXPR (hawk, px->incr); } PUT_SRCSTR (hawk, HAWK_T(")")); PUT_NL (hawk); - if (px->body->type == HAWK_NDE_BLK) + if (px->body->type == HAWK_NDE_BLK) { PRINT_STMTS (hawk, px->body, depth); } - else + else { PRINT_STMTS (hawk, px->body, depth + 1); } @@ -1057,11 +1057,11 @@ static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth) PUT_SRCSTR (hawk, HAWK_T(" ")); PRINT_EXPR (hawk, px->test); PUT_NL (hawk); - if (px->body->type == HAWK_NDE_BLK) + if (px->body->type == HAWK_NDE_BLK) { PRINT_STMTS (hawk, px->body, depth); } - else + else { PRINT_STMTS (hawk, px->body, depth + 1); } @@ -1091,14 +1091,14 @@ static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth) case HAWK_NDE_RETURN: { PRINT_TABS (hawk, depth); - if (((hawk_nde_return_t*)p)->val == HAWK_NULL) + if (((hawk_nde_return_t*)p)->val == HAWK_NULL) { hawk_getkwname (hawk, HAWK_KWID_RETURN, &kw); PUT_SRCSTRN (hawk, kw.ptr, kw.len); PUT_SRCSTR (hawk, HAWK_T(";")); PUT_NL (hawk); } - else + else { hawk_getkwname (hawk, HAWK_KWID_RETURN, &kw); PUT_SRCSTRN (hawk, kw.ptr, kw.len); @@ -1117,14 +1117,14 @@ static int print_stmt (hawk_t* hawk, hawk_nde_t* p, int depth) hawk_nde_exit_t* px = (hawk_nde_exit_t*)p; PRINT_TABS (hawk, depth); - if (px->val == HAWK_NULL) + if (px->val == HAWK_NULL) { hawk_getkwname (hawk, (px->abort? HAWK_KWID_XABORT: HAWK_KWID_EXIT), &kw); PUT_SRCSTRN (hawk, kw.ptr, kw.len); PUT_SRCSTR (hawk, HAWK_T(";")); PUT_NL (hawk); } - else + else { hawk_getkwname (hawk, (px->abort? HAWK_KWID_XABORT: HAWK_KWID_EXIT), &kw); PUT_SRCSTRN (hawk, kw.ptr, kw.len); @@ -1212,7 +1212,7 @@ static int print_stmts (hawk_t* hawk, hawk_nde_t* tree, int depth) { hawk_nde_t* p = tree; - while (p) + while (p) { if (print_stmt(hawk, p, depth) <= -1) return -1; p = p->next; @@ -1252,11 +1252,11 @@ void hawk_clrpt (hawk_t* hawk, hawk_nde_t* tree) hawk_nde_t* p = tree; hawk_nde_t* next; - while (p) + while (p) { next = p->next; - switch (p->type) + switch (p->type) { case HAWK_NDE_NULL: { @@ -1331,7 +1331,7 @@ void hawk_clrpt (hawk_t* hawk, hawk_nde_t* tree) case HAWK_NDE_EXIT: { - if (((hawk_nde_exit_t*)p)->val != HAWK_NULL) + if (((hawk_nde_exit_t*)p)->val != HAWK_NULL) hawk_clrpt (hawk, ((hawk_nde_exit_t*)p)->val); hawk_freemem (hawk, p); break; diff --git a/lib/utf16.c b/lib/utf16.c index 1bc35129..59a62937 100644 --- a/lib/utf16.c +++ b/lib/utf16.c @@ -38,13 +38,13 @@ hawk_oow_t hawk_uc_to_utf16 (hawk_uch_t uc, hawk_bch_t* utf16, hawk_oow_t size) { hawk_uint16_t* u16 = (hawk_uint16_t*)utf16; - if (uc <= 0xFFFF) + if (uc <= 0xFFFF) { u16[0] = (hawk_uint16_t)uc; return 2; } #if (HAWK_SIZEOF_UCH_T > 2) - else if (uc <= 0x10FFFF) + else if (uc <= 0x10FFFF) { u16[0] = HIGH_SURROGATE_START | (((uc >> 16) & 0x1F) - 1) | (uc >> 10); u16[1] = LOW_SURROGATE_START | (uc & 0x3FF); @@ -61,7 +61,7 @@ hawk_oow_t hawk_utf16_to_uc (const hawk_bch_t* utf16, hawk_oow_t size, hawk_uch_ if (size < 2) return 0; /* incomplete sequence */ - if (u16[0] < HIGH_SURROGATE_START || u16[0] > LOW_SURROGATE_END) + if (u16[0] < HIGH_SURROGATE_START || u16[0] > LOW_SURROGATE_END) { /* BMP - U+0000 - U+D7FF, U+E000 - U+FFFF */ *uc = u16[0]; diff --git a/lib/utf8.c b/lib/utf8.c index 68193bf8..618b404d 100644 --- a/lib/utf8.c +++ b/lib/utf8.c @@ -56,7 +56,7 @@ struct __utf8_t typedef struct __utf8_t __utf8_t; -static __utf8_t utf8_table[] = +static __utf8_t utf8_table[] = { {0x00000000ul, 0x0000007Ful, 0x00, 0x80, 0x7F, 1}, {0x00000080ul, 0x000007FFul, 0xC0, 0xE0, 0x1F, 2}, @@ -80,7 +80,7 @@ static HAWK_INLINE __utf8_t* get_utf8_slot (hawk_uch_t uc) end = utf8_table + HAWK_COUNTOF(utf8_table); cur = utf8_table; - while (cur < end) + while (cur < end) { if (uc >= cur->lower && uc <= cur->upper) return cur; cur++; @@ -98,7 +98,7 @@ hawk_oow_t hawk_uc_to_utf8 (hawk_uch_t uc, hawk_bch_t* utf8, hawk_oow_t size) if (utf8 && cur->length <= size) { int index = cur->length; - while (index > 1) + while (index > 1) { /* * 0x3F: 00111111 @@ -128,16 +128,16 @@ hawk_oow_t hawk_utf8_to_uc (const hawk_bch_t* utf8, hawk_oow_t size, hawk_uch_t* end = utf8_table + HAWK_COUNTOF(utf8_table); cur = utf8_table; - while (cur < end) + while (cur < end) { - if ((utf8[0] & cur->mask) == cur->fbyte) + if ((utf8[0] & cur->mask) == cur->fbyte) { - /* if size is less that cur->length, the incomplete-seqeunce + /* if size is less that cur->length, the incomplete-seqeunce * error is naturally indicated. so validate the string * only if size is as large as cur->length. */ - if (size >= cur->length) + if (size >= cur->length) { int i; @@ -149,12 +149,12 @@ hawk_oow_t hawk_utf8_to_uc (const hawk_bch_t* utf8, hawk_oow_t size, hawk_uch_t* for (i = 1; i < cur->length; i++) { /* in utf8, trailing bytes are all - * set with 0x80. + * set with 0x80. * * 10XXXXXX & 11000000 => 10000000 * * if not, invalid. */ - if ((utf8[i] & 0xC0) != 0x80) return 0; + if ((utf8[i] & 0xC0) != 0x80) return 0; w = (w << 6) | (utf8[i] & 0x3F); } *uc = w; @@ -164,19 +164,19 @@ hawk_oow_t hawk_utf8_to_uc (const hawk_bch_t* utf8, hawk_oow_t size, hawk_uch_t* for (i = 1; i < cur->length; i++) { /* in utf8, trailing bytes are all - * set with 0x80. + * set with 0x80. * * 10XXXXXX & 11000000 => 10000000 * * if not, invalid. */ - if ((utf8[i] & 0xC0) != 0x80) return 0; + if ((utf8[i] & 0xC0) != 0x80) return 0; } } } - /* this return value can indicate both - * the correct length (size >= cur->length) - * and + /* this return value can indicate both + * the correct length (size >= cur->length) + * and * the incomplete seqeunce error (size < cur->length). */ return (hawk_oow_t)cur->length; diff --git a/lib/utl-ass.c b/lib/utl-ass.c index 0d11cbc2..997df339 100644 --- a/lib/utl-ass.c +++ b/lib/utl-ass.c @@ -69,7 +69,7 @@ static void backtrace_stack_frames (void) unw_init_local(&cursor, &context); printf ("[BACKTRACE]\n"); - for (n = 0; unw_step(&cursor) > 0; n++) + for (n = 0; unw_step(&cursor) > 0; n++) { unw_word_t ip, sp, off; char symbol[256]; @@ -77,13 +77,13 @@ static void backtrace_stack_frames (void) unw_get_reg (&cursor, UNW_REG_IP, &ip); unw_get_reg (&cursor, UNW_REG_SP, &sp); - if (unw_get_proc_name(&cursor, symbol, HAWK_COUNTOF(symbol), &off)) + if (unw_get_proc_name(&cursor, symbol, HAWK_COUNTOF(symbol), &off)) { hawk_copy_bcstr (symbol, HAWK_COUNTOF(symbol), ""); } printf ( - "#%02d ip=0x%*p sp=0x%*p %s+0x%lu\n", + "#%02d ip=0x%*p sp=0x%*p %s+0x%lu\n", n, HAWK_SIZEOF(void*) * 2, (void*)ip, HAWK_SIZEOF(void*) * 2, (void*)sp, symbol, (unsigned long int)off); } } diff --git a/lib/utl-rnd.c b/lib/utl-rnd.c index 46f85baa..60bf100b 100644 --- a/lib/utl-rnd.c +++ b/lib/utl-rnd.c @@ -24,7 +24,7 @@ #include -/* Park-Miller "minimal standard" 31 bit +/* Park-Miller "minimal standard" 31 bit * pseudo-random number generator, implemented * with David G. Carta's optimisation: with * 32 bit math and without division. diff --git a/lib/utl-sort.c b/lib/utl-sort.c index 4a9787e4..1dea90fb 100644 --- a/lib/utl-sort.c +++ b/lib/utl-sort.c @@ -90,8 +90,8 @@ break; \ } \ } while(0) - - + + #define vecswap(a,b,n) do { \ if ((n) > 0) \ { \ @@ -102,12 +102,12 @@ static HAWK_INLINE hawk_oob_t* med3 (hawk_oob_t* a, hawk_oob_t* b, hawk_oob_t* c, hawk_sort_comper_t comper, void* ctx) { - if (comper(a, b, ctx) < 0) + if (comper(a, b, ctx) < 0) { if (comper(b, c, ctx) < 0) return b; return (comper(a, c, ctx) < 0)? c: a; } - else + else { if (comper(b, c, ctx) > 0) return b; return (comper(a, c, ctx) > 0)? c: a; @@ -127,7 +127,7 @@ static HAWK_INLINE hawk_oob_t* med3x (hawk_oob_t* a, hawk_oob_t* b, hawk_oob_t* if (comper(a, c, ctx, &n) <= -1) return HAWK_NULL; return (n < 0)? c: a; } - else + else { if (comper(b, c, ctx, &n) <= -1) return HAWK_NULL; if (n > 0) return b; @@ -144,11 +144,11 @@ void hawk_qsort (void* base, hawk_oow_t nmemb, hawk_oow_t size, hawk_sort_comper hawk_oow_t d; register hawk_oob_t* a = (hawk_oob_t*)base; -loop: +loop: swaptype = get_swaptype(a, size); swap_cnt = 0; - if (nmemb < 7) + if (nmemb < 7) { hawk_oob_t* end = (hawk_oob_t*)a + (nmemb * size); for (pm = (hawk_oob_t*)a + size; pm < end; pm += size) @@ -161,11 +161,11 @@ loop: return; } pm = (hawk_oob_t*)a + (nmemb / 2) * size; - if (nmemb > 7) + if (nmemb > 7) { pl = (hawk_oob_t*)a; pn = (hawk_oob_t*)a + (nmemb - 1) * size; - if (nmemb > 40) + if (nmemb > 40) { d = (nmemb / 8) * size; pl = med3(pl, pl + d, pl + 2 * d, comper, ctx); @@ -178,11 +178,11 @@ loop: pa = pb = (hawk_oob_t*)a + size; pc = pd = (hawk_oob_t*)a + (nmemb - 1) * size; - for (;;) + for (;;) { - while (pb <= pc && (r = comper(pb, a, ctx)) <= 0) + while (pb <= pc && (r = comper(pb, a, ctx)) <= 0) { - if (r == 0) + if (r == 0) { swap_cnt = 1; swap(pa, pb, size); @@ -190,9 +190,9 @@ loop: } pb += size; } - while (pb <= pc && (r = comper(pc, a, ctx)) >= 0) + while (pb <= pc && (r = comper(pc, a, ctx)) >= 0) { - if (r == 0) + if (r == 0) { swap_cnt = 1; swap(pc, pd, size); @@ -207,10 +207,10 @@ loop: pc -= size; } - if (swap_cnt == 0) + if (swap_cnt == 0) { /* switch to insertion sort */ - for (pm = (hawk_oob_t*)a + size; + for (pm = (hawk_oob_t*)a + size; pm < (hawk_oob_t*)a + nmemb * size; pm += size) { for (pl = pm; pl > (hawk_oob_t*)a && comper(pl - size, pl, ctx) > 0; pl -= size) @@ -229,7 +229,7 @@ loop: if ((r = pb - pa) > size) hawk_qsort(a, r / size, size, comper, ctx); - if ((r = pd - pc) > size) + if ((r = pd - pc) > size) { /* Iterate rather than recurse to save stack space */ a = pn - r; @@ -248,11 +248,11 @@ int hawk_qsortx (void* base, hawk_oow_t nmemb, hawk_oow_t size, hawk_sort_comper hawk_oow_t d; register hawk_oob_t* a = (hawk_oob_t*)base; -loop: +loop: swaptype = get_swaptype(a, size); swap_cnt = 0; - if (nmemb < 7) + if (nmemb < 7) { hawk_oob_t* end = (hawk_oob_t*)a + (nmemb * size); for (pm = (hawk_oob_t*)a + size; pm < end; pm += size) @@ -270,11 +270,11 @@ loop: return 0; } pm = (hawk_oob_t*)a + (nmemb / 2) * size; - if (nmemb > 7) + if (nmemb > 7) { pl = (hawk_oob_t*)a; pn = (hawk_oob_t*)a + (nmemb - 1) * size; - if (nmemb > 40) + if (nmemb > 40) { d = (nmemb / 8) * size; pl = med3x(pl, pl + d, pl + 2 * d, comper, ctx); @@ -291,14 +291,14 @@ loop: pa = pb = (hawk_oob_t*)a + size; pc = pd = (hawk_oob_t*)a + (nmemb - 1) * size; - for (;;) + for (;;) { while (pb <= pc) { if (comper(pb, a, ctx, &n) <= -1) return -1; if (n > 0) break; - if (n == 0) + if (n == 0) { swap_cnt = 1; swap(pa, pb, size); @@ -311,7 +311,7 @@ loop: if (comper(pc, a, ctx, &n) <= -1) return -1; if (n < 0) break; - if (n == 0) + if (n == 0) { swap_cnt = 1; swap(pc, pd, size); @@ -326,7 +326,7 @@ loop: pc -= size; } - if (swap_cnt == 0) + if (swap_cnt == 0) { /* switch to insertion sort */ hawk_oob_t* end = (hawk_oob_t*)a + (nmemb * size); @@ -350,12 +350,12 @@ loop: r = qsort_min (pd - pc, pn - pd - size); vecswap (pb, pn - r, r); - if ((r = pb - pa) > size) + if ((r = pb - pa) > size) { if (hawk_qsortx(a, r / size, size, comper, ctx) <= -1) return -1; } - if ((r = pd - pc) > size) + if ((r = pd - pc) > size) { /* Iterate rather than recurse to save stack space */ a = pn - r; @@ -369,7 +369,7 @@ loop: #if 0 -/* +/* * Below is an example of a naive qsort implementation */ @@ -404,15 +404,15 @@ void hawk_qsort (void* base, hawk_oow_t nmemb, hawk_oow_t size, void* arg, pivot = nmemb >> 1; /* choose the middle as the pivot index */ swap (REF(p,pivot), REF(p,nmemb-1), size); /* swap the pivot with the last item */ - start = 0; end = nmemb - 2; + start = 0; end = nmemb - 2; while (1) { /* look for the larger value than pivot */ - while (start <= end && + while (start <= end && compar(REF(p,start), REF(p,nmemb-1), arg) <= 0) start++; /* look for the less value than pivot. */ - while (end > start && + while (end > start && compar(REF(p,end), REF(p,nmemb-1), arg) >= 0) end--; if (start >= end) break; /* no more to swap */ @@ -427,7 +427,7 @@ void hawk_qsort (void* base, hawk_oow_t nmemb, hawk_oow_t size, void* arg, hawk_qsort (REF(p,pivot+1), nmemb - pivot - 1, size, arg, compar); } -/* +/* * For easier understanding, see the following */ @@ -448,7 +448,7 @@ void qsort (int* x, size_t n) pivot = x[index]; /* store the pivot value */ swap (x[index], x[n - 1]); /* swap the pivot with the last item */ - start = 0; end = n - 2; + start = 0; end = n - 2; while (1) { /* look for the larger value than pivot */ while (start <= end && x[start] <= pivot) start++; @@ -457,7 +457,7 @@ void qsort (int* x, size_t n) while (end > start && x[end] >= pivot) end--; if (start >= end) { - /* less values all on the left, + /* less values all on the left, * larger values all on the right */ break; diff --git a/lib/utl-str.c b/lib/utl-str.c index c543d76d..3e19dda4 100644 --- a/lib/utl-str.c +++ b/lib/utl-str.c @@ -22,11 +22,11 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* +/* * Do NOT edit utl-str.c. Edit utl-str.c.m4 instead. - * + * * Generate utl-str.c with m4 - * $ m4 utl-str.c.m4 > utl-str.c + * $ m4 utl-str.c.m4 > utl-str.c */ #include "hawk-prv.h" @@ -34,57 +34,57 @@ static int match_uch_class (const hawk_uch_t* pp, hawk_uch_t sc, int* matched) { - if (hawk_comp_ucstr_bcstr_limited(pp, "[:upper:]", 9, 0) == 0) + if (hawk_comp_ucstr_bcstr_limited(pp, "[:upper:]", 9, 0) == 0) { *matched = hawk_is_uch_upper(sc); return 9; } - else if (hawk_comp_ucstr_bcstr_limited(pp, "[:lower:]", 9, 0) == 0) + else if (hawk_comp_ucstr_bcstr_limited(pp, "[:lower:]", 9, 0) == 0) { *matched = hawk_is_uch_lower(sc); return 9; } - else if (hawk_comp_ucstr_bcstr_limited(pp, "[:alpha:]", 9, 0) == 0) + else if (hawk_comp_ucstr_bcstr_limited(pp, "[:alpha:]", 9, 0) == 0) { *matched = hawk_is_uch_alpha(sc); return 9; } - else if (hawk_comp_ucstr_bcstr_limited(pp, "[:digit:]", 9, 0) == 0) + else if (hawk_comp_ucstr_bcstr_limited(pp, "[:digit:]", 9, 0) == 0) { *matched = hawk_is_uch_digit(sc); return 9; } - else if (hawk_comp_ucstr_bcstr_limited(pp, "[:xdigit:]", 10, 0) == 0) + else if (hawk_comp_ucstr_bcstr_limited(pp, "[:xdigit:]", 10, 0) == 0) { *matched = hawk_is_uch_xdigit(sc); return 10; } - else if (hawk_comp_ucstr_bcstr_limited(pp, "[:alnum:]", 9, 0) == 0) + else if (hawk_comp_ucstr_bcstr_limited(pp, "[:alnum:]", 9, 0) == 0) { *matched = hawk_is_uch_alnum(sc); return 9; } - else if (hawk_comp_ucstr_bcstr_limited(pp, "[:space:]", 9, 0) == 0) + else if (hawk_comp_ucstr_bcstr_limited(pp, "[:space:]", 9, 0) == 0) { *matched = hawk_is_uch_space(sc); return 9; } - else if (hawk_comp_ucstr_bcstr_limited(pp, "[:print:]", 9, 0) == 0) + else if (hawk_comp_ucstr_bcstr_limited(pp, "[:print:]", 9, 0) == 0) { *matched = hawk_is_uch_print(sc); return 9; } - else if (hawk_comp_ucstr_bcstr_limited(pp, "[:graph:]", 9, 0) == 0) + else if (hawk_comp_ucstr_bcstr_limited(pp, "[:graph:]", 9, 0) == 0) { *matched = hawk_is_uch_graph(sc); return 9; } - else if (hawk_comp_ucstr_bcstr_limited(pp, "[:cntrl:]", 9, 0) == 0) + else if (hawk_comp_ucstr_bcstr_limited(pp, "[:cntrl:]", 9, 0) == 0) { *matched = hawk_is_uch_cntrl(sc); return 9; } - else if (hawk_comp_ucstr_bcstr_limited(pp, "[:punct:]", 9, 0) == 0) + else if (hawk_comp_ucstr_bcstr_limited(pp, "[:punct:]", 9, 0) == 0) { *matched = hawk_is_uch_punct(sc); return 9; @@ -95,57 +95,57 @@ static int match_uch_class (const hawk_uch_t* pp, hawk_uch_t sc, int* matched) static int match_bch_class (const hawk_bch_t* pp, hawk_bch_t sc, int* matched) { - if (hawk_comp_bcstr_limited(pp, "[:upper:]", 9, 0) == 0) + if (hawk_comp_bcstr_limited(pp, "[:upper:]", 9, 0) == 0) { *matched = hawk_is_bch_upper(sc); return 9; } - else if (hawk_comp_bcstr_limited(pp, "[:lower:]", 9, 0) == 0) + else if (hawk_comp_bcstr_limited(pp, "[:lower:]", 9, 0) == 0) { *matched = hawk_is_bch_lower(sc); return 9; } - else if (hawk_comp_bcstr_limited(pp, "[:alpha:]", 9, 0) == 0) + else if (hawk_comp_bcstr_limited(pp, "[:alpha:]", 9, 0) == 0) { *matched = hawk_is_bch_alpha(sc); return 9; } - else if (hawk_comp_bcstr_limited(pp, "[:digit:]", 9, 0) == 0) + else if (hawk_comp_bcstr_limited(pp, "[:digit:]", 9, 0) == 0) { *matched = hawk_is_bch_digit(sc); return 9; } - else if (hawk_comp_bcstr_limited(pp, "[:xdigit:]", 10, 0) == 0) + else if (hawk_comp_bcstr_limited(pp, "[:xdigit:]", 10, 0) == 0) { *matched = hawk_is_bch_xdigit(sc); return 10; } - else if (hawk_comp_bcstr_limited(pp, "[:alnum:]", 9, 0) == 0) + else if (hawk_comp_bcstr_limited(pp, "[:alnum:]", 9, 0) == 0) { *matched = hawk_is_bch_alnum(sc); return 9; } - else if (hawk_comp_bcstr_limited(pp, "[:space:]", 9, 0) == 0) + else if (hawk_comp_bcstr_limited(pp, "[:space:]", 9, 0) == 0) { *matched = hawk_is_bch_space(sc); return 9; } - else if (hawk_comp_bcstr_limited(pp, "[:print:]", 9, 0) == 0) + else if (hawk_comp_bcstr_limited(pp, "[:print:]", 9, 0) == 0) { *matched = hawk_is_bch_print(sc); return 9; } - else if (hawk_comp_bcstr_limited(pp, "[:graph:]", 9, 0) == 0) + else if (hawk_comp_bcstr_limited(pp, "[:graph:]", 9, 0) == 0) { *matched = hawk_is_bch_graph(sc); return 9; } - else if (hawk_comp_bcstr_limited(pp, "[:cntrl:]", 9, 0) == 0) + else if (hawk_comp_bcstr_limited(pp, "[:cntrl:]", 9, 0) == 0) { *matched = hawk_is_bch_cntrl(sc); return 9; } - else if (hawk_comp_bcstr_limited(pp, "[:punct:]", 9, 0) == 0) + else if (hawk_comp_bcstr_limited(pp, "[:punct:]", 9, 0) == 0) { *matched = hawk_is_bch_punct(sc); return 9; @@ -168,7 +168,7 @@ int hawk_comp_uchars (const hawk_uch_t* str1, hawk_oow_t len1, const hawk_uch_t* while (str1 < end1) { c1 = hawk_to_uch_lower(*str1); - if (str2 < end2) + if (str2 < end2) { c2 = hawk_to_uch_lower(*str2); if (c1 > c2) return 1; @@ -183,7 +183,7 @@ int hawk_comp_uchars (const hawk_uch_t* str1, hawk_oow_t len1, const hawk_uch_t* while (str1 < end1) { c1 = *str1; - if (str2 < end2) + if (str2 < end2) { c2 = *str2; if (c1 > c2) return 1; @@ -208,7 +208,7 @@ int hawk_comp_bchars (const hawk_bch_t* str1, hawk_oow_t len1, const hawk_bch_t* while (str1 < end1) { c1 = hawk_to_bch_lower(*str1); - if (str2 < end2) + if (str2 < end2) { c2 = hawk_to_bch_lower(*str2); if (c1 > c2) return 1; @@ -223,7 +223,7 @@ int hawk_comp_bchars (const hawk_bch_t* str1, hawk_oow_t len1, const hawk_bch_t* while (str1 < end1) { c1 = *str1; - if (str2 < end2) + if (str2 < end2) { c2 = *str2; if (c1 > c2) return 1; @@ -341,14 +341,14 @@ int hawk_comp_uchars_ucstr (const hawk_uch_t* str1, hawk_oow_t len, const hawk_u { /* for "abc\0" of length 4 vs "abc", the fourth character * of the first string is equal to the terminating null of - * the second string. the first string is still considered + * the second string. the first string is still considered * bigger */ if (ignorecase) { const hawk_uch_t* end = str1 + len; hawk_uch_t c1; hawk_uch_t c2; - while (str1 < end && *str2 != '\0') + while (str1 < end && *str2 != '\0') { c1 = hawk_to_uch_lower(*str1); c2 = hawk_to_uch_lower(*str2); @@ -360,7 +360,7 @@ int hawk_comp_uchars_ucstr (const hawk_uch_t* str1, hawk_oow_t len, const hawk_u else { const hawk_uch_t* end = str1 + len; - while (str1 < end && *str2 != '\0') + while (str1 < end && *str2 != '\0') { if (*str1 != *str2) return ((hawk_uchu_t)*str1 > (hawk_uchu_t)*str2)? 1: -1; str1++; str2++; @@ -373,14 +373,14 @@ int hawk_comp_bchars_bcstr (const hawk_bch_t* str1, hawk_oow_t len, const hawk_b { /* for "abc\0" of length 4 vs "abc", the fourth character * of the first string is equal to the terminating null of - * the second string. the first string is still considered + * the second string. the first string is still considered * bigger */ if (ignorecase) { const hawk_bch_t* end = str1 + len; hawk_bch_t c1; hawk_bch_t c2; - while (str1 < end && *str2 != '\0') + while (str1 < end && *str2 != '\0') { c1 = hawk_to_bch_lower(*str1); c2 = hawk_to_bch_lower(*str2); @@ -392,7 +392,7 @@ int hawk_comp_bchars_bcstr (const hawk_bch_t* str1, hawk_oow_t len, const hawk_b else { const hawk_bch_t* end = str1 + len; - while (str1 < end && *str2 != '\0') + while (str1 < end && *str2 != '\0') { if (*str1 != *str2) return ((hawk_bchu_t)*str1 > (hawk_bchu_t)*str2)? 1: -1; str1++; str2++; @@ -415,7 +415,7 @@ hawk_oow_t hawk_concat_uchars_to_ucstr (hawk_uch_t* buf, hawk_oow_t bsz, const h end = str + len; - while (p < p2) + while (p < p2) { if (str >= end) break; *p++ = *str++; @@ -439,7 +439,7 @@ hawk_oow_t hawk_concat_bchars_to_bcstr (hawk_bch_t* buf, hawk_oow_t bsz, const h end = str + len; - while (p < p2) + while (p < p2) { if (str >= end) break; *p++ = *str++; @@ -460,7 +460,7 @@ hawk_oow_t hawk_concat_ucstr (hawk_uch_t* buf, hawk_oow_t bsz, const hawk_uch_t* p = buf + blen; p2 = buf + bsz - 1; - while (p < p2) + while (p < p2) { if (*str == '\0') break; *p++ = *str++; @@ -481,7 +481,7 @@ hawk_oow_t hawk_concat_bcstr (hawk_bch_t* buf, hawk_oow_t bsz, const hawk_bch_t* p = buf + blen; p2 = buf + bsz - 1; - while (p < p2) + while (p < p2) { if (*str == '\0') break; *p++ = *str++; @@ -742,15 +742,15 @@ hawk_oow_t hawk_copy_fmt_ucses_to_ucstr (hawk_uch_t* buf, hawk_oow_t bsz, const hawk_uch_t* b = buf; hawk_uch_t* end = buf + bsz - 1; const hawk_uch_t* f = fmt; - + if (bsz <= 0) return 0; - + while (*f != '\0') { if (*f == '\\') { /* get the escaped character and treat it normally. - * if the escaper is the last character, treat it + * if the escaper is the last character, treat it * normally also. */ if (f[1] != '\0') f++; } @@ -760,24 +760,24 @@ hawk_oow_t hawk_copy_fmt_ucses_to_ucstr (hawk_uch_t* buf, hawk_oow_t bsz, const { const hawk_uch_t* tmp, * tmpend; hawk_oow_t idx = 0; - + tmp = f; f += 2; - + do idx = idx * 10 + (*f++ - '0'); while (*f >= '0' && *f <= '9'); - + if (*f != '}') { f = tmp; goto normal; } - + f++; - + tmp = str[idx].ptr; tmpend = tmp + str[idx].len; - + while (tmp < tmpend) { if (b >= end) goto fini; @@ -787,12 +787,12 @@ hawk_oow_t hawk_copy_fmt_ucses_to_ucstr (hawk_uch_t* buf, hawk_oow_t bsz, const } else if (f[1] == '$') f++; } - + normal: if (b >= end) break; *b++ = *f++; } - + fini: *b = '\0'; return b - buf; @@ -803,15 +803,15 @@ hawk_oow_t hawk_copy_fmt_bcses_to_bcstr (hawk_bch_t* buf, hawk_oow_t bsz, const hawk_bch_t* b = buf; hawk_bch_t* end = buf + bsz - 1; const hawk_bch_t* f = fmt; - + if (bsz <= 0) return 0; - + while (*f != '\0') { if (*f == '\\') { /* get the escaped character and treat it normally. - * if the escaper is the last character, treat it + * if the escaper is the last character, treat it * normally also. */ if (f[1] != '\0') f++; } @@ -821,24 +821,24 @@ hawk_oow_t hawk_copy_fmt_bcses_to_bcstr (hawk_bch_t* buf, hawk_oow_t bsz, const { const hawk_bch_t* tmp, * tmpend; hawk_oow_t idx = 0; - + tmp = f; f += 2; - + do idx = idx * 10 + (*f++ - '0'); while (*f >= '0' && *f <= '9'); - + if (*f != '}') { f = tmp; goto normal; } - + f++; - + tmp = str[idx].ptr; tmpend = tmp + str[idx].len; - + while (tmp < tmpend) { if (b >= end) goto fini; @@ -848,12 +848,12 @@ hawk_oow_t hawk_copy_fmt_bcses_to_bcstr (hawk_bch_t* buf, hawk_oow_t bsz, const } else if (f[1] == '$') f++; } - + normal: if (b >= end) break; *b++ = *f++; } - + fini: *b = '\0'; return b - buf; @@ -864,14 +864,14 @@ hawk_oow_t hawk_count_ucstr (const hawk_uch_t* str) const hawk_uch_t* ptr = str; while (*ptr != '\0') ptr++; return ptr - str; -} +} hawk_oow_t hawk_count_bcstr (const hawk_bch_t* str) { const hawk_bch_t* ptr = str; while (*ptr != '\0') ptr++; return ptr - str; -} +} hawk_oow_t hawk_count_ucstr_limited (const hawk_uch_t* str, hawk_oow_t maxlen) { @@ -1047,13 +1047,13 @@ hawk_uch_t* hawk_find_uchars_in_uchars (const hawk_uch_t* str, hawk_oow_t strsz, if (subsz == 0) return (hawk_uch_t*)str; if (strsz < subsz) return HAWK_NULL; - + end = str + strsz - subsz; subp = sub + subsz; if (HAWK_UNLIKELY(ignorecase)) { - while (str <= end) + while (str <= end) { const hawk_uch_t* x = str; const hawk_uch_t* y = sub; @@ -1070,7 +1070,7 @@ hawk_uch_t* hawk_find_uchars_in_uchars (const hawk_uch_t* str, hawk_oow_t strsz, } else { - while (str <= end) + while (str <= end) { const hawk_uch_t* x = str; const hawk_uch_t* y = sub; @@ -1095,13 +1095,13 @@ hawk_bch_t* hawk_find_bchars_in_bchars (const hawk_bch_t* str, hawk_oow_t strsz, if (subsz == 0) return (hawk_bch_t*)str; if (strsz < subsz) return HAWK_NULL; - + end = str + strsz - subsz; subp = sub + subsz; if (HAWK_UNLIKELY(ignorecase)) { - while (str <= end) + while (str <= end) { const hawk_bch_t* x = str; const hawk_bch_t* y = sub; @@ -1118,7 +1118,7 @@ hawk_bch_t* hawk_find_bchars_in_bchars (const hawk_bch_t* str, hawk_oow_t strsz, } else { - while (str <= end) + while (str <= end) { const hawk_bch_t* x = str; const hawk_bch_t* y = sub; @@ -1149,12 +1149,12 @@ hawk_uch_t* hawk_rfind_uchars_in_uchars (const hawk_uch_t* str, hawk_oow_t strsz if (HAWK_UNLIKELY(ignorecase)) { - while (p >= str) + while (p >= str) { const hawk_uch_t* x = p; const hawk_uch_t* y = sub; - while (1) + while (1) { if (y >= subp) return (hawk_uch_t*)p; if (hawk_to_uch_lower(*x) != hawk_to_uch_lower(*y)) break; @@ -1166,17 +1166,17 @@ hawk_uch_t* hawk_rfind_uchars_in_uchars (const hawk_uch_t* str, hawk_oow_t strsz } else { - while (p >= str) + while (p >= str) { const hawk_uch_t* x = p; const hawk_uch_t* y = sub; - while (1) + while (1) { if (y >= subp) return (hawk_uch_t*)p; if (*x != *y) break; x++; y++; - } + } p--; } @@ -1197,12 +1197,12 @@ hawk_bch_t* hawk_rfind_bchars_in_bchars (const hawk_bch_t* str, hawk_oow_t strsz if (HAWK_UNLIKELY(ignorecase)) { - while (p >= str) + while (p >= str) { const hawk_bch_t* x = p; const hawk_bch_t* y = sub; - while (1) + while (1) { if (y >= subp) return (hawk_bch_t*)p; if (hawk_to_bch_lower(*x) != hawk_to_bch_lower(*y)) break; @@ -1214,17 +1214,17 @@ hawk_bch_t* hawk_rfind_bchars_in_bchars (const hawk_bch_t* str, hawk_oow_t strsz } else { - while (p >= str) + while (p >= str) { const hawk_bch_t* x = p; const hawk_bch_t* y = sub; - while (1) + while (1) { if (y >= subp) return (hawk_bch_t*)p; if (*x != *y) break; x++; y++; - } + } p--; } @@ -1239,30 +1239,30 @@ hawk_oow_t hawk_compact_uchars (hawk_uch_t* str, hawk_oow_t len) int followed_by_space = 0; int state = 0; - while (p < end) + while (p < end) { - if (state == 0) + if (state == 0) { - if (!hawk_is_uch_space(*p)) + if (!hawk_is_uch_space(*p)) { *q++ = *p; state = 1; } } - else if (state == 1) + else if (state == 1) { - if (hawk_is_uch_space(*p)) + if (hawk_is_uch_space(*p)) { - if (!followed_by_space) + if (!followed_by_space) { followed_by_space = 1; *q++ = *p; } } - else + else { followed_by_space = 0; - *q++ = *p; + *q++ = *p; } } @@ -1278,30 +1278,30 @@ hawk_oow_t hawk_compact_bchars (hawk_bch_t* str, hawk_oow_t len) int followed_by_space = 0; int state = 0; - while (p < end) + while (p < end) { - if (state == 0) + if (state == 0) { - if (!hawk_is_bch_space(*p)) + if (!hawk_is_bch_space(*p)) { *q++ = *p; state = 1; } } - else if (state == 1) + else if (state == 1) { - if (hawk_is_bch_space(*p)) + if (hawk_is_bch_space(*p)) { - if (!followed_by_space) + if (!followed_by_space) { followed_by_space = 1; *q++ = *p; } } - else + else { followed_by_space = 0; - *q++ = *p; + *q++ = *p; } } @@ -1400,11 +1400,11 @@ hawk_uch_t* hawk_trim_uchars (const hawk_uch_t* str, hawk_oow_t* len, int flags) if (e) { - if (flags & HAWK_TRIM_UCHARS_RIGHT) + if (flags & HAWK_TRIM_UCHARS_RIGHT) { *len -= end - e - 1; } - if (flags & HAWK_TRIM_UCHARS_LEFT) + if (flags & HAWK_TRIM_UCHARS_LEFT) { *len -= s - str; str = s; @@ -1413,7 +1413,7 @@ hawk_uch_t* hawk_trim_uchars (const hawk_uch_t* str, hawk_oow_t* len, int flags) else { /* the entire string need to be deleted */ - if ((flags & HAWK_TRIM_UCHARS_RIGHT) || + if ((flags & HAWK_TRIM_UCHARS_RIGHT) || (flags & HAWK_TRIM_UCHARS_LEFT)) *len = 0; } } @@ -1442,11 +1442,11 @@ hawk_bch_t* hawk_trim_bchars (const hawk_bch_t* str, hawk_oow_t* len, int flags) if (e) { - if (flags & HAWK_TRIM_BCHARS_RIGHT) + if (flags & HAWK_TRIM_BCHARS_RIGHT) { *len -= end - e - 1; } - if (flags & HAWK_TRIM_BCHARS_LEFT) + if (flags & HAWK_TRIM_BCHARS_LEFT) { *len -= s - str; str = s; @@ -1455,7 +1455,7 @@ hawk_bch_t* hawk_trim_bchars (const hawk_bch_t* str, hawk_oow_t* len, int flags) else { /* the entire string need to be deleted */ - if ((flags & HAWK_TRIM_BCHARS_RIGHT) || + if ((flags & HAWK_TRIM_BCHARS_RIGHT) || (flags & HAWK_TRIM_BCHARS_LEFT)) *len = 0; } } @@ -1471,35 +1471,35 @@ int hawk_split_ucstr (hawk_uch_t* s, const hawk_uch_t* delim, hawk_uch_t lquote, int cnt = 0; if (delim == HAWK_NULL) delim_mode = 0; - else + else { delim_mode = 1; for (d = (hawk_uch_t*)delim; *d != '\0'; d++) if (!hawk_is_uch_space(*d)) delim_mode = 2; } - if (delim_mode == 0) + if (delim_mode == 0) { /* skip preceding space characters */ while (hawk_is_uch_space(*p)) p++; /* when 0 is given as "delim", it has an effect of cutting preceding and trailing space characters off "s". */ - if (lquote != '\0' && *p == lquote) + if (lquote != '\0' && *p == lquote) { hawk_copy_ucstr_unlimited (p, p + 1); - for (;;) + for (;;) { if (*p == '\0') return -1; - if (escape != '\0' && *p == escape) + if (escape != '\0' && *p == escape) { hawk_copy_ucstr_unlimited (p, p + 1); } - else + else { - if (*p == rquote) + if (*p == rquote) { p++; break; @@ -1514,18 +1514,18 @@ int hawk_split_ucstr (hawk_uch_t* s, const hawk_uch_t* delim, hawk_uch_t lquote, if (*p != '\0') return -1; if (sp == 0 && ep == 0) s[0] = '\0'; - else + else { ep[1] = '\0'; if (s != (hawk_uch_t*)sp) hawk_copy_ucstr_unlimited (s, sp); cnt++; } } - else + else { - while (*p) + while (*p) { - if (!hawk_is_uch_space(*p)) + if (!hawk_is_uch_space(*p)) { if (sp == 0) sp = p; ep = p; @@ -1534,7 +1534,7 @@ int hawk_split_ucstr (hawk_uch_t* s, const hawk_uch_t* delim, hawk_uch_t lquote, } if (sp == 0 && ep == 0) s[0] = '\0'; - else + else { ep[1] = '\0'; if (s != (hawk_uch_t*)sp) hawk_copy_ucstr_unlimited (s, sp); @@ -1542,31 +1542,31 @@ int hawk_split_ucstr (hawk_uch_t* s, const hawk_uch_t* delim, hawk_uch_t lquote, } } } - else if (delim_mode == 1) + else if (delim_mode == 1) { hawk_uch_t* o; - while (*p) + while (*p) { o = p; while (hawk_is_uch_space(*p)) p++; if (o != p) { hawk_copy_ucstr_unlimited (o, p); p = o; } - if (lquote != '\0' && *p == lquote) + if (lquote != '\0' && *p == lquote) { hawk_copy_ucstr_unlimited (p, p + 1); - for (;;) + for (;;) { if (*p == '\0') return -1; - if (escape != '\0' && *p == escape) + if (escape != '\0' && *p == escape) { hawk_copy_ucstr_unlimited (p, p + 1); } - else + else { - if (*p == rquote) + if (*p == rquote) { *p++ = '\0'; cnt++; @@ -1576,17 +1576,17 @@ int hawk_split_ucstr (hawk_uch_t* s, const hawk_uch_t* delim, hawk_uch_t lquote, p++; } } - else + else { o = p; - for (;;) + for (;;) { - if (*p == '\0') + if (*p == '\0') { if (o != p) cnt++; break; } - if (hawk_is_uch_space(*p)) + if (hawk_is_uch_space(*p)) { *p++ = '\0'; cnt++; @@ -1602,27 +1602,27 @@ int hawk_split_ucstr (hawk_uch_t* s, const hawk_uch_t* delim, hawk_uch_t lquote, hawk_uch_t* o; int ok; - while (*p != '\0') + while (*p != '\0') { o = p; while (hawk_is_uch_space(*p)) p++; if (o != p) { hawk_copy_ucstr_unlimited (o, p); p = o; } - if (lquote != '\0' && *p == lquote) + if (lquote != '\0' && *p == lquote) { hawk_copy_ucstr_unlimited (p, p + 1); - for (;;) + for (;;) { if (*p == '\0') return -1; - if (escape != '\0' && *p == escape) + if (escape != '\0' && *p == escape) { hawk_copy_ucstr_unlimited (p, p + 1); } - else + else { - if (*p == rquote) + if (*p == rquote) { *p++ = '\0'; cnt++; @@ -1635,9 +1635,9 @@ int hawk_split_ucstr (hawk_uch_t* s, const hawk_uch_t* delim, hawk_uch_t lquote, ok = 0; while (hawk_is_uch_space(*p)) p++; if (*p == '\0') ok = 1; - for (d = (hawk_uch_t*)delim; *d != '\0'; d++) + for (d = (hawk_uch_t*)delim; *d != '\0'; d++) { - if (*p == *d) + if (*p == *d) { ok = 1; hawk_copy_ucstr_unlimited (p, p + 1); @@ -1646,15 +1646,15 @@ int hawk_split_ucstr (hawk_uch_t* s, const hawk_uch_t* delim, hawk_uch_t lquote, } if (ok == 0) return -1; } - else + else { o = p; sp = ep = 0; - for (;;) + for (;;) { - if (*p == '\0') + if (*p == '\0') { - if (ep) + if (ep) { ep[1] = '\0'; p = &ep[1]; @@ -1662,16 +1662,16 @@ int hawk_split_ucstr (hawk_uch_t* s, const hawk_uch_t* delim, hawk_uch_t lquote, cnt++; break; } - for (d = (hawk_uch_t*)delim; *d != '\0'; d++) + for (d = (hawk_uch_t*)delim; *d != '\0'; d++) { - if (*p == *d) + if (*p == *d) { - if (sp == HAWK_NULL) + if (sp == HAWK_NULL) { hawk_copy_ucstr_unlimited (o, p); p = o; *p++ = '\0'; } - else + else { hawk_copy_ucstr_unlimited (&ep[1], p); hawk_copy_ucstr_unlimited (o, sp); @@ -1685,7 +1685,7 @@ int hawk_split_ucstr (hawk_uch_t* s, const hawk_uch_t* delim, hawk_uch_t lquote, } } - if (!hawk_is_uch_space(*p)) + if (!hawk_is_uch_space(*p)) { if (sp == HAWK_NULL) sp = p; ep = p; @@ -1709,35 +1709,35 @@ int hawk_split_bcstr (hawk_bch_t* s, const hawk_bch_t* delim, hawk_bch_t lquote, int cnt = 0; if (delim == HAWK_NULL) delim_mode = 0; - else + else { delim_mode = 1; for (d = (hawk_bch_t*)delim; *d != '\0'; d++) if (!hawk_is_bch_space(*d)) delim_mode = 2; } - if (delim_mode == 0) + if (delim_mode == 0) { /* skip preceding space characters */ while (hawk_is_bch_space(*p)) p++; /* when 0 is given as "delim", it has an effect of cutting preceding and trailing space characters off "s". */ - if (lquote != '\0' && *p == lquote) + if (lquote != '\0' && *p == lquote) { hawk_copy_bcstr_unlimited (p, p + 1); - for (;;) + for (;;) { if (*p == '\0') return -1; - if (escape != '\0' && *p == escape) + if (escape != '\0' && *p == escape) { hawk_copy_bcstr_unlimited (p, p + 1); } - else + else { - if (*p == rquote) + if (*p == rquote) { p++; break; @@ -1752,18 +1752,18 @@ int hawk_split_bcstr (hawk_bch_t* s, const hawk_bch_t* delim, hawk_bch_t lquote, if (*p != '\0') return -1; if (sp == 0 && ep == 0) s[0] = '\0'; - else + else { ep[1] = '\0'; if (s != (hawk_bch_t*)sp) hawk_copy_bcstr_unlimited (s, sp); cnt++; } } - else + else { - while (*p) + while (*p) { - if (!hawk_is_bch_space(*p)) + if (!hawk_is_bch_space(*p)) { if (sp == 0) sp = p; ep = p; @@ -1772,7 +1772,7 @@ int hawk_split_bcstr (hawk_bch_t* s, const hawk_bch_t* delim, hawk_bch_t lquote, } if (sp == 0 && ep == 0) s[0] = '\0'; - else + else { ep[1] = '\0'; if (s != (hawk_bch_t*)sp) hawk_copy_bcstr_unlimited (s, sp); @@ -1780,31 +1780,31 @@ int hawk_split_bcstr (hawk_bch_t* s, const hawk_bch_t* delim, hawk_bch_t lquote, } } } - else if (delim_mode == 1) + else if (delim_mode == 1) { hawk_bch_t* o; - while (*p) + while (*p) { o = p; while (hawk_is_bch_space(*p)) p++; if (o != p) { hawk_copy_bcstr_unlimited (o, p); p = o; } - if (lquote != '\0' && *p == lquote) + if (lquote != '\0' && *p == lquote) { hawk_copy_bcstr_unlimited (p, p + 1); - for (;;) + for (;;) { if (*p == '\0') return -1; - if (escape != '\0' && *p == escape) + if (escape != '\0' && *p == escape) { hawk_copy_bcstr_unlimited (p, p + 1); } - else + else { - if (*p == rquote) + if (*p == rquote) { *p++ = '\0'; cnt++; @@ -1814,17 +1814,17 @@ int hawk_split_bcstr (hawk_bch_t* s, const hawk_bch_t* delim, hawk_bch_t lquote, p++; } } - else + else { o = p; - for (;;) + for (;;) { - if (*p == '\0') + if (*p == '\0') { if (o != p) cnt++; break; } - if (hawk_is_bch_space(*p)) + if (hawk_is_bch_space(*p)) { *p++ = '\0'; cnt++; @@ -1840,27 +1840,27 @@ int hawk_split_bcstr (hawk_bch_t* s, const hawk_bch_t* delim, hawk_bch_t lquote, hawk_bch_t* o; int ok; - while (*p != '\0') + while (*p != '\0') { o = p; while (hawk_is_bch_space(*p)) p++; if (o != p) { hawk_copy_bcstr_unlimited (o, p); p = o; } - if (lquote != '\0' && *p == lquote) + if (lquote != '\0' && *p == lquote) { hawk_copy_bcstr_unlimited (p, p + 1); - for (;;) + for (;;) { if (*p == '\0') return -1; - if (escape != '\0' && *p == escape) + if (escape != '\0' && *p == escape) { hawk_copy_bcstr_unlimited (p, p + 1); } - else + else { - if (*p == rquote) + if (*p == rquote) { *p++ = '\0'; cnt++; @@ -1873,9 +1873,9 @@ int hawk_split_bcstr (hawk_bch_t* s, const hawk_bch_t* delim, hawk_bch_t lquote, ok = 0; while (hawk_is_bch_space(*p)) p++; if (*p == '\0') ok = 1; - for (d = (hawk_bch_t*)delim; *d != '\0'; d++) + for (d = (hawk_bch_t*)delim; *d != '\0'; d++) { - if (*p == *d) + if (*p == *d) { ok = 1; hawk_copy_bcstr_unlimited (p, p + 1); @@ -1884,15 +1884,15 @@ int hawk_split_bcstr (hawk_bch_t* s, const hawk_bch_t* delim, hawk_bch_t lquote, } if (ok == 0) return -1; } - else + else { o = p; sp = ep = 0; - for (;;) + for (;;) { - if (*p == '\0') + if (*p == '\0') { - if (ep) + if (ep) { ep[1] = '\0'; p = &ep[1]; @@ -1900,16 +1900,16 @@ int hawk_split_bcstr (hawk_bch_t* s, const hawk_bch_t* delim, hawk_bch_t lquote, cnt++; break; } - for (d = (hawk_bch_t*)delim; *d != '\0'; d++) + for (d = (hawk_bch_t*)delim; *d != '\0'; d++) { - if (*p == *d) + if (*p == *d) { - if (sp == HAWK_NULL) + if (sp == HAWK_NULL) { hawk_copy_bcstr_unlimited (o, p); p = o; *p++ = '\0'; } - else + else { hawk_copy_bcstr_unlimited (&ep[1], p); hawk_copy_bcstr_unlimited (o, sp); @@ -1923,7 +1923,7 @@ int hawk_split_bcstr (hawk_bch_t* s, const hawk_bch_t* delim, hawk_bch_t lquote, } } - if (!hawk_is_bch_space(*p)) + if (!hawk_is_bch_space(*p)) { if (sp == HAWK_NULL) sp = p; ep = p; @@ -1945,7 +1945,7 @@ hawk_uch_t* hawk_tokenize_uchars (const hawk_uch_t* s, hawk_oow_t len, const haw const hawk_uch_t* end = s + len; const hawk_uch_t* sp = HAWK_NULL, * ep = HAWK_NULL; const hawk_uch_t* delim_end = delim + delim_len; - hawk_uch_t c; + hawk_uch_t c; int delim_mode; #define __DELIM_NULL 0 @@ -1954,13 +1954,13 @@ hawk_uch_t* hawk_tokenize_uchars (const hawk_uch_t* s, hawk_oow_t len, const haw #define __DELIM_NOSPACES 3 #define __DELIM_COMPOSITE 4 if (delim == HAWK_NULL) delim_mode = __DELIM_NULL; - else + else { delim_mode = __DELIM_EMPTY; - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { - if (hawk_is_uch_space(*d)) + if (hawk_is_uch_space(*d)) { if (delim_mode == __DELIM_EMPTY) delim_mode = __DELIM_SPACES; @@ -1984,20 +1984,20 @@ hawk_uch_t* hawk_tokenize_uchars (const hawk_uch_t* s, hawk_oow_t len, const haw /* TODO: verify the following statement... */ if (delim_mode == __DELIM_SPACES && delim_len == 1 && delim[0] != ' ') delim_mode = __DELIM_NOSPACES; - } - - if (delim_mode == __DELIM_NULL) - { - /* when HAWK_NULL is given as "delim", it trims off the + } + + if (delim_mode == __DELIM_NULL) + { + /* when HAWK_NULL is given as "delim", it trims off the * leading and trailing spaces characters off the source * string "s" eventually. */ while (p < end && hawk_is_uch_space(*p)) p++; - while (p < end) + while (p < end) { c = *p; - if (!hawk_is_uch_space(c)) + if (!hawk_is_uch_space(c)) { if (sp == HAWK_NULL) sp = p; ep = p; @@ -2015,13 +2015,13 @@ hawk_uch_t* hawk_tokenize_uchars (const hawk_uch_t* s, hawk_oow_t len, const haw ep = p++; } } - else if (delim_mode == __DELIM_SPACES) + else if (delim_mode == __DELIM_SPACES) { /* each token is delimited by space characters. all leading * and trailing spaces are removed. */ while (p < end && hawk_is_uch_space(*p)) p++; - while (p < end) + while (p < end) { c = *p; if (hawk_is_uch_space(c)) break; @@ -2032,14 +2032,14 @@ hawk_uch_t* hawk_tokenize_uchars (const hawk_uch_t* s, hawk_oow_t len, const haw } else if (delim_mode == __DELIM_NOSPACES) { - /* each token is delimited by one of charaters + /* each token is delimited by one of charaters * in the delimeter set "delim". */ if (ignorecase) { - while (p < end) + while (p < end) { c = hawk_to_uch_lower(*p); - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { if (c == hawk_to_uch_lower(*d)) goto exit_loop; } @@ -2050,10 +2050,10 @@ hawk_uch_t* hawk_tokenize_uchars (const hawk_uch_t* s, hawk_oow_t len, const haw } else { - while (p < end) + while (p < end) { c = *p; - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { if (c == *d) goto exit_loop; } @@ -2063,7 +2063,7 @@ hawk_uch_t* hawk_tokenize_uchars (const hawk_uch_t* s, hawk_oow_t len, const haw } } } - else /* if (delim_mode == __DELIM_COMPOSITE) */ + else /* if (delim_mode == __DELIM_COMPOSITE) */ { /* each token is delimited by one of non-space charaters * in the delimeter set "delim". however, all space characters @@ -2071,15 +2071,15 @@ hawk_uch_t* hawk_tokenize_uchars (const hawk_uch_t* s, hawk_oow_t len, const haw while (p < end && hawk_is_uch_space(*p)) p++; if (ignorecase) { - while (p < end) + while (p < end) { c = hawk_to_uch_lower(*p); - if (hawk_is_uch_space(c)) + if (hawk_is_uch_space(c)) { p++; continue; } - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { if (c == hawk_to_uch_lower(*d)) goto exit_loop; } @@ -2089,15 +2089,15 @@ hawk_uch_t* hawk_tokenize_uchars (const hawk_uch_t* s, hawk_oow_t len, const haw } else { - while (p < end) + while (p < end) { c = *p; - if (hawk_is_uch_space(c)) + if (hawk_is_uch_space(c)) { p++; continue; } - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { if (c == *d) goto exit_loop; } @@ -2108,12 +2108,12 @@ hawk_uch_t* hawk_tokenize_uchars (const hawk_uch_t* s, hawk_oow_t len, const haw } exit_loop: - if (sp == HAWK_NULL) + if (sp == HAWK_NULL) { tok->ptr = HAWK_NULL; tok->len = (hawk_oow_t)0; } - else + else { tok->ptr = (hawk_uch_t*)sp; tok->len = ep - sp + 1; @@ -2131,7 +2131,7 @@ hawk_bch_t* hawk_tokenize_bchars (const hawk_bch_t* s, hawk_oow_t len, const haw const hawk_bch_t* end = s + len; const hawk_bch_t* sp = HAWK_NULL, * ep = HAWK_NULL; const hawk_bch_t* delim_end = delim + delim_len; - hawk_bch_t c; + hawk_bch_t c; int delim_mode; #define __DELIM_NULL 0 @@ -2140,13 +2140,13 @@ hawk_bch_t* hawk_tokenize_bchars (const hawk_bch_t* s, hawk_oow_t len, const haw #define __DELIM_NOSPACES 3 #define __DELIM_COMPOSITE 4 if (delim == HAWK_NULL) delim_mode = __DELIM_NULL; - else + else { delim_mode = __DELIM_EMPTY; - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { - if (hawk_is_bch_space(*d)) + if (hawk_is_bch_space(*d)) { if (delim_mode == __DELIM_EMPTY) delim_mode = __DELIM_SPACES; @@ -2170,20 +2170,20 @@ hawk_bch_t* hawk_tokenize_bchars (const hawk_bch_t* s, hawk_oow_t len, const haw /* TODO: verify the following statement... */ if (delim_mode == __DELIM_SPACES && delim_len == 1 && delim[0] != ' ') delim_mode = __DELIM_NOSPACES; - } - - if (delim_mode == __DELIM_NULL) - { - /* when HAWK_NULL is given as "delim", it trims off the + } + + if (delim_mode == __DELIM_NULL) + { + /* when HAWK_NULL is given as "delim", it trims off the * leading and trailing spaces characters off the source * string "s" eventually. */ while (p < end && hawk_is_bch_space(*p)) p++; - while (p < end) + while (p < end) { c = *p; - if (!hawk_is_bch_space(c)) + if (!hawk_is_bch_space(c)) { if (sp == HAWK_NULL) sp = p; ep = p; @@ -2201,13 +2201,13 @@ hawk_bch_t* hawk_tokenize_bchars (const hawk_bch_t* s, hawk_oow_t len, const haw ep = p++; } } - else if (delim_mode == __DELIM_SPACES) + else if (delim_mode == __DELIM_SPACES) { /* each token is delimited by space characters. all leading * and trailing spaces are removed. */ while (p < end && hawk_is_bch_space(*p)) p++; - while (p < end) + while (p < end) { c = *p; if (hawk_is_bch_space(c)) break; @@ -2218,14 +2218,14 @@ hawk_bch_t* hawk_tokenize_bchars (const hawk_bch_t* s, hawk_oow_t len, const haw } else if (delim_mode == __DELIM_NOSPACES) { - /* each token is delimited by one of charaters + /* each token is delimited by one of charaters * in the delimeter set "delim". */ if (ignorecase) { - while (p < end) + while (p < end) { c = hawk_to_bch_lower(*p); - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { if (c == hawk_to_bch_lower(*d)) goto exit_loop; } @@ -2236,10 +2236,10 @@ hawk_bch_t* hawk_tokenize_bchars (const hawk_bch_t* s, hawk_oow_t len, const haw } else { - while (p < end) + while (p < end) { c = *p; - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { if (c == *d) goto exit_loop; } @@ -2249,7 +2249,7 @@ hawk_bch_t* hawk_tokenize_bchars (const hawk_bch_t* s, hawk_oow_t len, const haw } } } - else /* if (delim_mode == __DELIM_COMPOSITE) */ + else /* if (delim_mode == __DELIM_COMPOSITE) */ { /* each token is delimited by one of non-space charaters * in the delimeter set "delim". however, all space characters @@ -2257,15 +2257,15 @@ hawk_bch_t* hawk_tokenize_bchars (const hawk_bch_t* s, hawk_oow_t len, const haw while (p < end && hawk_is_bch_space(*p)) p++; if (ignorecase) { - while (p < end) + while (p < end) { c = hawk_to_bch_lower(*p); - if (hawk_is_bch_space(c)) + if (hawk_is_bch_space(c)) { p++; continue; } - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { if (c == hawk_to_bch_lower(*d)) goto exit_loop; } @@ -2275,15 +2275,15 @@ hawk_bch_t* hawk_tokenize_bchars (const hawk_bch_t* s, hawk_oow_t len, const haw } else { - while (p < end) + while (p < end) { c = *p; - if (hawk_is_bch_space(c)) + if (hawk_is_bch_space(c)) { p++; continue; } - for (d = delim; d < delim_end; d++) + for (d = delim; d < delim_end; d++) { if (c == *d) goto exit_loop; } @@ -2294,12 +2294,12 @@ hawk_bch_t* hawk_tokenize_bchars (const hawk_bch_t* s, hawk_oow_t len, const haw } exit_loop: - if (sp == HAWK_NULL) + if (sp == HAWK_NULL) { tok->ptr = HAWK_NULL; tok->len = (hawk_oow_t)0; } - else + else { tok->ptr = (hawk_bch_t*)sp; tok->len = ep - sp + 1; @@ -2322,7 +2322,7 @@ hawk_oow_t hawk_byte_to_ucstr (hawk_uint8_t byte, hawk_uch_t* buf, hawk_oow_t si radix_char = (flagged_radix & HAWK_BYTE_TO_UCSTR_LOWERCASE)? 'a': 'A'; if (radix < 2 || radix > 36 || size <= 0) return 0; - do + do { hawk_uint8_t digit = byte % radix; if (digit < 10) *p++ = digit + '0'; @@ -2331,9 +2331,9 @@ hawk_oow_t hawk_byte_to_ucstr (hawk_uint8_t byte, hawk_uch_t* buf, hawk_oow_t si } while (byte > 0); - if (fill != '\0') + if (fill != '\0') { - while (size - 1 > p - tmp) + while (size - 1 > p - tmp) { *bp++ = fill; size--; @@ -2356,7 +2356,7 @@ hawk_oow_t hawk_byte_to_bcstr (hawk_uint8_t byte, hawk_bch_t* buf, hawk_oow_t si radix_char = (flagged_radix & HAWK_BYTE_TO_BCSTR_LOWERCASE)? 'a': 'A'; if (radix < 2 || radix > 36 || size <= 0) return 0; - do + do { hawk_uint8_t digit = byte % radix; if (digit < 10) *p++ = digit + '0'; @@ -2365,9 +2365,9 @@ hawk_oow_t hawk_byte_to_bcstr (hawk_uint8_t byte, hawk_bch_t* buf, hawk_oow_t si } while (byte > 0); - if (fill != '\0') + if (fill != '\0') { - while (size - 1 > p - tmp) + while (size - 1 > p - tmp) { *bp++ = fill; size--; @@ -2391,14 +2391,14 @@ hawk_oow_t hawk_int_to_ucstr (hawk_int_t value, int radix, const hawk_uch_t* pre if (t == 0) { /* zero */ - if (buf == HAWK_NULL) + if (buf == HAWK_NULL) { - /* if buf is not given, + /* if buf is not given, * return the number of bytes required */ return prefix_len + 1; } - if (size < prefix_len+1) + if (size < prefix_len+1) { /* buffer too small */ return (hawk_oow_t)-1; @@ -2428,7 +2428,7 @@ hawk_oow_t hawk_int_to_ucstr (hawk_int_t value, int radix, const hawk_uch_t* pre t = value; if (t < 0) t = -t; - while (t > 0) + while (t > 0) { rem = t % radix; if (rem >= 10) @@ -2438,9 +2438,9 @@ hawk_oow_t hawk_int_to_ucstr (hawk_int_t value, int radix, const hawk_uch_t* pre t /= radix; } - if (value < 0) + if (value < 0) { - for (i = 1; i <= prefix_len; i++) + for (i = 1; i <= prefix_len; i++) { buf[i] = prefix[i-1]; len--; @@ -2467,14 +2467,14 @@ hawk_oow_t hawk_int_to_bcstr (hawk_int_t value, int radix, const hawk_bch_t* pre if (t == 0) { /* zero */ - if (buf == HAWK_NULL) + if (buf == HAWK_NULL) { - /* if buf is not given, + /* if buf is not given, * return the number of bytes required */ return prefix_len + 1; } - if (size < prefix_len+1) + if (size < prefix_len+1) { /* buffer too small */ return (hawk_oow_t)-1; @@ -2504,7 +2504,7 @@ hawk_oow_t hawk_int_to_bcstr (hawk_int_t value, int radix, const hawk_bch_t* pre t = value; if (t < 0) t = -t; - while (t > 0) + while (t > 0) { rem = t % radix; if (rem >= 10) @@ -2514,9 +2514,9 @@ hawk_oow_t hawk_int_to_bcstr (hawk_int_t value, int radix, const hawk_bch_t* pre t /= radix; } - if (value < 0) + if (value < 0) { - for (i = 1; i <= prefix_len; i++) + for (i = 1; i <= prefix_len; i++) { buf[i] = prefix[i-1]; len--; @@ -2543,14 +2543,14 @@ hawk_oow_t hawk_uint_to_ucstr (hawk_uint_t value, int radix, const hawk_uch_t* p if (t == 0) { /* zero */ - if (buf == HAWK_NULL) + if (buf == HAWK_NULL) { - /* if buf is not given, + /* if buf is not given, * return the number of bytes required */ return prefix_len + 1; } - if (size < prefix_len+1) + if (size < prefix_len+1) { /* buffer too small */ return (hawk_oow_t)-1; @@ -2580,7 +2580,7 @@ hawk_oow_t hawk_uint_to_ucstr (hawk_uint_t value, int radix, const hawk_uch_t* p t = value; if (t < 0) t = -t; - while (t > 0) + while (t > 0) { rem = t % radix; if (rem >= 10) @@ -2590,9 +2590,9 @@ hawk_oow_t hawk_uint_to_ucstr (hawk_uint_t value, int radix, const hawk_uch_t* p t /= radix; } - if (value < 0) + if (value < 0) { - for (i = 1; i <= prefix_len; i++) + for (i = 1; i <= prefix_len; i++) { buf[i] = prefix[i-1]; len--; @@ -2619,14 +2619,14 @@ hawk_oow_t hawk_uint_to_bcstr (hawk_uint_t value, int radix, const hawk_bch_t* p if (t == 0) { /* zero */ - if (buf == HAWK_NULL) + if (buf == HAWK_NULL) { - /* if buf is not given, + /* if buf is not given, * return the number of bytes required */ return prefix_len + 1; } - if (size < prefix_len+1) + if (size < prefix_len+1) { /* buffer too small */ return (hawk_oow_t)-1; @@ -2656,7 +2656,7 @@ hawk_oow_t hawk_uint_to_bcstr (hawk_uint_t value, int radix, const hawk_bch_t* p t = value; if (t < 0) t = -t; - while (t > 0) + while (t > 0) { rem = t % radix; if (rem >= 10) @@ -2666,9 +2666,9 @@ hawk_oow_t hawk_uint_to_bcstr (hawk_uint_t value, int radix, const hawk_bch_t* p t /= radix; } - if (value < 0) + if (value < 0) { - for (i = 1; i <= prefix_len; i++) + for (i = 1; i <= prefix_len; i++) { buf[i] = prefix[i-1]; len--; @@ -2692,7 +2692,7 @@ hawk_int_t hawk_uchars_to_int (const hawk_uch_t* str, hawk_oow_t len, int option int digit, negative = 0; int base = HAWK_UCHARS_TO_INTMAX_GET_OPTION_BASE(option); - p = str; + p = str; end = str + len; if (HAWK_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option)) @@ -2704,7 +2704,7 @@ hawk_int_t hawk_uchars_to_int (const hawk_uch_t* str, hawk_oow_t len, int option /* check for a sign */ while (p < end) { - if (*p == '-') + if (*p == '-') { negative = ~negative; p++; @@ -2715,9 +2715,9 @@ hawk_int_t hawk_uchars_to_int (const hawk_uch_t* str, hawk_oow_t len, int option /* check for a binary/octal/hexadecimal notation */ rem = end - p; - if (base == 0) + if (base == 0) { - if (rem >= 1 && *p == '0') + if (rem >= 1 && *p == '0') { p++; @@ -2725,7 +2725,7 @@ hawk_int_t hawk_uchars_to_int (const hawk_uch_t* str, hawk_oow_t len, int option else if (*p == 'x' || *p == 'X') { p++; base = 16; - } + } else if (*p == 'b' || *p == 'B') { p++; base = 2; @@ -2733,14 +2733,14 @@ hawk_int_t hawk_uchars_to_int (const hawk_uch_t* str, hawk_oow_t len, int option else base = 8; } else base = 10; - } + } else if (rem >= 2 && base == 16) { - if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; + if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; } else if (rem >= 2 && base == 2) { - if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; + if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; } /* process the digits */ @@ -2784,7 +2784,7 @@ hawk_int_t hawk_uchars_to_int (const hawk_uch_t* str, hawk_oow_t len, int option /* base 8: at least a zero digit has been seen. * other case: p > pp to be able to have at least 1 meaningful digit. */ - if (is_sober) *is_sober = (base == 8 || p > pp); + if (is_sober) *is_sober = (base == 8 || p > pp); if (HAWK_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option)) { @@ -2805,7 +2805,7 @@ hawk_int_t hawk_bchars_to_int (const hawk_bch_t* str, hawk_oow_t len, int option int digit, negative = 0; int base = HAWK_BCHARS_TO_INTMAX_GET_OPTION_BASE(option); - p = str; + p = str; end = str + len; if (HAWK_BCHARS_TO_INTMAX_GET_OPTION_LTRIM(option)) @@ -2817,7 +2817,7 @@ hawk_int_t hawk_bchars_to_int (const hawk_bch_t* str, hawk_oow_t len, int option /* check for a sign */ while (p < end) { - if (*p == '-') + if (*p == '-') { negative = ~negative; p++; @@ -2828,9 +2828,9 @@ hawk_int_t hawk_bchars_to_int (const hawk_bch_t* str, hawk_oow_t len, int option /* check for a binary/octal/hexadecimal notation */ rem = end - p; - if (base == 0) + if (base == 0) { - if (rem >= 1 && *p == '0') + if (rem >= 1 && *p == '0') { p++; @@ -2838,7 +2838,7 @@ hawk_int_t hawk_bchars_to_int (const hawk_bch_t* str, hawk_oow_t len, int option else if (*p == 'x' || *p == 'X') { p++; base = 16; - } + } else if (*p == 'b' || *p == 'B') { p++; base = 2; @@ -2846,14 +2846,14 @@ hawk_int_t hawk_bchars_to_int (const hawk_bch_t* str, hawk_oow_t len, int option else base = 8; } else base = 10; - } + } else if (rem >= 2 && base == 16) { - if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; + if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; } else if (rem >= 2 && base == 2) { - if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; + if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; } /* process the digits */ @@ -2897,7 +2897,7 @@ hawk_int_t hawk_bchars_to_int (const hawk_bch_t* str, hawk_oow_t len, int option /* base 8: at least a zero digit has been seen. * other case: p > pp to be able to have at least 1 meaningful digit. */ - if (is_sober) *is_sober = (base == 8 || p > pp); + if (is_sober) *is_sober = (base == 8 || p > pp); if (HAWK_BCHARS_TO_INTMAX_GET_OPTION_RTRIM(option)) { @@ -2918,7 +2918,7 @@ hawk_uint_t hawk_uchars_to_uint (const hawk_uch_t* str, hawk_oow_t len, int opti int digit; int base = HAWK_UCHARS_TO_UINTMAX_GET_OPTION_BASE(option); - p = str; + p = str; end = str + len; if (HAWK_UCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option)) @@ -2936,9 +2936,9 @@ hawk_uint_t hawk_uchars_to_uint (const hawk_uch_t* str, hawk_oow_t len, int opti /* check for a binary/octal/hexadecimal notation */ rem = end - p; - if (base == 0) + if (base == 0) { - if (rem >= 1 && *p == '0') + if (rem >= 1 && *p == '0') { p++; @@ -2946,7 +2946,7 @@ hawk_uint_t hawk_uchars_to_uint (const hawk_uch_t* str, hawk_oow_t len, int opti else if (*p == 'x' || *p == 'X') { p++; base = 16; - } + } else if (*p == 'b' || *p == 'B') { p++; base = 2; @@ -2954,14 +2954,14 @@ hawk_uint_t hawk_uchars_to_uint (const hawk_uch_t* str, hawk_oow_t len, int opti else base = 8; } else base = 10; - } + } else if (rem >= 2 && base == 16) { - if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; + if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; } else if (rem >= 2 && base == 2) { - if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; + if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; } /* process the digits */ @@ -3005,7 +3005,7 @@ hawk_uint_t hawk_uchars_to_uint (const hawk_uch_t* str, hawk_oow_t len, int opti /* base 8: at least a zero digit has been seen. * other case: p > pp to be able to have at least 1 meaningful digit. */ - if (is_sober) *is_sober = (base == 8 || p > pp); + if (is_sober) *is_sober = (base == 8 || p > pp); if (HAWK_UCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option)) { @@ -3026,7 +3026,7 @@ hawk_uint_t hawk_bchars_to_uint (const hawk_bch_t* str, hawk_oow_t len, int opti int digit; int base = HAWK_BCHARS_TO_UINTMAX_GET_OPTION_BASE(option); - p = str; + p = str; end = str + len; if (HAWK_BCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option)) @@ -3044,9 +3044,9 @@ hawk_uint_t hawk_bchars_to_uint (const hawk_bch_t* str, hawk_oow_t len, int opti /* check for a binary/octal/hexadecimal notation */ rem = end - p; - if (base == 0) + if (base == 0) { - if (rem >= 1 && *p == '0') + if (rem >= 1 && *p == '0') { p++; @@ -3054,7 +3054,7 @@ hawk_uint_t hawk_bchars_to_uint (const hawk_bch_t* str, hawk_oow_t len, int opti else if (*p == 'x' || *p == 'X') { p++; base = 16; - } + } else if (*p == 'b' || *p == 'B') { p++; base = 2; @@ -3062,14 +3062,14 @@ hawk_uint_t hawk_bchars_to_uint (const hawk_bch_t* str, hawk_oow_t len, int opti else base = 8; } else base = 10; - } + } else if (rem >= 2 && base == 16) { - if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; + if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; } else if (rem >= 2 && base == 2) { - if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; + if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; } /* process the digits */ @@ -3113,7 +3113,7 @@ hawk_uint_t hawk_bchars_to_uint (const hawk_bch_t* str, hawk_oow_t len, int opti /* base 8: at least a zero digit has been seen. * other case: p > pp to be able to have at least 1 meaningful digit. */ - if (is_sober) *is_sober = (base == 8 || p > pp); + if (is_sober) *is_sober = (base == 8 || p > pp); if (HAWK_BCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option)) { @@ -3133,16 +3133,16 @@ int hawk_fnmat_uchars_i (const hawk_uch_t* str, hawk_oow_t slen, const hawk_uch_ const hawk_uch_t* pe = ptn + plen; hawk_uch_t sc, pc, pc2; - while (1) + while (1) { - if (pp < pe && HAWK_FNMAT_IS_ESC(*pp) && !(flags & HAWK_FNMAT_NOESCAPE)) + if (pp < pe && HAWK_FNMAT_IS_ESC(*pp) && !(flags & HAWK_FNMAT_NOESCAPE)) { /* pattern is escaped and escaping is allowed. */ - if ((++pp) >= pe) + if ((++pp) >= pe) { - /* - * the last character of the pattern is an WCS_ESC. + /* + * the last character of the pattern is an WCS_ESC. * matching is performed as if the end of the pattern is * reached just without an WCS_ESC. */ @@ -3153,27 +3153,27 @@ int hawk_fnmat_uchars_i (const hawk_uch_t* str, hawk_oow_t slen, const hawk_uch_ if (sp >= se) return 0; /* premature string termination */ sc = *sp; pc = *pp; /* pc is just a normal character */ - if ((flags & HAWK_FNMAT_IGNORECASE) != 0) + if ((flags & HAWK_FNMAT_IGNORECASE) != 0) { /* make characters to lower-case */ sc = hawk_to_uch_lower(sc); - pc = hawk_to_uch_lower(pc); + pc = hawk_to_uch_lower(pc); } if (sc != pc) return 0; - sp++; pp++; + sp++; pp++; continue; } - if (pp >= pe) + if (pp >= pe) { - /* - * the end of the pattern has been reached. + /* + * the end of the pattern has been reached. * the string must terminate too. */ return sp >= se; } - if (sp >= se) + if (sp >= se) { /* the string terminats prematurely */ while (pp < pe && *pp == '*') pp++; @@ -3182,23 +3182,23 @@ int hawk_fnmat_uchars_i (const hawk_uch_t* str, hawk_oow_t slen, const hawk_uch_ sc = *sp; pc = *pp; - if (sc == '.' && (flags & HAWK_FNMAT_PERIOD)) + if (sc == '.' && (flags & HAWK_FNMAT_PERIOD)) { - /* - * a leading period in the staring must match - * a period in the pattern explicitly + /* + * a leading period in the staring must match + * a period in the pattern explicitly */ - if ((!no_first_period && sp == str) || - (HAWK_FNMAT_IS_SEP(sp[-1]) && (flags & HAWK_FNMAT_PATHNAME))) + if ((!no_first_period && sp == str) || + (HAWK_FNMAT_IS_SEP(sp[-1]) && (flags & HAWK_FNMAT_PATHNAME))) { if (pc != '.') return 0; sp++; pp++; continue; } } - else if (HAWK_FNMAT_IS_SEP(sc) && (flags & HAWK_FNMAT_PATHNAME)) + else if (HAWK_FNMAT_IS_SEP(sc) && (flags & HAWK_FNMAT_PATHNAME)) { - while (pc == '*') + while (pc == '*') { if ((++pp) >= pe) return 0; pc = *pp; @@ -3211,21 +3211,21 @@ int hawk_fnmat_uchars_i (const hawk_uch_t* str, hawk_oow_t slen, const hawk_uch_ } /* the handling of special pattern characters begins here */ - if (pc == '?') + if (pc == '?') { /* match any single character */ - sp++; pp++; - } - else if (pc == '*') - { + sp++; pp++; + } + else if (pc == '*') + { /* match zero or more characters */ /* compact asterisks */ do { pp++; } while (pp < pe && *pp == '*'); - if (pp >= pe) + if (pp >= pe) { - /* + /* * if the last character in the pattern is an asterisk, * the string should not have any directory separators * when HAWK_FNMAT_PATHNAME is set. @@ -3240,31 +3240,31 @@ int hawk_fnmat_uchars_i (const hawk_uch_t* str, hawk_oow_t slen, const hawk_uch_ } return 1; } - else + else { - do + do { if (hawk_fnmat_uchars_i(sp, se - sp, pp, pe - pp, flags, 1)) return 1; if (HAWK_FNMAT_IS_SEP(*sp) && (flags & HAWK_FNMAT_PATHNAME)) break; sp++; - } + } while (sp < se); return 0; } } - else if (pc == '[') + else if (pc == '[') { /* match range */ int negate = 0; int matched = 0; if ((++pp) >= pe) return 0; - if (*pp == '!') { negate = 1; pp++; } + if (*pp == '!') { negate = 1; pp++; } - while (pp < pe && *pp != ']') + while (pp < pe && *pp != ']') { - if (*pp == '[') + if (*pp == '[') { hawk_oow_t pl = pe - pp; @@ -3278,9 +3278,9 @@ int hawk_fnmat_uchars_i (const hawk_uch_t* str, hawk_oow_t slen, const hawk_uch_ } } - /* - * characters in an invalid class name are - * just treated as normal characters + /* + * characters in an invalid class name are + * just treated as normal characters */ } @@ -3290,44 +3290,44 @@ int hawk_fnmat_uchars_i (const hawk_uch_t* str, hawk_oow_t slen, const hawk_uch_ if (pp >= pe) break; pc = *pp; - if ((flags & HAWK_FNMAT_IGNORECASE) != 0) + if ((flags & HAWK_FNMAT_IGNORECASE) != 0) { - sc = hawk_to_uch_lower(sc); - pc = hawk_to_uch_lower(pc); + sc = hawk_to_uch_lower(sc); + pc = hawk_to_uch_lower(pc); } - if (pp + 1 < pe && pp[1] == '-') + if (pp + 1 < pe && pp[1] == '-') { pp += 2; /* move the a character next to a dash */ - if (pp >= pe) + if (pp >= pe) { if (sc >= pc) matched = 1; break; } - if (HAWK_FNMAT_IS_ESC(*pp) && !(flags & HAWK_FNMAT_NOESCAPE)) + if (HAWK_FNMAT_IS_ESC(*pp) && !(flags & HAWK_FNMAT_NOESCAPE)) { - if ((++pp) >= pe) + if ((++pp) >= pe) { if (sc >= pc) matched = 1; break; } } - else if (*pp == ']') + else if (*pp == ']') { if (sc >= pc) matched = 1; break; } pc2 = *pp; - if ((flags & HAWK_FNMAT_IGNORECASE) != 0) - pc2 = hawk_to_uch_lower(pc2); + if ((flags & HAWK_FNMAT_IGNORECASE) != 0) + pc2 = hawk_to_uch_lower(pc2); if (sc >= pc && sc <= pc2) matched = 1; pp++; } - else + else { if (sc == pc) matched = 1; pp++; @@ -3338,13 +3338,13 @@ int hawk_fnmat_uchars_i (const hawk_uch_t* str, hawk_oow_t slen, const hawk_uch_ if (!matched) return 0; sp++; if (pp < pe) pp++; } - else + else { /* a normal character */ - if ((flags & HAWK_FNMAT_IGNORECASE) != 0) + if ((flags & HAWK_FNMAT_IGNORECASE) != 0) { - sc = hawk_to_uch_lower(sc); - pc = hawk_to_uch_lower(pc); + sc = hawk_to_uch_lower(sc); + pc = hawk_to_uch_lower(pc); } if (sc != pc) return 0; @@ -3364,16 +3364,16 @@ int hawk_fnmat_bchars_i (const hawk_bch_t* str, hawk_oow_t slen, const hawk_bch_ const hawk_bch_t* pe = ptn + plen; hawk_bch_t sc, pc, pc2; - while (1) + while (1) { - if (pp < pe && HAWK_FNMAT_IS_ESC(*pp) && !(flags & HAWK_FNMAT_NOESCAPE)) + if (pp < pe && HAWK_FNMAT_IS_ESC(*pp) && !(flags & HAWK_FNMAT_NOESCAPE)) { /* pattern is escaped and escaping is allowed. */ - if ((++pp) >= pe) + if ((++pp) >= pe) { - /* - * the last character of the pattern is an WCS_ESC. + /* + * the last character of the pattern is an WCS_ESC. * matching is performed as if the end of the pattern is * reached just without an WCS_ESC. */ @@ -3384,27 +3384,27 @@ int hawk_fnmat_bchars_i (const hawk_bch_t* str, hawk_oow_t slen, const hawk_bch_ if (sp >= se) return 0; /* premature string termination */ sc = *sp; pc = *pp; /* pc is just a normal character */ - if ((flags & HAWK_FNMAT_IGNORECASE) != 0) + if ((flags & HAWK_FNMAT_IGNORECASE) != 0) { /* make characters to lower-case */ sc = hawk_to_bch_lower(sc); - pc = hawk_to_bch_lower(pc); + pc = hawk_to_bch_lower(pc); } if (sc != pc) return 0; - sp++; pp++; + sp++; pp++; continue; } - if (pp >= pe) + if (pp >= pe) { - /* - * the end of the pattern has been reached. + /* + * the end of the pattern has been reached. * the string must terminate too. */ return sp >= se; } - if (sp >= se) + if (sp >= se) { /* the string terminats prematurely */ while (pp < pe && *pp == '*') pp++; @@ -3413,23 +3413,23 @@ int hawk_fnmat_bchars_i (const hawk_bch_t* str, hawk_oow_t slen, const hawk_bch_ sc = *sp; pc = *pp; - if (sc == '.' && (flags & HAWK_FNMAT_PERIOD)) + if (sc == '.' && (flags & HAWK_FNMAT_PERIOD)) { - /* - * a leading period in the staring must match - * a period in the pattern explicitly + /* + * a leading period in the staring must match + * a period in the pattern explicitly */ - if ((!no_first_period && sp == str) || - (HAWK_FNMAT_IS_SEP(sp[-1]) && (flags & HAWK_FNMAT_PATHNAME))) + if ((!no_first_period && sp == str) || + (HAWK_FNMAT_IS_SEP(sp[-1]) && (flags & HAWK_FNMAT_PATHNAME))) { if (pc != '.') return 0; sp++; pp++; continue; } } - else if (HAWK_FNMAT_IS_SEP(sc) && (flags & HAWK_FNMAT_PATHNAME)) + else if (HAWK_FNMAT_IS_SEP(sc) && (flags & HAWK_FNMAT_PATHNAME)) { - while (pc == '*') + while (pc == '*') { if ((++pp) >= pe) return 0; pc = *pp; @@ -3442,21 +3442,21 @@ int hawk_fnmat_bchars_i (const hawk_bch_t* str, hawk_oow_t slen, const hawk_bch_ } /* the handling of special pattern characters begins here */ - if (pc == '?') + if (pc == '?') { /* match any single character */ - sp++; pp++; - } - else if (pc == '*') - { + sp++; pp++; + } + else if (pc == '*') + { /* match zero or more characters */ /* compact asterisks */ do { pp++; } while (pp < pe && *pp == '*'); - if (pp >= pe) + if (pp >= pe) { - /* + /* * if the last character in the pattern is an asterisk, * the string should not have any directory separators * when HAWK_FNMAT_PATHNAME is set. @@ -3471,31 +3471,31 @@ int hawk_fnmat_bchars_i (const hawk_bch_t* str, hawk_oow_t slen, const hawk_bch_ } return 1; } - else + else { - do + do { if (hawk_fnmat_bchars_i(sp, se - sp, pp, pe - pp, flags, 1)) return 1; if (HAWK_FNMAT_IS_SEP(*sp) && (flags & HAWK_FNMAT_PATHNAME)) break; sp++; - } + } while (sp < se); return 0; } } - else if (pc == '[') + else if (pc == '[') { /* match range */ int negate = 0; int matched = 0; if ((++pp) >= pe) return 0; - if (*pp == '!') { negate = 1; pp++; } + if (*pp == '!') { negate = 1; pp++; } - while (pp < pe && *pp != ']') + while (pp < pe && *pp != ']') { - if (*pp == '[') + if (*pp == '[') { hawk_oow_t pl = pe - pp; @@ -3509,9 +3509,9 @@ int hawk_fnmat_bchars_i (const hawk_bch_t* str, hawk_oow_t slen, const hawk_bch_ } } - /* - * characters in an invalid class name are - * just treated as normal characters + /* + * characters in an invalid class name are + * just treated as normal characters */ } @@ -3521,44 +3521,44 @@ int hawk_fnmat_bchars_i (const hawk_bch_t* str, hawk_oow_t slen, const hawk_bch_ if (pp >= pe) break; pc = *pp; - if ((flags & HAWK_FNMAT_IGNORECASE) != 0) + if ((flags & HAWK_FNMAT_IGNORECASE) != 0) { - sc = hawk_to_bch_lower(sc); - pc = hawk_to_bch_lower(pc); + sc = hawk_to_bch_lower(sc); + pc = hawk_to_bch_lower(pc); } - if (pp + 1 < pe && pp[1] == '-') + if (pp + 1 < pe && pp[1] == '-') { pp += 2; /* move the a character next to a dash */ - if (pp >= pe) + if (pp >= pe) { if (sc >= pc) matched = 1; break; } - if (HAWK_FNMAT_IS_ESC(*pp) && !(flags & HAWK_FNMAT_NOESCAPE)) + if (HAWK_FNMAT_IS_ESC(*pp) && !(flags & HAWK_FNMAT_NOESCAPE)) { - if ((++pp) >= pe) + if ((++pp) >= pe) { if (sc >= pc) matched = 1; break; } } - else if (*pp == ']') + else if (*pp == ']') { if (sc >= pc) matched = 1; break; } pc2 = *pp; - if ((flags & HAWK_FNMAT_IGNORECASE) != 0) - pc2 = hawk_to_bch_lower(pc2); + if ((flags & HAWK_FNMAT_IGNORECASE) != 0) + pc2 = hawk_to_bch_lower(pc2); if (sc >= pc && sc <= pc2) matched = 1; pp++; } - else + else { if (sc == pc) matched = 1; pp++; @@ -3569,13 +3569,13 @@ int hawk_fnmat_bchars_i (const hawk_bch_t* str, hawk_oow_t slen, const hawk_bch_ if (!matched) return 0; sp++; if (pp < pe) pp++; } - else + else { /* a normal character */ - if ((flags & HAWK_FNMAT_IGNORECASE) != 0) + if ((flags & HAWK_FNMAT_IGNORECASE) != 0) { - sc = hawk_to_bch_lower(sc); - pc = hawk_to_bch_lower(pc); + sc = hawk_to_bch_lower(sc); + pc = hawk_to_bch_lower(pc); } if (sc != pc) return 0; diff --git a/lib/utl-sys.c b/lib/utl-sys.c index a1562b27..ad31b797 100644 --- a/lib/utl-sys.c +++ b/lib/utl-sys.c @@ -58,8 +58,8 @@ int hawk_get_ntime (hawk_ntime_t* t) FILETIME ft; ULARGE_INTEGER li; - /* - * MSDN: The FILETIME structure is a 64-bit value representing the + /* + * MSDN: The FILETIME structure is a 64-bit value representing the * number of 100-nanosecond intervals since January 1, 1601 (UTC). */ @@ -81,9 +81,9 @@ int hawk_get_ntime (hawk_ntime_t* t) DATETIME dt; hawk_btime_t bt; - /* Can I use DosQuerySysInfo(QSV_TIME_LOW) and - * DosQuerySysInfo(QSV_TIME_HIGH) for this instead? - * Maybe, resolution too low as it returns values + /* Can I use DosQuerySysInfo(QSV_TIME_LOW) and + * DosQuerySysInfo(QSV_TIME_HIGH) for this instead? + * Maybe, resolution too low as it returns values * in seconds. */ rc = DosGetDateTime (&dt); @@ -126,12 +126,12 @@ int hawk_get_ntime (hawk_ntime_t* t) #elif defined(macintosh) unsigned long tv; - + GetDateTime (&tv); - + t->sec = tv; tv->nsec = 0; - + return 0; #elif defined(HAVE_CLOCK_GETTIME) @@ -342,7 +342,7 @@ void hawk_sub_ntime (hawk_ntime_t* z, const hawk_ntime_t* x, const hawk_ntime_t* xs = HAWK_TYPE_MIN(hawk_ntime_sec_t); ns = 0; } - } + } else { xs = xs - ys; diff --git a/lib/utl-xstr.c b/lib/utl-xstr.c index 63f96e1e..501b4633 100644 --- a/lib/utl-xstr.c +++ b/lib/utl-xstr.c @@ -42,10 +42,10 @@ void hawk_unescape_ucstr (hawk_uch_t* str) { c_acc = c_acc * 8 + c - '0'; digit_count++; - - if (digit_count >= escaped) + + if (digit_count >= escaped) { - /* should i limit the max to 0xFF/0377? + /* should i limit the max to 0xFF/0377? if (c_acc > 0377) c_acc = 0377; */ escaped = 0; *p2++ = c_acc; @@ -66,7 +66,7 @@ void hawk_unescape_ucstr (hawk_uch_t* str) { c_acc = c_acc * 16 + c - '0'; digit_count++; - if (digit_count >= escaped) + if (digit_count >= escaped) { *p2++ = c_acc; escaped = 0; @@ -77,7 +77,7 @@ void hawk_unescape_ucstr (hawk_uch_t* str) { c_acc = c_acc * 16 + c - 'A' + 10; digit_count++; - if (digit_count >= escaped) + if (digit_count >= escaped) { *p2++ = c_acc; escaped = 0; @@ -88,7 +88,7 @@ void hawk_unescape_ucstr (hawk_uch_t* str) { c_acc = c_acc * 16 + c - 'a' + 10; digit_count++; - if (digit_count >= escaped) + if (digit_count >= escaped) { *p2++ = c_acc; escaped = 0; @@ -97,7 +97,7 @@ void hawk_unescape_ucstr (hawk_uch_t* str) } else { - if (digit_count == 0) + if (digit_count == 0) { /* no valid character after the escaper. * keep the escaper as it is. consider this input: @@ -117,7 +117,7 @@ void hawk_unescape_ucstr (hawk_uch_t* str) if (escaped == 1) { - switch (c) + switch (c) { case 'n': c = '\n'; break; case 'r': c = '\r'; break; @@ -159,7 +159,7 @@ void hawk_unescape_ucstr (hawk_uch_t* str) } normal_char: - if (c == '\\') + if (c == '\\') { escaped = 1; continue; @@ -193,10 +193,10 @@ void hawk_unescape_bcstr (hawk_bch_t* str) { c_acc = c_acc * 8 + c - '0'; digit_count++; - - if (digit_count >= escaped) + + if (digit_count >= escaped) { - /* should i limit the max to 0xFF/0377? + /* should i limit the max to 0xFF/0377? if (c_acc > 0377) c_acc = 0377; */ escaped = 0; *p2++ = c_acc; @@ -217,7 +217,7 @@ void hawk_unescape_bcstr (hawk_bch_t* str) { c_acc = c_acc * 16 + c - '0'; digit_count++; - if (digit_count >= escaped) + if (digit_count >= escaped) { if (escaped == 2) *p2++ = c_acc; else p2 += utf8_cmgr->uctobc(c_acc, p2, HAWK_TYPE_MAX(hawk_oow_t)); @@ -229,7 +229,7 @@ void hawk_unescape_bcstr (hawk_bch_t* str) { c_acc = c_acc * 16 + c - 'A' + 10; digit_count++; - if (digit_count >= escaped) + if (digit_count >= escaped) { if (escaped == 2) *p2++ = c_acc; else p2 += utf8_cmgr->uctobc(c_acc, p2, HAWK_TYPE_MAX(hawk_oow_t)); @@ -241,7 +241,7 @@ void hawk_unescape_bcstr (hawk_bch_t* str) { c_acc = c_acc * 16 + c - 'a' + 10; digit_count++; - if (digit_count >= escaped) + if (digit_count >= escaped) { if (escaped == 2) *p2++ = c_acc; else p2 += utf8_cmgr->uctobc(c_acc, p2, HAWK_TYPE_MAX(hawk_oow_t)); @@ -252,8 +252,8 @@ void hawk_unescape_bcstr (hawk_bch_t* str) else { /* non digit or xdigit */ - - if (digit_count == 0) + + if (digit_count == 0) { /* no valid character after the escaper. * keep the escaper as it is. consider this input: @@ -264,7 +264,7 @@ void hawk_unescape_bcstr (hawk_bch_t* str) *p2++ = (escaped == 2)? 'x': (escaped == 4)? 'u': 'U'; } - else + else { /* for a unicode, the utf8 conversion can never outgrow the input string of the hexadecimal notation with an escaper. * so it must be safe to specify a very large buffer size to uctobc() */ @@ -279,7 +279,7 @@ void hawk_unescape_bcstr (hawk_bch_t* str) if (escaped == 1) { - switch (c) + switch (c) { case 'n': c = '\n'; break; case 'r': c = '\r'; break; @@ -321,7 +321,7 @@ void hawk_unescape_bcstr (hawk_bch_t* str) } normal_char: - if (c == '\\') + if (c == '\\') { escaped = 1; continue; @@ -341,8 +341,8 @@ static const hawk_uch_t* scan_dollar_for_subst_u (const hawk_uch_t* f, hawk_oow_ const hawk_uch_t* end = f + l; HAWK_ASSERT (l >= 2); - - f += 2; /* skip ${ */ + + f += 2; /* skip ${ */ if (ident) ident->ptr = (hawk_uch_t*)f; while (1) @@ -354,10 +354,10 @@ static const hawk_uch_t* scan_dollar_for_subst_u (const hawk_uch_t* f, hawk_oow_ if (*f == ':') { - if (f >= end || *(f + 1) != '=') + if (f >= end || *(f + 1) != '=') { /* not := */ - return HAWK_NULL; + return HAWK_NULL; } if (ident) ident->len = f - ident->ptr; @@ -377,7 +377,7 @@ static const hawk_uch_t* scan_dollar_for_subst_u (const hawk_uch_t* f, hawk_oow_ f = scan_dollar_for_subst_u(f, end - f, HAWK_NULL, HAWK_NULL, depth + 1); if (!f) return HAWK_NULL; } - else if (*f == '}') + else if (*f == '}') { /* ending bracket */ if (dfl) dfl->len = f - dfl->ptr; @@ -386,10 +386,10 @@ static const hawk_uch_t* scan_dollar_for_subst_u (const hawk_uch_t* f, hawk_oow_ else f++; } } - else if (*f == '}') + else if (*f == '}') { if (ident) ident->len = f - ident->ptr; - if (dfl) + if (dfl) { dfl->ptr = HAWK_NULL; dfl->len = 0; @@ -461,7 +461,7 @@ hawk_oow_t hawk_subst_for_uchars_to_ucstr (hawk_uch_t* buf, hawk_oow_t bsz, cons continue; } - else if (*(f + 1) == '$') + else if (*(f + 1) == '$') { /* $$ -> $. */ f++; @@ -494,8 +494,8 @@ static const hawk_bch_t* scan_dollar_for_subst_b (const hawk_bch_t* f, hawk_oow_ const hawk_bch_t* end = f + l; HAWK_ASSERT (l >= 2); - - f += 2; /* skip ${ */ + + f += 2; /* skip ${ */ if (ident) ident->ptr = (hawk_bch_t*)f; while (1) @@ -507,10 +507,10 @@ static const hawk_bch_t* scan_dollar_for_subst_b (const hawk_bch_t* f, hawk_oow_ if (*f == ':') { - if (f >= end || *(f + 1) != '=') + if (f >= end || *(f + 1) != '=') { /* not := */ - return HAWK_NULL; + return HAWK_NULL; } if (ident) ident->len = f - ident->ptr; @@ -530,7 +530,7 @@ static const hawk_bch_t* scan_dollar_for_subst_b (const hawk_bch_t* f, hawk_oow_ f = scan_dollar_for_subst_b(f, end - f, HAWK_NULL, HAWK_NULL, depth + 1); if (!f) return HAWK_NULL; } - else if (*f == '}') + else if (*f == '}') { /* ending bracket */ if (dfl) dfl->len = f - dfl->ptr; @@ -539,10 +539,10 @@ static const hawk_bch_t* scan_dollar_for_subst_b (const hawk_bch_t* f, hawk_oow_ else f++; } } - else if (*f == '}') + else if (*f == '}') { if (ident) ident->len = f - ident->ptr; - if (dfl) + if (dfl) { dfl->ptr = HAWK_NULL; dfl->len = 0; @@ -614,7 +614,7 @@ hawk_oow_t hawk_subst_for_bchars_to_bcstr (hawk_bch_t* buf, hawk_oow_t bsz, cons continue; } - else if (*(f + 1) == '$') + else if (*(f + 1) == '$') { /* $$ -> $. */ f++; @@ -681,16 +681,16 @@ hawk_oow_t hawk_subst_for_bcstr_to_bcstr (hawk_bch_t* buf, hawk_oow_t bsz, const * fraction 52 bits 63 bits 112 bits * sign 1 bit 1 bit 1 bit * integer 1 bit - */ + */ #define FLT_MAX_EXPONENT 511 hawk_flt_t hawk_uchars_to_flt (const hawk_uch_t* str, hawk_oow_t len, const hawk_uch_t** endptr, int stripspc) { - /* - * Table giving binary powers of 10. Entry is 10^2^i. + /* + * Table giving binary powers of 10. Entry is 10^2^i. * Used to convert decimal exponents into floating-point numbers. - */ - static hawk_flt_t powers_of_10[] = + */ + static hawk_flt_t powers_of_10[] = { 10., 100., 1.0e4, 1.0e8, 1.0e16, 1.0e32, 1.0e64, 1.0e128, 1.0e256 @@ -701,13 +701,13 @@ hawk_flt_t hawk_uchars_to_flt (const hawk_uch_t* str, hawk_oow_t len, const hawk hawk_uci_t c; int exp = 0; /* Exponent read from "EX" field */ - /* - * Exponent that derives from the fractional part. Under normal + /* + * Exponent that derives from the fractional part. Under normal * circumstatnces, it is the negative of the number of digits in F. - * However, if I is very long, the last digits of I get dropped + * However, if I is very long, the last digits of I get dropped * (otherwise a long I with a large negative exponent could cause an - * unnecessary overflow on I alone). In this case, frac_exp is - * incremented one for each dropped digit. + * unnecessary overflow on I alone). In this case, frac_exp is + * incremented one for each dropped digit. */ int frac_exp; @@ -723,14 +723,14 @@ hawk_flt_t hawk_uchars_to_flt (const hawk_uch_t* str, hawk_oow_t len, const hawk /*while (AWK_IS_SPACE(*p)) p++;*/ if (stripspc) { - /* strip off leading spaces */ + /* strip off leading spaces */ while (p < end && hawk_is_uch_space(*p)) p++; } /*while (*p != _T('\0')) */ while (p < end) { - if (*p == '-') + if (*p == '-') { negative = ~negative; p++; @@ -743,10 +743,10 @@ hawk_flt_t hawk_uchars_to_flt (const hawk_uch_t* str, hawk_oow_t len, const hawk * point), and also locate the decimal point. */ dec_pt = -1; /*for (mant_size = 0; ; mant_size++) */ - for (mant_size = 0; p < end; mant_size++) + for (mant_size = 0; p < end; mant_size++) { c = *p; - if (!hawk_is_uch_digit(c)) + if (!hawk_is_uch_digit(c)) { if (c != '.' || dec_pt >= 0) break; dec_pt = mant_size; @@ -762,11 +762,11 @@ hawk_flt_t hawk_uchars_to_flt (const hawk_uch_t* str, hawk_oow_t len, const hawk */ pexp = p; p -= mant_size; - if (dec_pt < 0) + if (dec_pt < 0) { dec_pt = mant_size; - } - else + } + else { mant_size--; /* One of the digits was the point */ } @@ -775,29 +775,29 @@ hawk_flt_t hawk_uchars_to_flt (const hawk_uch_t* str, hawk_oow_t len, const hawk { frac_exp = dec_pt - 18; mant_size = 18; - } - else + } + else { frac_exp = dec_pt - mant_size; } - if (mant_size == 0) + if (mant_size == 0) { fraction = 0.0; /*p = str;*/ p = pexp; goto done; - } - else + } + else { int frac1, frac2; frac1 = 0; - for ( ; mant_size > 9; mant_size--) + for ( ; mant_size > 9; mant_size--) { c = *p; p++; - if (c == '.') + if (c == '.') { c = *p; p++; @@ -806,10 +806,10 @@ hawk_flt_t hawk_uchars_to_flt (const hawk_uch_t* str, hawk_oow_t len, const hawk } frac2 = 0; - for (; mant_size > 0; mant_size--) + for (; mant_size > 0; mant_size--) { c = *p++; - if (c == '.') + if (c == '.') { c = *p; p++; @@ -821,18 +821,18 @@ hawk_flt_t hawk_uchars_to_flt (const hawk_uch_t* str, hawk_oow_t len, const hawk /* Skim off the exponent */ p = pexp; - if (p < end && (*p == 'E' || *p == 'e')) + if (p < end && (*p == 'E' || *p == 'e')) { p++; - if (p < end) + if (p < end) { - if (*p == '-') + if (*p == '-') { exp_negative = 1; p++; - } - else + } + else { if (*p == '+') p++; exp_negative = 0; @@ -840,14 +840,14 @@ hawk_flt_t hawk_uchars_to_flt (const hawk_uch_t* str, hawk_oow_t len, const hawk } else exp_negative = 0; - if (!(p < end && hawk_is_uch_digit(*p))) + if (!(p < end && hawk_is_uch_digit(*p))) { /*p = pexp;*/ /*goto done;*/ goto no_exp; } - while (p < end && hawk_is_uch_digit(*p)) + while (p < end && hawk_is_uch_digit(*p)) { exp = exp * 10 + (*p - '0'); p++; @@ -864,18 +864,18 @@ no_exp: * many powers of 2 of 10. Then combine the exponent with the * fraction. */ - if (exp < 0) + if (exp < 0) { exp_negative = 1; exp = -exp; - } + } else exp_negative = 0; if (exp > FLT_MAX_EXPONENT) exp = FLT_MAX_EXPONENT; dbl_exp = 1.0; - for (d = powers_of_10; exp != 0; exp >>= 1, d++) + for (d = powers_of_10; exp != 0; exp >>= 1, d++) { if (exp & 01) dbl_exp *= *d; } @@ -895,11 +895,11 @@ done: hawk_flt_t hawk_bchars_to_flt (const hawk_bch_t* str, hawk_oow_t len, const hawk_bch_t** endptr, int stripspc) { - /* - * Table giving binary powers of 10. Entry is 10^2^i. + /* + * Table giving binary powers of 10. Entry is 10^2^i. * Used to convert decimal exponents into floating-point numbers. - */ - static hawk_flt_t powers_of_10[] = + */ + static hawk_flt_t powers_of_10[] = { 10., 100., 1.0e4, 1.0e8, 1.0e16, 1.0e32, 1.0e64, 1.0e128, 1.0e256 @@ -910,13 +910,13 @@ hawk_flt_t hawk_bchars_to_flt (const hawk_bch_t* str, hawk_oow_t len, const hawk hawk_bci_t c; int exp = 0; /* Exponent read from "EX" field */ - /* - * Exponent that derives from the fractional part. Under normal + /* + * Exponent that derives from the fractional part. Under normal * circumstatnces, it is the negative of the number of digits in F. - * However, if I is very long, the last digits of I get dropped + * However, if I is very long, the last digits of I get dropped * (otherwise a long I with a large negative exponent could cause an - * unnecessary overflow on I alone). In this case, frac_exp is - * incremented one for each dropped digit. + * unnecessary overflow on I alone). In this case, frac_exp is + * incremented one for each dropped digit. */ int frac_exp; @@ -932,14 +932,14 @@ hawk_flt_t hawk_bchars_to_flt (const hawk_bch_t* str, hawk_oow_t len, const hawk /*while (AWK_IS_SPACE(*p)) p++;*/ if (stripspc) { - /* strip off leading spaces */ + /* strip off leading spaces */ while (p < end && hawk_is_bch_space(*p)) p++; } /*while (*p != _T('\0')) */ while (p < end) { - if (*p == '-') + if (*p == '-') { negative = ~negative; p++; @@ -952,10 +952,10 @@ hawk_flt_t hawk_bchars_to_flt (const hawk_bch_t* str, hawk_oow_t len, const hawk * point), and also locate the decimal point. */ dec_pt = -1; /*for (mant_size = 0; ; mant_size++) */ - for (mant_size = 0; p < end; mant_size++) + for (mant_size = 0; p < end; mant_size++) { c = *p; - if (!hawk_is_bch_digit(c)) + if (!hawk_is_bch_digit(c)) { if (c != '.' || dec_pt >= 0) break; dec_pt = mant_size; @@ -971,11 +971,11 @@ hawk_flt_t hawk_bchars_to_flt (const hawk_bch_t* str, hawk_oow_t len, const hawk */ pexp = p; p -= mant_size; - if (dec_pt < 0) + if (dec_pt < 0) { dec_pt = mant_size; - } - else + } + else { mant_size--; /* One of the digits was the point */ } @@ -984,29 +984,29 @@ hawk_flt_t hawk_bchars_to_flt (const hawk_bch_t* str, hawk_oow_t len, const hawk { frac_exp = dec_pt - 18; mant_size = 18; - } - else + } + else { frac_exp = dec_pt - mant_size; } - if (mant_size == 0) + if (mant_size == 0) { fraction = 0.0; /*p = str;*/ p = pexp; goto done; - } - else + } + else { int frac1, frac2; frac1 = 0; - for ( ; mant_size > 9; mant_size--) + for ( ; mant_size > 9; mant_size--) { c = *p; p++; - if (c == '.') + if (c == '.') { c = *p; p++; @@ -1015,10 +1015,10 @@ hawk_flt_t hawk_bchars_to_flt (const hawk_bch_t* str, hawk_oow_t len, const hawk } frac2 = 0; - for (; mant_size > 0; mant_size--) + for (; mant_size > 0; mant_size--) { c = *p++; - if (c == '.') + if (c == '.') { c = *p; p++; @@ -1030,18 +1030,18 @@ hawk_flt_t hawk_bchars_to_flt (const hawk_bch_t* str, hawk_oow_t len, const hawk /* Skim off the exponent */ p = pexp; - if (p < end && (*p == 'E' || *p == 'e')) + if (p < end && (*p == 'E' || *p == 'e')) { p++; - if (p < end) + if (p < end) { - if (*p == '-') + if (*p == '-') { exp_negative = 1; p++; - } - else + } + else { if (*p == '+') p++; exp_negative = 0; @@ -1049,14 +1049,14 @@ hawk_flt_t hawk_bchars_to_flt (const hawk_bch_t* str, hawk_oow_t len, const hawk } else exp_negative = 0; - if (!(p < end && hawk_is_bch_digit(*p))) + if (!(p < end && hawk_is_bch_digit(*p))) { /*p = pexp;*/ /*goto done;*/ goto no_exp; } - while (p < end && hawk_is_bch_digit(*p)) + while (p < end && hawk_is_bch_digit(*p)) { exp = exp * 10 + (*p - '0'); p++; @@ -1073,18 +1073,18 @@ no_exp: * many powers of 2 of 10. Then combine the exponent with the * fraction. */ - if (exp < 0) + if (exp < 0) { exp_negative = 1; exp = -exp; - } + } else exp_negative = 0; if (exp > FLT_MAX_EXPONENT) exp = FLT_MAX_EXPONENT; dbl_exp = 1.0; - for (d = powers_of_10; exp != 0; exp >>= 1, d++) + for (d = powers_of_10; exp != 0; exp >>= 1, d++) { if (exp & 01) dbl_exp *= *d; } @@ -1128,18 +1128,18 @@ int hawk_uchars_to_num (int option, const hawk_uch_t* ptr, hawk_oow_t len, hawk_ { const hawk_uch_t* p = endptr; do { p++; } while (p < end && hawk_is_uch_digit(*p)); - if (p < end && (*p == '.' || *p == 'E' || *p == 'e')) + if (p < end && (*p == '.' || *p == 'E' || *p == 'e')) { - /* it's probably an floating-point number. - * + /* it's probably an floating-point number. + * * BEGIN { b=99; printf "%f\n", (0 b 1.112); } * * for the above code, this function gets '0991.112'. * and endptr points to '9' after hawk_uchars_to_int() as - * the numeric string beginning with 0 is treated - * as an octal number. - * - * getting side-tracked, + * the numeric string beginning with 0 is treated + * as an octal number. + * + * getting side-tracked, * BEGIN { b=99; printf "%f\n", (0 b 1.000); } * the above code cause this function to get 0991, not 0991.000 * because of the default CONVFMT '%.6g' which doesn't produce '.000'. @@ -1186,18 +1186,18 @@ int hawk_bchars_to_num (int option, const hawk_bch_t* ptr, hawk_oow_t len, hawk_ { const hawk_bch_t* p = endptr; do { p++; } while (p < end && hawk_is_bch_digit(*p)); - if (p < end && (*p == '.' || *p == 'E' || *p == 'e')) + if (p < end && (*p == '.' || *p == 'E' || *p == 'e')) { - /* it's probably an floating-point number. - * + /* it's probably an floating-point number. + * * BEGIN { b=99; printf "%f\n", (0 b 1.112); } * * for the above code, this function gets '0991.112'. * and endptr points to '9' after hawk_bchars_to_int() as - * the numeric string beginning with 0 is treated - * as an octal number. - * - * getting side-tracked, + * the numeric string beginning with 0 is treated + * as an octal number. + * + * getting side-tracked, * BEGIN { b=99; printf "%f\n", (0 b 1.000); } * the above code cause this function to get 0991, not 0991.000 * because of the default CONVFMT '%.6g' which doesn't produce '.000'. diff --git a/lib/val-prv.h b/lib/val-prv.h index a25d815d..82f06263 100644 --- a/lib/val-prv.h +++ b/lib/val-prv.h @@ -39,7 +39,7 @@ struct hawk_val_chunk_t struct hawk_val_ichunk_t { hawk_val_chunk_t* next; - /* make sure that it has the same fields as + /* make sure that it has the same fields as hawk_val_chunk_t up to this point */ hawk_val_int_t slot[HAWK_VAL_CHUNK_SIZE]; @@ -48,21 +48,21 @@ struct hawk_val_ichunk_t struct hawk_val_rchunk_t { hawk_val_chunk_t* next; - /* make sure that it has the same fields as + /* make sure that it has the same fields as hawk_val_chunk_t up to this point */ hawk_val_flt_t slot[HAWK_VAL_CHUNK_SIZE]; }; -/* +/* * if shared objects link a static library, statically defined objects * in the static library will be instatiated in the multiple shared objects. * * so equality check with a value pointer doesn't work * if the code crosses the library boundaries. instead, i decided to * add a field to indicate if a value is static. - * + * #define HAWK_IS_STATICVAL(val) ((val) == HAWK_NULL || (val) == hawk_val_nil || (val) == hawk_val_zls || (val) == hawk_val_zlbs) */ @@ -77,7 +77,7 @@ struct hawk_val_rchunk_t * aligned malloc()? */ #define HAWK_VTR_NUM_TYPE_BITS_LO 2 /* last 2 bits */ #define HAWK_VTR_MASK_TYPE_BITS_LO 3 /* 11 - all 1's in the last 2 bits */ -#define HAWK_VTR_NUM_TYPE_BITS_LOHI 4 +#define HAWK_VTR_NUM_TYPE_BITS_LOHI 4 #define HAWK_VTR_MASK_TYPE_BITS_LOHI 15 /* 1111 */ @@ -91,7 +91,7 @@ struct hawk_val_rchunk_t #define HAWK_VTR_TYPE_BITS_RESERVED2 15 /* 1111 */ #define HAWK_VTR_SIGN_BIT ((hawk_uintptr_t)1 << (HAWK_SIZEOF_UINTPTR_T * 8 - 1)) -/* shrink the bit range by 1 more bit to ease sign-bit handling. +/* shrink the bit range by 1 more bit to ease sign-bit handling. * i want abs(max) == abs(min). * i don't want abs(max) + 1 == abs(min). e.g min: -32768, max: 32767 */ diff --git a/lib/val.c b/lib/val.c index c97216be..490fc74a 100644 --- a/lib/val.c +++ b/lib/val.c @@ -57,7 +57,7 @@ static hawk_val_mbs_t hawk_zlbs = { }; hawk_val_t* hawk_val_nil = (hawk_val_t*)&hawk_nil; -hawk_val_t* hawk_val_zls = (hawk_val_t*)&hawk_zls; +hawk_val_t* hawk_val_zls = (hawk_val_t*)&hawk_zls; hawk_val_t* hawk_val_zlbs = (hawk_val_t*)&hawk_zlbs; static const hawk_ooch_t* val_type_name[] = @@ -84,14 +84,14 @@ static const hawk_ooch_t* val_type_name[] = /* BEGIN { - @local a, b, c, nil; + @local a, b, c, nil; for (i = 1; i < 10; i++) a[i] = i; a[11] = a; a[12] = a; a = @nil; b[1] = a; c[1] = 0; -} +} BEGIN { @local a, b, c, nil; @@ -109,7 +109,7 @@ BEGIN { b[1] = a; c[1] = 0; } - + BEGIN { @local a, b, c, j, nil; j[1] = 20; @@ -126,7 +126,7 @@ BEGIN { b[1] = a; c[1] = 0; } - + BEGIN { @local a, b, c, nil; j[1] = 20; @@ -224,7 +224,7 @@ static void gc_trace_refs (hawk_gch_t* list) while (pair) { iv = (hawk_val_t*)HAWK_MAP_VPTR(pair); - if (HAWK_VTR_IS_POINTER(iv) && iv->v_gc) + if (HAWK_VTR_IS_POINTER(iv) && iv->v_gc) { hawk_val_to_gch(iv)->gc_refs--; } @@ -245,7 +245,7 @@ static void gc_trace_refs (hawk_gch_t* list) if (HAWK_ARR_SLOT(arr, i)) { iv = (hawk_val_t*)HAWK_ARR_DPTR(arr, i); - if (HAWK_VTR_IS_POINTER(iv) && iv->v_gc) + if (HAWK_VTR_IS_POINTER(iv) && iv->v_gc) { hawk_val_to_gch(iv)->gc_refs--; } @@ -308,7 +308,7 @@ static void gc_move_reachables (hawk_gch_t* list, hawk_gch_t* reachable_list) while (pair) { iv = (hawk_val_t*)HAWK_MAP_VPTR(pair); - if (HAWK_VTR_IS_POINTER(iv) && iv->v_gc) + if (HAWK_VTR_IS_POINTER(iv) && iv->v_gc) { tmp = hawk_val_to_gch(iv); if (tmp->gc_refs != GCH_MOVED) @@ -335,7 +335,7 @@ static void gc_move_reachables (hawk_gch_t* list, hawk_gch_t* reachable_list) if (HAWK_ARR_SLOT(arr, i)) { iv = (hawk_val_t*)HAWK_ARR_DPTR(arr, i); - if (HAWK_VTR_IS_POINTER(iv) && iv->v_gc) + if (HAWK_VTR_IS_POINTER(iv) && iv->v_gc) { tmp = hawk_val_to_gch(iv); if (tmp->gc_refs != GCH_MOVED) @@ -407,12 +407,12 @@ static HAWK_INLINE void gc_collect_garbage_in_generation (hawk_rtx_t* rtx, int g #endif newgen = (gen < HAWK_COUNTOF(rtx->gc.g) - 1)? (gen + 1): gen; - for (i = 0; i < gen; i++) + for (i = 0; i < gen; i++) { gc_move_all_gchs (&rtx->gc.g[i], &rtx->gc.g[gen]); } - if (rtx->gc.g[gen].gc_next != &rtx->gc.g[gen]) + if (rtx->gc.g[gen].gc_next != &rtx->gc.g[gen]) { hawk_gch_t reachable; @@ -427,7 +427,7 @@ static HAWK_INLINE void gc_collect_garbage_in_generation (hawk_rtx_t* rtx, int g /*gc_dump_refs (rtx, &rtx->gc.g[0]);*/ #endif gc_free_unreachables (rtx, &rtx->gc.g[gen]); - HAWK_ASSERT (rtx->gc.g[gen].gc_next == &rtx->gc.g[gen]); + HAWK_ASSERT (rtx->gc.g[gen].gc_next == &rtx->gc.g[gen]); /* move all reachables back to the main list */ gc_move_all_gchs (&reachable, &rtx->gc.g[newgen]); @@ -449,7 +449,7 @@ static HAWK_INLINE int gc_collect_garbage_auto (hawk_rtx_t* rtx) { hawk_oow_t i; - i = HAWK_COUNTOF(rtx->gc.g); + i = HAWK_COUNTOF(rtx->gc.g); while (i > 1) { --i; @@ -484,19 +484,19 @@ static HAWK_INLINE hawk_val_t* gc_calloc_val (hawk_rtx_t* rtx, hawk_oow_t size) hawk_gch_t* gch; int gc_gen = 0; - if (HAWK_UNLIKELY(rtx->gc.pressure[0] >= rtx->gc.threshold[0])) + if (HAWK_UNLIKELY(rtx->gc.pressure[0] >= rtx->gc.threshold[0])) { /* invoke generational garbage collection */ gc_gen = gc_collect_garbage_auto(rtx); } gch = (hawk_gch_t*)hawk_rtx_callocmem(rtx, HAWK_SIZEOF(*gch) + size); - if (HAWK_UNLIKELY(!gch)) + if (HAWK_UNLIKELY(!gch)) { - if (gc_gen < HAWK_COUNTOF(rtx->gc.g) - 1) + if (gc_gen < HAWK_COUNTOF(rtx->gc.g) - 1) { /* perform full gc if full gc has not been triggerred at the beginning of this function */ - hawk_rtx_gc (rtx, HAWK_COUNTOF(rtx->gc.g) - 1); + hawk_rtx_gc (rtx, HAWK_COUNTOF(rtx->gc.g) - 1); } gch = (hawk_gch_t*)hawk_rtx_callocmem(rtx, HAWK_SIZEOF(*gch) + size); if (HAWK_UNLIKELY(!gch)) return HAWK_NULL; @@ -563,13 +563,13 @@ hawk_val_t* hawk_rtx_makeintval (hawk_rtx_t* rtx, hawk_int_t v) * will cause a fault on such a platform */ c = hawk_rtx_allocmem(rtx, HAWK_SIZEOF(hawk_val_ichunk_t)); if (HAWK_UNLIKELY(!c)) return HAWK_NULL; - + c->next = rtx->vmgr.ichunk; /*run->vmgr.ichunk = c;*/ rtx->vmgr.ichunk = (hawk_val_chunk_t*)c; /*x = (hawk_val_int_t*)(c + 1); - for (i = 0; i < CHUNKSIZE-1; i++) + for (i = 0; i < CHUNKSIZE-1; i++) x[i].nde = (hawk_nde_int_t*)&x[i+1]; x[i].nde = HAWK_NULL; @@ -792,7 +792,7 @@ hawk_val_t* hawk_rtx_makenumorstrvalwithuchars (hawk_rtx_t* rtx, const hawk_uch_ x = hawk_uchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 1, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr, len, &l, &r); if (x == 0) return hawk_rtx_makeintval(rtx, l); else if (x >= 1) return hawk_rtx_makefltval(rtx, r); - } + } make_str: return hawk_rtx_makestrvalwithuchars(rtx, ptr, len); @@ -832,7 +832,7 @@ hawk_val_t* hawk_rtx_makenstrvalwithuchars (hawk_rtx_t* rtx, const hawk_uch_t* p if (HAWK_UNLIKELY(!v)) return HAWK_NULL; - if (x >= 0) + if (x >= 0) { /* set the numeric string flag if a string * can be converted to a number */ @@ -854,7 +854,7 @@ hawk_val_t* hawk_rtx_makenstrvalwithbchars (hawk_rtx_t* rtx, const hawk_bch_t* p v = hawk_rtx_makestrvalwithbchars(rtx, ptr, len); if (HAWK_UNLIKELY(!v)) return HAWK_NULL; - if (x >= 0) + if (x >= 0) { /* set the numeric string flag if a string * can be converted to a number */ @@ -1081,8 +1081,8 @@ static void free_arrayval (hawk_arr_t* arr, void* dptr, hawk_oow_t dlen) #if defined(HAWK_ENABLE_GC) if (HAWK_VTR_IS_POINTER(v) && v->v_gc && hawk_val_to_gch(v)->gc_refs == GCH_UNREACHABLE) { - /* do nothing if the element is unreachable. - * this behavior pairs up with gc_free_unreachables() to + /* do nothing if the element is unreachable. + * this behavior pairs up with gc_free_unreachables() to * achieve safe disposal of a value */ return; } @@ -1106,10 +1106,10 @@ hawk_val_t* hawk_rtx_makearrval (hawk_rtx_t* rtx, hawk_ooi_t init_capa) static hawk_arr_style_t style = { /* the key is copied inline into a pair and is freed when the pair - * is destroyed. not setting copier for a value means that the pointer - * to the data allocated somewhere else is remembered in a pair. but + * is destroyed. not setting copier for a value means that the pointer + * to the data allocated somewhere else is remembered in a pair. but * freeing the actual value is handled by free_arrval and same_arrval */ - + HAWK_ARR_COPIER_DEFAULT, free_arrayval, HAWK_ARR_COMPER_DEFAULT, @@ -1137,7 +1137,7 @@ retry: val->arr = (hawk_arr_t*)(val + 1); if (init_capa < 0) init_capa = 64; /* TODO: what is the best initial value? */ - if (HAWK_UNLIKELY(hawk_arr_init(val->arr, hawk_rtx_getgem(rtx), init_capa) <= -1)) + if (HAWK_UNLIKELY(hawk_arr_init(val->arr, hawk_rtx_getgem(rtx), init_capa) <= -1)) { #if defined(HAWK_ENABLE_GC) gc_free_val (rtx, (hawk_val_t*)val); @@ -1182,8 +1182,8 @@ static void free_mapval (hawk_map_t* map, void* dptr, hawk_oow_t dlen) #if defined(HAWK_ENABLE_GC) if (HAWK_VTR_IS_POINTER(v) && v->v_gc && hawk_val_to_gch(v)->gc_refs == GCH_UNREACHABLE) { - /* do nothing if the element is unreachable. - * this behavior pairs up with gc_free_unreachables() to + /* do nothing if the element is unreachable. + * this behavior pairs up with gc_free_unreachables() to * achieve safe disposal of a value */ return; } @@ -1206,8 +1206,8 @@ hawk_val_t* hawk_rtx_makemapval (hawk_rtx_t* rtx) static hawk_map_style_t style = { /* the key is copied inline into a pair and is freed when the pair - * is destroyed. not setting copier for a value means that the pointer - * to the data allocated somewhere else is remembered in a pair. but + * is destroyed. not setting copier for a value means that the pointer + * to the data allocated somewhere else is remembered in a pair. but * freeing the actual value is handled by free_mapval and same_mapval */ { HAWK_MAP_COPIER_INLINE, @@ -1386,7 +1386,7 @@ hawk_val_t* hawk_rtx_getmapvalfld (hawk_rtx_t* rtx, hawk_val_t* map, const hawk_ if (!pair) { /* the given key is not found in the map. - * we return NULL here as this function is called by + * we return NULL here as this function is called by * a user unlike the hawk statement accessing the map key. * so you can easily determine if the key is found by * checking the error number. @@ -1688,7 +1688,7 @@ void hawk_rtx_refdownval (hawk_rtx_t* rtx, hawk_val_t* val) } #else val->v_refs--; - if (val->v_refs <= 0) + if (val->v_refs <= 0) { hawk_rtx_freeval (rtx, val, HAWK_RTX_FREEVAL_CACHE); } @@ -1701,7 +1701,7 @@ void hawk_rtx_refdownval_nofree (hawk_rtx_t* rtx, hawk_val_t* val) if (HAWK_VTR_IS_POINTER(val)) { if (HAWK_IS_STATICVAL(val)) return; - + /* the reference count of a value should be greater than zero for it to be decremented. check the source code for any bugs */ HAWK_ASSERT (val->v_refs > 0); @@ -1755,10 +1755,10 @@ static int val_ref_to_bool (hawk_rtx_t* rtx, const hawk_val_ref_t* ref) { hawk_val_t** xref = (hawk_val_t**)ref->adr; - /* A reference value is not able to point to another + /* A reference value is not able to point to another * refernce value for the way values are represented * in HAWK */ - HAWK_ASSERT (HAWK_RTX_GETVALTYPE (rtx, *xref)!= HAWK_VAL_REF); + HAWK_ASSERT (HAWK_RTX_GETVALTYPE (rtx, *xref)!= HAWK_VAL_REF); /* make a recursive call back to the caller */ return hawk_rtx_valtobool(rtx, *xref); @@ -1807,7 +1807,7 @@ int hawk_rtx_valtobool (hawk_rtx_t* rtx, const hawk_val_t* val) /* the type of a value should be one of HAWK_VAL_XXX enumerators defined in hawk-prv.h */ HAWK_ASSERT (!"should never happen - invalid value type"); - + return 0; } @@ -1892,7 +1892,7 @@ static int mbs_to_str (hawk_rtx_t* rtx, const hawk_bch_t* str, hawk_oow_t str_le return -1; } /* hawk_rtx_convbtouchars() doesn't null terminate the result. -1 to secure space for '\0' */ - ucslen = out->u.cplcpy.len - 1; + ucslen = out->u.cplcpy.len - 1; if (hawk_rtx_convbtouchars(rtx, str, &str_len, out->u.cplcpy.ptr, &ucslen, 1) <= -1) return -1; out->u.cplcpy.ptr[ucslen] = HAWK_T('\0'); @@ -1942,9 +1942,9 @@ static int val_int_to_str (hawk_rtx_t* rtx, const hawk_val_int_t* v, hawk_rtx_va else { /* non-zero values */ - if (orgval < 0) + if (orgval < 0) { - t = orgval * -1; rlen++; + t = orgval * -1; rlen++; } else t = orgval; while (t > 0) { rlen++; t /= 10; } @@ -1954,10 +1954,10 @@ static int val_int_to_str (hawk_rtx_t* rtx, const hawk_val_int_t* v, hawk_rtx_va { case HAWK_RTX_VALTOSTR_CPL: /* CPL and CPLCP behave the same for int_t. - * i just fall through assuming that cplcpy + * i just fall through assuming that cplcpy * and cpl are the same type. the following * assertion at least ensure that they have - * the same size. */ + * the same size. */ HAWK_ASSERT (HAWK_SIZEOF(out->u.cpl) == HAWK_SIZEOF(out->u.cplcpy)); case HAWK_RTX_VALTOSTR_CPLCPY: @@ -1965,7 +1965,7 @@ static int val_int_to_str (hawk_rtx_t* rtx, const hawk_val_int_t* v, hawk_rtx_va { hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINVAL); /* store the buffer size needed */ - out->u.cplcpy.len = rlen + 1; + out->u.cplcpy.len = rlen + 1; return -1; } @@ -2019,13 +2019,13 @@ static int val_int_to_str (hawk_rtx_t* rtx, const hawk_val_int_t* v, hawk_rtx_va } } - if (orgval == 0) tmp[0] = HAWK_T('0'); + if (orgval == 0) tmp[0] = HAWK_T('0'); else { t = (orgval < 0)? (orgval * -1): orgval; /* fill in the buffer with digits */ - while (t > 0) + while (t > 0) { tmp[--rlen] = (hawk_ooch_t)(t % 10) + HAWK_T('0'); t /= 10; @@ -2074,10 +2074,10 @@ static int val_flt_to_str (hawk_rtx_t* rtx, const hawk_val_flt_t* v, hawk_rtx_va { case HAWK_RTX_VALTOSTR_CPL: /* CPL and CPLCP behave the same for flt_t. - * i just fall through assuming that cplcpy + * i just fall through assuming that cplcpy * and cpl are the same type. the following * assertion at least ensure that they have - * the same size. */ + * the same size. */ HAWK_ASSERT (HAWK_SIZEOF(out->u.cpl) == HAWK_SIZEOF(out->u.cplcpy)); case HAWK_RTX_VALTOSTR_CPLCPY: @@ -2085,7 +2085,7 @@ static int val_flt_to_str (hawk_rtx_t* rtx, const hawk_val_flt_t* v, hawk_rtx_va { hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINVAL); /* store the buffer size required */ - out->u.cplcpy.len = tmp_len + 1; + out->u.cplcpy.len = tmp_len + 1; goto oops; } @@ -2143,7 +2143,7 @@ static int val_ref_to_str (hawk_rtx_t* rtx, const hawk_val_ref_t* ref, hawk_rtx_ { hawk_oow_t idx; - /* special case when the reference value is + /* special case when the reference value is * pointing to the positional */ idx = (hawk_oow_t)ref->adr; @@ -2181,10 +2181,10 @@ static int val_ref_to_str (hawk_rtx_t* rtx, const hawk_val_ref_t* ref, hawk_rtx_ { hawk_val_t** xref = (hawk_val_t**)ref->adr; - /* A reference value is not able to point to another + /* A reference value is not able to point to another * refernce value for the way values are represented * in HAWK */ - HAWK_ASSERT (HAWK_RTX_GETVALTYPE (rtx, *xref) != HAWK_VAL_REF); + HAWK_ASSERT (HAWK_RTX_GETVALTYPE (rtx, *xref) != HAWK_VAL_REF); /* make a recursive call back to the caller */ return hawk_rtx_valtostr(rtx, *xref, out); @@ -2492,7 +2492,7 @@ hawk_ooch_t* hawk_rtx_getvaloocstrwithcmgr (hawk_rtx_t* rtx, hawk_val_t* v, hawk return ((hawk_val_str_t*)v)->val.ptr; #if 0 -/* i'm commenting out this part because hawk_rtx_setrefval() changes v->adr +/* i'm commenting out this part because hawk_rtx_setrefval() changes v->adr * and leads hawk_rtx_freevaloocstr() to check a wrong value obejct. * if you know that a value is a reference, you can get the referenced value * with hawk_rtx_getrefval() and call this function over it */ @@ -2586,7 +2586,7 @@ hawk_bch_t* hawk_rtx_getvalbcstrwithcmgr (hawk_rtx_t* rtx, hawk_val_t* v, hawk_o return ((hawk_val_mbs_t*)v)->val.ptr; #if 0 -/* i'm commenting out this part because hawk_rtx_setrefval() changes v->adr +/* i'm commenting out this part because hawk_rtx_setrefval() changes v->adr * and leads hawk_rtx_freevalbcstr() to check a wrong value obejct. * if you know that a value is a reference, you can get the referenced value * with hawk_rtx_getrefval() and call this function over it */ @@ -2650,7 +2650,7 @@ static int val_ref_to_num (hawk_rtx_t* rtx, const hawk_val_ref_t* ref, hawk_int_ case HAWK_VAL_REF_POS: { hawk_oow_t idx; - + idx = (hawk_oow_t)ref->adr; if (idx == 0) { @@ -2686,10 +2686,10 @@ static int val_ref_to_num (hawk_rtx_t* rtx, const hawk_val_ref_t* ref, hawk_int_ { hawk_val_t** xref = (hawk_val_t**)ref->adr; - /* A reference value is not able to point to another + /* A reference value is not able to point to another * refernce value for the way values are represented * in HAWK */ - HAWK_ASSERT (HAWK_RTX_GETVALTYPE(rtx, *xref) != HAWK_VAL_REF); + HAWK_ASSERT (HAWK_RTX_GETVALTYPE(rtx, *xref) != HAWK_VAL_REF); /* make a recursive call back to the caller */ return hawk_rtx_valtonum(rtx, *xref, l, r); @@ -2791,7 +2791,7 @@ int hawk_rtx_valtoint (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_int_t* l) hawk_flt_t r; n = hawk_rtx_valtonum(rtx, v, l, &r); - if (n == 1) + if (n == 1) { *l = (hawk_int_t)r; n = 0; @@ -2849,7 +2849,7 @@ hawk_fun_t* hawk_rtx_valtofun (hawk_rtx_t* rtx, hawk_val_t* v) hawk_oocs_t x; x.ptr = hawk_rtx_getvaloocstr(rtx, v, &x.len); if (HAWK_UNLIKELY(!x.ptr)) return HAWK_NULL; - if (hawk_count_oocstr(x.ptr) != x.len) + if (hawk_count_oocstr(x.ptr) != x.len) { hawk_rtx_freevaloocstr (rtx, v, x.ptr); goto error_inval; @@ -2874,7 +2874,7 @@ hawk_fnc_t* hawk_rtx_valtofnc (hawk_rtx_t* rtx, hawk_val_t* v, hawk_fnc_t* rfnc) /* this function looks for intrinsic functions as well as module functions. * it combines the functionality of the following two functions. * hawk_findfncwithoocs() - finds an intrisic function - * hawk_querymodulewithname() - finds a function defined in a module + * hawk_querymodulewithname() - finds a function defined in a module */ hawk_t* hawk = hawk_rtx_gethawk(rtx); @@ -2894,7 +2894,7 @@ hawk_fnc_t* hawk_rtx_valtofnc (hawk_rtx_t* rtx, hawk_val_t* v, hawk_fnc_t* rfnc) x.ptr = hawk_rtx_getvaloocstr(rtx, v, &x.len); if (HAWK_UNLIKELY(!x.ptr)) return HAWK_NULL; - if (hawk_count_oocstr(x.ptr) != x.len) + if (hawk_count_oocstr(x.ptr) != x.len) { hawk_rtx_freevaloocstr (rtx, v, x.ptr); goto error_inval; @@ -3055,11 +3055,11 @@ hawk_val_type_t hawk_rtx_getrefvaltype (hawk_rtx_t* rtx, hawk_val_ref_t* ref) hawk_val_t** xref = (hawk_val_t**)ref->adr; hawk_val_t* v; - /* A reference value is not able to point to another + /* A reference value is not able to point to another * refernce value for the way values are represented * in HAWK */ v = *xref; - HAWK_ASSERT (HAWK_RTX_GETVALTYPE(rtx, v) != HAWK_VAL_REF); + HAWK_ASSERT (HAWK_RTX_GETVALTYPE(rtx, v) != HAWK_VAL_REF); return HAWK_RTX_GETVALTYPE(rtx, v); } } @@ -3098,10 +3098,10 @@ hawk_val_t* hawk_rtx_getrefval (hawk_rtx_t* rtx, hawk_val_ref_t* ref) default: { hawk_val_t** xref = (hawk_val_t**)ref->adr; - /* A reference value is not able to point to another + /* A reference value is not able to point to another * refernce value for the way values are represented * in HAWK */ - HAWK_ASSERT (HAWK_RTX_GETVALTYPE(rtx, *xref) != HAWK_VAL_REF); + HAWK_ASSERT (HAWK_RTX_GETVALTYPE(rtx, *xref) != HAWK_VAL_REF); return *xref; } } @@ -3117,7 +3117,7 @@ int hawk_rtx_setrefval (hawk_rtx_t* rtx, hawk_val_ref_t* ref, hawk_val_t* val) * can accept a regular expression withtout evaluation when 'x' * is specified for the parameter, this function doesn't allow * regular expression to be set to a reference variable to - * avoid potential chaos. the nature of performing '/rex/ ~ $0' + * avoid potential chaos. the nature of performing '/rex/ ~ $0' * for a regular expression without the match operator * makes it difficult to be implemented. */ hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINVAL); @@ -3167,7 +3167,7 @@ int hawk_rtx_setrefval (hawk_rtx_t* rtx, hawk_val_ref_t* ref, hawk_val_t* val) #if !defined(HAWK_ENABLE_GC) if (vtype == HAWK_VAL_MAP || vtype == HAWK_VAL_ARR) { - /* an indexed variable cannot be assigned a map. + /* an indexed variable cannot be assigned a map. * in other cases, it falls down to the default case. */ hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENONSCATOIDX); return -1; @@ -3207,7 +3207,7 @@ int hawk_rtx_setrefval (hawk_rtx_t* rtx, hawk_val_ref_t* ref, hawk_val_t* val) } } } - + if (*rref != val) { /* if the new value is not the same as the old value */ @@ -3274,7 +3274,7 @@ void hawk_dprintval (hawk_rtx_t* run, hawk_val_t* val) #if defined(HAWK_OOCH_IS_UCH) else if (tmp <= 0xFFFF) hawk_errputstrf (HAWK_T("'\\u%04x'"), tmp); - else + else hawk_errputstrf (HAWK_T("'\\U%08x'"), tmp); #else else diff --git a/lib/xma.c b/lib/xma.c index 77aa8bb5..4354c19d 100644 --- a/lib/xma.c +++ b/lib/xma.c @@ -26,10 +26,10 @@ #include "hawk-prv.h" /* set ALIGN to twice the pointer size to prevent unaligned memory access by - * instructions dealing with data larger than the system word size. e.g. movaps on x86_64 - * + * instructions dealing with data larger than the system word size. e.g. movaps on x86_64 + * * in the following run, movaps tries to write to the address 0x7fffea722f78. - * since the instruction deals with 16-byte aligned data only, it triggered + * since the instruction deals with 16-byte aligned data only, it triggered * the general protection error. * $ gdb ~/xxx/bin/hawk @@ -82,7 +82,7 @@ struct hawk_xma_mblk_t hawk_oow_t size: HAWK_XMA_SIZE_BITS;/**< block size */ }; -struct hawk_xma_fblk_t +struct hawk_xma_fblk_t { hawk_oow_t prev_size; hawk_oow_t free: 1; @@ -99,7 +99,7 @@ static void DBG_VERIFY (hawk_xma_t* xma, const char* desc) { hawk_xma_mblk_t* tmp, * next; hawk_oow_t cnt; - hawk_oow_t fsum, asum; + hawk_oow_t fsum, asum; #if defined(HAWK_XMA_ENABLE_STAT) hawk_oow_t isum; #endif @@ -133,7 +133,7 @@ static void DBG_VERIFY (hawk_xma_t* xma, const char* desc) #define DBG_VERIFY(xma, desc) #endif -static HAWK_INLINE hawk_oow_t szlog2 (hawk_oow_t n) +static HAWK_INLINE hawk_oow_t szlog2 (hawk_oow_t n) { /* * 2**x = n; @@ -163,7 +163,7 @@ static HAWK_INLINE hawk_oow_t szlog2 (hawk_oow_t n) #if HAWK_SIZEOF_OOW_T >= 8 if ((n & (~(hawk_oow_t)0 << (BITS-32))) == 0) { x -= 32; n <<= 32; } #endif -#if HAWK_SIZEOF_OOW_T >= 4 +#if HAWK_SIZEOF_OOW_T >= 4 if ((n & (~(hawk_oow_t)0 << (BITS-16))) == 0) { x -= 16; n <<= 16; } #endif #if HAWK_SIZEOF_OOW_T >= 2 @@ -179,7 +179,7 @@ static HAWK_INLINE hawk_oow_t szlog2 (hawk_oow_t n) #undef BITS } -static HAWK_INLINE hawk_oow_t getxfi (hawk_xma_t* xma, hawk_oow_t size) +static HAWK_INLINE hawk_oow_t getxfi (hawk_xma_t* xma, hawk_oow_t size) { hawk_oow_t xfi = ((size) / ALIGN) - 1; if (xfi >= FIXED) xfi = szlog2(size) - (xma)->bdec + FIXED; @@ -230,7 +230,7 @@ int hawk_xma_init (hawk_xma_t* xma, hawk_mmgr_t* mmgr, void* zoneptr, hawk_oow_t internal = 1; } - else if (zonesize < FBLKMINSIZE) + else if (zonesize < FBLKMINSIZE) { /* the zone size is too small for an externally allocated zone. */ /* TODO: difference error code from memory allocation failure.. this is not really memory shortage */ @@ -255,7 +255,7 @@ int hawk_xma_init (hawk_xma_t* xma, hawk_mmgr_t* mmgr, void* zoneptr, hawk_oow_t /* get the free block index */ xfi = getxfi(xma, first->size); /* locate it into an apporopriate slot */ - xma->xfree[xfi] = first; + xma->xfree[xfi] = first; /* let it be the head, which is natural with only a block */ xma->start = (hawk_uint8_t*)first; xma->end = xma->start + zonesize; @@ -269,7 +269,7 @@ int hawk_xma_init (hawk_xma_t* xma, hawk_mmgr_t* mmgr, void* zoneptr, hawk_oow_t xma->stat.nfree = 1; xma->stat.nused = 0; #endif - + return 0; } @@ -284,15 +284,15 @@ void hawk_xma_fini (hawk_xma_t* xma) static HAWK_INLINE void attach_to_freelist (hawk_xma_t* xma, hawk_xma_fblk_t* b) { - /* - * attach a block to a free list + /* + * attach a block to a free list */ /* get the free list index for the block size */ - hawk_oow_t xfi = getxfi(xma, b->size); + hawk_oow_t xfi = getxfi(xma, b->size); /* let it be the head of the free list doubly-linked */ - b->free_prev = HAWK_NULL; + b->free_prev = HAWK_NULL; b->free_next = xma->xfree[xfi]; if (xma->xfree[xfi]) xma->xfree[xfi]->free_prev = b; xma->xfree[xfi] = b; @@ -309,11 +309,11 @@ static HAWK_INLINE void detach_from_freelist (hawk_xma_t* xma, hawk_xma_fblk_t* if (p) { - /* the previous item exists. let its 'next' pointer point to + /* the previous item exists. let its 'next' pointer point to * the block's next item. */ p->free_next = n; } - else + else { /* the previous item does not exist. the block is the first * item in the free list. */ @@ -324,7 +324,7 @@ static HAWK_INLINE void detach_from_freelist (hawk_xma_t* xma, hawk_xma_fblk_t* xma->xfree[xfi] = n; } - /* let the 'prev' pointer of the block's next item point to the + /* let the 'prev' pointer of the block's next item point to the * block's previous item */ if (n) n->free_prev = p; } @@ -346,8 +346,8 @@ static hawk_xma_fblk_t* alloc_from_freelist (hawk_xma_t* xma, hawk_oow_t xfi, ha { hawk_xma_mblk_t* y, * z; - /* the remaining part is large enough to hold - * another block. let's split it + /* the remaining part is large enough to hold + * another block. let's split it */ /* shrink the size of the 'cand' block */ @@ -478,7 +478,7 @@ static void* _realloc_merge (hawk_xma_t* xma, void* b, hawk_oow_t size) hawk_xma_mblk_t* blk = (hawk_xma_mblk_t*)USR_TO_SYS(b); DBG_VERIFY (xma, "realloc merge start"); - /* rounds up 'size' to be multiples of ALIGN */ + /* rounds up 'size' to be multiples of ALIGN */ if (size < MINALLOCSIZE) size = MINALLOCSIZE; size = HAWK_ALIGN_POW2(size, ALIGN); @@ -505,8 +505,8 @@ static void* _realloc_merge (hawk_xma_t* xma, void* b, hawk_oow_t size) rem = (MBLKHDRSIZE + n->size) - req; if (rem >= FBLKMINSIZE) { - /* - * the remaining part of the next block is large enough + /* + * the remaining part of the next block is large enough * to hold a block. break the next block. */ @@ -549,7 +549,7 @@ static void* _realloc_merge (hawk_xma_t* xma, void* b, hawk_oow_t size) { /* shrink the block */ hawk_oow_t rem = blk->size - size; - if (rem >= FBLKMINSIZE) + if (rem >= FBLKMINSIZE) { hawk_xma_mblk_t* n; @@ -622,7 +622,7 @@ void* hawk_xma_realloc (hawk_xma_t* xma, void* b, hawk_oow_t size) { void* n; - if (b == HAWK_NULL) + if (b == HAWK_NULL) { /* 'realloc' with NULL is the same as 'alloc' */ n = hawk_xma_alloc(xma, size); @@ -670,20 +670,20 @@ void hawk_xma_free (hawk_xma_t* xma, void* b) /* * Merge the block with surrounding blocks * - * blk + * blk * | * v * +------------+------------+------------+------------+ * | X | | Y | Z | * +------------+------------+------------+------------+ - * - * + * + * * +--------------------------------------+------------+ * | X | Z | * +--------------------------------------+------------+ * */ - + hawk_xma_mblk_t* z = next_mblk(y); hawk_oow_t ns = MBLKHDRSIZE + org_blk_size + MBLKHDRSIZE; hawk_oow_t bs = ns + y->size; @@ -713,8 +713,8 @@ void hawk_xma_free (hawk_xma_t* xma, void* b) * +------------+------------+------------+ * | | Y | Z | * +------------+------------+------------+ - * - * + * + * * * blk * | @@ -722,8 +722,8 @@ void hawk_xma_free (hawk_xma_t* xma, void* b) * +-------------------------+------------+ * | | Z | * +-------------------------+------------+ - * - * + * + * */ hawk_xma_mblk_t* z = next_mblk(y); @@ -748,7 +748,7 @@ void hawk_xma_free (hawk_xma_t* xma, void* b) else if ((hawk_uint8_t*)x >= xma->start && x->free) { /* - * Merge the block with the previous block + * Merge the block with the previous block * * blk * | @@ -791,7 +791,7 @@ void hawk_xma_free (hawk_xma_t* xma, void* b) void hawk_xma_dump (hawk_xma_t* xma, hawk_xma_dumper_t dumper, void* ctx) { hawk_xma_mblk_t* tmp; - hawk_oow_t fsum, asum; + hawk_oow_t fsum, asum; #if defined(HAWK_XMA_ENABLE_STAT) hawk_oow_t isum; #endif