*** empty log message ***

This commit is contained in:
hyung-hwan 2006-06-25 15:26:57 +00:00
parent 73e9adc303
commit a786fe2d1a
8 changed files with 117 additions and 36 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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