From 46f163c633767552bebcfdcb7a73b942b1ec0c81 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 18 Feb 2006 16:14:14 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/awk.c | 234 +--------------------------------------------- ase/awk/build.com | 48 ++++------ 2 files changed, 21 insertions(+), 261 deletions(-) diff --git a/ase/awk/awk.c b/ase/awk/awk.c index 94e22337..80b8262a 100644 --- a/ase/awk/awk.c +++ b/ase/awk/awk.c @@ -1,233 +1 @@ -/* - * $Id: awk.c,v 1.20 2006-02-07 15:28:05 bacon Exp $ - */ - -#include - -#ifndef __STAND_ALONE -#include -#include -#endif - -static void __free_func (void* func); - -xp_awk_t* xp_awk_open (xp_awk_t* awk) -{ - if (awk == XP_NULL) { - awk = (xp_awk_t*) xp_malloc (xp_sizeof(awk)); - if (awk == XP_NULL) return XP_NULL; - awk->__dynamic = xp_true; - } - else awk->__dynamic = xp_false; - - if (xp_str_open(&awk->token.name, 128) == XP_NULL) { - if (awk->__dynamic) xp_free (awk); - return XP_NULL; - } - - if (xp_awk_hash_open(&awk->tree.funcs, 256, __free_func) == XP_NULL) { - xp_str_close (&awk->token.name); - if (awk->__dynamic) xp_free (awk); - return XP_NULL; - } - - if (xp_awk_tab_open(&awk->parse.globals) == XP_NULL) { - xp_str_close (&awk->token.name); - xp_awk_hash_close (&awk->tree.funcs); - if (awk->__dynamic) xp_free (awk); - return XP_NULL; - } - - if (xp_awk_tab_open(&awk->parse.locals) == XP_NULL) { - xp_str_close (&awk->token.name); - xp_awk_hash_close (&awk->tree.funcs); - xp_awk_tab_close (&awk->parse.globals); - if (awk->__dynamic) xp_free (awk); - return XP_NULL; - } - - if (xp_awk_tab_open(&awk->parse.params) == XP_NULL) { - xp_str_close (&awk->token.name); - xp_awk_hash_close (&awk->tree.funcs); - xp_awk_tab_close (&awk->parse.globals); - xp_awk_tab_close (&awk->parse.locals); - if (awk->__dynamic) xp_free (awk); - return XP_NULL; - } - - awk->opt.parse = 0; - awk->opt.run = 0; - awk->errnum = XP_AWK_ENOERR; - - awk->src_func = XP_NULL; - awk->in_func = XP_NULL; - awk->out_func = XP_NULL; - - awk->src_arg = XP_NULL; - awk->in_arg = XP_NULL; - awk->out_arg = XP_NULL; - - awk->parse.nlocals_max = 0; - - awk->tree.nglobals = 0; - awk->tree.begin = XP_NULL; - awk->tree.end = XP_NULL; - awk->tree.chain = XP_NULL; - awk->tree.chain_tail = XP_NULL; - - awk->lex.curc = XP_CHAR_EOF; - awk->lex.ungotc_count = 0; - - return awk; -} - -int xp_awk_close (xp_awk_t* awk) -{ - xp_awk_clear (awk); - if (xp_awk_detsrc(awk) == -1) return -1; - - xp_awk_hash_close (&awk->tree.funcs); - xp_awk_tab_close (&awk->parse.globals); - xp_awk_tab_close (&awk->parse.locals); - xp_awk_tab_close (&awk->parse.params); - xp_str_close (&awk->token.name); - - if (awk->__dynamic) xp_free (awk); - return 0; -} - -int xp_awk_geterrnum (xp_awk_t* awk) -{ - return awk->errnum; -} - -const xp_char_t* xp_awk_geterrstr (xp_awk_t* awk) -{ - static const xp_char_t* __errstr[] = - { - XP_TEXT("no error"), - XP_TEXT("out of memory"), - - XP_TEXT("cannot open source"), - XP_TEXT("cannot close source"), - XP_TEXT("cannot read source"), - - XP_TEXT("invalid character"), - XP_TEXT("cannot unget character"), - - XP_TEXT("unexpected end of source"), - XP_TEXT("left brace expected"), - XP_TEXT("left parenthesis expected"), - XP_TEXT("right parenthesis expected"), - XP_TEXT("right bracket expected"), - XP_TEXT("comma expected"), - XP_TEXT("semicolon expected"), - XP_TEXT("expression expected"), - - XP_TEXT("keyword 'while' expected"), - XP_TEXT("assignment statement expected"), - XP_TEXT("identifier expected"), - XP_TEXT("duplicate BEGIN"), - XP_TEXT("duplicate END"), - XP_TEXT("duplicate function name"), - XP_TEXT("duplicate parameter name"), - XP_TEXT("duplicate variable name"), - XP_TEXT("duplicate name"), - XP_TEXT("undefined identifier") - }; - - if (awk->errnum >= 0 && awk->errnum < xp_countof(__errstr)) { - return __errstr[awk->errnum]; - } - - return XP_TEXT("unknown error"); -} - -// TODO: write a function to clear awk->parse data structure. -// this would be need either as a separate function or as a part of xp_awk_clear... -// do i have to pass an option to xp_awk_clear to do this??? - -void xp_awk_clear (xp_awk_t* awk) -{ - xp_awk_tab_clear (&awk->parse.globals); - xp_awk_tab_clear (&awk->parse.locals); - xp_awk_tab_clear (&awk->parse.params); - awk->parse.nlocals_max = 0; - - /* clear parse trees */ - awk->tree.nglobals = 0; - xp_awk_hash_clear (&awk->tree.funcs); - - if (awk->tree.begin != XP_NULL) { - xp_assert (awk->tree.begin->next == XP_NULL); - xp_awk_clrpt (awk->tree.begin); - awk->tree.begin = XP_NULL; - } - - if (awk->tree.end != XP_NULL) { - xp_assert (awk->tree.end->next == XP_NULL); - xp_awk_clrpt (awk->tree.end); - awk->tree.end = XP_NULL; - } - - while (awk->tree.chain != XP_NULL) { - xp_awk_chain_t* next = awk->tree.chain->next; - - if (awk->tree.chain->pattern != XP_NULL) - xp_awk_clrpt (awk->tree.chain->pattern); - if (awk->tree.chain->action != XP_NULL) - xp_awk_clrpt (awk->tree.chain->action); - xp_free (awk->tree.chain); - - awk->tree.chain = next; - } - awk->tree.chain_tail = XP_NULL; - - /* TODO: destroy function list */ -} - -int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg) -{ - if (xp_awk_detsrc(awk) == -1) return -1; - - xp_assert (awk->src_func == XP_NULL); - - if (src(XP_AWK_IO_OPEN, arg, XP_NULL, 0) == -1) { - awk->errnum = XP_AWK_ESRCOP; - return -1; - } - - awk->src_func = src; - awk->src_arg = arg; - awk->lex.curc = XP_CHAR_EOF; - awk->lex.ungotc_count = 0; - return 0; -} - -int xp_awk_detsrc (xp_awk_t* awk) -{ - 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->src_func = XP_NULL; - awk->src_arg = XP_NULL; - awk->lex.curc = XP_CHAR_EOF; - awk->lex.ungotc_count = 0; - } - - return 0; -} - -static void __free_func (void* func) -{ - xp_awk_func_t* f = (xp_awk_func_t*) func; - - /* f->name doesn't have to be freed */ - /*xp_free (f->name);*/ - - xp_awk_clrpt (f->body); - xp_free (f); -} +/* * $Id: awk.c,v 1.21 2006-02-18 16:14:14 bacon Exp $ */#include #ifndef __STAND_ALONE#include #include #endifstatic void __free_func (void* func);xp_awk_t* xp_awk_open (xp_awk_t* awk){ if (awk == XP_NULL) { awk = (xp_awk_t*) xp_malloc (xp_sizeof(awk)); if (awk == XP_NULL) return XP_NULL; awk->__dynamic = xp_true; } else awk->__dynamic = xp_false; if (xp_str_open(&awk->token.name, 128) == XP_NULL) { if (awk->__dynamic) xp_free (awk); return XP_NULL; } if (xp_awk_hash_open(&awk->tree.funcs, 256, __free_func) == XP_NULL) { xp_str_close (&awk->token.name); if (awk->__dynamic) xp_free (awk); return XP_NULL; } if (xp_awk_tab_open(&awk->parse.globals) == XP_NULL) { xp_str_close (&awk->token.name); xp_awk_hash_close (&awk->tree.funcs); if (awk->__dynamic) xp_free (awk); return XP_NULL; } if (xp_awk_tab_open(&awk->parse.locals) == XP_NULL) { xp_str_close (&awk->token.name); xp_awk_hash_close (&awk->tree.funcs); xp_awk_tab_close (&awk->parse.globals); if (awk->__dynamic) xp_free (awk); return XP_NULL; } if (xp_awk_tab_open(&awk->parse.params) == XP_NULL) { xp_str_close (&awk->token.name); xp_awk_hash_close (&awk->tree.funcs); xp_awk_tab_close (&awk->parse.globals); xp_awk_tab_close (&awk->parse.locals); if (awk->__dynamic) xp_free (awk); return XP_NULL; } awk->opt.parse = 0; awk->opt.run = 0; awk->errnum = XP_AWK_ENOERR; awk->src_func = XP_NULL; awk->in_func = XP_NULL; awk->out_func = XP_NULL; awk->src_arg = XP_NULL; awk->in_arg = XP_NULL; awk->out_arg = XP_NULL; awk->parse.nlocals_max = 0; awk->tree.nglobals = 0; awk->tree.begin = XP_NULL; awk->tree.end = XP_NULL; awk->tree.chain = XP_NULL; awk->tree.chain_tail = XP_NULL; awk->lex.curc = XP_CHAR_EOF; awk->lex.ungotc_count = 0; return awk;}int xp_awk_close (xp_awk_t* awk){ xp_awk_clear (awk); if (xp_awk_detsrc(awk) == -1) return -1; xp_awk_hash_close (&awk->tree.funcs); xp_awk_tab_close (&awk->parse.globals); xp_awk_tab_close (&awk->parse.locals); xp_awk_tab_close (&awk->parse.params); xp_str_close (&awk->token.name); if (awk->__dynamic) xp_free (awk); return 0;}int xp_awk_geterrnum (xp_awk_t* awk){ return awk->errnum;}const xp_char_t* xp_awk_geterrstr (xp_awk_t* awk){ static const xp_char_t* __errstr[] = { XP_TEXT("no error"), XP_TEXT("out of memory"), XP_TEXT("cannot open source"), XP_TEXT("cannot close source"), XP_TEXT("cannot read source"), XP_TEXT("invalid character"), XP_TEXT("cannot unget character"), XP_TEXT("unexpected end of source"), XP_TEXT("left brace expected"), XP_TEXT("left parenthesis expected"), XP_TEXT("right parenthesis expected"), XP_TEXT("right bracket expected"), XP_TEXT("comma expected"), XP_TEXT("semicolon expected"), XP_TEXT("expression expected"), XP_TEXT("keyword 'while' expected"), XP_TEXT("assignment statement expected"), XP_TEXT("identifier expected"), XP_TEXT("duplicate BEGIN"), XP_TEXT("duplicate END"), XP_TEXT("duplicate function name"), XP_TEXT("duplicate parameter name"), XP_TEXT("duplicate variable name"), XP_TEXT("duplicate name"), XP_TEXT("undefined identifier") }; if (awk->errnum >= 0 && awk->errnum < xp_countof(__errstr)) { return __errstr[awk->errnum]; } return XP_TEXT("unknown error");}// TODO: write a function to clear awk->parse data structure.// this would be need either as a separate function or as a part of xp_awk_clear...// do i have to pass an option to xp_awk_clear to do this???void xp_awk_clear (xp_awk_t* awk){ xp_awk_tab_clear (&awk->parse.globals); xp_awk_tab_clear (&awk->parse.locals); xp_awk_tab_clear (&awk->parse.params); awk->parse.nlocals_max = 0; /* clear parse trees */ awk->tree.nglobals = 0; xp_awk_hash_clear (&awk->tree.funcs); if (awk->tree.begin != XP_NULL) { xp_assert (awk->tree.begin->next == XP_NULL); xp_awk_clrpt (awk->tree.begin); awk->tree.begin = XP_NULL; } if (awk->tree.end != XP_NULL) { xp_assert (awk->tree.end->next == XP_NULL); xp_awk_clrpt (awk->tree.end); awk->tree.end = XP_NULL; } while (awk->tree.chain != XP_NULL) { xp_awk_chain_t* next = awk->tree.chain->next; if (awk->tree.chain->pattern != XP_NULL) xp_awk_clrpt (awk->tree.chain->pattern); if (awk->tree.chain->action != XP_NULL) xp_awk_clrpt (awk->tree.chain->action); xp_free (awk->tree.chain); awk->tree.chain = next; } awk->tree.chain_tail = XP_NULL; /* TODO: destroy function list */}int xp_awk_attsrc (xp_awk_t* awk, xp_awk_io_t src, void* arg){ if (xp_awk_detsrc(awk) == -1) return -1; xp_assert (awk->src_func == XP_NULL); if (src(XP_AWK_IO_OPEN, arg, XP_NULL, 0) == -1) { awk->errnum = XP_AWK_ESRCOP; return -1; } awk->src_func = src; awk->src_arg = arg; awk->lex.curc = XP_CHAR_EOF; awk->lex.ungotc_count = 0; return 0;}int xp_awk_detsrc (xp_awk_t* awk){ 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->src_func = XP_NULL; awk->src_arg = XP_NULL; awk->lex.curc = XP_CHAR_EOF; awk->lex.ungotc_count = 0; } return 0;}static void __free_func (void* func){ xp_awk_func_t* f = (xp_awk_func_t*) func; /* f->name doesn't have to be freed */ /*xp_free (f->name);*/ xp_awk_clrpt (f->body); xp_free (f);} \ No newline at end of file diff --git a/ase/awk/build.com b/ase/awk/build.com index 84d5c56b..a7d10337 100644 --- a/ase/awk/build.com +++ b/ase/awk/build.com @@ -1,33 +1,25 @@ -$ write sys$output "cc/define=__STAND_ALONE awk.c" -$ cc/define=__STAND_ALONE awk.c -$ -$ write sys$output "cc/define=__STAND_ALONE parse.c" -$ cc/define=__STAND_ALONE parse.c -$ -$ write sys$output "cc/define=__STAND_ALONE tree.c" -$ cc/define=__STAND_ALONE tree.c -$ -$ write sys$output "cc/define=__STAND_ALONE sa.c" -$ cc/define=__STAND_ALONE sa.c -$ -$ write sys$output "lib/create xpawk awk,parse,tree,sa" -$ lib/create xpawk awk,parse,tree,sa +$ xxx: - -$ objs := awk,hash,tab,tree,parse,sa -$ -$ loop: -$ file = -$ if file .ne. "" -$ then -$ gosub compile -$ goto loop -$ endif $ +$ names := awk,hash,tab,tree,parse,sa +$ gosub compile +$ gosub archive $ exit -$ +$ $ compile: -$ write sys$output "awk.c" +$ num = 0 +$ compile_loop: +$ name = f$element(num,",",names) +$ if name .eqs. "," then return +$ gosub compile_file +$ num = num + 1 +$ goto compile_loop +$ +$ compile_file: +$ write sys$output "Compiling ''name'.c..." +$ cc/define=__STAND_ALONE 'name' $ return - - +$ +$ archive: +$ write sys$output "Creating library..." +$ lib/create xpawk 'names'