touched up code

This commit is contained in:
2009-08-18 06:10:30 +00:00
parent 267a602d4b
commit 0f9d553ff8
35 changed files with 807 additions and 391 deletions

View File

@ -1,12 +1,10 @@
AM_CPPFLAGS = -I$(top_srcdir)/include
bin_PROGRAMS = sed01
bin_PROGRAMS =
LDFLAGS = -L../../lib/cmn -L../../lib/sed
LDADD = -lqsesed -lqsecmn $(LIBM)
sed01_SOURCES = sed01.c
if ENABLE_CXX
bin_PROGRAMS += sed02 sed03

View File

@ -32,7 +32,7 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = sed01$(EXEEXT) $(am__EXEEXT_1)
bin_PROGRAMS = $(am__EXEEXT_1)
@ENABLE_CXX_TRUE@am__append_1 = sed02 sed03
subdir = samples/sed
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
@ -51,14 +51,10 @@ CONFIG_CLEAN_FILES =
am__installdirs = "$(DESTDIR)$(bindir)"
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
am_sed01_OBJECTS = sed01.$(OBJEXT)
sed01_OBJECTS = $(am_sed01_OBJECTS)
sed01_LDADD = $(LDADD)
am__DEPENDENCIES_1 =
sed01_DEPENDENCIES = $(am__DEPENDENCIES_1)
am__sed02_SOURCES_DIST = sed02.cpp
@ENABLE_CXX_TRUE@am_sed02_OBJECTS = sed02.$(OBJEXT)
sed02_OBJECTS = $(am_sed02_OBJECTS)
am__DEPENDENCIES_1 =
am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
@ENABLE_CXX_TRUE@sed02_DEPENDENCIES = $(am__DEPENDENCIES_2)
am__sed03_SOURCES_DIST = sed03.cpp
@ -68,15 +64,6 @@ sed03_OBJECTS = $(am_sed03_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include/qse
depcomp = $(SHELL) $(top_srcdir)/ac/au/depcomp
am__depfiles_maybe = depfiles
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
@ -86,9 +73,8 @@ CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(sed01_SOURCES) $(sed02_SOURCES) $(sed03_SOURCES)
DIST_SOURCES = $(sed01_SOURCES) $(am__sed02_SOURCES_DIST) \
$(am__sed03_SOURCES_DIST)
SOURCES = $(sed02_SOURCES) $(sed03_SOURCES)
DIST_SOURCES = $(am__sed02_SOURCES_DIST) $(am__sed03_SOURCES_DIST)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -230,7 +216,6 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
AM_CPPFLAGS = -I$(top_srcdir)/include
LDADD = -lqsesed -lqsecmn $(LIBM)
sed01_SOURCES = sed01.c
@ENABLE_CXX_TRUE@sed02_SOURCES = sed02.cpp
@ENABLE_CXX_TRUE@sed02_LDADD = -lqsesed++ $(LDADD)
@ENABLE_CXX_TRUE@sed03_SOURCES = sed03.cpp
@ -238,7 +223,7 @@ sed01_SOURCES = sed01.c
all: all-am
.SUFFIXES:
.SUFFIXES: .c .cpp .lo .o .obj
.SUFFIXES: .cpp .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
@ -296,9 +281,6 @@ clean-binPROGRAMS:
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
sed01$(EXEEXT): $(sed01_OBJECTS) $(sed01_DEPENDENCIES)
@rm -f sed01$(EXEEXT)
$(LINK) $(sed01_OBJECTS) $(sed01_LDADD) $(LIBS)
sed02$(EXEEXT): $(sed02_OBJECTS) $(sed02_DEPENDENCIES)
@rm -f sed02$(EXEEXT)
$(CXXLINK) $(sed02_OBJECTS) $(sed02_LDADD) $(LIBS)
@ -312,31 +294,9 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sed01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sed02.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sed03.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po

View File

@ -1,262 +0,0 @@
/**
* $Id$
*
Copyright 2006-2009 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#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>
static const qse_char_t* g_script = QSE_NULL;
static const qse_char_t* g_infile = QSE_NULL;
static int g_option = 0;
static qse_ssize_t in (
qse_sed_t* sed, qse_sed_io_cmd_t cmd, qse_sed_io_arg_t* arg)
{
switch (cmd)
{
case QSE_SED_IO_OPEN:
if (arg->path == QSE_NULL ||
arg->path[0] == QSE_T('\0'))
{
if (g_infile)
{
arg->handle = qse_fopen (g_infile, QSE_T("r"));
if (arg->handle == QSE_NULL)
{
qse_cstr_t errarg;
errarg.ptr = g_infile;
errarg.len = qse_strlen(g_infile);
qse_sed_seterror (sed, QSE_SED_EIOFIL, 0, &errarg);
return -1;
}
}
else arg->handle = QSE_STDIN;
}
else
{
arg->handle = qse_fopen (arg->path, QSE_T("r"));
if (arg->handle == QSE_NULL) return -1;
}
return 1;
case QSE_SED_IO_CLOSE:
if (arg->handle != QSE_STDIN)
qse_fclose (arg->handle);
return 0;
case QSE_SED_IO_READ:
{
qse_cint_t c;
c = qse_fgetc (arg->handle);
if (c == QSE_CHAR_EOF) return 0;
arg->u.r.buf[0] = c;
return 1;
}
default:
return -1;
}
}
static qse_ssize_t out (
qse_sed_t* sed, qse_sed_io_cmd_t cmd, qse_sed_io_arg_t* arg)
{
switch (cmd)
{
case QSE_SED_IO_OPEN:
if (arg->path == QSE_NULL ||
arg->path[0] == QSE_T('\0'))
{
arg->handle = QSE_STDOUT;
}
else
{
arg->handle = qse_fopen (arg->path, QSE_T("w"));
if (arg->handle == QSE_NULL) return -1;
}
return 1;
case QSE_SED_IO_CLOSE:
if (arg->handle != QSE_STDOUT)
qse_fclose (arg->handle);
return 0;
case QSE_SED_IO_WRITE:
{
qse_size_t i = 0;
for (i = 0; i < arg->u.w.len; i++)
qse_fputc (arg->u.w.data[i], arg->handle);
return arg->u.w.len;
}
default:
return -1;
}
}
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]);
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"));
}
static int handle_args (int argc, qse_char_t* argv[])
{
static qse_opt_t opt =
{
QSE_T("hnar"),
QSE_NULL
};
qse_cint_t c;
while ((c = qse_getopt (argc, argv, &opt)) != QSE_CHAR_EOF)
{
switch (c)
{
default:
print_usage (QSE_STDERR, argc, argv);
return -1;
case QSE_T('?'):
qse_fprintf (QSE_STDERR,
QSE_T("ERROR: bad option - %c\n"),
opt.opt
);
print_usage (QSE_STDERR, argc, argv);
return -1;
case QSE_T(':'):
qse_fprintf (QSE_STDERR,
QSE_T("ERROR: bad parameter for %c\n"),
opt.opt
);
print_usage (QSE_STDERR, argc, argv);
return -1;
case QSE_T('h'):
print_usage (QSE_STDOUT, argc, argv);
return 0;
case QSE_T('n'):
g_option |= QSE_SED_QUIET;
break;
case QSE_T('a'):
g_option |= QSE_SED_STRICT;
break;
case QSE_T('r'):
g_option |= QSE_SED_REXBOUND;
break;
}
}
if (opt.ind < argc) g_script = argv[opt.ind++];
if (opt.ind < argc) g_infile = argv[opt.ind++];
if (g_script == QSE_NULL || opt.ind < argc)
{
print_usage (QSE_STDERR, argc, argv);
return -1;
}
return 1;
}
int sed_main (int argc, qse_char_t* argv[])
{
qse_sed_t* sed = QSE_NULL;
int ret = -1;
ret = handle_args (argc, argv);
if (ret <= -1) return -1;
if (ret == 0) return 0;
ret = -1;
sed = qse_sed_open (QSE_NULL, 0);
if (sed == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("cannot open a stream editor\n"));
goto oops;
}
qse_sed_setoption (sed, g_option);
if (qse_sed_comp (sed, g_script, qse_strlen(g_script)) == -1)
{
qse_size_t errlin = qse_sed_geterrlin(sed);
if (errlin > 0)
{
qse_fprintf (QSE_STDERR,
QSE_T("cannot compile - %s at line %lu\n"),
qse_sed_geterrmsg(sed),
(unsigned long)errlin
);
}
else
{
qse_fprintf (QSE_STDERR,
QSE_T("cannot compile - %s\n"),
qse_sed_geterrmsg(sed)
);
}
goto oops;
}
if (qse_sed_exec (sed, in, out) == -1)
{
qse_size_t errlin = qse_sed_geterrlin(sed);
if (errlin > 0)
{
qse_fprintf (QSE_STDERR,
QSE_T("cannot execute - %s at line %lu\n"),
qse_sed_geterrmsg(sed),
(unsigned long)errlin
);
}
else
{
qse_fprintf (QSE_STDERR,
QSE_T("cannot execute - %s\n"),
qse_sed_geterrmsg(sed)
);
}
goto oops;
}
ret = 0;
oops:
if (sed != QSE_NULL) qse_sed_close (sed);
return ret;
}
int qse_main (int argc, char* argv[])
{
return qse_runmain (argc, argv, sed_main);
}