*** 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>
@ -229,7 +229,6 @@ xp_size_t xp_awk_getsrcline (xp_awk_t* awk)
return awk->token.line;
}
/* 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)
{

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_
@ -62,15 +62,36 @@ enum
/* parse options */
enum
{
XP_AWK_IMPLICIT = (1 << 0), /* allow undeclared variables */
XP_AWK_EXPLICIT = (1 << 1), /* variable requires explicit declaration */
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 */
/* allow undeclared variables */
XP_AWK_IMPLICIT = (1 << 0),
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 */
@ -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_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);
xp_size_t xp_awk_getsrcline (xp_awk_t* awk);
int xp_awk_parse (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>
@ -144,7 +144,10 @@ int xp_awk_readextio (
xp_free (p->name);
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;
return -1;
}
@ -183,7 +186,10 @@ int xp_awk_readextio (
if (n == -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;
return -1;
}
@ -238,6 +244,8 @@ int xp_awk_writeextio (
return -1;
}
if (v->type != XP_AWK_VAL_STR)
{
/* TODO: optimize the buffer management.
* each xp_awk_run_t may have a buffer for this. */
if (xp_str_open (&buf, 256) == XP_NULL)
@ -252,6 +260,7 @@ int xp_awk_writeextio (
xp_str_close (&buf);
return -1;
}
}
/* look for the corresponding extio for name */
while (p != XP_NULL)
@ -278,7 +287,7 @@ int xp_awk_writeextio (
p = (xp_awk_extio_t*) xp_malloc (xp_sizeof(xp_awk_extio_t));
if (p == XP_NULL)
{
xp_str_close (&buf);
if (v->type != XP_AWK_VAL_STR) xp_str_close (&buf);
*errnum = XP_AWK_ENOMEM;
return -1;
}
@ -287,7 +296,7 @@ int xp_awk_writeextio (
if (p->name == XP_NULL)
{
xp_free (p);
xp_str_close (&buf);
if (v->type != XP_AWK_VAL_STR) xp_str_close (&buf);
*errnum = XP_AWK_ENOMEM;
return -1;
}
@ -302,9 +311,12 @@ int xp_awk_writeextio (
{
xp_free (p->name);
xp_free (p);
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);
/* TODO: set ERRNO */
*errnum = XP_AWK_ENOERR;
return -1;
}
@ -322,21 +334,35 @@ int xp_awk_writeextio (
/* TODO: if write handler returns less than the request, loop */
/* TODO: */
/* TODO: */
if (v->type != XP_AWK_VAL_STR)
{
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)
{
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;
}
if (n == 0)
{
xp_str_close (&buf);
if (v->type != XP_AWK_VAL_STR) xp_str_close (&buf);
return 0;
}
xp_str_close (&buf);
if (v->type != XP_AWK_VAL_STR) xp_str_close (&buf);
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>
@ -2084,7 +2084,9 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
return XP_NULL;
}
in = __parse_expression (awk);
/* TODO: is this correct? */
/*in = __parse_expression (awk);*/
in = __parse_primary (awk);
if (in == XP_NULL)
{
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);
if (__get_string(awk) == -1) return -1;
while (1)
while (awk->opt.parse & XP_AWK_STRCONCAT)
{
do
{
@ -3123,6 +3126,7 @@ static int __get_token (xp_awk_t* awk)
if (__get_string(awk) == -1) return -1;
}
}
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>
@ -460,7 +460,7 @@ static int __run_main (xp_awk_run_t* run)
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;
}
@ -626,7 +626,9 @@ static int __run_pattern_block_chain (xp_awk_run_t* run, xp_awk_chain_t* chain)
}
else
{
/* pattern, pattern { ... } */
xp_assert (ptn->next->next == XP_NULL);
/* TODO: implement this */
xp_awk_refdownval (run, v1);
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)
{
/* TODO: get $0 ans use it for v */
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);
}
v = run->inrec.d0;
xp_awk_refupval (v);
n = xp_awk_writeextio (run, p->out_type, dst, v, &errnum);
@ -1434,6 +1429,7 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
/* TODO: print proper field separator */
}
}
/* TODO: predefine the new line string
* for performance improvement*/
@ -1456,7 +1452,6 @@ static int __run_print (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
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);
return 0;
@ -1661,6 +1656,7 @@ static xp_awk_val_t* __do_assignment_scalar (
PANIC (run, XP_AWK_ENOTSCALARIZABLE);
}
/* TODO: if var->id.idxa == XP_AWK_GLOBAL_NF recompute $0, etc */
xp_awk_refdownval (run, old);
STACK_GLOBAL(run,var->id.idxa) = val;
xp_awk_refupval (val);

View File

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

View File

@ -1,13 +1,14 @@
BEGIN
{
j = -20;
for (i = -10; i < 10; i++)
{
if (i == 5) exit; /*break;*/
if (i == 5) exit;
//if (i == 5) break;
}
j = -10;
while (j < 10)
{
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_
@ -213,7 +213,7 @@ typedef int xp_mcint_t;
#if defined(vms) || defined(__vms)
typedef unsigned int xp_wchar_t;
typedef int xp_wcint_t;
#if XP_SIZEOF_LONG == 4
#elif XP_SIZEOF_LONG == 4
typedef long xp_wchar_t;
typedef long xp_wcint_t;
#else