fixed a bug in handling QSE_SED_QUIET for the 'n' command

This commit is contained in:
hyung-hwan 2009-09-05 07:08:19 +00:00
parent 10c75d357d
commit f14f01864d
25 changed files with 310 additions and 109 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c 273 2009-08-28 11:58:05Z hyunghwan.chung $
* $Id: awk.c 278 2009-09-04 13:08:19Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -22,7 +22,7 @@
#include <qse/cmn/mem.h>
#include <qse/cmn/chr.h>
#include <qse/cmn/opt.h>
#include <qse/cmn/misc.h>
#include <qse/cmn/stdio.h>
#include <qse/cmn/main.h>
@ -346,9 +346,10 @@ struct opttab_t
static void print_usage (QSE_FILE* out, const qse_char_t* argv0)
{
int j;
const qse_char_t* b = qse_basename (argv0);
qse_fprintf (out, QSE_T("USAGE: %s [options] -f sourcefile [ -- ] [datafile]*\n"), argv0);
qse_fprintf (out, QSE_T(" %s [options] [ -- ] sourcestring [datafile]*\n"), argv0);
qse_fprintf (out, QSE_T("USAGE: %s [options] -f sourcefile [ -- ] [datafile]*\n"), b);
qse_fprintf (out, QSE_T(" %s [options] [ -- ] sourcestring [datafile]*\n"), b);
qse_fprintf (out, QSE_T("Where options are:\n"));
qse_fprintf (out, QSE_T(" -h/--help print this message\n"));
qse_fprintf (out, QSE_T(" -d show extra information\n"));

View File

@ -17,13 +17,16 @@
*/
#include <qse/sed/sed.h>
#include <qse/cmn/stdio.h>
#include <qse/cmn/main.h>
#include <qse/cmn/str.h>
#include <qse/cmn/chr.h>
#include <qse/cmn/opt.h>
#include <qse/cmn/misc.h>
#include <qse/cmn/stdio.h>
#include <qse/cmn/main.h>
#include <stdlib.h>
static const qse_char_t* g_script = QSE_NULL;
static const qse_char_t* g_script_file = QSE_NULL;
static qse_char_t* g_script = QSE_NULL;
static const qse_char_t* g_infile = QSE_NULL;
static int g_option = 0;
@ -114,21 +117,26 @@ static qse_ssize_t out (
static void print_usage (QSE_FILE* out, int argc, qse_char_t* argv[])
{
qse_fprintf (out, QSE_T("%s [options] script [file]\n"), argv[0]);
const qse_char_t* b = qse_basename (argv[0]);
qse_fprintf (out, QSE_T("USAGE: %s [options] script [file]\n"), b);
qse_fprintf (out, QSE_T(" %s [options] -f script-file [file]\n"), b);
qse_fprintf (out, QSE_T("options as follows:\n"));
qse_fprintf (out, QSE_T(" -h show this message\n"));
qse_fprintf (out, QSE_T(" -n disable auto-print\n"));
qse_fprintf (out, QSE_T(" -a perform strict address check\n"));
qse_fprintf (out, QSE_T(" -r allows {n,m} in a regular expression\n"));
qse_fprintf (out, QSE_T(" -s allows text on the same line as c, a, i\n"));
qse_fprintf (out, QSE_T(" -l ensures a newline at text end"));
qse_fprintf (out, QSE_T(" -h show this message\n"));
qse_fprintf (out, QSE_T(" -n disable auto-print\n"));
qse_fprintf (out, QSE_T(" -a perform strict address check\n"));
qse_fprintf (out, QSE_T(" -r allow {n,m} in a regular expression\n"));
qse_fprintf (out, QSE_T(" -s allow text on the same line as c, a, i\n"));
qse_fprintf (out, QSE_T(" -l ensure a newline at text end\n"));
qse_fprintf (out, QSE_T(" -f file specifie a s script file\n"));
}
static int handle_args (int argc, qse_char_t* argv[])
{
static qse_opt_t opt =
{
QSE_T("hnarsl"),
QSE_T("hnarslf:"),
QSE_NULL
};
qse_cint_t c;
@ -180,14 +188,20 @@ static int handle_args (int argc, qse_char_t* argv[])
case QSE_T('l'):
g_option |= QSE_SED_ENSURENL;
break;
case QSE_T('f'):
g_script_file = opt.arg;
break;
}
}
if (opt.ind < argc) g_script = argv[opt.ind++];
if (opt.ind < argc && g_script_file == QSE_NULL)
g_script = argv[opt.ind++];
if (opt.ind < argc) g_infile = argv[opt.ind++];
if (g_script == QSE_NULL || opt.ind < argc)
if ((g_script_file == QSE_NULL && g_script == QSE_NULL) ||
opt.ind < argc)
{
print_usage (QSE_STDERR, argc, argv);
return -1;
@ -217,6 +231,14 @@ int sed_main (int argc, qse_char_t* argv[])
qse_sed_setoption (sed, g_option);
if (g_script_file != QSE_NULL)
{
QSE_ASSERT (g_script == QSE_NULL);
qse_fprintf (QSE_STDERR, QSE_T("-f file not implemented yet\n"));
goto oops;
/* TODO: load script from a file */
}
if (qse_sed_comp (sed, g_script, qse_strlen(g_script)) == -1)
{
const qse_sed_loc_t* errloc = qse_sed_geterrloc(sed);
@ -265,6 +287,7 @@ int sed_main (int argc, qse_char_t* argv[])
oops:
if (sed != QSE_NULL) qse_sed_close (sed);
if (g_script_file != QSE_NULL && g_script != QSE_NULL) free (g_script);
return ret;
}

View File

@ -0,0 +1,18 @@
#ifndef _QSE_CMN_MISC_H_
#define _QSE_CMN_MISC_H_
#include <qse/types.h>
#include <qse/macros.h>
#ifdef __cplusplus
extern "C" {
#endif
const qse_char_t* qse_basename (const qse_char_t* path);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -9,8 +9,8 @@ libqseawk_la_LDFLAGS = -L../cmn -version-info 1:0:0 -no-undefined
libqseawk_la_LIBADD = -lqsecmn $(LIBM)
if ENABLE_CXX
lib_LTLIBRARIES += libqseawk++.la
libqseawk___la_SOURCES = Awk.cpp StdAwk.cpp
libqseawk___la_LDFLAGS = -L. -L../cmn -version-info 1:0:0 -no-undefined
libqseawk___la_LIBADD = -lqseawk -lqsecmn $(LIBM)
lib_LTLIBRARIES += libqseawkxx.la
libqseawkxx_la_SOURCES = Awk.cpp StdAwk.cpp
libqseawkxx_la_LDFLAGS = -L. -L../cmn -version-info 1:0:0 -no-undefined
libqseawkxx_la_LIBADD = -lqseawk -lqsecmn $(LIBM)
endif

View File

@ -32,7 +32,7 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
@ENABLE_CXX_TRUE@am__append_1 = libqseawk++.la
@ENABLE_CXX_TRUE@am__append_1 = libqseawkxx.la
subdir = lib/awk
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@ -56,14 +56,6 @@ am__installdirs = "$(DESTDIR)$(libdir)"
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
@ENABLE_CXX_TRUE@libqseawk___la_DEPENDENCIES = $(am__DEPENDENCIES_1)
am__libqseawk___la_SOURCES_DIST = Awk.cpp StdAwk.cpp
@ENABLE_CXX_TRUE@am_libqseawk___la_OBJECTS = Awk.lo StdAwk.lo
libqseawk___la_OBJECTS = $(am_libqseawk___la_OBJECTS)
libqseawk___la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
$(CXXFLAGS) $(libqseawk___la_LDFLAGS) $(LDFLAGS) -o $@
@ENABLE_CXX_TRUE@am_libqseawk___la_rpath = -rpath $(libdir)
libqseawk_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
am_libqseawk_la_OBJECTS = awk.lo err.lo tree.lo parse.lo run.lo rec.lo \
val.lo fnc.lo misc.lo rio.lo std.lo
@ -71,6 +63,14 @@ libqseawk_la_OBJECTS = $(am_libqseawk_la_OBJECTS)
libqseawk_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(libqseawk_la_LDFLAGS) $(LDFLAGS) -o $@
@ENABLE_CXX_TRUE@libqseawkxx_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
am__libqseawkxx_la_SOURCES_DIST = Awk.cpp StdAwk.cpp
@ENABLE_CXX_TRUE@am_libqseawkxx_la_OBJECTS = Awk.lo StdAwk.lo
libqseawkxx_la_OBJECTS = $(am_libqseawkxx_la_OBJECTS)
libqseawkxx_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
$(CXXFLAGS) $(libqseawkxx_la_LDFLAGS) $(LDFLAGS) -o $@
@ENABLE_CXX_TRUE@am_libqseawkxx_la_rpath = -rpath $(libdir)
DEFAULT_INCLUDES =
depcomp = $(SHELL) $(top_srcdir)/ac/au/depcomp
am__depfiles_maybe = depfiles
@ -92,9 +92,9 @@ CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(libqseawk___la_SOURCES) $(libqseawk_la_SOURCES)
DIST_SOURCES = $(am__libqseawk___la_SOURCES_DIST) \
$(libqseawk_la_SOURCES)
SOURCES = $(libqseawk_la_SOURCES) $(libqseawkxx_la_SOURCES)
DIST_SOURCES = $(libqseawk_la_SOURCES) \
$(am__libqseawkxx_la_SOURCES_DIST)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -240,9 +240,9 @@ lib_LTLIBRARIES = libqseawk.la $(am__append_1)
libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c fnc.c misc.c rio.c std.c awk.h err.h rio.h val.h fnc.h misc.h parse.h run.h tree.h
libqseawk_la_LDFLAGS = -L../cmn -version-info 1:0:0 -no-undefined
libqseawk_la_LIBADD = -lqsecmn $(LIBM)
@ENABLE_CXX_TRUE@libqseawk___la_SOURCES = Awk.cpp StdAwk.cpp
@ENABLE_CXX_TRUE@libqseawk___la_LDFLAGS = -L. -L../cmn -version-info 1:0:0 -no-undefined
@ENABLE_CXX_TRUE@libqseawk___la_LIBADD = -lqseawk -lqsecmn $(LIBM)
@ENABLE_CXX_TRUE@libqseawkxx_la_SOURCES = Awk.cpp StdAwk.cpp
@ENABLE_CXX_TRUE@libqseawkxx_la_LDFLAGS = -L. -L../cmn -version-info 1:0:0 -no-undefined
@ENABLE_CXX_TRUE@libqseawkxx_la_LIBADD = -lqseawk -lqsecmn $(LIBM)
all: all-am
.SUFFIXES:
@ -303,10 +303,10 @@ clean-libLTLIBRARIES:
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libqseawk++.la: $(libqseawk___la_OBJECTS) $(libqseawk___la_DEPENDENCIES)
$(libqseawk___la_LINK) $(am_libqseawk___la_rpath) $(libqseawk___la_OBJECTS) $(libqseawk___la_LIBADD) $(LIBS)
libqseawk.la: $(libqseawk_la_OBJECTS) $(libqseawk_la_DEPENDENCIES)
$(libqseawk_la_LINK) -rpath $(libdir) $(libqseawk_la_OBJECTS) $(libqseawk_la_LIBADD) $(LIBS)
libqseawkxx.la: $(libqseawkxx_la_OBJECTS) $(libqseawkxx_la_DEPENDENCIES)
$(libqseawkxx_la_LINK) $(am_libqseawkxx_la_rpath) $(libqseawkxx_la_OBJECTS) $(libqseawkxx_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.cpp 272 2009-08-28 09:48:02Z hyunghwan.chung $
* $Id: StdAwk.cpp 278 2009-09-04 13:08:19Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -22,6 +22,7 @@
#include <qse/cmn/fio.h>
#include <qse/cmn/pio.h>
#include <qse/cmn/sio.h>
#include <qse/cmn/misc.h>
#include <qse/cmn/stdio.h>
#include "awk.h"
@ -823,7 +824,7 @@ int StdAwk::SourceFile::open (Data& io)
return -1;
}
base = qse_awk_basename ((awk_t*)io, name);
base = qse_basename (name);
if (base != name)
{
dir.ptr = name;

View File

@ -1,5 +1,5 @@
/*
* $Id: misc.c 250 2009-08-10 03:29:59Z hyunghwan.chung $
* $Id: misc.c 278 2009-09-04 13:08:19Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -999,17 +999,3 @@ void qse_awk_rtx_free (qse_awk_rtx_t* rtx, void* ptr)
qse_awk_free (rtx->awk, ptr);
}
const qse_char_t* qse_awk_basename (qse_awk_t* awk, const qse_char_t* path)
{
const qse_char_t* p, * last = QSE_NULL;
for (p = path; *p != QSE_T('\0'); p++)
{
if (*p == QSE_T('/')) last = p;
#ifdef _WIN32
else if (*p == QSE_T('\\')) last = p;
#endif
}
return (last == QSE_NULL)? path: (last + 1);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: misc.h 250 2009-08-10 03:29:59Z hyunghwan.chung $
* $Id: misc.h 278 2009-09-04 13:08:19Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -67,11 +67,6 @@ int qse_awk_matchrex (
qse_cstr_t* match, qse_awk_errnum_t* errnum
);
const qse_char_t* qse_awk_basename (
qse_awk_t* awk,
const qse_char_t* path
);
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/*
* $Id: std.c 273 2009-08-28 11:58:05Z hyunghwan.chung $
* $Id: std.c 278 2009-09-04 13:08:19Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -22,6 +22,7 @@
#include <qse/cmn/pio.h>
#include <qse/cmn/str.h>
#include <qse/cmn/time.h>
#include <qse/cmn/misc.h>
#include <qse/cmn/stdio.h> /* TODO: remove dependency on qse_vsprintf */
#include <stdarg.h>
@ -191,7 +192,7 @@ static qse_ssize_t sf_in_open (
return -1;
}
base = qse_awk_basename (awk, xtn->s.in.u.file);
base = qse_basename (xtn->s.in.u.file);
if (base != xtn->s.in.u.file)
{
xtn->s.in.dir.ptr = xtn->s.in.u.file;

View File

@ -1,5 +1,5 @@
/*
* $Id: misc.c 76 2009-02-22 14:18:06Z hyunghwan.chung $
* $Id: misc.c 278 2009-09-04 13:08:19Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -16,8 +16,19 @@
limitations under the License.
*/
#if defined(__BORLANDC__)
#pragma hdrstop
#define Library
#endif
#include <qse/cmn/misc.h>
const qse_char_t* qse_basename (const qse_char_t* path)
{
const qse_char_t* p, * last = QSE_NULL;
for (p = path; *p != QSE_T('\0'); p++)
{
if (*p == QSE_T('/')) last = p;
#ifdef _WIN32
else if (*p == QSE_T('\\')) last = p;
#endif
}
return (last == QSE_NULL)? path: (last + 1);
}

View File

@ -7,9 +7,9 @@ libqsesed_la_LDFLAGS = -version-info 1:0:0 -no-undefined -L../cmn
libqsesed_la_LIBADD = -lqsecmn
if ENABLE_CXX
lib_LTLIBRARIES += libqsesed++.la
libqsesed___la_SOURCES = Sed.cpp StdSed.cpp
libqsesed___la_LDFLAGS = -L. -L../cmn -version-info 1:0:0 -no-undefined
libqsesed___la_LIBADD = -lqsesed -lqsecmn
lib_LTLIBRARIES += libqsesedxx.la
libqsesedxx_la_SOURCES = Sed.cpp StdSed.cpp
libqsesedxx_la_LDFLAGS = -L. -L../cmn -version-info 1:0:0 -no-undefined
libqsesedxx_la_LIBADD = -lqsesed -lqsecmn
endif

View File

@ -32,7 +32,7 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
@ENABLE_CXX_TRUE@am__append_1 = libqsesed++.la
@ENABLE_CXX_TRUE@am__append_1 = libqsesedxx.la
subdir = lib/sed
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@ -55,20 +55,20 @@ am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(libdir)"
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
libqsesed___la_DEPENDENCIES =
am__libqsesed___la_SOURCES_DIST = Sed.cpp StdSed.cpp
@ENABLE_CXX_TRUE@am_libqsesed___la_OBJECTS = Sed.lo StdSed.lo
libqsesed___la_OBJECTS = $(am_libqsesed___la_OBJECTS)
libqsesed___la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
$(CXXFLAGS) $(libqsesed___la_LDFLAGS) $(LDFLAGS) -o $@
@ENABLE_CXX_TRUE@am_libqsesed___la_rpath = -rpath $(libdir)
libqsesed_la_DEPENDENCIES =
am_libqsesed_la_OBJECTS = sed.lo err.lo
libqsesed_la_OBJECTS = $(am_libqsesed_la_OBJECTS)
libqsesed_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(libqsesed_la_LDFLAGS) $(LDFLAGS) -o $@
libqsesedxx_la_DEPENDENCIES =
am__libqsesedxx_la_SOURCES_DIST = Sed.cpp StdSed.cpp
@ENABLE_CXX_TRUE@am_libqsesedxx_la_OBJECTS = Sed.lo StdSed.lo
libqsesedxx_la_OBJECTS = $(am_libqsesedxx_la_OBJECTS)
libqsesedxx_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
$(CXXFLAGS) $(libqsesedxx_la_LDFLAGS) $(LDFLAGS) -o $@
@ENABLE_CXX_TRUE@am_libqsesedxx_la_rpath = -rpath $(libdir)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include/qse
depcomp = $(SHELL) $(top_srcdir)/ac/au/depcomp
am__depfiles_maybe = depfiles
@ -90,9 +90,9 @@ CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(libqsesed___la_SOURCES) $(libqsesed_la_SOURCES)
DIST_SOURCES = $(am__libqsesed___la_SOURCES_DIST) \
$(libqsesed_la_SOURCES)
SOURCES = $(libqsesed_la_SOURCES) $(libqsesedxx_la_SOURCES)
DIST_SOURCES = $(libqsesed_la_SOURCES) \
$(am__libqsesedxx_la_SOURCES_DIST)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -237,9 +237,9 @@ lib_LTLIBRARIES = libqsesed.la $(am__append_1)
libqsesed_la_SOURCES = sed.c err.c sed.h
libqsesed_la_LDFLAGS = -version-info 1:0:0 -no-undefined -L../cmn
libqsesed_la_LIBADD = -lqsecmn
@ENABLE_CXX_TRUE@libqsesed___la_SOURCES = Sed.cpp StdSed.cpp
@ENABLE_CXX_TRUE@libqsesed___la_LDFLAGS = -L. -L../cmn -version-info 1:0:0 -no-undefined
@ENABLE_CXX_TRUE@libqsesed___la_LIBADD = -lqsesed -lqsecmn
@ENABLE_CXX_TRUE@libqsesedxx_la_SOURCES = Sed.cpp StdSed.cpp
@ENABLE_CXX_TRUE@libqsesedxx_la_LDFLAGS = -L. -L../cmn -version-info 1:0:0 -no-undefined
@ENABLE_CXX_TRUE@libqsesedxx_la_LIBADD = -lqsesed -lqsecmn
all: all-am
.SUFFIXES:
@ -300,10 +300,10 @@ clean-libLTLIBRARIES:
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libqsesed++.la: $(libqsesed___la_OBJECTS) $(libqsesed___la_DEPENDENCIES)
$(libqsesed___la_LINK) $(am_libqsesed___la_rpath) $(libqsesed___la_OBJECTS) $(libqsesed___la_LIBADD) $(LIBS)
libqsesed.la: $(libqsesed_la_OBJECTS) $(libqsesed_la_DEPENDENCIES)
$(libqsesed_la_LINK) -rpath $(libdir) $(libqsesed_la_OBJECTS) $(libqsesed_la_LIBADD) $(LIBS)
libqsesedxx.la: $(libqsesedxx_la_OBJECTS) $(libqsesedxx_la_DEPENDENCIES)
$(libqsesedxx_la_LINK) $(am_libqsesedxx_la_rpath) $(libqsesedxx_la_OBJECTS) $(libqsesedxx_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)

View File

@ -1,5 +1,5 @@
/*
* $Id: sed.c 277 2009-09-02 12:55:55Z hyunghwan.chung $
* $Id: sed.c 278 2009-09-04 13:08:19Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -2365,13 +2365,16 @@ static qse_sed_cmd_t* exec_cmd (qse_sed_t* sed, qse_sed_cmd_t* cmd)
break;
case QSE_SED_CMD_NEXT:
/* output the current pattern space */
n = write_str (
sed,
QSE_STR_PTR(&sed->e.in.line),
QSE_STR_LEN(&sed->e.in.line)
);
if (n <= -1) return QSE_NULL;
if (!(sed->option & QSE_SED_QUIET))
{
/* output the current pattern space */
n = write_str (
sed,
QSE_STR_PTR(&sed->e.in.line),
QSE_STR_LEN(&sed->e.in.line)
);
if (n <= -1) return QSE_NULL;
}
/* read the next line and fill the pattern space */
n = read_line (sed, 0);

View File

@ -0,0 +1,8 @@
{
if ($0 ~ /^-+$/) {
getline x; printf " %s\n", x; nobar=0;
}
else {
if (nobar) printf "\n"; printf "%s", $0; nobar=1;
}
}

View File

@ -0,0 +1,23 @@
ab...c
------
AAA
de...f
gh...i
------
AAA1
jk...l
mn...o
pq...r
------
AAA2
kbs
------
ddd
dif
------
cccc

View File

@ -0,0 +1,9 @@
BEGIN {
RS="\n-+\n";
first = 1;
}
{
if (!first) printf " ";
printf "%s", $0;
first = 0;
}

View File

@ -0,0 +1,23 @@
ab...c
------
AAA
de...f
gh...i
------
AAA1
jk...l
mn...o
pq...r
------
AAA2
kbs
------
ddd
dif
------
cccc

View File

@ -1931,6 +1931,66 @@ lease 10.218.255.151 {
uid "\001\000\033[\234\220\000";
}
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --newline=on -o- -f lang-036.awk lang-036.dat </dev/stdin 2>&1
--------------------------------------------------------------------------------
{
if (($0 ~ /^-+$/))
{
(getline x);
printf " %s\n",x;
nobar = 0;
}
else
{
if (nobar)
printf "\n";
printf "%s",$0;
nobar = 1;
}
}
ab...c AAA
de...f
gh...i AAA1
jk...l
mn...o
pq...r AAA2
kbs ddd
dif cccc
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --newline=on -o- -f lang-037.awk lang-037.dat </dev/stdin 2>&1
--------------------------------------------------------------------------------
BEGIN {
RS = "\n-+\n";
first = 1;
}
{
if ((!(first)))
printf " ";
printf "%s",$0;
first = 0;
}
ab...c AAA
de...f
gh...i AAA1
jk...l
mn...o
pq...r AAA2
kbs ddd
dif cccc
--------------------------------------------------------------------------------
../../cmd/awk/qseawk -f quicksort.awk quicksort.dat </dev/stdin 2>&1
--------------------------------------------------------------------------------
0.0000000000

View File

@ -138,6 +138,8 @@ PROGS="
lang-033.awk///--newline=on -o-
lang-034.awk///--newline=on --rwpipe=on -o-
lang-035.awk/lang-035.dat2//--newline=on -o- -vdatafile=lang-035.dat1 -vgroupname=lang-035
lang-036.awk/lang-036.dat//--newline=on -o-
lang-037.awk/lang-037.dat//--newline=on -o-
quicksort.awk/quicksort.dat//
quicksort2.awk/quicksort2.dat//

23
qse/regress/sed/001.dat Normal file
View File

@ -0,0 +1,23 @@
ab...c
------
AAA
de...f
gh...i
------
AAA1
jk...l
mn...o
pq...r
------
AAA2
kbs
------
ddd
dif
------
cccc

14
qse/regress/sed/001.sed Normal file
View File

@ -0,0 +1,14 @@
# require -n
h
:again n
/^-+$/ {
g
N
s/\n/ /
p
b skip
}
x
p
b again
:skip

View File

@ -18,8 +18,8 @@ awk06_SOURCES = awk06.cpp
awk07_SOURCES = awk07.cpp
awk08_SOURCES = awk08.cpp
awk05_LDADD = -lqseawk++ $(LDADD)
awk06_LDADD = -lqseawk++ $(LDADD)
awk07_LDADD = -lqseawk++ $(LDADD)
awk08_LDADD = -lqseawk++ $(LDADD)
awk05_LDADD = -lqseawkxx $(LDADD)
awk06_LDADD = -lqseawkxx $(LDADD)
awk07_LDADD = -lqseawkxx $(LDADD)
awk08_LDADD = -lqseawkxx $(LDADD)
endif

View File

@ -264,10 +264,10 @@ awk04_SOURCES = awk04.c
@ENABLE_CXX_TRUE@awk06_SOURCES = awk06.cpp
@ENABLE_CXX_TRUE@awk07_SOURCES = awk07.cpp
@ENABLE_CXX_TRUE@awk08_SOURCES = awk08.cpp
@ENABLE_CXX_TRUE@awk05_LDADD = -lqseawk++ $(LDADD)
@ENABLE_CXX_TRUE@awk06_LDADD = -lqseawk++ $(LDADD)
@ENABLE_CXX_TRUE@awk07_LDADD = -lqseawk++ $(LDADD)
@ENABLE_CXX_TRUE@awk08_LDADD = -lqseawk++ $(LDADD)
@ENABLE_CXX_TRUE@awk05_LDADD = -lqseawkxx $(LDADD)
@ENABLE_CXX_TRUE@awk06_LDADD = -lqseawkxx $(LDADD)
@ENABLE_CXX_TRUE@awk07_LDADD = -lqseawkxx $(LDADD)
@ENABLE_CXX_TRUE@awk08_LDADD = -lqseawkxx $(LDADD)
all: all-am
.SUFFIXES:

View File

@ -9,8 +9,8 @@ if ENABLE_CXX
bin_PROGRAMS += sed02 sed03
sed02_SOURCES = sed02.cpp
sed02_LDADD = -lqsesed++ $(LDADD)
sed02_LDADD = -lqsesedxx $(LDADD)
sed03_SOURCES = sed03.cpp
sed03_LDADD = -lqsesed++ $(LDADD)
sed03_LDADD = -lqsesedxx $(LDADD)
endif

View File

@ -217,9 +217,9 @@ top_srcdir = @top_srcdir@
AM_CPPFLAGS = -I$(top_srcdir)/include
LDADD = -lqsesed -lqsecmn $(LIBM)
@ENABLE_CXX_TRUE@sed02_SOURCES = sed02.cpp
@ENABLE_CXX_TRUE@sed02_LDADD = -lqsesed++ $(LDADD)
@ENABLE_CXX_TRUE@sed02_LDADD = -lqsesedxx $(LDADD)
@ENABLE_CXX_TRUE@sed03_SOURCES = sed03.cpp
@ENABLE_CXX_TRUE@sed03_LDADD = -lqsesed++ $(LDADD)
@ENABLE_CXX_TRUE@sed03_LDADD = -lqsesedxx $(LDADD)
all: all-am
.SUFFIXES: