From a786fe2d1af587f7b4d0a7cc73ba0db125870a49 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 25 Jun 2006 15:26:57 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/awk.h | 16 +++++++----- ase/awk/extio.c | 4 ++- ase/awk/parse.c | 27 ++++++--------------- ase/awk/run.c | 31 +++++++++++++++++++++-- ase/awk/tree.c | 5 ++-- ase/awk/tree.h | 5 ++-- ase/test/awk/awk.c | 58 +++++++++++++++++++++++++++++++++++++++++++- ase/test/awk/t10.awk | 7 +++--- 8 files changed, 117 insertions(+), 36 deletions(-) diff --git a/ase/awk/awk.h b/ase/awk/awk.h index 986fc4a0..793a654b 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.71 2006-06-22 04:25:44 bacon Exp $ + * $Id: awk.h,v 1.72 2006-06-25 15:26:57 bacon Exp $ */ #ifndef _XP_AWK_AWK_H_ @@ -35,12 +35,15 @@ enum enum { - XP_AWK_IO_FILE_READ = 0, - XP_AWK_IO_FILE_WRITE = 1, - XP_AWK_IO_FILE_APPEND = 2, + XP_AWK_IO_PIPE_READ = 0, + XP_AWK_IO_PIPE_WRITE = 1, - XP_AWK_IO_PIPE_READ = 0, - XP_AWK_IO_PIPE_WRITE = 1 + XP_AWK_IO_FILE_READ = 0, + XP_AWK_IO_FILE_WRITE = 1, + XP_AWK_IO_FILE_APPEND = 2, + + XP_AWK_IO_CONSOLE_READ = 0, + XP_AWK_IO_CONSOLE_WRITE = 1 }; /* parse options */ @@ -132,6 +135,7 @@ enum XP_AWK_EXTIO_PIPE, XP_AWK_EXTIO_COPROC, XP_AWK_EXTIO_FILE, + XP_AWK_EXTIO_CONSOLE, /* reserved for internal use only */ XP_AWK_EXTIO_NUM diff --git a/ase/awk/extio.c b/ase/awk/extio.c index 20ce0893..7e221376 100644 --- a/ase/awk/extio.c +++ b/ase/awk/extio.c @@ -1,5 +1,5 @@ /* - * $Id: extio.c,v 1.9 2006-06-22 14:15:01 bacon Exp $ + * $Id: extio.c,v 1.10 2006-06-25 15:26:57 bacon Exp $ */ #include @@ -147,6 +147,8 @@ int xp_awk_writeextio ( ioopt = XP_AWK_IO_PIPE_READ; else if (type == XP_AWK_EXTIO_FILE) ioopt = XP_AWK_IO_FILE_READ; + else if (type == XP_AWK_EXTIO_CONSOLE) + ioopt = XP_AWK_IO_CONSOLE_READ; else ioopt = 0; /* TODO: how to handle this??? */ if (handler (XP_AWK_IO_OPEN, ioopt, p, XP_NULL, 0) == -1) diff --git a/ase/awk/parse.c b/ase/awk/parse.c index bb85bf84..4f81ec5d 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.121 2006-06-22 14:15:01 bacon Exp $ + * $Id: parse.c,v 1.122 2006-06-25 15:26:57 bacon Exp $ */ #include @@ -2784,7 +2784,7 @@ static xp_awk_nde_t* __parse_print (xp_awk_t* awk) xp_awk_nde_print_t* nde; xp_awk_nde_t* args = XP_NULL; xp_awk_nde_t* out = XP_NULL; - int out_type = -1; + int out_type; /* TODO: handle expression list, not just a single expression */ /* TODO: handle ambiguiouty print "1111" > "2222". is > redirection? */ @@ -2799,24 +2799,13 @@ static xp_awk_nde_t* __parse_print (xp_awk_t* awk) if (args == XP_NULL) return XP_NULL; } - if (MATCH(awk,TOKEN_GT)) - { - out_type = XP_AWK_PRINT_FILE; - } - else if (MATCH(awk,TOKEN_RSHIFT)) - { - out_type = XP_AWK_PRINT_FILE_APPEND; - } - else if (MATCH(awk,TOKEN_BOR)) - { - out_type = XP_AWK_PRINT_PIPE; - } - else if (MATCH(awk,TOKEN_BORAND)) - { - out_type = XP_AWK_PRINT_COPROC; - } + out_type = MATCH(awk,TOKEN_GT)? XP_AWK_PRINT_FILE: + MATCH(awk,TOKEN_RSHIFT)? XP_AWK_PRINT_FILE_APPEND: + MATCH(awk,TOKEN_BOR)? XP_AWK_PRINT_PIPE: + MATCH(awk,TOKEN_BORAND)? XP_AWK_PRINT_COPROC: + XP_AWK_PRINT_CONSOLE; - if (out_type != -1) + if (out_type != XP_AWK_PRINT_CONSOLE) { if (__get_token(awk) == -1) { diff --git a/ase/awk/run.c b/ase/awk/run.c index c60c7972..59852dca 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.106 2006-06-22 14:15:01 bacon Exp $ + * $Id: run.c,v 1.107 2006-06-25 15:26:57 bacon Exp $ */ #include @@ -1162,6 +1162,33 @@ static int __run_print_statement (xp_awk_run_t* run, xp_awk_nde_print_t* nde) xp_printf (XP_T("eval_print PRINT_FILE not properly implemented....\n")); return -1; } + else if (p->out_type == XP_AWK_PRINT_CONSOLE) + { + xp_awk_nde_t* np; + int n, errnum; + + xp_assert (p->out == XP_NULL); + + for (np = p->args; np != XP_NULL; np = np->next) + { + v = __eval_expression (run, np); + if (v == XP_NULL) return -1; + xp_awk_refupval (v); + + /* console has the fixed name */ + n = xp_awk_writeextio ( + run, XP_AWK_EXTIO_CONSOLE, XP_T("console"), v, &errnum); + if (n < 0 && errnum != XP_AWK_ENOERR) + { + xp_awk_refdownval (run, v); + PANIC_I (run, errnum); + } + + xp_awk_refdownval (run, v); + } + + return 0; + } else if (p->out_type == XP_AWK_PRINT_FILE_APPEND) { xp_printf (XP_T("eval_print PRINT_FILE_APPEND not properly implemented....\n")); @@ -1169,7 +1196,7 @@ static int __run_print_statement (xp_awk_run_t* run, xp_awk_nde_print_t* nde) } else { - xp_assert (!"should never happen - wrong out_type for getline"); + xp_assert (!"should never happen - wrong out_type for print"); PANIC_I (run, XP_AWK_EINTERNAL); } } diff --git a/ase/awk/tree.c b/ase/awk/tree.c index e4fb6107..4800aab5 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -1,5 +1,5 @@ /* - * $Id: tree.c,v 1.56 2006-06-22 14:15:02 bacon Exp $ + * $Id: tree.c,v 1.57 2006-06-25 15:26:57 bacon Exp $ */ #include @@ -80,7 +80,8 @@ static const xp_char_t* __print_outop_str[] = XP_T("|"), XP_T("|&"), XP_T(">"), - XP_T(">>") + XP_T(">>"), + XP_T("") }; static void __print_tabs (int depth); diff --git a/ase/awk/tree.h b/ase/awk/tree.h index 10a698d2..a560d8c3 100644 --- a/ase/awk/tree.h +++ b/ase/awk/tree.h @@ -1,5 +1,5 @@ /* - * $Id: tree.h,v 1.48 2006-06-22 14:15:02 bacon Exp $ + * $Id: tree.h,v 1.49 2006-06-25 15:26:57 bacon Exp $ */ #ifndef _XP_AWK_TREE_H_ @@ -70,7 +70,8 @@ enum XP_AWK_PRINT_PIPE, XP_AWK_PRINT_COPROC, XP_AWK_PRINT_FILE, - XP_AWK_PRINT_FILE_APPEND + XP_AWK_PRINT_FILE_APPEND, + XP_AWK_PRINT_CONSOLE }; typedef struct xp_awk_afn_t xp_awk_afn_t; diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index 9c7af4f2..a2d4c8db 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.41 2006-06-22 04:25:44 bacon Exp $ + * $Id: awk.c,v 1.42 2006-06-25 15:26:57 bacon Exp $ */ #include @@ -248,6 +248,54 @@ xp_printf (XP_TEXT("closing %s of type %d\n"), epa->name, epa->type); return -1; } +static xp_ssize_t process_extio_console ( + int cmd, int opt, void* arg, xp_char_t* data, xp_size_t size) +{ + xp_awk_extio_t* epa = (xp_awk_extio_t*)arg; + + switch (cmd) + { + case XP_AWK_IO_OPEN: + { + /* TODO: OpenConsole in GUI APPLICATION */ + /* opt: XP_AWK_IO_CONSOLE_READ, + * XP_AWK_IO_CONSOLE_WRITE */ + + if (opt == XP_AWK_IO_CONSOLE_READ) + epa->handle = stdin; + else if (opt == XP_AWK_IO_CONSOLE_WRITE) + epa->handle = stdout; + else return -1; + } + + case XP_AWK_IO_CLOSE: + { + /* TODO: CloseConsole in GUI APPLICATION */ + } + + case XP_AWK_IO_READ: + { + if (_fgetts (data, size, (FILE*)epa->handle) == XP_NULL) + return 0; + return xp_strlen(data); + } + + case XP_AWK_IO_WRITE: + { + if (_fputts (data, /*size,*/ (FILE*)epa->handle) == XP_NULL) + return 0; + return size; + } + + case XP_AWK_IO_NEXT: + { + return -1; + } + + } + + return -1; +} #if defined(__STAND_ALONE) && !defined(_WIN32) static int __main (int argc, char* argv[]) @@ -289,6 +337,14 @@ static int __main (int argc, xp_char_t* argv[]) return -1; } + if (xp_awk_setextio (awk, + XP_AWK_EXTIO_CONSOLE, process_extio_console, XP_NULL) == -1) + { + xp_awk_close (awk); + xp_printf (XP_T("Error: cannot set extio file\n")); + return -1; + } + xp_awk_setparseopt (awk, XP_AWK_EXPLICIT | XP_AWK_UNIQUE | XP_AWK_DBLSLASHES | XP_AWK_SHADING | XP_AWK_IMPLICIT | XP_AWK_SHIFT | XP_AWK_EXTIO); diff --git a/ase/test/awk/t10.awk b/ase/test/awk/t10.awk index f251f8ad..bb92bb28 100644 --- a/ase/test/awk/t10.awk +++ b/ase/test/awk/t10.awk @@ -1,8 +1,9 @@ BEGIN { - print | "more"; - print >> "echo"; - print >> "echo"; + print "more"; + //print | "more"; + //print > "echo"; + //print >> "echo"; getline x < "abc"; /* open("abc", O_RDONLY|O_LARGEFILE) = 3 */ //print 10 >> "abc"; /* open("abc", O_WRONLY|O_APPEND|O_CREAT|O_LARGEFILE, 0666) = 4 */