enhanced and fixed a few functions.

- qse_awk_rtx_call()
- qse_awk_parsesimple() 
- qse_awk_parsesimple_in_t
- qse_awk_parsesimple_out_t
This commit is contained in:
hyung-hwan 2009-02-23 08:10:34 +00:00
parent 2e24e29e8c
commit d0ce35eacf
55 changed files with 615 additions and 363 deletions

View File

@ -17,6 +17,7 @@
*/ */
#include <qse/awk/awk.h> #include <qse/awk/awk.h>
#include <qse/awk/std.h>
#include <qse/cmn/sll.h> #include <qse/cmn/sll.h>
#include <qse/cmn/mem.h> #include <qse/cmn/mem.h>
#include <qse/cmn/chr.h> #include <qse/cmn/chr.h>
@ -50,7 +51,7 @@ static int app_debug = 0;
struct argout_t struct argout_t
{ {
qse_awk_parsesimple_type_t ist; /* input source type */ qse_awk_parsestd_type_t ist; /* input source type */
union union
{ {
const qse_char_t* str; const qse_char_t* str;
@ -58,7 +59,7 @@ struct argout_t
} isp; } isp;
qse_size_t isfl; /* the number of input source files */ 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 */ 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 */ /* 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++]; ao->isp.str = argv[opt.ind++];
free (isf); free (isf);
} }
else else
{ {
ao->ist = QSE_AWK_PARSESIMPLE_FILE; ao->ist = QSE_AWK_PARSESTD_FILE;
ao->isp.files = isf; 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; icf[icfl] = QSE_NULL;
ao->ost = QSE_AWK_PARSESIMPLE_FILE; ao->ost = QSE_AWK_PARSESTD_FILE;
ao->osf = osf; ao->osf = osf;
ao->icf = icf; ao->icf = icf;
@ -548,7 +549,7 @@ static qse_awk_t* open_awk (void)
{ {
qse_awk_t* awk; qse_awk_t* awk;
awk = qse_awk_opensimple (); awk = qse_awk_openstd ();
if (awk == QSE_NULL) if (awk == QSE_NULL)
{ {
qse_printf (QSE_T("ERROR: cannot open awk\n")); 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; if (awk == QSE_NULL) return -1;
/* TODO: change it to support multiple source files */ /* TODO: change it to support multiple source files */
qse_awk_parsesimple_in_t psin; qse_awk_parsestd_in_t psin;
qse_awk_parsesimple_out_t psout; qse_awk_parsestd_out_t psout;
psin.type = ao.ist; 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]; else psin.u.file = ao.isp.files[0];
if (ao.osf != QSE_NULL) if (ao.osf != QSE_NULL)
@ -623,7 +624,7 @@ static int awk_main (int argc, qse_char_t* argv[])
psout.u.file = ao.osf; 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) ((ao.osf == QSE_NULL)? QSE_NULL: &psout)) == -1)
{ {
qse_printf ( qse_printf (
@ -642,8 +643,8 @@ static int awk_main (int argc, qse_char_t* argv[])
rcb.on_exit = on_run_exit; rcb.on_exit = on_run_exit;
rcb.data = &ao; rcb.data = &ao;
rtx = qse_awk_rtx_opensimple ( rtx = qse_awk_rtx_openstd (
awk, ao.icf, QSE_AWK_RTX_OPENSIMPLE_STDIO); awk, ao.icf, QSE_AWK_RTX_OPENSTD_STDIO);
if (rtx == QSE_NULL) if (rtx == QSE_NULL)
{ {
qse_printf ( qse_printf (
@ -680,7 +681,7 @@ static int awk_main (int argc, qse_char_t* argv[])
oops: oops:
qse_awk_close (awk); 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); ao.isp.files != QSE_NULL) free (ao.isp.files);
/*if (ao.osf != QSE_NULL) free (ao.osf);*/ /*if (ao.osf != QSE_NULL) free (ao.osf);*/
if (ao.icf != QSE_NULL) free (ao.icf); if (ao.icf != QSE_NULL) free (ao.icf);

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -1,5 +1,5 @@
pkginclude_HEADERS = awk.h pkginclude_HEADERS = awk.h std.h
if ENABLE_CXX if ENABLE_CXX
pkginclude_HEADERS += Awk.hpp StdAwk.hpp pkginclude_HEADERS += Awk.hpp StdAwk.hpp

View File

@ -44,7 +44,7 @@ CONFIG_HEADER = $(top_builddir)/include/qse/config.h
CONFIG_CLEAN_FILES = CONFIG_CLEAN_FILES =
SOURCES = SOURCES =
DIST_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_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \ am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@ -179,7 +179,7 @@ sysconfdir = @sysconfdir@
target_alias = @target_alias@ target_alias = @target_alias@
top_builddir = @top_builddir@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
pkginclude_HEADERS = awk.h $(am__append_1) pkginclude_HEADERS = awk.h std.h $(am__append_1)
CLEANFILES = *dist CLEANFILES = *dist
all: all-am all: all-am

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -556,11 +556,31 @@ enum qse_awk_val_ref_id_t
enum qse_awk_rtx_valtostr_opt_t enum qse_awk_rtx_valtostr_opt_t
{ {
QSE_AWK_VALTOSTR_CLEAR = (1 << 0), QSE_AWK_RTX_VALTOSTR_CLEAR = (1 << 0),
QSE_AWK_VALTOSTR_FIXED = (1 << 1), /* this overrides CLEAR */ QSE_AWK_RTX_VALTOSTR_FIXED = (1 << 1), /* this overrides CLEAR */
QSE_AWK_VALTOSTR_PRINT = (1 << 2) 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_nil_t qse_awk_val_nil_t;
typedef struct qse_awk_val_int_t qse_awk_val_int_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; 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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -1221,13 +1184,15 @@ int qse_awk_rtx_loop (
* rtx = qse_awk_rtx_open (awk, rio, rcb, QSE_NULL, QSE_NULL); * rtx = qse_awk_rtx_open (awk, rio, rcb, QSE_NULL, QSE_NULL);
* if (rtx != 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); * 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); * qse_awk_rtx_close (rtx);
* } * }
* SYNOPSIS * SYNOPSIS
*/ */
int qse_awk_rtx_call ( qse_awk_val_t* qse_awk_rtx_call (
qse_awk_rtx_t* rtx, qse_awk_rtx_t* rtx,
const qse_char_t* name, const qse_char_t* name,
qse_awk_val_t** args, qse_awk_val_t** args,
@ -1469,7 +1434,6 @@ void qse_awk_rtx_seterror (
const qse_cstr_t* errarg const qse_cstr_t* errarg
); );
/* record and field functions */ /* record and field functions */
int qse_awk_rtx_clrrec ( int qse_awk_rtx_clrrec (
qse_awk_rtx_t* rtx, qse_awk_rtx_t* rtx,
@ -1540,12 +1504,6 @@ qse_bool_t qse_awk_rtx_isstaticval (
qse_awk_val_t* val 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 ( void qse_awk_rtx_refupval (
qse_awk_rtx_t* rtx, qse_awk_rtx_t* rtx,
qse_awk_val_t* val 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 #ifdef __cplusplus
} }
#endif #endif

146
qse/include/qse/awk/std.h Normal file
View File

@ -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 <qse/awk/awk.h>
/****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

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -1,5 +1,5 @@
/* /*
* $Id$ * $Id: fio.h 75 2009-02-22 14:10:34Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -1,5 +1,5 @@
/* /*
* $Id$ * $Id: pio.h 75 2009-02-22 14:10:34Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -1,5 +1,5 @@
/* /*
* $Id$ * $Id: time.h 75 2009-02-22 14:10:34Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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} * {License}
*/ */

View File

@ -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} * {License}
*/ */

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -250,7 +250,7 @@ static int fnc_close (
else else
{ {
name = qse_awk_rtx_valtostr ( 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; if (name == QSE_NULL) return -1;
} }
@ -364,7 +364,7 @@ static int fnc_fflush (
else else
{ {
str0 = qse_awk_rtx_valtostr ( 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; if (str0 == QSE_NULL) return -1;
} }
@ -437,7 +437,7 @@ static int fnc_index (
else else
{ {
str0 = qse_awk_rtx_valtostr ( 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; if (str0 == QSE_NULL) return -1;
} }
@ -449,7 +449,7 @@ static int fnc_index (
else else
{ {
str1 = qse_awk_rtx_valtostr ( 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 (str1 == QSE_NULL)
{ {
if (a0->type != QSE_AWK_VAL_STR) if (a0->type != QSE_AWK_VAL_STR)
@ -494,7 +494,7 @@ static int fnc_length (
else else
{ {
str = qse_awk_rtx_valtostr ( 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; if (str == QSE_NULL) return -1;
QSE_AWK_FREE (run->awk, str); QSE_AWK_FREE (run->awk, str);
} }
@ -536,7 +536,7 @@ static int fnc_substr (
else else
{ {
str = qse_awk_rtx_valtostr ( 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; if (str == QSE_NULL) return -1;
} }
@ -642,7 +642,7 @@ static int fnc_split (
else else
{ {
str = qse_awk_rtx_valtostr ( 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; if (str == QSE_NULL) return -1;
str_free = str; str_free = str;
} }
@ -666,7 +666,7 @@ static int fnc_split (
else else
{ {
fs_ptr = qse_awk_rtx_valtostr ( 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 (fs_ptr == QSE_NULL)
{ {
if (str_free != QSE_NULL) if (str_free != QSE_NULL)
@ -693,7 +693,7 @@ static int fnc_split (
else else
{ {
fs_ptr = qse_awk_rtx_valtostr ( 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 (fs_ptr == QSE_NULL)
{ {
if (str_free != QSE_NULL) if (str_free != QSE_NULL)
@ -861,7 +861,7 @@ static int fnc_tolower (
else else
{ {
str = qse_awk_rtx_valtostr ( 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; if (str == QSE_NULL) return -1;
} }
@ -901,7 +901,7 @@ static int fnc_toupper (
else else
{ {
str = qse_awk_rtx_valtostr ( 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; if (str == QSE_NULL) return -1;
} }
@ -968,7 +968,7 @@ static int __substitute (qse_awk_rtx_t* run, qse_long_t max_count)
else else
{ {
a0_ptr = qse_awk_rtx_valtostr ( 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) if (a0_ptr == QSE_NULL)
{ {
FREE_A_PTRS (run->awk); FREE_A_PTRS (run->awk);
@ -985,7 +985,7 @@ static int __substitute (qse_awk_rtx_t* run, qse_long_t max_count)
else else
{ {
a1_ptr = qse_awk_rtx_valtostr ( 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) if (a1_ptr == QSE_NULL)
{ {
FREE_A_PTRS (run->awk); FREE_A_PTRS (run->awk);
@ -1041,7 +1041,7 @@ static int __substitute (qse_awk_rtx_t* run, qse_long_t max_count)
else else
{ {
a2_ptr = qse_awk_rtx_valtostr ( 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) if (a2_ptr == QSE_NULL)
{ {
FREE_A_PTRS (run->awk); FREE_A_PTRS (run->awk);
@ -1250,7 +1250,7 @@ static int fnc_match (
else else
{ {
str0 = qse_awk_rtx_valtostr ( 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; if (str0 == QSE_NULL) return -1;
} }
@ -1268,7 +1268,7 @@ static int fnc_match (
else else
{ {
str1 = qse_awk_rtx_valtostr ( 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 (str1 == QSE_NULL)
{ {
if (a0->type != QSE_AWK_VAL_STR) if (a0->type != QSE_AWK_VAL_STR)
@ -1374,7 +1374,7 @@ static int fnc_sprintf (
else else
{ {
cs0.ptr = qse_awk_rtx_valtostr ( 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) if (cs0.ptr == QSE_NULL)
{ {
qse_str_fini (&fbu); qse_str_fini (&fbu);

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -123,7 +123,7 @@ static int split_record (qse_awk_rtx_t* run)
else else
{ {
fs_ptr = qse_awk_rtx_valtostr ( 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; if (fs_ptr == QSE_NULL) return -1;
fs_free = fs_ptr; fs_free = fs_ptr;
} }

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -218,7 +218,7 @@ int qse_awk_rtx_readio (
else else
{ {
rs_ptr = qse_awk_rtx_valtostr ( 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) if (rs_ptr == QSE_NULL)
{ {
qse_awk_rtx_refdownval (run, rs); qse_awk_rtx_refdownval (run, rs);
@ -426,7 +426,7 @@ int qse_awk_rtx_writeio_val (
{ {
str = qse_awk_rtx_valtostr ( str = qse_awk_rtx_valtostr (
run, v, run, v,
QSE_AWK_VALTOSTR_CLEAR | QSE_AWK_VALTOSTR_PRINT, QSE_AWK_RTX_VALTOSTR_CLEAR | QSE_AWK_RTX_VALTOSTR_PRINT,
QSE_NULL, &len); QSE_NULL, &len);
if (str == QSE_NULL) return -1; if (str == QSE_NULL) return -1;
} }

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -315,7 +315,7 @@ static int set_global (
qse_size_t convfmt_len, i; qse_size_t convfmt_len, i;
convfmt_ptr = qse_awk_rtx_valtostr (run, 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; if (convfmt_ptr == QSE_NULL) return -1;
for (i = 0; i < convfmt_len; i++) for (i = 0; i < convfmt_len; i++)
@ -362,7 +362,7 @@ static int set_global (
QSE_ASSERT (val->type != QSE_AWK_VAL_REX); QSE_ASSERT (val->type != QSE_AWK_VAL_REX);
fs_ptr = qse_awk_rtx_valtostr ( 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; if (fs_ptr == QSE_NULL) return -1;
} }
@ -443,7 +443,7 @@ static int set_global (
qse_size_t ofmt_len, i; qse_size_t ofmt_len, i;
ofmt_ptr = qse_awk_rtx_valtostr ( 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; if (ofmt_ptr == QSE_NULL) return -1;
for (i = 0; i < ofmt_len; i++) for (i = 0; i < ofmt_len; i++)
@ -467,7 +467,7 @@ static int set_global (
qse_size_t ofs_len; qse_size_t ofs_len;
ofs_ptr = qse_awk_rtx_valtostr ( 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 (ofs_ptr == QSE_NULL) return -1;
if (run->gbl.ofs.ptr != QSE_NULL) if (run->gbl.ofs.ptr != QSE_NULL)
@ -481,7 +481,7 @@ static int set_global (
qse_size_t ors_len; qse_size_t ors_len;
ors_ptr = qse_awk_rtx_valtostr ( 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 (ors_ptr == QSE_NULL) return -1;
if (run->gbl.ors.ptr != QSE_NULL) if (run->gbl.ors.ptr != QSE_NULL)
@ -506,7 +506,7 @@ static int set_global (
QSE_ASSERT (val->type != QSE_AWK_VAL_REX); QSE_ASSERT (val->type != QSE_AWK_VAL_REX);
rs_ptr = qse_awk_rtx_valtostr ( 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; if (rs_ptr == QSE_NULL) return -1;
} }
@ -540,7 +540,7 @@ static int set_global (
qse_size_t subsep_len; qse_size_t subsep_len;
subsep_ptr = qse_awk_rtx_valtostr ( 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 (subsep_ptr == QSE_NULL) return -1;
if (run->gbl.subsep.ptr != QSE_NULL) 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); qse_awk_rtx_refupval (data->rtx, data->val);
} }
static int enter_stack_frame (qse_awk_rtx_t* run) static int enter_stack_frame (qse_awk_rtx_t* run)
{ {
qse_size_t saved_stack_top; qse_size_t saved_stack_top;
@ -1462,11 +1461,13 @@ int qse_awk_rtx_loop (qse_awk_rtx_t* rtx)
} }
/* call an AWK function */ /* 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_rtx_t* rtx, const qse_char_t* name,
qse_awk_val_t** args, qse_size_t nargs) qse_awk_val_t** args, qse_size_t nargs)
{ {
#if 0
int ret = 0; int ret = 0;
#endif
qse_map_pair_t* pair; qse_map_pair_t* pair;
qse_awk_fun_t* fun; qse_awk_fun_t* fun;
struct capture_retval_data_t crdata; struct capture_retval_data_t crdata;
@ -1479,7 +1480,7 @@ int qse_awk_rtx_call (
/* cannot call the function again when exit() is called /* cannot call the function again when exit() is called
* in an AWK program or qse_awk_rtx_stop() is invoked */ * in an AWK program or qse_awk_rtx_stop() is invoked */
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOPER, 0, QSE_NULL); qse_awk_rtx_seterror (rtx, QSE_AWK_ENOPER, 0, QSE_NULL);
return -1; return QSE_NULL;
} }
/*rtx->exit_level = EXIT_NONE;*/ /*rtx->exit_level = EXIT_NONE;*/
@ -1503,7 +1504,7 @@ int qse_awk_rtx_call (
errarg.len = call.what.fun.name.len; errarg.len = call.what.fun.name.len;
qse_awk_rtx_seterror (rtx, QSE_AWK_EFUNNONE, 0, &errarg); qse_awk_rtx_seterror (rtx, QSE_AWK_EFUNNONE, 0, &errarg);
return -1; return QSE_NULL;
} }
fun = (qse_awk_fun_t*)QSE_MAP_VPTR(pair); 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 /* TODO: is this correct? what if i want to
* allow arbitarary numbers of arguments? */ * allow arbitarary numbers of arguments? */
qse_awk_rtx_seterror (rtx, QSE_AWK_EARGTM, 0, QSE_NULL); 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 */ /* now that the function is found and ok, let's execute it */
@ -1532,8 +1533,44 @@ int qse_awk_rtx_call (
if (v == QSE_NULL) 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) if (crdata.val == QSE_NULL)
{ {
/* no return value has been caputured. this must
* be an error */
QSE_ASSERT (rtx->errnum != QSE_AWK_ENOERR); QSE_ASSERT (rtx->errnum != QSE_AWK_ENOERR);
v = qse_awk_val_nil; /* defaults to nil */ v = qse_awk_val_nil; /* defaults to nil */
ret = -1; ret = -1;
@ -1556,17 +1593,19 @@ int qse_awk_rtx_call (
} }
else else
{ {
/* the reference count of crdata.val is updated in /* the return value captured in termination by exit()
* capture_retval_on_exit(). update reference count of * is reference-counted up in capture_retval_on_exit().
* v here to balance it */ * let's do the same thing for the return value normally
* returned. */
qse_awk_rtx_refupval (rtx, v); qse_awk_rtx_refupval (rtx, v);
} }
if (rtx->rcb.on_exit != QSE_NULL) if (rtx->rcb.on_exit != QSE_NULL)
rtx->rcb.on_exit (rtx, v, rtx->rcb.data); rtx->rcb.on_exit (rtx, v, rtx->rcb.data);
qse_awk_rtx_refdownval (rtx, v);
qse_awk_rtx_refdownval (rtx, v);
return ret; return ret;
#endif
} }
static int run_pattern_blocks (qse_awk_rtx_t* run) 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 */ /* try with a fixed-size buffer */
keylen = QSE_COUNTOF(buf); keylen = QSE_COUNTOF(buf);
key = qse_awk_rtx_valtostr ( key = qse_awk_rtx_valtostr (
run, idx, QSE_AWK_VALTOSTR_FIXED, run, idx, QSE_AWK_RTX_VALTOSTR_FIXED,
(qse_str_t*)buf, &keylen); (qse_str_t*)buf, &keylen);
if (key == QSE_NULL) if (key == QSE_NULL)
{ {
/* if it doesn't work, switch to dynamic mode */ /* if it doesn't work, switch to dynamic mode */
key = qse_awk_rtx_valtostr ( key = qse_awk_rtx_valtostr (
run, idx, QSE_AWK_VALTOSTR_CLEAR, run, idx, QSE_AWK_RTX_VALTOSTR_CLEAR,
QSE_NULL, &keylen); 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 */ /* try with a fixed-size buffer */
keylen = QSE_COUNTOF(buf); keylen = QSE_COUNTOF(buf);
key = qse_awk_rtx_valtostr ( key = qse_awk_rtx_valtostr (
run, idx, QSE_AWK_VALTOSTR_FIXED, run, idx, QSE_AWK_RTX_VALTOSTR_FIXED,
(qse_str_t*)buf, &keylen); (qse_str_t*)buf, &keylen);
if (key == QSE_NULL) if (key == QSE_NULL)
{ {
/* if it doesn't work, switch to dynamic mode */ /* if it doesn't work, switch to dynamic mode */
key = qse_awk_rtx_valtostr ( key = qse_awk_rtx_valtostr (
run, idx, QSE_AWK_VALTOSTR_CLEAR, run, idx, QSE_AWK_RTX_VALTOSTR_CLEAR,
QSE_NULL, &keylen); 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); qse_awk_rtx_refupval (run, v);
out = qse_awk_rtx_valtostr ( 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) if (out == QSE_NULL)
{ {
qse_awk_rtx_refdownval (run, v); 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); qse_awk_rtx_refupval (run, v);
out = qse_awk_rtx_valtostr ( 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) if (out == QSE_NULL)
{ {
qse_awk_rtx_refdownval (run, v); qse_awk_rtx_refdownval (run, v);
@ -3585,7 +3624,7 @@ static qse_awk_val_t* do_assignment_pos (
else else
{ {
str = qse_awk_rtx_valtostr ( 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) if (str == QSE_NULL)
{ {
/* change error line */ /* change error line */
@ -4038,7 +4077,7 @@ static int __cmp_int_str (
} }
str = qse_awk_rtx_valtostr ( 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 (str == QSE_NULL) return CMP_ERROR;
if (run->gbl.ignorecase) if (run->gbl.ignorecase)
@ -4110,7 +4149,7 @@ static int __cmp_real_str (
} }
str = qse_awk_rtx_valtostr ( 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 (str == QSE_NULL) return CMP_ERROR;
if (run->gbl.ignorecase) if (run->gbl.ignorecase)
@ -4630,11 +4669,11 @@ static qse_awk_val_t* eval_binop_concat (
qse_awk_val_t* res; qse_awk_val_t* res;
strl = qse_awk_rtx_valtostr ( 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; if (strl == QSE_NULL) return QSE_NULL;
strr = qse_awk_rtx_valtostr ( 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) if (strr == QSE_NULL)
{ {
QSE_AWK_FREE (run->awk, strl); QSE_AWK_FREE (run->awk, strl);
@ -4739,7 +4778,7 @@ static qse_awk_val_t* eval_binop_match0 (
else else
{ {
str = qse_awk_rtx_valtostr ( 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; if (str == QSE_NULL) return QSE_NULL;
rex_code = QSE_AWK_BUILDREX (run->awk, str, len, &errnum); rex_code = QSE_AWK_BUILDREX (run->awk, str, len, &errnum);
@ -4785,7 +4824,7 @@ static qse_awk_val_t* eval_binop_match0 (
else else
{ {
str = qse_awk_rtx_valtostr ( 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 (str == QSE_NULL)
{ {
if (right->type != QSE_AWK_VAL_REX) 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 ( 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_nde_call_t* call = (qse_awk_nde_call_t*)nde;
qse_awk_fun_t* fun; 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) \ while ((nargs) > 0) \
{ \ { \
--(nargs); \ --(nargs); \
qse_awk_rtx_refdownval ((rtx), \ qse_awk_rtx_refdownval ((rtx), (rtx)->stack[(rtx)->stack_top-1]); \
(rtx)->stack[(rtx)->stack_top-1]); \
__raw_pop (rtx); \ __raw_pop (rtx); \
} \ } \
} while (0) } 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) 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 * any reference. but its reference has not been
* updated yet as it is carried out after the * updated yet as it is carried out after successful
* successful stack push. so it adds up a reference * stack push. so it adds up a reference and
* and dereferences it */ * dereferences it */
qse_awk_rtx_refupval (rtx, pafv->args[nargs]); qse_awk_rtx_refupval (rtx, pafv->args[nargs]);
qse_awk_rtx_refdownval (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); rtx, QSE_AWK_ENOMEM, call->line, QSE_NULL);
return (qse_size_t)-1; return (qse_size_t)-1;
} }
qse_awk_rtx_refupval (rtx, pafv->args[nargs]);
} }
return 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 */ * should not be called immediately below */
qse_awk_rtx_refupval (run, v); qse_awk_rtx_refupval (run, v);
in = qse_awk_rtx_valtostr ( 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) if (in == QSE_NULL)
{ {
qse_awk_rtx_refdownval (run, v); qse_awk_rtx_refdownval (run, v);
@ -6450,7 +6491,7 @@ static int shorten_record (qse_awk_rtx_t* run, qse_size_t nflds)
else else
{ {
ofs = qse_awk_rtx_valtostr ( ofs = qse_awk_rtx_valtostr (
run, v, QSE_AWK_VALTOSTR_CLEAR, run, v, QSE_AWK_RTX_VALTOSTR_CLEAR,
QSE_NULL, &ofs_len); QSE_NULL, &ofs_len);
if (ofs == QSE_NULL) return -1; if (ofs == QSE_NULL) return -1;
@ -6534,14 +6575,14 @@ static qse_char_t* idxnde_to_str (
{ {
/* try with a fixed-size buffer */ /* try with a fixed-size buffer */
str = qse_awk_rtx_valtostr ( 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 (str == QSE_NULL)
{ {
/* if it doen't work, switch to the dynamic mode */ /* if it doen't work, switch to the dynamic mode */
str = qse_awk_rtx_valtostr ( 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) if (str == QSE_NULL)
{ {
@ -7250,8 +7291,11 @@ qse_char_t* qse_awk_rtx_format (
return QSE_NULL; return QSE_NULL;
} }
str = qse_awk_rtx_valtostr (run, v, str = qse_awk_rtx_valtostr (
QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &str_len); run, v,
QSE_AWK_RTX_VALTOSTR_CLEAR,
QSE_NULL, &str_len
);
if (str == QSE_NULL) if (str == QSE_NULL)
{ {
qse_awk_rtx_refdownval (run, v); qse_awk_rtx_refdownval (run, v);

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -1,5 +1,5 @@
/* /*
* $Id$ * $Id: std.c 75 2009-02-22 14:10:34Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -17,6 +17,7 @@
*/ */
#include "awk.h" #include "awk.h"
#include <qse/awk/std.h>
#include <qse/cmn/sio.h> #include <qse/cmn/sio.h>
#include <qse/cmn/pio.h> #include <qse/cmn/pio.h>
#include <qse/cmn/str.h> #include <qse/cmn/str.h>
@ -33,33 +34,33 @@ typedef struct xtn_t
{ {
struct struct
{ {
qse_awk_parsesimple_type_t type; qse_awk_parsestd_type_t type;
union union
{ {
const qse_char_t* file; const qse_char_t* file;
const qse_char_t* str; const qse_char_t* cp;
struct struct
{ {
const qse_char_t* ptr; const qse_char_t* ptr;
const qse_char_t* end; const qse_char_t* end;
} strl; } cpl;
} u; } u;
qse_sio_t* handle; /* the handle to an open file */ qse_sio_t* handle; /* the handle to an open file */
} in; } in;
struct struct
{ {
qse_awk_parsesimple_type_t type; qse_awk_parsestd_type_t type;
union union
{ {
const qse_char_t* file; const qse_char_t* file;
qse_char_t* str; qse_char_t* cp;
struct struct
{ {
qse_xstr_t* osp; qse_xstr_t* osp;
qse_char_t* ptr; qse_char_t* ptr;
qse_char_t* end; qse_char_t* end;
} strl; } cpl;
} u; } u;
qse_sio_t* handle; qse_sio_t* handle;
} out; } out;
@ -88,7 +89,7 @@ typedef struct rxtn_t
} 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_T(""),
QSE_NULL QSE_NULL
@ -137,7 +138,7 @@ static qse_cint_t custom_awk_toccls (
static int add_functions (qse_awk_t* awk); 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_t* awk;
qse_awk_prm_t prm; qse_awk_prm_t prm;
@ -156,9 +157,6 @@ qse_awk_t* qse_awk_opensimple (void)
xtn = (xtn_t*) QSE_XTN (awk); xtn = (xtn_t*) QSE_XTN (awk);
QSE_MEMSET (xtn, 0, QSE_SIZEOF(xtn_t)); QSE_MEMSET (xtn, 0, QSE_SIZEOF(xtn_t));
/* set default options */
qse_awk_setoption (awk, QSE_AWK_CLASSIC);
/* add intrinsic functions */ /* add intrinsic functions */
if (add_functions (awk) == -1) if (add_functions (awk) == -1)
{ {
@ -169,7 +167,7 @@ qse_awk_t* qse_awk_opensimple (void)
return awk; return awk;
} }
/*** PARSESIMPLE ***/ /*** PARSESTD ***/
static qse_ssize_t sf_in ( static qse_ssize_t sf_in (
qse_awk_t* awk, qse_awk_sio_cmd_t cmd, 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) 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; if (xtn->s.in.u.file == QSE_NULL) return -1;
xtn->s.in.handle = qse_sio_open ( 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; if (xtn->s.in.handle == QSE_NULL) return -1;
return 1; return 1;
case QSE_AWK_PARSESIMPLE_STDIO: case QSE_AWK_PARSESTD_STDIO:
xtn->s.in.handle = qse_sio_in; xtn->s.in.handle = qse_sio_in;
return 1; return 1;
case QSE_AWK_PARSESIMPLE_STR: case QSE_AWK_PARSESTD_CP:
case QSE_AWK_PARSESIMPLE_STRL: case QSE_AWK_PARSESTD_CPL:
xtn->s.in.handle = QSE_NULL; xtn->s.in.handle = QSE_NULL;
return 1; return 1;
} }
@ -219,27 +217,27 @@ static qse_ssize_t sf_in (
{ {
switch (xtn->s.in.type) switch (xtn->s.in.type)
{ {
case QSE_AWK_PARSESIMPLE_FILE: case QSE_AWK_PARSESTD_FILE:
case QSE_AWK_PARSESIMPLE_STDIO: case QSE_AWK_PARSESTD_STDIO:
QSE_ASSERT (xtn->s.in.handle != QSE_NULL); QSE_ASSERT (xtn->s.in.handle != QSE_NULL);
return qse_sio_getsn (xtn->s.in.handle, data, size); 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; 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; return n;
} }
case QSE_AWK_PARSESIMPLE_STRL: case QSE_AWK_PARSESTD_CPL:
{ {
qse_size_t n = 0; 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; return n;
} }
@ -260,7 +258,7 @@ static qse_ssize_t sf_out (
{ {
switch (xtn->s.out.type) 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; if (xtn->s.out.u.file == QSE_NULL) return -1;
xtn->s.out.handle = qse_sio_open ( 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; if (xtn->s.out.handle == QSE_NULL) return -1;
return 1; return 1;
case QSE_AWK_PARSESIMPLE_STDIO: case QSE_AWK_PARSESTD_STDIO:
xtn->s.out.handle = qse_sio_out; xtn->s.out.handle = qse_sio_out;
return 1; return 1;
case QSE_AWK_PARSESIMPLE_STR: case QSE_AWK_PARSESTD_CP:
case QSE_AWK_PARSESIMPLE_STRL: case QSE_AWK_PARSESTD_CPL:
xtn->s.out.handle = QSE_NULL; xtn->s.out.handle = QSE_NULL;
return 1; return 1;
} }
@ -288,8 +286,8 @@ static qse_ssize_t sf_out (
{ {
switch (xtn->s.out.type) switch (xtn->s.out.type)
{ {
case QSE_AWK_PARSESIMPLE_FILE: case QSE_AWK_PARSESTD_FILE:
case QSE_AWK_PARSESIMPLE_STDIO: case QSE_AWK_PARSESTD_STDIO:
qse_sio_flush (xtn->s.out.handle); qse_sio_flush (xtn->s.out.handle);
if (xtn->s.out.handle != qse_sio_in && if (xtn->s.out.handle != qse_sio_in &&
@ -300,14 +298,14 @@ static qse_ssize_t sf_out (
} }
return 0; return 0;
case QSE_AWK_PARSESIMPLE_STR: case QSE_AWK_PARSESTD_CP:
*xtn->s.out.u.str = QSE_T('\0'); *xtn->s.out.u.cp = QSE_T('\0');
return 0; return 0;
case QSE_AWK_PARSESIMPLE_STRL: case QSE_AWK_PARSESTD_CPL:
xtn->s.out.u.strl.osp->len = xtn->s.out.u.cpl.osp->len =
xtn->s.out.u.strl.ptr - xtn->s.out.u.cpl.ptr -
xtn->s.out.u.strl.osp->ptr; xtn->s.out.u.cpl.osp->ptr;
return 0; return 0;
} }
} }
@ -315,27 +313,27 @@ static qse_ssize_t sf_out (
{ {
switch (xtn->s.out.type) switch (xtn->s.out.type)
{ {
case QSE_AWK_PARSESIMPLE_FILE: case QSE_AWK_PARSESTD_FILE:
case QSE_AWK_PARSESIMPLE_STDIO: case QSE_AWK_PARSESTD_STDIO:
QSE_ASSERT (xtn->s.out.handle != QSE_NULL); QSE_ASSERT (xtn->s.out.handle != QSE_NULL);
return qse_sio_putsn (xtn->s.out.handle, data, size); 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; 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; return n;
} }
case QSE_AWK_PARSESIMPLE_STRL: case QSE_AWK_PARSESTD_CPL:
{ {
qse_size_t n = 0; 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; return n;
} }
@ -345,10 +343,10 @@ static qse_ssize_t sf_out (
return -1; return -1;
} }
int qse_awk_parsesimple ( int qse_awk_parsestd (
qse_awk_t* awk, qse_awk_t* awk,
const qse_awk_parsesimple_in_t* in, const qse_awk_parsestd_in_t* in,
qse_awk_parsesimple_out_t* out) qse_awk_parsestd_out_t* out)
{ {
qse_awk_sio_t sio; qse_awk_sio_t sio;
xtn_t* xtn = (xtn_t*) QSE_XTN (awk); xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
@ -362,20 +360,20 @@ int qse_awk_parsesimple (
switch (in->type) switch (in->type)
{ {
case QSE_AWK_PARSESIMPLE_FILE: case QSE_AWK_PARSESTD_FILE:
xtn->s.in.u.file = in->u.file; xtn->s.in.u.file = in->u.file;
break; break;
case QSE_AWK_PARSESIMPLE_STR: case QSE_AWK_PARSESTD_CP:
xtn->s.in.u.str = in->u.str; xtn->s.in.u.cp = in->u.cp;
break; break;
case QSE_AWK_PARSESIMPLE_STRL: case QSE_AWK_PARSESTD_CPL:
xtn->s.in.u.strl.ptr = in->u.strl.ptr; xtn->s.in.u.cpl.ptr = in->u.cpl.ptr;
xtn->s.in.u.strl.end = in->u.strl.ptr + in->u.strl.len; xtn->s.in.u.cpl.end = in->u.cpl.ptr + in->u.cpl.len;
break; break;
case QSE_AWK_PARSESIMPLE_STDIO: case QSE_AWK_PARSESTD_STDIO:
/* nothing to do */ /* nothing to do */
break; break;
@ -392,21 +390,21 @@ int qse_awk_parsesimple (
{ {
switch (out->type) switch (out->type)
{ {
case QSE_AWK_PARSESIMPLE_FILE: case QSE_AWK_PARSESTD_FILE:
xtn->s.out.u.file = out->u.file; xtn->s.out.u.file = out->u.file;
break; break;
case QSE_AWK_PARSESIMPLE_STR: case QSE_AWK_PARSESTD_CP:
xtn->s.out.u.str = out->u.str; xtn->s.out.u.cp = out->u.cp;
break; break;
case QSE_AWK_PARSESIMPLE_STRL: case QSE_AWK_PARSESTD_CPL:
xtn->s.out.u.strl.osp = &out->u.strl; xtn->s.out.u.cpl.osp = &out->u.cpl;
xtn->s.out.u.strl.ptr = out->u.strl.ptr; xtn->s.out.u.cpl.ptr = out->u.cpl.ptr;
xtn->s.out.u.strl.end = out->u.strl.ptr + out->u.strl.len; xtn->s.out.u.cpl.end = out->u.cpl.ptr + out->u.cpl.len;
break; break;
case QSE_AWK_PARSESIMPLE_STDIO: case QSE_AWK_PARSESTD_STDIO:
/* nothing to do */ /* nothing to do */
break; break;
@ -422,8 +420,7 @@ int qse_awk_parsesimple (
return qse_awk_parse (awk, &sio); return qse_awk_parse (awk, &sio);
} }
/*** RUNSIMPLE ***/ /*** RTX_OPENSTD ***/
static qse_ssize_t awk_rio_pipe ( static qse_ssize_t awk_rio_pipe (
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_riod_t* riod, qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_riod_t* riod,
qse_char_t* data, qse_size_t size) qse_char_t* data, qse_size_t size)
@ -876,7 +873,7 @@ static qse_ssize_t awk_rio_console (
return -1; return -1;
} }
qse_awk_rtx_t* qse_awk_rtx_opensimple ( qse_awk_rtx_t* qse_awk_rtx_openstd (
qse_awk_t* awk, qse_awk_t* awk,
const qse_char_t*const* icf, const qse_char_t*const* icf,
const qse_char_t*const* ocf) 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 else
{ {
str = qse_awk_rtx_valtostr ( 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; if (str == QSE_NULL) return -1;
} }

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.

View File

@ -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. 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) 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); qse_map_fini (((qse_awk_val_map_t*)val)->map);
/* END CHECK */
QSE_AWK_FREE (rtx->awk, val); QSE_AWK_FREE (rtx->awk, val);
} }
else if (val->type == QSE_AWK_VAL_REF) 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; if (len != QSE_NULL) *len = str_len;
return tmp; 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); QSE_ASSERT (buf != QSE_NULL && len != QSE_NULL);
@ -816,7 +813,7 @@ static qse_char_t* str_to_str (
{ {
qse_size_t n; 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); n = qse_str_ncat (buf, str, str_len);
if (n == (qse_size_t)-1) if (n == (qse_size_t)-1)
{ {
@ -857,7 +854,7 @@ static qse_char_t* val_int_to_str (
if (len != QSE_NULL) *len = 1; if (len != QSE_NULL) *len = 1;
return tmp; 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); QSE_ASSERT (buf != QSE_NULL && len != QSE_NULL);
@ -877,7 +874,7 @@ static qse_char_t* val_int_to_str (
} }
else 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) if (qse_str_cat (buf, QSE_T("0")) == (qse_size_t)-1)
{ {
qse_awk_rtx_seterror ( qse_awk_rtx_seterror (
@ -907,7 +904,7 @@ static qse_char_t* val_int_to_str (
tmp[rlen] = QSE_T('\0'); tmp[rlen] = QSE_T('\0');
if (len != QSE_NULL) *len = rlen; 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); QSE_ASSERT (buf != QSE_NULL && len != QSE_NULL);
@ -925,7 +922,7 @@ static qse_char_t* val_int_to_str (
else else
{ {
/* clear the buffer */ /* 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); 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 (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); tmp = QSE_STR_PTR(buf);
if (len != QSE_NULL) *len = QSE_STR_LEN(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_size_t tmp_len;
qse_str_t out, fbu; qse_str_t out, fbu;
if (opt & QSE_AWK_VALTOSTR_PRINT) if (opt & QSE_AWK_RTX_VALTOSTR_PRINT)
{ {
tmp = run->gbl.ofmt.ptr; tmp = run->gbl.ofmt.ptr;
tmp_len = run->gbl.ofmt.len; 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; 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); QSE_ASSERT (buf != QSE_NULL && len != QSE_NULL);
@ -1032,7 +1029,7 @@ static qse_char_t* val_real_to_str (
} }
else 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) if (qse_str_ncat (buf, tmp, tmp_len) == (qse_size_t)-1)
{ {

View File

@ -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. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -23,6 +23,12 @@
extern "C" { extern "C" {
#endif #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 ( void qse_awk_rtx_freevalchunk (
qse_awk_rtx_t* rtx, qse_awk_rtx_t* rtx,
qse_awk_val_chunk_t* chunk qse_awk_val_chunk_t* chunk

View File

@ -1,6 +1,6 @@
AM_CPPFLAGS = -I$(top_srcdir)/include 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 LDFLAGS = -L../../lib/cmn -L../../lib/utl -L../../lib/awk
LDADD = -lqseawk -lqseutl -lqsecmn $(LIBM) LDADD = -lqseawk -lqseutl -lqsecmn $(LIBM)
@ -8,3 +8,4 @@ LDADD = -lqseawk -lqseutl -lqsecmn $(LIBM)
awk01_SOURCES = awk01.c awk01_SOURCES = awk01.c
awk02_SOURCES = awk02.c awk02_SOURCES = awk02.c
awk03_SOURCES = awk03.c awk03_SOURCES = awk03.c
awk04_SOURCES = awk04.c

View File

@ -32,7 +32,8 @@ PRE_UNINSTALL = :
POST_UNINSTALL = : POST_UNINSTALL = :
build_triplet = @build@ build_triplet = @build@
host_triplet = @host@ host_triplet = @host@
bin_PROGRAMS = awk01$(EXEEXT) awk02$(EXEEXT) awk03$(EXEEXT) bin_PROGRAMS = awk01$(EXEEXT) awk02$(EXEEXT) awk03$(EXEEXT) \
awk04$(EXEEXT)
subdir = test/awk subdir = test/awk
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@ -58,6 +59,10 @@ am_awk03_OBJECTS = awk03.$(OBJEXT)
awk03_OBJECTS = $(am_awk03_OBJECTS) awk03_OBJECTS = $(am_awk03_OBJECTS)
awk03_LDADD = $(LDADD) awk03_LDADD = $(LDADD)
awk03_DEPENDENCIES = $(am__DEPENDENCIES_1) 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 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include/qse
depcomp = $(SHELL) $(top_srcdir)/autoconf/depcomp depcomp = $(SHELL) $(top_srcdir)/autoconf/depcomp
am__depfiles_maybe = depfiles am__depfiles_maybe = depfiles
@ -70,8 +75,10 @@ CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@ $(LDFLAGS) -o $@
SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) \
DIST_SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) $(awk04_SOURCES)
DIST_SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) \
$(awk04_SOURCES)
ETAGS = etags ETAGS = etags
CTAGS = ctags CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -201,6 +208,7 @@ LDADD = -lqseawk -lqseutl -lqsecmn $(LIBM)
awk01_SOURCES = awk01.c awk01_SOURCES = awk01.c
awk02_SOURCES = awk02.c awk02_SOURCES = awk02.c
awk03_SOURCES = awk03.c awk03_SOURCES = awk03.c
awk04_SOURCES = awk04.c
all: all-am all: all-am
.SUFFIXES: .SUFFIXES:
@ -271,6 +279,9 @@ awk02$(EXEEXT): $(awk02_OBJECTS) $(awk02_DEPENDENCIES)
awk03$(EXEEXT): $(awk03_OBJECTS) $(awk03_DEPENDENCIES) awk03$(EXEEXT): $(awk03_OBJECTS) $(awk03_DEPENDENCIES)
@rm -f awk03$(EXEEXT) @rm -f awk03$(EXEEXT)
$(LINK) $(awk03_OBJECTS) $(awk03_LDADD) $(LIBS) $(LINK) $(awk03_OBJECTS) $(awk03_LDADD) $(LIBS)
awk04$(EXEEXT): $(awk04_OBJECTS) $(awk04_DEPENDENCIES)
@rm -f awk04$(EXEEXT)
$(LINK) $(awk04_OBJECTS) $(awk04_LDADD) $(LIBS)
mostlyclean-compile: mostlyclean-compile:
-rm -f *.$(OBJEXT) -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)/awk01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk02.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)/awk03.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk04.Po@am__quote@
.c.o: .c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<

View File

@ -23,6 +23,7 @@
*/ */
#include <qse/awk/awk.h> #include <qse/awk/awk.h>
#include <qse/awk/std.h>
#include <qse/utl/stdio.h> #include <qse/utl/stdio.h>
const qse_char_t* src = QSE_T( const qse_char_t* src = QSE_T(
@ -40,20 +41,20 @@ int main ()
{ {
qse_awk_t* awk = QSE_NULL; qse_awk_t* awk = QSE_NULL;
qse_awk_rtx_t* rtx = QSE_NULL; qse_awk_rtx_t* rtx = QSE_NULL;
qse_awk_parsesimple_in_t psin; qse_awk_parsestd_in_t psin;
int ret; int ret;
awk = qse_awk_opensimple (); awk = qse_awk_openstd ();
if (awk == QSE_NULL) if (awk == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n"));
goto oops; goto oops;
} }
psin.type = QSE_AWK_PARSESIMPLE_STR; psin.type = QSE_AWK_PARSESTD_CP;
psin.u.str = src; psin.u.cp = src;
ret = qse_awk_parsesimple (awk, &psin, QSE_NULL); ret = qse_awk_parsestd (awk, &psin, QSE_NULL);
if (ret == -1) if (ret == -1)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
@ -61,10 +62,10 @@ int main ()
goto oops; goto oops;
} }
rtx = qse_awk_rtx_opensimple ( rtx = qse_awk_rtx_openstd (
awk, awk,
QSE_NULL, /* no console input */ QSE_NULL, /* no console input */
QSE_AWK_RTX_OPENSIMPLE_STDIO /* stdout for console output */ QSE_AWK_RTX_OPENSTD_STDIO /* stdout for console output */
); );
if (rtx == QSE_NULL) if (rtx == QSE_NULL)
{ {

View File

@ -23,6 +23,7 @@
*/ */
#include <qse/awk/awk.h> #include <qse/awk/awk.h>
#include <qse/awk/std.h>
#include <qse/cmn/mem.h> #include <qse/cmn/mem.h>
#include <qse/utl/stdio.h> #include <qse/utl/stdio.h>
@ -44,12 +45,12 @@ int main ()
qse_awk_t* awk = QSE_NULL; qse_awk_t* awk = QSE_NULL;
qse_awk_rtx_t* rtx = QSE_NULL; qse_awk_rtx_t* rtx = QSE_NULL;
qse_awk_parsesimple_in_t psin; qse_awk_parsestd_in_t psin;
qse_awk_parsesimple_out_t psout; qse_awk_parsestd_out_t psout;
int ret; int ret;
awk = qse_awk_opensimple (); awk = qse_awk_openstd ();
if (awk == QSE_NULL) if (awk == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); 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); qse_memset (srcout, QSE_T(' '), QSE_COUNTOF(srcout)-1);
srcout[QSE_COUNTOF(srcout)-1] = QSE_T('\0'); srcout[QSE_COUNTOF(srcout)-1] = QSE_T('\0');
psin.type = QSE_AWK_PARSESIMPLE_STR; psin.type = QSE_AWK_PARSESTD_CP;
psin.u.str = src; psin.u.cp = src;
psout.type = QSE_AWK_PARSESIMPLE_STR; psout.type = QSE_AWK_PARSESTD_CP;
psout.u.str = srcout; psout.u.cp = srcout;
ret = qse_awk_parsesimple (awk, &psin, &psout); ret = qse_awk_parsestd (awk, &psin, &psout);
if (ret == -1) if (ret == -1)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
@ -76,10 +77,10 @@ int main ()
qse_printf (QSE_T("=================================\n")); qse_printf (QSE_T("=================================\n"));
qse_fflush (QSE_STDOUT); qse_fflush (QSE_STDOUT);
rtx = qse_awk_rtx_opensimple ( rtx = qse_awk_rtx_openstd (
awk, awk,
QSE_NULL, /* no console input */ QSE_NULL, /* no console input */
QSE_AWK_RTX_OPENSIMPLE_STDIO /* stdout for console output */ QSE_AWK_RTX_OPENSTD_STDIO /* stdout for console output */
); );
if (rtx == QSE_NULL) if (rtx == QSE_NULL)
{ {

View File

@ -25,12 +25,13 @@
*/ */
#include <qse/awk/awk.h> #include <qse/awk/awk.h>
#include <qse/awk/std.h>
#include <qse/utl/stdio.h> #include <qse/utl/stdio.h>
static const qse_char_t* src = QSE_T( static const qse_char_t* src = QSE_T(
"function init() { a = 20; }" "function init() { a = 20; return a; }"
"function main() { a++; }" "function main() { return ++a; }"
"function fini() { print a; }" "function fini() { print ++a; return a; }"
); );
static const qse_char_t* fnc[] = static const qse_char_t* fnc[] =
@ -48,12 +49,12 @@ int main ()
qse_awk_t* awk = QSE_NULL; qse_awk_t* awk = QSE_NULL;
qse_awk_rtx_t* rtx = QSE_NULL; qse_awk_rtx_t* rtx = QSE_NULL;
qse_awk_parsesimple_in_t psin; qse_awk_parsestd_in_t psin;
int ret, i; int ret, i;
/* create a main processor */ /* create a main processor */
awk = qse_awk_opensimple (); awk = qse_awk_openstd ();
if (awk == QSE_NULL) if (awk == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); 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 */ /* don't allow BEGIN, END, pattern-action blocks */
qse_awk_setoption (awk, qse_awk_getoption(awk) & ~QSE_AWK_PABLOCK); qse_awk_setoption (awk, qse_awk_getoption(awk) & ~QSE_AWK_PABLOCK);
psin.type = QSE_AWK_PARSESIMPLE_STR; psin.type = QSE_AWK_PARSESTD_CP;
psin.u.str = src; psin.u.cp = src;
ret = qse_awk_parsesimple (awk, &psin, QSE_NULL); ret = qse_awk_parsestd (awk, &psin, QSE_NULL);
if (ret == -1) if (ret == -1)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"), qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
@ -75,10 +76,10 @@ int main ()
} }
/* create a runtime context */ /* create a runtime context */
rtx = qse_awk_rtx_opensimple ( rtx = qse_awk_rtx_openstd (
awk, awk,
QSE_NULL, /* no console input */ QSE_NULL, /* no console input */
QSE_AWK_RTX_OPENSIMPLE_STDIO /* stdout for console output */ QSE_AWK_RTX_OPENSTD_STDIO /* stdout for console output */
); );
if (rtx == QSE_NULL) if (rtx == QSE_NULL)
{ {
@ -90,13 +91,25 @@ int main ()
/* invoke functions as indicated in the array fnc */ /* invoke functions as indicated in the array fnc */
for (i = 0; i < QSE_COUNTOF(fnc); i++) for (i = 0; i < QSE_COUNTOF(fnc); i++)
{ {
ret = qse_awk_rtx_call (rtx, fnc[i], QSE_NULL, 0); qse_awk_val_t* v;
if (ret == -1) 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_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx)); 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: oops:

130
qse/test/awk/awk04.c Normal file
View File

@ -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 <qse/awk/awk.h>
#include <qse/awk/std.h>
#include <qse/utl/stdio.h>
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;
}
/******/