From 006dd8975f428aaa13b8f12a25d3e2ceb75100b8 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 19 Aug 2012 14:20:05 +0000 Subject: [PATCH] added 'abort' & QSE_AWK_ABORT to awk. added a new sed command 'C' that resembles the cut utility dropped the cut utility. added qse_str_nrcat()/qse_mbs_nrcat()/qse_wcs_nrcat() --- qse/lib/Makefile.am | 2 +- qse/lib/Makefile.in | 2 +- qse/lib/awk/parse.c | 7 +- qse/lib/awk/parse.h | 1 + qse/lib/awk/run.c | 2 +- qse/lib/awk/tree.c | 4 +- qse/lib/awk/tree.h | 1 + qse/lib/cmn/str-dynm.c | 71 ++++ qse/lib/cmn/str-dynw.c | 71 ++++ qse/lib/cut/Cut.cpp | 175 --------- qse/lib/cut/Makefile.am | 19 - qse/lib/cut/Makefile.in | 613 ------------------------------- qse/lib/cut/StdCut.cpp | 261 -------------- qse/lib/cut/cut.c | 772 ---------------------------------------- qse/lib/cut/cut.h | 117 ------ qse/lib/cut/err.c | 97 ----- qse/lib/cut/std.c | 228 ------------ qse/lib/sed/err.c | 1 + qse/lib/sed/sed.c | 537 ++++++++++++++++++++++++++-- qse/lib/sed/sed.h | 11 +- 20 files changed, 665 insertions(+), 2327 deletions(-) delete mode 100644 qse/lib/cut/Cut.cpp delete mode 100644 qse/lib/cut/Makefile.am delete mode 100644 qse/lib/cut/Makefile.in delete mode 100644 qse/lib/cut/StdCut.cpp delete mode 100644 qse/lib/cut/cut.c delete mode 100644 qse/lib/cut/cut.h delete mode 100644 qse/lib/cut/err.c delete mode 100644 qse/lib/cut/std.c diff --git a/qse/lib/Makefile.am b/qse/lib/Makefile.am index b5254368..476b1f44 100644 --- a/qse/lib/Makefile.am +++ b/qse/lib/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = cmn awk cut sed net stx +SUBDIRS = cmn awk sed net stx DIST_SUBDIRS = $(SUBDIRS) diff --git a/qse/lib/Makefile.in b/qse/lib/Makefile.in index faec0b03..81aab7c6 100644 --- a/qse/lib/Makefile.in +++ b/qse/lib/Makefile.in @@ -238,7 +238,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -SUBDIRS = cmn awk cut sed net stx +SUBDIRS = cmn awk sed net stx DIST_SUBDIRS = $(SUBDIRS) all: all-recursive diff --git a/qse/lib/awk/parse.c b/qse/lib/awk/parse.c index 933c256b..a902e595 100644 --- a/qse/lib/awk/parse.c +++ b/qse/lib/awk/parse.c @@ -103,6 +103,7 @@ enum tok_t TOK_CONTINUE, TOK_RETURN, TOK_EXIT, + TOK_ABORT, TOK_NEXT, TOK_NEXTFILE, TOK_NEXTOFILE, @@ -249,6 +250,7 @@ static kwent_t kwtab[] = * also keep it sorted by the first field for binary search */ { { QSE_T("BEGIN"), 5 }, TOK_BEGIN, QSE_AWK_PABLOCK }, { { QSE_T("END"), 3 }, TOK_END, QSE_AWK_PABLOCK }, + { { QSE_T("abort"), 5 }, TOK_ABORT, QSE_AWK_ABORT }, { { QSE_T("break"), 5 }, TOK_BREAK, 0 }, { { QSE_T("continue"), 8 }, TOK_CONTINUE, 0 }, { { QSE_T("delete"), 6 }, TOK_DELETE, 0 }, @@ -2530,7 +2532,7 @@ static qse_awk_nde_t* parse_exit (qse_awk_t* awk, const qse_awk_loc_t* xloc) qse_awk_nde_exit_t* nde; qse_awk_nde_t* val; - QSE_ASSERT (awk->ptok.type == TOK_EXIT); + QSE_ASSERT (awk->ptok.type == TOK_EXIT || awk->ptok.type == TOK_ABORT); nde = (qse_awk_nde_exit_t*) QSE_AWK_ALLOC (awk, QSE_SIZEOF(qse_awk_nde_exit_t)); @@ -2542,6 +2544,7 @@ static qse_awk_nde_t* parse_exit (qse_awk_t* awk, const qse_awk_loc_t* xloc) nde->type = QSE_AWK_NDE_EXIT; nde->loc = *xloc; + nde->abort = (awk->ptok.type == TOK_ABORT); nde->next = QSE_NULL; if (MATCH_TERMINATOR(awk)) @@ -2957,7 +2960,7 @@ static qse_awk_nde_t* parse_statement_nb ( if (get_token(awk) <= -1) return QSE_NULL; nde = parse_return (awk, xloc); } - else if (MATCH(awk,TOK_EXIT)) + else if (MATCH(awk,TOK_EXIT) || MATCH(awk,TOK_ABORT)) { if (get_token(awk) <= -1) return QSE_NULL; nde = parse_exit (awk, xloc); diff --git a/qse/lib/awk/parse.h b/qse/lib/awk/parse.h index af7e42b7..25d12af7 100644 --- a/qse/lib/awk/parse.h +++ b/qse/lib/awk/parse.h @@ -26,6 +26,7 @@ enum qse_awk_kwid_t { QSE_AWK_KWID_BEGIN, QSE_AWK_KWID_END, + QSE_AWK_KWID_ABORT, QSE_AWK_KWID_BREAK, QSE_AWK_KWID_CONTINUE, QSE_AWK_KWID_DELETE, diff --git a/qse/lib/awk/run.c b/qse/lib/awk/run.c index 27b1b6db..67e55c5f 100644 --- a/qse/lib/awk/run.c +++ b/qse/lib/awk/run.c @@ -2291,7 +2291,7 @@ static int run_exit (qse_awk_rtx_t* run, qse_awk_nde_exit_t* nde) qse_awk_rtx_refupval (run, val); } - run->exit_level = EXIT_GLOBAL; + run->exit_level = (nde->abort)? EXIT_ABORT: EXIT_GLOBAL; return 0; } diff --git a/qse/lib/awk/tree.c b/qse/lib/awk/tree.c index 3bf905b7..5a1177c7 100644 --- a/qse/lib/awk/tree.c +++ b/qse/lib/awk/tree.c @@ -971,14 +971,14 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth) if (px->val == QSE_NULL) { - qse_awk_getkwname (awk, QSE_AWK_KWID_EXIT, &kw); + qse_awk_getkwname (awk, (px->abort? QSE_AWK_KWID_ABORT: QSE_AWK_KWID_EXIT), &kw); PUT_SRCSTRN (awk, kw.ptr, kw.len); PUT_SRCSTR (awk, QSE_T(";")); PUT_NL (awk); } else { - qse_awk_getkwname (awk, QSE_AWK_KWID_EXIT, &kw); + qse_awk_getkwname (awk, (px->abort? QSE_AWK_KWID_ABORT: QSE_AWK_KWID_EXIT), &kw); PUT_SRCSTRN (awk, kw.ptr, kw.len); PUT_SRCSTR (awk, QSE_T(" ")); QSE_ASSERT (px->val->next == QSE_NULL); diff --git a/qse/lib/awk/tree.h b/qse/lib/awk/tree.h index 5d148a56..088ef432 100644 --- a/qse/lib/awk/tree.h +++ b/qse/lib/awk/tree.h @@ -273,6 +273,7 @@ struct qse_awk_nde_exit_t { QSE_AWK_NDE_HDR; qse_awk_nde_t* val; /* optional (no exit code if QSE_NULL) */ + int abort; }; /* QSE_AWK_NDE_NEXT */ diff --git a/qse/lib/cmn/str-dynm.c b/qse/lib/cmn/str-dynm.c index 04f4de4a..ab3ab1a9 100644 --- a/qse/lib/cmn/str-dynm.c +++ b/qse/lib/cmn/str-dynm.c @@ -257,8 +257,55 @@ qse_size_t qse_mbs_cat (qse_mbs_t* str, const qse_mchar_t* s) return qse_mbs_ncat (str, s, qse_mbslen(s)); } +static int resize_for_ncat (qse_mbs_t* str, qse_size_t len) +{ + if (len > str->capa - str->val.len) + { + qse_size_t ncapa, mincapa; + + /* let the minimum capacity be as large as + * to fit in the new substring */ + mincapa = str->val.len + len; + + if (str->sizer == QSE_NULL) + { + /* increase the capacity by the length to add */ + ncapa = mincapa; + /* if the new capacity is less than the double, + * just double it */ + if (ncapa < str->capa * 2) ncapa = str->capa * 2; + } + else + { + /* let the user determine the new capacity. + * pass the minimum capacity required as a hint */ + ncapa = str->sizer (str, mincapa); + /* if no change in capacity, return current length */ + if (ncapa == str->capa) return 0; + } + + /* change the capacity */ + do + { + if (qse_mbs_setcapa (str, ncapa) != (qse_size_t)-1) break; + if (ncapa <= mincapa) return -1; + ncapa--; + } + while (1); + } + else if (str->capa <= 0 && len <= 0) + { + QSE_ASSERT (str->val.ptr == QSE_NULL); + QSE_ASSERT (str->val.len <= 0); + if (qse_mbs_setcapa (str, 1) == (qse_size_t)-1) return -1; + } + + return 1; +} + qse_size_t qse_mbs_ncat (qse_mbs_t* str, const qse_mchar_t* s, qse_size_t len) { +#if 0 if (len > str->capa - str->val.len) { qse_size_t ncapa, mincapa; @@ -299,6 +346,12 @@ qse_size_t qse_mbs_ncat (qse_mbs_t* str, const qse_mchar_t* s, qse_size_t len) QSE_ASSERT (str->val.len <= 0); if (qse_mbs_setcapa (str, 1) == (qse_size_t)-1) return (qse_size_t)-1; } +#endif + int n; + + n = resize_for_ncat (str, len); + if (n <= -1) return (qse_size_t)-1; + if (n == 0) return str->val.len; if (len > str->capa - str->val.len) { @@ -321,6 +374,24 @@ qse_size_t qse_mbs_ncat (qse_mbs_t* str, const qse_mchar_t* s, qse_size_t len) return str->val.len; } +qse_size_t qse_mbs_nrcat (qse_mbs_t* str, const qse_mchar_t* s, qse_size_t len) +{ + int n; + qse_size_t i, j; + + n = resize_for_ncat (str, len); + if (n <= -1) return (qse_size_t)-1; + if (n == 0) return str->val.len; + + if (len > str->capa - str->val.len) len = str->capa - str->val.len; + + for (i = len, j = str->val.len ; i > 0; j++) str->val.ptr[j] = s[--i]; + str->val.ptr[j] = QSE_MT('\0'); + str->val.len = j; + + return str->val.len; +} + qse_size_t qse_mbs_ccat (qse_mbs_t* str, qse_mchar_t c) { return qse_mbs_ncat (str, &c, 1); diff --git a/qse/lib/cmn/str-dynw.c b/qse/lib/cmn/str-dynw.c index 0fcbeca0..8ddf5632 100644 --- a/qse/lib/cmn/str-dynw.c +++ b/qse/lib/cmn/str-dynw.c @@ -257,8 +257,55 @@ qse_size_t qse_wcs_cat (qse_wcs_t* str, const qse_wchar_t* s) return qse_wcs_ncat (str, s, qse_wcslen(s)); } +static int resize_for_ncat (qse_wcs_t* str, qse_size_t len) +{ + if (len > str->capa - str->val.len) + { + qse_size_t ncapa, mincapa; + + /* let the minimum capacity be as large as + * to fit in the new substring */ + mincapa = str->val.len + len; + + if (str->sizer == QSE_NULL) + { + /* increase the capacity by the length to add */ + ncapa = mincapa; + /* if the new capacity is less than the double, + * just double it */ + if (ncapa < str->capa * 2) ncapa = str->capa * 2; + } + else + { + /* let the user determine the new capacity. + * pass the minimum capacity required as a hint */ + ncapa = str->sizer (str, mincapa); + /* if no change in capacity, return current length */ + if (ncapa == str->capa) return 0; + } + + /* change the capacity */ + do + { + if (qse_wcs_setcapa (str, ncapa) != (qse_size_t)-1) break; + if (ncapa <= mincapa) return -1; + ncapa--; + } + while (1); + } + else if (str->capa <= 0 && len <= 0) + { + QSE_ASSERT (str->val.ptr == QSE_NULL); + QSE_ASSERT (str->val.len <= 0); + if (qse_wcs_setcapa (str, 1) == (qse_size_t)-1) return -1; + } + + return 1; +} + qse_size_t qse_wcs_ncat (qse_wcs_t* str, const qse_wchar_t* s, qse_size_t len) { +#if 0 if (len > str->capa - str->val.len) { qse_size_t ncapa, mincapa; @@ -299,6 +346,12 @@ qse_size_t qse_wcs_ncat (qse_wcs_t* str, const qse_wchar_t* s, qse_size_t len) QSE_ASSERT (str->val.len <= 0); if (qse_wcs_setcapa (str, 1) == (qse_size_t)-1) return (qse_size_t)-1; } +#endif + int n; + + n = resize_for_ncat (str, len); + if (n <= -1) return (qse_size_t)-1; + if (n == 0) return str->val.len; if (len > str->capa - str->val.len) { @@ -321,6 +374,24 @@ qse_size_t qse_wcs_ncat (qse_wcs_t* str, const qse_wchar_t* s, qse_size_t len) return str->val.len; } +qse_size_t qse_wcs_nrcat (qse_wcs_t* str, const qse_wchar_t* s, qse_size_t len) +{ + int n; + qse_size_t i, j; + + n = resize_for_ncat (str, len); + if (n <= -1) return (qse_size_t)-1; + if (n == 0) return str->val.len; + + if (len > str->capa - str->val.len) len = str->capa - str->val.len; + + for (i = len, j = str->val.len ; i > 0; j++) str->val.ptr[j] = s[--i]; + str->val.ptr[j] = QSE_WT('\0'); + str->val.len = j; + + return str->val.len; +} + qse_size_t qse_wcs_ccat (qse_wcs_t* str, qse_wchar_t c) { return qse_wcs_ncat (str, &c, 1); diff --git a/qse/lib/cut/Cut.cpp b/qse/lib/cut/Cut.cpp deleted file mode 100644 index 5862ed57..00000000 --- a/qse/lib/cut/Cut.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - * $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 "../cmn/mem.h" -#include "cut.h" - -///////////////////////////////// -QSE_BEGIN_NAMESPACE(QSE) -///////////////////////////////// - -int Cut::open () -{ - cut = qse_cut_open (this->mmgr, QSE_SIZEOF(Cut*)); - if (cut == QSE_NULL) return -1; - *(Cut**)QSE_XTN(cut) = this; - - dflerrstr = qse_cut_geterrstr (cut); - qse_cut_seterrstr (cut, xerrstr); - - return 0; -} - -void Cut::close () -{ - if (cut != QSE_NULL) - { - qse_cut_close (cut); - cut = QSE_NULL; - } -} - -int Cut::compile (const char_t* sptr) -{ - QSE_ASSERT (cut != QSE_NULL); - return qse_cut_comp (cut, sptr, qse_strlen(sptr)); -} - -int Cut::compile (const char_t* sptr, size_t slen) -{ - QSE_ASSERT (cut != QSE_NULL); - return qse_cut_comp (cut, sptr, slen); -} - -int Cut::execute (Stream& iostream) -{ - QSE_ASSERT (cut != QSE_NULL); - - this->iostream = &iostream; - return qse_cut_exec (cut, xin, xout); -} - -int Cut::getOption() const -{ - QSE_ASSERT (cut != QSE_NULL); - return qse_cut_getoption (cut); -} - -void Cut::setOption (int opt) -{ - QSE_ASSERT (cut != QSE_NULL); - qse_cut_setoption (cut, opt); -} - -const Cut::char_t* Cut::getErrorMessage () const -{ - return (cut == QSE_NULL)? QSE_T(""): qse_cut_geterrmsg (cut); -} - -Cut::errnum_t Cut::getErrorNumber () const -{ - return (cut == QSE_NULL)? QSE_CUT_ENOERR: qse_cut_geterrnum (cut); -} - -void Cut::setError (errnum_t err, const cstr_t* args) -{ - QSE_ASSERT (cut != QSE_NULL); - qse_cut_seterror (cut, err, args); -} - -Cut::ssize_t Cut::xin ( - cut_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* buf, size_t len) -{ - Cut* cut = *(Cut**)QSE_XTN(s); - - Stream::Data iodata (cut, Stream::READ, arg); - - try - { - switch (cmd) - { - case QSE_CUT_IO_OPEN: - return cut->iostream->open (iodata); - case QSE_CUT_IO_CLOSE: - return cut->iostream->close (iodata); - case QSE_CUT_IO_READ: - return cut->iostream->read (iodata, buf, len); - default: - return -1; - } - } - catch (...) - { - return -1; - } -} - -Cut::ssize_t Cut::xout ( - cut_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* dat, size_t len) -{ - Cut* cut = *(Cut**)QSE_XTN(s); - - Stream::Data iodata (cut, Stream::WRITE, arg); - - try - { - switch (cmd) - { - case QSE_CUT_IO_OPEN: - return cut->iostream->open (iodata); - case QSE_CUT_IO_CLOSE: - return cut->iostream->close (iodata); - case QSE_CUT_IO_WRITE: - return cut->iostream->write (iodata, dat, len); - default: - return -1; - } - } - catch (...) - { - return -1; - } -} - -const Cut::char_t* Cut::getErrorString (errnum_t num) const -{ - QSE_ASSERT (dflerrstr != QSE_NULL); - return dflerrstr (cut, num); -} - -const Cut::char_t* Cut::xerrstr (cut_t* s, errnum_t num) -{ - Cut* cut = *(Cut**)QSE_XTN(s); - try - { - return cut->getErrorString (num); - } - catch (...) - { - return cut->dflerrstr (s, num); - } -} - -///////////////////////////////// -QSE_END_NAMESPACE(QSE) -///////////////////////////////// - diff --git a/qse/lib/cut/Makefile.am b/qse/lib/cut/Makefile.am deleted file mode 100644 index cf4cd9af..00000000 --- a/qse/lib/cut/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ -AUTOMAKE_OPTIONS = nostdinc - -AM_CPPFLAGS = \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/include \ - -I$(includedir) - -lib_LTLIBRARIES = libqsecut.la -libqsecut_la_SOURCES = cut.c err.c cut.h std.c -libqsecut_la_LDFLAGS = -L../cmn -L$(libdir) -version-info 1:0:0 -no-undefined -libqsecut_la_LIBADD = -lqsecmn - -if ENABLE_CXX -lib_LTLIBRARIES += libqsecutxx.la -libqsecutxx_la_SOURCES = Cut.cpp StdCut.cpp -libqsecutxx_la_LDFLAGS = -L. -L../cmn -L$(libdir) -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 deleted file mode 100644 index e61a8521..00000000 --- a/qse/lib/cut/Makefile.in +++ /dev/null @@ -1,613 +0,0 @@ -# Makefile.in generated by automake 1.11.1 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008, 2009 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@ -@ENABLE_CXX_TRUE@am__append_1 = libqsecutxx.la -subdir = lib/cut -DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/ax_numval.m4 \ - $(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/m4/libtool.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__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 = f=`echo $$p | sed -e 's|^.*/||'`; -am__install_max = 40 -am__nobase_strip_setup = \ - srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` -am__nobase_strip = \ - for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" -am__nobase_list = $(am__nobase_strip_setup); \ - for p in $$list; do echo "$$p $$p"; done | \ - sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ - $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ - if (++n[$$2] == $(am__install_max)) \ - { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ - END { for (dir in files) print dir, files[dir] }' -am__base_list = \ - sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ - sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' -am__installdirs = "$(DESTDIR)$(libdir)" -LTLIBRARIES = $(lib_LTLIBRARIES) -libqsecut_la_DEPENDENCIES = -am_libqsecut_la_OBJECTS = cut.lo err.lo std.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 $@ -libqsecutxx_la_DEPENDENCIES = -am__libqsecutxx_la_SOURCES_DIST = Cut.cpp StdCut.cpp -@ENABLE_CXX_TRUE@am_libqsecutxx_la_OBJECTS = Cut.lo StdCut.lo -libqsecutxx_la_OBJECTS = $(am_libqsecutxx_la_OBJECTS) -libqsecutxx_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(libqsecutxx_la_LDFLAGS) $(LDFLAGS) -o $@ -@ENABLE_CXX_TRUE@am_libqsecutxx_la_rpath = -rpath $(libdir) -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 $@ -CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -CXXLD = $(CXX) -CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ - $(LDFLAGS) -o $@ -SOURCES = $(libqsecut_la_SOURCES) $(libqsecutxx_la_SOURCES) -DIST_SOURCES = $(libqsecut_la_SOURCES) \ - $(am__libqsecutxx_la_SOURCES_DIST) -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@ -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@ -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@ -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@ -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_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@ -STRIP = @STRIP@ -TRUE = @TRUE@ -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@ -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@ -AUTOMAKE_OPTIONS = nostdinc -AM_CPPFLAGS = \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/include \ - -I$(includedir) - -lib_LTLIBRARIES = libqsecut.la $(am__append_1) -libqsecut_la_SOURCES = cut.c err.c cut.h std.c -libqsecut_la_LDFLAGS = -L../cmn -L$(libdir) -version-info 1:0:0 -no-undefined -libqsecut_la_LIBADD = -lqsecmn -@ENABLE_CXX_TRUE@libqsecutxx_la_SOURCES = Cut.cpp StdCut.cpp -@ENABLE_CXX_TRUE@libqsecutxx_la_LDFLAGS = -L. -L../cmn -L$(libdir) -version-info 1:0:0 -no-undefined -@ENABLE_CXX_TRUE@libqsecutxx_la_LIBADD = -lqsecut -lqsecmn -all: all-am - -.SUFFIXES: -.SUFFIXES: .c .cpp .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'; \ - $(am__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 -$(am__aclocal_m4_deps): -install-libLTLIBRARIES: $(lib_LTLIBRARIES) - @$(NORMAL_INSTALL) - test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" - @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ - list2=; for p in $$list; do \ - if test -f $$p; then \ - list2="$$list2 $$p"; \ - else :; fi; \ - done; \ - test -z "$$list2" || { \ - echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ - $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ - } - -uninstall-libLTLIBRARIES: - @$(NORMAL_UNINSTALL) - @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ - for p in $$list; do \ - $(am__strip_dir) \ - echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ - $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ - 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) -libqsecutxx.la: $(libqsecutxx_la_OBJECTS) $(libqsecutxx_la_DEPENDENCIES) - $(libqsecutxx_la_LINK) $(am_libqsecutxx_la_rpath) $(libqsecutxx_la_OBJECTS) $(libqsecutxx_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)/StdCut.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cut.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/err.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/std.Plo@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 $@ $< - -.cpp.o: -@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< - -.cpp.obj: -@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` - -.cpp.lo: -@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -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 $(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) - -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-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 - -html-am: - -info: info-am - -info-am: - -install-data-am: - -install-dvi: install-dvi-am - -install-dvi-am: - -install-exec-am: install-libLTLIBRARIES - -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-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 - - -# 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/StdCut.cpp b/qse/lib/cut/StdCut.cpp deleted file mode 100644 index aad7b0ca..00000000 --- a/qse/lib/cut/StdCut.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/* - * $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 "cut.h" -#include "../cmn/mem.h" - -///////////////////////////////// -QSE_BEGIN_NAMESPACE(QSE) -///////////////////////////////// - -static qse_sio_t* open_sio (StdCut::Stream::Data& io, const qse_char_t* file, int flags) -{ - qse_sio_t* sio; - - sio = qse_sio_open (((StdCut::cut_t*)io)->mmgr, 0, file, flags); - if (sio == QSE_NULL) - { - qse_cstr_t ea; - ea.ptr = file; - ea.len = qse_strlen (file); - ((StdCut::Cut*)io)->setError (QSE_CUT_EIOFIL, &ea); - } - return sio; -} - -static qse_sio_t* open_sio_std (StdCut::Stream::Data& io, qse_sio_std_t std, int flags) -{ - qse_sio_t* sio; - static const qse_char_t* std_names[] = - { - QSE_T("stdin"), - QSE_T("stdout"), - QSE_T("stderr"), - }; - - sio = qse_sio_openstd (((StdCut::cut_t*)io)->mmgr, 0, std, flags); - if (sio == QSE_NULL) - { - qse_cstr_t ea; - ea.ptr = std_names[std]; - ea.len = qse_strlen (std_names[std]); - ((StdCut::Cut*)io)->setError (QSE_CUT_EIOFIL, &ea); - } - return sio; -} - -int StdCut::FileStream::open (Data& io) -{ - qse_sio_t* sio; - - if (io.getMode() == READ) - { - sio = (infile == QSE_NULL)? - open_sio_std (io, QSE_SIO_STDIN, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR): - open_sio (io, infile, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR); - if (sio == QSE_NULL) return -1; - } - else - { - sio = (outfile == QSE_NULL)? - open_sio_std (io, QSE_SIO_STDIN, QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR): - open_sio (io, outfile, QSE_SIO_WRITE | QSE_SIO_CREATE | QSE_SIO_TRUNCATE | QSE_SIO_IGNOREMBWCERR); - if (sio == QSE_NULL) return -1; - } - - io.setHandle (sio); - return 1; -} - -int StdCut::FileStream::close (Data& io) -{ - qse_sio_t* sio = (qse_sio_t*)io.getHandle(); - - qse_sio_flush (sio); - qse_sio_close (sio); - - return 0; -} - -StdCut::ssize_t StdCut::FileStream::read (Data& io, char_t* buf, size_t len) -{ - ssize_t n = qse_sio_getstrn ((qse_sio_t*)io.getHandle(), buf, len); - - if (n == -1) - { - if (infile != QSE_NULL) - { - // if writing to outfile, set the error message - // explicitly. other cases are handled by - // the caller in cut.c. - qse_cstr_t ea; - ea.ptr = infile; - ea.len = qse_strlen (infile); - ((Cut*)io)->setError (QSE_CUT_EIOFIL, &ea); - } - } - - return n; -} - -StdCut::ssize_t StdCut::FileStream::write (Data& io, const char_t* buf, size_t len) -{ - ssize_t n = qse_sio_putstrn ((qse_sio_t*)io.getHandle(), buf, len); - - if (n == -1) - { - if (outfile != QSE_NULL) - { - // if writing to outfile, set the error message - // explicitly. other cases are handled by - // the caller in cut.c. - qse_cstr_t ea; - ea.ptr = outfile; - ea.len = qse_strlen (outfile); - ((Cut*)io)->setError (QSE_CUT_EIOFIL, &ea); - } - } - - return n; -} - -StdCut::StringStream::StringStream (const char_t* in) -{ - this->in.ptr = in; - this->in.end = in + qse_strlen(in); - this->out.inited = false; -} - -StdCut::StringStream::StringStream (const char_t* in, size_t len) -{ - this->in.ptr = in; - this->in.end = in + len; - this->out.inited = false; -} - -StdCut::StringStream::~StringStream () -{ - if (out.inited) qse_str_fini (&out.buf); -} - -int StdCut::StringStream::open (Data& io) -{ - // open a main data stream - if (io.getMode() == READ) - { - in.cur = in.ptr; - io.setHandle ((void*)in.ptr); - } - else - { - if (!out.inited) - { - if (qse_str_init (&out.buf, ((Cut*)io)->getMmgr(), 256) <= -1) - { - ((Cut*)io)->setError (QSE_CUT_ENOMEM); - return -1; - } - - out.inited = true; - } - - qse_str_clear (&out.buf); - io.setHandle (&out.buf); - } - - return 1; -} - -int StdCut::StringStream::close (Data& io) -{ - const void* handle = io.getHandle(); - if (handle != in.ptr && handle != &out.buf) - qse_sio_close ((qse_sio_t*)handle); - return 0; -} - -StdCut::ssize_t StdCut::StringStream::read (Data& io, char_t* buf, size_t len) -{ - const void* handle = io.getHandle(); - - if (len == (size_t)-1) len--; // shrink buffer if too long - if (handle == in.ptr) - { - size_t n = 0; - while (in.cur < in.end && n < len) - buf[n++] = *in.cur++; - return (ssize_t)n; - } - else - { - QSE_ASSERT (handle != &out.buf); - return -1; - } -} - -StdCut::ssize_t StdCut::StringStream::write (Data& io, const char_t* data, size_t len) -{ - const void* handle = io.getHandle(); - - if (len == (qse_size_t)-1) len--; // shrink data if too long - - if (handle == &out.buf) - { - if (qse_str_ncat (&out.buf, data, len) == (qse_size_t)-1) - { - ((Cut*)io)->setError (QSE_CUT_ENOMEM); - return -1; - } - - return len; - } - else - { - QSE_ASSERT (handle != in.ptr); - return -1; - } -} - -const StdCut::char_t* StdCut::StringStream::getInput (size_t* len) const -{ - if (len) *len = in.end - in.ptr; - return in.ptr; -} - -const StdCut::char_t* StdCut::StringStream::getOutput (size_t* len) const -{ - if (out.inited) - { - if (len) *len = QSE_STR_LEN(&out.buf); - return QSE_STR_PTR(&out.buf); - } - else - { - if (len) *len = 0; - return QSE_T(""); - } -} - -///////////////////////////////// -QSE_END_NAMESPACE(QSE) -///////////////////////////////// diff --git a/qse/lib/cut/cut.c b/qse/lib/cut/cut.c deleted file mode 100644 index 5430c093..00000000 --- a/qse/lib/cut/cut.c +++ /dev/null @@ -1,772 +0,0 @@ -/* - * $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 "cut.h" -#include "../cmn/mem.h" -#include - -QSE_IMPLEMENT_COMMON_FUNCTIONS (cut) - -static int 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 DFL_LINE_CAPA 256 - -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; - cut->sel.fcount = 0; - cut->sel.ccount = 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; - cut->sel.fcount = 0; - cut->sel.ccount = 0; -} - -qse_cut_t* qse_cut_open (qse_mmgr_t* mmgr, qse_size_t xtn) -{ - qse_cut_t* cut; - - 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) <= -1) - { - 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 int 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; - - cut->e.in.cflds = QSE_COUNTOF(cut->e.in.sflds); - cut->e.in.flds = cut->e.in.sflds; - - if (qse_str_init ( - &cut->e.in.line, QSE_MMGR(cut), DFL_LINE_CAPA) <= -1) - { - SETERR0 (cut, QSE_CUT_ENOMEM); - return -1; - } - - return 0; -} - -static void qse_cut_fini (qse_cut_t* cut) -{ - free_all_selector_blocks (cut); - if (cut->e.in.flds != cut->e.in.sflds) - QSE_MMGR_FREE (cut->mmgr, cut->e.in.flds); - qse_str_fini (&cut->e.in.line); -} - -void qse_cut_setoption (qse_cut_t* cut, int option) -{ - cut->option = option; -} - -int qse_cut_getoption (qse_cut_t* cut) -{ - return cut->option; -} - -void qse_cut_clear (qse_cut_t* cut) -{ - free_all_selector_blocks (cut); - if (cut->e.in.flds != cut->e.in.sflds) - QSE_MMGR_FREE (cut->mmgr, cut->e.in.flds); - cut->e.in.cflds = QSE_COUNTOF(cut->e.in.sflds); - cut->e.in.flds = cut->e.in.sflds; - - qse_str_clear (&cut->e.in.line); - qse_str_setcapa (&cut->e.in.line, DFL_LINE_CAPA); -} - -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* lastp = str + len; - qse_cint_t c; - int sel = QSE_SED_SEL_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) -#define MAX QSE_TYPE_MAX(qse_size_t) - - /* free selector blocks compiled previously */ - free_all_selector_blocks (cut); - - /* set the default delimiters */ - cut->sel.din = QSE_T(' '); - cut->sel.dout = QSE_T(' '); - - /* if the selector string is empty, don't need to proceed */ - if (len <= 0) return 0; - - /* compile the selector string */ - lastp--; c = CC (p, lastp); - while (1) - { - qse_size_t start = 0, end = 0; - int mask = 0; - - while (QSE_ISSPACE(c)) c = NC (p, lastp); - if (EOF(c)) - { - if (cut->sel.count > 0) - { - SETERR0 (cut, QSE_CUT_ESELNV); - return -1; - } - - break; - } - - if (c == QSE_T('d')) - { - /* the next character is the input delimiter. - * the output delimiter defaults to the input - * delimiter. */ - c = NC (p, lastp); - if (EOF(c)) - { - SETERR0 (cut, QSE_CUT_ESELNV); - return -1; - } - cut->sel.din = c; - cut->sel.dout = c; - - c = NC (p, lastp); - } - else if (c == QSE_T('D')) - { - /* the next two characters are the input and - * the output delimiter each. */ - c = NC (p, lastp); - if (EOF(c)) - { - SETERR0 (cut, QSE_CUT_ESELNV); - return -1; - } - cut->sel.din = c; - - c = NC (p, lastp); - if (EOF(c)) - { - SETERR0 (cut, QSE_CUT_ESELNV); - return -1; - } - cut->sel.dout = c; - - c = NC (p, lastp); - } - else - { - if (c == QSE_T('c') || c == QSE_T('f')) - { - sel = c; - c = NC (p, lastp); - while (QSE_ISSPACE(c)) c = NC (p, lastp); - } - - if (QSE_ISDIGIT(c)) - { - do - { - start = start * 10 + (c - QSE_T('0')); - c = NC (p, lastp); - } - while (QSE_ISDIGIT(c)); - - while (QSE_ISSPACE(c)) c = NC (p, lastp); - mask |= MASK_START; - } - else start++; - - if (c == QSE_T('-')) - { - c = NC (p, lastp); - while (QSE_ISSPACE(c)) c = NC (p, lastp); - - if (QSE_ISDIGIT(c)) - { - do - { - end = end * 10 + (c - QSE_T('0')); - c = NC (p, lastp); - } - while (QSE_ISDIGIT(c)); - mask |= MASK_END; - } - else end = MAX; - - while (QSE_ISSPACE(c)) c = NC (p, lastp); - } - 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].id = sel; - 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 (sel == QSE_SED_SEL_FIELD) cut->sel.fcount++; - else cut->sel.ccount++; - } - - if (EOF(c)) break; - if (c == QSE_T(',')) c = NC (p, lastp); - } - - return 0; -} - -static int read_char (qse_cut_t* cut, qse_char_t* c) -{ - qse_ssize_t n; - - if (cut->e.in.pos >= cut->e.in.len) - { - cut->errnum = QSE_CUT_ENOERR; - n = cut->e.in.fun ( - cut, QSE_CUT_IO_READ, &cut->e.in.arg, - cut->e.in.buf, QSE_COUNTOF(cut->e.in.buf) - ); - if (n <= -1) - { - if (cut->errnum == QSE_CUT_ENOERR) - SETERR0 (cut, QSE_CUT_EIOUSR); - return -1; - } - - if (n == 0) return 0; /* end of file */ - - cut->e.in.len = n; - cut->e.in.pos = 0; - } - - *c = cut->e.in.buf[cut->e.in.pos++]; - return 1; -} - -static int read_line (qse_cut_t* cut) -{ - qse_size_t len = 0; - qse_char_t c; - int n; - - qse_str_clear (&cut->e.in.line); - if (cut->e.in.eof) return 0; - - while (1) - { - n = read_char (cut, &c); - if (n <= -1) return -1; - if (n == 0) - { - cut->e.in.eof = 1; - if (len == 0) return 0; - break; - } - - if (c == QSE_T('\n')) - { - /* don't include the line terminater to a line */ - /* TODO: support different line end convension */ - break; - } - - if (qse_str_ccat (&cut->e.in.line, c) == (qse_size_t)-1) - { - SETERR0 (cut, QSE_CUT_ENOMEM); - return -1; - } - len++; - } - - cut->e.in.num++; - - if (cut->option & QSE_CUT_TRIMSPACE) qse_str_trm (&cut->e.in.line); - if (cut->option & QSE_CUT_NORMSPACE) qse_str_pac (&cut->e.in.line); - return 1; -} - -static int flush (qse_cut_t* cut) -{ - qse_size_t pos = 0; - qse_ssize_t n; - - while (cut->e.out.len > 0) - { - cut->errnum = QSE_CUT_ENOERR; - n = cut->e.out.fun ( - cut, QSE_CUT_IO_WRITE, &cut->e.out.arg, - &cut->e.out.buf[pos], cut->e.out.len); - - if (n <= -1) - { - if (cut->errnum == QSE_CUT_ENOERR) - SETERR0 (cut, QSE_CUT_EIOUSR); - return -1; - } - - if (n == 0) - { - /* reached the end of file - this is also an error */ - if (cut->errnum == QSE_CUT_ENOERR) - SETERR0 (cut, QSE_CUT_EIOUSR); - return -1; - } - - pos += n; - cut->e.out.len -= n; - } - - return 0; -} - -static int write_char (qse_cut_t* cut, qse_char_t c) -{ - cut->e.out.buf[cut->e.out.len++] = c; - if (c == QSE_T('\n') || - cut->e.out.len >= QSE_COUNTOF(cut->e.out.buf)) - { - return flush (cut); - } - - return 0; -} - -static int write_linebreak (qse_cut_t* cut) -{ - /* TODO: different line termination convention */ - return write_char (cut, QSE_T('\n')); -} - -static int write_str (qse_cut_t* cut, const qse_char_t* str, qse_size_t len) -{ - qse_size_t i; - - for (i = 0; i < len; i++) - { - if (write_char (cut, str[i]) <= -1) return -1; - } - - return 0; -} - -static int cut_chars ( - qse_cut_t* cut, qse_size_t start, qse_size_t end, int delim) -{ - const qse_char_t* ptr = QSE_STR_PTR(&cut->e.in.line); - qse_size_t len = QSE_STR_LEN(&cut->e.in.line); - - if (len <= 0) return 0; - - if (start <= end) - { - if (start <= len && end > 0) - { - if (start >= 1) start--; - if (end >= 1) end--; - - if (end >= len) end = len - 1; - - if (delim && write_char (cut, cut->sel.dout) <= -1) - return -1; - - if (write_str (cut, &ptr[start], end-start+1) <= -1) - return -1; - - return 1; - } - } - else - { - if (start > 0 && end <= len) - { - qse_size_t i; - - if (start >= 1) start--; - if (end >= 1) end--; - - if (start >= len) start = len - 1; - - if (delim && write_char (cut, cut->sel.dout) <= -1) - return -1; - - for (i = start; i >= end; i--) - { - if (write_char (cut, ptr[i]) <= -1) - return -1; - } - - return 1; - } - } - - return 0; -} - -static int isdelim (qse_cut_t* cut, qse_char_t c) -{ - return ((cut->option & QSE_CUT_WHITESPACE) && QSE_ISSPACE(c)) || - (!(cut->option & QSE_CUT_WHITESPACE) && c == cut->sel.din); -} - -static int split_line (qse_cut_t* cut) -{ - const qse_char_t* ptr = QSE_STR_PTR(&cut->e.in.line); - qse_size_t len = QSE_STR_LEN(&cut->e.in.line); - qse_size_t i, x = 0, xl = 0; - - cut->e.in.delimited = 0; - cut->e.in.flds[x].ptr = ptr; - for (i = 0; i < len; ) - { - qse_char_t c = ptr[i++]; - if (isdelim(cut,c)) - { - if (cut->option & QSE_CUT_FOLDDELIMS) - { - while (i < len && isdelim(cut,ptr[i])) i++; - } - - cut->e.in.flds[x++].len = xl; - - if (x >= cut->e.in.cflds) - { - qse_cstr_t* tmp; - qse_size_t nsz; - - nsz = cut->e.in.cflds; - if (nsz > 100000) nsz += 100000; - else nsz *= 2; - - tmp = QSE_MMGR_ALLOC (cut->mmgr, - QSE_SIZEOF(*tmp) * nsz); - if (tmp == QSE_NULL) - { - SETERR0 (cut, QSE_CUT_ENOMEM); - return -1; - } - - QSE_MEMCPY (tmp, cut->e.in.flds, - QSE_SIZEOF(*tmp) * cut->e.in.cflds); - - if (cut->e.in.flds != cut->e.in.sflds) - QSE_MMGR_FREE (cut->mmgr, cut->e.in.flds); - cut->e.in.flds = tmp; - cut->e.in.cflds = nsz; - } - - xl = 0; - cut->e.in.flds[x].ptr = &ptr[i]; - cut->e.in.delimited = 1; - } - else xl++; - } - cut->e.in.flds[x].len = xl; - cut->e.in.nflds = ++x; - return 0; -} - -static int cut_fields ( - qse_cut_t* cut, qse_size_t start, qse_size_t end, int delim) -{ - qse_size_t len = cut->e.in.nflds; - - if (!cut->e.in.delimited /*|| len <= 0*/) return 0; - - QSE_ASSERT (len > 0); - if (start <= end) - { - if (start <= len && end > 0) - { - qse_size_t i; - - if (start >= 1) start--; - if (end >= 1) end--; - - if (end >= len) end = len - 1; - - if (delim && write_char (cut, cut->sel.dout) <= -1) - return -1; - - for (i = start; i <= end; i++) - { - if (write_str (cut, cut->e.in.flds[i].ptr, cut->e.in.flds[i].len) <= -1) - return -1; - - if (i < end && write_char (cut, cut->sel.dout) <= -1) - return -1; - } - - return 1; - } - } - else - { - if (start > 0 && end <= len) - { - qse_size_t i; - - if (start >= 1) start--; - if (end >= 1) end--; - - if (start >= len) start = len - 1; - - if (delim && write_char (cut, cut->sel.dout) <= -1) - return -1; - - for (i = start; i >= end; i--) - { - if (write_str (cut, cut->e.in.flds[i].ptr, cut->e.in.flds[i].len) <= -1) - return -1; - - if (i > end && write_char (cut, cut->sel.dout) <= -1) - return -1; - } - - return 1; - } - } - - return 0; -} - -int qse_cut_exec (qse_cut_t* cut, qse_cut_io_fun_t inf, qse_cut_io_fun_t outf) -{ - int ret = 0; - qse_ssize_t n; - - cut->e.out.fun = outf; - cut->e.out.eof = 0; - cut->e.out.len = 0; - - cut->e.in.fun = inf; - cut->e.in.eof = 0; - cut->e.in.len = 0; - cut->e.in.pos = 0; - cut->e.in.num = 0; - - cut->errnum = QSE_CUT_ENOERR; - n = cut->e.in.fun (cut, QSE_CUT_IO_OPEN, &cut->e.in.arg, QSE_NULL, 0); - if (n <= -1) - { - ret = -1; - if (cut->errnum == QSE_CUT_ENOERR) - SETERR0 (cut, QSE_CUT_EIOUSR); - goto done3; - } - if (n == 0) - { - /* EOF reached upon opening an input stream. - * no data to process. this is success */ - goto done2; - } - - cut->errnum = QSE_CUT_ENOERR; - n = cut->e.out.fun (cut, QSE_CUT_IO_OPEN, &cut->e.out.arg, QSE_NULL, 0); - if (n <= -1) - { - ret = -1; - if (cut->errnum == QSE_CUT_ENOERR) - SETERR0 (cut, QSE_CUT_EIOUSR); - goto done2; - } - if (n == 0) - { - /* still don't know if we will write something. - * just mark EOF on the output stream and continue */ - cut->e.out.eof = 1; - } - - while (1) - { - qse_cut_sel_blk_t* b; - int id = 0; /* mark 'no output' so far */ - int delimited = 0; - int linebreak = 0; - - n = read_line (cut); - if (n <= -1) { ret = -1; goto done; } - if (n == 0) goto done; - - if (cut->sel.fcount > 0) - { - if (split_line (cut) <= -1) { ret = -1; goto done; } - delimited = cut->e.in.delimited; - } - - for (b = &cut->sel.fb; b != QSE_NULL; b = b->next) - { - qse_size_t i; - - for (i = 0; i < b->len; i++) - { - if (b->range[i].id == QSE_SED_SEL_CHAR) - { - n = cut_chars ( - cut, - b->range[i].start, - b->range[i].end, - id == 2 - ); - if (n >= 1) - { - /* mark a char's been output */ - id = 1; - } - } - else - { - n = cut_fields ( - cut, - b->range[i].start, - b->range[i].end, - id > 0 - ); - if (n >= 1) - { - /* mark a field's been output */ - id = 2; - } - } - - if (n <= -1) { ret = -1; goto done; } - } - } - - if (cut->sel.ccount > 0) - { - /* so long as there is a character selector, - * a newline must be printed */ - linebreak = 1; - } - else if (cut->sel.fcount > 0) - { - /* if only field selectors are specified */ - - if (delimited) - { - /* and if the input line is delimited, - * write a line break */ - linebreak = 1; - } - else if (!(cut->option & QSE_CUT_DELIMONLY)) - { - /* if not delimited, write the - * entire undelimited input line depending - * on the option set. */ - if (write_str (cut, - QSE_STR_PTR(&cut->e.in.line), - QSE_STR_LEN(&cut->e.in.line)) <= -1) - { - ret = -1; goto done; - } - - /* a line break is needed in this case */ - linebreak = 1; - } - } - - if (linebreak && write_linebreak(cut) <= -1) - { - ret = -1; goto done; - } - } - -done: - cut->e.out.fun (cut, QSE_CUT_IO_CLOSE, &cut->e.out.arg, QSE_NULL, 0); -done2: - cut->e.in.fun (cut, QSE_CUT_IO_CLOSE, &cut->e.in.arg, QSE_NULL, 0); -done3: - return ret; -} diff --git a/qse/lib/cut/cut.h b/qse/lib/cut/cut.h deleted file mode 100644 index 63e73ab3..00000000 --- a/qse/lib/cut/cut.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * $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 . - */ - -#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 - { - QSE_SED_SEL_CHAR = QSE_T('c'), - QSE_SED_SEL_FIELD = QSE_T('f') - } id; - qse_size_t start; - qse_size_t end; - } range[128]; - 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 - { - qse_cut_sel_blk_t fb; /**< the first block is static */ - qse_cut_sel_blk_t* lb; /**< points to the last block */ - - qse_char_t din; /**< input field delimiter */ - qse_char_t dout; /**< output field delimiter */ - - qse_size_t count; - qse_size_t fcount; - qse_size_t ccount; - } sel; - - struct - { - /** data needed for output streams */ - struct - { - qse_cut_io_fun_t fun; /**< an output handler */ - qse_cut_io_arg_t arg; /**< output handling data */ - - qse_char_t buf[2048]; - qse_size_t len; - int eof; - } out; - - /** data needed for input streams */ - struct - { - qse_cut_io_fun_t fun; /**< an input handler */ - qse_cut_io_arg_t arg; /**< input handling data */ - - qse_char_t xbuf[1]; /**< a read-ahead buffer */ - int xbuf_len; /**< data length in the buffer */ - - qse_char_t buf[2048]; /**< input buffer */ - qse_size_t len; /**< data length in the buffer */ - qse_size_t pos; /**< current position in the buffer */ - int eof; /**< EOF indicator */ - - qse_str_t line; /**< pattern space */ - qse_size_t num; /**< current line number */ - - qse_size_t nflds; /**< the number of fields */ - qse_size_t cflds; /**< capacity of flds field */ - qse_cstr_t sflds[128]; /**< static field buffer */ - qse_cstr_t* flds; - int delimited; - } in; - } e; -}; - -#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 deleted file mode 100644 index 28163760..00000000 --- a/qse/lib/cut/err.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * $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 "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("invalid parameter or data"), - QSE_T("selector not valid"), - 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/cut/std.c b/qse/lib/cut/std.c deleted file mode 100644 index 6e7639bf..00000000 --- a/qse/lib/cut/std.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * $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 "cut.h" -#include -#include -#include -#include "../cmn/mem.h" - -struct xtn_t -{ - const qse_char_t* infile; - const qse_char_t* outfile; -}; - -typedef struct xtn_t xtn_t; - -qse_cut_t* qse_cut_openstd (qse_size_t xtnsize) -{ - return qse_cut_openstdwithmmgr (QSE_MMGR_GETDFL(), xtnsize); -} - -qse_cut_t* qse_cut_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize) -{ - qse_cut_t* cut; - xtn_t* xtn; - - /* create an object */ - cut = qse_cut_open ( - QSE_MMGR_GETDFL(), QSE_SIZEOF(xtn_t) + xtnsize); - if (cut == QSE_NULL) return QSE_NULL; - - /* initialize extension */ - xtn = (xtn_t*) QSE_XTN (cut); - QSE_MEMSET (xtn, 0, QSE_SIZEOF(xtn_t)); - - return cut; -} - -void* qse_cut_getxtnstd (qse_cut_t* cut) -{ - return (void*)((xtn_t*)QSE_XTN(cut) + 1); -} - -int qse_cut_compstd (qse_cut_t* cut, const qse_char_t* sptr) -{ - return qse_cut_comp (cut, sptr, qse_strlen(sptr)); -} - -static qse_sio_t* open_sio_file (qse_cut_t* cut, const qse_char_t* file, int flags) -{ - qse_sio_t* sio; - - sio = qse_sio_open (cut->mmgr, 0, file, flags); - if (sio == QSE_NULL) - { - qse_cstr_t ea; - ea.ptr = file; - ea.len = qse_strlen (file); - qse_cut_seterrnum (cut, QSE_CUT_EIOFIL, &ea); - } - return sio; -} - -struct sio_std_name_t -{ - const qse_char_t* ptr; - qse_size_t len; -}; - -static struct sio_std_name_t sio_std_names[] = -{ - { QSE_T("stdin"), 5 }, - { QSE_T("stdout"), 6 }, - { QSE_T("stderr"), 6 } -}; - -static qse_sio_t* open_sio_std (qse_cut_t* cut, qse_sio_std_t std, int flags) -{ - qse_sio_t* sio; - - sio = qse_sio_openstd (cut->mmgr, 0, std, flags); - if (sio == QSE_NULL) - { - qse_cstr_t ea; - ea.ptr = sio_std_names[std].ptr; - ea.len = sio_std_names[std].len; - qse_cut_seterrnum (cut, QSE_CUT_EIOFIL, &ea); - } - return sio; -} - -static qse_ssize_t xin ( - qse_cut_t* cut, qse_cut_io_cmd_t cmd, qse_cut_io_arg_t* arg, - qse_char_t* buf, qse_size_t len) -{ - qse_sio_t* sio; - xtn_t* xtn = (xtn_t*) QSE_XTN (cut); - - switch (cmd) - { - case QSE_CUT_IO_OPEN: - { - /* main data stream */ - sio = xtn->infile? - open_sio_file (cut, xtn->infile, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR): - open_sio_std (cut, QSE_SIO_STDIN, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR); - if (sio == QSE_NULL) return -1; - arg->handle = sio; - return 1; - } - - case QSE_CUT_IO_CLOSE: - { - sio = (qse_sio_t*)arg->handle; - qse_sio_close (sio); - return 0; - } - - case QSE_CUT_IO_READ: - { - qse_ssize_t n = qse_sio_getstrn (arg->handle, buf, len); - - if (n <= -1) - { - qse_cstr_t ea; - if (xtn->infile) - { - ea.ptr = xtn->infile; - ea.len = qse_strlen (xtn->infile); - } - else - { - ea.ptr = sio_std_names[QSE_SIO_STDIN].ptr; - ea.len = sio_std_names[QSE_SIO_STDIN].len; - } - qse_cut_seterrnum (cut, QSE_CUT_EIOFIL, &ea); - } - - return n; - } - - default: - return -1; - } -} - -static qse_ssize_t xout ( - qse_cut_t* cut, qse_cut_io_cmd_t cmd, qse_cut_io_arg_t* arg, - qse_char_t* dat, qse_size_t len) -{ - qse_sio_t* sio; - xtn_t* xtn = (xtn_t*) QSE_XTN (cut); - - switch (cmd) - { - case QSE_CUT_IO_OPEN: - { - sio = xtn->outfile? - open_sio_file (cut, xtn->outfile, QSE_SIO_WRITE | QSE_SIO_CREATE | QSE_SIO_TRUNCATE | QSE_SIO_IGNOREMBWCERR): - open_sio_std (cut, QSE_SIO_STDOUT, QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR); - if (sio == QSE_NULL) return -1; - arg->handle = sio; - return 1; - } - - case QSE_CUT_IO_CLOSE: - { - sio = (qse_sio_t*)arg->handle; - qse_sio_flush (sio); - qse_sio_close (sio); - return 0; - } - - case QSE_CUT_IO_WRITE: - { - qse_ssize_t n = qse_sio_putstrn (arg->handle, dat, len); - - if (n <= -1) - { - qse_cstr_t ea; - if (xtn->outfile) - { - ea.ptr = xtn->outfile; - ea.len = qse_strlen (xtn->outfile); - } - else - { - ea.ptr = sio_std_names[QSE_SIO_STDOUT].ptr; - ea.len = sio_std_names[QSE_SIO_STDOUT].len; - } - qse_cut_seterrnum (cut, QSE_CUT_EIOFIL, &ea); - } - - return n; - } - - default: - return -1; - } -} - -/* TODO: refer to sed/std.c and make similar enhancements */ -/* TODO: accept cmgr */ -int qse_cut_execstd (qse_cut_t* cut, const qse_char_t* infile, const qse_char_t* outfile) -{ - xtn_t* xtn = (xtn_t*) QSE_XTN (cut); - xtn->infile = infile; - xtn->outfile = outfile; - return qse_cut_exec (cut, xin, xout); -} diff --git a/qse/lib/sed/err.c b/qse/lib/sed/err.c index 27a133e4..b01a76c8 100644 --- a/qse/lib/sed/err.c +++ b/qse/lib/sed/err.c @@ -59,6 +59,7 @@ const qse_char_t* qse_sed_dflerrstr ( QSE_T("occurrence specifier zero"), QSE_T("occurrence specifier too large"), QSE_T("no previous regular expression"), + QSE_T("cut selector not valid"), QSE_T("I/O error with file '${0}'"), QSE_T("error returned by user I/O handler") }; diff --git a/qse/lib/sed/sed.c b/qse/lib/sed/sed.c index 9a9b9248..54672733 100644 --- a/qse/lib/sed/sed.c +++ b/qse/lib/sed/sed.c @@ -55,6 +55,8 @@ do { \ qse_sed_seterror (sed, num, &__ea__, loc); \ } while (0) +static void free_all_cut_selector_blocks (qse_sed_t* sed, qse_sed_cmd_t* cmd); + qse_sed_t* qse_sed_open (qse_mmgr_t* mmgr, qse_size_t xtnsize) { qse_sed_t* sed; @@ -95,13 +97,16 @@ int qse_sed_init (qse_sed_t* sed, qse_mmgr_t* mmgr) /* init_append (sed); */ if (qse_str_init (&sed->e.txt.hold, mmgr, 256) <= -1) goto oops_6; - if (qse_str_init (&sed->e.txt.subst, mmgr, 256) <= -1) goto oops_7; + if (qse_str_init (&sed->e.txt.scratch, mmgr, 256) <= -1) goto oops_7; /* on init, the last points to the first */ sed->cmd.lb = &sed->cmd.fb; /* the block has no data yet */ sed->cmd.fb.len = 0; + /* initialize field buffers for cut */ + sed->e.cutf.cflds = QSE_COUNTOF(sed->e.cutf.sflds); + sed->e.cutf.flds = sed->e.cutf.sflds; return 0; @@ -123,7 +128,10 @@ void qse_sed_fini (qse_sed_t* sed) free_all_command_blocks (sed); free_all_cids (sed); - qse_str_fini (&sed->e.txt.subst); + if (sed->e.cutf.flds != sed->e.cutf.sflds) + QSE_MMGR_FREE (sed->mmgr, sed->e.cutf.flds); + + qse_str_fini (&sed->e.txt.scratch); qse_str_fini (&sed->e.txt.hold); free_appends (sed); @@ -569,6 +577,10 @@ static void free_command (qse_sed_t* sed, qse_sed_cmd_t* cmd) QSE_MMGR_FREE (sed->mmgr, cmd->u.transet.ptr); break; + case QSE_SED_CMD_CUT: + free_all_cut_selector_blocks (sed, cmd); + break; + default: break; } @@ -1492,6 +1504,224 @@ oops: return -1; } +static int add_cut_selector_block (qse_sed_t* sed, qse_sed_cmd_t* cmd) +{ + qse_sed_cut_sel_t* b; + + b = (qse_sed_cut_sel_t*) QSE_MMGR_ALLOC (sed->mmgr, QSE_SIZEOF(*b)); + if (b == QSE_NULL) + { + SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL); + return -1; + } + + QSE_MEMSET (b, 0, QSE_SIZEOF(*b)); + b->next = QSE_NULL; + b->len = 0; + + if (cmd->u.cut.fb == QSE_NULL) + { + cmd->u.cut.fb = b; + cmd->u.cut.lb = b; + } + else + { + cmd->u.cut.lb->next = b; + cmd->u.cut.lb = b; + } + + return 0; +} + +static void free_all_cut_selector_blocks (qse_sed_t* sed, qse_sed_cmd_t* cmd) +{ + qse_sed_cut_sel_t* b, * next; + + for (b = cmd->u.cut.fb; b; b = next) + { + next = b->next; + QSE_MMGR_FREE (sed->mmgr, b); + } + + cmd->u.cut.lb = QSE_NULL; + cmd->u.cut.fb = QSE_NULL; + + cmd->u.cut.count = 0; + cmd->u.cut.fcount = 0; + cmd->u.cut.ccount = 0; +} + +static int get_cut (qse_sed_t* sed, qse_sed_cmd_t* cmd) +{ + qse_cint_t c, delim; + qse_size_t i; + int sel = QSE_SED_CUT_SEL_CHAR; + + c = CURSC (sed); + CHECK_CMDIC (sed, cmd, c, goto oops); + + delim = c; + if (delim == QSE_T('\\')) + { + /* backspace is an illegal delimiter */ + SETERR0 (sed, QSE_SED_EBSDEL, &sed->src.loc); + goto oops; + } + + /* initialize the delimeter to a space letter */ + for (i = 0; i < QSE_COUNTOF(cmd->u.cut.delim); i++) + cmd->u.cut.delim[i] = QSE_T(' '); + + NXTSC_GOTO (sed, c, oops); + while (1) + { + qse_size_t start = 0, end = 0; + +#define MASK_START (1 << 1) +#define MASK_END (1 << 2) +#define MAX QSE_TYPE_MAX(qse_size_t) + int mask = 0; + + while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops); + if (c == QSE_CHAR_EOF) + { + SETERR0 (sed, QSE_SED_ECSLNV, &sed->src.loc); + goto oops; + } + + if (c == QSE_T('d') || c == QSE_T('D')) + { + int delim_idx = (c == QSE_T('d'))? 0: 1; + /* the next character is an input/output delimiter. */ + NXTSC_GOTO (sed, c, oops); + if (c == QSE_CHAR_EOF) + { + SETERR0 (sed, QSE_SED_ECSLNV, &sed->src.loc); + goto oops; + } + cmd->u.cut.delim[delim_idx] = c; + NXTSC_GOTO (sed, c, oops); + } + else + { + if (c == QSE_T('c') || c == QSE_T('f')) + { + sel = c; + NXTSC_GOTO (sed, c, oops); + while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops); + } + + if (QSE_ISDIGIT(c)) + { + do + { + start = start * 10 + (c - QSE_T('0')); + NXTSC_GOTO (sed, c, oops); + } + while (QSE_ISDIGIT(c)); + + while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops); + mask |= MASK_START; + + if (start >= 1) start--; /* convert it to index */ + } + else start = 0; + + if (c == QSE_T('-')) + { + NXTSC_GOTO (sed, c, oops); + while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops); + + if (QSE_ISDIGIT(c)) + { + do + { + end = end * 10 + (c - QSE_T('0')); + NXTSC_GOTO (sed, c, oops); + } + while (QSE_ISDIGIT(c)); + mask |= MASK_END; + } + else end = MAX; + + while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops); + + if (end >= 1) end--; /* convert it to index */ + } + else end = start; + + if (!(mask & (MASK_START | MASK_END))) + { + SETERR0 (sed, QSE_SED_ECSLNV, &sed->src.loc); + goto oops; + } + + if (cmd->u.cut.lb == QSE_NULL || + cmd->u.cut.lb->len >= QSE_COUNTOF(cmd->u.cut.lb->range)) + { + if (add_cut_selector_block (sed, cmd) <= -1) goto oops; + } + + cmd->u.cut.lb->range[cmd->u.cut.lb->len].id = sel; + cmd->u.cut.lb->range[cmd->u.cut.lb->len].start = start; + cmd->u.cut.lb->range[cmd->u.cut.lb->len].end = end; + cmd->u.cut.lb->len++; + + cmd->u.cut.count++; + if (sel == QSE_SED_CUT_SEL_FIELD) cmd->u.cut.fcount++; + else cmd->u.cut.ccount++; + } + + while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops); + + if (c == QSE_CHAR_EOF) + { + SETERR0 (sed, QSE_SED_ECSLNV, &sed->src.loc); + goto oops; + } + + if (c == delim) break; + + if (c != QSE_T(',')) + { + SETERR0 (sed, QSE_SED_ECSLNV, &sed->src.loc); + goto oops; + } + NXTSC_GOTO (sed, c, oops); /* skip a comma */ + } + + /* skip spaces before options */ + do { NXTSC_GOTO (sed, c, oops); } while (IS_SPACE(c)); + + /* get options */ + do + { + if (c == QSE_T('f')) + { + cmd->u.cut.f = 1; + } + else if (c == QSE_T('w')) + { + cmd->u.cut.w = 1; + } + else if (c == QSE_T('d')) + { + cmd->u.cut.d = 1; + } + else break; + + NXTSC_GOTO (sed, c, oops); + } + while (1); + + if (terminate_command (sed) <= -1) goto oops; + return 0; + +oops: + free_all_cut_selector_blocks (sed, cmd); + return -1; +} + /* process a command code and following parts into cmd */ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd) { @@ -1720,6 +1950,11 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd) if (get_transet (sed, cmd) <= -1) return -1; break; + case QSE_T('C'): + cmd->type = c; + NXTSC (sed, c, -1); + if (get_cut (sed, cmd) <= -1) return -1; + break; } return 0; @@ -2471,6 +2706,32 @@ static int emit_appends (qse_sed_t* sed) return 0; } +static const qse_char_t* trim_line (qse_sed_t* sed, qse_cstr_t* str) +{ + const qse_char_t* lineterm; + + str->ptr = QSE_STR_PTR(&sed->e.in.line); + str->len = QSE_STR_LEN(&sed->e.in.line); + + /* TODO: support different line end convension */ + if (str->len > 0 && str->ptr[str->len-1] == QSE_T('\n')) + { + str->len--; + if (str->len > 0 && str->ptr[str->len-1] == QSE_T('\r')) + { + lineterm = QSE_T("\r\n"); + str->len--; + } + else + { + lineterm = QSE_T("\n"); + } + } + else lineterm = QSE_NULL; + + return lineterm; +} + static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) { qse_cstr_t mat, pmat; @@ -2478,7 +2739,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) #if defined(USE_REX) qse_rex_errnum_t errnum; #endif - const qse_char_t* finalizer = QSE_NULL; + const qse_char_t* lineterm; qse_cstr_t str, cur; const qse_char_t* str_end; @@ -2486,28 +2747,12 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) QSE_ASSERT (cmd->type == QSE_SED_CMD_SUBSTITUTE); - qse_str_clear (&sed->e.txt.subst); + qse_str_clear (&sed->e.txt.scratch); #if defined(USE_REX) if (cmd->u.subst.i) opt = QSE_REX_IGNORECASE; #endif - str.ptr = QSE_STR_PTR(&sed->e.in.line); - str.len = QSE_STR_LEN(&sed->e.in.line); - - /* TODO: support different line end convension */ - if (str.len > 0 && str.ptr[str.len-1] == QSE_T('\n')) - { - str.len--; - if (str.len > 0 && str.ptr[str.len-1] == QSE_T('\r')) - { - finalizer = QSE_T("\r\n"); - str.len--; - } - else - { - finalizer = QSE_T("\n"); - } - } + lineterm = trim_line (sed, &str); str_end = str.ptr + str.len; cur = str; @@ -2573,7 +2818,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) { /* no more match found */ if (qse_str_ncat ( - &sed->e.txt.subst, + &sed->e.txt.scratch, cur.ptr, cur.len) == (qse_size_t)-1) { SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL); @@ -2595,7 +2840,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) if (cur.ptr < str_end) { m = qse_str_ncat ( - &sed->e.txt.subst, + &sed->e.txt.scratch, cur.ptr, mat.ptr-cur.ptr+mat.len ); if (m == (qse_size_t)-1) @@ -2612,7 +2857,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) if (cur.ptr < str_end) { m = qse_str_ncat ( - &sed->e.txt.subst, cur.ptr, mat.ptr-cur.ptr + &sed->e.txt.scratch, cur.ptr, mat.ptr-cur.ptr ); if (m == (qse_size_t)-1) { @@ -2633,7 +2878,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) { int smi = nc - QSE_T('1'); m = qse_str_ncat ( - &sed->e.txt.subst, + &sed->e.txt.scratch, submat[smi].ptr, submat[smi].len ); } @@ -2642,7 +2887,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) #endif /* the know speical characters have been escaped * in get_subst(). so i don't call trans_escaped() here */ - m = qse_str_ccat (&sed->e.txt.subst, nc); + m = qse_str_ccat (&sed->e.txt.scratch, nc); #ifndef USE_REX } #endif @@ -2652,13 +2897,13 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) else if (cmd->u.subst.rpl.ptr[i] == QSE_T('&')) { m = qse_str_ncat ( - &sed->e.txt.subst, + &sed->e.txt.scratch, mat.ptr, mat.len); } else { m = qse_str_ccat ( - &sed->e.txt.subst, + &sed->e.txt.scratch, cmd->u.subst.rpl.ptr[i]); } @@ -2682,7 +2927,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) if (cur.ptr < str_end) { /* special treament is needed if the match length is 0 */ - m = qse_str_ncat (&sed->e.txt.subst, cur.ptr, 1); + m = qse_str_ncat (&sed->e.txt.scratch, cur.ptr, 1); if (m == (qse_size_t)-1) { SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL); @@ -2694,9 +2939,9 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) } } - if (finalizer) + if (lineterm) { - m = qse_str_cat (&sed->e.txt.subst, finalizer); + m = qse_str_cat (&sed->e.txt.scratch, lineterm); if (m == (qse_size_t)-1) { SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL); @@ -2704,7 +2949,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) } } - qse_str_swap (&sed->e.in.line, &sed->e.txt.subst); + qse_str_swap (&sed->e.in.line, &sed->e.txt.scratch); if (repl) { @@ -2736,6 +2981,221 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd) return 0; } +static QSE_INLINE int isdelim (qse_sed_cmd_t* cmd, qse_char_t c) +{ + return (cmd->u.cut.w && QSE_ISSPACE(c)) || + (!cmd->u.cut.w && c == cmd->u.cut.delim[0]); +} + +static int split_into_fields_for_cut ( + qse_sed_t* sed, qse_sed_cmd_t* cmd, const qse_cstr_t* str) +{ + qse_size_t i, x = 0, xl = 0; + + sed->e.cutf.delimited = 0; + sed->e.cutf.flds[x].ptr = str->ptr; + + for (i = 0; i < str->len; ) + { + qse_char_t c = str->ptr[i++]; + + if (isdelim(cmd,c)) + { + if (cmd->u.cut.f) + { + while (i < str->len && isdelim(cmd,str->ptr[i])) i++; + } + + sed->e.cutf.flds[x++].len = xl; + + if (x >= sed->e.cutf.cflds) + { + qse_cstr_t* tmp; + qse_size_t nsz; + + nsz = sed->e.cutf.cflds; + if (nsz > 100000) nsz += 100000; + else nsz *= 2; + + if (sed->e.cutf.flds != sed->e.cutf.sflds) + { + tmp = QSE_MMGR_ALLOC (sed->mmgr, QSE_SIZEOF(*tmp) * nsz); + if (tmp == QSE_NULL) + { + SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL); + return -1; + } + + QSE_MEMCPY (tmp, sed->e.cutf.flds, QSE_SIZEOF(*tmp) * sed->e.cutf.cflds); + QSE_MMGR_FREE (sed->mmgr, sed->e.cutf.flds); + + if (sed->e.cutf.flds != sed->e.cutf.sflds) + QSE_MMGR_FREE (sed->mmgr, sed->e.cutf.flds); + } + else + { + tmp = QSE_MMGR_REALLOC (sed->mmgr, sed->e.cutf.flds, QSE_SIZEOF(*tmp) * nsz); + if (tmp == QSE_NULL) + { + SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL); + return -1; + } + } + + sed->e.cutf.flds = tmp; + sed->e.cutf.cflds = nsz; + } + + xl = 0; + sed->e.cutf.flds[x].ptr = &str->ptr[i]; + sed->e.cutf.delimited = 1; + } + else xl++; + } + + sed->e.cutf.flds[x].len = xl; + sed->e.cutf.nflds = ++x; + + return 0; +} + +static int do_cut (qse_sed_t* sed, qse_sed_cmd_t* cmd) +{ + qse_sed_cut_sel_t* b; + const qse_char_t* lineterm; + qse_cstr_t str; + int out_state; + + qse_str_clear (&sed->e.txt.scratch); + + lineterm = trim_line (sed, &str); + + if (str.len <= 0) goto done; + + if (cmd->u.cut.fcount > 0) + { + if (split_into_fields_for_cut (sed, cmd, &str) <= -1) goto oops; + + if (cmd->u.cut.d && !sed->e.cutf.delimited) + { + /* if the 'd' option is set and the line is not + * delimited by the input delimiter, delete the pattern + * space and finish the current cycle */ + qse_str_clear (&sed->e.in.line); + return 0; + } + } + + out_state = 0; + + for (b = cmd->u.cut.fb; b; b = b->next) + { + qse_size_t i, s, e; + + for (i = 0; i < b->len; i++) + { + if (b->range[i].id == QSE_SED_CUT_SEL_CHAR) + { + s = b->range[i].start; + e = b->range[i].end; + + if (s <= e) + { + if (s < str.len) + { + if (e >= str.len) e = str.len - 1; + if ((out_state == 2 && qse_str_ccat (&sed->e.txt.scratch, cmd->u.cut.delim[1]) == (qse_size_t)-1) || + qse_str_ncat (&sed->e.txt.scratch, &str.ptr[s], e - s + 1) == (qse_size_t)-1) + { + SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL); + goto oops; + } + + out_state = 1; + } + } + else + { + if (e < str.len) + { + if (s >= str.len) s = str.len - 1; + if ((out_state == 2 && qse_str_ccat (&sed->e.txt.scratch, cmd->u.cut.delim[1]) == (qse_size_t)-1) || + qse_str_nrcat (&sed->e.txt.scratch, &str.ptr[e], s - e + 1) == (qse_size_t)-1) + { + SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL); + goto oops; + } + + out_state = 1; + } + } + } + else /*if (b->range[i].id == QSE_SED_CUT_SEL_FIELD)*/ + { + s = b->range[i].start; + e = b->range[i].end; + + if (s <= e) + { + if (s < str.len) + { + if (e >= sed->e.cutf.nflds) e = sed->e.cutf.nflds - 1; + + while (s <= e) + { + if ((out_state > 0 && qse_str_ccat (&sed->e.txt.scratch, cmd->u.cut.delim[1]) == (qse_size_t)-1) || + qse_str_ncat (&sed->e.txt.scratch, sed->e.cutf.flds[s].ptr, sed->e.cutf.flds[s].len) == (qse_size_t)-1) + { + SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL); + goto oops; + } + s++; + + out_state = 2; + } + } + } + else + { + if (e < str.len) + { + if (s >= sed->e.cutf.nflds) s = sed->e.cutf.nflds - 1; + + while (e <= s) + { + if ((out_state > 0 && qse_str_ccat (&sed->e.txt.scratch, cmd->u.cut.delim[1]) == (qse_size_t)-1) || + qse_str_ncat (&sed->e.txt.scratch, sed->e.cutf.flds[e].ptr, sed->e.cutf.flds[e].len) == (qse_size_t)-1) + { + SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL); + goto oops; + } + e++; + + out_state = 2; + } + } + } + } + } + } + +done: + if (lineterm) + { + if (qse_str_cat (&sed->e.txt.scratch, lineterm) == (qse_size_t)-1) + { + SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL); + return -1; + } + } + + qse_str_swap (&sed->e.in.line, &sed->e.txt.scratch); + return 1; + +oops: + return -1; +} + static int match_a (qse_sed_t* sed, qse_sed_cmd_t* cmd, qse_sed_adr_t* a) { switch (a->type) @@ -3221,8 +3681,7 @@ static qse_sed_cmd_t* exec_cmd (qse_sed_t* sed, qse_sed_cmd_t* cmd) break; case QSE_SED_CMD_SUBSTITUTE: - n = do_subst (sed, cmd); - if (n <= -1) return QSE_NULL; + if (do_subst (sed, cmd) <= -1) return QSE_NULL; break; case QSE_SED_CMD_TRANSLATE: @@ -3259,11 +3718,15 @@ static qse_sed_cmd_t* exec_cmd (qse_sed_t* sed, qse_sed_cmd_t* cmd) } case QSE_SED_CMD_CLEAR_PATTERN: - { /* clear pattern space */ qse_str_clear (&sed->e.in.line); break; - } + + case QSE_SED_CMD_CUT: + n = do_cut (sed, cmd); + if (n <= -1) return QSE_NULL; + if (n == 0) jumpto = &sed->cmd.over; /* finish the current cycle */ + break; } if (jumpto == QSE_NULL) jumpto = cmd->state.next; @@ -3455,7 +3918,7 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_fun_t inf, qse_sed_io_fun_t outf) sed->e.subst_done = 0; free_appends (sed); - qse_str_clear (&sed->e.txt.subst); + qse_str_clear (&sed->e.txt.scratch); qse_str_clear (&sed->e.txt.hold); if (qse_str_ccat (&sed->e.txt.hold, QSE_T('\n')) == (qse_size_t)-1) { diff --git a/qse/lib/sed/sed.h b/qse/lib/sed/sed.h index 0f1c22c3..3eb7e31d 100644 --- a/qse/lib/sed/sed.h +++ b/qse/lib/sed/sed.h @@ -201,9 +201,18 @@ struct qse_sed_t struct { qse_str_t hold; /* hold space */ - qse_str_t subst; + qse_str_t scratch; } txt; + struct + { + qse_size_t nflds; /**< the number of fields */ + qse_size_t cflds; /**< capacity of flds field */ + qse_cstr_t sflds[128]; /**< static field buffer */ + qse_cstr_t* flds; + int delimited; + } cutf; + /** indicates if a successful substitution has been made * since the last read on the input stream. */ int subst_done;