*** empty log message ***
This commit is contained in:
parent
8704625234
commit
e8e8a80522
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.c,v 1.4 2005-12-05 15:11:29 bacon Exp $
|
* $Id: awk.c,v 1.5 2005-12-29 12:04:51 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk.h>
|
#include <xp/awk/awk.h>
|
||||||
@ -22,13 +22,13 @@ xp_awk_t* xp_awk_open (xp_awk_t* awk)
|
|||||||
|
|
||||||
awk->errnum = XP_AWK_ENOERR;
|
awk->errnum = XP_AWK_ENOERR;
|
||||||
|
|
||||||
awk->source_func = XP_NULL;
|
awk->src_func = XP_NULL;
|
||||||
awk->input_func = XP_NULL;
|
awk->inp_func = XP_NULL;
|
||||||
awk->output_func = XP_NULL;
|
awk->outp_func = XP_NULL;
|
||||||
|
|
||||||
awk->source_arg = XP_NULL;
|
awk->src_arg = XP_NULL;
|
||||||
awk->input_arg = XP_NULL;
|
awk->inp_arg = XP_NULL;
|
||||||
awk->output_arg = XP_NULL;
|
awk->outp_arg = XP_NULL;
|
||||||
|
|
||||||
awk->lex.curc = XP_CHAR_EOF;
|
awk->lex.curc = XP_CHAR_EOF;
|
||||||
awk->lex.ungotc_count = 0;
|
awk->lex.ungotc_count = 0;
|
||||||
@ -38,40 +38,40 @@ xp_awk_t* xp_awk_open (xp_awk_t* awk)
|
|||||||
|
|
||||||
int xp_awk_close (xp_awk_t* awk)
|
int xp_awk_close (xp_awk_t* awk)
|
||||||
{
|
{
|
||||||
if (xp_awk_detach_source(awk) == -1) return -1;
|
if (xp_awk_detsrc(awk) == -1) return -1;
|
||||||
xp_str_close (&awk->token.name);
|
xp_str_close (&awk->token.name);
|
||||||
if (awk->__dynamic) xp_free (awk);
|
if (awk->__dynamic) xp_free (awk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xp_awk_attach_source (xp_awk_t* awk, xp_awk_io_t source, void* arg)
|
int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg)
|
||||||
{
|
{
|
||||||
if (xp_awk_detach_source(awk) == -1) return -1;
|
if (xp_awk_detsrc(awk) == -1) return -1;
|
||||||
|
|
||||||
xp_assert (awk->source_func == XP_NULL);
|
xp_assert (awk->src_func == XP_NULL);
|
||||||
|
|
||||||
if (source(XP_AWK_IO_OPEN, arg, XP_NULL, 0) == -1) {
|
if (source(XP_AWK_IO_OPEN, arg, XP_NULL, 0) == -1) {
|
||||||
awk->errnum = XP_AWK_ESRCOP;
|
awk->errnum = XP_AWK_ESRCOP;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
awk->source_func = source;
|
awk->src_func = src;
|
||||||
awk->source_arg = arg;
|
awk->src_arg = arg;
|
||||||
awk->lex.curc = XP_CHAR_EOF;
|
awk->lex.curc = XP_CHAR_EOF;
|
||||||
awk->lex.ungotc_count = 0;
|
awk->lex.ungotc_count = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xp_awk_detach_source (xp_awk_t* awk)
|
int xp_awk_detsrc (xp_awk_t* awk)
|
||||||
{
|
{
|
||||||
if (awk->source_func != XP_NULL) {
|
if (awk->src_func != XP_NULL) {
|
||||||
if (awk->source_func(XP_AWK_IO_CLOSE, awk->source_arg, XP_NULL, 0) == -1) {
|
if (awk->src_func(XP_AWK_IO_CLOSE, awk->src_arg, XP_NULL, 0) == -1) {
|
||||||
awk->errnum = XP_AWK_ESRCCL;
|
awk->errnum = XP_AWK_ESRCCL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
awk->source_func = XP_NULL;
|
awk->src_func = XP_NULL;
|
||||||
awk->source_arg = XP_NULL;
|
awk->src_arg = XP_NULL;
|
||||||
awk->lex.curc = XP_CHAR_EOF;
|
awk->lex.curc = XP_CHAR_EOF;
|
||||||
awk->lex.ungotc_count = 0;
|
awk->lex.ungotc_count = 0;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h,v 1.5 2005-12-05 15:11:29 bacon Exp $
|
* $Id: awk.h,v 1.6 2005-12-29 12:04:51 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_AWK_AWK_H_
|
#ifndef _XP_AWK_AWK_H_
|
||||||
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include <xp/types.h>
|
#include <xp/types.h>
|
||||||
#include <xp/macros.h>
|
#include <xp/macros.h>
|
||||||
#include <xp/bas/string.h>
|
#include <xp/bas/str.h>
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -41,13 +41,13 @@ enum
|
|||||||
struct xp_awk_t
|
struct xp_awk_t
|
||||||
{
|
{
|
||||||
/* io functions */
|
/* io functions */
|
||||||
xp_awk_io_t source_func;
|
xp_awk_io_t src_func;
|
||||||
xp_awk_io_t input_func;
|
xp_awk_io_t inp_func;
|
||||||
xp_awk_io_t output_func;
|
xp_awk_io_t outp_func;
|
||||||
|
|
||||||
void* source_arg;
|
void* src_arg;
|
||||||
void* input_arg;
|
void* inp_arg;
|
||||||
void* output_arg;
|
void* outp_arg;
|
||||||
|
|
||||||
/* source buffer management */
|
/* source buffer management */
|
||||||
struct {
|
struct {
|
||||||
@ -71,11 +71,31 @@ struct xp_awk_t
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FUNCTION: xp_awk_open
|
||||||
|
*/
|
||||||
xp_awk_t* xp_awk_open (xp_awk_t* awk);
|
xp_awk_t* xp_awk_open (xp_awk_t* awk);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FUNCTION: xp_awk_close
|
||||||
|
*/
|
||||||
int xp_awk_close (xp_awk_t* awk);
|
int xp_awk_close (xp_awk_t* awk);
|
||||||
|
|
||||||
int xp_awk_attach_source (xp_awk_t* awk, xp_awk_io_t source, void* source_arg);
|
/*
|
||||||
int xp_awk_detach_source (xp_awk_t* awk);
|
* FUNCTION: xp_awk_attsrc
|
||||||
|
*/
|
||||||
|
int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FUNCTION: xp_awk_detsrc
|
||||||
|
*/
|
||||||
|
int xp_awk_detsrc (xp_awk_t* awk);
|
||||||
|
|
||||||
|
int xp_awk_attinp (xp_awk_t* awk, xp_awk_io_t inp, void* arg);
|
||||||
|
int xp_awk_detinp (xp_awk_t* awk);
|
||||||
|
|
||||||
|
int xp_awk_attoutp (xp_awk_t* awk, xp_awk_io_t outp, void* arg);
|
||||||
|
int xp_awk_detoutp (xp_awk_t* awk);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: parse.c,v 1.8 2005-12-11 13:56:13 bacon Exp $
|
* $Id: parse.c,v 1.9 2005-12-29 12:04:51 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk.h>
|
#include <xp/awk/awk.h>
|
||||||
#include <xp/bas/memory.h>
|
#include <xp/bas/memory.h>
|
||||||
#include <xp/bas/ctype.h>
|
#include <xp/bas/ctype.h>
|
||||||
|
#include <xp/bas/string.h>
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -32,7 +33,7 @@ enum
|
|||||||
TOKEN_REGEX,
|
TOKEN_REGEX,
|
||||||
|
|
||||||
TOKEN_IDENT,
|
TOKEN_IDENT,
|
||||||
TOEKN_BEGIN,
|
TOKEN_BEGIN,
|
||||||
TOKEN_END,
|
TOKEN_END,
|
||||||
TOKEN_FUNCTION,
|
TOKEN_FUNCTION,
|
||||||
TOKEN_IF,
|
TOKEN_IF,
|
||||||
@ -52,8 +53,9 @@ static int __skip_spaces (xp_awk_t* awk);
|
|||||||
static int __skip_comment (xp_awk_t* awk);
|
static int __skip_comment (xp_awk_t* awk);
|
||||||
static int __classfy_ident (const xp_char_t* ident);
|
static int __classfy_ident (const xp_char_t* ident);
|
||||||
|
|
||||||
struct __kwent {
|
struct __kwent
|
||||||
const xp_char_t* name,
|
{
|
||||||
|
const xp_char_t* name;
|
||||||
int type;
|
int type;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -74,9 +76,9 @@ static struct __kwent __kwtab[] =
|
|||||||
#define GET_CHAR(awk) \
|
#define GET_CHAR(awk) \
|
||||||
do { if (__get_char(awk) == -1) return -1; } while(0)
|
do { if (__get_char(awk) == -1) return -1; } while(0)
|
||||||
|
|
||||||
#define GET_CHAR_TO(awk, c) do { \
|
#define GET_CHAR_TO(awk,c) do { \
|
||||||
if (__get_char(awk) == -1) return -1; \
|
if (__get_char(awk) == -1) return -1; \
|
||||||
c = (awk)->lex.curc; \
|
c = (awk)->lex.curc; \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define SET_TOKEN_TYPE(awk,code) ((awk)->token.type = code)
|
#define SET_TOKEN_TYPE(awk,code) ((awk)->token.type = code)
|
||||||
@ -90,9 +92,11 @@ static struct __kwent __kwtab[] =
|
|||||||
#define ADD_TOKEN_STR(awk,str) do { \
|
#define ADD_TOKEN_STR(awk,str) do { \
|
||||||
if (xp_str_cat(&(awk)->token.name,(str)) == -1) { \
|
if (xp_str_cat(&(awk)->token.name,(str)) == -1) { \
|
||||||
(awk)->errnum = XP_AWK_ENOMEM; return -1; \
|
(awk)->errnum = XP_AWK_ENOMEM; return -1; \
|
||||||
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define GET_TOKEN(awk) do { if (__get_token(awk) == -1) return -1; }
|
#define GET_TOKEN(awk) \
|
||||||
|
do { if (__get_token(awk) == -1) return -1; } while(0)
|
||||||
|
|
||||||
int xp_awk_parse (xp_awk_t* awk)
|
int xp_awk_parse (xp_awk_t* awk)
|
||||||
{
|
{
|
||||||
@ -245,27 +249,27 @@ static int __get_token (xp_awk_t* awk)
|
|||||||
ADD_TOKEN_STR (awk, XP_TEXT("-"));
|
ADD_TOKEN_STR (awk, XP_TEXT("-"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (c == XP_CHAR('(') {
|
else if (c == XP_CHAR('(')) {
|
||||||
SET_TOKEN_TYPE (awk, TOKEN_LPAREN);
|
SET_TOKEN_TYPE (awk, TOKEN_LPAREN);
|
||||||
ADD_TOKEN_STR (awk, c);
|
ADD_TOKEN_CHAR (awk, c);
|
||||||
}
|
}
|
||||||
else if (c == XP_CHAR(')') {
|
else if (c == XP_CHAR(')')) {
|
||||||
SET_TOKEN_TYPE (awk, TOKEN_RPAREN);
|
SET_TOKEN_TYPE (awk, TOKEN_RPAREN);
|
||||||
ADD_TOKEN_STR (awk, c);
|
ADD_TOKEN_CHAR (awk, c);
|
||||||
}
|
}
|
||||||
else if (c == XP_CHAR('{') {
|
else if (c == XP_CHAR('{')) {
|
||||||
SET_TOKEN_TYPE (awk, TOKEN_LBRACE);
|
SET_TOKEN_TYPE (awk, TOKEN_LBRACE);
|
||||||
ADD_TOKEN_STR (awk, c);
|
ADD_TOKEN_CHAR (awk, c);
|
||||||
}
|
}
|
||||||
else if (c == XP_CHAR('}') {
|
else if (c == XP_CHAR('}')) {
|
||||||
SET_TOKEN_TYPE (awk, TOKEN_RBRACE);
|
SET_TOKEN_TYPE (awk, TOKEN_RBRACE);
|
||||||
ADD_TOKEN_CHAR (awk, c);
|
ADD_TOKEN_CHAR (awk, c);
|
||||||
}
|
}
|
||||||
else if (c == XP_CHAR('[') {
|
else if (c == XP_CHAR('[')) {
|
||||||
SET_TOKEN_TYPE (awk, TOKEN_LBRAKET);
|
SET_TOKEN_TYPE (awk, TOKEN_LBRAKET);
|
||||||
ADD_TOKEN_STR (awk, c);
|
ADD_TOKEN_CHAR (awk, c);
|
||||||
}
|
}
|
||||||
else if (c == XP_CHAR(']') {
|
else if (c == XP_CHAR(']')) {
|
||||||
SET_TOKEN_TYPE (awk, TOKEN_RBRAKET);
|
SET_TOKEN_TYPE (awk, TOKEN_RBRAKET);
|
||||||
ADD_TOKEN_CHAR (awk, c);
|
ADD_TOKEN_CHAR (awk, c);
|
||||||
}
|
}
|
||||||
@ -284,8 +288,8 @@ static int __get_char (xp_awk_t* awk)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (awk->source_func(XP_AWK_IO_DATA,
|
if (awk->src_func(XP_AWK_IO_DATA,
|
||||||
awk->source_arg, &awk->lex.curc, 1) == -1) {
|
awk->src_arg, &awk->lex.curc, 1) == -1) {
|
||||||
awk->errnum = XP_AWK_ESRCDT;
|
awk->errnum = XP_AWK_ESRCDT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user