diff --git a/ase/awk/awk.h b/ase/awk/awk.h index e7d992fe..2dbe2afd 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.68 2006-06-21 11:44:55 bacon Exp $ + * $Id: awk.h,v 1.69 2006-06-21 13:52:15 bacon Exp $ */ #ifndef _XP_AWK_AWK_H_ @@ -18,6 +18,7 @@ typedef struct xp_awk_val_t xp_awk_val_t; struct xp_awk_extio_t { + int type; xp_char_t* name; void* handle; xp_awk_extio_t* next; diff --git a/ase/awk/awk_i.h b/ase/awk/awk_i.h index 97c45c2e..7d69b8cb 100644 --- a/ase/awk/awk_i.h +++ b/ase/awk/awk_i.h @@ -1,5 +1,5 @@ /* - * $Id: awk_i.h,v 1.20 2006-06-21 11:44:55 bacon Exp $ + * $Id: awk_i.h,v 1.21 2006-06-21 13:52:15 bacon Exp $ */ #ifndef _XP_AWK_AWKI_H_ @@ -163,16 +163,8 @@ struct xp_awk_run_t xp_str_t line; } input; - struct - { - xp_awk_extio_t* in_pipe; - xp_awk_extio_t* in_file; - /* - xp_awk_extio_t* out_pipe; - xp_awk_extio_t* out_file; - xp_awk_extio_t* coproc; - */ - } extio; + /* extio chain */ + xp_awk_extio_t* extio; int opt; int errnum; diff --git a/ase/awk/extio.c b/ase/awk/extio.c index 1b39142e..621acb3e 100644 --- a/ase/awk/extio.c +++ b/ase/awk/extio.c @@ -1,5 +1,5 @@ /* - * $Id: extio.c,v 1.5 2006-06-19 09:08:50 bacon Exp $ + * $Id: extio.c,v 1.6 2006-06-21 13:52:15 bacon Exp $ */ #include @@ -10,16 +10,17 @@ #include #endif -int xp_awk_readextio (xp_awk_run_t* run, - xp_awk_extio_t** extio, xp_awk_io_t handler, - const xp_char_t* name, int* errnum) +int xp_awk_readextio ( + xp_awk_run_t* run, int type, const xp_char_t* name, int* errnum) { - xp_awk_extio_t* p = *extio; + xp_awk_extio_t* p = run->extio; + xp_awk_io_t handler = run->awk->extio[type]; xp_bool_t extio_created = xp_false; while (p != XP_NULL) { - if (xp_strcmp(p->name,name) == 0) break; + if (p->type == type && + xp_strcmp(p->name,name) == 0) break; p = p->next; } @@ -40,6 +41,7 @@ int xp_awk_readextio (xp_awk_run_t* run, return -1; } + p->type = type; p->handle = XP_NULL; p->next = XP_NULL; extio_created = xp_true; @@ -79,8 +81,8 @@ int xp_awk_readextio (xp_awk_run_t* run, /* link it to the extio chain */ if (extio_created) { - p->next = *extio; - *extio = p; + p->next = run->extio; + run->extio = p; } { @@ -98,16 +100,20 @@ xp_printf(XP_TEXT("%s"), buf); return 1; } -int xp_awk_closeextio (xp_awk_run_t* run, - xp_awk_extio_t** extio, xp_awk_io_t handler, - const xp_char_t* name, int* errnum) +int xp_awk_closeextio (xp_awk_run_t* run, const xp_char_t* name, int* errnum) { - xp_awk_extio_t* p = *extio, * px = XP_NULL; + xp_awk_extio_t* p = run->extio, * px = XP_NULL; while (p != XP_NULL) { + /* it handles the first name that matches + * regardless of the extio type */ if (xp_strcmp(p->name,name) == 0) { + xp_awk_io_t handler = run->awk->extio[p->type]; + + /* TODO: io command should not be XP_AWK_INPUT_CLOSE + * it should have more generic form than this... */ if (handler (XP_AWK_INPUT_CLOSE, p, XP_NULL, 0) == -1) { /* this is not a run-time error.*/ @@ -119,7 +125,7 @@ int xp_awk_closeextio (xp_awk_run_t* run, //if (opt_remove_closed_extio) // TODO:... //{ if (px != XP_NULL) px->next = p->next; - else *extio = p->next; + else run->extio = p->next; xp_free (p->name); xp_free (p); @@ -135,3 +141,40 @@ int xp_awk_closeextio (xp_awk_run_t* run, *errnum = XP_AWK_ENOERR; return -1; } + +int xp_awk_clearextio (xp_awk_run_t* run, int* errnum) +{ + xp_awk_extio_t* p = run->extio; + xp_awk_extio_t* next; + xp_awk_io_t handler; + + while (p != XP_NULL) + { + handler = run->awk->extio[p->type]; + next = p->next; + + /* TODO: io command should not be XP_AWK_INPUT_CLOSE + * it should have more generic form than this... */ + if (handler (XP_AWK_INPUT_CLOSE, p, XP_NULL, 0) == -1) + { +/* TODO: should it be removed from the chain???? */ + /* this is not a run-time error.*/ + *errnum = XP_AWK_ENOERR; + return -1; + } + + p->handle = XP_NULL; + //if (opt_remove_closed_extio) // TODO:... + //{ + if (px != XP_NULL) px->next = p->next; + else run->extio = p->next; + + xp_free (p->name); + xp_free (p); + //} + + p = next; + } + + return 0; +} diff --git a/ase/awk/extio.h b/ase/awk/extio.h index 01fdb3ac..a40936e8 100644 --- a/ase/awk/extio.h +++ b/ase/awk/extio.h @@ -10,13 +10,10 @@ extern "C" #endif -int xp_awk_readextio (xp_awk_run_t* run, - xp_awk_extio_t** extio, xp_awk_io_t handler, - const xp_char_t* name, int* errnum); - -int xp_awk_closeextio (xp_awk_run_t* run, - xp_awk_extio_t** extio, xp_awk_io_t handler, - const xp_char_t* name, int* errnum); +int xp_awk_readextio ( + xp_awk_run_t* run, int type, const xp_char_t* name, int* errnum); +int xp_awk_closeextio ( + xp_awk_run_t* run, const xp_char_t* name, int* errnum); #ifdef __cplusplus } diff --git a/ase/awk/func.c b/ase/awk/func.c index ac56eaa6..a555640d 100644 --- a/ase/awk/func.c +++ b/ase/awk/func.c @@ -1,5 +1,5 @@ /* - * $Id: func.c,v 1.3 2006-06-21 11:44:55 bacon Exp $ + * $Id: func.c,v 1.4 2006-06-21 13:52:15 bacon Exp $ */ #include @@ -55,7 +55,6 @@ static int __bfn_close (void* run) return -1; } - /* n = xp_awk_closeextio (run, XP_STR_BUF(&buf), &errnum); if (n == -1 && errnum != XP_AWK_ENOERR) { @@ -63,9 +62,6 @@ static int __bfn_close (void* run) xp_awk_seterrnum (run, errnum); return -1; } - */ -n = -1; -xp_printf (XP_T("closing %s\n"), XP_STR_BUF(&buf)); xp_str_close (&buf); diff --git a/ase/awk/run.c b/ase/awk/run.c index 76b996ea..e063751b 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.102 2006-06-21 11:44:55 bacon Exp $ + * $Id: run.c,v 1.103 2006-06-21 13:52:15 bacon Exp $ */ #include @@ -261,10 +261,7 @@ static int __open_run ( return -1; } - /* TODO: */ - run->extio.in_pipe = XP_NULL; - run->extio.in_file = XP_NULL; - + run->extio = XP_NULL; return 0; } @@ -2943,9 +2940,7 @@ static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde) } xp_awk_refdownval (run, in); - n = xp_awk_readextio ( - run, &run->extio.in_pipe, - run->awk->extio[XP_AWK_EXTIO_PIPE], str, &errnum); + n = xp_awk_readextio (run, XP_AWK_EXTIO_PIPE, str, &errnum); xp_free (str); if (n < 0 && errnum != XP_AWK_ENOERR) PANIC (run, errnum); @@ -2974,9 +2969,7 @@ static xp_awk_val_t* __eval_getline (xp_awk_run_t* run, xp_awk_nde_t* nde) } xp_awk_refdownval (run, in); - n = xp_awk_readextio ( - run, &run->extio.in_file, - run->awk->extio[XP_AWK_EXTIO_FILE], str, &errnum); + n = xp_awk_readextio (run, XP_AWK_EXTIO_FILE, str, &errnum); xp_free (str); if (n < 0 && errnum != XP_AWK_ENOERR) PANIC (run, errnum); diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index 70ab45c1..72cccf35 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.39 2006-06-19 15:43:27 bacon Exp $ + * $Id: awk.c,v 1.40 2006-06-21 13:52:15 bacon Exp $ */ #include @@ -152,6 +152,7 @@ static xp_ssize_t process_extio_pipe ( case XP_AWK_INPUT_CLOSE: { +xp_printf (XP_TEXT("closing %s of type %d\n"), epa->name, epa->type); fclose ((FILE*)epa->handle); epa->handle = NULL; return 0; @@ -202,6 +203,7 @@ static xp_ssize_t process_extio_file ( case XP_AWK_INPUT_CLOSE: { +xp_printf (XP_TEXT("closing %s of type %d\n"), epa->name, epa->type); fclose ((FILE*)epa->handle); epa->handle = NULL; return 0; @@ -277,7 +279,7 @@ static int __main (int argc, xp_char_t* argv[]) } xp_awk_setparseopt (awk, - XP_AWK_EXPLICIT | XP_AWK_UNIQUE | + XP_AWK_EXPLICIT | XP_AWK_UNIQUE | XP_AWK_DBLSLASHES | XP_AWK_SHADING | XP_AWK_IMPLICIT | XP_AWK_SHIFT | XP_AWK_EXTIO); if (argc == 2) diff --git a/ase/test/awk/t10.awk b/ase/test/awk/t10.awk index 28d7729a..6de4b092 100644 --- a/ase/test/awk/t10.awk +++ b/ase/test/awk/t10.awk @@ -1,10 +1,10 @@ BEGIN { 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 */ + //print 10 >> "abc"; /* open("abc", O_WRONLY|O_APPEND|O_CREAT|O_LARGEFILE, 0666) = 4 */ getline x < "abc"; - print x; - close ("abc"); /* close(4) */ - print "hey" - close ("abc"); /* close(3) */ + //print x; + a = close ("abc"); /* close(4) */ + //print "hey" + b = close ("abc"); /* close(3) */ }