*** empty log message ***
This commit is contained in:
parent
5fef89a690
commit
dbe1b14a23
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: misc.c,v 1.14 2006-09-05 04:10:24 bacon Exp $
|
* $Id: misc.c,v 1.15 2006-09-05 15:18:15 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -659,9 +659,14 @@ xp_char_t* xp_awk_strxntokbyrex (
|
|||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
xp_char_t* match_ptr;
|
xp_char_t* match_ptr;
|
||||||
xp_size_t match_len;
|
xp_size_t match_len, i;
|
||||||
|
const xp_char_t* p = s;
|
||||||
|
xp_size_t left = len;
|
||||||
|
|
||||||
n = xp_awk_matchrex (awk, rex, s, len, &match_ptr, &match_len, errnum);
|
// TODO:...
|
||||||
|
while (len > 0)
|
||||||
|
{
|
||||||
|
n = xp_awk_matchrex (awk, rex, p, left, &match_ptr, &match_len, errnum);
|
||||||
if (n == -1) return XP_NULL;
|
if (n == -1) return XP_NULL;
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
{
|
{
|
||||||
@ -674,9 +679,44 @@ xp_char_t* xp_awk_strxntokbyrex (
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert (n == 1);
|
assert (n == 1);
|
||||||
|
|
||||||
|
if (match_len == 0)
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
left--;
|
||||||
|
}
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len == 0)
|
||||||
|
{
|
||||||
|
*tok = (xp_char_t*)s;
|
||||||
|
*tok_len = len;
|
||||||
|
*errnum = XP_AWK_ENOERR;
|
||||||
|
return XP_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
//xp_printf (XP_T("%d [%s]\n"), match_len, match_ptr);
|
||||||
|
if (match_len == 0 && s == match_ptr && len > 0)
|
||||||
|
{
|
||||||
|
//xp_printf (XP_T("%d [%s]\n"), match_len, match_ptr);
|
||||||
|
match_ptr++;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
*tok = (xp_char_t*)s;
|
*tok = (xp_char_t*)s;
|
||||||
*tok_len = match_ptr - s;
|
*tok_len = match_ptr - s;
|
||||||
|
|
||||||
|
for (i = 0; i < match_len; i++)
|
||||||
|
{
|
||||||
|
if (!XP_AWK_ISSPACE(awk, match_ptr[i]))
|
||||||
|
{
|
||||||
|
*errnum = XP_AWK_ENOERR;
|
||||||
|
return match_ptr+match_len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
*errnum = XP_AWK_ENOERR;
|
*errnum = XP_AWK_ENOERR;
|
||||||
return (match_ptr+match_len >= s+len)? XP_NULL: (match_ptr+match_len);
|
return (match_ptr+match_len >= s+len)? XP_NULL: (match_ptr+match_len);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: rex.c,v 1.27 2006-09-01 07:18:40 bacon Exp $
|
* $Id: rex.c,v 1.28 2006-09-05 15:18:16 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -154,7 +154,7 @@ static int __build_pattern0 (__builder_t* rex);
|
|||||||
static int __build_branch (__builder_t* rex);
|
static int __build_branch (__builder_t* rex);
|
||||||
static int __build_atom (__builder_t* rex);
|
static int __build_atom (__builder_t* rex);
|
||||||
static int __build_charset (__builder_t* rex, struct __code_t* cmd);
|
static int __build_charset (__builder_t* rex, struct __code_t* cmd);
|
||||||
static int __build_boundary (__builder_t* rex, struct __code_t* cmd);
|
static int __build_occurrences (__builder_t* rex, struct __code_t* cmd);
|
||||||
static int __build_cclass (__builder_t* rex, xp_char_t* cc);
|
static int __build_cclass (__builder_t* rex, xp_char_t* cc);
|
||||||
static int __build_range (__builder_t* rex, struct __code_t* cmd);
|
static int __build_range (__builder_t* rex, struct __code_t* cmd);
|
||||||
static int __next_char (__builder_t* rex, int level);
|
static int __next_char (__builder_t* rex, int level);
|
||||||
@ -186,7 +186,7 @@ static const xp_byte_t* __match_charset (
|
|||||||
static const xp_byte_t* __match_group (
|
static const xp_byte_t* __match_group (
|
||||||
__matcher_t* matcher, const xp_byte_t* base, __match_t* mat);
|
__matcher_t* matcher, const xp_byte_t* base, __match_t* mat);
|
||||||
|
|
||||||
static const xp_byte_t* __match_boundary (
|
static const xp_byte_t* __match_occurrences (
|
||||||
__matcher_t* matcher, xp_size_t si, const xp_byte_t* p,
|
__matcher_t* matcher, xp_size_t si, const xp_byte_t* p,
|
||||||
xp_size_t lbound, xp_size_t ubound, __match_t* mat);
|
xp_size_t lbound, xp_size_t ubound, __match_t* mat);
|
||||||
|
|
||||||
@ -308,6 +308,7 @@ int xp_awk_matchrex (
|
|||||||
__matcher_t matcher;
|
__matcher_t matcher;
|
||||||
__match_t mat;
|
__match_t mat;
|
||||||
xp_size_t offset = 0;
|
xp_size_t offset = 0;
|
||||||
|
/*const xp_char_t* match_ptr_zero = XP_NULL;*/
|
||||||
|
|
||||||
matcher.awk = awk;
|
matcher.awk = awk;
|
||||||
|
|
||||||
@ -321,7 +322,7 @@ int xp_awk_matchrex (
|
|||||||
matcher.depth.cur = 0;
|
matcher.depth.cur = 0;
|
||||||
|
|
||||||
mat.matched = xp_false;
|
mat.matched = xp_false;
|
||||||
/* TODO: shoud it allow an offset here??? */
|
/* TODO: should it allow an offset here??? */
|
||||||
mat.match_ptr = str + offset;
|
mat.match_ptr = str + offset;
|
||||||
|
|
||||||
while (mat.match_ptr < matcher.match.str.end)
|
while (mat.match_ptr < matcher.match.str.end)
|
||||||
@ -334,14 +335,35 @@ int xp_awk_matchrex (
|
|||||||
|
|
||||||
if (mat.matched)
|
if (mat.matched)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
if (mat.match_len == 0)
|
||||||
|
{
|
||||||
|
if (match_ptr_zero == XP_NULL)
|
||||||
|
match_ptr_zero = mat.match_ptr;
|
||||||
|
mat.match_ptr++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (match_ptr != XP_NULL) *match_ptr = mat.match_ptr;
|
if (match_ptr != XP_NULL) *match_ptr = mat.match_ptr;
|
||||||
if (match_len != XP_NULL) *match_len = mat.match_len;
|
if (match_len != XP_NULL) *match_len = mat.match_len;
|
||||||
|
|
||||||
|
/*match_ptr_zero = XP_NULL;*/
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mat.match_ptr++;
|
mat.match_ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (match_ptr_zero != XP_NULL)
|
||||||
|
{
|
||||||
|
if (match_ptr != XP_NULL) *match_ptr = match_ptr_zero;
|
||||||
|
if (match_len != XP_NULL) *match_len = 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return (mat.matched)? 1: 0;
|
return (mat.matched)? 1: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,7 +488,7 @@ static int __build_branch (__builder_t* builder)
|
|||||||
|
|
||||||
if (n == 0) break; /* no atom */
|
if (n == 0) break; /* no atom */
|
||||||
|
|
||||||
n = __build_boundary (builder, cmd);
|
n = __build_occurrences (builder, cmd);
|
||||||
if (n == -1)
|
if (n == -1)
|
||||||
{
|
{
|
||||||
builder->code.size = old_size;
|
builder->code.size = old_size;
|
||||||
@ -474,7 +496,7 @@ static int __build_branch (__builder_t* builder)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* n == 0 no bound character. just continue */
|
/* n == 0 no bound character. just continue */
|
||||||
/* n == 1 bound has been applied by build_boundary */
|
/* n == 1 bound has been applied by build_occurrences */
|
||||||
|
|
||||||
CODEAT(builder,pos_na,xp_size_t) += 1;
|
CODEAT(builder,pos_na,xp_size_t) += 1;
|
||||||
}
|
}
|
||||||
@ -738,7 +760,7 @@ static int __build_cclass (__builder_t* builder, xp_char_t* cc)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int __build_boundary (__builder_t* builder, struct __code_t* cmd)
|
static int __build_occurrences (__builder_t* builder, struct __code_t* cmd)
|
||||||
{
|
{
|
||||||
if (builder->ptn.curc.type != CT_SPECIAL) return 0;
|
if (builder->ptn.curc.type != CT_SPECIAL) return 0;
|
||||||
|
|
||||||
@ -826,7 +848,7 @@ static int __build_range (__builder_t* builder, struct __code_t* cmd)
|
|||||||
|
|
||||||
if (cmd->lbound > cmd->ubound)
|
if (cmd->lbound > cmd->ubound)
|
||||||
{
|
{
|
||||||
/* invalid boundary range */
|
/* invalid occurrences range */
|
||||||
builder->errnum = XP_AWK_EREXBRANGE;
|
builder->errnum = XP_AWK_EREXBRANGE;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1165,7 +1187,7 @@ static const xp_byte_t* __match_any_char (
|
|||||||
//xp_printf (XP_T("max si = %d\n"), si);
|
//xp_printf (XP_T("max si = %d\n"), si);
|
||||||
if (si >= lbound && si <= ubound)
|
if (si >= lbound && si <= ubound)
|
||||||
{
|
{
|
||||||
p = __match_boundary (matcher, si, p, lbound, ubound, mat);
|
p = __match_occurrences (matcher, si, p, lbound, ubound, mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
@ -1215,10 +1237,10 @@ static const xp_byte_t* __match_ord_char (
|
|||||||
si++;
|
si++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//xp_printf (XP_T("max si = %d\n"), si);
|
//xp_printf (XP_T("max si = %d, lbound = %u, ubound = %u\n"), si, lbound, ubound);
|
||||||
if (si >= lbound && si <= ubound)
|
if (si >= lbound && si <= ubound)
|
||||||
{
|
{
|
||||||
p = __match_boundary (matcher, si, p, lbound, ubound, mat);
|
p = __match_occurrences (matcher, si, p, lbound, ubound, mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
@ -1259,7 +1281,7 @@ static const xp_byte_t* __match_charset (
|
|||||||
|
|
||||||
if (si >= lbound && si <= ubound)
|
if (si >= lbound && si <= ubound)
|
||||||
{
|
{
|
||||||
p = __match_boundary (matcher, si, p, lbound, ubound, mat);
|
p = __match_occurrences (matcher, si, p, lbound, ubound, mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
@ -1345,7 +1367,7 @@ static const xp_byte_t* __match_group (
|
|||||||
/* increment p by the length of the subpattern */
|
/* increment p by the length of the subpattern */
|
||||||
p += *(xp_size_t*)(p+xp_sizeof(xp_size_t));
|
p += *(xp_size_t*)(p+xp_sizeof(xp_size_t));
|
||||||
|
|
||||||
/* check the boundary */
|
/* check the occurrences */
|
||||||
if (si >= cp->lbound && si <= cp->ubound)
|
if (si >= cp->lbound && si <= cp->ubound)
|
||||||
{
|
{
|
||||||
if (cp->lbound == cp->ubound || p >= mat->branch_end)
|
if (cp->lbound == cp->ubound || p >= mat->branch_end)
|
||||||
@ -1394,7 +1416,7 @@ static const xp_byte_t* __match_group (
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const xp_byte_t* __match_boundary (
|
static const xp_byte_t* __match_occurrences (
|
||||||
__matcher_t* matcher, xp_size_t si, const xp_byte_t* p,
|
__matcher_t* matcher, xp_size_t si, const xp_byte_t* p,
|
||||||
xp_size_t lbound, xp_size_t ubound, __match_t* mat)
|
xp_size_t lbound, xp_size_t ubound, __match_t* mat)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
BEGIN { FS="a+"; }
|
BEGIN { FS=":*"; }
|
||||||
{
|
{
|
||||||
print "NF=" NF;
|
print "NF=" NF;
|
||||||
for (i = 0; i < NF; i++) print i " [" $(i+1) "]";
|
for (i = 0; i < NF; i++) print i " [" $(i+1) "]";
|
||||||
|
Loading…
Reference in New Issue
Block a user