diff --git a/ase/cmd/awk/awk.c b/ase/cmd/awk/awk.c index 4c6f6499..2933506c 100644 --- a/ase/cmd/awk/awk.c +++ b/ase/cmd/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c 464 2008-12-09 08:50:16Z baconevi $ + * $Id: awk.c 468 2008-12-10 10:19:59Z baconevi $ */ #include @@ -63,15 +63,7 @@ typedef struct runio_data_t ase_size_t icf_no; } runio_data_t; -static void local_dprintf (const ase_char_t* fmt, ...) -{ - va_list ap; - va_start (ap, fmt); - ase_vfprintf (stderr, fmt, ap); - va_end (ap); -} - -static void custom_awk_dprintf (void* custom, const ase_char_t* fmt, ...) +static void dprint (const ase_char_t* fmt, ...) { va_list ap; va_start (ap, fmt); @@ -130,43 +122,6 @@ static int custom_awk_sprintf ( return n; } -static ase_ssize_t awk_srcio_out ( - int cmd, void* arg, ase_char_t* data, ase_size_t size) -{ - /*struct srcio_data_t* srcio = (struct srcio_data_t*)arg;*/ - - if (cmd == ASE_AWK_IO_OPEN) return 1; - else if (cmd == ASE_AWK_IO_CLOSE) - { - fflush (stdout); - return 0; - } - else if (cmd == ASE_AWK_IO_WRITE) - { - ase_size_t left = size; - - while (left > 0) - { - if (*data == ASE_T('\0')) - { - if (ase_fputc (*data, stdout) == ASE_CHAR_EOF) return -1; - left -= 1; data += 1; - } - else - { - int chunk = (left > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): (int)left; - int n = ase_fprintf (stdout, ASE_T("%.*s"), chunk, data); - if (n < 0) return -1; - left -= n; data += n; - } - } - - return size; - } - - return -1; -} - static ase_ssize_t awk_extio_pipe ( int cmd, void* arg, ase_char_t* data, ase_size_t size) { @@ -185,7 +140,7 @@ static ase_ssize_t awk_extio_pipe ( mode = ASE_T("w"); else return -1; /* TODO: any way to set the error number? */ - local_dprintf (ASE_T("opening %s of type %d (pipe)\n"), epa->name, epa->type); + dprint (ASE_T("opening %s of type %d (pipe)\n"), epa->name, epa->type); handle = ase_popen (epa->name, mode); if (handle == NULL) return -1; epa->handle = (void*)handle; @@ -194,7 +149,7 @@ static ase_ssize_t awk_extio_pipe ( case ASE_AWK_IO_CLOSE: { - local_dprintf (ASE_T("closing %s of type (pipe) %d\n"), epa->name, epa->type); + dprint (ASE_T("closing %s of type (pipe) %d\n"), epa->name, epa->type); fclose ((FILE*)epa->handle); epa->handle = NULL; return 0; @@ -311,7 +266,7 @@ static ase_ssize_t awk_extio_file ( mode = ASE_T("a"); else return -1; /* TODO: any way to set the error number? */ - local_dprintf (ASE_T("opening %s of type %d (file)\n"), epa->name, epa->type); + dprint (ASE_T("opening %s of type %d (file)\n"), epa->name, epa->type); handle = ase_fopen (epa->name, mode); if (handle == NULL) { @@ -330,7 +285,7 @@ static ase_ssize_t awk_extio_file ( case ASE_AWK_IO_CLOSE: { - local_dprintf (ASE_T("closing %s of type %d (file)\n"), epa->name, epa->type); + dprint (ASE_T("closing %s of type %d (file)\n"), epa->name, epa->type); fclose ((FILE*)epa->handle); epa->handle = NULL; return 0; @@ -528,7 +483,7 @@ static ase_ssize_t awk_extio_console ( } } - local_dprintf (ASE_T("open the next console [%s]\n"), rd->icf[rd->icf_no]); + dprint (ASE_T("open the next console [%s]\n"), rd->icf[rd->icf_no]); epa->handle = fp; } @@ -579,20 +534,20 @@ static int open_extio_console (ase_awk_extio_t* epa) runio_data_t* rd = (runio_data_t*)epa->data; /* TODO: OpenConsole in GUI APPLICATION */ - local_dprintf (ASE_T("opening console[%s] of type %x\n"), epa->name, epa->type); + dprint (ASE_T("opening console[%s] of type %x\n"), epa->name, epa->type); if (epa->mode == ASE_AWK_EXTIO_CONSOLE_READ) { if (rd->icf[rd->icf_no] == ASE_NULL) { /* no more input file */ - local_dprintf (ASE_T("console - no more file\n"));; + dprint (ASE_T("console - no more file\n"));; return 0; } if (rd->icf[rd->icf_no][0] == ASE_T('\0')) { - local_dprintf (ASE_T(" console(r) - \n")); + dprint (ASE_T(" console(r) - \n")); epa->handle = stdin; } else @@ -611,7 +566,7 @@ static int open_extio_console (ase_awk_extio_t* epa) return -1; } - local_dprintf (ASE_T(" console(r) - %s\n"), rd->icf[rd->icf_no]); + dprint (ASE_T(" console(r) - %s\n"), rd->icf[rd->icf_no]); if (ase_awk_setfilename ( epa->run, rd->icf[rd->icf_no], ase_strlen(rd->icf[rd->icf_no])) == -1) @@ -628,7 +583,7 @@ static int open_extio_console (ase_awk_extio_t* epa) } else if (epa->mode == ASE_AWK_EXTIO_CONSOLE_WRITE) { - local_dprintf (ASE_T(" console(w) - \n")); + dprint (ASE_T(" console(w) - \n")); if (ase_awk_setofilename (epa->run, ASE_T(""), 0) == -1) { @@ -644,7 +599,7 @@ static int open_extio_console (ase_awk_extio_t* epa) static int close_extio_console (ase_awk_extio_t* epa) { - local_dprintf (ASE_T("closing console of type %x\n"), epa->type); + dprint (ASE_T("closing console of type %x\n"), epa->type); if (epa->handle != ASE_NULL && epa->handle != stdin && @@ -671,7 +626,7 @@ static int next_extio_console (ase_awk_extio_t* epa) int n; FILE* fp = (FILE*)epa->handle; - local_dprintf (ASE_T("switching console[%s] of type %x\n"), epa->name, epa->type); + dprint (ASE_T("switching console[%s] of type %x\n"), epa->name, epa->type); n = open_extio_console(epa); if (n == -1) return -1; @@ -715,49 +670,71 @@ static void stop_run (int sig) static void on_run_start (ase_awk_run_t* run, void* custom) { app_run = run; - local_dprintf (ASE_T("[AWK ABOUT TO START]\n")); + dprint (ASE_T("[AWK ABOUT TO START]\n")); } static ase_map_walk_t print_awk_value ( ase_map_t* map, ase_map_pair_t* pair, void* arg) { ase_awk_run_t* run = (ase_awk_run_t*)arg; - local_dprintf (ASE_T("%.*s = "), - (int)ASE_MAP_KLEN(pair), ASE_MAP_KPTR(pair)); - ase_awk_dprintval (run, (ase_awk_val_t*)ASE_MAP_VPTR(pair)); - local_dprintf (ASE_T("\n")); + ase_char_t* str; + ase_size_t len; + + str = ase_awk_valtostr (run, ASE_MAP_VPTR(pair), 0, ASE_NULL, &len); + if (str == ASE_NULL) + { + dprint (ASE_T("***OUT OF MEMORY***\n")); + } + else + { + dprint (ASE_T("%.*s = %.*s\n"), + (int)ASE_MAP_KLEN(pair), ASE_MAP_KPTR(pair), + (int)len, str); + ase_awk_free (ase_awk_getrunawk(run), str); + } + return ASE_MAP_WALK_FORWARD; } static void on_run_statement ( ase_awk_run_t* run, ase_size_t line, void* custom) { - /*local_dprintf (L"running %d\n", (int)line);*/ + /*dprint (L"running %d\n", (int)line);*/ } static void on_run_return ( ase_awk_run_t* run, ase_awk_val_t* ret, void* custom) { - local_dprintf (ASE_T("[RETURN] - ")); - ase_awk_dprintval (run, ret); - local_dprintf (ASE_T("\n")); + ase_size_t len; + ase_char_t* str; - local_dprintf (ASE_T("[NAMED VARIABLES]\n")); + str = ase_awk_valtostr (run, ret, 0, ASE_NULL, &len); + if (str == ASE_NULL) + { + dprint (ASE_T("[RETURN] - ***OUT OF MEMORY***\n")); + } + else + { + dprint (ASE_T("[RETURN] - %.*s\n"), (int)len, str); + ase_awk_free (ase_awk_getrunawk(run), str); + } + + dprint (ASE_T("[NAMED VARIABLES]\n")); ase_map_walk (ase_awk_getrunnamedvarmap(run), print_awk_value, run); - local_dprintf (ASE_T("[END NAMED VARIABLES]\n")); + dprint (ASE_T("[END NAMED VARIABLES]\n")); } static void on_run_end (ase_awk_run_t* run, int errnum, void* data) { if (errnum != ASE_AWK_ENOERR) { - local_dprintf (ASE_T("[AWK ENDED WITH AN ERROR]\n")); + dprint (ASE_T("[AWK ENDED WITH AN ERROR]\n")); ase_printf (ASE_T("RUN ERROR: CODE [%d] LINE [%u] %s\n"), errnum, (unsigned int)ase_awk_getrunerrlin(run), ase_awk_getrunerrmsg(run)); } - else local_dprintf (ASE_T("[AWK ENDED SUCCESSFULLY]\n")); + else dprint (ASE_T("[AWK ENDED SUCCESSFULLY]\n")); app_run = NULL; } @@ -790,7 +767,12 @@ static void print_usage (const ase_char_t* argv0) { int j; - ase_printf (ASE_T("Usage: %s [-m] [-d] [-a argument]* -f source-file [data-file]*\n"), argv0); + ase_printf (ASE_T("Usage: %s [options] -f sourcefile [ -- ] [datafile]*\n"), argv0); + ase_printf (ASE_T(" %s [options] [ -- ] sourcestring [datafile]*\n"), argv0); + ase_printf (ASE_T("Where options are:\n")); + ase_printf (ASE_T(" -f sourcefile --file=sourcefile\n")); + ase_printf (ASE_T(" -d deparsedfile --deparsed-file=deparsedfile\n")); + ase_printf (ASE_T(" -F string --field-separator=string\n")); ase_printf (ASE_T("\nYou may specify the following options to change the behavior of the interpreter.\n")); for (j = 0; j < ASE_COUNTOF(otab); j++) @@ -911,7 +893,7 @@ static int handle_args (int argc, ase_char_t* argv[], struct argout_t* ao) { ASE_T(":main"), ASE_T('m') }, { ASE_T(":file"), ASE_T('f') }, { ASE_T(":field-separator"), ASE_T('F') }, - { ASE_T(":deparse-file"), ASE_T('d') }, + { ASE_T(":deparsed-file"), ASE_T('d') }, { ASE_T(":assign"), ASE_T('v') }, { ASE_T("help"), ASE_T('h') } @@ -1126,7 +1108,6 @@ static void init_awk_extension (ase_awk_t* awk) ext->prmfns.pow = custom_awk_pow; ext->prmfns.sprintf = custom_awk_sprintf; - ext->prmfns.dprintf = custom_awk_dprintf; ext->prmfns.data = ASE_NULL; ase_awk_setprmfns (awk, &ext->prmfns); } @@ -1243,7 +1224,8 @@ static int awk_main (int argc, ase_char_t* argv[]) app_awk = awk; - if (ase_awk_parsefiles (awk, ao.isf, ao.isfl, ao.osf) == -1) + if (ase_awk_parsesimple ( + awk, ao.isf, ao.isfl, ao.osf, ASE_AWK_PARSE_FILES) == -1) { ase_printf ( ASE_T("PARSE ERROR: CODE [%d] LINE [%u] %s\n"), @@ -1272,6 +1254,7 @@ static int awk_main (int argc, ase_char_t* argv[]) if (ao.iss != ASE_NULL) free (ao.iss); if (ao.isf != ASE_NULL) free (ao.isf); if (ao.osf != ASE_NULL) free (ao.osf); + if (ao.icf != ASE_NULL) free (ao.icf); if (ao.vm != ASE_NULL) ase_map_close (ao.vm); return 0; diff --git a/ase/configure b/ase/configure index 9144d4a6..2bfee4e8 100755 --- a/ase/configure +++ b/ase/configure @@ -20346,8 +20346,8 @@ else fi fi -CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE -D_AUTO_CONFIGURED" -CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE -D_AUTO_CONFIGURED" +CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE" +CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE" LIBM= case $host in diff --git a/ase/configure.ac b/ase/configure.ac index d1b3c039..fcc8c0d2 100644 --- a/ase/configure.ac +++ b/ase/configure.ac @@ -66,8 +66,8 @@ else fi dnl make visible the 64bit interface to the file system -CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE -D_AUTO_CONFIGURED" -CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE -D_AUTO_CONFIGURED" +CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE" +CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE" dnl Checks for the math library (is -lm needed?) AC_CHECK_LIBM diff --git a/ase/include/ase/awk/Awk.hpp b/ase/include/ase/awk/Awk.hpp index ac65bff1..1979bcd4 100644 --- a/ase/include/ase/awk/Awk.hpp +++ b/ase/include/ase/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp 449 2008-10-31 10:32:28Z baconevi $ + * $Id: Awk.hpp 468 2008-12-10 10:19:59Z baconevi $ * * {License} */ @@ -1044,7 +1044,6 @@ protected: virtual real_t pow (real_t x, real_t y) = 0; virtual int vsprintf (char_t* buf, size_t size, const char_t* fmt, va_list arg) = 0; - virtual void vdprintf (const char_t* fmt, va_list arg) = 0; // static glue members for various handlers static ssize_t sourceReader ( @@ -1078,7 +1077,6 @@ protected: static real_t pow (void* data, real_t x, real_t y); static int sprintf (void* data, char_t* buf, size_t size, const char_t* fmt, ...); - static void dprintf (void* data, const char_t* fmt, ...); protected: awk_t* awk; diff --git a/ase/include/ase/awk/StdAwk.hpp b/ase/include/ase/awk/StdAwk.hpp index 3fba8e7a..7bdc3925 100644 --- a/ase/include/ase/awk/StdAwk.hpp +++ b/ase/include/ase/awk/StdAwk.hpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.hpp 341 2008-08-20 10:58:19Z baconevi $ + * $Id: StdAwk.hpp 468 2008-12-10 10:19:59Z baconevi $ * * {License} */ @@ -83,7 +83,6 @@ protected: real_t pow (real_t x, real_t y); int vsprintf (char_t* buf, size_t size, const char_t* fmt, va_list arg); - void vdprintf (const char_t* fmt, va_list arg); protected: unsigned int seed; diff --git a/ase/include/ase/awk/awk.h b/ase/include/ase/awk/awk.h index 833a90b4..b49288b4 100644 --- a/ase/include/ase/awk/awk.h +++ b/ase/include/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h 464 2008-12-09 08:50:16Z baconevi $ + * $Id: awk.h 468 2008-12-10 10:19:59Z baconevi $ * * {License} */ @@ -37,7 +37,6 @@ typedef ase_real_t (*ase_awk_pow_t) (void* data, ase_real_t x, ase_real_t y); typedef int (*ase_awk_sprintf_t) ( void* data, ase_char_t* buf, ase_size_t size, const ase_char_t* fmt, ...); -typedef void (*ase_awk_dprintf_t) (void* data, const ase_char_t* fmt, ...); typedef ase_ssize_t (*ase_awk_io_t) ( int cmd, void* arg, ase_char_t* data, ase_size_t count); @@ -75,7 +74,6 @@ struct ase_awk_prmfns_t { ase_awk_pow_t pow; /* required */ ase_awk_sprintf_t sprintf; /* required */ - ase_awk_dprintf_t dprintf; /* required in the debug mode */ /* user-defined data passed to the functions above */ void* data; /* optional */ @@ -476,6 +474,12 @@ enum ase_awk_valtostr_opt_t ASE_AWK_VALTOSTR_PRINT = (1 << 2) }; +enum ase_awk_parse_opt_t +{ + ASE_AWK_PARSE_FILES = 0, + ASE_AWK_PARSE_STRING = 1 +}; + typedef struct ase_awk_val_nil_t ase_awk_val_nil_t; typedef struct ase_awk_val_int_t ase_awk_val_int_t; typedef struct ase_awk_val_real_t ase_awk_val_real_t; @@ -822,12 +826,29 @@ int ase_awk_parse ( /******/ -int ase_awk_parsefiles ( - ase_awk_t* awk, - const ase_char_t*const* isf /* input source file names */, - ase_size_t isfl /* the number of input source files */, - const ase_char_t* osf /* an output source file name */ +/****f* ase.awk/ase_awk_opensimple + * NAME + * ase_awk_opensimple - create an awk object + * + * SYNOPSIS + */ +ase_awk_t* ase_awk_opensimple (void); +/******/ + +/****f* ase.awk/ase_awk_parsesimple + * NAME + * ase_awk_parsesimple - parse source code + * + * SYNOPSIS + */ +int ase_awk_parsesimple ( + ase_awk_t* awk, + const void* is /* source file names or source string */, + ase_size_t isl /* source file count or source string length */, + const ase_char_t* osf /* an output source file name */, + int opt /* ASE_AWK_PARSE_FILES, ASE_AWK_PARSE_STRING */ ); +/******/ /** * Executes a parsed program. @@ -1049,7 +1070,6 @@ int ase_awk_strtonum ( ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len, ase_long_t* l, ase_real_t* r); -void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val); #ifdef __cplusplus } #endif diff --git a/ase/include/ase/types.h b/ase/include/ase/types.h index 3851f9d8..e1154511 100644 --- a/ase/include/ase/types.h +++ b/ase/include/ase/types.h @@ -1,5 +1,5 @@ /* - * $Id: types.h 463 2008-12-09 06:52:03Z baconevi $ + * $Id: types.h 468 2008-12-10 10:19:59Z baconevi $ * * {License} */ @@ -17,7 +17,7 @@ ****** */ -#if defined(_AUTO_CONFIGURED) +#if defined(HAVE_CONFIG_H) #include #elif defined(_WIN32) #include diff --git a/ase/lib/awk/Awk.cpp b/ase/lib/awk/Awk.cpp index 809cf267..f0e7e6b8 100644 --- a/ase/lib/awk/Awk.cpp +++ b/ase/lib/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp 449 2008-10-31 10:32:28Z baconevi $ + * $Id: Awk.cpp 468 2008-12-10 10:19:59Z baconevi $ * * {License} */ @@ -1050,7 +1050,6 @@ Awk::Awk (): awk (ASE_NULL), functionMap (ASE_NULL), prmfns.pow = pow; prmfns.sprintf = sprintf; - prmfns.dprintf = dprintf; prmfns.data = this; } @@ -1777,14 +1776,6 @@ int Awk::sprintf (void* data, char_t* buf, size_t size, return n; } -void Awk::dprintf (void* data, const char_t* fmt, ...) -{ - va_list ap; - va_start (ap, fmt); - ((Awk*)data)->vdprintf (fmt, ap); - va_end (ap); -} - ///////////////////////////////// ASE_END_NAMESPACE(ASE) ///////////////////////////////// diff --git a/ase/lib/awk/StdAwk.cpp b/ase/lib/awk/StdAwk.cpp index 11f73d3a..1e779d46 100644 --- a/ase/lib/awk/StdAwk.cpp +++ b/ase/lib/awk/StdAwk.cpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.cpp 424 2008-10-14 10:08:31Z baconevi $ + * $Id: StdAwk.cpp 468 2008-12-10 10:19:59Z baconevi $ * * {License} */ @@ -457,11 +457,6 @@ int StdAwk::vsprintf ( return ase_vsprintf (buf, size, fmt, arg); } -void StdAwk::vdprintf (const char_t* fmt, va_list arg) -{ - ase_vfprintf (stderr, fmt, arg); -} - ///////////////////////////////// ASE_END_NAMESPACE(ASE) ///////////////////////////////// diff --git a/ase/lib/awk/std.c b/ase/lib/awk/std.c index ed913868..81c8c945 100644 --- a/ase/lib/awk/std.c +++ b/ase/lib/awk/std.c @@ -3,8 +3,10 @@ */ #include "awk.h" -#include +#include + #include +#include typedef struct ext_t { @@ -31,15 +33,7 @@ static int custom_awk_sprintf ( return n; } -static void custom_awk_dprintf (void* custom, const ase_char_t* fmt, ...) -{ - va_list ap; - va_start (ap, fmt); - ase_vfprintf (ASE_STDERR, fmt, ap); - va_end (ap); -} - -ase_awk_t* ase_awk_openstd (void) +ase_awk_t* ase_awk_opensimple (void) { ase_awk_t* awk; ext_t* ext; @@ -50,7 +44,6 @@ ase_awk_t* ase_awk_openstd (void) ext = (ext_t*)ase_awk_getextension(awk); ext->prmfns.pow = custom_awk_pow; ext->prmfns.sprintf = custom_awk_sprintf; - ext->prmfns.dprintf = custom_awk_dprintf; ext->prmfns.data = ASE_NULL; ase_awk_setprmfns (awk, &ext->prmfns); @@ -63,6 +56,8 @@ ase_awk_t* ase_awk_openstd (void) return awk; } +/*** PARSESIMPLE ***/ + typedef struct sf_t sf_t; struct sf_t @@ -72,14 +67,16 @@ struct sf_t const ase_char_t*const* files; ase_size_t count; /* the number of files */ ase_size_t index; /* current file index */ - ASE_FILE* handle; /* the handle to an open file */ + ase_sio_t* handle; /* the handle to an open file */ } in; struct { const ase_char_t* file; - ASE_FILE* handle; + ase_sio_t* handle; } out; + + ase_awk_t* awk; }; static ase_ssize_t sf_in (int cmd, void* arg, ase_char_t* data, ase_size_t size) @@ -93,11 +90,16 @@ static ase_ssize_t sf_in (int cmd, void* arg, ase_char_t* data, ase_size_t size) if (sf->in.files[sf->in.index][0] == ASE_T('\0')) { - sf->in.handle = ASE_STDIN; + sf->in.handle = ase_sio_in; } else { - sf->in.handle = ase_fopen (sf->in.files[sf->in.index], ASE_T("r")); + sf->in.handle = ase_sio_open ( + ase_awk_getmmgr(sf->awk), + 0, + sf->in.files[sf->in.index], + ASE_SIO_READ + ); if (sf->in.handle == ASE_NULL) return -1; } @@ -110,16 +112,42 @@ static ase_ssize_t sf_in (int cmd, void* arg, ase_char_t* data, ase_size_t size) else if (cmd == ASE_AWK_IO_CLOSE) { if (sf->in.index >= sf->in.count) return 0; - if (sf->in.handle != ASE_STDIN) ase_fclose (sf->in.handle); + if (sf->in.handle != ase_sio_in) ase_sio_close (sf->in.handle); return 0; } else if (cmd == ASE_AWK_IO_READ) { ase_ssize_t n = 0; - ASE_FILE* fp; + ase_sio_t* fp; retry: fp = sf->in.handle; + + n = ase_sio_getsx (fp, data, size); + if (n == 0 && ++sf->in.index < sf->in.count) + { + if (fp != ase_sio_in) ase_sio_close (fp); + if (sf->in.files[sf->in.index][0] == ASE_T('\0')) + { + sf->in.handle = ase_sio_in; + } + else + { + sf->in.handle = ase_sio_open ( + ase_awk_getmmgr(sf->awk), + 0, + sf->in.files[sf->in.index], + ASE_SIO_READ + ); + if (sf->in.handle == ASE_NULL) return -1; + } + /* TODO: reset internal line counters... + ase_awk_setsinname (); + */ + goto retry; + } + + #if 0 while (!ase_feof(fp) && n < size) { ase_cint_t c = ase_fgetc (fp); @@ -136,14 +164,16 @@ static ase_ssize_t sf_in (int cmd, void* arg, ase_char_t* data, ase_size_t size) sf->in.index++; if (sf->in.index < sf->in.count) { - if (fp != ASE_STDIN) ase_fclose (fp); + if (fp != ase_sio_in) ase_sio_close (fp); if (sf->in.files[sf->in.index][0] == ASE_T('\0')) { - sf->in.handle = ASE_STDIN; + sf->in.handle = ase_sio_in; } else { - sf->in.handle = ase_fopen (sf->in.files[sf->in.index], ASE_T("r")); + sf->in.handle = ase_sio_open ( + ase_awk_getmmgr(sf->awk), 0, + sf->in.files[sf->in.index], ASE_SIO_READ); if (sf->in.handle == ASE_NULL) return -1; } /* TODO: reset internal line counters... @@ -152,6 +182,8 @@ static ase_ssize_t sf_in (int cmd, void* arg, ase_char_t* data, ase_size_t size) goto retry; } } + #endif + return n; } @@ -166,11 +198,16 @@ static ase_ssize_t sf_out (int cmd, void* arg, ase_char_t* data, ase_size_t size { if (sf->out.file[0] == ASE_T('\0')) { - sf->out.handle = ASE_STDOUT; + sf->out.handle = ase_sio_out; } else { - sf->out.handle = ase_fopen (sf->out.file, ASE_T("w")); + sf->out.handle = ase_sio_open ( + ase_awk_getmmgr(sf->awk), + 0, + sf->out.file, + ASE_SIO_WRITE|ASE_SIO_CREATE|ASE_SIO_TRUNCATE + ); if (sf->out.handle == ASE_NULL) return -1; } @@ -178,13 +215,14 @@ static ase_ssize_t sf_out (int cmd, void* arg, ase_char_t* data, ase_size_t size } else if (cmd == ASE_AWK_IO_CLOSE) { - ase_fflush (sf->out.handle); - if (sf->out.handle != ASE_STDOUT && - sf->out.handle != ASE_STDERR) ase_fclose (sf->out.handle); + ase_sio_flush (sf->out.handle); + if (sf->out.handle != ase_sio_out && + sf->out.handle != ase_sio_err) ase_sio_close (sf->out.handle); return 0; } else if (cmd == ASE_AWK_IO_WRITE) { + /* ase_size_t left = size; while (left > 0) @@ -201,31 +239,48 @@ static ase_ssize_t sf_out (int cmd, void* arg, ase_char_t* data, ase_size_t size if (n < 0) return -1; left -= n; data += n; } - } - return size; + } + */ + + return ase_sio_putsx (sf->out.handle, data, size); } return -1; } -int ase_awk_parsefiles (ase_awk_t* awk, const ase_char_t*const* isf, ase_size_t isfl, const ase_char_t* osf) +int ase_awk_parsesimple ( + ase_awk_t* awk, const void* is, ase_size_t isl, + const ase_char_t* osf, int opt) { sf_t sf; ase_awk_srcios_t sio; - if (isf == ASE_NULL || isfl == 0) + if (is == ASE_NULL || isl == 0) { ase_awk_seterrnum (awk, ASE_AWK_EINVAL); return -1; } - sf.in.files = isf; - sf.in.count = isfl; - sf.in.index = 0; - sf.in.handle = ASE_NULL; + if (opt == ASE_AWK_PARSE_FILES) + { + sf.in.files = is; + sf.in.count = isl; + sf.in.index = 0; + sf.in.handle = ASE_NULL; + } + else if (opt == ASE_AWK_PARSE_STRING) + { + /* TODO */ + } + else + { + ase_awk_seterrnum (awk, ASE_AWK_EINVAL); + return -1; + } sf.out.file = osf; + sf.awk = awk; sio.in = sf_in; sio.out = (osf == ASE_NULL)? ASE_NULL: sf_out; @@ -234,9 +289,10 @@ int ase_awk_parsefiles (ase_awk_t* awk, const ase_char_t*const* isf, ase_size_t return ase_awk_parse (awk, &sio); } -#if 0 -int ase_awk_parsestring (ase_awk_t* awk, const ase_char_t* str, ase_size_t len) +/*** RUNSIMPLE ***/ + +ase_awk_run_t* ase_awk_runsimple ( + ase_awk_t* awk, ase_size_t argc, const char* args[]) { - return -1; + return ASE_NULL; } -#endif diff --git a/ase/lib/awk/val.c b/ase/lib/awk/val.c index 4f60ded5..bb2af24c 100644 --- a/ase/lib/awk/val.c +++ b/ase/lib/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c 466 2008-12-09 09:50:40Z baconevi $ + * $Id: val.c 468 2008-12-10 10:19:59Z baconevi $ * * {License} */ @@ -1131,6 +1131,8 @@ int ase_awk_strtonum ( return 0; /* long */ } +#if 0 + #define DPRINTF run->awk->prmfns->dprintf #define DCUSTOM run->awk->prmfns->data @@ -1212,3 +1214,4 @@ void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val) } } +#endif