*** empty log message ***

This commit is contained in:
hyung-hwan 2005-12-29 12:04:51 +00:00
parent 8704625234
commit e8e8a80522
3 changed files with 71 additions and 47 deletions

View File

@ -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>
@ -22,13 +22,13 @@ xp_awk_t* xp_awk_open (xp_awk_t* awk)
awk->errnum = XP_AWK_ENOERR;
awk->source_func = XP_NULL;
awk->input_func = XP_NULL;
awk->output_func = XP_NULL;
awk->src_func = XP_NULL;
awk->inp_func = XP_NULL;
awk->outp_func = XP_NULL;
awk->source_arg = XP_NULL;
awk->input_arg = XP_NULL;
awk->output_arg = XP_NULL;
awk->src_arg = XP_NULL;
awk->inp_arg = XP_NULL;
awk->outp_arg = XP_NULL;
awk->lex.curc = XP_CHAR_EOF;
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)
{
if (xp_awk_detach_source(awk) == -1) return -1;
if (xp_awk_detsrc(awk) == -1) return -1;
xp_str_close (&awk->token.name);
if (awk->__dynamic) xp_free (awk);
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) {
awk->errnum = XP_AWK_ESRCOP;
return -1;
}
awk->source_func = source;
awk->source_arg = arg;
awk->src_func = src;
awk->src_arg = arg;
awk->lex.curc = XP_CHAR_EOF;
awk->lex.ungotc_count = 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->source_func(XP_AWK_IO_CLOSE, awk->source_arg, XP_NULL, 0) == -1) {
if (awk->src_func != XP_NULL) {
if (awk->src_func(XP_AWK_IO_CLOSE, awk->src_arg, XP_NULL, 0) == -1) {
awk->errnum = XP_AWK_ESRCCL;
return -1;
}
awk->source_func = XP_NULL;
awk->source_arg = XP_NULL;
awk->src_func = XP_NULL;
awk->src_arg = XP_NULL;
awk->lex.curc = XP_CHAR_EOF;
awk->lex.ungotc_count = 0;
}

View File

@ -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_
@ -7,7 +7,7 @@
#include <xp/types.h>
#include <xp/macros.h>
#include <xp/bas/string.h>
#include <xp/bas/str.h>
enum
{
@ -41,13 +41,13 @@ enum
struct xp_awk_t
{
/* io functions */
xp_awk_io_t source_func;
xp_awk_io_t input_func;
xp_awk_io_t output_func;
xp_awk_io_t src_func;
xp_awk_io_t inp_func;
xp_awk_io_t outp_func;
void* source_arg;
void* input_arg;
void* output_arg;
void* src_arg;
void* inp_arg;
void* outp_arg;
/* source buffer management */
struct {
@ -71,11 +71,31 @@ struct xp_awk_t
extern "C" {
#endif
/*
* FUNCTION: xp_awk_open
*/
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_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
}

View File

@ -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/bas/memory.h>
#include <xp/bas/ctype.h>
#include <xp/bas/string.h>
enum
{
@ -32,7 +33,7 @@ enum
TOKEN_REGEX,
TOKEN_IDENT,
TOEKN_BEGIN,
TOKEN_BEGIN,
TOKEN_END,
TOKEN_FUNCTION,
TOKEN_IF,
@ -52,8 +53,9 @@ static int __skip_spaces (xp_awk_t* awk);
static int __skip_comment (xp_awk_t* awk);
static int __classfy_ident (const xp_char_t* ident);
struct __kwent {
const xp_char_t* name,
struct __kwent
{
const xp_char_t* name;
int type;
};
@ -74,9 +76,9 @@ static struct __kwent __kwtab[] =
#define GET_CHAR(awk) \
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; \
c = (awk)->lex.curc; \
c = (awk)->lex.curc; \
} while(0)
#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 { \
if (xp_str_cat(&(awk)->token.name,(str)) == -1) { \
(awk)->errnum = XP_AWK_ENOMEM; return -1; \
} \
} 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)
{
@ -245,27 +249,27 @@ static int __get_token (xp_awk_t* awk)
ADD_TOKEN_STR (awk, XP_TEXT("-"));
}
}
else if (c == XP_CHAR('(') {
else if (c == XP_CHAR('(')) {
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);
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);
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);
ADD_TOKEN_CHAR (awk, c);
}
else if (c == XP_CHAR('[') {
else if (c == XP_CHAR('[')) {
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);
ADD_TOKEN_CHAR (awk, c);
}
@ -284,8 +288,8 @@ static int __get_char (xp_awk_t* awk)
return 0;
}
if (awk->source_func(XP_AWK_IO_DATA,
awk->source_arg, &awk->lex.curc, 1) == -1) {
if (awk->src_func(XP_AWK_IO_DATA,
awk->src_arg, &awk->lex.curc, 1) == -1) {
awk->errnum = XP_AWK_ESRCDT;
return -1;
}