*** empty log message ***
This commit is contained in:
parent
e6dc5c7a66
commit
e198b2632d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: extio.c,v 1.37 2006-08-29 15:01:44 bacon Exp $
|
||||
* $Id: extio.c,v 1.38 2006-08-30 07:15:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -254,7 +254,8 @@ int xp_awk_readextio (
|
||||
if (rs_ptr == XP_NULL)
|
||||
{
|
||||
/* separate by a new line */
|
||||
if (c == XP_T('\n')) break;
|
||||
/* TODO: handle different line terminator like \r\n */
|
||||
if (c == XP_T('\n')) break;
|
||||
}
|
||||
else if (rs_len == 0)
|
||||
{
|
||||
@ -320,13 +321,50 @@ int xp_awk_readextio (
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO: handle difference line terminator like \r\n */
|
||||
/* TODO: handle different line terminator like \r\n */
|
||||
if (c == XP_T('\n')) line_len = 0;
|
||||
else line_len = line_len + 1;
|
||||
}
|
||||
|
||||
if (rs_ptr != XP_NULL && rs->type != XP_AWK_VAL_STR) xp_free (rs_ptr);
|
||||
xp_awk_refdownval (run, rs);
|
||||
|
||||
/* increment NR */
|
||||
if (ret != -1)
|
||||
{
|
||||
xp_awk_val_t* nr;
|
||||
xp_long_t lv;
|
||||
xp_real_t rv;
|
||||
|
||||
nr = xp_awk_getglobal (run, XP_AWK_GLOBAL_NR);
|
||||
xp_awk_refupval (nr);
|
||||
|
||||
n = xp_awk_valtonum (nr, &lv, &rv);
|
||||
xp_awk_refdownval (run, nr);
|
||||
|
||||
if (n == -1)
|
||||
{
|
||||
run->errnum = XP_AWK_EVALTYPE;
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (n == 1) lv = (xp_long_t)rv;
|
||||
|
||||
nr = xp_awk_makeintval (run, lv + 1);
|
||||
if (nr == XP_NULL)
|
||||
{
|
||||
run->errnum = XP_AWK_ENOMEM;
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xp_awk_setglobal (
|
||||
run, XP_AWK_GLOBAL_NR, nr) == -1) ret = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parse.c,v 1.169 2006-08-29 15:01:44 bacon Exp $
|
||||
* $Id: parse.c,v 1.170 2006-08-30 07:15:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -3700,7 +3700,7 @@ static int __get_charstr (xp_awk_t* awk)
|
||||
{
|
||||
if (awk->src.lex.curc != XP_T('\"'))
|
||||
{
|
||||
/* the starting quote has been comsumed before this function
|
||||
/* the starting quote has been consumed before this function
|
||||
* has been called */
|
||||
ADD_TOKEN_CHAR (awk, awk->src.lex.curc);
|
||||
}
|
||||
@ -3709,13 +3709,18 @@ static int __get_charstr (xp_awk_t* awk)
|
||||
|
||||
static int __get_rexstr (xp_awk_t* awk)
|
||||
{
|
||||
if (awk->src.lex.curc != XP_T('/'))
|
||||
if (awk->src.lex.curc == XP_T('/'))
|
||||
{
|
||||
/* the starting slash has been comsumed before this function
|
||||
* has been called */
|
||||
ADD_TOKEN_CHAR (awk, awk->src.lex.curc);
|
||||
/* this part of the function is different from __get_charstr
|
||||
* because of the way this function is called */
|
||||
GET_CHAR (awk);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ADD_TOKEN_CHAR (awk, awk->src.lex.curc);
|
||||
return __get_string (awk, XP_T('/'), XP_T('\\'), xp_true);
|
||||
}
|
||||
return __get_string (awk, XP_T('/'), XP_T('\\'), xp_true);
|
||||
}
|
||||
|
||||
static int __get_string (
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: rex.c,v 1.23 2006-08-16 15:21:17 bacon Exp $
|
||||
* $Id: rex.c,v 1.24 2006-08-30 07:15:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -348,9 +348,28 @@ int xp_awk_safematchrex (void* code,
|
||||
|
||||
void xp_awk_freerex (void* code)
|
||||
{
|
||||
xp_assert (code != XP_NULL);
|
||||
xp_free (code);
|
||||
}
|
||||
|
||||
xp_bool_t xp_awk_isemptyrex (void* code)
|
||||
{
|
||||
const xp_byte_t* p = code;
|
||||
xp_size_t nb, el;
|
||||
|
||||
xp_assert (p != XP_NULL);
|
||||
|
||||
nb = *(xp_size_t*)p; p += xp_sizeof(nb);
|
||||
el = *(xp_size_t*)p; p += xp_sizeof(el);
|
||||
|
||||
/* an empty regular expression look like:
|
||||
* | expression |
|
||||
* | header | branch |
|
||||
* | | branch header |
|
||||
* | NB(1) | EL(16) | NA(1) | BL(8) | */
|
||||
return (nb == 1 && el == xp_sizeof(xp_size_t)*4)? xp_true: xp_false;
|
||||
}
|
||||
|
||||
static int __build_pattern (__builder_t* builder)
|
||||
{
|
||||
int n;
|
||||
@ -1574,7 +1593,7 @@ static const xp_byte_t* __print_pattern (const xp_byte_t* p)
|
||||
|
||||
nb = *(xp_size_t*)p; p += xp_sizeof(nb);
|
||||
el = *(xp_size_t*)p; p += xp_sizeof(el);
|
||||
//xp_printf (XP_T("NA = %u, EL = %u\n"), (unsigned int)nb, (unsigned int)el);
|
||||
xp_printf (XP_T("NB = %u, EL = %u\n"), (unsigned int)nb, (unsigned int)el);
|
||||
|
||||
for (i = 0; i < nb; i++)
|
||||
{
|
||||
@ -1591,7 +1610,7 @@ static const xp_byte_t* __print_branch (const xp_byte_t* p)
|
||||
|
||||
na = *(xp_size_t*)p; p += xp_sizeof(na);
|
||||
bl = *(xp_size_t*)p; p += xp_sizeof(bl);
|
||||
//xp_printf (XP_T("NA = %u, BL = %u\n"), (unsigned int) na, (unsigned int)bl);
|
||||
xp_printf (XP_T("NA = %u, BL = %u\n"), (unsigned int) na, (unsigned int)bl);
|
||||
|
||||
for (i = 0; i < na; i++)
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: rex.h,v 1.13 2006-08-16 11:35:53 bacon Exp $
|
||||
* $Id: rex.h,v 1.14 2006-08-30 07:15:14 bacon Exp $
|
||||
**/
|
||||
|
||||
#ifndef _XP_AWK_REX_H_
|
||||
@ -62,6 +62,8 @@ int xp_awk_safematchrex (void* code,
|
||||
|
||||
void xp_awk_freerex (void* code);
|
||||
|
||||
xp_bool_t xp_awk_isemptyrex (void* code);
|
||||
|
||||
#ifndef XP_AWK_NTDDK
|
||||
void xp_awk_printrex (void* code);
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.c,v 1.182 2006-08-29 15:01:45 bacon Exp $
|
||||
* $Id: run.c,v 1.183 2006-08-30 07:15:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -622,12 +622,21 @@ static int __run_main (xp_awk_run_t* run)
|
||||
/* restore the stack_top with the saved value
|
||||
* instead of calling __raw_pop as many times as
|
||||
* the successful __raw_push. it is ok because
|
||||
* the values pushed so fare are all xp_awk_val_nil */
|
||||
* the values pushed so far are all xp_awk_val_nil */
|
||||
run->stack_top = saved_stack_top;
|
||||
PANIC_I (run, XP_AWK_ENOMEM);
|
||||
}
|
||||
}
|
||||
|
||||
if (xp_awk_setglobal (run, XP_AWK_GLOBAL_NR, xp_awk_val_zero) == -1)
|
||||
{
|
||||
/* it can simply restore the top of the stack this way
|
||||
* because the values pused onto the stack so far are
|
||||
* all xp_awk_val_nils */
|
||||
run->stack_top = saved_stack_top;
|
||||
return -1;
|
||||
}
|
||||
|
||||
run->exit_level = EXIT_NONE;
|
||||
|
||||
if (run->awk->option & XP_AWK_RUNMAIN)
|
||||
@ -1825,22 +1834,34 @@ static xp_awk_val_t* __eval_expression (xp_awk_run_t* run, xp_awk_nde_t* nde)
|
||||
|
||||
if (v->type == XP_AWK_VAL_REX)
|
||||
{
|
||||
xp_assert (run->inrec.d0->type == XP_AWK_VAL_STR);
|
||||
|
||||
xp_awk_refupval (v);
|
||||
n = xp_awk_matchrex (
|
||||
((xp_awk_val_rex_t*)v)->code,
|
||||
((xp_awk_val_str_t*)run->inrec.d0)->buf,
|
||||
((xp_awk_val_str_t*)run->inrec.d0)->len,
|
||||
XP_NULL, XP_NULL, &errnum);
|
||||
|
||||
if (n == -1)
|
||||
if (run->inrec.d0->type == XP_AWK_VAL_NIL)
|
||||
{
|
||||
xp_awk_refdownval (run, v);
|
||||
PANIC (run, errnum);
|
||||
/* the record has never been read.
|
||||
* probably, this functions has been triggered
|
||||
* by the statements in the BEGIN block */
|
||||
n = xp_awk_isemptyrex(
|
||||
((xp_awk_val_rex_t*)v)->code)? 1: 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
xp_assert (run->inrec.d0->type == XP_AWK_VAL_STR);
|
||||
|
||||
xp_awk_refdownval (run, v);
|
||||
xp_awk_refupval (v);
|
||||
n = xp_awk_matchrex (
|
||||
((xp_awk_val_rex_t*)v)->code,
|
||||
((xp_awk_val_str_t*)run->inrec.d0)->buf,
|
||||
((xp_awk_val_str_t*)run->inrec.d0)->len,
|
||||
XP_NULL, XP_NULL, &errnum);
|
||||
|
||||
if (n == -1)
|
||||
{
|
||||
xp_awk_refdownval (run, v);
|
||||
PANIC (run, errnum);
|
||||
}
|
||||
|
||||
xp_awk_refdownval (run, v);
|
||||
|
||||
}
|
||||
|
||||
v = xp_awk_makeintval (run, (n != 0));
|
||||
if (v == XP_NULL) PANIC (run, XP_AWK_ENOMEM);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: sa.h,v 1.31 2006-08-16 11:35:54 bacon Exp $
|
||||
* $Id: sa.h,v 1.32 2006-08-30 07:15:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _XP_AWK_SA_H_
|
||||
@ -96,6 +96,7 @@
|
||||
#define XP_STR_SIZE(x) ((x)->size + 1)
|
||||
#define XP_STR_CAPA(x) ((x)->capa)
|
||||
#define XP_STR_BUF(x) ((x)->buf)
|
||||
#define XP_STR_CHAR(x,idx) ((x)->buf[idx])
|
||||
|
||||
typedef struct xp_str_t xp_str_t;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c,v 1.78 2006-08-28 14:30:08 bacon Exp $
|
||||
* $Id: awk.c,v 1.79 2006-08-30 07:15:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk.h>
|
||||
@ -567,7 +567,8 @@ static int __main (int argc, xp_char_t* argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
opt = XP_AWK_EXPLICIT | XP_AWK_UNIQUE | XP_AWK_DBLSLASHES |
|
||||
opt = XP_AWK_EXPLICIT | XP_AWK_UNIQUE | XP_AWK_HASHSIGN |
|
||||
/*XP_AWK_DBLSLASHES |*/
|
||||
XP_AWK_SHADING | XP_AWK_IMPLICIT | XP_AWK_SHIFT |
|
||||
XP_AWK_EXTIO | XP_AWK_BLOCKLESS | XP_AWK_STRINDEXONE;
|
||||
|
||||
|
@ -19,7 +19,8 @@ int xp_main (int argc, const xp_char_t* argv[])
|
||||
//ptn = XP_T("^he.llo(jo(in|kk)s|com)+h*e{1,40}abc|[^abc][de-f]|^he.llo(jo(in|kk)s|com)+h*e{1,40}abc|[^abc][de-f]");
|
||||
//ptn = XP_T("^he.llo(jo(in|kk)s|com)+h*e{1,40}abc|[^abc][de-f]");
|
||||
//ptn = XP_T("^he.llo(jo(in|kk)s|com)|[^x[:space:][:alpha:]j][^abc][de-f]|^he.llo(jo(in|kk)s|com)|[^x[:space:][:alpha:]j][^abc][de-f]");
|
||||
ptn = XP_T("^.{0,2}.z[^[:space:]]+(abc|zzz){1,2}khg");
|
||||
//ptn = XP_T("^.{0,2}.z[^[:space:]]+(abc|zzz){1,2}khg");
|
||||
ptn = XP_T("");
|
||||
|
||||
rex = xp_awk_buildrex (ptn, xp_strlen(ptn), &errnum);
|
||||
if (rex == XP_NULL)
|
||||
@ -28,6 +29,7 @@ int xp_main (int argc, const xp_char_t* argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
xp_printf (XP_T("isemptyrex => %d\n"), xp_awk_isemptyrex (rex));
|
||||
xp_printf (XP_T("NA: %u\n"), (unsigned int)XP_AWK_REX_NA(rex));
|
||||
xp_printf (XP_T("LEN: %u\n"), (unsigned int)XP_AWK_REX_LEN(rex));
|
||||
xp_awk_printrex (rex);
|
||||
|
@ -1,2 +1,2 @@
|
||||
BEGIN { /*RS = "Asia";*/ /*RS=746;*/ RS=/USA/; }
|
||||
{ print "RECORD: ", $0; }
|
||||
BEGIN { /*RS = "Asia";*/ /*RS=746;*/ /*RS="";*/ RS=/USA/; }
|
||||
{ print NR, " ", $0; }
|
||||
|
@ -5,7 +5,7 @@ BEGIN {
|
||||
delete NF;
|
||||
print "NF[1]=", NF[1];
|
||||
|
||||
NF[1] = 20; // this line should not be allowed
|
||||
NF[1] = 20; # this line should not be allowed
|
||||
print "AWK IMPLEMENTATION ERROR: hey... NF[1] = 20 has succeeded in the BEGIN block. your interpreter must be wrong";
|
||||
print "NF[1]=", NF[1];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user