revised docs

This commit is contained in:
hyung-hwan 2013-01-12 16:46:12 +00:00
parent 4581bf1e4e
commit ef6d295cac
49 changed files with 849 additions and 312 deletions

View File

@ -205,6 +205,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -186,6 +186,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -181,6 +181,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -637,7 +637,7 @@ static int comparg (int argc, qse_char_t* argv[], struct arg_t* arg)
isf[isfl].type = QSE_AWK_PARSESTD_FILE;
isf[isfl].u.file.path = opt.arg;
isf[isfl].cmgr = QSE_NULL;
isf[isfl].u.file.cmgr = QSE_NULL;
isfl++;
break;
}
@ -809,7 +809,11 @@ static int comparg (int argc, qse_char_t* argv[], struct arg_t* arg)
isfl++;
}
for (i = 0; i < isfl ; i++) isf[isfl].cmgr = arg->script_cmgr;
for (i = 0; i < isfl ; i++)
{
if (isf[i].type == QSE_AWK_PARSESTD_FILE)
isf[isfl].u.file.cmgr = arg->script_cmgr;
}
isf[isfl].type = QSE_AWK_PARSESTD_NULL;
arg->psin = isf;
@ -992,7 +996,7 @@ static int awk_main (int argc, qse_char_t* argv[])
{
psout.type = QSE_AWK_PARSESTD_FILE;
psout.u.file.path = arg.osf;
psout.cmgr = arg.script_cmgr;
psout.u.file.cmgr = arg.script_cmgr;
}
#if defined(QSE_BUILD_DEBUG)

View File

@ -175,6 +175,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -175,6 +175,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

10
qse/configure vendored
View File

@ -624,6 +624,8 @@ LTLIBOBJS
LIBOBJS
QSE_PROJECT_URL
QSE_PROJECT_AUTHOR
QSE_SIZEOF_OFF64_T
QSE_SIZEOF_OFF_T
QSE_SIZEOF_LONG_DOUBLE
QSE_SIZEOF_DOUBLE
QSE_SIZEOF_FLOAT
@ -1471,8 +1473,8 @@ Optional Features:
optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds)
--enable-ltdl-install install libltdl
--enable-wchar use wchar_t a default charater type when enabled
(default. yes)
--enable-wchar Use the wide character type as the default charater
type when enabled (default. yes)
--enable-bundled-unicode
use thn bundled unicode routines (default. no)
--enable-xcmgrs include more built-in cmgrs like cp949 and cp950
@ -20743,6 +20745,10 @@ QSE_SIZEOF_DOUBLE=$ac_cv_sizeof_double
QSE_SIZEOF_LONG_DOUBLE=$ac_cv_sizeof_long_double
QSE_SIZEOF_OFF_T=$ac_cv_sizeof_off_t
QSE_SIZEOF_OFF64_T=$ac_cv_sizeof_off64_t
QSE_PROJECT_AUTHOR="${PACKAGE_BUGREPORT}"

View File

@ -390,15 +390,15 @@ AC_C_BIGENDIAN(
[AC_DEFINE([QSE_ENDIAN_UNKNOWN],[],[Unknown Endian])])
dnl define extra options
AC_ARG_ENABLE([wchar], [AS_HELP_STRING([--enable-wchar],[use wchar_t a default charater type when enabled (default. yes)])],
AC_ARG_ENABLE([wchar], [AS_HELP_STRING([--enable-wchar],[Use the wide character type as the default charater type when enabled (default. yes)])],
enable_wchar_is=$enableval,enable_wchar_is=yes)
test "${ac_cv_sizeof_wchar_t}" = "0" && enable_wchar_is=no
if test "${enable_wchar_is}" = "yes"
then
AC_DEFINE([QSE_CHAR_IS_WCHAR],[],[char is wchar])
AC_DEFINE([QSE_CHAR_IS_WCHAR],[],[The default character type is the wide character type])
AC_SUBST(CHAR_MODE, "QSE_CHAR_IS_WCHAR")
else
AC_DEFINE([QSE_CHAR_IS_MCHAR],[],[char is mchar])
AC_DEFINE([QSE_CHAR_IS_MCHAR],[],[The default character type is the multi-byte character type])
AC_SUBST(CHAR_MODE, "QSE_CHAR_IS_MCHAR")
fi
AM_CONDITIONAL(WCHAR, test "${enable_wchar_is}" = "yes")
@ -480,6 +480,8 @@ AC_SUBST(QSE_SIZEOF_VOID_P, $ac_cv_sizeof_void_p)
AC_SUBST(QSE_SIZEOF_FLOAT, $ac_cv_sizeof_float)
AC_SUBST(QSE_SIZEOF_DOUBLE, $ac_cv_sizeof_double)
AC_SUBST(QSE_SIZEOF_LONG_DOUBLE, $ac_cv_sizeof_long_double)
AC_SUBST(QSE_SIZEOF_OFF_T, $ac_cv_sizeof_off_t)
AC_SUBST(QSE_SIZEOF_OFF64_T, $ac_cv_sizeof_off64_t)
AC_SUBST(QSE_PROJECT_AUTHOR, "${PACKAGE_BUGREPORT}")
AC_SUBST(QSE_PROJECT_URL, "${PACKAGE_URL}")

View File

@ -736,7 +736,9 @@ EXAMPLE_PATH = @top_srcdir@/samples \
# blank all files are included.
EXAMPLE_PATTERNS = *.c \
*.cpp
*.cpp \
awk00.h
# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
# searched for input files to be used with the \include or \dontinclude
@ -1549,6 +1551,8 @@ PREDEFINED = "QSE_BEGIN_NAMESPACE(x)=namespace x {" \
"QSE_SIZEOF_FLOAT=@QSE_SIZEOF_FLOAT@" \
"QSE_SIZEOF_DOUBLE=@QSE_SIZEOF_DOUBLE@" \
"QSE_SIZEOF_LONG_DOUBLE=@QSE_SIZEOF_LONG_DOUBLE@" \
"QSE_SIZEOF_OFF_T=@QSE_SIZEOF_OFF_T@" \
"QSE_SIZEOF_OFF64_T=@QSE_SIZEOF_OFF64_T@" \
"QSE_EXPORT=" \
"@CHAR_MODE@"

View File

@ -150,6 +150,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -34,6 +34,26 @@ Separation of the awk object and the runtime context was devised to deal with
such cases as you want to reuse the same script over different data streams.
More complex samples concerning this will be shown later.
Locale
------
While QSEAWK can use a wide character type as the default character type,
the hosting program still has to initialize the locale whenever necessary.
All the samples to be shown from here down will call a common function
init_awk_sample_locale(), use the qse_main() macro as the main function,
and call qse_runmain() for cross-platform and cross-character-set support.
Here is the function prototype.
\includelineno awk00.h
Here goes the actual function.
\includelineno awk00.c
Note that these two files do not constitute QSEAWK and are used for samples
here only.
Customizing Console I/O
-----------------------
@ -49,6 +69,28 @@ and pipe handler by qse_awk_rtx_openstd().
\includelineno awk02.c
Extention Area
--------------
When creating an awk object or a runtime context object, you can ask
a private extension area to be allocated with the main object. You can
use this extension area to store data associated with the object.
You can specify the size of the extension area when calling qse_awk_open(),
qse_awk_rtx_open(), qse_awk_openstd(), and qse_awk_rtx_openstd().
These functions iniitlize the area to zeros. You can get the pointer
to the beginning of the area with qse_awk_getxtn(), qse_awk_rtx_getxtn(),
qse_awk_getxtnstd(), qse_awk_rtx_getxtnstd() respectively.
In the sample above, the string and the buffer used for I/O customization
are declared globally. When you have multiple runtime contexts and independent
console strings and buffers, you may want to associate a runtime context
with an independent console string and buffer. The extension area that can
be allocated on demand when you create a runtime context comes in handy.
The sample below shows how to associate them through the extension area
but does not create multiple runtime contexts for simplicity.
\includelineno awk03.c
Entry Point
-----------
@ -60,14 +102,14 @@ change the entry point for your preference. The qse_awk_rtx_call() function
used is limited to user-defined functions. It is not able to call built-in
functions like *gsub* or *index*.
\includelineno awk03.c
\includelineno awk04.c
If you want to pass arguments to the function, you must create values with
value creation functions, updates their reference count, and pass them to
qse_awk_rtx_call(). The sample below creates 2 integer values with
qse_awk_rtx_makeintval() and pass them to the *pow* function.
\includelineno awk04.c
\includelineno awk05.c
While qse_awk_rtx_call() looks up a function in the function table by name,
you can find the function in advance and use the information found when
@ -77,7 +119,7 @@ into 2 separate calls to qse_awk_rtx_findfun() and qse_awk_rtx_callfun().
You can reduce look-up overhead via these 2 functions if you are to execute
the same function multiple times.
\includelineno awk05.c
\includelineno awk06.c
Similarly, you can pass a more complex value than a number. You can compose
a map value with qse_awk_rtx_makemapval() or qse_awk_rtx_makemapvalwithdata().
@ -85,7 +127,7 @@ The sample below demonstrates how to use qse_awk_rtx_makemapvalwithdata(),
pass a created map value to qse_awk_rtx_call(), and traverse a map value
returned with qse_awk_rtx_getfirstmapvalitr() and qse_awk_rtx_getnextmapvalitr().
\includelineno awk06.c
\includelineno awk07.c
Global Variables
----------------

View File

@ -23,6 +23,13 @@ and optionally an input file name and an output file name.
\includelineno sed01.c
You can call qse_sed_compstdfile() instead of qse_sed_compstdstr() to compile
sed commands stored in a file. You can use qse_sed_compstd() or qse_sed_comp()
for more flexibility.
Customize Console
-----------------
Accessing Pattern Space
-----------------------

View File

@ -187,6 +187,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -222,6 +222,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -182,6 +182,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -1440,10 +1440,18 @@ QSE_EXPORT int qse_awk_close (
qse_awk_t* awk /**< awk */
);
/**
* The qse_awk_getmmgr() function gets the memory manager used in
* qse_awk_open().
*/
QSE_EXPORT qse_mmgr_t* qse_awk_getmmgr (
qse_awk_t* awk
);
/**
* The qse_awk_getxtn() function gets the poniter to the beginning
* of the extension area created with qse_awk_open ().
*/
QSE_EXPORT void* qse_awk_getxtn (
qse_awk_t* awk
);
@ -2101,7 +2109,8 @@ QSE_EXPORT qse_mmgr_t* qse_awk_rtx_getmmgr (
);
/**
* The qse_awk_rtx_getxtn() function gets the pointer to the extension block.
* The qse_awk_rtx_getxtn() function gets the pointer to the extension area
* created with qse_awk_rtx_open().
*/
QSE_EXPORT void* qse_awk_rtx_getxtn (
qse_awk_rtx_t* rtx /**< runtime context */

View File

@ -35,15 +35,14 @@
*/
/**
* The qse_awk_parsestd_type_t type defines the types of source I/O.
* The qse_awk_parsestd_type_t type defines standard source I/O types.
*/
enum qse_awk_parsestd_type_t
{
QSE_AWK_PARSESTD_NULL = 0, /**< pseudo-value to indicate no script */
QSE_AWK_PARSESTD_FILE = 1, /**< script file */
QSE_AWK_PARSESTD_FILE = 1, /**< file */
QSE_AWK_PARSESTD_STR = 2 /**< length-bounded string */
};
typedef enum qse_awk_parsestd_type_t qse_awk_parsestd_type_t;
/**
@ -59,6 +58,10 @@ struct qse_awk_parsestd_t
{
/** file path to open. #QSE_NULL or '-' for stdin/stdout. */
const qse_char_t* path;
/** a stream created with the file path is set with this
* cmgr if it is not #QSE_NULL. */
qse_cmgr_t* cmgr;
} file;
/**
@ -73,10 +76,6 @@ struct qse_awk_parsestd_t
*/
qse_xstr_t str;
} u;
/* the streams created with the file path is set with this
* cmgr if it is not #QSE_NULL. */
qse_cmgr_t* cmgr;
};
typedef struct qse_awk_parsestd_t qse_awk_parsestd_t;
@ -106,9 +105,9 @@ QSE_EXPORT qse_awk_t* qse_awk_openstdwithmmgr (
);
/**
* The qse_awk_getxtnstd() gets the pointer to extension space.
* Note that you must not call qse_awk_getxtn() for an awk object
* created with qse_awk_openstd() and qse_awk_openstdwithmmgr().
* The qse_awk_getxtnstd() gets the pointer to extension area created with
* qse_awk_openstd() or qse_awk_openstdwithmmgr(). You must not call
* qse_awk_getxtn() for sunch an object.
*/
QSE_EXPORT void* qse_awk_getxtnstd (
qse_awk_t* awk
@ -158,7 +157,8 @@ QSE_EXPORT qse_awk_rtx_t* qse_awk_rtx_openstd (
);
/**
* The qse_awk_rtx_getxtnstd() function gets the pointer to extension space.
* The qse_awk_rtx_getxtnstd() function gets the pointer to extension area
* created with qse_awk_rtx_openstd().
*/
QSE_EXPORT void* qse_awk_rtx_getxtnstd (
qse_awk_rtx_t* rtx

View File

@ -187,6 +187,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -622,10 +622,10 @@
your system. */
#undef PTHREAD_CREATE_JOINABLE
/* char is mchar */
/* The default character type is the multi-byte character type */
#undef QSE_CHAR_IS_MCHAR
/* char is wchar */
/* The default character type is the wide character type */
#undef QSE_CHAR_IS_WCHAR
/* use the bundled unicode routines */

View File

@ -180,6 +180,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -182,6 +182,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -37,40 +37,46 @@
*/
/**
* The qse_sed_iostd_t type defines standard I/O resources.
* The qse_sed_iostd_type_t type defines types of standard
* I/O resources.
*/
typedef struct qse_sed_iostd_t qse_sed_iostd_t;
enum qse_sed_iostd_type_t
{
QSE_SED_IOSTD_NULL, /**< null resource type */
QSE_SED_IOSTD_FILE, /**< file */
QSE_SED_IOSTD_STR, /**< string */
QSE_SED_IOSTD_SIO /**< sio */
};
typedef enum qse_sed_iostd_type_t qse_sed_iostd_type_t;
/**
* The qse_sed_iostd_t type defines a standard I/O resource.
*/
struct qse_sed_iostd_t
{
enum
{
QSE_SED_IOSTD_NULL, /** invalid resource */
QSE_SED_IOSTD_FILE,
QSE_SED_IOSTD_STR,
QSE_SED_IOSTD_SIO
} type;
qse_sed_iostd_type_t type; /**< resource type */
union
{
struct
{
const qse_char_t* path;
qse_cmgr_t* cmgr;
} file;
const qse_char_t* path; /**< file path */
qse_cmgr_t* cmgr; /**< cmgr for the file */
} file;
qse_xstr_t str;
qse_sio_t* sio;
} u;
} u; /**< union containing data for each type */
};
typedef struct qse_sed_iostd_t qse_sed_iostd_t;
#ifdef __cplusplus
extern "C" {
#endif
/**
* The qse_sed_openstd() function creates a stream editor with the default
* memory manager and initializes it. Use qse_getxtnstd(), not qse_getxtn()
* to get the pointer to the extension area.
* memory manager and initializes it. Use qse_sed_getxtnstd() to get the
* pointer to the extension area. Do not use qse_sed_getxtn() for this.
* @return pointer to a stream editor on success, #QSE_NULL on failure.
*/
QSE_EXPORT qse_sed_t* qse_sed_openstd (
@ -80,8 +86,8 @@ QSE_EXPORT qse_sed_t* qse_sed_openstd (
/**
* The qse_sed_openstdwithmmgr() function creates a stream editor with a
* user-defined memory manager. It is equivalent to qse_sed_openstd(),
* except that you can specify your own memory manager.Use qse_getxtnstd(),
* not qse_getxtn() to get the pointer to the extension area.
* except that you can specify your own memory manager.Use qse_sed_getxtnstd(),
* not qse_sed_getxtn() to get the pointer to the extension area.
* @return pointer to a stream editor on success, #QSE_NULL on failure.
*/
QSE_EXPORT qse_sed_t* qse_sed_openstdwithmmgr (

View File

@ -186,6 +186,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -226,6 +226,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -700,7 +700,8 @@ static int open_parsestd (qse_awk_t* awk, xtn_t* xtn, qse_size_t index)
}
}
if (psin->cmgr) qse_sio_setcmgr (xtn->s.in.u.file.sio, psin->cmgr);
if (psin->u.file.cmgr)
qse_sio_setcmgr (xtn->s.in.u.file.sio, psin->u.file.cmgr);
return 0;
case QSE_AWK_PARSESTD_STR:
@ -975,8 +976,8 @@ static qse_ssize_t sf_out (
if (xtn->s.out.u.file.sio == QSE_NULL) return -1;
}
if (xtn->s.out.x->cmgr)
qse_sio_setcmgr (xtn->s.out.u.file.sio, xtn->s.out.x->cmgr);
if (xtn->s.out.x->u.file.cmgr)
qse_sio_setcmgr (xtn->s.out.u.file.sio, xtn->s.out.x->u.file.cmgr);
return 1;
case QSE_AWK_PARSESTD_STR:

View File

@ -254,6 +254,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -203,6 +203,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -217,6 +217,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -123,8 +123,7 @@ static int verify_iostd_in (qse_sed_t* sed, qse_sed_iostd_t in[])
for (i = 0; in[i].type != QSE_SED_IOSTD_NULL; i++)
{
if (in[i].type != QSE_SED_IOSTD_SIO &&
in[i].type != QSE_SED_IOSTD_FILE &&
if (in[i].type != QSE_SED_IOSTD_FILE &&
in[i].type != QSE_SED_IOSTD_STR)
{
qse_sed_seterrnum (sed, QSE_SED_EINVAL, QSE_NULL);
@ -183,10 +182,6 @@ static void close_main_stream (
{
switch (io->type)
{
case QSE_SED_IOSTD_SIO:
/* nothing to do */
break;
case QSE_SED_IOSTD_FILE:
qse_sio_close (arg->handle);
break;
@ -213,10 +208,6 @@ static int open_input_stream (
QSE_ASSERT (io != QSE_NULL);
switch (io->type)
{
case QSE_SED_IOSTD_SIO:
arg->handle = io->u.sio;
break;
case QSE_SED_IOSTD_FILE:
{
qse_sio_t* sio;
@ -281,10 +272,6 @@ static int open_output_stream (qse_sed_t* sed, qse_sed_io_arg_t* arg, qse_sed_io
QSE_ASSERT (io != QSE_NULL);
switch (io->type)
{
case QSE_SED_IOSTD_SIO:
arg->handle = io->u.sio;
break;
case QSE_SED_IOSTD_FILE:
{
qse_sio_t* sio;
@ -773,8 +760,7 @@ int qse_sed_execstd (
if (out)
{
if (out->type != QSE_SED_IOSTD_SIO &&
out->type != QSE_SED_IOSTD_FILE &&
if (out->type != QSE_SED_IOSTD_FILE &&
out->type != QSE_SED_IOSTD_STR)
{
qse_sed_seterrnum (sed, QSE_SED_EINVAL, QSE_NULL);

View File

@ -186,6 +186,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -237,6 +237,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -187,6 +187,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -150,6 +150,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -152,6 +152,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -187,6 +187,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -5,7 +5,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(includedir)
bin_PROGRAMS = awk01 awk02 awk03 awk04 awk05 awk06 awk09 awk11 awk15
bin_PROGRAMS = awk01 awk02 awk03 awk04 awk05 awk06 awk07 awk09 awk11 awk15
LDFLAGS = -L../../lib/awk -L../../lib/cmn
LDADD = -lqseawk -lqsecmn $(LIBM)
@ -16,15 +16,16 @@ LDADD += $(UNICOWS_LIBS)
endif
endif
awk01_SOURCES = awk01.c
awk02_SOURCES = awk02.c
awk03_SOURCES = awk03.c
awk04_SOURCES = awk04.c
awk05_SOURCES = awk05.c
awk06_SOURCES = awk06.c
awk09_SOURCES = awk09.c
awk11_SOURCES = awk11.c
awk15_SOURCES = awk15.c
awk01_SOURCES = awk01.c
awk02_SOURCES = awk02.c awk00.c awk00.h
awk03_SOURCES = awk03.c awk00.c awk00.h
awk04_SOURCES = awk04.c awk00.c awk00.h
awk05_SOURCES = awk05.c awk00.c awk00.h
awk06_SOURCES = awk06.c awk00.c awk00.h
awk07_SOURCES = awk07.c awk00.c awk00.h
awk09_SOURCES = awk09.c awk00.c awk00.h
awk11_SOURCES = awk11.c awk00.c awk00.h
awk15_SOURCES = awk15.c awk00.c awk00.h
if ENABLE_CXX

View File

@ -35,8 +35,8 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = awk01$(EXEEXT) awk02$(EXEEXT) awk03$(EXEEXT) \
awk04$(EXEEXT) awk05$(EXEEXT) awk06$(EXEEXT) awk09$(EXEEXT) \
awk11$(EXEEXT) awk15$(EXEEXT) $(am__EXEEXT_1)
awk04$(EXEEXT) awk05$(EXEEXT) awk06$(EXEEXT) awk07$(EXEEXT) \
awk09$(EXEEXT) awk11$(EXEEXT) awk15$(EXEEXT) $(am__EXEEXT_1)
@WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
@ENABLE_CXX_TRUE@am__append_2 = awk21 awk22 awk23 awk24 awk25 awk26 awk27 awk28
subdir = samples/awk
@ -65,35 +65,39 @@ awk01_LDADD = $(LDADD)
am__DEPENDENCIES_1 =
@WCHAR_TRUE@@WIN32_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
awk01_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
am_awk02_OBJECTS = awk02.$(OBJEXT)
am_awk02_OBJECTS = awk02.$(OBJEXT) awk00.$(OBJEXT)
awk02_OBJECTS = $(am_awk02_OBJECTS)
awk02_LDADD = $(LDADD)
awk02_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
am_awk03_OBJECTS = awk03.$(OBJEXT)
am_awk03_OBJECTS = awk03.$(OBJEXT) awk00.$(OBJEXT)
awk03_OBJECTS = $(am_awk03_OBJECTS)
awk03_LDADD = $(LDADD)
awk03_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
am_awk04_OBJECTS = awk04.$(OBJEXT)
am_awk04_OBJECTS = awk04.$(OBJEXT) awk00.$(OBJEXT)
awk04_OBJECTS = $(am_awk04_OBJECTS)
awk04_LDADD = $(LDADD)
awk04_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
am_awk05_OBJECTS = awk05.$(OBJEXT)
am_awk05_OBJECTS = awk05.$(OBJEXT) awk00.$(OBJEXT)
awk05_OBJECTS = $(am_awk05_OBJECTS)
awk05_LDADD = $(LDADD)
awk05_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
am_awk06_OBJECTS = awk06.$(OBJEXT)
am_awk06_OBJECTS = awk06.$(OBJEXT) awk00.$(OBJEXT)
awk06_OBJECTS = $(am_awk06_OBJECTS)
awk06_LDADD = $(LDADD)
awk06_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
am_awk09_OBJECTS = awk09.$(OBJEXT)
am_awk07_OBJECTS = awk07.$(OBJEXT) awk00.$(OBJEXT)
awk07_OBJECTS = $(am_awk07_OBJECTS)
awk07_LDADD = $(LDADD)
awk07_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
am_awk09_OBJECTS = awk09.$(OBJEXT) awk00.$(OBJEXT)
awk09_OBJECTS = $(am_awk09_OBJECTS)
awk09_LDADD = $(LDADD)
awk09_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
am_awk11_OBJECTS = awk11.$(OBJEXT)
am_awk11_OBJECTS = awk11.$(OBJEXT) awk00.$(OBJEXT)
awk11_OBJECTS = $(am_awk11_OBJECTS)
awk11_LDADD = $(LDADD)
awk11_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
am_awk15_OBJECTS = awk15.$(OBJEXT)
am_awk15_OBJECTS = awk15.$(OBJEXT) awk00.$(OBJEXT)
awk15_OBJECTS = $(am_awk15_OBJECTS)
awk15_LDADD = $(LDADD)
awk15_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
@ -162,17 +166,18 @@ CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) \
$(awk04_SOURCES) $(awk05_SOURCES) $(awk06_SOURCES) \
$(awk09_SOURCES) $(awk11_SOURCES) $(awk15_SOURCES) \
$(awk21_SOURCES) $(awk22_SOURCES) $(awk23_SOURCES) \
$(awk24_SOURCES) $(awk25_SOURCES) $(awk26_SOURCES) \
$(awk27_SOURCES) $(awk28_SOURCES)
$(awk07_SOURCES) $(awk09_SOURCES) $(awk11_SOURCES) \
$(awk15_SOURCES) $(awk21_SOURCES) $(awk22_SOURCES) \
$(awk23_SOURCES) $(awk24_SOURCES) $(awk25_SOURCES) \
$(awk26_SOURCES) $(awk27_SOURCES) $(awk28_SOURCES)
DIST_SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) \
$(awk04_SOURCES) $(awk05_SOURCES) $(awk06_SOURCES) \
$(awk09_SOURCES) $(awk11_SOURCES) $(awk15_SOURCES) \
$(am__awk21_SOURCES_DIST) $(am__awk22_SOURCES_DIST) \
$(am__awk23_SOURCES_DIST) $(am__awk24_SOURCES_DIST) \
$(am__awk25_SOURCES_DIST) $(am__awk26_SOURCES_DIST) \
$(am__awk27_SOURCES_DIST) $(am__awk28_SOURCES_DIST)
$(awk07_SOURCES) $(awk09_SOURCES) $(awk11_SOURCES) \
$(awk15_SOURCES) $(am__awk21_SOURCES_DIST) \
$(am__awk22_SOURCES_DIST) $(am__awk23_SOURCES_DIST) \
$(am__awk24_SOURCES_DIST) $(am__awk25_SOURCES_DIST) \
$(am__awk26_SOURCES_DIST) $(am__awk27_SOURCES_DIST) \
$(am__awk28_SOURCES_DIST)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -272,6 +277,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
@ -354,15 +361,16 @@ AM_CPPFLAGS = \
-I$(includedir)
LDADD = -lqseawk -lqsecmn $(LIBM) $(am__append_1)
awk01_SOURCES = awk01.c
awk02_SOURCES = awk02.c
awk03_SOURCES = awk03.c
awk04_SOURCES = awk04.c
awk05_SOURCES = awk05.c
awk06_SOURCES = awk06.c
awk09_SOURCES = awk09.c
awk11_SOURCES = awk11.c
awk15_SOURCES = awk15.c
awk01_SOURCES = awk01.c
awk02_SOURCES = awk02.c awk00.c awk00.h
awk03_SOURCES = awk03.c awk00.c awk00.h
awk04_SOURCES = awk04.c awk00.c awk00.h
awk05_SOURCES = awk05.c awk00.c awk00.h
awk06_SOURCES = awk06.c awk00.c awk00.h
awk07_SOURCES = awk07.c awk00.c awk00.h
awk09_SOURCES = awk09.c awk00.c awk00.h
awk11_SOURCES = awk11.c awk00.c awk00.h
awk15_SOURCES = awk15.c awk00.c awk00.h
@ENABLE_CXX_TRUE@CXXLIB = -lqseawkxx -lqsecmnxx
@ENABLE_CXX_TRUE@awk21_SOURCES = awk21.cpp
@ENABLE_CXX_TRUE@awk22_SOURCES = awk22.cpp
@ -475,6 +483,9 @@ awk05$(EXEEXT): $(awk05_OBJECTS) $(awk05_DEPENDENCIES) $(EXTRA_awk05_DEPENDENCIE
awk06$(EXEEXT): $(awk06_OBJECTS) $(awk06_DEPENDENCIES) $(EXTRA_awk06_DEPENDENCIES)
@rm -f awk06$(EXEEXT)
$(LINK) $(awk06_OBJECTS) $(awk06_LDADD) $(LIBS)
awk07$(EXEEXT): $(awk07_OBJECTS) $(awk07_DEPENDENCIES) $(EXTRA_awk07_DEPENDENCIES)
@rm -f awk07$(EXEEXT)
$(LINK) $(awk07_OBJECTS) $(awk07_LDADD) $(LIBS)
awk09$(EXEEXT): $(awk09_OBJECTS) $(awk09_DEPENDENCIES) $(EXTRA_awk09_DEPENDENCIES)
@rm -f awk09$(EXEEXT)
$(LINK) $(awk09_OBJECTS) $(awk09_LDADD) $(LIBS)
@ -515,12 +526,14 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk00.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)/awk03.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk04.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk05.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk06.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk07.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk09.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk11.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk15.Po@am__quote@

31
qse/samples/awk/awk00.c Normal file
View File

@ -0,0 +1,31 @@
/* awk00.c */
#include "awk00.h"
#include <qse/cmn/mbwc.h>
#include <locale.h>
#if defined(_WIN32)
# include <windows.h>
#endif
void init_awk_sample_locale (void)
{
#if defined(_WIN32)
char locale[100];
UINT codepage = GetConsoleOutputCP();
if (codepage == CP_UTF8)
{
/*SetConsoleOutputCP (CP_UTF8);*/
qse_setdflcmgrbyid (QSE_CMGR_UTF8);
}
else
{
sprintf (locale, ".%u", (unsigned int)codepage);
setlocale (LC_ALL, locale);
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
}
#else
setlocale (LC_ALL, "");
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
#endif
}

16
qse/samples/awk/awk00.h Normal file
View File

@ -0,0 +1,16 @@
/* awk00.h */
#ifndef _AWK00_H_
#define _AWK00_H_
#ifdef __cplusplus
extern "C" {
#endif
void init_awk_sample_locale (void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,8 @@
#include <qse/awk/std.h>
#include <qse/cmn/str.h>
#include <qse/cmn/main.h>
#include <qse/cmn/stdio.h>
#include "awk00.h"
/* i'll print records with the second field grater than 4.
* at the end, we'll print the number of records seen so far */
@ -73,8 +75,7 @@ static qse_ssize_t handle_console (
return -1;
}
int main ()
static int awk_main (int argc, qse_char_t* argv[])
{
qse_awk_t* awk = QSE_NULL;
qse_awk_rtx_t* rtx = QSE_NULL;
@ -151,3 +152,10 @@ oops:
qse_printf (QSE_T("Console Output:\n================\n%.*s\n"), (int)conoutpos, conout);
return ret;
}
int qse_main (int argc, qse_achar_t* argv[])
{
extern void init_awk_sample_locale (void);
init_awk_sample_locale ();
return qse_runmain (argc, argv, awk_main);
}

View File

@ -1,117 +1,177 @@
#include <qse/awk/std.h>
#include <qse/cmn/str.h>
#include <qse/cmn/main.h>
#include <qse/cmn/stdio.h>
#include "awk00.h"
static const qse_char_t* src = QSE_T(
"function init() { a = 20; return a; }"
"function main() { return ++a; }"
"function fini() { print \"a in fini() =>\", ++a; return a; }"
);
/* i'll print records with the second field grater than 4.
* at the end, we'll print the number of records seen so far */
static const qse_char_t* script =
QSE_T("$2 > 4 { print $0; } END { print NR; }");
static const qse_char_t* fnc[] =
struct console_t
{
QSE_T("init"),
QSE_T("main"),
QSE_T("main"),
QSE_T("main"),
QSE_T("main"),
QSE_T("fini"),
/* console input */
const qse_char_t* conin;
qse_size_t coninpos;
/* console output */
qse_char_t conout[10000]; /* fixed-size console buffer for demo only */
qse_size_t conoutpos;
};
int main ()
typedef struct console_t console_t;
/* this is the console I/O handler */
static qse_ssize_t handle_console (
qse_awk_rtx_t* rtx,
qse_awk_rio_cmd_t cmd,
qse_awk_rio_arg_t* arg,
qse_char_t* data,
qse_size_t count)
{
console_t* con = qse_awk_rtx_getxtnstd (rtx);
/* this function is called separately for the console input and console
* output. however, since i don't maintain underlying resources like
* file handles, i don't really check if it's input or output.
* you can check the value of #qse_awk_rio_mode_t in the arg->mode
* field if you want to tell.
*/
switch (cmd)
{
case QSE_AWK_RIO_OPEN:
/* 0 for success, -1 for failure. */
return 0;
case QSE_AWK_RIO_CLOSE:
/* 0 for success, -1 for failure. */
return 0;
case QSE_AWK_RIO_READ:
{
qse_ssize_t len = 0;
while (con->conin[con->coninpos] && len < count)
data[len++] = con->conin[con->coninpos++];
/* 0 for EOF, -1 for failure.
positive numbers for the number of characters read */
return len;
}
case QSE_AWK_RIO_WRITE:
con->conoutpos += qse_strxncpy (
&con->conout[con->conoutpos], QSE_COUNTOF(con->conout) - con->conoutpos,
data, count);
/* 0 for EOF, -1 for failure.
positive numbers for the number of characters written */
return count;
case QSE_AWK_RIO_FLUSH:
/* 0 for success, -1 for failure. */
return 0;
case QSE_AWK_RIO_NEXT:
/* 0 for success, -1 for failure. */
return 0;
}
/* this part will never be reached */
return -1;
}
static int awk_main (int argc, qse_char_t* argv[])
{
qse_awk_t* awk = QSE_NULL;
qse_awk_rtx_t* rtx = QSE_NULL;
qse_awk_val_t* retv;
qse_awk_parsestd_t psin[2];
int ret, i, opt;
qse_awk_rio_t rio;
int ret = -1;
console_t* con;
/* create an awk object */
awk = qse_awk_openstd (0);
if (awk == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n"));
ret = -1; goto oops;
qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open awk\n"));
goto oops;
}
/* get the awk's trait */
qse_awk_getopt (awk, QSE_AWK_TRAIT, &opt);
/* change the trait value to disallow BEGIN, END, pattern-action blocks */
opt &= ~QSE_AWK_PABLOCK;
/* update the trait */
qse_awk_setopt (awk, QSE_AWK_TRAIT, &opt);
/* prepare a script to parse */
psin[0].type = QSE_AWK_PARSESTD_STR;
psin[0].u.str.ptr = src;
psin[0].u.str.len = qse_strlen(src);
psin[0].u.str.ptr = script;
psin[0].u.str.len = qse_strlen(script);
psin[1].type = QSE_AWK_PARSESTD_NULL;
/* parse a script */
ret = qse_awk_parsestd (awk, psin, QSE_NULL);
if (ret == -1)
/* parse a script in a string */
if (qse_awk_parsestd (awk, psin, QSE_NULL) <= -1)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"),
qse_awk_geterrmsg(awk));
goto oops;
}
/* create a runtime context */
/* open a runtime context */
rtx = qse_awk_rtx_openstd (
awk,
0,
QSE_T("awk03"),
awk,
QSE_SIZEOF(console_t), /* the size of extenstion area */
QSE_T("awk01"),
QSE_NULL, /* stdin */
QSE_NULL, /* stdout */
QSE_NULL, /* stdout */
QSE_NULL /* default cmgr */
);
if (rtx == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"),
qse_awk_geterrmsg(awk));
ret = -1; goto oops;
goto oops;
}
/* get the pointer to the extension area. */
con = (console_t*)qse_awk_rtx_getxtnstd (rtx);
/* initialize fields that require non-zero values.
* the entire extension area was initialized to zeros
* when it was created. */
con->conin = QSE_T("Beth 4.00 0\nDan 3.74 0\nKathy 4.00 10\nMark 5.00 20\nMary 5.50 22\nSusie 4.25 18\n");
/* call init() initially, followed by 4 calls to main(),
* and a final call to fini() */
for (i = 0; i < QSE_COUNTOF(fnc); i++)
/* retrieve the I/O handlers created by qse_awk_rtx_openstd() */
qse_awk_rtx_getrio (rtx, &rio);
/* override the console handler */
rio.console = handle_console;
/* update the I/O handlers */
qse_awk_rtx_setrio (rtx, &rio);
/* execute pattern-action blocks */
retv = qse_awk_rtx_loop (rtx);
if (retv == QSE_NULL)
{
qse_awk_val_t* v;
qse_char_t* str;
qse_size_t len;
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
goto oops;
}
/* call the function */
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));
ret = -1; goto oops;
}
/* convert the return value to a string with duplication */
str = qse_awk_rtx_valtostrdup (rtx, v, &len);
/* clear the return value */
qse_awk_rtx_refdownval (rtx, v);
if (str == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
/* print the return value */
qse_printf (QSE_T("return: [%.*s]\n"), (int)len, str);
/* destroy the duplicated string */
qse_awk_rtx_freemem (rtx, str);
}
/* decrement the reference count of the return value */
qse_awk_rtx_refdownval (rtx, retv);
ret = 0;
oops:
/* destroy a runtime context */
/* the buffer is available during the runtime context is alive */
qse_printf (QSE_T("Console Output:\n================\n%.*s\n"), (int)con->conoutpos, con->conout);
/* destroy the runtime context */
if (rtx) qse_awk_rtx_close (rtx);
/* destroy the awk object */
if (awk) qse_awk_close (awk);
return ret;
}
int qse_main (int argc, qse_achar_t* argv[])
{
init_awk_sample_locale ();
return qse_runmain (argc, argv, awk_main);
}

View File

@ -1,19 +1,29 @@
#include <qse/awk/std.h>
#include <qse/cmn/main.h>
#include <qse/cmn/stdio.h>
#include "awk00.h"
static const qse_char_t* src = QSE_T(
"function pow(x,y) { return x ** y; }"
"function init() { a = 20; return a; }"
"function main() { return ++a; }"
"function fini() { print \"a in fini() =>\", ++a; return a; }"
);
int main ()
static const qse_char_t* fnc[] =
{
QSE_T("init"),
QSE_T("main"),
QSE_T("main"),
QSE_T("main"),
QSE_T("main"),
QSE_T("fini"),
};
static int awk_main (int argc, qse_char_t* argv[])
{
qse_awk_t* awk = QSE_NULL;
qse_awk_rtx_t* rtx = QSE_NULL;
qse_awk_parsestd_t psin[2];
qse_char_t* str;
qse_size_t len;
qse_awk_val_t* rtv = QSE_NULL;
qse_awk_val_t* arg[2] = { QSE_NULL, QSE_NULL };
int ret, i, opt;
/* create an awk object */
@ -31,13 +41,13 @@ int main ()
/* update the trait */
qse_awk_setopt (awk, QSE_AWK_TRAIT, &opt);
/* prepare an awk script to parse */
/* prepare a script to parse */
psin[0].type = QSE_AWK_PARSESTD_STR;
psin[0].u.str.ptr = src;
psin[0].u.str.len = qse_strlen(src);
psin[1].type = QSE_AWK_PARSESTD_NULL;
/* parse the script */
/* parse a script */
ret = qse_awk_parsestd (awk, psin, QSE_NULL);
if (ret == -1)
{
@ -48,9 +58,9 @@ int main ()
/* create a runtime context */
rtx = qse_awk_rtx_openstd (
awk,
awk,
0,
QSE_T("awk04"),
QSE_T("awk03"),
QSE_NULL, /* stdin */
QSE_NULL, /* stdout */
QSE_NULL /* default cmgr */
@ -62,64 +72,54 @@ int main ()
ret = -1; goto oops;
}
/* create the first argument to the pow function to call */
arg[0] = qse_awk_rtx_makeintval (rtx, 50);
if (arg[0] == QSE_NULL)
/* call init() initially, followed by 4 calls to main(),
* and a final call to fini() */
for (i = 0; i < QSE_COUNTOF(fnc); i++)
{
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]);
qse_awk_val_t* v;
qse_char_t* str;
qse_size_t len;
/* create the second argument to the pow function to call */
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]);
/* call the function */
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));
ret = -1; goto oops;
}
/* call the pow function */
rtv = qse_awk_rtx_call (rtx, QSE_T("pow"), arg, 2);
if (rtv == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
/* convert the return value to a string with duplication */
str = qse_awk_rtx_valtostrdup (rtx, v, &len);
/* duplicate the return value to a string */
str = qse_awk_rtx_valtostrdup (rtx, rtv, &len);
/* clear the return value */
qse_awk_rtx_refdownval (rtx, v);
/* clear the return value */
qse_awk_rtx_refdownval (rtx, rtv);
if (str == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
if (str == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
/* print the return value */
qse_printf (QSE_T("return: [%.*s]\n"), (int)len, str);
qse_printf (QSE_T("[%.*s]\n"), (int)len, str);
/* destroy the duplicated string */
qse_awk_rtx_freemem (rtx, str);
/* destroy the duplicated string */
qse_awk_rtx_freemem (rtx, str);
}
oops:
/* dereference all arguments */
for (i = 0; i < QSE_COUNTOF(arg); i++)
{
if (arg[i]) qse_awk_rtx_refdownval (rtx, arg[i]);
}
/* destroy a runtime context */
if (rtx) qse_awk_rtx_close (rtx);
/* destroy the processor */
/* destroy the awk object */
if (awk) qse_awk_close (awk);
return ret;
}
int qse_main (int argc, qse_achar_t* argv[])
{
init_awk_sample_locale ();
return qse_runmain (argc, argv, awk_main);
}

134
qse/samples/awk/awk05.c Normal file
View File

@ -0,0 +1,134 @@
#include <qse/awk/std.h>
#include <qse/cmn/main.h>
#include <qse/cmn/stdio.h>
#include "awk00.h"
static const qse_char_t* src = QSE_T(
"function pow(x,y) { return x ** y; }"
);
static int awk_main (int argc, qse_char_t* argv[])
{
qse_awk_t* awk = QSE_NULL;
qse_awk_rtx_t* rtx = QSE_NULL;
qse_awk_parsestd_t psin[2];
qse_char_t* str;
qse_size_t len;
qse_awk_val_t* rtv = QSE_NULL;
qse_awk_val_t* arg[2] = { QSE_NULL, QSE_NULL };
int ret, i, opt;
/* create an awk object */
awk = qse_awk_openstd (0);
if (awk == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n"));
ret = -1; goto oops;
}
/* get the awk's trait */
qse_awk_getopt (awk, QSE_AWK_TRAIT, &opt);
/* change the trait value to disallow BEGIN, END, pattern-action blocks */
opt &= ~QSE_AWK_PABLOCK;
/* update the trait */
qse_awk_setopt (awk, QSE_AWK_TRAIT, &opt);
/* prepare an awk script to parse */
psin[0].type = QSE_AWK_PARSESTD_STR;
psin[0].u.str.ptr = src;
psin[0].u.str.len = qse_strlen(src);
psin[1].type = QSE_AWK_PARSESTD_NULL;
/* parse the script */
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,
0,
QSE_T("awk04"),
QSE_NULL, /* stdin */
QSE_NULL, /* stdout */
QSE_NULL /* default cmgr */
);
if (rtx == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_geterrmsg(awk));
ret = -1; goto oops;
}
/* create the first argument to the pow function to call */
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]);
/* create the second argument to the pow function to call */
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]);
/* call the pow function */
rtv = qse_awk_rtx_call (rtx, QSE_T("pow"), arg, 2);
if (rtv == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
/* duplicate the return value to a string */
str = qse_awk_rtx_valtostrdup (rtx, rtv, &len);
/* clear the return value */
qse_awk_rtx_refdownval (rtx, rtv);
if (str == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
qse_printf (QSE_T("[%.*s]\n"), (int)len, str);
/* destroy the duplicated string */
qse_awk_rtx_freemem (rtx, str);
oops:
/* dereference all arguments */
for (i = 0; i < QSE_COUNTOF(arg); i++)
{
if (arg[i]) qse_awk_rtx_refdownval (rtx, arg[i]);
}
/* destroy a runtime context */
if (rtx) qse_awk_rtx_close (rtx);
/* destroy the processor */
if (awk) qse_awk_close (awk);
return ret;
}
int qse_main (int argc, qse_achar_t* argv[])
{
init_awk_sample_locale ();
return qse_runmain (argc, argv, awk_main);
}

View File

@ -1,29 +1,25 @@
#include <qse/awk/std.h>
#include <qse/cmn/main.h>
#include <qse/cmn/stdio.h>
#include "awk00.h"
static const qse_char_t* src = QSE_T(
"function dump(x) { OFS=\"=\"; for (k in x) print k, x[k]; x[\"f99\"]=\"os2\"; return x; }"
"function pow(x,y) { return x ** y; }"
);
int main ()
static int awk_main (int argc, qse_char_t* argv[])
{
qse_awk_t* awk = QSE_NULL;
qse_awk_rtx_t* rtx = QSE_NULL;
qse_awk_parsestd_t psin[2];
qse_char_t* str;
qse_size_t len;
qse_awk_val_t* rtv = QSE_NULL;
qse_awk_val_t* arg = QSE_NULL;
int ret, opt;
qse_awk_val_t* arg[2] = { QSE_NULL, QSE_NULL };
int ret, i, opt;
qse_awk_fun_t* fun;
/* this structure is passed to qse_awk_rtx_makemapvalwithdata() */
qse_awk_val_map_data_t md[] =
{
{ { QSE_T("f0"), 2 }, QSE_AWK_VAL_MAP_DATA_STR, QSE_T("linux") },
{ { QSE_T("f1"), 2 }, QSE_AWK_VAL_MAP_DATA_STR, QSE_T("openvms") },
{ { QSE_T("f2"), 2 }, QSE_AWK_VAL_MAP_DATA_STR, QSE_T("hpux") },
{ { QSE_NULL, 0 }, 0, QSE_NULL } /* last item */
};
/* create a standard awk object */
/* create an awk object */
awk = qse_awk_openstd (0);
if (awk == QSE_NULL)
{
@ -38,7 +34,7 @@ int main ()
/* update the trait */
qse_awk_setopt (awk, QSE_AWK_TRAIT, &opt);
/* prepare a script to parse */
/* prepare an awk script to parse */
psin[0].type = QSE_AWK_PARSESTD_STR;
psin[0].u.str.ptr = src;
psin[0].u.str.len = qse_strlen(src);
@ -53,15 +49,14 @@ int main ()
goto oops;
}
/* create a standard runtime context */
/* create a runtime context */
rtx = qse_awk_rtx_openstd (
awk,
0,
QSE_T("awk06"),
QSE_T("awk05"),
QSE_NULL, /* stdin */
QSE_NULL, /* stdout */
QSE_NULL /* default cmgr */
);
if (rtx == QSE_NULL)
{
@ -70,18 +65,37 @@ int main ()
ret = -1; goto oops;
}
/* create a map value to pass as an argument */
arg = qse_awk_rtx_makemapvalwithdata (rtx, md);
if (arg == QSE_NULL)
/* create the first argument to the pow function to call */
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);
/* execute the dump function in the awk script */
rtv = qse_awk_rtx_call (rtx, QSE_T("dump"), &arg, 1);
qse_awk_rtx_refupval (rtx, arg[0]);
/* create the second argument to the pow function to call */
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]);
/* find the pow function */
fun = qse_awk_rtx_findfun (rtx, QSE_T("pow"));
if (fun == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
/* call the function found */
rtv = qse_awk_rtx_callfun (rtx, fun, arg, 2);
if (rtv == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
@ -89,72 +103,42 @@ int main ()
ret = -1; goto oops;
}
if (rtv->type == QSE_AWK_VAL_MAP)
/* duplicate the return value to a string */
str = qse_awk_rtx_valtostrdup (rtx, rtv, &len);
/* clear the return value */
qse_awk_rtx_refdownval (rtx, rtv);
if (str == QSE_NULL)
{
/* if a returned value is a map,
* traverse the map and print the key/value pairs. */
qse_awk_val_map_itr_t itr;
qse_awk_val_map_itr_t* iptr;
/* get the iterator to the first key/value pair */
iptr = qse_awk_rtx_getfirstmapvalitr (rtx, rtv, &itr);
while (iptr)
{
qse_xstr_t str;
/* #QSE_AWK_VAL_MAP_ITR_VAL returns the value part */
str.ptr = qse_awk_rtx_valtostrdup (
rtx, QSE_AWK_VAL_MAP_ITR_VAL(iptr), &str.len);
if (str.ptr == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
/* #QSE_AWK_VAL_MAP_ITR_KEY returns the key part */
qse_printf (QSE_T("ret [%.*s]=[%.*s]\n"),
(int)QSE_AWK_VAL_MAP_ITR_KEY(iptr)->len,
QSE_AWK_VAL_MAP_ITR_KEY(iptr)->ptr,
(int)str.len, str.ptr
);
qse_awk_rtx_freemem (rtx, str.ptr);
/* get the iterator to the next key/value pair */
iptr = qse_awk_rtx_getnextmapvalitr (rtx, rtv, &itr);
}
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
else
{
/* if it is a plain value, convert it to a string
* and print it */
qse_xstr_t str;
str.ptr = qse_awk_rtx_valtostrdup (rtx, rtv, &str.len);
if (str.ptr == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
qse_printf (QSE_T("ret [%.*s]\n"), (int)str.len, str.ptr);
qse_awk_rtx_freemem (rtx, str.ptr);
}
qse_printf (QSE_T("[%.*s]\n"), (int)len, str);
/* destroy the duplicated string */
qse_awk_rtx_freemem (rtx, str);
oops:
/* clear the return value */
if (rtv) qse_awk_rtx_refdownval (rtx, rtv);
/* dereference the argument */
if (arg) qse_awk_rtx_refdownval (rtx, arg);
/* dereference all arguments */
for (i = 0; i < QSE_COUNTOF(arg); i++)
{
if (arg[i]) qse_awk_rtx_refdownval (rtx, arg[i]);
}
/* destroy a runtime context */
if (rtx) qse_awk_rtx_close (rtx);
/* destroy the processor */
if (awk) qse_awk_close (awk);
return ret;
}
int qse_main (int argc, qse_achar_t* argv[])
{
init_awk_sample_locale ();
return qse_runmain (argc, argv, awk_main);
}

169
qse/samples/awk/awk07.c Normal file
View File

@ -0,0 +1,169 @@
#include <qse/awk/std.h>
#include <qse/cmn/main.h>
#include <qse/cmn/stdio.h>
#include "awk00.h"
static const qse_char_t* src = QSE_T(
"function dump(x) { OFS=\"=\"; for (k in x) print k, x[k]; x[\"f99\"]=\"os2\"; return x; }"
);
static int awk_main (int argc, qse_char_t* argv[])
{
qse_awk_t* awk = QSE_NULL;
qse_awk_rtx_t* rtx = QSE_NULL;
qse_awk_parsestd_t psin[2];
qse_awk_val_t* rtv = QSE_NULL;
qse_awk_val_t* arg = QSE_NULL;
int ret, opt;
/* this structure is passed to qse_awk_rtx_makemapvalwithdata() */
qse_awk_val_map_data_t md[] =
{
{ { QSE_T("f0"), 2 }, QSE_AWK_VAL_MAP_DATA_STR, QSE_T("linux") },
{ { QSE_T("f1"), 2 }, QSE_AWK_VAL_MAP_DATA_STR, QSE_T("openvms") },
{ { QSE_T("f2"), 2 }, QSE_AWK_VAL_MAP_DATA_STR, QSE_T("hpux") },
{ { QSE_NULL, 0 }, 0, QSE_NULL } /* last item */
};
/* create a standard awk object */
awk = qse_awk_openstd (0);
if (awk == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n"));
ret = -1; goto oops;
}
/* get the awk's trait */
qse_awk_getopt (awk, QSE_AWK_TRAIT, &opt);
/* change the trait value to disallow BEGIN, END, pattern-action blocks */
opt &= ~QSE_AWK_PABLOCK;
/* update the trait */
qse_awk_setopt (awk, QSE_AWK_TRAIT, &opt);
/* prepare a script to parse */
psin[0].type = QSE_AWK_PARSESTD_STR;
psin[0].u.str.ptr = src;
psin[0].u.str.len = qse_strlen(src);
psin[1].type = QSE_AWK_PARSESTD_NULL;
/* parse the script */
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 standard runtime context */
rtx = qse_awk_rtx_openstd (
awk,
0,
QSE_T("awk06"),
QSE_NULL, /* stdin */
QSE_NULL, /* stdout */
QSE_NULL /* default cmgr */
);
if (rtx == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_geterrmsg(awk));
ret = -1; goto oops;
}
/* create a map value to pass as an argument */
arg = qse_awk_rtx_makemapvalwithdata (rtx, md);
if (arg == 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);
/* execute the dump function in the awk script */
rtv = qse_awk_rtx_call (rtx, QSE_T("dump"), &arg, 1);
if (rtv == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
if (rtv->type == QSE_AWK_VAL_MAP)
{
/* if a returned value is a map,
* traverse the map and print the key/value pairs. */
qse_awk_val_map_itr_t itr;
qse_awk_val_map_itr_t* iptr;
/* get the iterator to the first key/value pair */
iptr = qse_awk_rtx_getfirstmapvalitr (rtx, rtv, &itr);
while (iptr)
{
qse_xstr_t str;
/* #QSE_AWK_VAL_MAP_ITR_VAL returns the value part */
str.ptr = qse_awk_rtx_valtostrdup (
rtx, QSE_AWK_VAL_MAP_ITR_VAL(iptr), &str.len);
if (str.ptr == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
/* #QSE_AWK_VAL_MAP_ITR_KEY returns the key part */
qse_printf (QSE_T("ret [%.*s]=[%.*s]\n"),
(int)QSE_AWK_VAL_MAP_ITR_KEY(iptr)->len,
QSE_AWK_VAL_MAP_ITR_KEY(iptr)->ptr,
(int)str.len, str.ptr
);
qse_awk_rtx_freemem (rtx, str.ptr);
/* get the iterator to the next key/value pair */
iptr = qse_awk_rtx_getnextmapvalitr (rtx, rtv, &itr);
}
}
else
{
/* if it is a plain value, convert it to a string
* and print it */
qse_xstr_t str;
str.ptr = qse_awk_rtx_valtostrdup (rtx, rtv, &str.len);
if (str.ptr == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_rtx_geterrmsg(rtx));
ret = -1; goto oops;
}
qse_printf (QSE_T("ret [%.*s]\n"), (int)str.len, str.ptr);
qse_awk_rtx_freemem (rtx, str.ptr);
}
oops:
/* clear the return value */
if (rtv) qse_awk_rtx_refdownval (rtx, rtv);
/* dereference the argument */
if (arg) qse_awk_rtx_refdownval (rtx, arg);
/* destroy a runtime context */
if (rtx) qse_awk_rtx_close (rtx);
/* destroy the processor */
if (awk) qse_awk_close (awk);
return ret;
}
int qse_main (int argc, qse_achar_t* argv[])
{
init_awk_sample_locale ();
return qse_runmain (argc, argv, awk_main);
}

View File

@ -346,6 +346,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -182,6 +182,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -195,6 +195,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@

View File

@ -149,6 +149,8 @@ QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
QSE_SIZEOF_OFF64_T = @QSE_SIZEOF_OFF64_T@
QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@