*** empty log message ***

This commit is contained in:
hyung-hwan 2006-07-30 15:53:42 +00:00
parent e6be1240e1
commit 913b7dd072
9 changed files with 136 additions and 82 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.61 2006-07-28 10:34:21 bacon Exp $ * $Id: awk.c,v 1.62 2006-07-30 15:53:42 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -229,7 +229,6 @@ xp_size_t xp_awk_getsrcline (xp_awk_t* awk)
return awk->token.line; return awk->token.line;
} }
/* TODO: imrove this... should it close io when it is overridden with a new handler??? */ /* TODO: imrove this... should it close io when it is overridden with a new handler??? */
int xp_awk_setextio (xp_awk_t* awk, int id, xp_awk_io_t handler, void* arg) int xp_awk_setextio (xp_awk_t* awk, int id, xp_awk_io_t handler, void* arg)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h,v 1.83 2006-07-28 10:34:21 bacon Exp $ * $Id: awk.h,v 1.84 2006-07-30 15:53:42 bacon Exp $
*/ */
#ifndef _XP_AWK_AWK_H_ #ifndef _XP_AWK_AWK_H_
@ -61,16 +61,37 @@ enum
/* parse options */ /* parse options */
enum enum
{ {
XP_AWK_IMPLICIT = (1 << 0), /* allow undeclared variables */ /* allow undeclared variables */
XP_AWK_EXPLICIT = (1 << 1), /* variable requires explicit declaration */ XP_AWK_IMPLICIT = (1 << 0),
XP_AWK_UNIQUE = (1 << 2), /* a function name should not coincide to be a variable name */
XP_AWK_SHADING = (1 << 3), /* allow variable shading */
XP_AWK_SHIFT = (1 << 4), /* support shift operators */
XP_AWK_HASHSIGN = (1 << 5), /* support comments by a hash sign */
XP_AWK_DBLSLASHES = (1 << 6), /* support comments by double slashes */
XP_AWK_EXTIO = (1 << 7) /* support getline and print */ /* variable requires explicit declaration */
XP_AWK_EXPLICIT = (1 << 1),
/* a function name should not coincide to be a variable name */
XP_AWK_UNIQUE = (1 << 2),
/* allow variable shading */
XP_AWK_SHADING = (1 << 3),
/* support shift operators */
XP_AWK_SHIFT = (1 << 4),
/* support comments by a hash sign */
XP_AWK_HASHSIGN = (1 << 5),
/* support comments by double slashes */
XP_AWK_DBLSLASHES = (1 << 6),
/* support string concatenation in tokenization.
* this option can change the behavior of a certain construct.
* getline < "abc" ".def" is treated as if it is getline < "abc.def"
* when this option is on. If this option is off, the same expression
* is treated as if it is (getline < "abc") ".def". */
XP_AWK_STRCONCAT = (1 << 7),
/* support getline and print */
XP_AWK_EXTIO = (1 << 8)
}; };
/* run options */ /* run options */
@ -177,10 +198,9 @@ void xp_awk_setrunopt (xp_awk_t* awk, int opt);
int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg); int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg);
int xp_awk_detsrc (xp_awk_t* awk); int xp_awk_detsrc (xp_awk_t* awk);
xp_size_t xp_awk_getsrcline (xp_awk_t* awk);
int xp_awk_setextio (xp_awk_t* awk, int id, xp_awk_io_t handler, void* arg); int xp_awk_setextio (xp_awk_t* awk, int id, xp_awk_io_t handler, void* arg);
xp_size_t xp_awk_getsrcline (xp_awk_t* awk);
int xp_awk_parse (xp_awk_t* awk); int xp_awk_parse (xp_awk_t* awk);
int xp_awk_run (xp_awk_t* awk); int xp_awk_run (xp_awk_t* awk);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: extio.c,v 1.21 2006-07-28 10:34:21 bacon Exp $ * $Id: extio.c,v 1.22 2006-07-30 15:53:42 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -144,7 +144,10 @@ int xp_awk_readextio (
xp_free (p->name); xp_free (p->name);
xp_free (p); xp_free (p);
/* TODO: set ERRNO */ /* TODO: use meaningful error code */
xp_awk_setglobal (run,
XP_AWK_GLOBAL_ERRNO, xp_awk_val_one);
*errnum = XP_AWK_ENOERR; *errnum = XP_AWK_ENOERR;
return -1; return -1;
} }
@ -183,7 +186,10 @@ int xp_awk_readextio (
if (n == -1) if (n == -1)
{ {
/* handler error. getline should return -1 */ /* handler error. getline should return -1 */
/* TODO: set ERRNO */ /* TODO: use meaningful error code */
xp_awk_setglobal (run,
XP_AWK_GLOBAL_ERRNO, xp_awk_val_one);
*errnum = XP_AWK_ENOERR; *errnum = XP_AWK_ENOERR;
return -1; return -1;
} }
@ -238,19 +244,22 @@ int xp_awk_writeextio (
return -1; return -1;
} }
/* TODO: optimize the buffer management. if (v->type != XP_AWK_VAL_STR)
* each xp_awk_run_t may have a buffer for this. */
if (xp_str_open (&buf, 256) == XP_NULL)
{ {
*errnum = XP_AWK_ENOMEM; /* TODO: optimize the buffer management.
return -1; * each xp_awk_run_t may have a buffer for this. */
} if (xp_str_open (&buf, 256) == XP_NULL)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
/* convert the value to string representation first */ /* convert the value to string representation first */
if (xp_awk_valtostr(v, errnum, &buf, XP_NULL) == XP_NULL) if (xp_awk_valtostr(v, errnum, &buf, XP_NULL) == XP_NULL)
{ {
xp_str_close (&buf); xp_str_close (&buf);
return -1; return -1;
}
} }
/* look for the corresponding extio for name */ /* look for the corresponding extio for name */
@ -278,7 +287,7 @@ int xp_awk_writeextio (
p = (xp_awk_extio_t*) xp_malloc (xp_sizeof(xp_awk_extio_t)); p = (xp_awk_extio_t*) xp_malloc (xp_sizeof(xp_awk_extio_t));
if (p == XP_NULL) if (p == XP_NULL)
{ {
xp_str_close (&buf); if (v->type != XP_AWK_VAL_STR) xp_str_close (&buf);
*errnum = XP_AWK_ENOMEM; *errnum = XP_AWK_ENOMEM;
return -1; return -1;
} }
@ -287,7 +296,7 @@ int xp_awk_writeextio (
if (p->name == XP_NULL) if (p->name == XP_NULL)
{ {
xp_free (p); xp_free (p);
xp_str_close (&buf); if (v->type != XP_AWK_VAL_STR) xp_str_close (&buf);
*errnum = XP_AWK_ENOMEM; *errnum = XP_AWK_ENOMEM;
return -1; return -1;
} }
@ -302,9 +311,12 @@ int xp_awk_writeextio (
{ {
xp_free (p->name); xp_free (p->name);
xp_free (p); xp_free (p);
xp_str_close (&buf); if (v->type != XP_AWK_VAL_STR) xp_str_close (&buf);
/* TODO: set ERRNO */ /* TODO: use meaningful error code */
xp_awk_setglobal (run,
XP_AWK_GLOBAL_ERRNO, xp_awk_val_one);
*errnum = XP_AWK_ENOERR; *errnum = XP_AWK_ENOERR;
return -1; return -1;
} }
@ -322,21 +334,35 @@ int xp_awk_writeextio (
/* TODO: if write handler returns less than the request, loop */ /* TODO: if write handler returns less than the request, loop */
/* TODO: */ /* TODO: */
/* TODO: */ /* TODO: */
n = handler (XP_AWK_IO_WRITE, p, if (v->type != XP_AWK_VAL_STR)
XP_STR_BUF(&buf), XP_STR_LEN(&buf)); {
n = handler (XP_AWK_IO_WRITE, p,
XP_STR_BUF(&buf), XP_STR_LEN(&buf));
}
else
{
n = handler (XP_AWK_IO_WRITE, p,
((xp_awk_val_str_t*)v)->buf,
((xp_awk_val_str_t*)v)->len);
}
if (n == -1) if (n == -1)
{ {
xp_str_close (&buf); if (v->type != XP_AWK_VAL_STR) xp_str_close (&buf);
/* TODO: use meaningful error code */
xp_awk_setglobal (run,
XP_AWK_GLOBAL_ERRNO, xp_awk_val_one);
*errnum = XP_AWK_ENOERR;
return -1; return -1;
} }
if (n == 0) if (n == 0)
{ {
xp_str_close (&buf); if (v->type != XP_AWK_VAL_STR) xp_str_close (&buf);
return 0; return 0;
} }
xp_str_close (&buf); if (v->type != XP_AWK_VAL_STR) xp_str_close (&buf);
return 1; return 1;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c,v 1.144 2006-07-28 10:36:30 bacon Exp $ * $Id: parse.c,v 1.145 2006-07-30 15:53:42 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -2084,7 +2084,9 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
return XP_NULL; return XP_NULL;
} }
in = __parse_expression (awk); /* TODO: is this correct? */
/*in = __parse_expression (awk);*/
in = __parse_primary (awk);
if (in == XP_NULL) if (in == XP_NULL)
{ {
if (var != XP_NULL) xp_awk_clrpt (var); if (var != XP_NULL) xp_awk_clrpt (var);
@ -3109,7 +3111,8 @@ static int __get_token (xp_awk_t* awk)
SET_TOKEN_TYPE (awk, TOKEN_STR); SET_TOKEN_TYPE (awk, TOKEN_STR);
if (__get_string(awk) == -1) return -1; if (__get_string(awk) == -1) return -1;
while (1)
while (awk->opt.parse & XP_AWK_STRCONCAT)
{ {
do do
{ {
@ -3123,6 +3126,7 @@ static int __get_token (xp_awk_t* awk)
if (__get_string(awk) == -1) return -1; if (__get_string(awk) == -1) return -1;
} }
} }
else if (c == XP_T('=')) else if (c == XP_T('='))
{ {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.143 2006-07-28 10:36:30 bacon Exp $ * $Id: run.c,v 1.144 2006-07-30 15:53:42 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -460,7 +460,7 @@ static int __run_main (xp_awk_run_t* run)
if (__run_block (run, blk) == -1) n = -1; if (__run_block (run, blk) == -1) n = -1;
} }
if (n == 0) if (n == 0 && run->awk->tree.chain != XP_NULL)
{ {
if (__run_pattern_blocks (run) == -1) n = -1; if (__run_pattern_blocks (run) == -1) n = -1;
} }
@ -626,7 +626,9 @@ static int __run_pattern_block_chain (xp_awk_run_t* run, xp_awk_chain_t* chain)
} }
else else
{ {
/* pattern, pattern { ... } */
xp_assert (ptn->next->next == XP_NULL); xp_assert (ptn->next->next == XP_NULL);
/* TODO: implement this */ /* TODO: implement this */
xp_awk_refdownval (run, v1); xp_awk_refdownval (run, v1);
xp_printf (XP_T("ERROR: pattern, pattern NOT OMPLEMENTED\n")); xp_printf (XP_T("ERROR: pattern, pattern NOT OMPLEMENTED\n"));
@ -1388,14 +1390,7 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
if (p->args == XP_NULL) if (p->args == XP_NULL)
{ {
/* TODO: get $0 ans use it for v */ v = run->inrec.d0;
v = xp_awk_makestrval0 (
XP_T("<TODO: PRINT $0 WITH A TRAILING NEWLINE>\n"));
if (v == XP_NULL)
{
if (out != XP_NULL) xp_free (out);
PANIC_I (run, XP_AWK_ENOMEM);
}
xp_awk_refupval (v); xp_awk_refupval (v);
n = xp_awk_writeextio (run, p->out_type, dst, v, &errnum); n = xp_awk_writeextio (run, p->out_type, dst, v, &errnum);
@ -1434,30 +1429,30 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
/* TODO: print proper field separator */ /* TODO: print proper field separator */
} }
/* TODO: predefine the new line string
* for performance improvement*/
v = xp_awk_makestrval (XP_T("\n"), 1);
if (v == XP_NULL)
{
if (out != XP_NULL) xp_free (out);
PANIC_I (run, XP_AWK_ENOMEM);
}
xp_awk_refupval (v);
n = xp_awk_writeextio (
run, p->out_type, dst, v, &errnum);
if (n < 0 && errnum != XP_AWK_ENOERR)
{
if (out != XP_NULL) xp_free (out);
xp_awk_refdownval (run, v);
PANIC_I (run, errnum);
}
xp_awk_refdownval (run, v);
/* TODO: how to handle n == -1 && errnum == XP_AWK_ENOERR. that is the user handler returned an error... */
} }
/* TODO: predefine the new line string
* for performance improvement*/
v = xp_awk_makestrval (XP_T("\n"), 1);
if (v == XP_NULL)
{
if (out != XP_NULL) xp_free (out);
PANIC_I (run, XP_AWK_ENOMEM);
}
xp_awk_refupval (v);
n = xp_awk_writeextio (
run, p->out_type, dst, v, &errnum);
if (n < 0 && errnum != XP_AWK_ENOERR)
{
if (out != XP_NULL) xp_free (out);
xp_awk_refdownval (run, v);
PANIC_I (run, errnum);
}
xp_awk_refdownval (run, v);
/* TODO: how to handle n == -1 && errnum == XP_AWK_ENOERR. that is the user handler returned an error... */
if (out != XP_NULL) xp_free (out); if (out != XP_NULL) xp_free (out);
return 0; return 0;
} }
@ -1661,6 +1656,7 @@ static xp_awk_val_t* __do_assignment_scalar (
PANIC (run, XP_AWK_ENOTSCALARIZABLE); PANIC (run, XP_AWK_ENOTSCALARIZABLE);
} }
/* TODO: if var->id.idxa == XP_AWK_GLOBAL_NF recompute $0, etc */
xp_awk_refdownval (run, old); xp_awk_refdownval (run, old);
STACK_GLOBAL(run,var->id.idxa) = val; STACK_GLOBAL(run,var->id.idxa) = val;
xp_awk_refupval (val); xp_awk_refupval (val);

View File

@ -17,7 +17,6 @@ BEGIN
getline x < "abc"; getline x < "abc";
if (x == "a") print "xxxxxxxxxxxxxxxx"; else print x; if (x == "a") print "xxxxxxxxxxxxxxxx"; else print x;
*/ */
/* /*
@ -26,9 +25,13 @@ BEGIN
print "--------------"; print "--------------";
*/ */
getline x < "abc"; if (getline x < "abc" == -1)
print x > "abc"; {
print "ERRNO = ", ERRNO;
}
print (1 (2 getline j) j); print x > "def";
print "abc" 1 + 2 3 + 49 2 / 3;
// print (1 (2 getline j) j);
// print "abc" 1 + 2 3 + 49 2 / 3;
} }

View File

@ -1,7 +1,7 @@
/hello/ /hello/
{ {
//print FILENAME; //print FILENAME;
print "**1**" $0; print "**1**" $0;
//nextfile; //nextfile;
print "----------------"; print "----------------";
} }

View File

@ -1,13 +1,14 @@
BEGIN BEGIN
{ {
j = -20;
for (i = -10; i < 10; i++) for (i = -10; i < 10; i++)
{ {
if (i == 5) exit; /*break;*/ if (i == 5) exit;
//if (i == 5) break;
} }
j = -10;
while (j < 10) while (j < 10)
{ {
if (j == 5) break; if (j == 5) break;
@ -15,3 +16,8 @@ BEGIN
} }
} }
END
{
print "i = ", i;
print "j = ", j;
}

View File

@ -1,5 +1,5 @@
/* /*
* $Id: types.h,v 1.51 2006-07-28 17:20:27 bacon Exp $ * $Id: types.h,v 1.52 2006-07-30 15:53:42 bacon Exp $
*/ */
#ifndef _XP_TYPES_H_ #ifndef _XP_TYPES_H_
@ -213,7 +213,7 @@ typedef int xp_mcint_t;
#if defined(vms) || defined(__vms) #if defined(vms) || defined(__vms)
typedef unsigned int xp_wchar_t; typedef unsigned int xp_wchar_t;
typedef int xp_wcint_t; typedef int xp_wcint_t;
#if XP_SIZEOF_LONG == 4 #elif XP_SIZEOF_LONG == 4
typedef long xp_wchar_t; typedef long xp_wchar_t;
typedef long xp_wcint_t; typedef long xp_wcint_t;
#else #else