2013-02-22 03:18:42 +00:00
|
|
|
#include <qse/awk/stdawk.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include <qse/si/sio.h>
|
2013-01-14 16:02:04 +00:00
|
|
|
|
|
|
|
/* this sample produces 8 text files containing multiplication chart. */
|
|
|
|
|
|
|
|
const qse_char_t* src = QSE_T(
|
|
|
|
"BEGIN {"
|
|
|
|
" for (i=2;i<=9;i++)"
|
|
|
|
" {"
|
|
|
|
" print \"OFILENAME:\" OFILENAME;"
|
|
|
|
" for (j=1;j<=9;j++)"
|
|
|
|
" print i \"*\" j \"=\" i * j;"
|
|
|
|
" nextofile;"
|
|
|
|
" }"
|
|
|
|
"}"
|
|
|
|
);
|
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
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 = -1, opt;
|
|
|
|
|
|
|
|
const qse_char_t* output_files[] =
|
|
|
|
{
|
2014-06-08 14:11:12 +00:00
|
|
|
QSE_T("awk12.out.2"),
|
|
|
|
QSE_T("awk12.out.3"),
|
|
|
|
QSE_T("awk12.out.4"),
|
|
|
|
QSE_T("awk12.out.5"),
|
|
|
|
QSE_T("awk12.out.6"),
|
|
|
|
QSE_T("awk12.out.7"),
|
|
|
|
QSE_T("awk12.out.8"),
|
|
|
|
QSE_T("awk12.out.9"),
|
2013-01-14 16:02:04 +00:00
|
|
|
QSE_NULL
|
|
|
|
};
|
|
|
|
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_open_stdsios ();
|
2014-06-08 14:11:12 +00:00
|
|
|
|
2014-07-11 14:17:00 +00:00
|
|
|
awk = qse_awk_openstd (0, QSE_NULL);
|
2013-01-14 16:02:04 +00:00
|
|
|
if (awk == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open awk\n"));
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_awk_getopt (awk, QSE_AWK_TRAIT, &opt);
|
2013-01-29 03:43:32 +00:00
|
|
|
opt |= QSE_AWK_NEXTOFILE;
|
2013-01-14 16:02:04 +00:00
|
|
|
qse_awk_setopt (awk, QSE_AWK_TRAIT, &opt);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (qse_awk_parsestd (awk, psin, QSE_NULL) <= -1)
|
|
|
|
{
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"),
|
|
|
|
qse_awk_geterrmsg(awk));
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
rtx = qse_awk_rtx_openstd (
|
|
|
|
awk,
|
|
|
|
0,
|
2014-06-08 14:11:12 +00:00
|
|
|
QSE_T("awk12"),
|
2013-01-14 16:02:04 +00:00
|
|
|
QSE_NULL, /* stdin */
|
|
|
|
output_files,
|
|
|
|
QSE_NULL /* default cmgr */
|
|
|
|
);
|
|
|
|
if (rtx == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"),
|
|
|
|
qse_awk_geterrmsg(awk));
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
retv = qse_awk_rtx_loop (rtx);
|
|
|
|
if (retv == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"),
|
|
|
|
qse_awk_rtx_geterrmsg(rtx));
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_awk_rtx_refdownval (rtx, retv);
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
oops:
|
|
|
|
if (rtx != QSE_NULL) qse_awk_rtx_close (rtx);
|
|
|
|
if (awk != QSE_NULL) qse_awk_close (awk);
|
2014-06-08 14:11:12 +00:00
|
|
|
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_close_stdsios ();
|
2013-01-14 16:02:04 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|