interim commit
This commit is contained in:
parent
9eb2c2da4c
commit
876cd7bec9
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.hpp 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||
* $Id: Awk.hpp 251 2009-08-10 07:11:16Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -880,6 +880,16 @@ public:
|
||||
*/
|
||||
OPT_NCMPONSTR = QSE_AWK_NCMPONSTR,
|
||||
|
||||
/**
|
||||
* Enables the strict naming rule.
|
||||
* - a parameter name can not be the same as the owning
|
||||
* function name.
|
||||
* - a local variable name can not be the same as the
|
||||
* owning function name.
|
||||
*/
|
||||
|
||||
OPT_STRICTNAMING = QSE_AWK_STRICTNAMING,
|
||||
|
||||
/** Enables 'include' */
|
||||
OPT_INCLUDE = QSE_AWK_INCLUDE
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||
* $Id: awk.h 251 2009-08-10 07:11:16Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -600,8 +600,9 @@ enum qse_awk_option_t
|
||||
|
||||
/**
|
||||
* enables the strict naming rule.
|
||||
* - a parameter can not be the same as the owning function name.
|
||||
* - a local variable can not be the same as the owning function name.
|
||||
* - a parameter name can not be the same as the owning function name.
|
||||
* - a local variable name can not be the same as the owning
|
||||
* function name.
|
||||
*/
|
||||
QSE_AWK_STRICTNAMING = (1 << 15),
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: StdAwk.cpp 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||
* $Id: StdAwk.cpp 251 2009-08-10 07:11:16Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -778,7 +778,7 @@ int StdAwk::vsprintf (
|
||||
int StdAwk::SourceFile::open (Data& io)
|
||||
{
|
||||
qse_sio_t* sio;
|
||||
const qse_char_t* ioname = io.getName();
|
||||
const char_t* ioname = io.getName();
|
||||
|
||||
if (ioname == QSE_NULL)
|
||||
{
|
||||
|
@ -11,15 +11,15 @@ awk03_SOURCES = awk03.c
|
||||
awk04_SOURCES = awk04.c
|
||||
|
||||
if ENABLE_CXX
|
||||
bin_PROGRAMS += awk05 awk06 awk07 #awk08
|
||||
bin_PROGRAMS += awk05 awk06 awk07 awk08
|
||||
|
||||
awk05_SOURCES = awk05.cpp
|
||||
awk06_SOURCES = awk06.cpp
|
||||
awk07_SOURCES = awk07.cpp
|
||||
#awk08_SOURCES = awk08.cpp
|
||||
awk08_SOURCES = awk08.cpp
|
||||
|
||||
awk05_LDADD = -lqseawk++ $(LDADD)
|
||||
awk06_LDADD = -lqseawk++ $(LDADD)
|
||||
awk07_LDADD = -lqseawk++ $(LDADD)
|
||||
#awk08_LDADD = -lqseawk++ $(LDADD)
|
||||
awk08_LDADD = -lqseawk++ $(LDADD)
|
||||
endif
|
||||
|
@ -34,7 +34,7 @@ build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
bin_PROGRAMS = awk01$(EXEEXT) awk02$(EXEEXT) awk03$(EXEEXT) \
|
||||
awk04$(EXEEXT) $(am__EXEEXT_1)
|
||||
@ENABLE_CXX_TRUE@am__append_1 = awk05 awk06 awk07 #awk08
|
||||
@ENABLE_CXX_TRUE@am__append_1 = awk05 awk06 awk07 awk08
|
||||
subdir = samples/awk
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
@ -49,7 +49,7 @@ mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/include/qse/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
@ENABLE_CXX_TRUE@am__EXEEXT_1 = awk05$(EXEEXT) awk06$(EXEEXT) \
|
||||
@ENABLE_CXX_TRUE@ awk07$(EXEEXT)
|
||||
@ENABLE_CXX_TRUE@ awk07$(EXEEXT) awk08$(EXEEXT)
|
||||
am__installdirs = "$(DESTDIR)$(bindir)"
|
||||
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
|
||||
PROGRAMS = $(bin_PROGRAMS)
|
||||
@ -83,6 +83,10 @@ am__awk07_SOURCES_DIST = awk07.cpp
|
||||
@ENABLE_CXX_TRUE@am_awk07_OBJECTS = awk07.$(OBJEXT)
|
||||
awk07_OBJECTS = $(am_awk07_OBJECTS)
|
||||
@ENABLE_CXX_TRUE@awk07_DEPENDENCIES = $(am__DEPENDENCIES_2)
|
||||
am__awk08_SOURCES_DIST = awk08.cpp
|
||||
@ENABLE_CXX_TRUE@am_awk08_OBJECTS = awk08.$(OBJEXT)
|
||||
awk08_OBJECTS = $(am_awk08_OBJECTS)
|
||||
@ENABLE_CXX_TRUE@awk08_DEPENDENCIES = $(am__DEPENDENCIES_2)
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include/qse
|
||||
depcomp = $(SHELL) $(top_srcdir)/ac/au/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
@ -106,10 +110,11 @@ CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) \
|
||||
$(awk04_SOURCES) $(awk05_SOURCES) $(awk06_SOURCES) \
|
||||
$(awk07_SOURCES)
|
||||
$(awk07_SOURCES) $(awk08_SOURCES)
|
||||
DIST_SOURCES = $(awk01_SOURCES) $(awk02_SOURCES) $(awk03_SOURCES) \
|
||||
$(awk04_SOURCES) $(am__awk05_SOURCES_DIST) \
|
||||
$(am__awk06_SOURCES_DIST) $(am__awk07_SOURCES_DIST)
|
||||
$(am__awk06_SOURCES_DIST) $(am__awk07_SOURCES_DIST) \
|
||||
$(am__awk08_SOURCES_DIST)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
@ -258,10 +263,11 @@ awk04_SOURCES = awk04.c
|
||||
@ENABLE_CXX_TRUE@awk05_SOURCES = awk05.cpp
|
||||
@ENABLE_CXX_TRUE@awk06_SOURCES = awk06.cpp
|
||||
@ENABLE_CXX_TRUE@awk07_SOURCES = awk07.cpp
|
||||
#awk08_SOURCES = awk08.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)
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
@ -344,6 +350,9 @@ awk06$(EXEEXT): $(awk06_OBJECTS) $(awk06_DEPENDENCIES)
|
||||
awk07$(EXEEXT): $(awk07_OBJECTS) $(awk07_DEPENDENCIES)
|
||||
@rm -f awk07$(EXEEXT)
|
||||
$(CXXLINK) $(awk07_OBJECTS) $(awk07_LDADD) $(LIBS)
|
||||
awk08$(EXEEXT): $(awk08_OBJECTS) $(awk08_DEPENDENCIES)
|
||||
@rm -f awk08$(EXEEXT)
|
||||
$(CXXLINK) $(awk08_OBJECTS) $(awk08_LDADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
@ -358,6 +367,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk05.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk06.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk07.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk08.Po@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@ -585,7 +595,6 @@ uninstall-am: uninstall-binPROGRAMS
|
||||
pdf pdf-am ps ps-am tags uninstall uninstall-am \
|
||||
uninstall-binPROGRAMS
|
||||
|
||||
#awk08_LDADD = -lqseawk++ $(LDADD)
|
||||
# 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:
|
||||
|
@ -115,7 +115,7 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
int sleep (Run& run, Return& ret, const Argument* args, size_t nargs,
|
||||
int sleep (Run& run, Value& ret, const Value* args, size_t nargs,
|
||||
const char_t* name, size_t len)
|
||||
{
|
||||
if (args[0].isIndexed())
|
||||
@ -126,7 +126,7 @@ public:
|
||||
|
||||
long_t x = args[0].toInt();
|
||||
|
||||
/*Argument arg;
|
||||
/*Value arg;
|
||||
if (run.getGlobal(idLastSleep, arg) == 0)
|
||||
qse_printf (QSE_T("GOOD: [%d]\n"), (int)arg.toInt());
|
||||
else { qse_printf (QSE_T("BAD:\n")); }
|
||||
@ -136,56 +136,54 @@ public:
|
||||
|
||||
#ifdef _WIN32
|
||||
::Sleep ((DWORD)(x * 1000));
|
||||
return ret.set ((long_t)0);
|
||||
return ret.setInt (0);
|
||||
#else
|
||||
return ret.set ((long_t)::sleep (x));
|
||||
return ret.setInt (::sleep (x));
|
||||
#endif
|
||||
}
|
||||
|
||||
int sumintarray (Run& run, Return& ret, const Argument* args, size_t nargs,
|
||||
int sumintarray (Run& run, Value& ret, const Value* args, size_t nargs,
|
||||
const char_t* name, size_t len)
|
||||
{
|
||||
long_t x = 0;
|
||||
|
||||
if (args[0].isIndexed())
|
||||
{
|
||||
Argument idx(run), val(run);
|
||||
Value val(run);
|
||||
Value::Index idx;
|
||||
Value::IndexIterator ii;
|
||||
|
||||
int n = args[0].getFirstIndex (idx);
|
||||
while (n > 0)
|
||||
ii = args[0].getFirstIndex (&idx);
|
||||
while (ii != ii.END)
|
||||
{
|
||||
size_t len;
|
||||
const char_t* ptr = idx.toStr(&len);
|
||||
|
||||
if (args[0].getIndexed(ptr, len, val) <= -1) return -1;
|
||||
if (args[0].getIndexed(idx, &val) <= -1) return -1;
|
||||
x += val.toInt ();
|
||||
|
||||
n = args[0].getNextIndex (idx);
|
||||
ii = args[0].getNextIndex (&idx, ii);
|
||||
}
|
||||
if (n != 0) return -1;
|
||||
}
|
||||
else x += args[0].toInt();
|
||||
|
||||
return ret.set (x);
|
||||
return ret.setInt (x);
|
||||
}
|
||||
|
||||
int arrayindices (Run& run, Return& ret, const Argument* args, size_t nargs,
|
||||
int arrayindices (Run& run, Value& ret, const Value* args, size_t nargs,
|
||||
const char_t* name, size_t len)
|
||||
{
|
||||
if (!args[0].isIndexed()) return 0;
|
||||
|
||||
Argument idx (run);
|
||||
Value::Index idx;
|
||||
Value::IndexIterator ii;
|
||||
long_t i;
|
||||
|
||||
int n = args[0].getFirstIndex (idx);
|
||||
for (i = 0; n > 0; i++)
|
||||
ii = args[0].getFirstIndex (&idx);
|
||||
for (i = 0; ii != ii.END ; i++)
|
||||
{
|
||||
size_t len;
|
||||
const char_t* ptr = idx.toStr(&len);
|
||||
n = args[0].getNextIndex (idx);
|
||||
if (ret.setIndexed (i, ptr, len) <= -1) return -1;
|
||||
Value::IntIndex iidx (i);
|
||||
if (ret.setIndexedStr (
|
||||
iidx, idx.ptr, idx.len) <= -1) return -1;
|
||||
ii = args[0].getNextIndex (&idx, ii);
|
||||
}
|
||||
if (n != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -205,7 +203,7 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
void onLoopExit (Run& run, const Argument& ret)
|
||||
void onLoopExit (Run& run, const Value& ret)
|
||||
{
|
||||
unset_intr_run ();
|
||||
|
||||
@ -417,26 +415,32 @@ static void print_error (const qse_char_t* msg)
|
||||
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"), msg);
|
||||
}
|
||||
|
||||
static struct
|
||||
|
||||
struct opttab_t
|
||||
{
|
||||
const qse_char_t* name;
|
||||
MyAwk::Option opt;
|
||||
} otab[] =
|
||||
int opt;
|
||||
const qse_char_t* desc;
|
||||
} opttab[] =
|
||||
{
|
||||
{ QSE_T("implicit"), MyAwk::OPT_IMPLICIT },
|
||||
{ QSE_T("explicit"), MyAwk::OPT_EXPLICIT },
|
||||
{ QSE_T("bxor"), MyAwk::OPT_BXOR },
|
||||
{ QSE_T("shift"), MyAwk::OPT_SHIFT },
|
||||
{ QSE_T("idiv"), MyAwk::OPT_IDIV },
|
||||
{ QSE_T("rio"), MyAwk::OPT_RIO },
|
||||
{ QSE_T("rwpipe"), MyAwk::OPT_RWPIPE },
|
||||
{ QSE_T("newline"), MyAwk::OPT_NEWLINE },
|
||||
{ QSE_T("stripspaces"), MyAwk::OPT_STRIPSPACES },
|
||||
{ QSE_T("nextofile"), MyAwk::OPT_NEXTOFILE },
|
||||
{ QSE_T("crlf"), MyAwk::OPT_CRLF },
|
||||
{ QSE_T("reset"), MyAwk::OPT_RESET },
|
||||
{ QSE_T("maptovar"), MyAwk::OPT_MAPTOVAR },
|
||||
{ QSE_T("pablock"), MyAwk::OPT_PABLOCK }
|
||||
{ QSE_T("implicit"), MyAwk::OPT_IMPLICIT, QSE_T("allow undeclared variables") },
|
||||
{ QSE_T("explicit"), MyAwk::OPT_EXPLICIT, QSE_T("allow declared variables(local,global)") },
|
||||
{ QSE_T("extraops"), MyAwk::OPT_EXTRAOPS, QSE_T("enable extra operators(<<,>>,^^,//)") },
|
||||
{ QSE_T("rio"), MyAwk::OPT_RIO, QSE_T("enable builtin I/O including getline & print") },
|
||||
{ QSE_T("rwpipe"), MyAwk::OPT_RWPIPE, QSE_T("allow a dual-directional pipe") },
|
||||
{ QSE_T("newline"), MyAwk::OPT_NEWLINE, QSE_T("enable a newline to terminate a statement") },
|
||||
{ QSE_T("striprecspc"), MyAwk::OPT_STRIPRECSPC, QSE_T("strip spaces in splitting a record") },
|
||||
{ QSE_T("stripstrspc"), MyAwk::OPT_STRIPSTRSPC, QSE_T("strip spaces in converting a string to a number") },
|
||||
{ QSE_T("nextofile"), MyAwk::OPT_NEXTOFILE, QSE_T("enable 'nextofile'") },
|
||||
{ QSE_T("reset"), MyAwk::OPT_RESET, QSE_T("enable 'reset'") },
|
||||
{ QSE_T("crlf"), MyAwk::OPT_CRLF, QSE_T("use CRLF for a newline") },
|
||||
{ QSE_T("maptovar"), MyAwk::OPT_MAPTOVAR, QSE_T("allow a map to be assigned or returned") },
|
||||
{ QSE_T("pablock"), MyAwk::OPT_PABLOCK, QSE_T("enable pattern-action loop") },
|
||||
{ QSE_T("rexbound"), MyAwk::OPT_REXBOUND, QSE_T("enable {n,m} in a regular expression") },
|
||||
{ QSE_T("ncmponstr"), MyAwk::OPT_NCMPONSTR, QSE_T("perform numeric comparsion on numeric strings") },
|
||||
{ QSE_T("strictnaming"), MyAwk::OPT_STRICTNAMING, QSE_T("enable the strict naming rule") },
|
||||
{ QSE_T("include"), MyAwk::OPT_INCLUDE, QSE_T("enable 'include'") },
|
||||
{ QSE_NULL, 0 }
|
||||
};
|
||||
|
||||
static void print_usage (const qse_char_t* argv0)
|
||||
@ -462,9 +466,9 @@ static void print_usage (const qse_char_t* argv0)
|
||||
|
||||
|
||||
qse_printf (QSE_T("\nYou may specify the following options to change the behavior of the interpreter.\n"));
|
||||
for (j = 0; j < (int)QSE_COUNTOF(otab); j++)
|
||||
for (j = 0; j < (int)QSE_COUNTOF(opttab); j++)
|
||||
{
|
||||
qse_printf (QSE_T(" -%-20s -no%-20s\n"), otab[j].name, otab[j].name);
|
||||
qse_printf (QSE_T(" -%-20s -no%-20s\n"), opttab[j].name, opttab[j].name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -514,22 +518,22 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
|
||||
if (argv[i][1] == QSE_T('n') && argv[i][2] == QSE_T('o'))
|
||||
{
|
||||
for (j = 0; j < (int)QSE_COUNTOF(otab); j++)
|
||||
for (j = 0; j < (int)QSE_COUNTOF(opttab); j++)
|
||||
{
|
||||
if (qse_strcmp(&argv[i][3], otab[j].name) == 0)
|
||||
if (qse_strcmp(&argv[i][3], opttab[j].name) == 0)
|
||||
{
|
||||
awk.setOption (awk.getOption() & ~otab[j].opt);
|
||||
awk.setOption (awk.getOption() & ~opttab[j].opt);
|
||||
goto ok_valid;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; j < (int)QSE_COUNTOF(otab); j++)
|
||||
for (j = 0; j < (int)QSE_COUNTOF(opttab); j++)
|
||||
{
|
||||
if (qse_strcmp(&argv[i][1], otab[j].name) == 0)
|
||||
if (qse_strcmp(&argv[i][1], opttab[j].name) == 0)
|
||||
{
|
||||
awk.setOption (awk.getOption() | otab[j].opt);
|
||||
awk.setOption (awk.getOption() | opttab[j].opt);
|
||||
goto ok_valid;
|
||||
}
|
||||
}
|
||||
@ -646,7 +650,7 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
}
|
||||
|
||||
#if 0
|
||||
MyAwk::Return args[2];
|
||||
MyAwk::Value args[2];
|
||||
|
||||
args[0].setRun (run);
|
||||
args[1].setRun (run);
|
||||
|
Loading…
Reference in New Issue
Block a user