*** empty log message ***

This commit is contained in:
hyung-hwan 2006-04-21 16:21:27 +00:00
parent 48bfdf6e2c
commit a5a2a79d9b
4 changed files with 101 additions and 24 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.42 2006-04-20 16:17:01 bacon Exp $
* $Id: awk.c,v 1.43 2006-04-21 16:21:27 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -19,25 +19,29 @@ xp_awk_t* xp_awk_open (void)
awk = (xp_awk_t*) xp_malloc (xp_sizeof(xp_awk_t));
if (awk == XP_NULL) return XP_NULL;
if (xp_str_open(&awk->token.name, 128) == XP_NULL) {
if (xp_str_open(&awk->token.name, 128) == XP_NULL)
{
xp_free (awk);
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_free (awk);
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_awk_map_close (&awk->tree.funcs);
xp_free (awk);
return XP_NULL;
}
if (xp_awk_tab_open(&awk->parse.locals) == XP_NULL) {
if (xp_awk_tab_open(&awk->parse.locals) == XP_NULL)
{
xp_str_close (&awk->token.name);
xp_awk_map_close (&awk->tree.funcs);
xp_awk_tab_close (&awk->parse.globals);
@ -45,7 +49,8 @@ xp_awk_t* xp_awk_open (void)
return XP_NULL;
}
if (xp_awk_tab_open(&awk->parse.params) == XP_NULL) {
if (xp_awk_tab_open(&awk->parse.params) == XP_NULL)
{
xp_str_close (&awk->token.name);
xp_awk_map_close (&awk->tree.funcs);
xp_awk_tab_close (&awk->parse.globals);
@ -55,7 +60,8 @@ xp_awk_t* xp_awk_open (void)
}
/* TODO: initial map size... */
if (xp_awk_map_open(&awk->run.named,awk,256,__free_namedval) == XP_NULL) {
if (xp_awk_map_open(&awk->run.named,awk,256,__free_namedval) == XP_NULL)
{
xp_str_close (&awk->token.name);
xp_awk_map_close (&awk->tree.funcs);
xp_awk_tab_close (&awk->parse.globals);

View File

@ -1,5 +1,5 @@
/*
* $Id: awk_i.h,v 1.5 2006-04-21 06:06:32 bacon Exp $
* $Id: awk_i.h,v 1.6 2006-04-21 16:21:27 bacon Exp $
*/
#ifndef _XP_AWK_AWKI_H_
@ -19,6 +19,7 @@
#endif
typedef struct xp_awk_chain_t xp_awk_chain_t;
typedef struct xp_awk_run-t xp_awk_run_t;
/*
*
@ -33,12 +34,12 @@ struct xp_awk_run_t
};
awk = xp_awk_open ();
xp_awk_parse (awk, "source");
xp_awk_parse (awk, source_input, source_output);
thr = create_thread (5);
thr[0]->xp_awk_run (awk, "data1");
thr[1]->xp_awk_run (awk, "data2");
thr[2]->xp_awk_run (awk, "data3");
thr[0]->xp_awk_run (awk, input_stream1, output_stream1);
thr[1]->xp_awk_run (awk, input_stream2, output_stream2);
thr[2]->xp_awk_run (awk, input_stream3, output_stream3);
xp_awk_setcallback (void* __command_callback (int cmd, void* arg), void* arg);
xp_awk_run (awk)
@ -125,7 +126,6 @@ struct xp_awk_t
/* housekeeping */
int errnum;
xp_bool_t __dynamic;
};
struct xp_awk_chain_t
@ -135,4 +135,24 @@ struct xp_awk_chain_t
xp_awk_chain_t* next;
};
struct xp_awk_run_t
{
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;
/* input_stream */
/* output_stream */
xp_awk_t* awk;
};
#endif

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.65 2006-04-21 06:06:32 bacon Exp $
* $Id: run.c,v 1.66 2006-04-21 16:21:27 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -304,6 +304,57 @@ xp_printf (XP_TEXT("-[END VARIABLES]--------------------------\n"));
return n;
}
static void __free_namedval (xp_run_t* awk, void* val)
{
xp_awk_refdownval (run, val);
}
static int __open_run (xp_awk_run_t* run, xp_awk_run_t* awk)
{
run->awk = awk;
run->stack = XP_NULL;
run->stack_top = 0;
run->stack_base = 0;
run->stack_limit = 0;
run->exit_level = 0;
run->icache_count = 0;
run->rcache_count = 0;
if (xp_awk_map_open (&run->named,
awk, 256, __free_namedval) == XP_NULL) return -1;
}
static void __close_run (xp_awk_run_t* run)
{
/* destroy run stack */
if (run->stack != XP_NULL)
{
xp_free (run->stack);
run->stack = XP_NULL;
run->stack_top = 0;
run->stack_base = 0;
run->stack_limit = 0;
}
/* destroy named variables */
xp_awk_map_close (&run->named);
/* destroy values in free list */
while (run->icache_count > 0)
{
--run->icache_count;
xp_awk_freeval (run,
run->icache[run->icache_count], xp_false);
}
while (run->rcache_count > 0)
{
--run->rcache_count;
xp_awk_freeval (run,
run->rcache[run->rcache_count], xp_false);
}
}
static int __run_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde)
{
xp_awk_nde_t* p;

View File

@ -1,5 +1,5 @@
/*
* $Id: sa.c,v 1.17 2006-04-19 04:18:43 bacon Exp $
* $Id: sa.c,v 1.18 2006-04-21 16:21:27 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -83,9 +83,7 @@ int xp_strxncmp (
const xp_char_t* end1 = s1 + len1;
const xp_char_t* end2 = s2 + len2;
while (s1 < end1 && s2 < end2 && *s1 == *s2) {
s1++; s2++;
}
while (s1 < end1 && s2 < end2 && *s1 == *s2) s1++, s2++;
if (s1 == end1 && s2 == end2) return 0;
if (*s1 == *s2) return (s1 < end1)? 1: -1;
return (*s1 > *s2)? 1: -1;
@ -148,16 +146,17 @@ int xp_vsprintf (xp_char_t* buf, xp_size_t size, const xp_char_t* fmt, xp_va_lis
xp_str_t* xp_str_open (xp_str_t* str, xp_size_t capa)
{
if (str == XP_NULL) {
if (str == XP_NULL)
{
str = (xp_str_t*)xp_malloc (sizeof(xp_str_t));
if (str == XP_NULL) return XP_NULL;
str->__dynamic = xp_true;
}
else str->__dynamic = xp_false;
str->buf = (xp_char_t*)xp_malloc (
xp_sizeof(xp_char_t) * (capa + 1));
if (str->buf == XP_NULL) {
str->buf = (xp_char_t*) xp_malloc (xp_sizeof(xp_char_t) * (capa + 1));
if (str->buf == XP_NULL)
{
if (str->__dynamic) xp_free (str);
return XP_NULL;
}
@ -199,13 +198,14 @@ xp_size_t xp_str_ncat (xp_str_t* str, const xp_char_t* s, xp_size_t len)
xp_char_t* buf;
xp_size_t capa;
if (len > str->capa - str->size) {
if (len > str->capa - str->size)
{
capa = str->size + len;
/* double the capa if necessary for concatenation */
if (capa < str->capa * 2) capa = str->capa * 2;
buf = (xp_char_t*)xp_realloc (
buf = (xp_char_t*) xp_realloc (
str->buf, xp_sizeof(xp_char_t) * (capa + 1));
if (buf == XP_NULL) return (xp_size_t)-1;