added one more test program for awk

This commit is contained in:
hyung-hwan 2009-02-17 08:22:42 +00:00
parent 5570b60ef2
commit b9958d4ff7
4 changed files with 73 additions and 4 deletions

View File

@ -594,6 +594,8 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_riod_t* riod)
{
/*dprint (QSE_T(" console(w) - <standard output>\n"));*/
/* TODO: open console file properly..... */
if (qse_awk_rtx_setofilename (rtx, QSE_T(""), 0) == -1)
{
return -1;

View File

@ -1,8 +1,9 @@
AM_CPPFLAGS = -I$(top_srcdir)/include
bin_PROGRAMS = awk01
bin_PROGRAMS = awk01 awk03
LDFLAGS = -L../../lib/cmn -L../../lib/utl -L../../lib/awk
LDADD = -lqseawk -lqseutl -lqsecmn $(LIBM)
awk01_SOURCES = awk01.c
awk03_SOURCES = awk03.c

View File

@ -32,7 +32,7 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = awk01$(EXEEXT)
bin_PROGRAMS = awk01$(EXEEXT) awk03$(EXEEXT)
subdir = test/awk
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@ -50,6 +50,10 @@ awk01_OBJECTS = $(am_awk01_OBJECTS)
awk01_LDADD = $(LDADD)
am__DEPENDENCIES_1 =
awk01_DEPENDENCIES = $(am__DEPENDENCIES_1)
am_awk03_OBJECTS = awk03.$(OBJEXT)
awk03_OBJECTS = $(am_awk03_OBJECTS)
awk03_LDADD = $(LDADD)
awk03_DEPENDENCIES = $(am__DEPENDENCIES_1)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include/qse
depcomp = $(SHELL) $(top_srcdir)/autoconf/depcomp
am__depfiles_maybe = depfiles
@ -62,8 +66,8 @@ CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(awk01_SOURCES)
DIST_SOURCES = $(awk01_SOURCES)
SOURCES = $(awk01_SOURCES) $(awk03_SOURCES)
DIST_SOURCES = $(awk01_SOURCES) $(awk03_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -191,6 +195,7 @@ top_srcdir = @top_srcdir@
AM_CPPFLAGS = -I$(top_srcdir)/include
LDADD = -lqseawk -lqseutl -lqsecmn $(LIBM)
awk01_SOURCES = awk01.c
awk03_SOURCES = awk03.c
all: all-am
.SUFFIXES:
@ -255,6 +260,9 @@ clean-binPROGRAMS:
awk01$(EXEEXT): $(awk01_OBJECTS) $(awk01_DEPENDENCIES)
@rm -f awk01$(EXEEXT)
$(LINK) $(awk01_OBJECTS) $(awk01_LDADD) $(LIBS)
awk03$(EXEEXT): $(awk03_OBJECTS) $(awk03_DEPENDENCIES)
@rm -f awk03$(EXEEXT)
$(LINK) $(awk03_OBJECTS) $(awk03_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@ -263,6 +271,7 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk03.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<

57
qse/test/awk/awk03.c Normal file
View File

@ -0,0 +1,57 @@
#include <qse/awk/awk.h>
#include <qse/utl/stdio.h>
const qse_char_t* src = QSE_T(
"function init() { a = 20; }"
"function main() { a++; }"
"function fini() { output (a); }"
"function output(x) { print x; }"
);
int main ()
{
qse_awk_t* awk = QSE_NULL;
qse_awk_rtx_t* rtx = QSE_NULL;
int ret;
awk = qse_awk_opensimple ();
if (awk == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n"));
goto oops;
}
ret = qse_awk_parsesimple (
awk,
QSE_AWK_PARSE_STRING, src, /* parse AWK source in a string */
QSE_NULL /* no parse output */
);
if (ret == -1)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_geterrmsg(awk));
goto oops;
}
rtx = qse_awk_rtx_opensimple (
awk,
QSE_NULL /* no console files */
);
if (rtx == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
qse_awk_geterrmsg(awk));
goto oops;
}
qse_awk_rtx_call (rtx, QSE_T("init"), QSE_NULL, 0);
qse_awk_rtx_call (rtx, QSE_T("main"), QSE_NULL, 0);
qse_awk_rtx_call (rtx, QSE_T("main"), QSE_NULL, 0);
qse_awk_rtx_call (rtx, QSE_T("main"), QSE_NULL, 0);
qse_awk_rtx_call (rtx, QSE_T("fini"), QSE_NULL, 0);
oops:
if (rtx != QSE_NULL) qse_awk_rtx_close (rtx);
if (awk != QSE_NULL) qse_awk_close (awk);
return -1;
}