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:
2009-02-23 08:10:34 +00:00
parent 2e24e29e8c
commit d0ce35eacf
55 changed files with 615 additions and 363 deletions

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.

View File

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

View File

@ -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

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.

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.
@ -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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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}
*/

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}
*/

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.

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.

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.

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.

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.