From 60255caf396987d8d65ce6a91c3d288c267be37d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 6 Feb 2013 14:31:32 +0000 Subject: [PATCH] added more code to xli --- qse/cmd/Makefile.am | 2 +- qse/cmd/Makefile.in | 2 +- qse/cmd/sed/sed.c | 4 +- qse/cmd/xli/Makefile.am | 18 + qse/cmd/xli/Makefile.in | 588 ++++++++++++++++++++++++++++++++ qse/cmd/xli/xli.c | 416 ++++++++++++++++++++++ qse/configure | 3 +- qse/configure.ac | 1 + qse/include/qse/xli/Makefile.am | 2 +- qse/include/qse/xli/Makefile.in | 2 +- qse/include/qse/xli/xli.h | 44 ++- qse/lib/awk/awk.c | 30 +- qse/lib/awk/awk.h | 4 +- qse/lib/awk/err.c | 2 +- qse/lib/awk/parse.c | 28 +- qse/lib/awk/std.c | 4 - qse/lib/sed/sed.c | 12 +- qse/lib/xli/Makefile.am | 2 +- qse/lib/xli/Makefile.in | 8 +- qse/lib/xli/read.c | 378 +++++++++++++++----- qse/lib/xli/write.c | 35 ++ qse/lib/xli/xli.c | 112 ++++-- qse/lib/xli/xli.h | 5 +- 23 files changed, 1523 insertions(+), 179 deletions(-) create mode 100644 qse/cmd/xli/Makefile.am create mode 100644 qse/cmd/xli/Makefile.in create mode 100644 qse/cmd/xli/xli.c create mode 100644 qse/lib/xli/write.c diff --git a/qse/cmd/Makefile.am b/qse/cmd/Makefile.am index c999e56b..4ab3fa4d 100644 --- a/qse/cmd/Makefile.am +++ b/qse/cmd/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = awk sed net +SUBDIRS = awk sed xli net DIST_SUBDIRS = $(SUBDIRS) diff --git a/qse/cmd/Makefile.in b/qse/cmd/Makefile.in index 747d22e3..7b06c40e 100644 --- a/qse/cmd/Makefile.in +++ b/qse/cmd/Makefile.in @@ -263,7 +263,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -SUBDIRS = awk sed net +SUBDIRS = awk sed xli net DIST_SUBDIRS = $(SUBDIRS) all: all-recursive diff --git a/qse/cmd/sed/sed.c b/qse/cmd/sed/sed.c index 3720d5a5..2639f922 100644 --- a/qse/cmd/sed/sed.c +++ b/qse/cmd/sed/sed.c @@ -741,9 +741,11 @@ static int sed_main (int argc, qse_char_t* argv[]) if (qse_sed_compstd (sed, g_script.io, &script_count) <= -1) { - const qse_sed_loc_t* errloc = qse_sed_geterrloc(sed); + const qse_sed_loc_t* errloc; const qse_char_t* target; qse_char_t exprbuf[128]; + + errloc = qse_sed_geterrloc(sed); if (g_script.io[script_count].type == QSE_SED_IOSTD_FILE) { diff --git a/qse/cmd/xli/Makefile.am b/qse/cmd/xli/Makefile.am new file mode 100644 index 00000000..8480a41a --- /dev/null +++ b/qse/cmd/xli/Makefile.am @@ -0,0 +1,18 @@ +AUTOMAKE_OPTIONS = nostdinc + +AM_CPPFLAGS = \ + -I$(top_builddir)/include \ + -I$(top_srcdir)/include \ + -I$(includedir) + +bin_PROGRAMS = qsexli + +qsexli_SOURCES = xli.c +qsexli_LDFLAGS = -L../../lib/xli -L../../lib/cmn -L$(libdir) +qsexli_LDADD = -lqsexli -lqsecmn + +if WIN32 +if WCHAR +qsexli_LDADD += $(UNICOWS_LIBS) +endif +endif diff --git a/qse/cmd/xli/Makefile.in b/qse/cmd/xli/Makefile.in new file mode 100644 index 00000000..267b6e7f --- /dev/null +++ b/qse/cmd/xli/Makefile.in @@ -0,0 +1,588 @@ +# Makefile.in generated by automake 1.11.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software +# Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +bin_PROGRAMS = qsexli$(EXEEXT) +@WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS) +subdir = cmd/xli +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/argz.m4 \ + $(top_srcdir)/m4/ax_numval.m4 $(top_srcdir)/m4/ax_pthread.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltdl.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/m4/lx_find_mpi.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/include/qse/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +PROGRAMS = $(bin_PROGRAMS) +am_qsexli_OBJECTS = xli.$(OBJEXT) +qsexli_OBJECTS = $(am_qsexli_OBJECTS) +am__DEPENDENCIES_1 = +@WCHAR_TRUE@@WIN32_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) +qsexli_DEPENDENCIES = $(am__DEPENDENCIES_2) +qsexli_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(qsexli_LDFLAGS) \ + $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = +depcomp = $(SHELL) $(top_srcdir)/ac/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(qsexli_SOURCES) +DIST_SOURCES = $(qsexli_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +ARGZ_H = @ARGZ_H@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BUILD_MODE = @BUILD_MODE@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CHAR_MODE = @CHAR_MODE@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +HAVE_CXX = @HAVE_CXX@ +INCLTDL = @INCLTDL@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBADD_DL = @LIBADD_DL@ +LIBADD_DLD_LINK = @LIBADD_DLD_LINK@ +LIBADD_DLOPEN = @LIBADD_DLOPEN@ +LIBADD_SHL_LOAD = @LIBADD_SHL_LOAD@ +LIBLTDL = @LIBLTDL@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTDLDEPS = @LTDLDEPS@ +LTDLINCL = @LTDLINCL@ +LTDLOPEN = @LTDLOPEN@ +LTLIBOBJS = @LTLIBOBJS@ +LT_CONFIG_H = @LT_CONFIG_H@ +LT_DLLOADERS = @LT_DLLOADERS@ +LT_DLPREOPEN = @LT_DLPREOPEN@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MPICC = @MPICC@ +MPI_CFLAGS = @MPI_CFLAGS@ +MPI_CLDFLAGS = @MPI_CLDFLAGS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PACKAGE_VERSION_MAJOR = @PACKAGE_VERSION_MAJOR@ +PACKAGE_VERSION_MINOR = @PACKAGE_VERSION_MINOR@ +PACKAGE_VERSION_PATCH = @PACKAGE_VERSION_PATCH@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PTHREAD_CC = @PTHREAD_CC@ +PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ +PTHREAD_LIBS = @PTHREAD_LIBS@ +QSE_PROJECT_AUTHOR = @QSE_PROJECT_AUTHOR@ +QSE_PROJECT_URL = @QSE_PROJECT_URL@ +QSE_SIZEOF_CHAR = @QSE_SIZEOF_CHAR@ +QSE_SIZEOF_DOUBLE = @QSE_SIZEOF_DOUBLE@ +QSE_SIZEOF_FLOAT = @QSE_SIZEOF_FLOAT@ +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@ +RANLIB = @RANLIB@ +RM = @RM@ +RMDIR = @RMDIR@ +SED = @SED@ +SENDFILE_LIBS = @SENDFILE_LIBS@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SOCKET_LIBS = @SOCKET_LIBS@ +SSL_LIBS = @SSL_LIBS@ +STRIP = @STRIP@ +TRUE = @TRUE@ +UCI_LIBS = @UCI_LIBS@ +UNICOWS_LIBS = @UNICOWS_LIBS@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +ax_pthread_config = @ax_pthread_config@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +ltdl_LIBOBJS = @ltdl_LIBOBJS@ +ltdl_LTLIBOBJS = @ltdl_LTLIBOBJS@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +subdirs = @subdirs@ +sys_symbol_underscore = @sys_symbol_underscore@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +AUTOMAKE_OPTIONS = nostdinc +AM_CPPFLAGS = \ + -I$(top_builddir)/include \ + -I$(top_srcdir)/include \ + -I$(includedir) + +qsexli_SOURCES = xli.c +qsexli_LDFLAGS = -L../../lib/xli -L../../lib/cmn -L$(libdir) +qsexli_LDADD = -lqsexli -lqsecmn $(am__append_1) +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign cmd/xli/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign cmd/xli/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p || test -f $$p1; \ + then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + +clean-binPROGRAMS: + @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +qsexli$(EXEEXT): $(qsexli_OBJECTS) $(qsexli_DEPENDENCIES) $(EXTRA_qsexli_DEPENDENCIES) + @rm -f qsexli$(EXEEXT) + $(qsexli_LINK) $(qsexli_OBJECTS) $(qsexli_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xli.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ + clean-generic clean-libtool ctags distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-binPROGRAMS install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am \ + uninstall-binPROGRAMS + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/qse/cmd/xli/xli.c b/qse/cmd/xli/xli.c new file mode 100644 index 00000000..87e46b9f --- /dev/null +++ b/qse/cmd/xli/xli.c @@ -0,0 +1,416 @@ +/* + * $Id$ + * + Copyright 2006-2012 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#if defined(_WIN32) +# include +# include +# include +#elif defined(__OS2__) +# define INCL_DOSPROCESS +# define INCL_DOSEXCEPTIONS +# define INCL_ERRORS +# include +#elif defined(__DOS__) +# include +#else +# include +# include +#endif + +static qse_char_t* g_input_file = QSE_NULL; +static qse_char_t* g_output_file = QSE_NULL; +static qse_ulong_t g_memlimit = 0; +static int g_option = 0; + +static qse_cmgr_t* g_infile_cmgr = QSE_NULL; +static qse_cmgr_t* g_outfile_cmgr = QSE_NULL; + +#if defined(QSE_BUILD_DEBUG) +#include +static qse_ulong_t g_failmalloc = 0; +static qse_ulong_t debug_mmgr_count = 0; +static qse_ulong_t debug_mmgr_alloc_count = 0; +static qse_ulong_t debug_mmgr_realloc_count = 0; +static qse_ulong_t debug_mmgr_free_count = 0; + +static void* debug_mmgr_alloc (void* ctx, qse_size_t size) +{ + void* ptr; + debug_mmgr_count++; + if (debug_mmgr_count % g_failmalloc == 0) return QSE_NULL; + ptr = malloc (size); + if (ptr) debug_mmgr_alloc_count++; + return ptr; +} + +static void* debug_mmgr_realloc (void* ctx, void* ptr, qse_size_t size) +{ + void* rptr; + debug_mmgr_count++; + if (debug_mmgr_count % g_failmalloc == 0) return QSE_NULL; + rptr = realloc (ptr, size); + if (rptr) + { + if (ptr) debug_mmgr_realloc_count++; + else debug_mmgr_alloc_count++; + } + return rptr; +} + +static void debug_mmgr_free (void* ctx, void* ptr) +{ + debug_mmgr_free_count++; + free (ptr); +} + +static qse_mmgr_t debug_mmgr = +{ + debug_mmgr_alloc, + debug_mmgr_realloc, + debug_mmgr_free, + QSE_NULL +}; +#endif + +static qse_mmgr_t xma_mmgr = +{ + (qse_mmgr_alloc_t)qse_xma_alloc, + (qse_mmgr_realloc_t)qse_xma_realloc, + (qse_mmgr_free_t)qse_xma_free, + QSE_NULL +}; + +static void print_version (void) +{ + qse_printf (QSE_T("QSEXLI version %hs\n"), QSE_PACKAGE_VERSION); +} + +static void print_usage (QSE_FILE* out, int argc, qse_char_t* argv[]) +{ + const qse_char_t* b = qse_basename (argv[0]); + + qse_fprintf (out, QSE_T("USAGE: %s [options] -f input-file\n"), b); + + qse_fprintf (out, QSE_T("options as follows:\n")); + qse_fprintf (out, QSE_T(" -h/--help show this message\n")); + qse_fprintf (out, QSE_T(" --version show version\n")); + qse_fprintf (out, QSE_T(" -f file specify an input file\n")); + qse_fprintf (out, QSE_T(" -o file specify an output file\n")); + qse_fprintf (out, QSE_T(" -m number specify the maximum amount of memory to use in bytes\n")); +#if defined(QSE_BUILD_DEBUG) + qse_fprintf (out, QSE_T(" -X number fail the number'th memory allocation\n")); +#endif +#if defined(QSE_CHAR_IS_WCHAR) + qse_fprintf (out, QSE_T(" --infile-encoding string specify input file encoding name\n")); + qse_fprintf (out, QSE_T(" --outfile-encoding string specify output file encoding name\n")); +#endif +} + +static int handle_args (int argc, qse_char_t* argv[]) +{ + static qse_opt_lng_t lng[] = + { +#if defined(QSE_CHAR_IS_WCHAR) + { QSE_T(":infile-encoding"), QSE_T('\0') }, + { QSE_T(":outfile-encoding"), QSE_T('\0') }, +#endif + + { QSE_T("version"), QSE_T('\0') }, + { QSE_T("help"), QSE_T('h') }, + { QSE_NULL, QSE_T('\0') } + }; + static qse_opt_t opt = + { +#if defined(QSE_BUILD_DEBUG) + QSE_T("hf:o:m:X:"), +#else + QSE_T("hf:o:m:"), +#endif + lng + }; + qse_cint_t c; + + while ((c = qse_getopt (argc, argv, &opt)) != QSE_CHAR_EOF) + { + switch (c) + { + default: + print_usage (QSE_STDERR, argc, argv); + goto oops; + + case QSE_T('?'): + qse_fprintf (QSE_STDERR, + QSE_T("ERROR: bad option - %c\n"), + opt.opt + ); + print_usage (QSE_STDERR, argc, argv); + goto oops; + + case QSE_T(':'): + qse_fprintf (QSE_STDERR, + QSE_T("ERROR: bad parameter for %c\n"), + opt.opt + ); + print_usage (QSE_STDERR, argc, argv); + goto oops; + + case QSE_T('h'): + print_usage (QSE_STDOUT, argc, argv); + goto done; + + case QSE_T('f'): + g_input_file = opt.arg; + break; + + case QSE_T('o'): + g_output_file = opt.arg; + break; + + case QSE_T('m'): + g_memlimit = qse_strtoulong (opt.arg); + break; + +#if defined(QSE_BUILD_DEBUG) + case QSE_T('X'): + g_failmalloc = qse_strtoulong (opt.arg); + break; +#endif + + case QSE_T('\0'): + { + if (qse_strcmp(opt.lngopt, QSE_T("version")) == 0) + { + print_version (); + goto done; + } + else if (qse_strcmp(opt.lngopt, QSE_T("infile-encoding")) == 0) + { + g_infile_cmgr = qse_findcmgr (opt.arg); + if (g_infile_cmgr == QSE_NULL) + { + qse_fprintf (QSE_STDERR, QSE_T("ERROR: unknown input file encoding - %s\n"), opt.arg); + goto oops; + } + } + else if (qse_strcmp(opt.lngopt, QSE_T("outfile-encoding")) == 0) + { + g_outfile_cmgr = qse_findcmgr (opt.arg); + if (g_outfile_cmgr == QSE_NULL) + { + qse_fprintf (QSE_STDERR, QSE_T("ERROR: unknown output file encoding - %s\n"), opt.arg); + goto oops; + } + } + break; + } + + } + } + + if (!g_input_file) + { + print_usage (QSE_STDERR, argc, argv); + goto oops; + } + + return 1; + +oops: + return -1; + +done: + return 0; +} + +void print_exec_error (qse_xli_t* xli) +{ +#if 0 + const qse_xli_loc_t* errloc = qse_xli_geterrloc(xli); + if (errloc->line > 0 || errloc->colm > 0) + { + qse_fprintf (QSE_STDERR, + QSE_T("ERROR: cannot execute - %s at line %lu column %lu\n"), + qse_xli_geterrmsg(xli), + (unsigned long)errloc->line, + (unsigned long)errloc->colm + ); + } + else + { + qse_fprintf (QSE_STDERR, + QSE_T("ERROR: cannot execute - %s\n"), + qse_xli_geterrmsg(xli) + ); + } +#endif +} + +static int xli_main (int argc, qse_char_t* argv[]) +{ + qse_mmgr_t* mmgr = QSE_MMGR_GETDFL(); + qse_xli_t* xli = QSE_NULL; + qse_fs_t* fs = QSE_NULL; + qse_xli_iostd_t in, out; + int ret = -1; + + ret = handle_args (argc, argv); + if (ret <= -1) return -1; + if (ret == 0) return 0; + + ret = -1; + +#if defined(QSE_BUILD_DEBUG) + if (g_failmalloc > 0) + { + debug_mmgr.ctx = QSE_NULL; + mmgr = &debug_mmgr; + } + else +#endif + if (g_memlimit > 0) + { + xma_mmgr.ctx = qse_xma_open (QSE_MMGR_GETDFL(), 0, g_memlimit); + if (xma_mmgr.ctx == QSE_NULL) + { + qse_printf (QSE_T("ERROR: cannot open memory heap\n")); + goto oops; + } + mmgr = &xma_mmgr; + } + + xli = qse_xli_openstdwithmmgr (mmgr, 0); + if (xli == QSE_NULL) + { + qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open stream editor\n")); + goto oops; + } + + qse_xli_setopt (xli, QSE_XLI_TRAIT, &g_option); + + in.type = QSE_XLI_IOSTD_FILE; + in.u.file.path = g_input_file; + in.u.file.cmgr = g_infile_cmgr; + + if (qse_xli_readstd (xli, &in) <= -1) + { +#if 0 + const qse_xli_loc_t* errloc; + const qse_char_t* target; + qse_char_t exprbuf[128]; + + errloc = getxli_geterrloc (xli); + if (g_script.io[script_count].type == QSE_XLI_IOSTD_FILE) + { + target = g_script.io[script_count].u.file.path; + } + else + { + /* i dont' use QSE_XLI_IOSTD_SIO for input */ + QSE_ASSERT (g_script.io[script_count].type == QSE_XLI_IOSTD_STR); + qse_sprintf (exprbuf, QSE_COUNTOF(exprbuf), + QSE_T("expression #%lu"), (unsigned long)script_count); + target = exprbuf; + } + + if (errloc->line > 0 || errloc->colm > 0) + { + qse_fprintf (QSE_STDERR, + QSE_T("ERROR: cannot compile %s - %s at line %lu column %lu\n"), + target, + qse_xli_geterrmsg(xli), + (unsigned long)errloc->line, + (unsigned long)errloc->colm + ); + } + else + { + qse_fprintf (QSE_STDERR, + QSE_T("ERROR: cannot compile %s - %s\n"), + target, + qse_xli_geterrmsg(xli) + ); + } +#endif + qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot read\n")); + goto oops; + } + + ret = 0; + +oops: + if (xli) qse_xli_close (xli); + if (fs) qse_fs_close (fs); + if (xma_mmgr.ctx) qse_xma_close (xma_mmgr.ctx); + +#if defined(QSE_BUILD_DEBUG) + if (g_failmalloc > 0) + { + qse_fprintf (QSE_STDERR, QSE_T("\n")); + qse_fprintf (QSE_STDERR, QSE_T("-[MALLOC COUNTS]---------------------------------------\n")); + qse_fprintf (QSE_STDERR, QSE_T("ALLOC: %lu FREE: %lu: REALLOC: %lu\n"), + (unsigned long)debug_mmgr_alloc_count, + (unsigned long)debug_mmgr_free_count, + (unsigned long)debug_mmgr_realloc_count); + qse_fprintf (QSE_STDERR, QSE_T("-------------------------------------------------------\n")); + } +#endif + return ret; +} + +int qse_main (int argc, qse_achar_t* argv[]) +{ +#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 + + return qse_runmain (argc, argv, xli_main); +} + diff --git a/qse/configure b/qse/configure index 9150a2fd..cd30dcd4 100755 --- a/qse/configure +++ b/qse/configure @@ -20846,7 +20846,7 @@ QSE_PROJECT_AUTHOR="${PACKAGE_BUGREPORT}" QSE_PROJECT_URL="${PACKAGE_URL}" -ac_config_files="$ac_config_files Makefile README include/Makefile include/qse/Makefile include/qse/cmn/Makefile include/qse/awk/Makefile include/qse/sed/Makefile include/qse/xli/Makefile include/qse/net/Makefile lib/Makefile lib/cmn/Makefile lib/awk/Makefile lib/sed/Makefile lib/xli/Makefile lib/net/Makefile cmd/Makefile cmd/awk/Makefile cmd/sed/Makefile cmd/net/Makefile samples/Makefile samples/cmn/Makefile samples/awk/Makefile samples/sed/Makefile samples/net/Makefile regress/Makefile regress/awk/Makefile regress/awk/regress.sh regress/sed/Makefile regress/sed/regress.sh doc/Makefile doc/Doxyfile tools/Makefile" +ac_config_files="$ac_config_files Makefile README include/Makefile include/qse/Makefile include/qse/cmn/Makefile include/qse/awk/Makefile include/qse/sed/Makefile include/qse/xli/Makefile include/qse/net/Makefile lib/Makefile lib/cmn/Makefile lib/awk/Makefile lib/sed/Makefile lib/xli/Makefile lib/net/Makefile cmd/Makefile cmd/awk/Makefile cmd/sed/Makefile cmd/xli/Makefile cmd/net/Makefile samples/Makefile samples/cmn/Makefile samples/awk/Makefile samples/sed/Makefile samples/net/Makefile regress/Makefile regress/awk/Makefile regress/awk/regress.sh regress/sed/Makefile regress/sed/regress.sh doc/Makefile doc/Doxyfile tools/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -22036,6 +22036,7 @@ do "cmd/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/Makefile" ;; "cmd/awk/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/awk/Makefile" ;; "cmd/sed/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/sed/Makefile" ;; + "cmd/xli/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/xli/Makefile" ;; "cmd/net/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/net/Makefile" ;; "samples/Makefile") CONFIG_FILES="$CONFIG_FILES samples/Makefile" ;; "samples/cmn/Makefile") CONFIG_FILES="$CONFIG_FILES samples/cmn/Makefile" ;; diff --git a/qse/configure.ac b/qse/configure.ac index e1ed6b57..f205913a 100644 --- a/qse/configure.ac +++ b/qse/configure.ac @@ -535,6 +535,7 @@ AC_CONFIG_FILES([ cmd/Makefile cmd/awk/Makefile cmd/sed/Makefile + cmd/xli/Makefile cmd/net/Makefile samples/Makefile samples/cmn/Makefile diff --git a/qse/include/qse/xli/Makefile.am b/qse/include/qse/xli/Makefile.am index b8a123e6..70d5ebe9 100644 --- a/qse/include/qse/xli/Makefile.am +++ b/qse/include/qse/xli/Makefile.am @@ -1,4 +1,4 @@ pkgincludedir= $(includedir)/qse/xli -pkginclude_HEADERS = xli.h +pkginclude_HEADERS = xli.h std.h diff --git a/qse/include/qse/xli/Makefile.in b/qse/include/qse/xli/Makefile.in index ade3f516..7411b560 100644 --- a/qse/include/qse/xli/Makefile.in +++ b/qse/include/qse/xli/Makefile.in @@ -257,7 +257,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -pkginclude_HEADERS = xli.h +pkginclude_HEADERS = xli.h std.h all: all-am .SUFFIXES: diff --git a/qse/include/qse/xli/xli.h b/qse/include/qse/xli/xli.h index 5c4d1a2d..29e5ae3f 100644 --- a/qse/include/qse/xli/xli.h +++ b/qse/include/qse/xli/xli.h @@ -93,6 +93,7 @@ struct qse_xli_list_t struct qse_xli_str_t { QSE_XLI_VAL_HDR; + int verbatim; const qse_char_t* ptr; qse_size_t len; }; @@ -137,6 +138,10 @@ typedef void (*qse_xli_ecb_close_t) ( qse_xli_t* xli /**< xli */ ); +typedef void (*qse_xli_ecb_clear_t) ( + qse_xli_t* xli /**< xli */ +); + /** * The qse_xli_ecb_t type defines an event callback set. * You can register a callback function set with @@ -146,10 +151,10 @@ typedef void (*qse_xli_ecb_close_t) ( typedef struct qse_xli_ecb_t qse_xli_ecb_t; struct qse_xli_ecb_t { - /** - * called by qse_xli_close(). - */ + /** called by qse_xli_close() */ qse_xli_ecb_close_t close; + /** called by qse_xli_clear() */ + qse_xli_ecb_clear_t clear; /* internal use only. don't touch this field */ qse_xli_ecb_t* next; @@ -191,7 +196,7 @@ struct qse_xli_io_lxc_t enum qse_xli_io_arg_flag_t { - QSE_XLI_SIO_INCLUDED = (1 << 0) + QSE_XLI_IO_INCLUDED = (1 << 0) }; typedef struct qse_xli_io_arg_t qse_xli_io_arg_t; @@ -282,7 +287,6 @@ QSE_EXPORT qse_xli_ecb_t* qse_xli_popecb ( qse_xli_t* xli ); - QSE_EXPORT void* qse_xli_allocmem ( qse_xli_t* xli, qse_size_t size @@ -298,21 +302,39 @@ QSE_EXPORT void qse_xli_freemem ( void* ptr ); +QSE_EXPORT qse_xli_pair_t* qse_xli_insertpairwithemptylist ( + qse_xli_t* xli, + qse_xli_list_t* parent, + qse_xli_atom_t* peer, + const qse_char_t* key, + const qse_char_t* name +); + +QSE_EXPORT qse_xli_pair_t* qse_xli_insertpairwithstr ( + qse_xli_t* xli, + qse_xli_list_t* parent, + qse_xli_atom_t* peer, + const qse_char_t* key, + const qse_char_t* name, + const qse_char_t* value, + int verbatim +); + + +QSE_EXPORT void qse_xli_clear ( + qse_xli_t* xli +); + QSE_EXPORT int qse_xli_read ( qse_xli_t* xli, qse_xli_io_impl_t io ); - QSE_EXPORT int qse_xli_write ( - qse_xli_t* xli, + qse_xli_t* xli, qse_xli_io_impl_t io ); -QSE_EXPORT void qse_xli_clear ( - qse_xli_t* xli -); - #if defined(__cplusplus) } #endif diff --git a/qse/lib/awk/awk.c b/qse/lib/awk/awk.c index 21c7bf9e..8a9f29b2 100644 --- a/qse/lib/awk/awk.c +++ b/qse/lib/awk/awk.c @@ -151,15 +151,14 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_awk_prm_t* pr if (init_token (mmgr, &awk->tok) == -1) goto oops; if (init_token (mmgr, &awk->ntok) == -1) goto oops; - awk->sio.names = qse_htb_open ( + awk->sio_names = qse_htb_open ( mmgr, QSE_SIZEOF(awk), 128, 70, QSE_SIZEOF(qse_char_t), 1 ); - if (awk->sio.names == QSE_NULL) goto oops; - *(qse_awk_t**)QSE_XTN(awk->sio.names) = awk; - qse_htb_setmancbs (awk->sio.names, + if (awk->sio_names == QSE_NULL) goto oops; + *(qse_awk_t**)QSE_XTN(awk->sio_names) = awk; + qse_htb_setmancbs (awk->sio_names, qse_gethtbmancbs(QSE_HTB_MANCBS_INLINE_KEY_COPIER) ); - awk->sio.inp = &awk->sio.arg; /* TODO: initial map size?? */ awk->tree.funs = qse_htb_open ( @@ -257,7 +256,7 @@ oops: if (awk->parse.named) qse_htb_close (awk->parse.named); if (awk->parse.funs) qse_htb_close (awk->parse.funs); if (awk->tree.funs) qse_htb_close (awk->tree.funs); - if (awk->sio.names) qse_htb_close (awk->sio.names); + if (awk->sio_names) qse_htb_close (awk->sio_names); fini_token (&awk->ntok); fini_token (&awk->tok); fini_token (&awk->ptok); @@ -287,7 +286,7 @@ int qse_awk_close (qse_awk_t* awk) qse_htb_close (awk->parse.funs); qse_htb_close (awk->tree.funs); - qse_htb_close (awk->sio.names); + qse_htb_close (awk->sio_names); fini_token (&awk->ntok); fini_token (&awk->tok); @@ -391,26 +390,11 @@ int qse_awk_clear (qse_awk_t* awk) awk->tree.chain_tail = QSE_NULL; awk->tree.chain_size = 0; - QSE_ASSERT (awk->sio.inp == &awk->sio.arg); /* this table must not be cleared here as there can be a reference * to an entry of this table from errinf.fil when qse_awk_parse() * failed. this table is cleared in qse_awk_parse(). - * qse_htb_clear (awk->sio.names); + * qse_htb_clear (awk->sio_names); */ - - awk->sio.last.c = QSE_CHAR_EOF; - awk->sio.last.line = 0; - awk->sio.last.colm = 0; - awk->sio.last.file = QSE_NULL; - awk->sio.nungots = 0; - - awk->sio.arg.flags = 0; - awk->sio.arg.name = QSE_NULL; - awk->sio.arg.line = 1; - awk->sio.arg.colm = 1; - awk->sio.arg.b.pos = 0; - awk->sio.arg.b.len = 0; - return 0; } diff --git a/qse/lib/awk/awk.h b/qse/lib/awk/awk.h index cbd93d5d..ff024d3e 100644 --- a/qse/lib/awk/awk.h +++ b/qse/lib/awk/awk.h @@ -201,9 +201,9 @@ struct qse_awk_t qse_awk_sio_lxc_t ungot[5]; qse_awk_sio_arg_t arg; /* for the top level source */ - qse_awk_sio_arg_t* inp; /* current input */ - qse_htb_t* names; + qse_awk_sio_arg_t* inp; /* current input argument. */ } sio; + qse_htb_t* sio_names; /* previous token */ qse_awk_tok_t ptok; diff --git a/qse/lib/awk/err.c b/qse/lib/awk/err.c index 04a6ab27..8f703432 100644 --- a/qse/lib/awk/err.c +++ b/qse/lib/awk/err.c @@ -101,7 +101,7 @@ const qse_char_t* qse_awk_dflerrstr (const qse_awk_t* awk, qse_awk_errnum_t errn QSE_T("'nextfile' illegal in the END block"), QSE_T("both prefix and postfix increment/decrement operator present"), QSE_T("illegal operand for increment/decrement operator"), - QSE_T("'include' not followed by a string"), + QSE_T("'@include' not followed by a string"), QSE_T("include level too deep"), QSE_T("@word '${0}' not recognized"), QSE_T("@ not followed by a valid word"), diff --git a/qse/lib/awk/parse.c b/qse/lib/awk/parse.c index 36bf5ff3..5ad7a326 100644 --- a/qse/lib/awk/parse.c +++ b/qse/lib/awk/parse.c @@ -601,7 +601,7 @@ oops: if (ret <= -1) { /* an error occurred and control has reached here - * probably, some included files might not have beed + * probably, some included files might not have been * closed. close them */ while (awk->sio.inp != &awk->sio.arg) { @@ -667,9 +667,15 @@ int qse_awk_parse (qse_awk_t* awk, qse_awk_sio_t* sio) QSE_ASSERT (awk->parse.depth.expr == 0); qse_awk_clear (awk); - qse_htb_clear (awk->sio.names); + qse_htb_clear (awk->sio_names); + + QSE_MEMSET (&awk->sio, 0, QSE_SIZEOF(awk->sio)); awk->sio.inf = sio->in; awk->sio.outf = sio->out; + awk->sio.last.c = QSE_CHAR_EOF; + awk->sio.arg.line = 1; + awk->sio.arg.colm = 1; + awk->sio.inp = &awk->sio.arg; n = parse (awk); if (n == 0 && awk->sio.outf != QSE_NULL) n = deparse (awk); @@ -740,9 +746,9 @@ static int begin_include (qse_awk_t* awk) return -1; } - /* store the file name to awk->sio.names */ + /* store the file name to awk->sio_names */ pair = qse_htb_ensert ( - awk->sio.names, + awk->sio_names, QSE_STR_PTR(awk->tok.name), QSE_STR_LEN(awk->tok.name) + 1, /* to include '\0' */ QSE_NULL, 0 @@ -771,6 +777,8 @@ static int begin_include (qse_awk_t* awk) arg->flags = QSE_AWK_SIO_INCLUDED; arg->name = QSE_HTB_KPTR(pair); + arg->line = 1; + arg->colm = 1; CLRERR (awk); op = awk->sio.inf (awk, QSE_AWK_SIO_OPEN, arg, QSE_NULL, 0); @@ -785,9 +793,6 @@ static int begin_include (qse_awk_t* awk) awk->sio.inp = arg; awk->parse.depth.incl++; - awk->sio.inp->line = 1; - awk->sio.inp->colm = 1; - /* read in the first character in the included file. * so the next call to get_token() sees the character read * from this file. */ @@ -851,8 +856,7 @@ static int parse_progunit (qse_awk_t* awk) if (!MATCH(awk,TOK_STR)) { - SETERR_LOC ( - awk, QSE_AWK_EINCLSTR, &awk->ptok.loc); + SETERR_LOC (awk, QSE_AWK_EINCLSTR, &awk->ptok.loc); return -1; } @@ -6081,7 +6085,6 @@ retry: ADD_TOKEN_CHAR (awk, tok, c); } - return 0; } else { @@ -6249,10 +6252,7 @@ static int deparse (qse_awk_t* awk) QSE_ASSERT (awk->sio.outf != QSE_NULL); - awk->sio.arg.name = QSE_NULL; - awk->sio.arg.handle = QSE_NULL; - awk->sio.arg.b.len = 0; - awk->sio.arg.b.pos = 0; + QSE_MEMSET (&awk->sio.arg, 0, QSE_SIZEOF(awk->sio.arg)); CLRERR (awk); op = awk->sio.outf ( diff --git a/qse/lib/awk/std.c b/qse/lib/awk/std.c index 3ef0d4e1..7b3a62ba 100644 --- a/qse/lib/awk/std.c +++ b/qse/lib/awk/std.c @@ -749,8 +749,6 @@ static qse_ssize_t sf_in_open ( awk->sio.arg.name = xtn->s.in.x[0].u.file.path; else awk->sio.arg.name = QSE_NULL; - awk->sio.arg.line = 1; - awk->sio.arg.colm = 1; } return x; @@ -902,8 +900,6 @@ static qse_ssize_t sf_in_read ( awk->sio.arg.name = xtn->s.in.x[next].u.file.path; else awk->sio.arg.name = QSE_NULL; - awk->sio.arg.line = 1; - awk->sio.arg.colm = 1; goto again; } diff --git a/qse/lib/sed/sed.c b/qse/lib/sed/sed.c index 32050aaa..3fccb3e1 100644 --- a/qse/lib/sed/sed.c +++ b/qse/lib/sed/sed.c @@ -62,12 +62,14 @@ qse_sed_t* qse_sed_open (qse_mmgr_t* mmgr, qse_size_t xtnsize) qse_sed_t* sed; sed = (qse_sed_t*) QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_sed_t) + xtnsize); - if (sed == QSE_NULL) return QSE_NULL; - - if (qse_sed_init (sed, mmgr) <= -1) + if (sed) { - QSE_MMGR_FREE (sed->mmgr, sed); - return QSE_NULL; + if (qse_sed_init (sed, mmgr) <= -1) + { + QSE_MMGR_FREE (sed->mmgr, sed); + return QSE_NULL; + } + else QSE_MEMSET (QSE_XTN(sed), 0, xtnsize); } return sed; diff --git a/qse/lib/xli/Makefile.am b/qse/lib/xli/Makefile.am index dbdb190b..d08e5539 100644 --- a/qse/lib/xli/Makefile.am +++ b/qse/lib/xli/Makefile.am @@ -6,7 +6,7 @@ AM_CPPFLAGS = \ -I$(includedir) lib_LTLIBRARIES = libqsexli.la -libqsexli_la_SOURCES = xli.h xli.c read.c +libqsexli_la_SOURCES = xli.h xli.c read.c write.c std.c libqsexli_la_LDFLAGS = -L../cmn -L$(libdir) -version-info 1:0:0 -no-undefined libqsexli_la_LIBADD = -lqsecmn diff --git a/qse/lib/xli/Makefile.in b/qse/lib/xli/Makefile.in index 95b79ced..bb62937e 100644 --- a/qse/lib/xli/Makefile.in +++ b/qse/lib/xli/Makefile.in @@ -79,7 +79,7 @@ am__uninstall_files_from_dir = { \ am__installdirs = "$(DESTDIR)$(libdir)" LTLIBRARIES = $(lib_LTLIBRARIES) libqsexli_la_DEPENDENCIES = -am_libqsexli_la_OBJECTS = xli.lo read.lo +am_libqsexli_la_OBJECTS = xli.lo read.lo write.lo std.lo libqsexli_la_OBJECTS = $(am_libqsexli_la_OBJECTS) libqsexli_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ @@ -282,7 +282,7 @@ AM_CPPFLAGS = \ -I$(includedir) lib_LTLIBRARIES = libqsexli.la -libqsexli_la_SOURCES = xli.h xli.c read.c +libqsexli_la_SOURCES = xli.h xli.c read.c write.c std.c libqsexli_la_LDFLAGS = -L../cmn -L$(libdir) -version-info 1:0:0 -no-undefined libqsexli_la_LIBADD = -lqsecmn all: all-am @@ -359,8 +359,10 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xli.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/read.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/std.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/write.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xli.Plo@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/qse/lib/xli/read.c b/qse/lib/xli/read.c index 435a1f99..44dabf6e 100644 --- a/qse/lib/xli/read.c +++ b/qse/lib/xli/read.c @@ -21,35 +21,16 @@ #include "xli.h" #include -#if 0 -static int open_stream (qse_xli_t* xli) -{ - qse_ssize_t n; - - xli->errnum = QSE_XLI_ENOERR; - n = xli->src.fun (xli, QSE_XLI_IO_OPEN, &xli->src.arg, QSE_NULL, 0); - if (n <= -1) - { - if (xli->errnum == QSE_XLI_ENOERR) xli->errnum = QSE_XLI_EIOUSR; - return -1; - } - - xli->src.cur = xli->src.buf; - xli->src.end = xli->src.buf; - xli->src.cc = QSE_CHAR_EOF; - xli->src.loc.line = 1; - xli->src.loc.colm = 0; - - xli->src.eof = 0; - return 0; -} +static int get_char (qse_xli_t* xli); +static int get_token (qse_xli_t* xli); +static int read_list (qse_xli_t* xli, qse_xli_list_t* list); static int close_stream (qse_xli_t* xli) { qse_ssize_t n; xli->errnum = QSE_XLI_ENOERR; - n = xli->src.fun (xli, QSE_XLI_IO_CLOSE, &xli->src.arg, QSE_NULL, 0); + n = xli->sio.inf (xli, QSE_XLI_IO_CLOSE, xli->sio.inp, QSE_NULL, 0); if (n <= -1) { if (xli->errnum == QSE_XLI_ENOERR) xli->errnum = QSE_XLI_EIOUSR; @@ -59,36 +40,6 @@ static int close_stream (qse_xli_t* xli) return 0; } -static int read_stream (qse_xli_t* xli) -{ - qse_ssize_t n; - - xli->errnum = QSE_XLI_ENOERR; - n = xli->src.fun ( - xli, QSE_XLI_IO_READ, &xli->src.arg, - xli->src.buf, QSE_COUNTOF(xli->src.buf) - ); - if (n <= -1) - { - if (xli->errnum == QSE_XLI_ENOERR) xli->errnum = QSE_XLI_EIOUSR; - return -1; /* error */ - } - - if (n == 0) - { - /* don't change xli->src.cur and xli->src.end. - * they remain the same on eof */ - xli->src.eof = 1; - return 0; /* eof */ - } - - xli->src.cur = xli->src.buf; - xli->src.end = xli->src.buf + n; - return 1; /* read something */ -} - -#endif - enum tok_t { TOK_EOF, @@ -253,8 +204,7 @@ static int classify_ident (qse_xli_t* xli, const qse_cstr_t* name) right = mid - 1; } else if (n < 0) left = mid + 1; - - return kwp->type; + else return kwp->type; } return TOK_IDENT; @@ -307,6 +257,114 @@ static int get_symbols (qse_xli_t* xli, qse_cint_t c, qse_xli_tok_t* tok) return 0; } +static int end_include (qse_xli_t* xli) +{ + int x; + qse_xli_io_arg_t* cur; + + if (xli->sio.inp == &xli->sio.arg) return 0; /* no include */ + + /* if it is an included file, close it and + * retry to read a character from an outer file */ + + xli->errnum = QSE_XLI_ENOERR; + x = xli->sio.inf ( + xli, QSE_XLI_IO_CLOSE, + xli->sio.inp, QSE_NULL, 0); + + /* if closing has failed, still destroy the + * sio structure first as normal and return + * the failure below. this way, the caller + * does not call QSE_XLI_SIO_CLOSE on + * xli->sio.inp again. */ + + cur = xli->sio.inp; + xli->sio.inp = xli->sio.inp->next; + + QSE_ASSERT (cur->name != QSE_NULL); + QSE_MMGR_FREE (xli->mmgr, cur); + /* xli->parse.depth.incl--; */ + + if (x != 0) + { + /* the failure mentioned above is returned here */ + if (xli->errnum == QSE_XLI_ENOERR) xli->errnum = QSE_XLI_EIOUSR; + return -1; + } + + xli->sio.last = xli->sio.inp->last; + return 1; /* ended the included file successfully */ +} + +static int begin_include (qse_xli_t* xli) +{ + qse_ssize_t op; + qse_xli_io_arg_t* arg = QSE_NULL; + qse_htb_pair_t* pair = QSE_NULL; + + /* store the file name to xli->sio_names */ + pair = qse_htb_ensert ( + xli->sio_names, + QSE_STR_PTR(xli->tok.name), + QSE_STR_LEN(xli->tok.name) + 1, /* to include '\0' */ + QSE_NULL, 0 + ); + if (pair == QSE_NULL) + { +#if 0 + SETERR_LOC (xli, QSE_XLI_ENOMEM, &xli->ptok.loc); +#endif + goto oops; + } + + /*QSE_HTB_VPTR(pair) = QSE_HTB_KPTR(pair); + QSE_HTB_VLEN(pair) = QSE_HTB_KLEN(pair);*/ + + arg = (qse_xli_io_arg_t*) qse_xli_callocmem (xli, QSE_SIZEOF(*arg)); + if (arg == QSE_NULL) + { +#if 0 + ADJERR_LOC (xli, &xli->ptok.loc); +#endif + goto oops; + } + + arg->flags = QSE_XLI_IO_INCLUDED; + arg->name = QSE_HTB_KPTR(pair); + arg->line = 1; + arg->colm = 1; + + xli->errnum = QSE_XLI_ENOERR; + op = xli->sio.inf (xli, QSE_XLI_IO_OPEN, arg, QSE_NULL, 0); + if (op <= -1) + { + if (xli->errnum == QSE_XLI_ENOERR) xli->errnum = QSE_XLI_EIOUSR; + goto oops; + } + + arg->next = xli->sio.inp; + xli->sio.inp = arg; + /* xli->parse.depth.incl++; */ + + /* read in the first character in the included file. + * so the next call to get_token() sees the character read + * from this file. */ + if (get_char (xli) <= -1 || get_token (xli) <= -1) + { + end_include (xli); + /* i don't jump to oops since i've called + * end_include() where xli->sio.inp/arg is freed. */ + return -1; + } + + return 0; + +oops: + if (arg) QSE_MMGR_FREE (xli->mmgr, arg); + return -1; +} + + static int get_token_into (qse_xli_t* xli, qse_xli_tok_t* tok) { qse_cint_t c; @@ -330,7 +388,6 @@ retry: if (c == QSE_CHAR_EOF) { -#if 0 n = end_include (xli); if (n <= -1) return -1; if (n >= 1) @@ -340,7 +397,6 @@ retry: skip_semicolon_after_include = 1; goto retry; } -#endif ADD_TOKEN_STR (xli, tok, QSE_T(""), 5); SET_TOKEN_TYPE (xli, tok, TOK_EOF); @@ -399,10 +455,9 @@ retry: else if (c == QSE_T('\'') || c == QSE_T('\"')) { /* single-quoted string - no escaping */ - qse_cint_t sc = c; + qse_cint_t cc = c; - SET_TOKEN_TYPE (xli, tok, - ((sc == QSE_T('\''))? TOK_SQSTR: TOK_DQSTR)); + SET_TOKEN_TYPE (xli, tok, ((cc == QSE_T('\''))? TOK_SQSTR: TOK_DQSTR)); while (1) { @@ -417,7 +472,7 @@ retry: return -1; } - if (c == sc) + if (c == cc) { /* terminating quote */ GET_CHAR (xli); @@ -426,7 +481,6 @@ retry: ADD_TOKEN_CHAR (xli, tok, c); } - return 0; } else { @@ -479,38 +533,198 @@ static int get_token (qse_xli_t* xli) return get_token_into (xli, &xli->tok); } +static int read_pair (qse_xli_t* xli, qse_xli_list_t* list) +{ + qse_char_t* key = QSE_NULL; + qse_char_t* name = QSE_NULL; + int got_eq = 0; + qse_xli_pair_t* pair; + + key = qse_strdup (QSE_STR_PTR(xli->tok.name), xli->mmgr); + if (key == QSE_NULL) + { + xli->errnum = QSE_XLI_ENOMEM; + goto oops; + } + + if (get_token (xli) <= -1) goto oops; + if (MATCH (xli, TOK_SQSTR) || MATCH(xli, TOK_DQSTR)) + { + name = qse_strdup (QSE_STR_PTR(xli->tok.name), xli->mmgr); + if (name == QSE_NULL) + { + xli->errnum = QSE_XLI_ENOMEM; + goto oops; + } + + if (get_token (xli) <= -1) goto oops; + } + + if (MATCH (xli, TOK_EQ)) + { + if (get_token (xli) <= -1) goto oops; + got_eq = 1; + } + + if (MATCH (xli, TOK_LBRACE)) + { + if (get_token (xli) <= -1) goto oops; + +/* TODO: make it optional??? check duplicate entries... */ + + /* insert a pair with an empty list */ + pair = qse_xli_insertpairwithemptylist (xli, list, QSE_NULL, key, name); + if (pair == QSE_NULL) goto oops; + + if (read_list (xli, (qse_xli_list_t*)pair->val) <= -1) goto oops; + + if (!MATCH (xli, TOK_RBRACE)) + { + /* TODO: syntax error */ + goto oops; + } + + if (get_token (xli) <= -1) goto oops; + + /* semicolon is optional for a list */ + if (MATCH (xli, TOK_SEMICOLON)) + { + /* skip the semicolon */ + if (get_token (xli) <= -1) goto oops; + } + } + else if (MATCH (xli, TOK_SQSTR) || MATCH (xli, TOK_DQSTR)) + { + if (!got_eq) + { + /* TODO: syntax error */ + goto oops; + } + + pair = qse_xli_insertpairwithstr ( + xli, list, QSE_NULL, key, name, + QSE_STR_PTR(xli->tok.name), MATCH (xli, TOK_SQSTR)); + if (pair == QSE_NULL) goto oops; + + if (get_token (xli) <= -1) goto oops; + + /* semicolon is mandatory for a string */ + if (!MATCH (xli, TOK_SEMICOLON)) + { + /* TODO: syntax error */ + goto oops; + } + + if (get_token (xli) <= -1) goto oops; + } + else + { + /* TODO: syntax error */ + goto oops; + } + + QSE_MMGR_FREE (xli->mmgr, name); + QSE_MMGR_FREE (xli->mmgr, key); + return 0; + +oops: + if (name) QSE_MMGR_FREE (xli->mmgr, name); + if (key) QSE_MMGR_FREE (xli->mmgr, key); + return -1; +} + +static int read_list (qse_xli_t* xli, qse_xli_list_t* list) +{ + while (1) + { + if (MATCH (xli, TOK_XINCLUDE)) + { + if (get_token(xli) <= -1) goto oops; + + if (!MATCH(xli,TOK_SQSTR) && !MATCH(xli,TOK_DQSTR)) + { +#if 0 + SETERR_LOC (xli, QSE_XLI_EINCLSTR, &xli->ptok.loc); +#endif + return -1; + } + + if (begin_include (xli) <= -1) goto oops; + } + else if (MATCH (xli, TOK_IDENT)) + { + if (read_pair (xli, list) <= -1) goto oops; + } + else if (MATCH (xli, TOK_TEXT)) + { + if (get_token(xli) <= -1) goto oops; + } + else break; + } + + return 0; + +oops: + return -1; +} + int qse_xli_read (qse_xli_t* xli, qse_xli_io_impl_t io) { + qse_ssize_t n; + if (io == QSE_NULL) { xli->errnum = QSE_XLI_EINVAL; return -1; } + QSE_MEMSET (&xli->sio, 0, QSE_SIZEOF(xli->sio)); xli->sio.inf = io; -#if 0 - if (open_stream (xli) <= -1) return -1; + xli->sio.arg.line = 1; + xli->sio.arg.colm = 1; + xli->sio.inp = &xli->sio.arg; + qse_htb_clear (xli->sio_names); - close_stream (xli); -#endif - - do + xli->errnum = QSE_XLI_ENOERR; + n = xli->sio.inf (xli, QSE_XLI_IO_OPEN, xli->sio.inp, QSE_NULL, 0); + if (n <= -1) { - if (get_token (xli) <= -1) return -1; - if (MATCH (xli, TOK_XINCLUDE)) - { - } - else if (MATCH (xli, TOK_IDENT)) - { - } - else if (MATCH (xli, TOK_TEXT)) - { - } - else - { - } + if (xli->errnum == QSE_XLI_ENOERR) xli->errnum = QSE_XLI_EIOUSR; + return -1; } - while (1); + /* the input stream is open now */ + if (get_char (xli) <= -1 || get_token (xli) <= -1) goto oops; + if (read_list (xli, &xli->root) <= -1) goto oops; + + if (!MATCH (xli, TOK_EOF)) + { +/* TODO: set erro code */ +qse_printf (QSE_T("NOT ENDING WITH EOF... %s\n"), QSE_STR_PTR(xli->tok.name)); + goto oops; + } + + QSE_ASSERT (xli->sio.inp == &xli->sio.arg); + close_stream (xli); return 0; + +oops: + /* an error occurred and control has reached here + * probably, some included files might not have been + * closed. close them */ + while (xli->sio.inp != &xli->sio.arg) + { + qse_xli_io_arg_t* next; + + /* nothing much to do about a close error */ + close_stream (xli); + + next = xli->sio.inp->next; + QSE_ASSERT (xli->sio.inp->name != QSE_NULL); + QSE_MMGR_FREE (xli->mmgr, xli->sio.inp); + xli->sio.inp = next; + } + + close_stream (xli); + return -1; } diff --git a/qse/lib/xli/write.c b/qse/lib/xli/write.c new file mode 100644 index 00000000..5f8eceae --- /dev/null +++ b/qse/lib/xli/write.c @@ -0,0 +1,35 @@ +/* + * $Id$ + * + Copyright 2006-2012 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 . + */ + +#include "xli.h" + +int qse_xli_write (qse_xli_t* xli, qse_xli_io_impl_t io) +{ + if (io == QSE_NULL) + { + xli->errnum = QSE_XLI_EINVAL; + return -1; + } + + /* TODO: write data to io stream */ + xli->errnum = QSE_XLI_ENOIMPL; + return -1; +} + diff --git a/qse/lib/xli/xli.c b/qse/lib/xli/xli.c index c44c9f7d..ce72e4ba 100644 --- a/qse/lib/xli/xli.c +++ b/qse/lib/xli/xli.c @@ -25,12 +25,14 @@ qse_xli_t* qse_xli_open (qse_mmgr_t* mmgr, qse_size_t xtnsize) qse_xli_t* xli; xli = (qse_xli_t*) QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_xli_t) + xtnsize); - if (xli == QSE_NULL) return QSE_NULL; - - if (qse_xli_init (xli, mmgr) <= -1) + if (xli) { - QSE_MMGR_FREE (xli->mmgr, xli); - return QSE_NULL; + if (qse_xli_init (xli, mmgr) <= -1) + { + QSE_MMGR_FREE (xli->mmgr, xli); + return QSE_NULL; + } + else QSE_MEMSET (QSE_XTN(xli), 0, xtnsize); } return xli; @@ -53,17 +55,30 @@ int qse_xli_init (qse_xli_t* xli, qse_mmgr_t* mmgr) xli->mmgr = mmgr; xli->tok.name = qse_str_open (mmgr, 0, 128); - if (xli->tok.name == QSE_NULL) - { - xli->errnum = QSE_XLI_ENOMEM; - return -1; - } + if (xli->tok.name == QSE_NULL) goto oops; + + xli->sio_names = qse_htb_open ( + mmgr, QSE_SIZEOF(xli), 128, 70, QSE_SIZEOF(qse_char_t), 1 + ); + if (xli->sio_names == QSE_NULL) goto oops; + *(qse_xli_t**)QSE_XTN(xli->sio_names) = xli; + qse_htb_setmancbs (xli->sio_names, + qse_gethtbmancbs(QSE_HTB_MANCBS_INLINE_KEY_COPIER) + ); return 0; + +oops: + xli->errnum = QSE_XLI_ENOMEM; + if (xli->sio_names) qse_htb_close (xli->sio_names); + if (xli->tok.name) qse_str_close (xli->tok.name); + return -1; } void qse_xli_fini (qse_xli_t* xli) { + qse_xli_clear (xli); + qse_htb_close (xli->sio_names); qse_str_close (xli->tok.name); } @@ -154,6 +169,7 @@ static void insert_atom ( { /* insert it to the tail */ atom->prev = parent->tail; + if (parent->tail) parent->tail->next = atom; parent->tail = atom; if (parent->head == QSE_NULL) parent->head = atom; } @@ -175,7 +191,7 @@ static void insert_atom ( } } -qse_xli_atom_t* qse_xli_insertpair ( +qse_xli_pair_t* qse_xli_insertpair ( qse_xli_t* xli, qse_xli_list_t* parent, qse_xli_atom_t* peer, const qse_char_t* key, const qse_char_t* name, qse_xli_val_t* value) { @@ -196,17 +212,35 @@ qse_xli_atom_t* qse_xli_insertpair ( pair->name = pair->key + klen + 1; pair->val = value; /* this assumes it points to a dynamically allocated atom */ - insert_atom (xli, parent, peer, pair); + qse_strcpy (pair->key, key); + if (name) qse_strcpy (pair->name, name); - return (qse_xli_atom_t*)pair; + insert_atom (xli, parent, peer, (qse_xli_atom_t*)pair); + return pair; } -qse_xli_atom_t* qse_xli_insertpairwithstr ( +qse_xli_pair_t* qse_xli_insertpairwithemptylist ( qse_xli_t* xli, qse_xli_list_t* parent, qse_xli_atom_t* peer, - const qse_char_t* key, const qse_char_t* name, const qse_char_t* value) + const qse_char_t* key, const qse_char_t* name) +{ + qse_xli_list_t* val; + qse_xli_pair_t* tmp; + + val = qse_xli_callocmem (xli, QSE_SIZEOF(*val)); + if (val == QSE_NULL) return QSE_NULL; + + val->type = QSE_XLI_LIST; + tmp = qse_xli_insertpair (xli, parent, peer, key, name, (qse_xli_val_t*)val); + if (tmp == QSE_NULL) qse_xli_freemem (xli, val); + return tmp; +} + +qse_xli_pair_t* qse_xli_insertpairwithstr ( + qse_xli_t* xli, qse_xli_list_t* parent, qse_xli_atom_t* peer, + const qse_char_t* key, const qse_char_t* name, const qse_char_t* value, int verbatim) { qse_xli_str_t* val; - qse_xli_atom_t* tmp; + qse_xli_pair_t* tmp; qse_size_t vlen; vlen = qse_strlen (value); @@ -216,13 +250,14 @@ qse_xli_atom_t* qse_xli_insertpairwithstr ( val->type = QSE_XLI_STR; val->ptr = (const qse_char_t*)(val + 1); val->len = vlen; - tmp = qse_xli_insertpair (xli, parent, peer, key, name, val); + val->verbatim = verbatim; + tmp = qse_xli_insertpair (xli, parent, peer, key, name, (qse_xli_val_t*)val); if (tmp == QSE_NULL) qse_xli_freemem (xli, val); return tmp; } -qse_xli_atom_t* qse_xli_inserttext ( - qse_xli_t* xli, qse_xli_atom_t* parent, qse_xli_atom_t* peer, const qse_char_t* str) +qse_xli_text_t* qse_xli_inserttext ( + qse_xli_t* xli, qse_xli_list_t* parent, qse_xli_atom_t* peer, const qse_char_t* str) { qse_xli_text_t* text; qse_size_t slen; @@ -236,21 +271,48 @@ qse_xli_atom_t* qse_xli_inserttext ( text->ptr = (const qse_char_t*)(text + 1); text->len = slen; - insert_atom (xli, parent, peer, text); + insert_atom (xli, parent, peer, (qse_xli_atom_t*)text); - return (qse_xli_atom_t*)text; + return text; } /* ------------------------------------------------------ */ -int qse_xli_write (qse_xli_t* xli, qse_xli_io_impl_t io) +static void free_list (qse_xli_t* xli, qse_xli_list_t* list); + +static void free_atom (qse_xli_t* xli, qse_xli_atom_t* atom) { - /* TODO: write data to io stream */ - xli->errnum = QSE_XLI_ENOIMPL; - return -1; + if (atom->type == QSE_XLI_PAIR) + { + qse_xli_pair_t* pair = (qse_xli_pair_t*)atom; + + if (pair->val->type == QSE_XLI_LIST) + free_list (xli, (qse_xli_list_t*)pair->val); + + QSE_MMGR_FREE (xli->mmgr, pair->val); + } + + QSE_MMGR_FREE (xli->mmgr, atom); +} + +static void free_list (qse_xli_t* xli, qse_xli_list_t* list) +{ + qse_xli_atom_t* p, * n; + + p = list->head; + while (p) + { + n = p->next; + free_atom (xli, p); + p = n; + } + + list->head = QSE_NULL; + list->tail = QSE_NULL; } void qse_xli_clear (qse_xli_t* xli) { /* TODO: free data under xli->root */ + free_list (xli, &xli->root); } diff --git a/qse/lib/xli/xli.h b/qse/lib/xli/xli.h index 52489e6a..cad917c0 100644 --- a/qse/lib/xli/xli.h +++ b/qse/lib/xli/xli.h @@ -23,6 +23,7 @@ #include #include +#include #include "../cmn/mem.h" typedef struct qse_xli_tok_t qse_xli_tok_t; @@ -52,11 +53,11 @@ struct qse_xli_t struct { qse_xli_io_impl_t inf; /* input handler */ + qse_xli_io_lxc_t last; qse_xli_io_arg_t arg; /* for top level */ qse_xli_io_arg_t* inp; /* current */ - - qse_xli_io_lxc_t last; } sio; + qse_htb_t* sio_names; };