found a critical bug. need to change the qse_awk_run() function
This commit is contained in:
		| @ -32,10 +32,21 @@ | |||||||
| #	include <errno.h> | #	include <errno.h> | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| static qse_awk_t* app_awk = NULL; |  | ||||||
| static qse_awk_run_t* app_run = NULL; | static qse_awk_run_t* app_run = NULL; | ||||||
| static int app_debug = 0; | 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, ...) | static void dprint (const qse_char_t* fmt, ...) | ||||||
| { | { | ||||||
| 	if (app_debug) | 	if (app_debug) | ||||||
| @ -100,11 +111,32 @@ static void unset_intr_run (void) | |||||||
| #endif | #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; | 	app_run = run; | ||||||
| 	set_intr_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")); | 	dprint (QSE_T("[AWK ABOUT TO START]\n")); | ||||||
|  |  | ||||||
|  | 	//return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static qse_map_walk_t print_awk_value ( | 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"));	 | 	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 int handle_args (int argc, qse_char_t* argv[], struct argout_t* ao) | ||||||
| { | { | ||||||
| 	static qse_opt_lng_t lng[] =  | 	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_char_t** icf = QSE_NULL; /* input console files */ | ||||||
|  |  | ||||||
| 	qse_map_t* vm = QSE_NULL;  /* global variable map */ | 	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); | 	isf = (qse_char_t**) malloc (QSE_SIZEOF(*isf) * isfc); | ||||||
| 	if (isf == QSE_NULL) | 	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'): | 			case QSE_T('F'): | ||||||
| 			{ | 			{ | ||||||
| 				qse_printf  (QSE_T("[field separator] = %s\n"), opt.arg); | 				fs = opt.arg; | ||||||
| 				break; | 				break; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| @ -497,6 +521,7 @@ static int handle_args (int argc, qse_char_t* argv[], struct argout_t* ao) | |||||||
| 	ao->icf = icf; | 	ao->icf = icf; | ||||||
| 	ao->icfl = icfl; | 	ao->icfl = icfl; | ||||||
| 	ao->vm = vm; | 	ao->vm = vm; | ||||||
|  | 	ao->fs = fs; | ||||||
|  |  | ||||||
| 	return 0; | 	return 0; | ||||||
|  |  | ||||||
| @ -547,8 +572,8 @@ static qse_awk_t* open_awk (void) | |||||||
| static int awk_main (int argc, qse_char_t* argv[]) | static int awk_main (int argc, qse_char_t* argv[]) | ||||||
| { | { | ||||||
| 	qse_awk_t* awk; | 	qse_awk_t* awk; | ||||||
|  |  | ||||||
| 	qse_awk_runcbs_t runcbs; | 	qse_awk_runcbs_t runcbs; | ||||||
| 	struct sigaction sa_int; |  | ||||||
|  |  | ||||||
| 	int i, file_count = 0; | 	int i, file_count = 0; | ||||||
| 	const qse_char_t* mfn = QSE_NULL; | 	const qse_char_t* mfn = QSE_NULL; | ||||||
| @ -575,7 +600,6 @@ static int awk_main (int argc, qse_char_t* argv[]) | |||||||
| 	awk = open_awk (); | 	awk = open_awk (); | ||||||
| 	if (awk == QSE_NULL) return -1; | 	if (awk == QSE_NULL) return -1; | ||||||
|  |  | ||||||
| 	app_awk = awk; |  | ||||||
|  |  | ||||||
| 	if (qse_awk_parsesimple (awk, ao.isp, ao.ist, ao.osf) == -1) | 	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; | 		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_start = on_run_start; | ||||||
| 	runcbs.on_statement = on_run_statement; | 	runcbs.on_statement = on_run_statement; | ||||||
| 	runcbs.on_return = on_run_return; | 	runcbs.on_return = on_run_return; | ||||||
| 	runcbs.on_end = on_run_end; | 	runcbs.on_end = on_run_end; | ||||||
| 	runcbs.data = QSE_NULL; | 	runcbs.data = &ao; | ||||||
|  |  | ||||||
| 	if (qse_awk_runsimple (awk, ao.icf, &runcbs) == -1) | 	if (qse_awk_runsimple (awk, ao.icf, &runcbs) == -1) | ||||||
| 	{ | 	{ | ||||||
|  | |||||||
| @ -917,6 +917,8 @@ qse_awk_val_t* qse_awk_getarg (qse_awk_run_t* run, qse_size_t idx); | |||||||
|  * RETURN |  * RETURN | ||||||
|  *  The pointer to a value is returned. This function never fails |  *  The pointer to a value is returned. This function never fails | ||||||
|  *  so long as id is valid. Otherwise, you may fall into trouble. |  *  so long as id is valid. Otherwise, you may fall into trouble. | ||||||
|  |  * | ||||||
|  |  * SYNOPSIS | ||||||
|  */ |  */ | ||||||
| qse_awk_val_t* qse_awk_getglobal ( | qse_awk_val_t* qse_awk_getglobal ( | ||||||
| 	qse_awk_run_t* run, | 	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 ( | int qse_awk_setglobal ( | ||||||
| 	qse_awk_run_t* run,  | 	qse_awk_run_t* run,  | ||||||
| 	int            id, | 	int            id, | ||||||
| 	qse_awk_val_t* val | 	qse_awk_val_t* val | ||||||
| ); | ); | ||||||
|  | /******/ | ||||||
|  |  | ||||||
| /****f* qse.awk/qse_awk_setretval | /****f* qse.awk/qse_awk_setretval | ||||||
|  * NAME |  * NAME | ||||||
|  | |||||||
| @ -314,3 +314,11 @@ | |||||||
|  |  | ||||||
| /* Version number of package */ | /* Version number of package */ | ||||||
| #undef VERSION | #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 | ||||||
|  | |||||||
| @ -265,12 +265,15 @@ static int set_global ( | |||||||
| { | { | ||||||
| 	qse_awk_val_t* old; | 	qse_awk_val_t* old; | ||||||
|         |         | ||||||
|  | qse_printf (QSE_T("################\n")); | ||||||
| 	old = STACK_GLOBAL (run, idx); | 	old = STACK_GLOBAL (run, idx); | ||||||
|  | qse_printf (QSE_T("@@@@@@@@@@@@@@@@@@@\n")); | ||||||
| 	if (old->type == QSE_AWK_VAL_MAP) | 	if (old->type == QSE_AWK_VAL_MAP) | ||||||
| 	{	 | 	{	 | ||||||
| 		/* once a variable becomes a map, | 		/* once a variable becomes a map, | ||||||
| 		 * it cannot be changed to a scalar variable */ | 		 * it cannot be changed to a scalar variable */ | ||||||
|  |  | ||||||
|  | qse_printf (QSE_T("%%%%%%%%%%%%%%%%%%%%\n")); | ||||||
| 		if (var != QSE_NULL) | 		if (var != QSE_NULL) | ||||||
| 		{ | 		{ | ||||||
| 			/* global variable */ | 			/* global variable */ | ||||||
| @ -347,13 +350,16 @@ static int set_global ( | |||||||
| 		qse_char_t* fs_ptr; | 		qse_char_t* fs_ptr; | ||||||
| 		qse_size_t fs_len; | 		qse_size_t fs_len; | ||||||
|  |  | ||||||
|  | 		qse_printf (QSE_T("aaaaaaaaaaaa\n")); | ||||||
| 		if (val->type == QSE_AWK_VAL_STR) | 		if (val->type == QSE_AWK_VAL_STR) | ||||||
| 		{ | 		{ | ||||||
|  | 		qse_printf (QSE_T("bbbbbbbbbbbbb\n")); | ||||||
| 			fs_ptr = ((qse_awk_val_str_t*)val)->ptr; | 			fs_ptr = ((qse_awk_val_str_t*)val)->ptr; | ||||||
| 			fs_len = ((qse_awk_val_str_t*)val)->len; | 			fs_len = ((qse_awk_val_str_t*)val)->len; | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| 		{ | 		{ | ||||||
|  | 		qse_printf (QSE_T("ccccccccccc\n")); | ||||||
| 			/* due to the expression evaluation rule, the  | 			/* due to the expression evaluation rule, the  | ||||||
| 			 * regular expression can not be an assigned value */ | 			 * regular expression can not be an assigned value */ | ||||||
| 			QSE_ASSERT (val->type != QSE_AWK_VAL_REX); | 			QSE_ASSERT (val->type != QSE_AWK_VAL_REX); | ||||||
| @ -367,6 +373,7 @@ static int set_global ( | |||||||
| 		{ | 		{ | ||||||
| 			void* rex; | 			void* rex; | ||||||
|  |  | ||||||
|  | 		qse_printf (QSE_T("dddddddddddddd\n")); | ||||||
| 			/* compile the regular expression */ | 			/* compile the regular expression */ | ||||||
| 			/* TODO: use safebuild */ | 			/* TODO: use safebuild */ | ||||||
| 			rex = QSE_AWK_BUILDREX ( | 			rex = QSE_AWK_BUILDREX ( | ||||||
| @ -383,9 +390,12 @@ static int set_global ( | |||||||
| 				QSE_AWK_FREEREX (run->awk, run->global.fs); | 				QSE_AWK_FREEREX (run->awk, run->global.fs); | ||||||
| 			} | 			} | ||||||
| 			run->global.fs = rex; | 			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); | 		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) | 	else if (idx == QSE_AWK_GLOBAL_IGNORECASE) | ||||||
| 	{ | 	{ | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user