diff --git a/qse/cmd/awk/awk.c b/qse/cmd/awk/awk.c index a7a226fd..bb633ce8 100644 --- a/qse/cmd/awk/awk.c +++ b/qse/cmd/awk/awk.c @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -50,7 +51,7 @@ static int app_debug = 0; struct argout_t { - qse_awk_parsesimple_type_t ist; /* input source type */ + qse_awk_parsestd_type_t ist; /* input source type */ union { const qse_char_t* str; @@ -58,7 +59,7 @@ struct argout_t } isp; qse_size_t isfl; /* the number of input source files */ - qse_awk_parsesimple_type_t ost; /* output source type */ + qse_awk_parsestd_type_t ost; /* output source type */ qse_char_t* osf; /* output source file */ @@ -495,14 +496,14 @@ static int handle_args (int argc, qse_char_t* argv[], struct argout_t* ao) } /* the source code is the string, not from the file */ - ao->ist = QSE_AWK_PARSESIMPLE_STR; + ao->ist = QSE_AWK_PARSESTD_CP; ao->isp.str = argv[opt.ind++]; free (isf); } else { - ao->ist = QSE_AWK_PARSESIMPLE_FILE; + ao->ist = QSE_AWK_PARSESTD_FILE; ao->isp.files = isf; } @@ -527,7 +528,7 @@ static int handle_args (int argc, qse_char_t* argv[], struct argout_t* ao) } icf[icfl] = QSE_NULL; - ao->ost = QSE_AWK_PARSESIMPLE_FILE; + ao->ost = QSE_AWK_PARSESTD_FILE; ao->osf = osf; ao->icf = icf; @@ -548,7 +549,7 @@ static qse_awk_t* open_awk (void) { qse_awk_t* awk; - awk = qse_awk_opensimple (); + awk = qse_awk_openstd (); if (awk == QSE_NULL) { qse_printf (QSE_T("ERROR: cannot open awk\n")); @@ -610,11 +611,11 @@ static int awk_main (int argc, qse_char_t* argv[]) if (awk == QSE_NULL) return -1; /* TODO: change it to support multiple source files */ - qse_awk_parsesimple_in_t psin; - qse_awk_parsesimple_out_t psout; + qse_awk_parsestd_in_t psin; + qse_awk_parsestd_out_t psout; psin.type = ao.ist; - if (ao.ist == QSE_AWK_PARSESIMPLE_STR) psin.u.str = ao.isp.str; + if (ao.ist == QSE_AWK_PARSESTD_CP) psin.u.cp = ao.isp.str; else psin.u.file = ao.isp.files[0]; if (ao.osf != QSE_NULL) @@ -623,7 +624,7 @@ static int awk_main (int argc, qse_char_t* argv[]) psout.u.file = ao.osf; } - if (qse_awk_parsesimple (awk, &psin, + if (qse_awk_parsestd (awk, &psin, ((ao.osf == QSE_NULL)? QSE_NULL: &psout)) == -1) { qse_printf ( @@ -642,8 +643,8 @@ static int awk_main (int argc, qse_char_t* argv[]) rcb.on_exit = on_run_exit; rcb.data = &ao; - rtx = qse_awk_rtx_opensimple ( - awk, ao.icf, QSE_AWK_RTX_OPENSIMPLE_STDIO); + rtx = qse_awk_rtx_openstd ( + awk, ao.icf, QSE_AWK_RTX_OPENSTD_STDIO); if (rtx == QSE_NULL) { qse_printf ( @@ -680,7 +681,7 @@ static int awk_main (int argc, qse_char_t* argv[]) oops: qse_awk_close (awk); - if (ao.ist == QSE_AWK_PARSESIMPLE_FILE && + if (ao.ist == QSE_AWK_PARSESTD_FILE && ao.isp.files != QSE_NULL) free (ao.isp.files); /*if (ao.osf != QSE_NULL) free (ao.osf);*/ if (ao.icf != QSE_NULL) free (ao.icf); diff --git a/qse/include/qse/awk/Awk.hpp b/qse/include/qse/awk/Awk.hpp index c7290865..471300d2 100644 --- a/qse/include/qse/awk/Awk.hpp +++ b/qse/include/qse/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp 468 2008-12-10 10:19:59Z baconevi $ + * $Id: Awk.hpp 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/awk/Makefile.am b/qse/include/qse/awk/Makefile.am index ab194462..4ab76ada 100644 --- a/qse/include/qse/awk/Makefile.am +++ b/qse/include/qse/awk/Makefile.am @@ -1,5 +1,5 @@ -pkginclude_HEADERS = awk.h +pkginclude_HEADERS = awk.h std.h if ENABLE_CXX pkginclude_HEADERS += Awk.hpp StdAwk.hpp diff --git a/qse/include/qse/awk/Makefile.in b/qse/include/qse/awk/Makefile.in index e41de781..191c1c3e 100644 --- a/qse/include/qse/awk/Makefile.in +++ b/qse/include/qse/awk/Makefile.in @@ -44,7 +44,7 @@ CONFIG_HEADER = $(top_builddir)/include/qse/config.h CONFIG_CLEAN_FILES = SOURCES = DIST_SOURCES = -am__pkginclude_HEADERS_DIST = awk.h Awk.hpp StdAwk.hpp +am__pkginclude_HEADERS_DIST = awk.h std.h Awk.hpp StdAwk.hpp am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -179,7 +179,7 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -pkginclude_HEADERS = awk.h $(am__append_1) +pkginclude_HEADERS = awk.h std.h $(am__append_1) CLEANFILES = *dist all: all-am diff --git a/qse/include/qse/awk/StdAwk.hpp b/qse/include/qse/awk/StdAwk.hpp index 6689d179..44f5e7a7 100644 --- a/qse/include/qse/awk/StdAwk.hpp +++ b/qse/include/qse/awk/StdAwk.hpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.hpp 499 2008-12-16 09:42:48Z baconevi $ + * $Id: StdAwk.hpp 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/awk/awk.h b/qse/include/qse/awk/awk.h index 528c4942..782d9839 100644 --- a/qse/include/qse/awk/awk.h +++ b/qse/include/qse/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h 501 2008-12-17 08:39:15Z baconevi $ + * $Id: awk.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -556,11 +556,31 @@ enum qse_awk_val_ref_id_t enum qse_awk_rtx_valtostr_opt_t { - QSE_AWK_VALTOSTR_CLEAR = (1 << 0), - QSE_AWK_VALTOSTR_FIXED = (1 << 1), /* this overrides CLEAR */ - QSE_AWK_VALTOSTR_PRINT = (1 << 2) + QSE_AWK_RTX_VALTOSTR_CLEAR = (1 << 0), + QSE_AWK_RTX_VALTOSTR_FIXED = (1 << 1), /* this overrides CLEAR */ + QSE_AWK_RTX_VALTOSTR_PRINT = (1 << 2) }; +#if 0 +/* TODO: change qse_awk_valtostr() according to the following structure... */ +struct qse_awk_valtostr_out_t +{ + enum + { + QSE_AWK_RTX_VALTOSTR_CP + QSE_AWK_RTX_VALTOSTR_CPL + QSE_AWK_RTX_VALTOSTR_STRP + } type; + + union + { + qse_char_t* cp; + qse_xstr_t cpl; + qse_str_t* strp; + } u; +}; +typedef struct qse_awk_valtostr_out_t qse_awk_valtostr_out_t; +#endif typedef struct qse_awk_val_nil_t qse_awk_val_nil_t; typedef struct qse_awk_val_int_t qse_awk_val_int_t; @@ -653,63 +673,6 @@ struct qse_awk_val_ref_t qse_awk_val_t** adr; }; -/****e* AWK/qse_awk_parsesimple_type_t - * NAME - * qse_awk_parsesimple_type_t - define a source type - * SYNOPSIS - */ -enum qse_awk_parsesimple_type_t -{ - QSE_AWK_PARSESIMPLE_FILE = 0, - QSE_AWK_PARSESIMPLE_STR = 1, - QSE_AWK_PARSESIMPLE_STRL = 2, - QSE_AWK_PARSESIMPLE_STDIO = 3 -}; -typedef enum qse_awk_parsesimple_type_t qse_awk_parsesimple_type_t; -/******/ - - -/****s* AWK/qse_awk_parsesimple_in_t - * NAME - * qse_awk_parsesimple_in_t - define source input - * SYNOPSIS - */ -struct qse_awk_parsesimple_in_t -{ - qse_awk_parsesimple_type_t type; - - union - { - const qse_char_t* file; - const qse_char_t* str; - qse_cstr_t strl; - } u; -}; -typedef struct qse_awk_parsesimple_in_t qse_awk_parsesimple_in_t; -/******/ - -/****s* AWK/qse_awk_parsesimple_out_t - * NAME - * qse_awk_parsesimple_out_t - define source output - * SYNOPSIS - */ -struct qse_awk_parsesimple_out_t -{ - qse_awk_parsesimple_type_t type; - - union - { - const qse_char_t* file; - qse_char_t* str; - qse_xstr_t strl; - } u; -}; -typedef struct qse_awk_parsesimple_out_t qse_awk_parsesimple_out_t; -/******/ - -#define QSE_AWK_RTX_OPENSIMPLE_STDIO (qse_awk_rtx_opensimple_stdio) -extern const qse_char_t* qse_awk_rtx_opensimple_stdio[]; - #ifdef __cplusplus extern "C" { #endif @@ -1221,13 +1184,15 @@ int qse_awk_rtx_loop ( * rtx = qse_awk_rtx_open (awk, rio, rcb, QSE_NULL, QSE_NULL); * if (rtx != QSE_NULL) * { - * qse_awk_rtx_call (rtx, QSE_T("init"), QSE_NULL, 0); + * v = qse_awk_rtx_call (rtx, QSE_T("init"), QSE_NULL, 0); + * if (v != QSE_NULL) qse_awk_rtx_refdownval (rtx, v); * qse_awk_rtx_call (rtx, QSE_T("fini"), QSE_NULL, 0); + * if (v != QSE_NULL) qse_awk_rtx_refdownval (rtx, v); * qse_awk_rtx_close (rtx); * } * SYNOPSIS */ -int qse_awk_rtx_call ( +qse_awk_val_t* qse_awk_rtx_call ( qse_awk_rtx_t* rtx, const qse_char_t* name, qse_awk_val_t** args, @@ -1469,7 +1434,6 @@ void qse_awk_rtx_seterror ( const qse_cstr_t* errarg ); - /* record and field functions */ int qse_awk_rtx_clrrec ( qse_awk_rtx_t* rtx, @@ -1540,12 +1504,6 @@ qse_bool_t qse_awk_rtx_isstaticval ( qse_awk_val_t* val ); -void qse_awk_rtx_freeval ( - qse_awk_rtx_t* rtx, - qse_awk_val_t* val, - qse_bool_t cache -); - void qse_awk_rtx_refupval ( qse_awk_rtx_t* rtx, qse_awk_val_t* val @@ -1619,61 +1577,6 @@ int qse_awk_rtx_strtonum ( ); /******/ -/****f* AWK/qse_awk_opensimple - * NAME - * qse_awk_opensimple - create an awk object - * SYNOPSIS - */ -qse_awk_t* qse_awk_opensimple ( - void -); -/******/ - -/****f* AWK/qse_awk_parsesimple - * NAME - * qse_awk_parsesimple - parse source code - * EXAMPLE - * The following example parses the literal string 'BEGIN { print 10; }' and - * deparses it out to a buffer 'buf'. - * int n; - * qse_awk_parsesimple_in_t in; - * qse_awk_parsesimple_out_t out; - * qse_char_t buf[1000]; - * - * qse_memset (buf, QSE_T(' '), QSE_COUNTOF(buf)); - * buf[QSE_COUNTOF(buf)-1] = QSE_T('\0'); - * in.type = QSE_AWK_PARSESIMPLE_STR; - * in.u.str = QSE_T("BEGIN { print 10; }"); - * out.type = QSE_AWK_PARSESIMPLE_STR; - * out.u.str = buf; - * - * n = qse_awk_parsesimple (awk, &in, &out); - * SYNOPSIS - */ -int qse_awk_parsesimple ( - qse_awk_t* awk, - const qse_awk_parsesimple_in_t* in, - qse_awk_parsesimple_out_t* out -); -/******/ - -/****f* AWK/qse_awk_rtx_opensimple - * NAME - * qse_awk_rtx_opensimple - create a runtime context - * DESCRIPTION - * The caller should keep the contents of icf and ocf valid throughout - * the lifetime of the runtime context created. The runtime context - * remembers the pointers without copying in the contents. - * - * SYNOPSIS - */ -qse_awk_rtx_t* qse_awk_rtx_opensimple ( - qse_awk_t* awk, - const qse_char_t*const* icf, - const qse_char_t*const* ocf -); -/******/ - #ifdef __cplusplus } #endif diff --git a/qse/include/qse/awk/std.h b/qse/include/qse/awk/std.h new file mode 100644 index 00000000..3084c08e --- /dev/null +++ b/qse/include/qse/awk/std.h @@ -0,0 +1,146 @@ +/* + * $Id: std.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ + * + Copyright 2006-2009 Chung, Hyung-Hwan. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#ifndef _QSE_AWK_STD_H_ +#define _QSE_AWK_STD_H_ + +#include + +/****e* AWK/qse_awk_parsestd_type_t + * NAME + * qse_awk_parsestd_type_t - define a source type + * SYNOPSIS + */ +enum qse_awk_parsestd_type_t +{ + QSE_AWK_PARSESTD_FILE = 0, /* file name */ + QSE_AWK_PARSESTD_CP = 1, /* character pointer */ + QSE_AWK_PARSESTD_CPL = 2, /* character pointer + length */ + QSE_AWK_PARSESTD_STDIO = 3 /* standard input/output */ +}; +typedef enum qse_awk_parsestd_type_t qse_awk_parsestd_type_t; +/******/ + + +/****s* AWK/qse_awk_parsestd_in_t + * NAME + * qse_awk_parsestd_in_t - define source input + * SYNOPSIS + */ +struct qse_awk_parsestd_in_t +{ + qse_awk_parsestd_type_t type; + + union + { + const qse_char_t* file; + const qse_char_t* cp; + qse_cstr_t cpl; + } u; +}; +typedef struct qse_awk_parsestd_in_t qse_awk_parsestd_in_t; +/******/ + +/****s* AWK/qse_awk_parsestd_out_t + * NAME + * qse_awk_parsestd_out_t - define source output + * SYNOPSIS + */ +struct qse_awk_parsestd_out_t +{ + qse_awk_parsestd_type_t type; + + union + { + const qse_char_t* file; + qse_char_t* cp; + qse_xstr_t cpl; + } u; +}; +typedef struct qse_awk_parsestd_out_t qse_awk_parsestd_out_t; +/******/ + +#define QSE_AWK_RTX_OPENSTD_STDIO (qse_awk_rtx_openstd_stdio) +extern const qse_char_t* qse_awk_rtx_openstd_stdio[]; + + +#ifdef __cplusplus +extern "C" { +#endif + +/****f* AWK/qse_awk_openstd + * NAME + * qse_awk_openstd - create an awk object + * SYNOPSIS + */ +qse_awk_t* qse_awk_openstd ( + void +); +/******/ + +/****f* AWK/qse_awk_parsestd + * NAME + * qse_awk_parsestd - parse source code + * EXAMPLE + * The following example parses the literal string 'BEGIN { print 10; }' and + * deparses it out to a buffer 'buf'. + * int n; + * qse_awk_parsestd_in_t in; + * qse_awk_parsestd_out_t out; + * qse_char_t buf[1000]; + * + * qse_memset (buf, QSE_T(' '), QSE_COUNTOF(buf)); + * buf[QSE_COUNTOF(buf)-1] = QSE_T('\0'); + * in.type = QSE_AWK_PARSESTD_CP; + * in.u.cp = QSE_T("BEGIN { print 10; }"); + * out.type = QSE_AWK_PARSESTD_CP; + * out.u.cp = buf; + * + * n = qse_awk_parsestd (awk, &in, &out); + * SYNOPSIS + */ +int qse_awk_parsestd ( + qse_awk_t* awk, + const qse_awk_parsestd_in_t* in, + qse_awk_parsestd_out_t* out +); +/******/ + +/****f* AWK/qse_awk_rtx_openstd + * NAME + * qse_awk_rtx_openstd - create a runtime context + * DESCRIPTION + * The caller should keep the contents of icf and ocf valid throughout + * the lifetime of the runtime context created. The runtime context + * remembers the pointers without copying in the contents. + * + * SYNOPSIS + */ +qse_awk_rtx_t* qse_awk_rtx_openstd ( + qse_awk_t* awk, + const qse_char_t*const* icf, + const qse_char_t*const* ocf +); +/******/ + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/qse/include/qse/cmn/chr.h b/qse/include/qse/cmn/chr.h index eff1d8ac..ed691916 100644 --- a/qse/include/qse/cmn/chr.h +++ b/qse/include/qse/cmn/chr.h @@ -1,5 +1,5 @@ /* - * $Id: ctype.h 223 2008-06-26 06:44:41Z baconevi $ + * $Id: chr.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/dll.h b/qse/include/qse/cmn/dll.h index cde881ce..b2b750f8 100644 --- a/qse/include/qse/cmn/dll.h +++ b/qse/include/qse/cmn/dll.h @@ -1,5 +1,5 @@ /* - * $Id: map.h 223 2008-06-26 06:44:41Z baconevi $ + * $Id: dll.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/fio.h b/qse/include/qse/cmn/fio.h index 66c93b72..83e0094a 100644 --- a/qse/include/qse/cmn/fio.h +++ b/qse/include/qse/cmn/fio.h @@ -1,5 +1,5 @@ /* - * $Id$ + * $Id: fio.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/lda.h b/qse/include/qse/cmn/lda.h index defb269f..46d28a44 100644 --- a/qse/include/qse/cmn/lda.h +++ b/qse/include/qse/cmn/lda.h @@ -1,5 +1,5 @@ /* - * $Id: lda.h 363 2008-09-04 10:58:08Z baconevi $ + * $Id: lda.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/map.h b/qse/include/qse/cmn/map.h index ae0f84a6..22693726 100644 --- a/qse/include/qse/cmn/map.h +++ b/qse/include/qse/cmn/map.h @@ -1,5 +1,5 @@ /* - * $Id: map.h 496 2008-12-15 09:56:48Z baconevi $ + * $Id: map.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/mem.h b/qse/include/qse/cmn/mem.h index 32d8ecf1..eda9225d 100644 --- a/qse/include/qse/cmn/mem.h +++ b/qse/include/qse/cmn/mem.h @@ -1,5 +1,5 @@ /* - * $Id: mem.h 337 2008-08-20 09:17:25Z baconevi $ + * $Id: mem.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/opt.h b/qse/include/qse/cmn/opt.h index 2ecfaf3a..ba6af828 100644 --- a/qse/include/qse/cmn/opt.h +++ b/qse/include/qse/cmn/opt.h @@ -1,5 +1,5 @@ /* - * $Id: getopt.h 290 2008-07-27 06:16:54Z baconevi $ + * $Id: opt.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/pio.h b/qse/include/qse/cmn/pio.h index 11fc9217..3f8ff3b9 100644 --- a/qse/include/qse/cmn/pio.h +++ b/qse/include/qse/cmn/pio.h @@ -1,5 +1,5 @@ /* - * $Id$ + * $Id: pio.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/rex.h b/qse/include/qse/cmn/rex.h index b574a6be..a82b2f5d 100644 --- a/qse/include/qse/cmn/rex.h +++ b/qse/include/qse/cmn/rex.h @@ -1,5 +1,5 @@ /* - * $Id: rex.h 223 2008-06-26 06:44:41Z baconevi $ + * $Id: rex.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/sio.h b/qse/include/qse/cmn/sio.h index 31b89ede..c803d155 100644 --- a/qse/include/qse/cmn/sio.h +++ b/qse/include/qse/cmn/sio.h @@ -1,5 +1,5 @@ /* - * $Id: sio.h,v 1.29 2005/12/26 05:38:24 bacon Ease $ + * $Id: sio.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/sll.h b/qse/include/qse/cmn/sll.h index 80f3eafa..9b066be1 100644 --- a/qse/include/qse/cmn/sll.h +++ b/qse/include/qse/cmn/sll.h @@ -1,5 +1,5 @@ /* - * $Id: sll.h 223 2008-06-26 06:44:41Z baconevi $ + * $Id: sll.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/str.h b/qse/include/qse/cmn/str.h index a02ff15a..83cb81fc 100644 --- a/qse/include/qse/cmn/str.h +++ b/qse/include/qse/cmn/str.h @@ -1,5 +1,5 @@ /* - * $Id: str.h 496 2008-12-15 09:56:48Z baconevi $ + * $Id: str.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/time.h b/qse/include/qse/cmn/time.h index dc2ad8dc..29e60011 100644 --- a/qse/include/qse/cmn/time.h +++ b/qse/include/qse/cmn/time.h @@ -1,5 +1,5 @@ /* - * $Id$ + * $Id: time.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/cmn/tio.h b/qse/include/qse/cmn/tio.h index 53a50dba..9a06681b 100644 --- a/qse/include/qse/cmn/tio.h +++ b/qse/include/qse/cmn/tio.h @@ -1,5 +1,5 @@ /* - * $Id: tio.h,v 1.19 2006/01/01 13:50:24 bacon Exp $ + * $Id: tio.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/conf_msw.h b/qse/include/qse/conf_msw.h index b6e76be7..4771278d 100644 --- a/qse/include/qse/conf_msw.h +++ b/qse/include/qse/conf_msw.h @@ -1,5 +1,5 @@ /* - * $Id: conf_msw.h 225 2008-06-26 06:48:38Z baconevi $ + * $Id: conf_msw.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * * {License} */ diff --git a/qse/include/qse/conf_vms.h b/qse/include/qse/conf_vms.h index f81b9f29..51e29a3d 100644 --- a/qse/include/qse/conf_vms.h +++ b/qse/include/qse/conf_vms.h @@ -1,5 +1,5 @@ /* - * $Id: conf_vms.h 225 2008-06-26 06:48:38Z baconevi $ + * $Id: conf_vms.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * * {License} */ diff --git a/qse/include/qse/macros.h b/qse/include/qse/macros.h index 5e9e7fed..b4d4d9e6 100644 --- a/qse/include/qse/macros.h +++ b/qse/include/qse/macros.h @@ -1,5 +1,5 @@ /* - * $Id: macros.h 455 2008-11-26 09:05:00Z baconevi $ + * $Id: macros.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/pack1.h b/qse/include/qse/pack1.h index 65266b13..1bd93110 100644 --- a/qse/include/qse/pack1.h +++ b/qse/include/qse/pack1.h @@ -1,5 +1,5 @@ /* - * $Id: pack1.h 225 2008-06-26 06:48:38Z baconevi $ + * $Id: pack1.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/pack2.h b/qse/include/qse/pack2.h index c61fdc97..790ed4a4 100644 --- a/qse/include/qse/pack2.h +++ b/qse/include/qse/pack2.h @@ -1,5 +1,5 @@ /* - * $Id: pack2.h 225 2008-06-26 06:48:38Z baconevi $ + * $Id: pack2.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/types.h b/qse/include/qse/types.h index d6f840a2..a447a5db 100644 --- a/qse/include/qse/types.h +++ b/qse/include/qse/types.h @@ -1,5 +1,5 @@ /* - * $Id: types.h 476 2008-12-12 06:25:48Z baconevi $ + * $Id: types.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/include/qse/unpack.h b/qse/include/qse/unpack.h index 0671ebdd..2f3088e0 100644 --- a/qse/include/qse/unpack.h +++ b/qse/include/qse/unpack.h @@ -1,5 +1,5 @@ /* - * $Id: unpack.h 225 2008-06-26 06:48:38Z baconevi $ + * $Id: unpack.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/Awk.cpp b/qse/lib/awk/Awk.cpp index 40d1dcc7..ca5b5224 100644 --- a/qse/lib/awk/Awk.cpp +++ b/qse/lib/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp 496 2008-12-15 09:56:48Z baconevi $ + * $Id: Awk.cpp 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/StdAwk.cpp b/qse/lib/awk/StdAwk.cpp index 7fb14856..5fde041c 100644 --- a/qse/lib/awk/StdAwk.cpp +++ b/qse/lib/awk/StdAwk.cpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.cpp 501 2008-12-17 08:39:15Z baconevi $ + * $Id: StdAwk.cpp 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/awk.c b/qse/lib/awk/awk.c index b734a5c4..0220251f 100644 --- a/qse/lib/awk/awk.c +++ b/qse/lib/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c 501 2008-12-17 08:39:15Z baconevi $ + * $Id: awk.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/awk.h b/qse/lib/awk/awk.h index 117448d6..c58b75cc 100644 --- a/qse/lib/awk/awk.h +++ b/qse/lib/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk_i.h 332 2008-08-18 11:21:48Z baconevi $ + * $Id: awk.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/err.c b/qse/lib/awk/err.c index 70a456d7..87cdd622 100644 --- a/qse/lib/awk/err.c +++ b/qse/lib/awk/err.c @@ -1,5 +1,5 @@ /* - * $Id: err.c 337 2008-08-20 09:17:25Z baconevi $ + * $Id: err.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/fnc.c b/qse/lib/awk/fnc.c index da8d521b..13b422c9 100644 --- a/qse/lib/awk/fnc.c +++ b/qse/lib/awk/fnc.c @@ -1,5 +1,5 @@ /* - * $Id: func.c 499 2008-12-16 09:42:48Z baconevi $ + * $Id: fnc.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -250,7 +250,7 @@ static int fnc_close ( else { name = qse_awk_rtx_valtostr ( - run, a0, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, a0, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (name == QSE_NULL) return -1; } @@ -364,7 +364,7 @@ static int fnc_fflush ( else { str0 = qse_awk_rtx_valtostr ( - run, a0, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len0); + run, a0, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len0); if (str0 == QSE_NULL) return -1; } @@ -437,7 +437,7 @@ static int fnc_index ( else { str0 = qse_awk_rtx_valtostr ( - run, a0, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len0); + run, a0, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len0); if (str0 == QSE_NULL) return -1; } @@ -449,7 +449,7 @@ static int fnc_index ( else { str1 = qse_awk_rtx_valtostr ( - run, a1, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len1); + run, a1, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len1); if (str1 == QSE_NULL) { if (a0->type != QSE_AWK_VAL_STR) @@ -494,7 +494,7 @@ static int fnc_length ( else { str = qse_awk_rtx_valtostr ( - run, v, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, v, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (str == QSE_NULL) return -1; QSE_AWK_FREE (run->awk, str); } @@ -536,7 +536,7 @@ static int fnc_substr ( else { str = qse_awk_rtx_valtostr ( - run, a0, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, a0, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (str == QSE_NULL) return -1; } @@ -642,7 +642,7 @@ static int fnc_split ( else { str = qse_awk_rtx_valtostr ( - run, a0, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &str_len); + run, a0, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &str_len); if (str == QSE_NULL) return -1; str_free = str; } @@ -666,7 +666,7 @@ static int fnc_split ( else { fs_ptr = qse_awk_rtx_valtostr ( - run, t1, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &fs_len); + run, t1, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &fs_len); if (fs_ptr == QSE_NULL) { if (str_free != QSE_NULL) @@ -693,7 +693,7 @@ static int fnc_split ( else { fs_ptr = qse_awk_rtx_valtostr ( - run, a2, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &fs_len); + run, a2, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &fs_len); if (fs_ptr == QSE_NULL) { if (str_free != QSE_NULL) @@ -861,7 +861,7 @@ static int fnc_tolower ( else { str = qse_awk_rtx_valtostr ( - run, a0, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, a0, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (str == QSE_NULL) return -1; } @@ -901,7 +901,7 @@ static int fnc_toupper ( else { str = qse_awk_rtx_valtostr ( - run, a0, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, a0, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (str == QSE_NULL) return -1; } @@ -968,7 +968,7 @@ static int __substitute (qse_awk_rtx_t* run, qse_long_t max_count) else { a0_ptr = qse_awk_rtx_valtostr ( - run, a0, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &a0_len); + run, a0, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &a0_len); if (a0_ptr == QSE_NULL) { FREE_A_PTRS (run->awk); @@ -985,7 +985,7 @@ static int __substitute (qse_awk_rtx_t* run, qse_long_t max_count) else { a1_ptr = qse_awk_rtx_valtostr ( - run, a1, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &a1_len); + run, a1, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &a1_len); if (a1_ptr == QSE_NULL) { FREE_A_PTRS (run->awk); @@ -1041,7 +1041,7 @@ static int __substitute (qse_awk_rtx_t* run, qse_long_t max_count) else { a2_ptr = qse_awk_rtx_valtostr ( - run, *a2_ref, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &a2_len); + run, *a2_ref, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &a2_len); if (a2_ptr == QSE_NULL) { FREE_A_PTRS (run->awk); @@ -1250,7 +1250,7 @@ static int fnc_match ( else { str0 = qse_awk_rtx_valtostr ( - run, a0, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len0); + run, a0, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len0); if (str0 == QSE_NULL) return -1; } @@ -1268,7 +1268,7 @@ static int fnc_match ( else { str1 = qse_awk_rtx_valtostr ( - run, a1, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len1); + run, a1, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len1); if (str1 == QSE_NULL) { if (a0->type != QSE_AWK_VAL_STR) @@ -1374,7 +1374,7 @@ static int fnc_sprintf ( else { cs0.ptr = qse_awk_rtx_valtostr ( - run, a0, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &cs0.len); + run, a0, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &cs0.len); if (cs0.ptr == QSE_NULL) { qse_str_fini (&fbu); diff --git a/qse/lib/awk/fnc.h b/qse/lib/awk/fnc.h index 27a707f4..73f29a28 100644 --- a/qse/lib/awk/fnc.h +++ b/qse/lib/awk/fnc.h @@ -1,5 +1,5 @@ /* - * $Id: func.h 363 2008-09-04 10:58:08Z baconevi $ + * $Id: fnc.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/misc.c b/qse/lib/awk/misc.c index 897e4c55..489aeeb5 100644 --- a/qse/lib/awk/misc.c +++ b/qse/lib/awk/misc.c @@ -1,5 +1,5 @@ /* - * $Id: misc.c 337 2008-08-20 09:17:25Z baconevi $ + * $Id: misc.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/misc.h b/qse/lib/awk/misc.h index a75bb23a..587429fd 100644 --- a/qse/lib/awk/misc.h +++ b/qse/lib/awk/misc.h @@ -1,5 +1,5 @@ /* - * $Id: misc.h 363 2008-09-04 10:58:08Z baconevi $ + * $Id: misc.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/parse.c b/qse/lib/awk/parse.c index 59ec65a6..0aeef62f 100644 --- a/qse/lib/awk/parse.c +++ b/qse/lib/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c 496 2008-12-15 09:56:48Z baconevi $ + * $Id: parse.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/parse.h b/qse/lib/awk/parse.h index 93ff541d..4cbc4f9d 100644 --- a/qse/lib/awk/parse.h +++ b/qse/lib/awk/parse.h @@ -1,5 +1,5 @@ /* - * $Id: parse.h 363 2008-09-04 10:58:08Z baconevi $ + * $Id: parse.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/rec.c b/qse/lib/awk/rec.c index d7ba33be..0ce63375 100644 --- a/qse/lib/awk/rec.c +++ b/qse/lib/awk/rec.c @@ -1,5 +1,5 @@ /* - * $Id: rec.c 372 2008-09-23 09:51:24Z baconevi $ + * $Id: rec.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -123,7 +123,7 @@ static int split_record (qse_awk_rtx_t* run) else { fs_ptr = qse_awk_rtx_valtostr ( - run, fs, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &fs_len); + run, fs, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &fs_len); if (fs_ptr == QSE_NULL) return -1; fs_free = fs_ptr; } diff --git a/qse/lib/awk/rio.c b/qse/lib/awk/rio.c index 60c9bf0a..46004746 100644 --- a/qse/lib/awk/rio.c +++ b/qse/lib/awk/rio.c @@ -1,5 +1,5 @@ /* - * $Id: eio.c 466 2008-12-09 09:50:40Z baconevi $ + * $Id: rio.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -218,7 +218,7 @@ int qse_awk_rtx_readio ( else { rs_ptr = qse_awk_rtx_valtostr ( - run, rs, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &rs_len); + run, rs, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &rs_len); if (rs_ptr == QSE_NULL) { qse_awk_rtx_refdownval (run, rs); @@ -426,7 +426,7 @@ int qse_awk_rtx_writeio_val ( { str = qse_awk_rtx_valtostr ( run, v, - QSE_AWK_VALTOSTR_CLEAR | QSE_AWK_VALTOSTR_PRINT, + QSE_AWK_RTX_VALTOSTR_CLEAR | QSE_AWK_RTX_VALTOSTR_PRINT, QSE_NULL, &len); if (str == QSE_NULL) return -1; } diff --git a/qse/lib/awk/rio.h b/qse/lib/awk/rio.h index 8a6dd2c2..6db571ce 100644 --- a/qse/lib/awk/rio.h +++ b/qse/lib/awk/rio.h @@ -1,5 +1,5 @@ /* - * $Id: eio.h 363 2008-09-04 10:58:08Z baconevi $ + * $Id: rio.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/run.c b/qse/lib/awk/run.c index 1302ff0e..a10c90d9 100644 --- a/qse/lib/awk/run.c +++ b/qse/lib/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c 496 2008-12-15 09:56:48Z baconevi $ + * $Id: run.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -315,7 +315,7 @@ static int set_global ( qse_size_t convfmt_len, i; convfmt_ptr = qse_awk_rtx_valtostr (run, - val, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &convfmt_len); + val, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &convfmt_len); if (convfmt_ptr == QSE_NULL) return -1; for (i = 0; i < convfmt_len; i++) @@ -362,7 +362,7 @@ static int set_global ( QSE_ASSERT (val->type != QSE_AWK_VAL_REX); fs_ptr = qse_awk_rtx_valtostr ( - run, val, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &fs_len); + run, val, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &fs_len); if (fs_ptr == QSE_NULL) return -1; } @@ -443,7 +443,7 @@ static int set_global ( qse_size_t ofmt_len, i; ofmt_ptr = qse_awk_rtx_valtostr ( - run, val, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &ofmt_len); + run, val, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &ofmt_len); if (ofmt_ptr == QSE_NULL) return -1; for (i = 0; i < ofmt_len; i++) @@ -467,7 +467,7 @@ static int set_global ( qse_size_t ofs_len; ofs_ptr = qse_awk_rtx_valtostr ( - run, val, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &ofs_len); + run, val, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &ofs_len); if (ofs_ptr == QSE_NULL) return -1; if (run->gbl.ofs.ptr != QSE_NULL) @@ -481,7 +481,7 @@ static int set_global ( qse_size_t ors_len; ors_ptr = qse_awk_rtx_valtostr ( - run, val, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &ors_len); + run, val, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &ors_len); if (ors_ptr == QSE_NULL) return -1; if (run->gbl.ors.ptr != QSE_NULL) @@ -506,7 +506,7 @@ static int set_global ( QSE_ASSERT (val->type != QSE_AWK_VAL_REX); rs_ptr = qse_awk_rtx_valtostr ( - run, val, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &rs_len); + run, val, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &rs_len); if (rs_ptr == QSE_NULL) return -1; } @@ -540,7 +540,7 @@ static int set_global ( qse_size_t subsep_len; subsep_ptr = qse_awk_rtx_valtostr ( - run, val, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &subsep_len); + run, val, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &subsep_len); if (subsep_ptr == QSE_NULL) return -1; if (run->gbl.subsep.ptr != QSE_NULL) @@ -1271,7 +1271,6 @@ static void capture_retval_on_exit (void* arg) qse_awk_rtx_refupval (data->rtx, data->val); } - static int enter_stack_frame (qse_awk_rtx_t* run) { qse_size_t saved_stack_top; @@ -1462,11 +1461,13 @@ int qse_awk_rtx_loop (qse_awk_rtx_t* rtx) } /* call an AWK function */ -int qse_awk_rtx_call ( +qse_awk_val_t* qse_awk_rtx_call ( qse_awk_rtx_t* rtx, const qse_char_t* name, qse_awk_val_t** args, qse_size_t nargs) { +#if 0 int ret = 0; +#endif qse_map_pair_t* pair; qse_awk_fun_t* fun; struct capture_retval_data_t crdata; @@ -1479,7 +1480,7 @@ int qse_awk_rtx_call ( /* cannot call the function again when exit() is called * in an AWK program or qse_awk_rtx_stop() is invoked */ qse_awk_rtx_seterror (rtx, QSE_AWK_ENOPER, 0, QSE_NULL); - return -1; + return QSE_NULL; } /*rtx->exit_level = EXIT_NONE;*/ @@ -1503,7 +1504,7 @@ int qse_awk_rtx_call ( errarg.len = call.what.fun.name.len; qse_awk_rtx_seterror (rtx, QSE_AWK_EFUNNONE, 0, &errarg); - return -1; + return QSE_NULL; } fun = (qse_awk_fun_t*)QSE_MAP_VPTR(pair); @@ -1515,7 +1516,7 @@ int qse_awk_rtx_call ( /* TODO: is this correct? what if i want to * allow arbitarary numbers of arguments? */ qse_awk_rtx_seterror (rtx, QSE_AWK_EARGTM, 0, QSE_NULL); - return -1; + return QSE_NULL; } /* now that the function is found and ok, let's execute it */ @@ -1530,10 +1531,46 @@ int qse_awk_rtx_call ( &crdata ); + if (v == QSE_NULL) + { + /* an error occurred. let's check if it is caused by exit(). + * if so, the return value should have been captured into + * crdata.val. */ + if (crdata.val != QSE_NULL) v = crdata.val; /* yet it is */ + } + else + { + /* thr return value captured in termination by exit() + * is reference-counted up in capture_retval_on_exit(). + * let's do the same thing for the return value normally + * returned. */ + qse_awk_rtx_refupval (rtx, v); + } + + if (rtx->rcb.on_exit != QSE_NULL) + { + rtx->rcb.on_exit ( + rtx, + ((v == QSE_NULL)? qse_awk_val_nil: v), + rtx->rcb.data + ); + } + + /* return the return value with its reference count at least 1. + * the caller of this function should reference-count it down. */ + return v; + + +#if 0 if (v == QSE_NULL) { + /* an error occurred. but this might have been + * caused by exit(). so let's check it */ + if (crdata.val == QSE_NULL) { + /* no return value has been caputured. this must + * be an error */ QSE_ASSERT (rtx->errnum != QSE_AWK_ENOERR); v = qse_awk_val_nil; /* defaults to nil */ ret = -1; @@ -1556,17 +1593,19 @@ int qse_awk_rtx_call ( } else { - /* the reference count of crdata.val is updated in - * capture_retval_on_exit(). update reference count of - * v here to balance it */ + /* the return value captured in termination by exit() + * is reference-counted up in capture_retval_on_exit(). + * let's do the same thing for the return value normally + * returned. */ qse_awk_rtx_refupval (rtx, v); } if (rtx->rcb.on_exit != QSE_NULL) rtx->rcb.on_exit (rtx, v, rtx->rcb.data); - qse_awk_rtx_refdownval (rtx, v); + qse_awk_rtx_refdownval (rtx, v); return ret; +#endif } static int run_pattern_blocks (qse_awk_rtx_t* run) @@ -2534,13 +2573,13 @@ static int run_delete (qse_awk_rtx_t* run, qse_awk_nde_delete_t* nde) /* try with a fixed-size buffer */ keylen = QSE_COUNTOF(buf); key = qse_awk_rtx_valtostr ( - run, idx, QSE_AWK_VALTOSTR_FIXED, + run, idx, QSE_AWK_RTX_VALTOSTR_FIXED, (qse_str_t*)buf, &keylen); if (key == QSE_NULL) { /* if it doesn't work, switch to dynamic mode */ key = qse_awk_rtx_valtostr ( - run, idx, QSE_AWK_VALTOSTR_CLEAR, + run, idx, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &keylen); } @@ -2659,13 +2698,13 @@ static int run_delete (qse_awk_rtx_t* run, qse_awk_nde_delete_t* nde) /* try with a fixed-size buffer */ keylen = QSE_COUNTOF(buf); key = qse_awk_rtx_valtostr ( - run, idx, QSE_AWK_VALTOSTR_FIXED, + run, idx, QSE_AWK_RTX_VALTOSTR_FIXED, (qse_str_t*)buf, &keylen); if (key == QSE_NULL) { /* if it doesn't work, switch to dynamic mode */ key = qse_awk_rtx_valtostr ( - run, idx, QSE_AWK_VALTOSTR_CLEAR, + run, idx, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &keylen); } @@ -2779,7 +2818,7 @@ static int run_print (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde) qse_awk_rtx_refupval (run, v); out = qse_awk_rtx_valtostr ( - run, v, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, v, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (out == QSE_NULL) { qse_awk_rtx_refdownval (run, v); @@ -2937,7 +2976,7 @@ static int run_printf (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde) qse_awk_rtx_refupval (run, v); out = qse_awk_rtx_valtostr ( - run, v, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, v, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (out == QSE_NULL) { qse_awk_rtx_refdownval (run, v); @@ -3585,7 +3624,7 @@ static qse_awk_val_t* do_assignment_pos ( else { str = qse_awk_rtx_valtostr ( - run, val, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, val, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (str == QSE_NULL) { /* change error line */ @@ -4038,7 +4077,7 @@ static int __cmp_int_str ( } str = qse_awk_rtx_valtostr ( - run, left, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, left, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (str == QSE_NULL) return CMP_ERROR; if (run->gbl.ignorecase) @@ -4110,7 +4149,7 @@ static int __cmp_real_str ( } str = qse_awk_rtx_valtostr ( - run, left, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, left, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (str == QSE_NULL) return CMP_ERROR; if (run->gbl.ignorecase) @@ -4630,11 +4669,11 @@ static qse_awk_val_t* eval_binop_concat ( qse_awk_val_t* res; strl = qse_awk_rtx_valtostr ( - run, left, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &strl_len); + run, left, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &strl_len); if (strl == QSE_NULL) return QSE_NULL; strr = qse_awk_rtx_valtostr ( - run, right, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &strr_len); + run, right, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &strr_len); if (strr == QSE_NULL) { QSE_AWK_FREE (run->awk, strl); @@ -4739,7 +4778,7 @@ static qse_awk_val_t* eval_binop_match0 ( else { str = qse_awk_rtx_valtostr ( - run, right, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, right, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (str == QSE_NULL) return QSE_NULL; rex_code = QSE_AWK_BUILDREX (run->awk, str, len, &errnum); @@ -4785,7 +4824,7 @@ static qse_awk_val_t* eval_binop_match0 ( else { str = qse_awk_rtx_valtostr ( - run, left, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, left, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (str == QSE_NULL) { if (right->type != QSE_AWK_VAL_REX) @@ -5387,7 +5426,8 @@ static qse_awk_val_t* eval_fnc (qse_awk_rtx_t* run, qse_awk_nde_t* nde) } static qse_awk_val_t* eval_fun_ex ( - qse_awk_rtx_t* run, qse_awk_nde_t* nde, void(*errhandler)(void*), void* eharg) + qse_awk_rtx_t* run, qse_awk_nde_t* nde, + void(*errhandler)(void*), void* eharg) { qse_awk_nde_call_t* call = (qse_awk_nde_call_t*)nde; qse_awk_fun_t* fun; @@ -5435,8 +5475,7 @@ static qse_awk_val_t* eval_fun (qse_awk_rtx_t* run, qse_awk_nde_t* nde) while ((nargs) > 0) \ { \ --(nargs); \ - qse_awk_rtx_refdownval ((rtx), \ - (rtx)->stack[(rtx)->stack_top-1]); \ + qse_awk_rtx_refdownval ((rtx), (rtx)->stack[(rtx)->stack_top-1]); \ __raw_pop (rtx); \ } \ } while (0) @@ -5707,11 +5746,11 @@ static qse_size_t push_arg_from_vals (qse_awk_rtx_t* rtx, qse_awk_nde_call_t* ca { if (__raw_push (rtx, pafv->args[nargs]) == -1) { - /* ugly - v needs to be freed if it doesn't have + /* ugly - arg needs to be freed if it doesn't have * any reference. but its reference has not been - * updated yet as it is carried out after the - * successful stack push. so it adds up a reference - * and dereferences it */ + * updated yet as it is carried out after successful + * stack push. so it adds up a reference and + * dereferences it */ qse_awk_rtx_refupval (rtx, pafv->args[nargs]); qse_awk_rtx_refdownval (rtx, pafv->args[nargs]); @@ -5720,6 +5759,8 @@ static qse_size_t push_arg_from_vals (qse_awk_rtx_t* rtx, qse_awk_nde_call_t* ca rtx, QSE_AWK_ENOMEM, call->line, QSE_NULL); return (qse_size_t)-1; } + + qse_awk_rtx_refupval (rtx, pafv->args[nargs]); } return nargs; @@ -6255,7 +6296,7 @@ static qse_awk_val_t* eval_getline (qse_awk_rtx_t* run, qse_awk_nde_t* nde) * should not be called immediately below */ qse_awk_rtx_refupval (run, v); in = qse_awk_rtx_valtostr ( - run, v, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, v, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (in == QSE_NULL) { qse_awk_rtx_refdownval (run, v); @@ -6450,7 +6491,7 @@ static int shorten_record (qse_awk_rtx_t* run, qse_size_t nflds) else { ofs = qse_awk_rtx_valtostr ( - run, v, QSE_AWK_VALTOSTR_CLEAR, + run, v, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &ofs_len); if (ofs == QSE_NULL) return -1; @@ -6534,14 +6575,14 @@ static qse_char_t* idxnde_to_str ( { /* try with a fixed-size buffer */ str = qse_awk_rtx_valtostr ( - run, idx, QSE_AWK_VALTOSTR_FIXED, (qse_str_t*)buf, len); + run, idx, QSE_AWK_RTX_VALTOSTR_FIXED, (qse_str_t*)buf, len); } if (str == QSE_NULL) { /* if it doen't work, switch to the dynamic mode */ str = qse_awk_rtx_valtostr ( - run, idx, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, len); + run, idx, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, len); if (str == QSE_NULL) { @@ -7250,8 +7291,11 @@ qse_char_t* qse_awk_rtx_format ( return QSE_NULL; } - str = qse_awk_rtx_valtostr (run, v, - QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &str_len); + str = qse_awk_rtx_valtostr ( + run, v, + QSE_AWK_RTX_VALTOSTR_CLEAR, + QSE_NULL, &str_len + ); if (str == QSE_NULL) { qse_awk_rtx_refdownval (run, v); diff --git a/qse/lib/awk/run.h b/qse/lib/awk/run.h index ca6337e1..a9454349 100644 --- a/qse/lib/awk/run.h +++ b/qse/lib/awk/run.h @@ -1,5 +1,5 @@ /* - * $Id: run.h 363 2008-09-04 10:58:08Z baconevi $ + * $Id: run.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/std.c b/qse/lib/awk/std.c index 8b251103..2d4c18b0 100644 --- a/qse/lib/awk/std.c +++ b/qse/lib/awk/std.c @@ -1,5 +1,5 @@ /* - * $Id$ + * $Id: std.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -17,6 +17,7 @@ */ #include "awk.h" +#include #include #include #include @@ -33,33 +34,33 @@ typedef struct xtn_t { struct { - qse_awk_parsesimple_type_t type; + qse_awk_parsestd_type_t type; union { const qse_char_t* file; - const qse_char_t* str; + const qse_char_t* cp; struct { const qse_char_t* ptr; const qse_char_t* end; - } strl; + } cpl; } u; qse_sio_t* handle; /* the handle to an open file */ } in; struct { - qse_awk_parsesimple_type_t type; + qse_awk_parsestd_type_t type; union { const qse_char_t* file; - qse_char_t* str; + qse_char_t* cp; struct { qse_xstr_t* osp; qse_char_t* ptr; qse_char_t* end; - } strl; + } cpl; } u; qse_sio_t* handle; } out; @@ -88,7 +89,7 @@ typedef struct rxtn_t } rxtn_t; -const qse_char_t* qse_awk_rtx_opensimple_stdio[] = +const qse_char_t* qse_awk_rtx_openstd_stdio[] = { QSE_T(""), QSE_NULL @@ -137,7 +138,7 @@ static qse_cint_t custom_awk_toccls ( static int add_functions (qse_awk_t* awk); -qse_awk_t* qse_awk_opensimple (void) +qse_awk_t* qse_awk_openstd (void) { qse_awk_t* awk; qse_awk_prm_t prm; @@ -156,9 +157,6 @@ qse_awk_t* qse_awk_opensimple (void) xtn = (xtn_t*) QSE_XTN (awk); QSE_MEMSET (xtn, 0, QSE_SIZEOF(xtn_t)); - /* set default options */ - qse_awk_setoption (awk, QSE_AWK_CLASSIC); - /* add intrinsic functions */ if (add_functions (awk) == -1) { @@ -169,7 +167,7 @@ qse_awk_t* qse_awk_opensimple (void) return awk; } -/*** PARSESIMPLE ***/ +/*** PARSESTD ***/ static qse_ssize_t sf_in ( qse_awk_t* awk, qse_awk_sio_cmd_t cmd, @@ -181,7 +179,7 @@ static qse_ssize_t sf_in ( { switch (xtn->s.in.type) { - case QSE_AWK_PARSESIMPLE_FILE: + case QSE_AWK_PARSESTD_FILE: if (xtn->s.in.u.file == QSE_NULL) return -1; xtn->s.in.handle = qse_sio_open ( @@ -193,12 +191,12 @@ static qse_ssize_t sf_in ( if (xtn->s.in.handle == QSE_NULL) return -1; return 1; - case QSE_AWK_PARSESIMPLE_STDIO: + case QSE_AWK_PARSESTD_STDIO: xtn->s.in.handle = qse_sio_in; return 1; - case QSE_AWK_PARSESIMPLE_STR: - case QSE_AWK_PARSESIMPLE_STRL: + case QSE_AWK_PARSESTD_CP: + case QSE_AWK_PARSESTD_CPL: xtn->s.in.handle = QSE_NULL; return 1; } @@ -219,27 +217,27 @@ static qse_ssize_t sf_in ( { switch (xtn->s.in.type) { - case QSE_AWK_PARSESIMPLE_FILE: - case QSE_AWK_PARSESIMPLE_STDIO: + case QSE_AWK_PARSESTD_FILE: + case QSE_AWK_PARSESTD_STDIO: QSE_ASSERT (xtn->s.in.handle != QSE_NULL); return qse_sio_getsn (xtn->s.in.handle, data, size); - case QSE_AWK_PARSESIMPLE_STR: + case QSE_AWK_PARSESTD_CP: { qse_size_t n = 0; - while (n < size && *xtn->s.in.u.str != QSE_T('\0')) + while (n < size && *xtn->s.in.u.cp != QSE_T('\0')) { - data[n++] = *xtn->s.in.u.str++; + data[n++] = *xtn->s.in.u.cp++; } return n; } - case QSE_AWK_PARSESIMPLE_STRL: + case QSE_AWK_PARSESTD_CPL: { qse_size_t n = 0; - while (n < size && xtn->s.in.u.strl.ptr < xtn->s.in.u.strl.end) + while (n < size && xtn->s.in.u.cpl.ptr < xtn->s.in.u.cpl.end) { - data[n++] = *xtn->s.in.u.strl.ptr++; + data[n++] = *xtn->s.in.u.cpl.ptr++; } return n; } @@ -260,7 +258,7 @@ static qse_ssize_t sf_out ( { switch (xtn->s.out.type) { - case QSE_AWK_PARSESIMPLE_FILE: + case QSE_AWK_PARSESTD_FILE: if (xtn->s.out.u.file == QSE_NULL) return -1; xtn->s.out.handle = qse_sio_open ( @@ -274,12 +272,12 @@ static qse_ssize_t sf_out ( if (xtn->s.out.handle == QSE_NULL) return -1; return 1; - case QSE_AWK_PARSESIMPLE_STDIO: + case QSE_AWK_PARSESTD_STDIO: xtn->s.out.handle = qse_sio_out; return 1; - case QSE_AWK_PARSESIMPLE_STR: - case QSE_AWK_PARSESIMPLE_STRL: + case QSE_AWK_PARSESTD_CP: + case QSE_AWK_PARSESTD_CPL: xtn->s.out.handle = QSE_NULL; return 1; } @@ -288,8 +286,8 @@ static qse_ssize_t sf_out ( { switch (xtn->s.out.type) { - case QSE_AWK_PARSESIMPLE_FILE: - case QSE_AWK_PARSESIMPLE_STDIO: + case QSE_AWK_PARSESTD_FILE: + case QSE_AWK_PARSESTD_STDIO: qse_sio_flush (xtn->s.out.handle); if (xtn->s.out.handle != qse_sio_in && @@ -300,14 +298,14 @@ static qse_ssize_t sf_out ( } return 0; - case QSE_AWK_PARSESIMPLE_STR: - *xtn->s.out.u.str = QSE_T('\0'); + case QSE_AWK_PARSESTD_CP: + *xtn->s.out.u.cp = QSE_T('\0'); return 0; - case QSE_AWK_PARSESIMPLE_STRL: - xtn->s.out.u.strl.osp->len = - xtn->s.out.u.strl.ptr - - xtn->s.out.u.strl.osp->ptr; + case QSE_AWK_PARSESTD_CPL: + xtn->s.out.u.cpl.osp->len = + xtn->s.out.u.cpl.ptr - + xtn->s.out.u.cpl.osp->ptr; return 0; } } @@ -315,27 +313,27 @@ static qse_ssize_t sf_out ( { switch (xtn->s.out.type) { - case QSE_AWK_PARSESIMPLE_FILE: - case QSE_AWK_PARSESIMPLE_STDIO: + case QSE_AWK_PARSESTD_FILE: + case QSE_AWK_PARSESTD_STDIO: QSE_ASSERT (xtn->s.out.handle != QSE_NULL); return qse_sio_putsn (xtn->s.out.handle, data, size); - case QSE_AWK_PARSESIMPLE_STR: + case QSE_AWK_PARSESTD_CP: { qse_size_t n = 0; - while (n < size && *xtn->s.out.u.str != QSE_T('\0')) + while (n < size && *xtn->s.out.u.cp != QSE_T('\0')) { - *xtn->s.out.u.str++ = data[n++]; + *xtn->s.out.u.cp++ = data[n++]; } return n; } - case QSE_AWK_PARSESIMPLE_STRL: + case QSE_AWK_PARSESTD_CPL: { qse_size_t n = 0; - while (n < size && xtn->s.out.u.strl.ptr < xtn->s.out.u.strl.end) + while (n < size && xtn->s.out.u.cpl.ptr < xtn->s.out.u.cpl.end) { - *xtn->s.out.u.strl.ptr++ = data[n++]; + *xtn->s.out.u.cpl.ptr++ = data[n++]; } return n; } @@ -345,10 +343,10 @@ static qse_ssize_t sf_out ( return -1; } -int qse_awk_parsesimple ( +int qse_awk_parsestd ( qse_awk_t* awk, - const qse_awk_parsesimple_in_t* in, - qse_awk_parsesimple_out_t* out) + const qse_awk_parsestd_in_t* in, + qse_awk_parsestd_out_t* out) { qse_awk_sio_t sio; xtn_t* xtn = (xtn_t*) QSE_XTN (awk); @@ -362,20 +360,20 @@ int qse_awk_parsesimple ( switch (in->type) { - case QSE_AWK_PARSESIMPLE_FILE: + case QSE_AWK_PARSESTD_FILE: xtn->s.in.u.file = in->u.file; break; - case QSE_AWK_PARSESIMPLE_STR: - xtn->s.in.u.str = in->u.str; + case QSE_AWK_PARSESTD_CP: + xtn->s.in.u.cp = in->u.cp; break; - case QSE_AWK_PARSESIMPLE_STRL: - xtn->s.in.u.strl.ptr = in->u.strl.ptr; - xtn->s.in.u.strl.end = in->u.strl.ptr + in->u.strl.len; + case QSE_AWK_PARSESTD_CPL: + xtn->s.in.u.cpl.ptr = in->u.cpl.ptr; + xtn->s.in.u.cpl.end = in->u.cpl.ptr + in->u.cpl.len; break; - case QSE_AWK_PARSESIMPLE_STDIO: + case QSE_AWK_PARSESTD_STDIO: /* nothing to do */ break; @@ -392,21 +390,21 @@ int qse_awk_parsesimple ( { switch (out->type) { - case QSE_AWK_PARSESIMPLE_FILE: + case QSE_AWK_PARSESTD_FILE: xtn->s.out.u.file = out->u.file; break; - case QSE_AWK_PARSESIMPLE_STR: - xtn->s.out.u.str = out->u.str; + case QSE_AWK_PARSESTD_CP: + xtn->s.out.u.cp = out->u.cp; break; - case QSE_AWK_PARSESIMPLE_STRL: - xtn->s.out.u.strl.osp = &out->u.strl; - xtn->s.out.u.strl.ptr = out->u.strl.ptr; - xtn->s.out.u.strl.end = out->u.strl.ptr + out->u.strl.len; + case QSE_AWK_PARSESTD_CPL: + xtn->s.out.u.cpl.osp = &out->u.cpl; + xtn->s.out.u.cpl.ptr = out->u.cpl.ptr; + xtn->s.out.u.cpl.end = out->u.cpl.ptr + out->u.cpl.len; break; - case QSE_AWK_PARSESIMPLE_STDIO: + case QSE_AWK_PARSESTD_STDIO: /* nothing to do */ break; @@ -422,8 +420,7 @@ int qse_awk_parsesimple ( return qse_awk_parse (awk, &sio); } -/*** RUNSIMPLE ***/ - +/*** RTX_OPENSTD ***/ static qse_ssize_t awk_rio_pipe ( qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_riod_t* riod, qse_char_t* data, qse_size_t size) @@ -876,7 +873,7 @@ static qse_ssize_t awk_rio_console ( return -1; } -qse_awk_rtx_t* qse_awk_rtx_opensimple ( +qse_awk_rtx_t* qse_awk_rtx_openstd ( qse_awk_t* awk, const qse_char_t*const* icf, const qse_char_t*const* ocf) @@ -1260,7 +1257,7 @@ static int fnc_system (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl else { str = qse_awk_rtx_valtostr ( - run, v, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + run, v, QSE_AWK_RTX_VALTOSTR_CLEAR, QSE_NULL, &len); if (str == QSE_NULL) return -1; } diff --git a/qse/lib/awk/tree.c b/qse/lib/awk/tree.c index bc511b50..674c17a8 100644 --- a/qse/lib/awk/tree.c +++ b/qse/lib/awk/tree.c @@ -1,5 +1,5 @@ /* - * $Id: tree.c 466 2008-12-09 09:50:40Z baconevi $ + * $Id: tree.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/tree.h b/qse/lib/awk/tree.h index 0bf8de3c..096f7147 100644 --- a/qse/lib/awk/tree.h +++ b/qse/lib/awk/tree.h @@ -1,5 +1,5 @@ /* - * $Id: tree.h 381 2008-09-24 11:07:24Z baconevi $ + * $Id: tree.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. diff --git a/qse/lib/awk/val.c b/qse/lib/awk/val.c index fff4da40..fe3c8f92 100644 --- a/qse/lib/awk/val.c +++ b/qse/lib/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c 496 2008-12-15 09:56:48Z baconevi $ + * $Id: val.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -617,10 +617,7 @@ void qse_awk_rtx_freeval (qse_awk_rtx_t* rtx, qse_awk_val_t* val, qse_bool_t cac } else if (val->type == QSE_AWK_VAL_MAP) { - /* CHECK */ - /* qse_map_close (((qse_awk_val_map_t*)val)->map);*/ qse_map_fini (((qse_awk_val_map_t*)val)->map); - /* END CHECK */ QSE_AWK_FREE (rtx->awk, val); } else if (val->type == QSE_AWK_VAL_REF) @@ -798,7 +795,7 @@ static qse_char_t* str_to_str ( if (len != QSE_NULL) *len = str_len; return tmp; } - else if (opt & QSE_AWK_VALTOSTR_FIXED) + else if (opt & QSE_AWK_RTX_VALTOSTR_FIXED) { QSE_ASSERT (buf != QSE_NULL && len != QSE_NULL); @@ -816,7 +813,7 @@ static qse_char_t* str_to_str ( { qse_size_t n; - if (opt & QSE_AWK_VALTOSTR_CLEAR) qse_str_clear (buf); + if (opt & QSE_AWK_RTX_VALTOSTR_CLEAR) qse_str_clear (buf); n = qse_str_ncat (buf, str, str_len); if (n == (qse_size_t)-1) { @@ -857,7 +854,7 @@ static qse_char_t* val_int_to_str ( if (len != QSE_NULL) *len = 1; return tmp; } - else if (opt & QSE_AWK_VALTOSTR_FIXED) + else if (opt & QSE_AWK_RTX_VALTOSTR_FIXED) { QSE_ASSERT (buf != QSE_NULL && len != QSE_NULL); @@ -877,7 +874,7 @@ static qse_char_t* val_int_to_str ( } else { - if (opt & QSE_AWK_VALTOSTR_CLEAR) qse_str_clear (buf); + if (opt & QSE_AWK_RTX_VALTOSTR_CLEAR) qse_str_clear (buf); if (qse_str_cat (buf, QSE_T("0")) == (qse_size_t)-1) { qse_awk_rtx_seterror ( @@ -907,7 +904,7 @@ static qse_char_t* val_int_to_str ( tmp[rlen] = QSE_T('\0'); if (len != QSE_NULL) *len = rlen; } - else if (opt & QSE_AWK_VALTOSTR_FIXED) + else if (opt & QSE_AWK_RTX_VALTOSTR_FIXED) { QSE_ASSERT (buf != QSE_NULL && len != QSE_NULL); @@ -925,7 +922,7 @@ static qse_char_t* val_int_to_str ( else { /* clear the buffer */ - if (opt & QSE_AWK_VALTOSTR_CLEAR) qse_str_clear (buf); + if (opt & QSE_AWK_RTX_VALTOSTR_CLEAR) qse_str_clear (buf); tmp = QSE_STR_PTR(buf) + QSE_STR_LEN(buf); @@ -950,7 +947,7 @@ static qse_char_t* val_int_to_str ( if (v->val < 0) tmp[--rlen] = QSE_T('-'); - if (buf != QSE_NULL && !(opt & QSE_AWK_VALTOSTR_FIXED)) + if (buf != QSE_NULL && !(opt & QSE_AWK_RTX_VALTOSTR_FIXED)) { tmp = QSE_STR_PTR(buf); if (len != QSE_NULL) *len = QSE_STR_LEN(buf); @@ -967,7 +964,7 @@ static qse_char_t* val_real_to_str ( qse_size_t tmp_len; qse_str_t out, fbu; - if (opt & QSE_AWK_VALTOSTR_PRINT) + if (opt & QSE_AWK_RTX_VALTOSTR_PRINT) { tmp = run->gbl.ofmt.ptr; tmp_len = run->gbl.ofmt.len; @@ -1009,7 +1006,7 @@ static qse_char_t* val_real_to_str ( if (len != QSE_NULL) *len = tmp_len; } - else if (opt & QSE_AWK_VALTOSTR_FIXED) + else if (opt & QSE_AWK_RTX_VALTOSTR_FIXED) { QSE_ASSERT (buf != QSE_NULL && len != QSE_NULL); @@ -1032,7 +1029,7 @@ static qse_char_t* val_real_to_str ( } else { - if (opt & QSE_AWK_VALTOSTR_CLEAR) qse_str_clear (buf); + if (opt & QSE_AWK_RTX_VALTOSTR_CLEAR) qse_str_clear (buf); if (qse_str_ncat (buf, tmp, tmp_len) == (qse_size_t)-1) { diff --git a/qse/lib/awk/val.h b/qse/lib/awk/val.h index 3c534865..f404b140 100644 --- a/qse/lib/awk/val.h +++ b/qse/lib/awk/val.h @@ -1,5 +1,5 @@ /* - * $Id: eio.h 363 2008-09-04 10:58:08Z baconevi $ + * $Id: val.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -23,6 +23,12 @@ extern "C" { #endif +void qse_awk_rtx_freeval ( + qse_awk_rtx_t* rtx, + qse_awk_val_t* val, + qse_bool_t cache +); + void qse_awk_rtx_freevalchunk ( qse_awk_rtx_t* rtx, qse_awk_val_chunk_t* chunk diff --git a/qse/test/awk/Makefile.am b/qse/test/awk/Makefile.am index 930e6f54..26feb39f 100644 --- a/qse/test/awk/Makefile.am +++ b/qse/test/awk/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -bin_PROGRAMS = awk01 awk02 awk03 +bin_PROGRAMS = awk01 awk02 awk03 awk04 LDFLAGS = -L../../lib/cmn -L../../lib/utl -L../../lib/awk LDADD = -lqseawk -lqseutl -lqsecmn $(LIBM) @@ -8,3 +8,4 @@ LDADD = -lqseawk -lqseutl -lqsecmn $(LIBM) awk01_SOURCES = awk01.c awk02_SOURCES = awk02.c awk03_SOURCES = awk03.c +awk04_SOURCES = awk04.c diff --git a/qse/test/awk/Makefile.in b/qse/test/awk/Makefile.in index 904a0baf..1a37c5fc 100644 --- a/qse/test/awk/Makefile.in +++ b/qse/test/awk/Makefile.in @@ -32,7 +32,8 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -bin_PROGRAMS = awk01$(EXEEXT) awk02$(EXEEXT) awk03$(EXEEXT) +bin_PROGRAMS = awk01$(EXEEXT) awk02$(EXEEXT) awk03$(EXEEXT) \ + awk04$(EXEEXT) subdir = test/awk DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -58,6 +59,10 @@ am_awk03_OBJECTS = awk03.$(OBJEXT) awk03_OBJECTS = $(am_awk03_OBJECTS) awk03_LDADD = $(LDADD) awk03_DEPENDENCIES = $(am__DEPENDENCIES_1) +am_awk04_OBJECTS = awk04.$(OBJEXT) +awk04_OBJECTS = $(am_awk04_OBJECTS) +awk04_LDADD = $(LDADD) +awk04_DEPENDENCIES = $(am__DEPENDENCIES_1) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include/qse depcomp = $(SHELL) $(top_srcdir)/autoconf/depcomp am__depfiles_maybe = depfiles @@ -70,8 +75,10 @@ CCLD = $(CC) LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ -SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) -DIST_SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) +SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) \ + $(awk04_SOURCES) +DIST_SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) \ + $(awk04_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -201,6 +208,7 @@ LDADD = -lqseawk -lqseutl -lqsecmn $(LIBM) awk01_SOURCES = awk01.c awk02_SOURCES = awk02.c awk03_SOURCES = awk03.c +awk04_SOURCES = awk04.c all: all-am .SUFFIXES: @@ -271,6 +279,9 @@ awk02$(EXEEXT): $(awk02_OBJECTS) $(awk02_DEPENDENCIES) awk03$(EXEEXT): $(awk03_OBJECTS) $(awk03_DEPENDENCIES) @rm -f awk03$(EXEEXT) $(LINK) $(awk03_OBJECTS) $(awk03_LDADD) $(LIBS) +awk04$(EXEEXT): $(awk04_OBJECTS) $(awk04_DEPENDENCIES) + @rm -f awk04$(EXEEXT) + $(LINK) $(awk04_OBJECTS) $(awk04_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -281,6 +292,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk01.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk02.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk03.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk04.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/qse/test/awk/awk01.c b/qse/test/awk/awk01.c index aec74e57..320a23fc 100644 --- a/qse/test/awk/awk01.c +++ b/qse/test/awk/awk01.c @@ -23,6 +23,7 @@ */ #include +#include #include const qse_char_t* src = QSE_T( @@ -40,20 +41,20 @@ int main () { qse_awk_t* awk = QSE_NULL; qse_awk_rtx_t* rtx = QSE_NULL; - qse_awk_parsesimple_in_t psin; + qse_awk_parsestd_in_t psin; int ret; - awk = qse_awk_opensimple (); + awk = qse_awk_openstd (); if (awk == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); goto oops; } - psin.type = QSE_AWK_PARSESIMPLE_STR; - psin.u.str = src; + psin.type = QSE_AWK_PARSESTD_CP; + psin.u.cp = src; - ret = qse_awk_parsesimple (awk, &psin, QSE_NULL); + ret = qse_awk_parsestd (awk, &psin, QSE_NULL); if (ret == -1) { qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), @@ -61,10 +62,10 @@ int main () goto oops; } - rtx = qse_awk_rtx_opensimple ( + rtx = qse_awk_rtx_openstd ( awk, - QSE_NULL, /* no console input */ - QSE_AWK_RTX_OPENSIMPLE_STDIO /* stdout for console output */ + QSE_NULL, /* no console input */ + QSE_AWK_RTX_OPENSTD_STDIO /* stdout for console output */ ); if (rtx == QSE_NULL) { diff --git a/qse/test/awk/awk02.c b/qse/test/awk/awk02.c index 94b52334..366e9fe0 100644 --- a/qse/test/awk/awk02.c +++ b/qse/test/awk/awk02.c @@ -23,6 +23,7 @@ */ #include +#include #include #include @@ -44,12 +45,12 @@ int main () qse_awk_t* awk = QSE_NULL; qse_awk_rtx_t* rtx = QSE_NULL; - qse_awk_parsesimple_in_t psin; - qse_awk_parsesimple_out_t psout; + qse_awk_parsestd_in_t psin; + qse_awk_parsestd_out_t psout; int ret; - awk = qse_awk_opensimple (); + awk = qse_awk_openstd (); if (awk == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); @@ -59,12 +60,12 @@ int main () qse_memset (srcout, QSE_T(' '), QSE_COUNTOF(srcout)-1); srcout[QSE_COUNTOF(srcout)-1] = QSE_T('\0'); - psin.type = QSE_AWK_PARSESIMPLE_STR; - psin.u.str = src; - psout.type = QSE_AWK_PARSESIMPLE_STR; - psout.u.str = srcout; + psin.type = QSE_AWK_PARSESTD_CP; + psin.u.cp = src; + psout.type = QSE_AWK_PARSESTD_CP; + psout.u.cp = srcout; - ret = qse_awk_parsesimple (awk, &psin, &psout); + ret = qse_awk_parsestd (awk, &psin, &psout); if (ret == -1) { qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), @@ -76,10 +77,10 @@ int main () qse_printf (QSE_T("=================================\n")); qse_fflush (QSE_STDOUT); - rtx = qse_awk_rtx_opensimple ( + rtx = qse_awk_rtx_openstd ( awk, - QSE_NULL, /* no console input */ - QSE_AWK_RTX_OPENSIMPLE_STDIO /* stdout for console output */ + QSE_NULL, /* no console input */ + QSE_AWK_RTX_OPENSTD_STDIO /* stdout for console output */ ); if (rtx == QSE_NULL) { diff --git a/qse/test/awk/awk03.c b/qse/test/awk/awk03.c index 97fa2339..f3ce24f1 100644 --- a/qse/test/awk/awk03.c +++ b/qse/test/awk/awk03.c @@ -25,12 +25,13 @@ */ #include +#include #include static const qse_char_t* src = QSE_T( - "function init() { a = 20; }" - "function main() { a++; }" - "function fini() { print a; }" + "function init() { a = 20; return a; }" + "function main() { return ++a; }" + "function fini() { print ++a; return a; }" ); static const qse_char_t* fnc[] = @@ -48,12 +49,12 @@ int main () qse_awk_t* awk = QSE_NULL; qse_awk_rtx_t* rtx = QSE_NULL; - qse_awk_parsesimple_in_t psin; + qse_awk_parsestd_in_t psin; int ret, i; /* create a main processor */ - awk = qse_awk_opensimple (); + awk = qse_awk_openstd (); if (awk == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); @@ -63,10 +64,10 @@ int main () /* don't allow BEGIN, END, pattern-action blocks */ qse_awk_setoption (awk, qse_awk_getoption(awk) & ~QSE_AWK_PABLOCK); - psin.type = QSE_AWK_PARSESIMPLE_STR; - psin.u.str = src; + psin.type = QSE_AWK_PARSESTD_CP; + psin.u.cp = src; - ret = qse_awk_parsesimple (awk, &psin, QSE_NULL); + ret = qse_awk_parsestd (awk, &psin, QSE_NULL); if (ret == -1) { qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), @@ -75,10 +76,10 @@ int main () } /* create a runtime context */ - rtx = qse_awk_rtx_opensimple ( + rtx = qse_awk_rtx_openstd ( awk, - QSE_NULL, /* no console input */ - QSE_AWK_RTX_OPENSIMPLE_STDIO /* stdout for console output */ + QSE_NULL, /* no console input */ + QSE_AWK_RTX_OPENSTD_STDIO /* stdout for console output */ ); if (rtx == QSE_NULL) { @@ -90,13 +91,25 @@ int main () /* invoke functions as indicated in the array fnc */ for (i = 0; i < QSE_COUNTOF(fnc); i++) { - ret = qse_awk_rtx_call (rtx, fnc[i], QSE_NULL, 0); - if (ret == -1) + qse_awk_val_t* v; + qse_char_t buf[1000]; + qse_size_t bufsize; + + v = qse_awk_rtx_call (rtx, fnc[i], QSE_NULL, 0); + if (v == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), qse_awk_rtx_geterrmsg(rtx)); - goto oops; + ret = -1; goto oops; } + + bufsize = QSE_COUNTOF(buf); + qse_awk_rtx_valtostr (rtx, v, + QSE_AWK_RTX_VALTOSTR_FIXED, buf, &bufsize); + qse_printf (QSE_T("return: [%.*s]\n"), (int)bufsize, buf); + + /* clear the return value */ + qse_awk_rtx_refdownval (rtx, v); } oops: diff --git a/qse/test/awk/awk04.c b/qse/test/awk/awk04.c new file mode 100644 index 00000000..0a202c34 --- /dev/null +++ b/qse/test/awk/awk04.c @@ -0,0 +1,130 @@ +/* + * $Id$ + * + Copyright 2006-2009 Chung, Hyung-Hwan. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/****S* AWK/Calling Functions + * DESCRIPTION + * This program demonstrates how to use qse_awk_rtx_call(). + * It parses the program stored in the string src and calls the functions + * stated in the array fnc. If no errors occur, it should print 24. + * SOURCE + */ + +#include +#include +#include + +static const qse_char_t* src = QSE_T( + "function pow(x,y) { return x ** y; }" +); + +int main () +{ + qse_awk_t* awk = QSE_NULL; + qse_awk_rtx_t* rtx = QSE_NULL; + qse_awk_parsestd_in_t psin; + qse_char_t buf[1000]; + qse_size_t bufsize; + qse_awk_val_t* v; + qse_awk_val_t* arg[2] = { QSE_NULL, QSE_NULL }; + int ret, i; + + /* create a main processor */ + awk = qse_awk_openstd (); + if (awk == QSE_NULL) + { + qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); + ret = -1; goto oops; + } + + /* don't allow BEGIN, END, pattern-action blocks */ + qse_awk_setoption (awk, qse_awk_getoption(awk) & ~QSE_AWK_PABLOCK); + + psin.type = QSE_AWK_PARSESTD_CP; + psin.u.cp = src; + + ret = qse_awk_parsestd (awk, &psin, QSE_NULL); + if (ret == -1) + { + qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), + qse_awk_geterrmsg(awk)); + goto oops; + } + + /* create a runtime context */ + rtx = qse_awk_rtx_openstd ( + awk, + QSE_NULL, /* no console input */ + QSE_AWK_RTX_OPENSTD_STDIO /* stdout for console output */ + ); + if (rtx == QSE_NULL) + { + qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), + qse_awk_geterrmsg(awk)); + ret = -1; goto oops; + } + + /* invoke the pow function */ + arg[0] = qse_awk_rtx_makeintval (rtx, 50); + if (arg[0] == QSE_NULL) + { + qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), + qse_awk_rtx_geterrmsg(rtx)); + ret = -1; goto oops; + } + qse_awk_rtx_refupval (rtx, arg[0]); + + arg[1] = qse_awk_rtx_makeintval (rtx, 3); + if (arg[1] == QSE_NULL) + { + qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), + qse_awk_rtx_geterrmsg(rtx)); + ret = -1; goto oops; + } + qse_awk_rtx_refupval (rtx, arg[1]); + + v = qse_awk_rtx_call (rtx, QSE_T("pow"), arg, 2); + if (v == QSE_NULL) + { + qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), + qse_awk_rtx_geterrmsg(rtx)); + ret = -1; goto oops; + } + + bufsize = QSE_COUNTOF(buf); + qse_awk_rtx_valtostr (rtx, v, + QSE_AWK_RTX_VALTOSTR_FIXED, buf, &bufsize); + qse_printf (QSE_T("[%.*s]\n"), (int)bufsize, buf); + + /* clear the return value */ + qse_awk_rtx_refdownval (rtx, v); + +oops: + /* dereference all arguments */ + for (i = 0; i < QSE_COUNTOF(arg); i++) + { + if (arg[i] != QSE_NULL) + qse_awk_rtx_refdownval (rtx, arg[i]); + } + + /* destroy a runtime context */ + if (rtx != QSE_NULL) qse_awk_rtx_close (rtx); + /* destroy the processor */ + if (awk != QSE_NULL) qse_awk_close (awk); + return ret; +} +/******/