*** empty log message ***

This commit is contained in:
hyung-hwan 2006-03-31 16:35:37 +00:00
parent c4a54c070c
commit 3079f4aac4
14 changed files with 244 additions and 228 deletions

View File

@ -1,8 +1,8 @@
/* /*
* $Id: awk.c,v 1.36 2006-03-29 16:37:31 bacon Exp $ * $Id: awk.c,v 1.37 2006-03-31 16:35:37 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef __STAND_ALONE
#include <xp/bas/memory.h> #include <xp/bas/memory.h>
@ -12,30 +12,28 @@
static void __free_func (xp_awk_t* awk, void* func); static void __free_func (xp_awk_t* awk, void* func);
static void __free_namedval (xp_awk_t* awk, void* val); static void __free_namedval (xp_awk_t* awk, void* val);
xp_awk_t* xp_awk_open (xp_awk_t* awk) xp_awk_t* xp_awk_open (void)
{ {
if (awk == XP_NULL) { xp_awk_t* awk;
awk = (xp_awk_t*) xp_malloc (xp_sizeof(awk));
if (awk == XP_NULL) return XP_NULL; awk = (xp_awk_t*) xp_malloc (xp_sizeof(awk));
awk->__dynamic = xp_true; if (awk == XP_NULL) return XP_NULL;
}
else awk->__dynamic = xp_false;
if (xp_str_open(&awk->token.name, 128) == XP_NULL) { if (xp_str_open(&awk->token.name, 128) == XP_NULL) {
if (awk->__dynamic) xp_free (awk); xp_free (awk);
return XP_NULL; return XP_NULL;
} }
if (xp_awk_map_open (&awk->tree.funcs, awk, 256, __free_func) == XP_NULL) { if (xp_awk_map_open (&awk->tree.funcs, awk, 256, __free_func) == XP_NULL) {
xp_str_close (&awk->token.name); xp_str_close (&awk->token.name);
if (awk->__dynamic) xp_free (awk); xp_free (awk);
return XP_NULL; return XP_NULL;
} }
if (xp_awk_tab_open(&awk->parse.globals) == XP_NULL) { if (xp_awk_tab_open(&awk->parse.globals) == XP_NULL) {
xp_str_close (&awk->token.name); xp_str_close (&awk->token.name);
xp_awk_map_close (&awk->tree.funcs); xp_awk_map_close (&awk->tree.funcs);
if (awk->__dynamic) xp_free (awk); xp_free (awk);
return XP_NULL; return XP_NULL;
} }
@ -43,7 +41,7 @@ xp_awk_t* xp_awk_open (xp_awk_t* awk)
xp_str_close (&awk->token.name); xp_str_close (&awk->token.name);
xp_awk_map_close (&awk->tree.funcs); xp_awk_map_close (&awk->tree.funcs);
xp_awk_tab_close (&awk->parse.globals); xp_awk_tab_close (&awk->parse.globals);
if (awk->__dynamic) xp_free (awk); xp_free (awk);
return XP_NULL; return XP_NULL;
} }
@ -52,7 +50,7 @@ xp_awk_t* xp_awk_open (xp_awk_t* awk)
xp_awk_map_close (&awk->tree.funcs); xp_awk_map_close (&awk->tree.funcs);
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);
if (awk->__dynamic) xp_free (awk); xp_free (awk);
return XP_NULL; return XP_NULL;
} }
@ -63,7 +61,7 @@ xp_awk_t* xp_awk_open (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);
if (awk->__dynamic) xp_free (awk); xp_free (awk);
return XP_NULL; return XP_NULL;
} }
@ -112,7 +110,7 @@ int xp_awk_close (xp_awk_t* awk)
xp_awk_tab_close (&awk->parse.params); xp_awk_tab_close (&awk->parse.params);
xp_str_close (&awk->token.name); xp_str_close (&awk->token.name);
if (awk->__dynamic) xp_free (awk); xp_free (awk);
return 0; return 0;
} }
@ -157,6 +155,11 @@ void xp_awk_clear (xp_awk_t* awk)
/* TODO: destroy function list */ /* TODO: destroy function list */
} }
void xp_awk_setparseopt (xp_awk_t* awk, int opt)
{
awk->opt.parse = opt;
}
int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg) int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg)
{ {
if (xp_awk_detsrc(awk) == -1) return -1; if (xp_awk_detsrc(awk) == -1) return -1;

View File

@ -1,34 +1,15 @@
/* /*
* $Id: awk.h,v 1.38 2006-03-28 16:33:09 bacon Exp $ * $Id: awk.h,v 1.39 2006-03-31 16:35:37 bacon Exp $
*/ */
#ifndef _XP_AWK_AWK_H_ #ifndef _XP_AWK_AWK_H_
#define _XP_AWK_AWK_H_ #define _XP_AWK_AWK_H_
#ifdef __STAND_ALONE
#include <xp/awk/sa.h>
#else
#include <xp/types.h> #include <xp/types.h>
#include <xp/macros.h> #include <xp/macros.h>
#include <xp/bas/str.h>
#endif
/*
* TYPE: xp_awk_t
*/
typedef struct xp_awk_t xp_awk_t; typedef struct xp_awk_t xp_awk_t;
typedef struct xp_awk_chain_t xp_awk_chain_t;
#include <xp/awk/err.h>
#include <xp/awk/tree.h>
#include <xp/awk/tab.h>
#include <xp/awk/map.h>
#include <xp/awk/val.h>
#include <xp/awk/run.h>
/*
* TYPE: xp_awk_io_t
*/
typedef xp_ssize_t (*xp_awk_io_t) ( typedef xp_ssize_t (*xp_awk_io_t) (
int cmd, void* arg, xp_char_t* data, xp_size_t count); int cmd, void* arg, xp_char_t* data, xp_size_t count);
@ -50,124 +31,23 @@ enum
XP_AWK_SHIFT = (1 << 4) /* support shift operators */ XP_AWK_SHIFT = (1 << 4) /* support shift operators */
}; };
struct xp_awk_t
{
/* options */
struct
{
int parse;
int run;
} opt;
/* io functions */
xp_awk_io_t src_func;
xp_awk_io_t in_func;
xp_awk_io_t out_func;
void* src_arg;
void* in_arg;
void* out_arg;
/* parse tree */
struct
{
xp_size_t nglobals;
xp_awk_map_t funcs;
xp_awk_nde_t* begin;
xp_awk_nde_t* end;
xp_awk_chain_t* chain;
xp_awk_chain_t* chain_tail;
} tree;
/* temporary information that the parser needs */
struct
{
xp_awk_tab_t globals;
xp_awk_tab_t locals;
xp_awk_tab_t params;
xp_size_t nlocals_max;
} parse;
/* run-time data structure */
struct
{
xp_awk_map_t named;
void** stack;
xp_size_t stack_top;
xp_size_t stack_base;
xp_size_t stack_limit;
int exit_level;
xp_awk_val_int_t* icache[100]; // TODO: ...
xp_awk_val_real_t* rcache[100]; // TODO: ...
xp_size_t icache_count;
xp_size_t rcache_count;
} run;
/* source buffer management */
struct
{
xp_cint_t curc;
xp_cint_t ungotc[5];
xp_size_t ungotc_count;
} lex;
/* token */
struct
{
int type;
xp_str_t name;
} token;
/* housekeeping */
int errnum;
xp_bool_t __dynamic;
};
struct xp_awk_chain_t
{
xp_awk_nde_t* pattern;
xp_awk_nde_t* action;
xp_awk_chain_t* next;
};
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* xp_awk_t* xp_awk_open (void);
* 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_close (xp_awk_t* awk);
int xp_awk_geterrnum (xp_awk_t* awk); int xp_awk_geterrnum (xp_awk_t* awk);
const xp_char_t* xp_awk_geterrstr (xp_awk_t* awk); const xp_char_t* xp_awk_geterrstr (xp_awk_t* awk);
/*
* FUNCTION: xp_awk_clear
*/
void xp_awk_clear (xp_awk_t* awk); void xp_awk_clear (xp_awk_t* awk);
void xp_awk_setparseopt (xp_awk_t* awk, int opt);
/*
* FUNCTION: xp_awk_attsrc
*/
int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg); 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_detsrc (xp_awk_t* awk);
int xp_awk_attin (xp_awk_t* awk, xp_awk_io_t in, void* arg); int xp_awk_attin (xp_awk_t* awk, xp_awk_io_t in, void* arg);
int xp_awk_detin (xp_awk_t* awk); int xp_awk_detin (xp_awk_t* awk);
int xp_awk_attout (xp_awk_t* awk, xp_awk_io_t out, void* arg); int xp_awk_attout (xp_awk_t* awk, xp_awk_io_t out, void* arg);
int xp_awk_detout (xp_awk_t* awk); int xp_awk_detout (xp_awk_t* awk);

106
ase/awk/awk_i.h Normal file
View File

@ -0,0 +1,106 @@
/*
* $Id: awk_i.h,v 1.1 2006-03-31 16:35:37 bacon Exp $
*/
#ifndef _XP_AWK_AWKI_H_
#define _XP_AWK_AWKI_H_
#include <xp/awk/awk.h>
#include <xp/awk/err.h>
#include <xp/awk/tree.h>
#include <xp/awk/tab.h>
#include <xp/awk/map.h>
#include <xp/awk/val.h>
#include <xp/awk/run.h>
#ifdef __STAND_ALONE
#include <xp/awk/sa.h>
#else
#include <xp/bas/str.h>
#endif
typedef struct xp_awk_chain_t xp_awk_chain_t;
struct xp_awk_t
{
/* options */
struct
{
int parse;
int run;
} opt;
/* io functions */
xp_awk_io_t src_func;
xp_awk_io_t in_func;
xp_awk_io_t out_func;
void* src_arg;
void* in_arg;
void* out_arg;
/* parse tree */
struct
{
xp_size_t nglobals;
xp_awk_map_t funcs;
xp_awk_nde_t* begin;
xp_awk_nde_t* end;
xp_awk_chain_t* chain;
xp_awk_chain_t* chain_tail;
} tree;
/* temporary information that the parser needs */
struct
{
xp_awk_tab_t globals;
xp_awk_tab_t locals;
xp_awk_tab_t params;
xp_size_t nlocals_max;
} parse;
/* run-time data structure */
struct
{
xp_awk_map_t named;
void** stack;
xp_size_t stack_top;
xp_size_t stack_base;
xp_size_t stack_limit;
int exit_level;
xp_awk_val_int_t* icache[100]; // TODO: ...
xp_awk_val_real_t* rcache[100]; // TODO: ...
xp_size_t icache_count;
xp_size_t rcache_count;
} run;
/* source buffer management */
struct
{
xp_cint_t curc;
xp_cint_t ungotc[5];
xp_size_t ungotc_count;
} lex;
/* token */
struct
{
int type;
xp_str_t name;
} token;
/* housekeeping */
int errnum;
xp_bool_t __dynamic;
};
struct xp_awk_chain_t
{
xp_awk_nde_t* pattern;
xp_awk_nde_t* action;
xp_awk_chain_t* next;
};
#endif

View File

@ -1,8 +1,8 @@
/* /*
* $Id: err.c,v 1.1 2006-03-04 10:08:13 bacon Exp $ * $Id: err.c,v 1.2 2006-03-31 16:35:37 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk_i.h>
int xp_awk_geterrnum (xp_awk_t* awk) int xp_awk_geterrnum (xp_awk_t* awk)
{ {

View File

@ -1,8 +1,8 @@
/* /*
* $Id: map.c,v 1.8 2006-03-27 14:14:00 bacon Exp $ * $Id: map.c,v 1.9 2006-03-31 16:35:37 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef __STAND_ALONE
#include <xp/bas/memory.h> #include <xp/bas/memory.h>

View File

@ -1,8 +1,8 @@
/* /*
* $Id: parse.c,v 1.66 2006-03-31 12:04:14 bacon Exp $ * $Id: parse.c,v 1.67 2006-03-31 16:35:37 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef __STAND_ALONE
#include <xp/bas/memory.h> #include <xp/bas/memory.h>
@ -137,6 +137,7 @@ static xp_awk_nde_t* __parse_break (xp_awk_t* awk);
static xp_awk_nde_t* __parse_continue (xp_awk_t* awk); static xp_awk_nde_t* __parse_continue (xp_awk_t* awk);
static xp_awk_nde_t* __parse_return (xp_awk_t* awk); static xp_awk_nde_t* __parse_return (xp_awk_t* awk);
static xp_awk_nde_t* __parse_exit (xp_awk_t* awk); static xp_awk_nde_t* __parse_exit (xp_awk_t* awk);
static xp_awk_nde_t* __parse_delete (xp_awk_t* awk);
static xp_awk_nde_t* __parse_next (xp_awk_t* awk); static xp_awk_nde_t* __parse_next (xp_awk_t* awk);
static xp_awk_nde_t* __parse_nextfile (xp_awk_t* awk); static xp_awk_nde_t* __parse_nextfile (xp_awk_t* awk);
@ -944,13 +945,11 @@ static xp_awk_nde_t* __parse_statement_nb (xp_awk_t* awk)
if (__get_token(awk) == -1) return XP_NULL; if (__get_token(awk) == -1) return XP_NULL;
nde = __parse_exit(awk); nde = __parse_exit(awk);
} }
/* TODO:
else if (MATCH(awk,TOKEN_DELETE)) else if (MATCH(awk,TOKEN_DELETE))
{ {
if (__get_token(awk) == -1) return XP_NULL; if (__get_token(awk) == -1) return XP_NULL;
nde = __parse_delete(awk); nde = __parse_delete(awk);
} }
*/
else if (MATCH(awk,TOKEN_NEXT)) else if (MATCH(awk,TOKEN_NEXT))
{ {
if (__get_token(awk) == -1) return XP_NULL; if (__get_token(awk) == -1) return XP_NULL;
@ -1088,8 +1087,40 @@ static xp_awk_nde_t* __parse_binary_expr (
return XP_NULL; return XP_NULL;
} }
// TODO: constant folding -> in other parts of the program also... /* TODO: enhance constant folding. do it in a better way */
/* TODO: differentiate different types of numbers ... */
if (left->type == XP_AWK_NDE_INT &&
right->type == XP_AWK_NDE_INT)
{
xp_long_t l, r;
l = ((xp_awk_nde_int_t*)left)->val;
r = ((xp_awk_nde_int_t*)right)->val;
/* TODO: more operators */
if (opcode == XP_AWK_BINOP_PLUS) l += r;
else if (opcode == XP_AWK_BINOP_MINUS) l -= r;
else if (opcode == XP_AWK_BINOP_MUL) l *= r;
else if (opcode == XP_AWK_BINOP_DIV) l /= r;
else if (opcode == XP_AWK_BINOP_MOD) l %= r;
else goto skip_constant_folding;
xp_awk_clrpt (right);
((xp_awk_nde_int_t*)left)->val = l;
continue;
}
/* TODO:
else if (left->type == XP_AWK_NDE_REAL &&
right->type == XP_AWK_NDE_REAL)
{
}
else if (left->type == XP_AWK_NDE_STR &&
right->type == XP_AWK_NDE_STR)
{
// TODO: string concatenation operator....
} */
skip_constant_folding:
nde = (xp_awk_nde_exp_t*)xp_malloc(xp_sizeof(xp_awk_nde_exp_t)); nde = (xp_awk_nde_exp_t*)xp_malloc(xp_sizeof(xp_awk_nde_exp_t));
if (nde == XP_NULL) if (nde == XP_NULL)
{ {
@ -2081,6 +2112,12 @@ static xp_awk_nde_t* __parse_exit (xp_awk_t* awk)
return (xp_awk_nde_t*)nde; return (xp_awk_nde_t*)nde;
} }
static xp_awk_nde_t* __parse_delete (xp_awk_t* awk)
{
// TODO: implement this...
return XP_NULL;
}
static xp_awk_nde_t* __parse_next (xp_awk_t* awk) static xp_awk_nde_t* __parse_next (xp_awk_t* awk)
{ {
xp_awk_nde_t* nde; xp_awk_nde_t* nde;

View File

@ -1,8 +1,8 @@
/* /*
* $Id: run.c,v 1.27 2006-03-30 16:31:50 bacon Exp $ * $Id: run.c,v 1.28 2006-03-31 16:35:37 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef __STAND_ALONE
#include <xp/bas/assert.h> #include <xp/bas/assert.h>

View File

@ -1,8 +1,8 @@
/* /*
* $Id: sa.c,v 1.12 2006-03-31 12:04:14 bacon Exp $ * $Id: sa.c,v 1.13 2006-03-31 16:35:37 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk_i.h>
#ifdef __STAND_ALONE #ifdef __STAND_ALONE

View File

@ -1,5 +1,5 @@
/* /*
* $Id: sa.h,v 1.16 2006-03-31 12:04:14 bacon Exp $ * $Id: sa.h,v 1.17 2006-03-31 16:35:37 bacon Exp $
*/ */
#ifndef _XP_AWK_SA_H_ #ifndef _XP_AWK_SA_H_
@ -59,59 +59,6 @@
#define xp_va_end(pvar) va_end(pvar) #define xp_va_end(pvar) va_end(pvar)
#define xp_va_arg(pvar,type) va_arg(pvar,type) #define xp_va_arg(pvar,type) va_arg(pvar,type)
#define xp_main main
#define XP_NULL NULL
#define xp_sizeof(n) (sizeof(n))
#define xp_countof(n) (sizeof(n) / sizeof(n[0]))
#define xp_true (0 == 0)
#define xp_false (0 != 0)
typedef unsigned char xp_byte_t;
typedef int xp_bool_t;
typedef size_t xp_size_t;
#ifdef XP_CHAR_IS_MCHAR
typedef char xp_char_t;
typedef int xp_cint_t;
#else
typedef wchar_t xp_char_t;
typedef wint_t xp_cint_t;
#endif
#if defined(_WIN32) || defined(vms) || defined(__vms)
typedef long xp_ssize_t;
#else
typedef ssize_t xp_ssize_t;
#endif
#if defined(_WIN32)
typedef __int64 xp_long_t;
typedef long double xp_real_t;
#elif defined(vax) || defined(__vax)
typedef long xp_long_t;
typedef long double xp_real_t;
#else
typedef long long xp_long_t;
typedef long double xp_real_t;
#endif
#ifdef XP_CHAR_IS_MCHAR
#define XP_CHAR(c) c
#define XP_TEXT(c) c
#define XP_CHAR_EOF EOF
#else
#define XP_CHAR(c) L##c
#define XP_TEXT(c) L##c
#ifdef WEOF
#define XP_CHAR_EOF WEOF
#else
#define XP_CHAR_EOF ((xp_char_t)-1)
#endif
#endif
#define XP_STR_LEN(x) ((x)->size) #define XP_STR_LEN(x) ((x)->size)
#define XP_STR_SIZE(x) ((x)->size + 1) #define XP_STR_SIZE(x) ((x)->size + 1)
#define XP_STR_CAPA(x) ((x)->capa) #define XP_STR_CAPA(x) ((x)->capa)
@ -131,29 +78,64 @@ struct xp_str_t
extern "C" { extern "C" {
#endif #endif
#define xp_strlen xp_awk_strlen
xp_size_t xp_strlen (const xp_char_t* str); xp_size_t xp_strlen (const xp_char_t* str);
#define xp_strdup xp_awk_strdup
xp_char_t* xp_strdup (const xp_char_t* str); xp_char_t* xp_strdup (const xp_char_t* str);
#define xp_strxdup xp_awk_strxdup
xp_char_t* xp_strxdup (const xp_char_t* str, xp_size_t len); xp_char_t* xp_strxdup (const xp_char_t* str, xp_size_t len);
#define xp_strcpy xp_awk_strcpy
xp_size_t xp_strcpy (xp_char_t* buf, const xp_char_t* str); xp_size_t xp_strcpy (xp_char_t* buf, const xp_char_t* str);
#define xp_strxncpy xp_awk_strxncpy
xp_size_t xp_strxncpy ( xp_size_t xp_strxncpy (
xp_char_t* buf, xp_size_t bsz, const xp_char_t* str, xp_size_t len); xp_char_t* buf, xp_size_t bsz, const xp_char_t* str, xp_size_t len);
#define xp_strcmp xp_awk_strcmp
int xp_strcmp (const xp_char_t* s1, const xp_char_t* s2); int xp_strcmp (const xp_char_t* s1, const xp_char_t* s2);
#define xp_strtolong xp_awk_strtolong
xp_long_t xp_strtolong (xp_char_t* str); xp_long_t xp_strtolong (xp_char_t* str);
#define xp_strtoreal xp_awk_strtoreal
xp_real_t xp_strtoreal (xp_char_t* str); xp_real_t xp_strtoreal (xp_char_t* str);
#define xp_printf xp_awk_printf
int xp_printf (const xp_char_t* fmt, ...); int xp_printf (const xp_char_t* fmt, ...);
#define xp_vprintf xp_awk_vprintf
int xp_vprintf (const xp_char_t* fmt, xp_va_list ap); int xp_vprintf (const xp_char_t* fmt, xp_va_list ap);
int xp_sprintf (xp_char_t* buf, xp_size_t size, const xp_char_t* fmt, ...);
#define xp_sprintf xp_awk_sprintf
int xp_sprintf (
xp_char_t* buf, xp_size_t size, const xp_char_t* fmt, ...);
#define xp_vsprintf xp_awk_vsprintf
int xp_vsprintf ( int xp_vsprintf (
xp_char_t* buf, xp_size_t size, const xp_char_t* fmt, xp_va_list ap); xp_char_t* buf, xp_size_t size, const xp_char_t* fmt, xp_va_list ap);
#define xp_str_open xp_awk_str_open
xp_str_t* xp_str_open (xp_str_t* str, xp_size_t capa); xp_str_t* xp_str_open (xp_str_t* str, xp_size_t capa);
#define xp_str_close xp_awk_str_close
void xp_str_close (xp_str_t* str); void xp_str_close (xp_str_t* str);
#define xp_str_forfeit xp_awk_str_forfeit
void xp_str_forfeit (xp_str_t* str);
#define xp_str_cat xp_awk_str_cat
xp_size_t xp_str_cat (xp_str_t* str, const xp_char_t* s); xp_size_t xp_str_cat (xp_str_t* str, const xp_char_t* s);
#define xp_str_ncat xp_awk_str_ncat
xp_size_t xp_str_ncat (xp_str_t* str, const xp_char_t* s, xp_size_t len); xp_size_t xp_str_ncat (xp_str_t* str, const xp_char_t* s, xp_size_t len);
#define xp_str_ccat xp_awk_str_ccat
xp_size_t xp_str_ccat (xp_str_t* str, xp_char_t c); xp_size_t xp_str_ccat (xp_str_t* str, xp_char_t c);
#define xp_str_clear xp_awk_str_clear
void xp_str_clear (xp_str_t* str); void xp_str_clear (xp_str_t* str);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,8 +1,8 @@
/* /*
* $Id: tab.c,v 1.6 2006-03-07 15:55:14 bacon Exp $ * $Id: tab.c,v 1.7 2006-03-31 16:35:37 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef __STAND_ALONE
#include <xp/bas/memory.h> #include <xp/bas/memory.h>

View File

@ -1,8 +1,8 @@
/* /*
* $Id: tree.c,v 1.29 2006-03-31 12:04:14 bacon Exp $ * $Id: tree.c,v 1.30 2006-03-31 16:35:37 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef __STAND_ALONE
#include <xp/bas/memory.h> #include <xp/bas/memory.h>

View File

@ -1,8 +1,8 @@
/* /*
* $Id: val.c,v 1.13 2006-03-28 16:33:09 bacon Exp $ * $Id: val.c,v 1.14 2006-03-31 16:35:37 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk_i.h>
#ifndef __STAND_ALONE #ifndef __STAND_ALONE
#include <xp/bas/string.h> #include <xp/bas/string.h>

View File

@ -1,9 +1,9 @@
CC = cl CC = cl
#CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\.. #CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\..
CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\.. -D__STAND_ALONE -DXP_CHAR_IS_WCHAR CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\..
LDFLAGS = /libpath:..\..\bas /libpath:..\..\awk LDFLAGS = /libpath:..\..\bas /libpath:..\..\awk
#LIBS = xpbas.lib xpawk.lib LIBS = xpbas.lib xpawk.lib
LIBS = xpawk.lib #LIBS = xpawk.lib
all: awk all: awk

View File

@ -1,4 +1,10 @@
/*
* $Id: awk.c,v 1.14 2006-03-31 16:35:37 bacon Exp $
*/
#include <xp/awk/awk.h> #include <xp/awk/awk.h>
#include <xp/bas/stdio.h>
#include <wchar.h>
#ifdef __STAND_ALONE #ifdef __STAND_ALONE
@ -62,7 +68,7 @@ int xp_main (int argc, xp_char_t* argv[])
int xp_main (int argc, char* argv[]) int xp_main (int argc, char* argv[])
#endif #endif
{ {
xp_awk_t awk; xp_awk_t* awk;
#ifdef __linux #ifdef __linux
mtrace (); mtrace ();
@ -75,35 +81,37 @@ int xp_main (int argc, char* argv[])
} }
#endif #endif
if (xp_awk_open(&awk) == XP_NULL) { if ((awk = xp_awk_open()) == XP_NULL) {
xp_printf (XP_TEXT("Error: cannot open awk\n")); xp_printf (XP_TEXT("Error: cannot open awk\n"));
return -1; return -1;
} }
if (xp_awk_attsrc(&awk, process_source, XP_NULL) == -1) { if (xp_awk_attsrc(awk, process_source, XP_NULL) == -1) {
xp_awk_close (&awk); xp_awk_close (awk);
xp_printf (XP_TEXT("error: cannot attach source\n")); xp_printf (XP_TEXT("error: cannot attach source\n"));
return -1; return -1;
} }
awk.opt.parse = XP_AWK_EXPLICIT | XP_AWK_UNIQUE | XP_AWK_SHADING | XP_AWK_IMPLICIT; xp_awk_setparseopt (awk,
XP_AWK_EXPLICIT | XP_AWK_UNIQUE |
XP_AWK_SHADING | XP_AWK_IMPLICIT);
if (xp_awk_parse(&awk) == -1) { if (xp_awk_parse(awk) == -1) {
xp_printf ( xp_printf (
XP_TEXT("error: cannot parse program - [%d] %s\n"), XP_TEXT("error: cannot parse program - [%d] %s\n"),
xp_awk_geterrnum(&awk), xp_awk_geterrstr(&awk)); xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
xp_awk_close (&awk); xp_awk_close (awk);
return -1; return -1;
} }
if (xp_awk_run(&awk) == -1) { if (xp_awk_run(awk) == -1) {
xp_printf ( xp_printf (
XP_TEXT("error: cannot run program - [%d] %s\n"), XP_TEXT("error: cannot run program - [%d] %s\n"),
xp_awk_geterrnum(&awk), xp_awk_geterrstr(&awk)); xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
xp_awk_close (&awk); xp_awk_close (awk);
} }
xp_awk_close (&awk); xp_awk_close (awk);
#ifdef __linux #ifdef __linux
muntrace (); muntrace ();