*** empty log message ***

This commit is contained in:
hyung-hwan 2006-06-21 13:52:15 +00:00
parent adca6e86fb
commit 0bef35ac1c
8 changed files with 79 additions and 55 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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 <xp/awk/awk_i.h>
@ -10,16 +10,17 @@
#include <xp/bas/memory.h>
#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;
}

View File

@ -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
}

View File

@ -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 <xp/awk/awk_i.h>
@ -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);

View File

@ -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 <xp/awk/awk_i.h>
@ -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);

View File

@ -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 <xp/awk/awk.h>
@ -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)

View File

@ -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) */
}