diff --git a/qse/README b/qse/README index 13e1c479..258a0fae 100644 --- a/qse/README +++ b/qse/README @@ -2,8 +2,8 @@ QSE is a code library that implements various Unix utilities in an embeddable form and provides a set of APIs to embed them into an application. The APIs have been designed to be flexible enough to access various aspects of a hosting application and an embedded object from each other. By embedding -a Unix utility into an application, a developer is relieved of the need to -invoke an external command and is given tighter control over it. +a Unix utility into an application, a developer is relieved of problems caused +by interacting with external programs and is given tighter control over it. Currently the library implements the following utilities: - SED Stream Editor diff --git a/qse/cmd/Makefile.am b/qse/cmd/Makefile.am index 52854116..d0d2bdf4 100644 --- a/qse/cmd/Makefile.am +++ b/qse/cmd/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = sed awk lsp utl +SUBDIRS = sed awk cut lsp utl DIST_SUBDIRS = $(SUBDIRS) diff --git a/qse/cmd/Makefile.in b/qse/cmd/Makefile.in index e72868d7..871212d1 100644 --- a/qse/cmd/Makefile.in +++ b/qse/cmd/Makefile.in @@ -194,7 +194,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -SUBDIRS = sed awk lsp utl +SUBDIRS = sed awk cut lsp utl DIST_SUBDIRS = $(SUBDIRS) all: all-recursive diff --git a/qse/cmd/sed/sed.c b/qse/cmd/sed/sed.c index 3053aeca..cf728fb8 100644 --- a/qse/cmd/sed/sed.c +++ b/qse/cmd/sed/sed.c @@ -34,7 +34,8 @@ static const qse_char_t* g_infile = QSE_NULL; static int g_option = 0; static qse_ssize_t in ( - qse_sed_t* sed, qse_sed_io_cmd_t cmd, qse_sed_io_arg_t* arg, qse_char_t* buf, qse_size_t size) + qse_sed_t* sed, qse_sed_io_cmd_t cmd, + qse_sed_io_arg_t* arg, qse_char_t* buf, qse_size_t size) { switch (cmd) { @@ -78,7 +79,8 @@ static qse_ssize_t in ( } static qse_ssize_t out ( - qse_sed_t* sed, qse_sed_io_cmd_t cmd, qse_sed_io_arg_t* arg, qse_char_t* data, qse_size_t len) + qse_sed_t* sed, qse_sed_io_cmd_t cmd, + qse_sed_io_arg_t* arg, qse_char_t* data, qse_size_t len) { switch (cmd) { diff --git a/qse/configure b/qse/configure index ad7b0d4c..ee31c14e 100755 --- a/qse/configure +++ b/qse/configure @@ -25648,7 +25648,7 @@ QSE_SIZEOF_DOUBLE=$ac_cv_sizeof_double QSE_SIZEOF_LONG_DOUBLE=$ac_cv_sizeof_long_double -ac_config_files="$ac_config_files Makefile include/Makefile include/qse/Makefile include/qse/cmn/Makefile include/qse/sed/Makefile include/qse/awk/Makefile include/qse/lsp/Makefile include/qse/utl/Makefile lib/Makefile lib/cmn/Makefile lib/sed/Makefile lib/awk/Makefile lib/lsp/Makefile lib/utl/Makefile cmd/Makefile cmd/sed/Makefile cmd/awk/Makefile cmd/lsp/Makefile cmd/utl/Makefile samples/Makefile samples/cmn/Makefile samples/sed/Makefile samples/awk/Makefile samples/utl/Makefile regress/Makefile regress/awk/Makefile doc/Makefile doc/page/Makefile doc/page.ko/Makefile doc/Doxyfile" +ac_config_files="$ac_config_files Makefile include/Makefile include/qse/Makefile include/qse/cmn/Makefile include/qse/sed/Makefile include/qse/awk/Makefile include/qse/cut/Makefile include/qse/lsp/Makefile include/qse/utl/Makefile lib/Makefile lib/cmn/Makefile lib/sed/Makefile lib/awk/Makefile lib/cut/Makefile lib/lsp/Makefile lib/utl/Makefile cmd/Makefile cmd/sed/Makefile cmd/awk/Makefile cmd/cut/Makefile cmd/lsp/Makefile cmd/utl/Makefile samples/Makefile samples/cmn/Makefile samples/sed/Makefile samples/awk/Makefile samples/utl/Makefile regress/Makefile regress/awk/Makefile doc/Makefile doc/page/Makefile doc/page.ko/Makefile doc/Doxyfile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -26672,17 +26672,20 @@ do "include/qse/cmn/Makefile") CONFIG_FILES="$CONFIG_FILES include/qse/cmn/Makefile" ;; "include/qse/sed/Makefile") CONFIG_FILES="$CONFIG_FILES include/qse/sed/Makefile" ;; "include/qse/awk/Makefile") CONFIG_FILES="$CONFIG_FILES include/qse/awk/Makefile" ;; + "include/qse/cut/Makefile") CONFIG_FILES="$CONFIG_FILES include/qse/cut/Makefile" ;; "include/qse/lsp/Makefile") CONFIG_FILES="$CONFIG_FILES include/qse/lsp/Makefile" ;; "include/qse/utl/Makefile") CONFIG_FILES="$CONFIG_FILES include/qse/utl/Makefile" ;; "lib/Makefile") CONFIG_FILES="$CONFIG_FILES lib/Makefile" ;; "lib/cmn/Makefile") CONFIG_FILES="$CONFIG_FILES lib/cmn/Makefile" ;; "lib/sed/Makefile") CONFIG_FILES="$CONFIG_FILES lib/sed/Makefile" ;; "lib/awk/Makefile") CONFIG_FILES="$CONFIG_FILES lib/awk/Makefile" ;; + "lib/cut/Makefile") CONFIG_FILES="$CONFIG_FILES lib/cut/Makefile" ;; "lib/lsp/Makefile") CONFIG_FILES="$CONFIG_FILES lib/lsp/Makefile" ;; "lib/utl/Makefile") CONFIG_FILES="$CONFIG_FILES lib/utl/Makefile" ;; "cmd/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/Makefile" ;; "cmd/sed/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/sed/Makefile" ;; "cmd/awk/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/awk/Makefile" ;; + "cmd/cut/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/cut/Makefile" ;; "cmd/lsp/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/lsp/Makefile" ;; "cmd/utl/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/utl/Makefile" ;; "samples/Makefile") CONFIG_FILES="$CONFIG_FILES samples/Makefile" ;; diff --git a/qse/configure.ac b/qse/configure.ac index 09bee87c..513f0156 100644 --- a/qse/configure.ac +++ b/qse/configure.ac @@ -249,17 +249,20 @@ AC_CONFIG_FILES([ include/qse/cmn/Makefile include/qse/sed/Makefile include/qse/awk/Makefile + include/qse/cut/Makefile include/qse/lsp/Makefile include/qse/utl/Makefile lib/Makefile lib/cmn/Makefile lib/sed/Makefile lib/awk/Makefile + lib/cut/Makefile lib/lsp/Makefile lib/utl/Makefile cmd/Makefile cmd/sed/Makefile cmd/awk/Makefile + cmd/cut/Makefile cmd/lsp/Makefile cmd/utl/Makefile samples/Makefile diff --git a/qse/doc/page/main.doc b/qse/doc/page/main.doc index 0b38acc7..cce0799d 100644 --- a/qse/doc/page/main.doc +++ b/qse/doc/page/main.doc @@ -6,8 +6,8 @@ embeddable form and provides a set of APIs to embed them into an application. The APIs have been designed to be flexible enough to access various aspects of a hosting application and an embedded object from each other. By embedding -a Unix utility into an application, a developer is relieved of the need to -invoke an external command and is given tighter control over it. +a Unix utility into an application, a developer is relieved of problems caused +by interacting with external programs and is given tighter control over it. Currently the library implements the following utilities: - @subpage sed "SED Stream Editor" diff --git a/qse/include/qse/Makefile.am b/qse/include/qse/Makefile.am index 66631e1d..b4846e34 100644 --- a/qse/include/qse/Makefile.am +++ b/qse/include/qse/Makefile.am @@ -1,5 +1,5 @@ # EXTRA_DIST = -SUBDIRS = cmn sed awk lsp utl +SUBDIRS = cmn sed awk cut lsp utl pkgincludedir = $(includedir)/qse diff --git a/qse/include/qse/Makefile.in b/qse/include/qse/Makefile.in index 4c2a11bf..474c6fef 100644 --- a/qse/include/qse/Makefile.in +++ b/qse/include/qse/Makefile.in @@ -211,7 +211,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ # EXTRA_DIST = -SUBDIRS = cmn sed awk lsp utl +SUBDIRS = cmn sed awk cut lsp utl pkginclude_HEADERS = config.h conf_msw.h conf_vms.h types.h macros.h \ pack1.h unpack.h $(am__append_1) all: config.h diff --git a/qse/include/qse/cut/Makefile.am b/qse/include/qse/cut/Makefile.am new file mode 100644 index 00000000..33c0d5a9 --- /dev/null +++ b/qse/include/qse/cut/Makefile.am @@ -0,0 +1,8 @@ +pkgincludedir= $(includedir)/qse/cut + +pkginclude_HEADERS = cut.h + +#if ENABLE_CXX +#pkginclude_HEADERS += Cut.hpp StdCut.hpp +#endif + diff --git a/qse/include/qse/cut/Makefile.in b/qse/include/qse/cut/Makefile.in new file mode 100644 index 00000000..c35b9041 --- /dev/null +++ b/qse/include/qse/cut/Makefile.in @@ -0,0 +1,435 @@ +# Makefile.in generated by automake 1.10.2 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008 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@ +pkglibdir = $(libdir)/@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@ +subdir = include/qse/cut +DIST_COMMON = $(pkginclude_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/ac/m4/libtool.m4 \ + $(top_srcdir)/ac/m4/ltoptions.m4 \ + $(top_srcdir)/ac/m4/ltsugar.m4 \ + $(top_srcdir)/ac/m4/ltversion.m4 \ + $(top_srcdir)/ac/m4/lt~obsolete.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 = +SOURCES = +DIST_SOURCES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(pkgincludedir)" +pkgincludeHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(pkginclude_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +pkgincludedir = $(includedir)/qse/cut +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +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@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +HAVE_CXX = @HAVE_CXX@ +HAVE_OBJC = @HAVE_OBJC@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJC = @OBJC@ +OBJCDEPMODE = @OBJCDEPMODE@ +OBJCFLAGS = @OBJCFLAGS@ +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_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +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_SHORT = @QSE_SIZEOF_SHORT@ +QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@ +QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@ +RANLIB = @RANLIB@ +RM = @RM@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +ac_ct_OBJC = @ac_ct_OBJC@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +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@ +lt_ECHO = @lt_ECHO@ +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@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +pkginclude_HEADERS = cut.h +all: all-am + +.SUFFIXES: +$(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 include/qse/cut/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --foreign include/qse/cut/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 + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-pkgincludeHEADERS: $(pkginclude_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(pkgincludedir)" || $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)" + @list='$(pkginclude_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(pkgincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(pkgincludedir)/$$f'"; \ + $(pkgincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(pkgincludedir)/$$f"; \ + done + +uninstall-pkgincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(pkginclude_HEADERS)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(pkgincludedir)/$$f'"; \ + rm -f "$(DESTDIR)$(pkgincludedir)/$$f"; \ + done + +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) + tags=; \ + 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; }; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + 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)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && 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 $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$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 $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(pkgincludedir)"; 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: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_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-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-pkgincludeHEADERS + +install-dvi: install-dvi-am + +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 + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-pkgincludeHEADERS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool ctags distclean distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am 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-pkgincludeHEADERS install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-pkgincludeHEADERS + + +#if ENABLE_CXX +#pkginclude_HEADERS += Cut.hpp StdCut.hpp +#endif +# 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/include/qse/cut/cut.h b/qse/include/qse/cut/cut.h new file mode 100644 index 00000000..109e0470 --- /dev/null +++ b/qse/include/qse/cut/cut.h @@ -0,0 +1,330 @@ +/* + * $Id: cut.h 287 2009-09-15 10:01:02Z baconevi $ + * + 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 . + */ + +#ifndef _QSE_CUT_CUT_H_ +#define _QSE_CUT_CUT_H_ + +#include +#include +#include + +/** @file + * cut utility + */ + +/** @struct qse_cut_t + */ +typedef struct qse_cut_t qse_cut_t; + +/** + * the qse_cut_errnum_t type defines error numbers. + */ +enum qse_cut_errnum_t +{ + QSE_CUT_ENOERR, /**< no error */ + QSE_CUT_ENOMEM, /**< insufficient memory */ + QSE_CUT_ESELNV, /**< selector not valid */ + QSE_CUT_EREXIC, /**< regular expression '${0}' incomplete */ + QSE_CUT_EREXBL, /**< failed to compile regular expression '${0}' */ + QSE_CUT_EREXMA, /**< failed to match regular expression */ + QSE_CUT_EA1PHB, /**< address 1 prohibited for '${0}' */ + QSE_CUT_EA2PHB, /**< address 2 prohibited */ + QSE_CUT_EA2MOI, /**< address 2 missing or invalid */ + QSE_CUT_ENEWLN, /**< newline expected */ + QSE_CUT_EBSEXP, /**< backslash expected */ + QSE_CUT_EBSDEL, /**< backslash used as delimiter */ + QSE_CUT_EGBABS, /**< garbage after backslash */ + QSE_CUT_ESCEXP, /**< semicolon expected */ + QSE_CUT_ELABEM, /**< empty label name */ + QSE_CUT_ELABDU, /**< duplicate label name '${0}' */ + QSE_CUT_ELABNF, /**< label '${0}' not found */ + QSE_CUT_EFILEM, /**< empty file name */ + QSE_CUT_EFILIL, /**< illegal file name */ + QSE_CUT_ETSNSL, /**< strings in translation set not the same length*/ + QSE_CUT_EGRNBA, /**< group brackets not balanced */ + QSE_CUT_EGRNTD, /**< group nesting too deep */ + QSE_CUT_EOCSDU, /**< multiple occurrence specifiers */ + QSE_CUT_EOCSZE, /**< occurrence specifier zero */ + QSE_CUT_EOCSTL, /**< occurrence specifier too large */ + QSE_CUT_EIOFIL, /**< io error with file '${0}'*/ + QSE_CUT_EIOUSR /**< error returned by user io handler */ +}; +typedef enum qse_cut_errnum_t qse_cut_errnum_t; + +/** + * The qse_cut_errstr_t type defines a error string getter. It should return + * an error formatting string for an error number requested. A new string + * should contain the same number of positional parameters (${X}) as in the + * default error formatting string. You can set a new getter into a stream + * editor with the qse_cut_seterrstr() function to customize an error string. + */ +typedef const qse_char_t* (*qse_cut_errstr_t) ( + qse_cut_t* sed, /**< stream editor */ + qse_cut_errnum_t num /**< an error number */ +); + +/** + * The qse_cut_option_t type defines various option codes for a stream editor. + * Options can be OR'ed with each other and be passed to a stream editor with + * the qse_cut_setoption() function. + */ +enum qse_cut_option_t +{ + QSE_CUT_STRIPLS = (1 << 0), /**< strip leading spaces from text */ + QSE_CUT_KEEPTBS = (1 << 1), /**< keep an trailing backslash */ + QSE_CUT_ENSURENL = (1 << 2), /**< ensure NL at the text end */ + QSE_CUT_QUIET = (1 << 3), /**< do not print pattern space */ + QSE_CUT_STRICT = (1 << 4), /**< do strict address check */ + QSE_CUT_STARTSTEP = (1 << 5), /**< allow start~step */ + QSE_CUT_REXBOUND = (1 << 6), /**< allow {n,m} in regular expression */ + QSE_CUT_SAMELINE = (1 << 7), /**< allow text on the same line as c, a, i */ +}; +typedef enum qse_cut_option_t qse_cut_option_t; + + +/** + * The qse_cut_depth_t type defines IDs for qse_cut_getmaxdepth() and + * qse_cut_setmaxdepth(). + */ +enum qse_cut_depth_t +{ + QSE_CUT_DEPTH_REX_BUILD = (1 << 0), + QSE_CUT_DEPTH_REX_MATCH = (1 << 1) +}; +typedef enum qse_cut_depth_t qse_cut_depth_t; + +/** + * The qse_cut_io_cmd_t type defines IO command codes. The code indicates + * the action to take in an IO handler. + */ +enum qse_cut_io_cmd_t +{ + QSE_CUT_IO_OPEN = 0, + QSE_CUT_IO_CLOSE = 1, + QSE_CUT_IO_READ = 2, + QSE_CUT_IO_WRITE = 3 +}; +typedef enum qse_cut_io_cmd_t qse_cut_io_cmd_t; + +/** + * The qse_cut_io_arg_t type defines a data structure required by an IO handler. + */ +struct qse_cut_io_arg_t +{ + void* handle; /**< IO handle */ + const qse_char_t* path; /**< file path. QSE_NULL for a console */ +}; +typedef struct qse_cut_io_arg_t qse_cut_io_arg_t; + +/** + * The qse_cut_io_fun_t type defines an IO handler. An IO handler is called by + * qse_cut_exec(). + */ +typedef qse_ssize_t (*qse_cut_io_fun_t) ( + qse_cut_t* sed, + qse_cut_io_cmd_t cmd, + qse_cut_io_arg_t* arg, + qse_char_t* data, + qse_size_t count +); + +#ifdef __cplusplus +extern "C" { +#endif + +QSE_DEFINE_COMMON_FUNCTIONS (cut) + +/** + * The qse_cut_open() function creates a stream editor object. A memory + * manager provided is used to allocate and destory the object and any dynamic + * data through out its lifetime. An extension area is allocated if an + * extension size greater than 0 is specified. You can access it with the + * qse_cut_getxtn() function and use it to store arbitrary data associated + * with the object. See #QSE_DEFINE_COMMON_FUNCTIONS() for qse_cut_getxtn(). + * When done, you should destroy the object with the qse_cut_close() function + * to avoid any resource leaks including memory. + * @return A pointer to a stream editor on success, QSE_NULL on failure + */ +qse_cut_t* qse_cut_open ( + qse_mmgr_t* mmgr, /**< a memory manager */ + qse_size_t xtn /**< the size of extension in bytes */ +); + +/** + * The qse_cut_close() function destroys a stream editor. + */ +void qse_cut_close ( + qse_cut_t* cut /**< stream editor */ +); + +/** + * The qse_cut_getoption() function retrieves the current options set in + * a stream editor. + * @return 0 or a number OR'ed of #qse_cut_option_t values + */ +int qse_cut_getoption ( + qse_cut_t* cut /**< stream editor */ +); + +/** + * The qse_cut_setoption() function sets the option code. + */ +void qse_cut_setoption ( + qse_cut_t* cut, /**< stream editor */ + int opt /**< 0 or a number OR'ed of #qse_cut_option_t values */ +); + +/** + * The qse_cut_getmaxdepth() gets the maximum processing depth. + */ +qse_size_t qse_cut_getmaxdepth ( + qse_cut_t* cut, /**< stream editor */ + qse_cut_depth_t id /**< one of qse_cut_depth_t values */ +); + +/** + * The qse_cut_setmaxdepth() sets the maximum processing depth. + */ +void qse_cut_setmaxdepth ( + qse_cut_t* cut, /**< stream editor */ + int ids, /**< 0 or a number OR'ed of #qse_cut_depth_t values */ + qse_size_t depth /**< maximum depth level */ +); + +/** + * The qse_cut_geterrstr() gets an error string getter. + */ +qse_cut_errstr_t qse_cut_geterrstr ( + qse_cut_t* cut /**< stream editor */ +); + +/** + * The qse_cut_seterrstr() sets an error string getter that is called to + * compose an error message when its retrieval is requested. + * + * Here is an example of changing the formatting string for the #QSE_CUT_ECMDNR + * error. + * @code + * qse_cut_errstr_t orgerrstr; + * + * const qse_char_t* myerrstr (qse_cut_t* cut, qse_cut_errnum_t num) + * { + * if (num == QSE_CUT_ECMDNR) return QSE_T("unrecognized command ${0}"); + * return orgerrstr (cut, num); + * } + * int main () + * { + * qse_cut_t* cut; + * ... + * orgerrstr = qse_cut_geterrstr (cut); + * qse_cut_seterrstr (cut, myerrstr); + * ... + * } + * @endcode + */ +void qse_cut_seterrstr ( + qse_cut_t* cut, /**< stream editor */ + qse_cut_errstr_t errstr /**< an error string getter */ +); + +/** + * The qse_cut_geterrnum() function gets the number of the last error. + * @return the number of the last error + */ +qse_cut_errnum_t qse_cut_geterrnum ( + qse_cut_t* cut /**< stream editor */ +); + +/** + * The qse_cut_geterrmsg() function gets a string describing the last error. + * @return a pointer to an error message + */ +const qse_char_t* qse_cut_geterrmsg ( + qse_cut_t* cut /**< stream editor */ +); + +/** + * The qse_cut_geterror() function gets an error number, an error location, + * and an error message. The information is set to the memory area pointed + * to by each parameter. + */ +void qse_cut_geterror ( + qse_cut_t* cut, /**< stream editor */ + qse_cut_errnum_t* errnum, /**< error number */ + const qse_char_t** errmsg /**< error message */ +); + +/** + * The qse_cut_seterrnum() function sets error information omitting error + * location. + */ +void qse_cut_seterrnum ( + qse_cut_t* cut, /**< stream editor */ + qse_cut_errnum_t errnum, /**< error number */ + const qse_cstr_t* errarg /**< argument for formatting error message */ +); + +/** + * The qse_cut_seterrmsg() function sets error information with a customized + * message for a given error number. + */ +void qse_cut_seterrmsg ( + qse_cut_t* cut, /**< stream editor */ + qse_cut_errnum_t errnum, /**< error number */ + const qse_char_t* errmsg /**< error message */ +); + +/** + * The qse_cut_seterror() function sets an error number, an error location, and + * an error message. An error string is composed of a formatting string + * and an array of formatting parameters. + */ +void qse_cut_seterror ( + qse_cut_t* cut, /**< stream editor */ + qse_cut_errnum_t errnum, /**< error number */ + const qse_cstr_t* errarg /**< array of arguments for formatting + * an error message */ +); + +/** + * The qse_cut_comp() function compiles a selector into an internal form. + * @return 0 on success, -1 on error + */ +int qse_cut_comp ( + qse_cut_t* cut, /**< stream editor */ + const qse_char_t* ptr, /**< pointer to a string containing commands */ + qse_size_t len /**< the number of characters in the string */ +); + +/** + * The qse_cut_exec() function executes the compiled commands. + * @return 0 on success, -1 on error + */ +int qse_cut_exec ( + qse_cut_t* cut, /**< stream editor */ + qse_cut_io_fun_t inf, /**< stream reader */ + qse_cut_io_fun_t outf /**< stream writer */ +); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/qse/lib/Makefile.am b/qse/lib/Makefile.am index 4f0287fa..04984175 100644 --- a/qse/lib/Makefile.am +++ b/qse/lib/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = cmn sed awk lsp utl +SUBDIRS = cmn sed awk cut lsp utl DIST_SUBDIRS = $(SUBDIRS) diff --git a/qse/lib/Makefile.in b/qse/lib/Makefile.in index 2645e145..f6a4f1e5 100644 --- a/qse/lib/Makefile.in +++ b/qse/lib/Makefile.in @@ -194,7 +194,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -SUBDIRS = cmn sed awk lsp utl +SUBDIRS = cmn sed awk cut lsp utl DIST_SUBDIRS = $(SUBDIRS) all: all-recursive diff --git a/qse/lib/cut/Makefile.am b/qse/lib/cut/Makefile.am new file mode 100644 index 00000000..e29821a2 --- /dev/null +++ b/qse/lib/cut/Makefile.am @@ -0,0 +1,15 @@ + +AM_CPPFLAGS = -I$(top_srcdir)/include + +lib_LTLIBRARIES = libqsecut.la +libqsecut_la_SOURCES = cut.c err.c cut.h +libqsecut_la_LDFLAGS = -version-info 1:0:0 -no-undefined -L../cmn +libqsecut_la_LIBADD = -lqsecmn + +#if ENABLE_CXX +#lib_LTLIBRARIES += libqsecutxx.la +#libqsecutxx_la_SOURCES = Sed.cpp StdSed.cpp +#libqsecutxx_la_LDFLAGS = -L. -L../cmn -version-info 1:0:0 -no-undefined +#libqsecutxx_la_LIBADD = -lqsecut -lqsecmn +#endif + diff --git a/qse/lib/cut/Makefile.in b/qse/lib/cut/Makefile.in new file mode 100644 index 00000000..ca0b9521 --- /dev/null +++ b/qse/lib/cut/Makefile.in @@ -0,0 +1,508 @@ +# Makefile.in generated by automake 1.10.2 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008 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@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@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@ +subdir = lib/cut +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/ac/m4/libtool.m4 \ + $(top_srcdir)/ac/m4/ltoptions.m4 \ + $(top_srcdir)/ac/m4/ltsugar.m4 \ + $(top_srcdir)/ac/m4/ltversion.m4 \ + $(top_srcdir)/ac/m4/lt~obsolete.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 = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(libdir)" +libLTLIBRARIES_INSTALL = $(INSTALL) +LTLIBRARIES = $(lib_LTLIBRARIES) +libqsecut_la_DEPENDENCIES = +am_libqsecut_la_OBJECTS = cut.lo err.lo +libqsecut_la_OBJECTS = $(am_libqsecut_la_OBJECTS) +libqsecut_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libqsecut_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include/qse +depcomp = $(SHELL) $(top_srcdir)/ac/au/depcomp +am__depfiles_maybe = depfiles +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 = $(libqsecut_la_SOURCES) +DIST_SOURCES = $(libqsecut_la_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +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@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +HAVE_CXX = @HAVE_CXX@ +HAVE_OBJC = @HAVE_OBJC@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJC = @OBJC@ +OBJCDEPMODE = @OBJCDEPMODE@ +OBJCFLAGS = @OBJCFLAGS@ +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_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +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_SHORT = @QSE_SIZEOF_SHORT@ +QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@ +QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@ +RANLIB = @RANLIB@ +RM = @RM@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +ac_ct_OBJC = @ac_ct_OBJC@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +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@ +lt_ECHO = @lt_ECHO@ +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@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +AM_CPPFLAGS = -I$(top_srcdir)/include +lib_LTLIBRARIES = libqsecut.la +libqsecut_la_SOURCES = cut.c err.c cut.h +libqsecut_la_LDFLAGS = -version-info 1:0:0 -no-undefined -L../cmn +libqsecut_la_LIBADD = -lqsecmn +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 lib/cut/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --foreign lib/cut/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 +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f=$(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + p=$(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libqsecut.la: $(libqsecut_la_OBJECTS) $(libqsecut_la_DEPENDENCIES) + $(libqsecut_la_LINK) -rpath $(libdir) $(libqsecut_la_OBJECTS) $(libqsecut_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cut.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/err.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(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@ mv -f $(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@ mv -f $(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) + tags=; \ + 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; }; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + 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)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && 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 $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$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 $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(libdir)"; 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: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_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-generic clean-libLTLIBRARIES 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 + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-exec-am: install-libLTLIBRARIES + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: 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-libLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libLTLIBRARIES 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-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-libLTLIBRARIES 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-libLTLIBRARIES + + +#if ENABLE_CXX +#lib_LTLIBRARIES += libqsecutxx.la +#libqsecutxx_la_SOURCES = Sed.cpp StdSed.cpp +#libqsecutxx_la_LDFLAGS = -L. -L../cmn -version-info 1:0:0 -no-undefined +#libqsecutxx_la_LIBADD = -lqsecut -lqsecmn +#endif +# 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/lib/cut/cut.c b/qse/lib/cut/cut.c new file mode 100644 index 00000000..023c3e0a --- /dev/null +++ b/qse/lib/cut/cut.c @@ -0,0 +1,287 @@ +/* + * $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 . + */ + +#include "cut.h" +#include "../cmn/mem.h" +#include +#include + +#define MAX QSE_TYPE_MAX(qse_size_t) + +QSE_IMPLEMENT_COMMON_FUNCTIONS (cut) + +static qse_cut_t* qse_cut_init (qse_cut_t* cut, qse_mmgr_t* mmgr); +static void qse_cut_fini (qse_cut_t* cut); + +#define SETERR0(cut,num) \ +do { qse_cut_seterror (cut, num, QSE_NULL); } while (0) + +#define SETERR1(cut,num,argp,argl) \ +do { \ + qse_cstr_t __ea__; \ + __ea__.ptr = argp; __ea__.len = argl; \ + qse_cut_seterror (cut, num, &__ea__); \ +} while (0) + +static int add_selector_block (qse_cut_t* cut) +{ + qse_cut_sel_blk_t* b; + + b = (qse_cut_sel_blk_t*) QSE_MMGR_ALLOC (cut->mmgr, QSE_SIZEOF(*b)); + if (b == QSE_NULL) + { + SETERR0 (cut, QSE_CUT_ENOMEM); + return -1; + } + + QSE_MEMSET (b, 0, QSE_SIZEOF(*b)); + b->next = QSE_NULL; + b->len = 0; + + cut->sel.lb->next = b; + cut->sel.lb = b; + cut->sel.count = 0; + + return 0; +} + +static void free_all_selector_blocks (qse_cut_t* cut) +{ + qse_cut_sel_blk_t* b; + + for (b = cut->sel.fb.next; b != QSE_NULL; ) + { + qse_cut_sel_blk_t* nxt = b->next; + QSE_MMGR_FREE (cut->mmgr, b); + b = nxt; + } + + cut->sel.lb = &cut->sel.fb; + cut->sel.lb->len = 0; + cut->sel.lb->next = QSE_NULL; + cut->sel.count = 0; +} + +qse_cut_t* qse_cut_open (qse_mmgr_t* mmgr, qse_size_t xtn) +{ + qse_cut_t* cut; + + if (mmgr == QSE_NULL) + { + mmgr = QSE_MMGR_GETDFL(); + + QSE_ASSERTX (mmgr != QSE_NULL, + "Set the memory manager with QSE_MMGR_SETDFL()"); + + if (mmgr == QSE_NULL) return QSE_NULL; + } + + cut = (qse_cut_t*) QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_cut_t) + xtn); + if (cut == QSE_NULL) return QSE_NULL; + + if (qse_cut_init (cut, mmgr) == QSE_NULL) + { + QSE_MMGR_FREE (cut->mmgr, cut); + return QSE_NULL; + } + + return cut; +} + +void qse_cut_close (qse_cut_t* cut) +{ + qse_cut_fini (cut); + QSE_MMGR_FREE (cut->mmgr, cut); +} + +static qse_cut_t* qse_cut_init (qse_cut_t* cut, qse_mmgr_t* mmgr) +{ + QSE_MEMSET (cut, 0, QSE_SIZEOF(*cut)); + + cut->mmgr = mmgr; + cut->errstr = qse_cut_dflerrstr; + + /* on init, the last points to the first */ + cut->sel.lb = &cut->sel.fb; + /* the block has no data yet */ + cut->sel.fb.len = 0; + + return cut; +} + + +static void qse_cut_fini (qse_cut_t* cut) +{ + free_all_selector_blocks (cut); +} + +void qse_cut_setoption (qse_cut_t* cut, int option) +{ + cut->option = option; +} + +int qse_cut_getoption (qse_cut_t* cut) +{ + return cut->option; +} + +qse_size_t qse_cut_getmaxdepth (qse_cut_t* cut, qse_cut_depth_t id) +{ + return (id & QSE_CUT_DEPTH_REX_BUILD)? cut->depth.rex.build: + (id & QSE_CUT_DEPTH_REX_MATCH)? cut->depth.rex.match: 0; +} + +void qse_cut_setmaxdepth (qse_cut_t* cut, int ids, qse_size_t depth) +{ + if (ids & QSE_CUT_DEPTH_REX_BUILD) cut->depth.rex.build = depth; + if (ids & QSE_CUT_DEPTH_REX_MATCH) cut->depth.rex.match = depth; +} + +int qse_cut_comp (qse_cut_t* cut, const qse_char_t* str, qse_size_t len) +{ + const qse_char_t* p = str; + const qse_char_t* xnd = str + len; + qse_cint_t c; + int type = CHAR; + +#define CC(x,y) (((x) <= (y))? ((qse_cint_t)*(x)): QSE_CHAR_EOF) +#define NC(x,y) (((x) < (y))? ((qse_cint_t)*(++(x))): QSE_CHAR_EOF) +#define EOF(x) ((x) == QSE_CHAR_EOF) +#define MASK_START (1 << 1) +#define MASK_END (1 << 2) + + free_all_selector_blocks (cut); + + if (len <= 0) return 0; + + xnd--; c = CC (p, xnd); + while (1) + { + qse_size_t start = 0, end = 0; + int mask = 0; + + while (QSE_ISSPACE(c)) c = NC (p, xnd); + if (EOF(c)) + { + if (cut->sel.count > 0) + { + SETERR0 (cut, QSE_CUT_ESELNV); + return -1; + } + + break; + } + + if (c == QSE_T('c')) + { + type = CHAR; + c = NC (p, xnd); + while (QSE_ISSPACE(c)) c = NC (p, xnd); + } + else if (c == QSE_T('f')) + { + type = FIELD; + c = NC (p, xnd); + while (QSE_ISSPACE(c)) c = NC (p, xnd); + } + + if (QSE_ISDIGIT(c)) + { + do + { + start = start * 10 + (c - QSE_T('0')); + c = NC (p, xnd); + } + while (QSE_ISDIGIT(c)); + + while (QSE_ISSPACE(c)) c = NC (p, xnd); + mask |= MASK_START; + } + else start++; + + if (c == QSE_T('-')) + { + c = NC (p, xnd); + while (QSE_ISSPACE(c)) c = NC (p, xnd); + + if (QSE_ISDIGIT(c)) + { + do + { + end = end * 10 + (c - QSE_T('0')); + c = NC (p, xnd); + } + while (QSE_ISDIGIT(c)); + mask |= MASK_END; + } + else end = MAX; + + while (QSE_ISSPACE(c)) c = NC (p, xnd); + } + else end = start; + + if (!(mask & (MASK_START | MASK_END))) + { + SETERR0 (cut, QSE_CUT_ESELNV); + return -1; + } + + if (cut->sel.lb->len >= QSE_COUNTOF(cut->sel.lb->range)) + { + if (add_selector_block (cut) <= -1) + { + return -1; + } + } + + cut->sel.lb->range[cut->sel.lb->len].type = type; + cut->sel.lb->range[cut->sel.lb->len].start = start; + cut->sel.lb->range[cut->sel.lb->len].end = end; + cut->sel.lb->len++; + cut->sel.count++; + + if (EOF(c)) break; + if (c == QSE_T(',')) c = NC (p, xnd); + } + + return 0; +} + +int qse_cut_exec (qse_cut_t* cut, qse_cut_io_fun_t inf, qse_cut_io_fun_t outf) + +{ + /* selector: c12-30, b30-40, f1-3,6-7,10 + * default input field delimiter: TAB + * default output field delimiter: same as input delimiter + * option: QSE_CUT_ONLYDELIMITED + */ + +{ +int i; +for (i = 0; i < cut->sel.count; i++) +{ +qse_printf (QSE_T("%d start = %llu, end = %llu\n"), + cut->sel.fb.range[i].type, + (unsigned long long)cut->sel.fb.range[i].start, + (unsigned long long)cut->sel.fb.range[i].end); +} +} + return -1; +} diff --git a/qse/lib/cut/cut.h b/qse/lib/cut/cut.h new file mode 100644 index 00000000..49ce531c --- /dev/null +++ b/qse/lib/cut/cut.h @@ -0,0 +1,82 @@ +/* + * $Id: cut.h 287 2009-09-15 10:01:02Z baconevi $ + * + 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 . + */ + +#ifndef _QSE_LIB_CUT_CUT_H_ +#define _QSE_LIB_CUT_CUT_H_ + +#include +#include + +typedef struct qse_cut_sel_blk_t qse_cut_sel_blk_t; + +struct qse_cut_sel_blk_t +{ + qse_size_t len; + struct + { + enum + { + CHAR, + FIELD + } type; + qse_size_t start; + qse_size_t end; + } range[256]; + qse_cut_sel_blk_t* next; +}; + +struct qse_cut_t +{ + QSE_DEFINE_COMMON_FIELDS (cut) + + qse_cut_errstr_t errstr; /**< error string getter */ + qse_cut_errnum_t errnum; /**< stores an error number */ + qse_char_t errmsg[128]; /**< error message holder */ + + int option; /**< stores options */ + + struct + { + struct + { + qse_size_t build; + qse_size_t match; + } rex; + } depth; + + struct + { + qse_cut_sel_blk_t fb; /**< the first block is static */ + qse_cut_sel_blk_t* lb; /**< points to the last block */ + qse_size_t count; + } sel; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +const qse_char_t* qse_cut_dflerrstr (qse_cut_t* cut, qse_cut_errnum_t errnum); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/qse/lib/cut/err.c b/qse/lib/cut/err.c new file mode 100644 index 00000000..7065b3ce --- /dev/null +++ b/qse/lib/cut/err.c @@ -0,0 +1,118 @@ +/* + * $Id: err.c 287 2009-09-15 10:01:02Z baconevi $ + * + 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 . + */ + +#include "cut.h" +#include "../cmn/mem.h" + +const qse_char_t* qse_cut_dflerrstr (qse_cut_t* cut, qse_cut_errnum_t errnum) +{ + static const qse_char_t* errstr[] = + { + QSE_T("no error"), + QSE_T("insufficient memory"), + QSE_T("selector not valid"), + QSE_T("regular expression '${0}' incomplete"), + QSE_T("failed to compile regular expression '${0}'"), + QSE_T("failed to match regular expression"), + QSE_T("address 1 prohibited for '${0}'"), + QSE_T("address 2 prohibited for '${0}'"), + QSE_T("address 2 missing or invalid"), + QSE_T("newline expected"), + QSE_T("backslash expected"), + QSE_T("backslash ucut as delimiter"), + QSE_T("garbage after backslash"), + QSE_T("semicolon expected"), + QSE_T("empty label name"), + QSE_T("duplicate label name '${0}'"), + QSE_T("label '${0}' not found"), + QSE_T("empty file name"), + QSE_T("illegal file name"), + QSE_T("strings in translation set not the same length"), + QSE_T("group brackets not balanced"), + QSE_T("group nesting too deep"), + QSE_T("multiple occurrence specifiers"), + QSE_T("occurrence specifier zero"), + QSE_T("occurrence specifier too large"), + QSE_T("io error with file '${0}'"), + QSE_T("error returned by user io handler") + }; + + return (errnum >= 0 && errnum < QSE_COUNTOF(errstr))? + errstr[errnum]: QSE_T("unknown error"); +} + +qse_cut_errstr_t qse_cut_geterrstr (qse_cut_t* cut) +{ + return cut->errstr; +} + +void qse_cut_seterrstr (qse_cut_t* cut, qse_cut_errstr_t errstr) +{ + cut->errstr = errstr; +} + +qse_cut_errnum_t qse_cut_geterrnum (qse_cut_t* cut) +{ + return cut->errnum; +} + +const qse_char_t* qse_cut_geterrmsg (qse_cut_t* cut) +{ + return (cut->errmsg[0] == QSE_T('\0'))? + qse_cut_geterrstr(cut)(cut,cut->errnum): cut->errmsg; +} + +void qse_cut_geterror ( + qse_cut_t* cut, qse_cut_errnum_t* errnum, const qse_char_t** errmsg) +{ + if (errnum != QSE_NULL) *errnum = cut->errnum; + if (errmsg != QSE_NULL) + { + *errmsg = (cut->errmsg[0] == QSE_T('\0'))? + qse_cut_geterrstr(cut)(cut,cut->errnum): + cut->errmsg; + } +} + +void qse_cut_seterrnum ( + qse_cut_t* cut, qse_cut_errnum_t errnum, const qse_cstr_t* errarg) +{ + qse_cut_seterror (cut, errnum, errarg); +} + +void qse_cut_seterrmsg ( + qse_cut_t* cut, qse_cut_errnum_t errnum, const qse_char_t* errmsg) +{ + cut->errnum = errnum; + qse_strxcpy (cut->errmsg, QSE_COUNTOF(cut->errmsg), errmsg); +} + +void qse_cut_seterror ( + qse_cut_t* cut, qse_cut_errnum_t errnum, const qse_cstr_t* errarg) +{ + const qse_char_t* errfmt; + + cut->errnum = errnum; + + errfmt = qse_cut_geterrstr(cut)(cut,cut->errnum); + QSE_ASSERT (errfmt != QSE_NULL); + qse_strxfncpy (cut->errmsg, QSE_COUNTOF(cut->errmsg), errfmt, errarg); +} + diff --git a/qse/lib/sed/sed.h b/qse/lib/sed/sed.h index da87cdd7..78a3a731 100644 --- a/qse/lib/sed/sed.h +++ b/qse/lib/sed/sed.h @@ -1,5 +1,5 @@ /* - * $Id: sed.h 287 2009-09-15 10:01:02Z hyunghwan.chung $ + * $Id: sed.h 293 2009-10-04 14:08:27Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. This file is part of QSE. @@ -190,16 +190,6 @@ struct qse_sed_t } tmp; /** compiled commands */ -#if 0 - struct - { - qse_size_t len; /**< buffer size */ - qse_sed_cmd_t* buf; /**< buffer holding compiled commands */ - qse_sed_cmd_t* end; /**< end of the buffer */ - qse_sed_cmd_t* cur; /**< points next to the last command */ - } cmd; -#endif - struct { qse_sed_cmd_blk_t fb; /**< the first block is static */ @@ -273,4 +263,5 @@ const qse_char_t* qse_sed_dflerrstr (qse_sed_t* sed, qse_sed_errnum_t errnum); #ifdef __cplusplus } #endif + #endif