* fixed a bug of opening a console output file in a wrong mode resulting in failure.

* added a new sample file for awk
This commit is contained in:
hyung-hwan 2011-04-17 08:55:26 +00:00
parent 603af95dca
commit bdc537fbdc
7 changed files with 140 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 344 2010-08-17 13:15:14Z hyunghwan.chung $
* $Id: awk.h 434 2011-04-16 14:55:26Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -52,6 +52,7 @@
*
* @example awk04.c
* This programs shows how to qse_awk_rtx_call().
*
*/
/** @struct qse_awk_t

View File

@ -1,5 +1,5 @@
/*
* $Id: std.h 340 2010-08-01 13:13:38Z hyunghwan.chung $
* $Id: std.h 434 2011-04-16 14:55:26Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -33,6 +33,11 @@
* normal file name.
*/
/**
* @example awk09.c
* This programs shows how to specify multiple console output files.
*/
/**
* The qse_awk_parsestd_type_t type defines a source script type
*/

View File

@ -1,5 +1,5 @@
/*
* $Id: std.c 380 2011-01-31 13:46:52Z hyunghwan.chung $
* $Id: std.c 434 2011-04-16 14:55:26Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -969,7 +969,9 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
else
{
sio = qse_sio_open (
rtx->awk->mmgr, 0, file, QSE_SIO_READ);
rtx->awk->mmgr, 0, file,
QSE_SIO_WRITE | QSE_SIO_CREATE | QSE_SIO_TRUNCATE
);
if (sio == QSE_NULL)
{
qse_cstr_t errarg;

View File

@ -5,7 +5,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(includedir)
bin_PROGRAMS = awk01 awk02 awk03 awk04
bin_PROGRAMS = awk01 awk02 awk03 awk04 awk09
LDFLAGS = -L../../lib/cmn -L../../lib/awk
LDADD = -lqseawk -lqsecmn $(LIBM)
@ -14,6 +14,7 @@ awk01_SOURCES = awk01.c
awk02_SOURCES = awk02.c
awk03_SOURCES = awk03.c
awk04_SOURCES = awk04.c
awk09_SOURCES = awk09.c
if ENABLE_CXX

View File

@ -35,7 +35,7 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = awk01$(EXEEXT) awk02$(EXEEXT) awk03$(EXEEXT) \
awk04$(EXEEXT) $(am__EXEEXT_1)
awk04$(EXEEXT) awk09$(EXEEXT) $(am__EXEEXT_1)
@ENABLE_CXX_TRUE@am__append_1 = awk05 awk06 awk07 awk08
subdir = samples/awk
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
@ -92,6 +92,10 @@ am__awk08_SOURCES_DIST = awk08.cpp
awk08_OBJECTS = $(am_awk08_OBJECTS)
@ENABLE_CXX_TRUE@awk08_DEPENDENCIES = $(am__DEPENDENCIES_1) \
@ENABLE_CXX_TRUE@ $(am__DEPENDENCIES_2)
am_awk09_OBJECTS = awk09.$(OBJEXT)
awk09_OBJECTS = $(am_awk09_OBJECTS)
awk09_LDADD = $(LDADD)
awk09_DEPENDENCIES = $(am__DEPENDENCIES_1)
DEFAULT_INCLUDES =
depcomp = $(SHELL) $(top_srcdir)/ac/depcomp
am__depfiles_maybe = depfiles
@ -116,11 +120,11 @@ CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) \
$(awk04_SOURCES) $(awk05_SOURCES) $(awk06_SOURCES) \
$(awk07_SOURCES) $(awk08_SOURCES)
$(awk07_SOURCES) $(awk08_SOURCES) $(awk09_SOURCES)
DIST_SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) \
$(awk04_SOURCES) $(am__awk05_SOURCES_DIST) \
$(am__awk06_SOURCES_DIST) $(am__awk07_SOURCES_DIST) \
$(am__awk08_SOURCES_DIST)
$(am__awk08_SOURCES_DIST) $(awk09_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -272,6 +276,7 @@ awk01_SOURCES = awk01.c
awk02_SOURCES = awk02.c
awk03_SOURCES = awk03.c
awk04_SOURCES = awk04.c
awk09_SOURCES = awk09.c
@ENABLE_CXX_TRUE@CXXLIB = -lqseawkxx -lqsecmnxx
@ENABLE_CXX_TRUE@awk05_SOURCES = awk05.cpp
@ENABLE_CXX_TRUE@awk06_SOURCES = awk06.cpp
@ -382,6 +387,9 @@ awk07$(EXEEXT): $(awk07_OBJECTS) $(awk07_DEPENDENCIES)
awk08$(EXEEXT): $(awk08_OBJECTS) $(awk08_DEPENDENCIES)
@rm -f awk08$(EXEEXT)
$(CXXLINK) $(awk08_OBJECTS) $(awk08_LDADD) $(LIBS)
awk09$(EXEEXT): $(awk09_OBJECTS) $(awk09_DEPENDENCIES)
@rm -f awk09$(EXEEXT)
$(LINK) $(awk09_OBJECTS) $(awk09_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@ -397,6 +405,7 @@ distclean-compile:
@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)/awk08.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk09.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<

View File

@ -26,7 +26,7 @@
#if defined(_WIN32)
# include <windows.h>
#if defined(__OS2__)
#elif defined(__OS2__)
# define INCL_DOSPROCESS
# include <os2.h>
#else

113
qse/samples/awk/awk09.c Normal file
View File

@ -0,0 +1,113 @@
/*
* $Id$
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#include <qse/awk/std.h>
#include <qse/cmn/stdio.h>
/* this sample produces 8 text files containing multiplication char */
const qse_char_t* src = QSE_T(
"BEGIN {"
" printf \"\"; # work around the empty OFILENAME when printed\n"
" # for the first time in the loop below\n"
" # this happens because the console file is opened\n"
" # and OFILENAME is set when the first console output\n"
" # operation is peformed\n"
" 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_in_t psin;
int ret = -1;
const qse_char_t* output_files[] =
{
QSE_T("awk09.out.2"),
QSE_T("awk09.out.3"),
QSE_T("awk09.out.4"),
QSE_T("awk09.out.5"),
QSE_T("awk09.out.6"),
QSE_T("awk09.out.7"),
QSE_T("awk09.out.8"),
QSE_T("awk09.out.9"),
QSE_NULL
};
awk = qse_awk_openstd (0);
if (awk == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open awk\n"));
goto oops;
}
qse_awk_setoption (awk, qse_awk_getoption(awk) | QSE_AWK_NEXTOFILE);
psin.type = QSE_AWK_PARSESTD_CP;
psin.u.cp = src;
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,
QSE_T("awk09"),
QSE_NULL, /* stdin */
output_files
);
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);
return ret;
}