From 5686bb8ac7ee3de984b191db16eb91519db06aa6 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 22 Jan 2009 04:37:55 +0000 Subject: [PATCH] found a critical bug. need to change the qse_awk_run() function --- qse/cmd/awk/awk.c | 67 +++++++++++++++++++++++-------------- qse/include/qse/awk/awk.h | 9 +++++ qse/include/qse/config.h.in | 8 +++++ qse/lib/awk/run.c | 10 ++++++ 4 files changed, 68 insertions(+), 26 deletions(-) diff --git a/qse/cmd/awk/awk.c b/qse/cmd/awk/awk.c index 4a1bb941..67a6eb82 100644 --- a/qse/cmd/awk/awk.c +++ b/qse/cmd/awk/awk.c @@ -32,10 +32,21 @@ # include #endif -static qse_awk_t* app_awk = NULL; static qse_awk_run_t* app_run = NULL; static int app_debug = 0; +struct argout_t +{ + void* isp; /* input source files or string */ + int ist; /* input source type */ + qse_size_t isfl; /* the number of input source files */ + qse_char_t* osf; /* output source file */ + qse_char_t** icf; /* input console files */ + qse_size_t icfl; /* the number of input console files */ + qse_map_t* vm; /* global variable map */ + qse_char_t* fs; /* field separator */ +}; + static void dprint (const qse_char_t* fmt, ...) { if (app_debug) @@ -100,11 +111,32 @@ static void unset_intr_run (void) #endif } -static void on_run_start (qse_awk_run_t* run, void* custom) +static void on_run_start (qse_awk_run_t* run, void* data) { + struct argout_t* ao = (struct argout_t*)data; + app_run = run; set_intr_run (); + + if (ao->fs != QSE_NULL) + { + qse_awk_val_t* fs; + + qse_printf (QSE_T("1111111111111111111\n")); + fs = qse_awk_makestrval0 (run, ao->fs); + qse_printf (QSE_T("2222222222222222222\n")); + //if (fs == QSE_NULL) return -1; + qse_awk_refupval (run, fs); + qse_printf (QSE_T("3333333333333333333\n")); + qse_awk_setglobal (run, QSE_AWK_GLOBAL_FS, fs); + qse_printf (QSE_T("4444444444444444444\n")); + qse_awk_refdownval (run, fs); + qse_printf (QSE_T("555555555555555555555555\n")); + } + dprint (QSE_T("[AWK ABOUT TO START]\n")); + + //return 0; } static qse_map_walk_t print_awk_value ( @@ -268,17 +300,6 @@ static void out_of_memory (void) qse_fprintf (QSE_STDERR, QSE_T("Error: out of memory\n")); } -struct argout_t -{ - void* isp; /* input source files or string */ - int ist; /* input source type */ - qse_size_t isfl; /* the number of input source files */ - qse_char_t* osf; /* output source file */ - qse_char_t** icf; /* input console files */ - qse_size_t icfl; /* the number of input console files */ - qse_map_t* vm; /* global variable map */ -}; - static int handle_args (int argc, qse_char_t* argv[], struct argout_t* ao) { static qse_opt_lng_t lng[] = @@ -327,6 +348,9 @@ static int handle_args (int argc, qse_char_t* argv[], struct argout_t* ao) qse_char_t** icf = QSE_NULL; /* input console files */ qse_map_t* vm = QSE_NULL; /* global variable map */ + qse_char_t* fs = QSE_NULL; /* field separator */ + + memset (ao, 0, QSE_SIZEOF(*ao)); isf = (qse_char_t**) malloc (QSE_SIZEOF(*isf) * isfc); if (isf == QSE_NULL) @@ -388,7 +412,7 @@ static int handle_args (int argc, qse_char_t* argv[], struct argout_t* ao) case QSE_T('F'): { - qse_printf (QSE_T("[field separator] = %s\n"), opt.arg); + fs = opt.arg; break; } @@ -497,6 +521,7 @@ static int handle_args (int argc, qse_char_t* argv[], struct argout_t* ao) ao->icf = icf; ao->icfl = icfl; ao->vm = vm; + ao->fs = fs; return 0; @@ -547,8 +572,8 @@ static qse_awk_t* open_awk (void) static int awk_main (int argc, qse_char_t* argv[]) { qse_awk_t* awk; + qse_awk_runcbs_t runcbs; - struct sigaction sa_int; int i, file_count = 0; const qse_char_t* mfn = QSE_NULL; @@ -575,7 +600,6 @@ static int awk_main (int argc, qse_char_t* argv[]) awk = open_awk (); if (awk == QSE_NULL) return -1; - app_awk = awk; if (qse_awk_parsesimple (awk, ao.isp, ao.ist, ao.osf) == -1) { @@ -590,20 +614,11 @@ static int awk_main (int argc, qse_char_t* argv[]) goto oops; } -#ifdef _WIN32 - SetConsoleCtrlHandler (stop_run, TRUE); -#else - sa_int.sa_handler = stop_run; - sigemptyset (&sa_int.sa_mask); - sa_int.sa_flags = 0; - sigaction (SIGINT, &sa_int, NULL); -#endif - runcbs.on_start = on_run_start; runcbs.on_statement = on_run_statement; runcbs.on_return = on_run_return; runcbs.on_end = on_run_end; - runcbs.data = QSE_NULL; + runcbs.data = &ao; if (qse_awk_runsimple (awk, ao.icf, &runcbs) == -1) { diff --git a/qse/include/qse/awk/awk.h b/qse/include/qse/awk/awk.h index 3644b619..ff9b2ddb 100644 --- a/qse/include/qse/awk/awk.h +++ b/qse/include/qse/awk/awk.h @@ -917,6 +917,8 @@ qse_awk_val_t* qse_awk_getarg (qse_awk_run_t* run, qse_size_t idx); * RETURN * The pointer to a value is returned. This function never fails * so long as id is valid. Otherwise, you may fall into trouble. + * + * SYNOPSIS */ qse_awk_val_t* qse_awk_getglobal ( qse_awk_run_t* run, @@ -924,11 +926,18 @@ qse_awk_val_t* qse_awk_getglobal ( ); /******/ +/****f* qse.awk/qse_awk_setglobal + * NAME + * qse_awk_setglobal - set the value of a global variable + * + * SYNOPSIS + */ int qse_awk_setglobal ( qse_awk_run_t* run, int id, qse_awk_val_t* val ); +/******/ /****f* qse.awk/qse_awk_setretval * NAME diff --git a/qse/include/qse/config.h.in b/qse/include/qse/config.h.in index 9ae7a9a2..def81655 100644 --- a/qse/include/qse/config.h.in +++ b/qse/include/qse/config.h.in @@ -314,3 +314,11 @@ /* Version number of package */ #undef VERSION + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ +#if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +#elif ! defined __LITTLE_ENDIAN__ +# undef WORDS_BIGENDIAN +#endif diff --git a/qse/lib/awk/run.c b/qse/lib/awk/run.c index 8bcace03..8f47e394 100644 --- a/qse/lib/awk/run.c +++ b/qse/lib/awk/run.c @@ -265,12 +265,15 @@ static int set_global ( { qse_awk_val_t* old; +qse_printf (QSE_T("################\n")); old = STACK_GLOBAL (run, idx); +qse_printf (QSE_T("@@@@@@@@@@@@@@@@@@@\n")); if (old->type == QSE_AWK_VAL_MAP) { /* once a variable becomes a map, * it cannot be changed to a scalar variable */ +qse_printf (QSE_T("%%%%%%%%%%%%%%%%%%%%\n")); if (var != QSE_NULL) { /* global variable */ @@ -347,13 +350,16 @@ static int set_global ( qse_char_t* fs_ptr; qse_size_t fs_len; + qse_printf (QSE_T("aaaaaaaaaaaa\n")); if (val->type == QSE_AWK_VAL_STR) { + qse_printf (QSE_T("bbbbbbbbbbbbb\n")); fs_ptr = ((qse_awk_val_str_t*)val)->ptr; fs_len = ((qse_awk_val_str_t*)val)->len; } else { + qse_printf (QSE_T("ccccccccccc\n")); /* due to the expression evaluation rule, the * regular expression can not be an assigned value */ QSE_ASSERT (val->type != QSE_AWK_VAL_REX); @@ -367,6 +373,7 @@ static int set_global ( { void* rex; + qse_printf (QSE_T("dddddddddddddd\n")); /* compile the regular expression */ /* TODO: use safebuild */ rex = QSE_AWK_BUILDREX ( @@ -383,9 +390,12 @@ static int set_global ( QSE_AWK_FREEREX (run->awk, run->global.fs); } run->global.fs = rex; + qse_printf (QSE_T("eeeeeeeeeeeeee\n")); } + qse_printf (QSE_T("fffffffffffff\n")); if (val->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (run->awk, fs_ptr); + qse_printf (QSE_T("ggggggggggggg\n")); } else if (idx == QSE_AWK_GLOBAL_IGNORECASE) {