*** empty log message ***
This commit is contained in:
parent
f6c98e99ec
commit
22de29f11e
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.c,v 1.59 2006-07-25 16:41:40 bacon Exp $
|
* $Id: awk.c,v 1.60 2006-07-26 05:19:44 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -61,17 +61,6 @@ xp_awk_t* xp_awk_open (void)
|
|||||||
return XP_NULL;
|
return XP_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xp_awk_rex_open (&awk->rex) == XP_NULL)
|
|
||||||
{
|
|
||||||
xp_str_close (&awk->token.name);
|
|
||||||
xp_awk_map_close (&awk->tree.afns);
|
|
||||||
xp_awk_tab_close (&awk->parse.globals);
|
|
||||||
xp_awk_tab_close (&awk->parse.locals);
|
|
||||||
xp_awk_tab_close (&awk->parse.params);
|
|
||||||
xp_free (awk);
|
|
||||||
return XP_NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
awk->opt.parse = 0;
|
awk->opt.parse = 0;
|
||||||
awk->opt.run = 0;
|
awk->opt.run = 0;
|
||||||
awk->errnum = XP_AWK_ENOERR;
|
awk->errnum = XP_AWK_ENOERR;
|
||||||
@ -116,7 +105,6 @@ int xp_awk_close (xp_awk_t* awk)
|
|||||||
xp_awk_tab_close (&awk->parse.globals);
|
xp_awk_tab_close (&awk->parse.globals);
|
||||||
xp_awk_tab_close (&awk->parse.locals);
|
xp_awk_tab_close (&awk->parse.locals);
|
||||||
xp_awk_tab_close (&awk->parse.params);
|
xp_awk_tab_close (&awk->parse.params);
|
||||||
xp_awk_rex_close (&awk->rex);
|
|
||||||
xp_str_close (&awk->token.name);
|
xp_str_close (&awk->token.name);
|
||||||
|
|
||||||
xp_free (awk);
|
xp_free (awk);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk_i.h,v 1.32 2006-07-25 16:41:40 bacon Exp $
|
* $Id: awk_i.h,v 1.33 2006-07-26 05:19:45 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_AWK_AWKI_H_
|
#ifndef _XP_AWK_AWKI_H_
|
||||||
@ -103,9 +103,6 @@ struct xp_awk_t
|
|||||||
xp_size_t nlocals_max;
|
xp_size_t nlocals_max;
|
||||||
} parse;
|
} parse;
|
||||||
|
|
||||||
/* regular expression compiler */
|
|
||||||
xp_awk_rex_t rex;
|
|
||||||
|
|
||||||
/* source buffer management */
|
/* source buffer management */
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -192,9 +189,6 @@ struct xp_awk_run_t
|
|||||||
/* extio chain */
|
/* extio chain */
|
||||||
xp_awk_extio_t* extio;
|
xp_awk_extio_t* extio;
|
||||||
|
|
||||||
/* regular expression matcher */
|
|
||||||
xp_awk_rex_t rex_matcher;
|
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
int errnum;
|
int errnum;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: parse.c,v 1.139 2006-07-25 16:41:40 bacon Exp $
|
* $Id: parse.c,v 1.140 2006-07-26 05:19:45 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -1916,23 +1916,17 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
|
|||||||
nde->type = XP_AWK_NDE_REX;
|
nde->type = XP_AWK_NDE_REX;
|
||||||
nde->next = XP_NULL;
|
nde->next = XP_NULL;
|
||||||
|
|
||||||
if (xp_awk_rex_compile (&awk->rex,
|
nde->buf = xp_awk_buildrex (
|
||||||
XP_STR_BUF(&awk->token.name),
|
XP_STR_BUF(&awk->token.name),
|
||||||
XP_STR_LEN(&awk->token.name)) == -1)
|
XP_STR_LEN(&awk->token.name));
|
||||||
{
|
|
||||||
xp_free (nde);
|
|
||||||
PANIC (awk, XP_AWK_EREXCMPL);
|
|
||||||
}
|
|
||||||
|
|
||||||
nde->len = awk->rex.code.size;
|
|
||||||
nde->buf = xp_malloc (nde->len);
|
|
||||||
if (nde->buf == XP_NULL)
|
if (nde->buf == XP_NULL)
|
||||||
{
|
{
|
||||||
|
/* TODO: get the proper errnum */
|
||||||
xp_free (nde);
|
xp_free (nde);
|
||||||
PANIC (awk, XP_AWK_ENOMEM);
|
PANIC (awk, XP_AWK_ENOMEM);
|
||||||
}
|
}
|
||||||
|
/* TODO: is nde->len necessary ? */
|
||||||
xp_memcpy (nde->buf, awk->rex.code.buf, nde->len);
|
nde->len = XP_AWK_REXLEN(nde->buf);
|
||||||
|
|
||||||
if (__get_token(awk) == -1)
|
if (__get_token(awk) == -1)
|
||||||
{
|
{
|
||||||
|
633
ase/awk/rex.c
633
ase/awk/rex.c
File diff suppressed because it is too large
Load Diff
@ -1,13 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: rex.h,v 1.8 2006-07-26 02:25:47 bacon Exp $
|
* $Id: rex.h,v 1.9 2006-07-26 05:19:45 bacon Exp $
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#ifndef _XP_AWK_REX_H_
|
#ifndef _XP_AWK_REX_H_
|
||||||
#define _XP_AWK_REX_H_
|
#define _XP_AWK_REX_H_
|
||||||
|
|
||||||
|
/*
|
||||||
#ifndef _XP_AWK_AWK_H_
|
#ifndef _XP_AWK_AWK_H_
|
||||||
#error Never include this file directly. Include <xp/awk/awk.h> instead
|
#error Never include this file directly. Include <xp/awk/awk.h> instead
|
||||||
#endif
|
#endif
|
||||||
|
*/
|
||||||
|
#include <xp/types.h>
|
||||||
|
#include <xp/macros.h>
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Regular Expression Syntax
|
* Regular Expression Syntax
|
||||||
@ -37,40 +42,6 @@
|
|||||||
* ab|xy -> |2|10|4|ORD_CHAR(no bound)|a|ORD_CHAR(no bound)|b|4|ORD_CHAR(no bound)|x|ORD_CHAR(no bound)|y|
|
* ab|xy -> |2|10|4|ORD_CHAR(no bound)|a|ORD_CHAR(no bound)|b|4|ORD_CHAR(no bound)|x|ORD_CHAR(no bound)|y|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct xp_awk_rex_t
|
|
||||||
{
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
const xp_char_t* ptr;
|
|
||||||
const xp_char_t* end;
|
|
||||||
const xp_char_t* curp;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
int type;
|
|
||||||
xp_char_t value;
|
|
||||||
} curc;
|
|
||||||
} ptn;
|
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
xp_byte_t* buf;
|
|
||||||
xp_size_t size;
|
|
||||||
xp_size_t capa;
|
|
||||||
} code;
|
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
const xp_char_t* ptr;
|
|
||||||
const xp_char_t* end;
|
|
||||||
} str;
|
|
||||||
} match;
|
|
||||||
|
|
||||||
int errnum;
|
|
||||||
xp_bool_t __dynamic;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
XP_AWK_REX_ENOERR, /* no error */
|
XP_AWK_REX_ENOERR, /* no error */
|
||||||
@ -87,27 +58,24 @@ enum
|
|||||||
XP_AWK_REX_EGARBAGE /* garbage after the pattern */
|
XP_AWK_REX_EGARBAGE /* garbage after the pattern */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define XP_AWK_REXNA(code) (*(xp_size_t*)(code))
|
||||||
|
|
||||||
|
#define XP_AWK_REXLEN(code) \
|
||||||
|
(*(xp_size_t*)((xp_byte_t*)(code)+xp_sizeof(xp_size_t)))
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const xp_char_t* xp_awk_rex_geterrstr (int errnum);
|
||||||
|
|
||||||
void* xp_awk_buildrex (const xp_char_t* ptn, xp_size_t len);
|
void* xp_awk_buildrex (const xp_char_t* ptn, xp_size_t len);
|
||||||
|
|
||||||
int xp_awk_matchrex (void* code,
|
int xp_awk_matchrex (void* code,
|
||||||
const xp_char_t* str, xp_size_t len,
|
const xp_char_t* str, xp_size_t len,
|
||||||
const xp_char_t** match_ptr, xp_size_t* match_len);
|
const xp_char_t** match_ptr, xp_size_t* match_len);
|
||||||
|
|
||||||
xp_awk_rex_t* xp_awk_rex_open (xp_awk_rex_t* rex);
|
void xp_awk_printrex (void* code);
|
||||||
void xp_awk_rex_close (xp_awk_rex_t* rex);
|
|
||||||
|
|
||||||
int xp_awk_rex_compile (
|
|
||||||
xp_awk_rex_t* rex, const xp_char_t* ptn, xp_size_t len);
|
|
||||||
|
|
||||||
int xp_awk_rex_match (xp_awk_rex_t* rex,
|
|
||||||
const xp_char_t* str, xp_size_t len,
|
|
||||||
const xp_char_t** match_ptr, xp_size_t* match_len);
|
|
||||||
|
|
||||||
void xp_awk_rex_print (xp_awk_rex_t* rex);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: run.c,v 1.137 2006-07-25 17:15:15 bacon Exp $
|
* $Id: run.c,v 1.138 2006-07-26 05:19:46 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -291,14 +291,6 @@ static int __open_run (
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xp_awk_rex_open (&run->rex_matcher) == XP_NULL)
|
|
||||||
{
|
|
||||||
xp_awk_map_close (&run->named);
|
|
||||||
xp_str_close (&run->inrec.line);
|
|
||||||
run->errnum = XP_AWK_ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
run->extio = XP_NULL;
|
run->extio = XP_NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -333,9 +325,6 @@ static void __close_run (xp_awk_run_t* run)
|
|||||||
run->stack_limit = 0;
|
run->stack_limit = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* destroy the regular expression matcher */
|
|
||||||
xp_awk_rex_close (&run->rex_matcher);
|
|
||||||
|
|
||||||
/* destroy named variables */
|
/* destroy named variables */
|
||||||
xp_awk_map_close (&run->named);
|
xp_awk_map_close (&run->named);
|
||||||
|
|
||||||
@ -654,7 +643,8 @@ static int __handle_pattern (xp_awk_run_t* run, xp_awk_val_t* val)
|
|||||||
/* TODO: do it properly match value...*/
|
/* TODO: do it properly match value...*/
|
||||||
//xp_awk_rex_setpattern (v->buf, v->len);
|
//xp_awk_rex_setpattern (v->buf, v->len);
|
||||||
|
|
||||||
n = xp_awk_rex_match (&run->rex_matcher,
|
n = xp_awk_matchrex (
|
||||||
|
((xp_awk_val_rex_t*)val)->buf,
|
||||||
((xp_awk_val_str_t*)run->inrec.d0)->buf,
|
((xp_awk_val_str_t*)run->inrec.d0)->buf,
|
||||||
((xp_awk_val_str_t*)run->inrec.d0)->len,
|
((xp_awk_val_str_t*)run->inrec.d0)->len,
|
||||||
XP_NULL, XP_NULL);
|
XP_NULL, XP_NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user