changed various parts

This commit is contained in:
hyung-hwan 2008-12-11 04:19:59 +00:00
parent 54855b9730
commit 6a3e652db3
11 changed files with 195 additions and 150 deletions

View File

@ -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 <ase/awk/awk.h> #include <ase/awk/awk.h>
@ -63,15 +63,7 @@ typedef struct runio_data_t
ase_size_t icf_no; ase_size_t icf_no;
} runio_data_t; } runio_data_t;
static void local_dprintf (const ase_char_t* fmt, ...) static void dprint (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, ...)
{ {
va_list ap; va_list ap;
va_start (ap, fmt); va_start (ap, fmt);
@ -130,43 +122,6 @@ static int custom_awk_sprintf (
return n; 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 ( static ase_ssize_t awk_extio_pipe (
int cmd, void* arg, ase_char_t* data, ase_size_t size) 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"); mode = ASE_T("w");
else return -1; /* TODO: any way to set the error number? */ 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); handle = ase_popen (epa->name, mode);
if (handle == NULL) return -1; if (handle == NULL) return -1;
epa->handle = (void*)handle; epa->handle = (void*)handle;
@ -194,7 +149,7 @@ static ase_ssize_t awk_extio_pipe (
case ASE_AWK_IO_CLOSE: 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); fclose ((FILE*)epa->handle);
epa->handle = NULL; epa->handle = NULL;
return 0; return 0;
@ -311,7 +266,7 @@ static ase_ssize_t awk_extio_file (
mode = ASE_T("a"); mode = ASE_T("a");
else return -1; /* TODO: any way to set the error number? */ 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); handle = ase_fopen (epa->name, mode);
if (handle == NULL) if (handle == NULL)
{ {
@ -330,7 +285,7 @@ static ase_ssize_t awk_extio_file (
case ASE_AWK_IO_CLOSE: 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); fclose ((FILE*)epa->handle);
epa->handle = NULL; epa->handle = NULL;
return 0; 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; 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; runio_data_t* rd = (runio_data_t*)epa->data;
/* TODO: OpenConsole in GUI APPLICATION */ /* 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 (epa->mode == ASE_AWK_EXTIO_CONSOLE_READ)
{ {
if (rd->icf[rd->icf_no] == ASE_NULL) if (rd->icf[rd->icf_no] == ASE_NULL)
{ {
/* no more input file */ /* no more input file */
local_dprintf (ASE_T("console - no more file\n"));; dprint (ASE_T("console - no more file\n"));;
return 0; return 0;
} }
if (rd->icf[rd->icf_no][0] == ASE_T('\0')) if (rd->icf[rd->icf_no][0] == ASE_T('\0'))
{ {
local_dprintf (ASE_T(" console(r) - <standard input>\n")); dprint (ASE_T(" console(r) - <standard input>\n"));
epa->handle = stdin; epa->handle = stdin;
} }
else else
@ -611,7 +566,7 @@ static int open_extio_console (ase_awk_extio_t* epa)
return -1; 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 ( if (ase_awk_setfilename (
epa->run, rd->icf[rd->icf_no], epa->run, rd->icf[rd->icf_no],
ase_strlen(rd->icf[rd->icf_no])) == -1) 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) else if (epa->mode == ASE_AWK_EXTIO_CONSOLE_WRITE)
{ {
local_dprintf (ASE_T(" console(w) - <standard output>\n")); dprint (ASE_T(" console(w) - <standard output>\n"));
if (ase_awk_setofilename (epa->run, ASE_T(""), 0) == -1) 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) 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 && if (epa->handle != ASE_NULL &&
epa->handle != stdin && epa->handle != stdin &&
@ -671,7 +626,7 @@ static int next_extio_console (ase_awk_extio_t* epa)
int n; int n;
FILE* fp = (FILE*)epa->handle; 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); n = open_extio_console(epa);
if (n == -1) return -1; 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) static void on_run_start (ase_awk_run_t* run, void* custom)
{ {
app_run = run; 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 ( static ase_map_walk_t print_awk_value (
ase_map_t* map, ase_map_pair_t* pair, void* arg) ase_map_t* map, ase_map_pair_t* pair, void* arg)
{ {
ase_awk_run_t* run = (ase_awk_run_t*)arg; ase_awk_run_t* run = (ase_awk_run_t*)arg;
local_dprintf (ASE_T("%.*s = "), ase_char_t* str;
(int)ASE_MAP_KLEN(pair), ASE_MAP_KPTR(pair)); ase_size_t len;
ase_awk_dprintval (run, (ase_awk_val_t*)ASE_MAP_VPTR(pair));
local_dprintf (ASE_T("\n")); 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; return ASE_MAP_WALK_FORWARD;
} }
static void on_run_statement ( static void on_run_statement (
ase_awk_run_t* run, ase_size_t line, void* custom) 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 ( static void on_run_return (
ase_awk_run_t* run, ase_awk_val_t* ret, void* custom) ase_awk_run_t* run, ase_awk_val_t* ret, void* custom)
{ {
local_dprintf (ASE_T("[RETURN] - ")); ase_size_t len;
ase_awk_dprintval (run, ret); ase_char_t* str;
local_dprintf (ASE_T("\n"));
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); 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) static void on_run_end (ase_awk_run_t* run, int errnum, void* data)
{ {
if (errnum != ASE_AWK_ENOERR) 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"), ase_printf (ASE_T("RUN ERROR: CODE [%d] LINE [%u] %s\n"),
errnum, errnum,
(unsigned int)ase_awk_getrunerrlin(run), (unsigned int)ase_awk_getrunerrlin(run),
ase_awk_getrunerrmsg(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; app_run = NULL;
} }
@ -790,7 +767,12 @@ static void print_usage (const ase_char_t* argv0)
{ {
int j; 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")); 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++) 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(":main"), ASE_T('m') },
{ ASE_T(":file"), ASE_T('f') }, { ASE_T(":file"), ASE_T('f') },
{ ASE_T(":field-separator"), 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(":assign"), ASE_T('v') },
{ ASE_T("help"), ASE_T('h') } { 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.pow = custom_awk_pow;
ext->prmfns.sprintf = custom_awk_sprintf; ext->prmfns.sprintf = custom_awk_sprintf;
ext->prmfns.dprintf = custom_awk_dprintf;
ext->prmfns.data = ASE_NULL; ext->prmfns.data = ASE_NULL;
ase_awk_setprmfns (awk, &ext->prmfns); ase_awk_setprmfns (awk, &ext->prmfns);
} }
@ -1243,7 +1224,8 @@ static int awk_main (int argc, ase_char_t* argv[])
app_awk = awk; 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_printf (
ASE_T("PARSE ERROR: CODE [%d] LINE [%u] %s\n"), 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.iss != ASE_NULL) free (ao.iss);
if (ao.isf != ASE_NULL) free (ao.isf); if (ao.isf != ASE_NULL) free (ao.isf);
if (ao.osf != ASE_NULL) free (ao.osf); 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); if (ao.vm != ASE_NULL) ase_map_close (ao.vm);
return 0; return 0;

4
ase/configure vendored
View File

@ -20346,8 +20346,8 @@ else
fi fi
fi fi
CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE -D_AUTO_CONFIGURED" CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE"
CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE -D_AUTO_CONFIGURED" CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE"
LIBM= LIBM=
case $host in case $host in

View File

@ -66,8 +66,8 @@ else
fi fi
dnl make visible the 64bit interface to the file system dnl make visible the 64bit interface to the file system
CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE -D_AUTO_CONFIGURED" CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE"
CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE -D_AUTO_CONFIGURED" CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE"
dnl Checks for the math library (is -lm needed?) dnl Checks for the math library (is -lm needed?)
AC_CHECK_LIBM AC_CHECK_LIBM

View File

@ -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} * {License}
*/ */
@ -1044,7 +1044,6 @@ protected:
virtual real_t pow (real_t x, real_t y) = 0; virtual real_t pow (real_t x, real_t y) = 0;
virtual int vsprintf (char_t* buf, size_t size, virtual int vsprintf (char_t* buf, size_t size,
const char_t* fmt, va_list arg) = 0; 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 glue members for various handlers
static ssize_t sourceReader ( static ssize_t sourceReader (
@ -1078,7 +1077,6 @@ protected:
static real_t pow (void* data, real_t x, real_t y); static real_t pow (void* data, real_t x, real_t y);
static int sprintf (void* data, char_t* buf, size_t size, static int sprintf (void* data, char_t* buf, size_t size,
const char_t* fmt, ...); const char_t* fmt, ...);
static void dprintf (void* data, const char_t* fmt, ...);
protected: protected:
awk_t* awk; awk_t* awk;

View File

@ -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} * {License}
*/ */
@ -83,7 +83,6 @@ protected:
real_t pow (real_t x, real_t y); real_t pow (real_t x, real_t y);
int vsprintf (char_t* buf, size_t size, int vsprintf (char_t* buf, size_t size,
const char_t* fmt, va_list arg); const char_t* fmt, va_list arg);
void vdprintf (const char_t* fmt, va_list arg);
protected: protected:
unsigned int seed; unsigned int seed;

View File

@ -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} * {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) ( typedef int (*ase_awk_sprintf_t) (
void* data, ase_char_t* buf, ase_size_t size, void* data, ase_char_t* buf, ase_size_t size,
const ase_char_t* fmt, ...); 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) ( typedef ase_ssize_t (*ase_awk_io_t) (
int cmd, void* arg, ase_char_t* data, ase_size_t count); 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_pow_t pow; /* required */
ase_awk_sprintf_t sprintf; /* 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 */ /* user-defined data passed to the functions above */
void* data; /* optional */ void* data; /* optional */
@ -476,6 +474,12 @@ enum ase_awk_valtostr_opt_t
ASE_AWK_VALTOSTR_PRINT = (1 << 2) 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_nil_t ase_awk_val_nil_t;
typedef struct ase_awk_val_int_t ase_awk_val_int_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; typedef struct ase_awk_val_real_t ase_awk_val_real_t;
@ -822,12 +826,29 @@ int ase_awk_parse (
/******/ /******/
int ase_awk_parsefiles ( /****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, ase_awk_t* awk,
const ase_char_t*const* isf /* input source file names */, const void* is /* source file names or source string */,
ase_size_t isfl /* the number of input source files */, ase_size_t isl /* source file count or source string length */,
const ase_char_t* osf /* an output source file name */ const ase_char_t* osf /* an output source file name */,
int opt /* ASE_AWK_PARSE_FILES, ASE_AWK_PARSE_STRING */
); );
/******/
/** /**
* Executes a parsed program. * 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_awk_run_t* run, const ase_char_t* ptr, ase_size_t len,
ase_long_t* l, ase_real_t* r); ase_long_t* l, ase_real_t* r);
void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -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} * {License}
*/ */
@ -17,7 +17,7 @@
****** ******
*/ */
#if defined(_AUTO_CONFIGURED) #if defined(HAVE_CONFIG_H)
#include <ase/config.h> #include <ase/config.h>
#elif defined(_WIN32) #elif defined(_WIN32)
#include <ase/conf_msw.h> #include <ase/conf_msw.h>

View File

@ -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} * {License}
*/ */
@ -1050,7 +1050,6 @@ Awk::Awk (): awk (ASE_NULL), functionMap (ASE_NULL),
prmfns.pow = pow; prmfns.pow = pow;
prmfns.sprintf = sprintf; prmfns.sprintf = sprintf;
prmfns.dprintf = dprintf;
prmfns.data = this; prmfns.data = this;
} }
@ -1777,14 +1776,6 @@ int Awk::sprintf (void* data, char_t* buf, size_t size,
return n; 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) ASE_END_NAMESPACE(ASE)
///////////////////////////////// /////////////////////////////////

View File

@ -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} * {License}
*/ */
@ -457,11 +457,6 @@ int StdAwk::vsprintf (
return ase_vsprintf (buf, size, fmt, arg); 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) ASE_END_NAMESPACE(ASE)
///////////////////////////////// /////////////////////////////////

View File

@ -3,8 +3,10 @@
*/ */
#include "awk.h" #include "awk.h"
#include <ase/utl/stdio.h> #include <ase/cmn/sio.h>
#include <math.h> #include <math.h>
#include <ase/utl/stdio.h>
typedef struct ext_t typedef struct ext_t
{ {
@ -31,15 +33,7 @@ static int custom_awk_sprintf (
return n; return n;
} }
static void custom_awk_dprintf (void* custom, const ase_char_t* fmt, ...) ase_awk_t* ase_awk_opensimple (void)
{
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* awk; ase_awk_t* awk;
ext_t* ext; ext_t* ext;
@ -50,7 +44,6 @@ ase_awk_t* ase_awk_openstd (void)
ext = (ext_t*)ase_awk_getextension(awk); ext = (ext_t*)ase_awk_getextension(awk);
ext->prmfns.pow = custom_awk_pow; ext->prmfns.pow = custom_awk_pow;
ext->prmfns.sprintf = custom_awk_sprintf; ext->prmfns.sprintf = custom_awk_sprintf;
ext->prmfns.dprintf = custom_awk_dprintf;
ext->prmfns.data = ASE_NULL; ext->prmfns.data = ASE_NULL;
ase_awk_setprmfns (awk, &ext->prmfns); ase_awk_setprmfns (awk, &ext->prmfns);
@ -63,6 +56,8 @@ ase_awk_t* ase_awk_openstd (void)
return awk; return awk;
} }
/*** PARSESIMPLE ***/
typedef struct sf_t sf_t; typedef struct sf_t sf_t;
struct sf_t struct sf_t
@ -72,14 +67,16 @@ struct sf_t
const ase_char_t*const* files; const ase_char_t*const* files;
ase_size_t count; /* the number of files */ ase_size_t count; /* the number of files */
ase_size_t index; /* current file index */ 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; } in;
struct struct
{ {
const ase_char_t* file; const ase_char_t* file;
ASE_FILE* handle; ase_sio_t* handle;
} out; } out;
ase_awk_t* awk;
}; };
static ase_ssize_t sf_in (int cmd, void* arg, ase_char_t* data, ase_size_t size) 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')) if (sf->in.files[sf->in.index][0] == ASE_T('\0'))
{ {
sf->in.handle = ASE_STDIN; sf->in.handle = ase_sio_in;
} }
else 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; 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) else if (cmd == ASE_AWK_IO_CLOSE)
{ {
if (sf->in.index >= sf->in.count) return 0; 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; return 0;
} }
else if (cmd == ASE_AWK_IO_READ) else if (cmd == ASE_AWK_IO_READ)
{ {
ase_ssize_t n = 0; ase_ssize_t n = 0;
ASE_FILE* fp; ase_sio_t* fp;
retry: retry:
fp = sf->in.handle; 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) while (!ase_feof(fp) && n < size)
{ {
ase_cint_t c = ase_fgetc (fp); 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++; sf->in.index++;
if (sf->in.index < sf->in.count) 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')) if (sf->in.files[sf->in.index][0] == ASE_T('\0'))
{ {
sf->in.handle = ASE_STDIN; sf->in.handle = ase_sio_in;
} }
else 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; if (sf->in.handle == ASE_NULL) return -1;
} }
/* TODO: reset internal line counters... /* 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; goto retry;
} }
} }
#endif
return n; 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')) if (sf->out.file[0] == ASE_T('\0'))
{ {
sf->out.handle = ASE_STDOUT; sf->out.handle = ase_sio_out;
} }
else 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; 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) else if (cmd == ASE_AWK_IO_CLOSE)
{ {
ase_fflush (sf->out.handle); ase_sio_flush (sf->out.handle);
if (sf->out.handle != ASE_STDOUT && if (sf->out.handle != ase_sio_out &&
sf->out.handle != ASE_STDERR) ase_fclose (sf->out.handle); sf->out.handle != ase_sio_err) ase_sio_close (sf->out.handle);
return 0; return 0;
} }
else if (cmd == ASE_AWK_IO_WRITE) else if (cmd == ASE_AWK_IO_WRITE)
{ {
/*
ase_size_t left = size; ase_size_t left = size;
while (left > 0) 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; if (n < 0) return -1;
left -= n; data += n; left -= n; data += n;
} }
}
return size; }
*/
return ase_sio_putsx (sf->out.handle, data, size);
} }
return -1; 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; sf_t sf;
ase_awk_srcios_t sio; ase_awk_srcios_t sio;
if (isf == ASE_NULL || isfl == 0) if (is == ASE_NULL || isl == 0)
{ {
ase_awk_seterrnum (awk, ASE_AWK_EINVAL); ase_awk_seterrnum (awk, ASE_AWK_EINVAL);
return -1; return -1;
} }
sf.in.files = isf; if (opt == ASE_AWK_PARSE_FILES)
sf.in.count = isfl; {
sf.in.files = is;
sf.in.count = isl;
sf.in.index = 0; sf.in.index = 0;
sf.in.handle = ASE_NULL; 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.out.file = osf;
sf.awk = awk;
sio.in = sf_in; sio.in = sf_in;
sio.out = (osf == ASE_NULL)? ASE_NULL: sf_out; 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); return ase_awk_parse (awk, &sio);
} }
#if 0 /*** RUNSIMPLE ***/
int ase_awk_parsestring (ase_awk_t* awk, const ase_char_t* str, ase_size_t len)
ase_awk_run_t* ase_awk_runsimple (
ase_awk_t* awk, ase_size_t argc, const char* args[])
{ {
return -1; return ASE_NULL;
} }
#endif

View File

@ -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} * {License}
*/ */
@ -1131,6 +1131,8 @@ int ase_awk_strtonum (
return 0; /* long */ return 0; /* long */
} }
#if 0
#define DPRINTF run->awk->prmfns->dprintf #define DPRINTF run->awk->prmfns->dprintf
#define DCUSTOM run->awk->prmfns->data #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