From 023d391d8651570f596b5c6f1342bc7a2e761c28 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 4 Apr 2006 16:03:14 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/Makefile.bcc | 2 +- ase/awk/Makefile.cl | 2 +- ase/awk/Makefile.lcc | 4 +-- ase/awk/awk.dsp | 4 +++ ase/awk/awk.h | 6 +++- ase/awk/makefile.in | 2 +- ase/awk/misc.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ ase/awk/parse.c | 6 ++-- ase/awk/sa.c | 22 +----------- ase/awk/sa.h | 8 +---- 10 files changed, 98 insertions(+), 37 deletions(-) create mode 100644 ase/awk/misc.c diff --git a/ase/awk/Makefile.bcc b/ase/awk/Makefile.bcc index 29eeb86e..32edb9bc 100644 --- a/ase/awk/Makefile.bcc +++ b/ase/awk/Makefile.bcc @@ -1,4 +1,4 @@ -SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c +SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c misc.c OBJS = $(SRCS:.c=.obj) OUT = xpawk.lib diff --git a/ase/awk/Makefile.cl b/ase/awk/Makefile.cl index fb2c044e..5903f05f 100644 --- a/ase/awk/Makefile.cl +++ b/ase/awk/Makefile.cl @@ -1,4 +1,4 @@ -SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c +SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c misc.c OBJS = $(SRCS:.c=.obj) OUT = xpawk diff --git a/ase/awk/Makefile.lcc b/ase/awk/Makefile.lcc index 1752593d..13dcc5c8 100644 --- a/ase/awk/Makefile.lcc +++ b/ase/awk/Makefile.lcc @@ -1,5 +1,5 @@ -SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c -OBJS = awk.obj err.obj tree.obj tab.obj map.obj parse.obj run.obj sa.obj val.obj +SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c misc.c +OBJS = awk.obj err.obj tree.obj tab.obj map.obj parse.obj run.obj sa.obj val.obj misc.obj OUT = xpawk.lib CC = lcc diff --git a/ase/awk/awk.dsp b/ase/awk/awk.dsp index 492e4704..382854b3 100644 --- a/ase/awk/awk.dsp +++ b/ase/awk/awk.dsp @@ -136,6 +136,10 @@ SOURCE=.\tree.c SOURCE=.\val.c # End Source File # End Group +# +SOURCE=.\misc.c +# End Source File +# End Group # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl" diff --git a/ase/awk/awk.h b/ase/awk/awk.h index 0e09eaeb..73069181 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.40 2006-04-02 12:41:14 bacon Exp $ + * $Id: awk.h,v 1.41 2006-04-04 16:03:14 bacon Exp $ */ #ifndef _XP_AWK_AWK_H_ @@ -89,6 +89,10 @@ int xp_awk_detout (xp_awk_t* awk); int xp_awk_parse (xp_awk_t* awk); int xp_awk_run (xp_awk_t* awk); +/* utility functions exported by awk.h */ +xp_long_t xp_awk_strtolong (const xp_char_t* str, int base); +xp_real_t xp_awk_strtoreal (const xp_char_t* str); + #ifdef __cplusplus } #endif diff --git a/ase/awk/makefile.in b/ase/awk/makefile.in index 80672f6a..6505bff2 100644 --- a/ase/awk/makefile.in +++ b/ase/awk/makefile.in @@ -1,4 +1,4 @@ -SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c +SRCS = awk.c err.c tree.c tab.c map.c parse.c run.c sa.c val.c misc.c OBJS = $(SRCS:.c=.o) OUT = libxpawk.a diff --git a/ase/awk/misc.c b/ase/awk/misc.c new file mode 100644 index 00000000..c7396b0e --- /dev/null +++ b/ase/awk/misc.c @@ -0,0 +1,79 @@ +/* + * $Id: misc.c,v 1.1 2006-04-04 16:03:14 bacon Exp $ + */ + +#include + +#ifndef __STAND_ALONE +#include +#include +#endif + +xp_long_t xp_awk_strtolong (const xp_char_t* str, int base) +{ + xp_long_t n = 0; + const xp_char_t* p; + int digit, sign = 0; + + xp_assert (base < 37); + + p = str; while (xp_isspace(*p)) p++; + + while (*p != XP_CHAR('\0')) + { + if (*p == XP_CHAR('-')) + { + sign = ~sign; + p++; + } + else if (*p == XP_CHAR('+')) p++; + else break; + } + + if (base == 0) + { + if (*p == XP_CHAR('0')) + { + p++; + if (*p == XP_CHAR('x')) + { + p++; base = 16; + } + else base = 8; + } + else base = 10; + } + else if (base == 16) + { + // skip a leading "0x" from hex numbers. + if ((*p == XP_CHAR('0')) && (*(p+1) == XP_CHAR('x'))) + { + p += 2; + } + } + + while (*p != XP_CHAR('\0')) + { + if (*p >= XP_CHAR('0') && *p <= XP_CHAR('9')) + digit = *p - XP_CHAR('0'); + else if (*p >= XP_CHAR('A') && *p <= XP_CHAR('Z')) + digit = *p - XP_CHAR('A') + 10; + else if (*p >= XP_CHAR('a') && *p <= XP_CHAR('z')) + digit = *p - XP_CHAR('a') + 10; + else break; + + if (digit >= base) break; + n = n * base + digit; + + p++; + } + + return (sign)? -n: n; +} + +xp_real_t xp_awk_strtoreal (const xp_char_t* str) +{ + /* TODO: */ + return (xp_real_t)0.0; +} + diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 020395df..ef4caabd 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.69 2006-04-04 06:26:56 bacon Exp $ + * $Id: parse.c,v 1.70 2006-04-04 16:03:14 bacon Exp $ */ #include @@ -1466,7 +1466,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk) nde->type = XP_AWK_NDE_INT; nde->next = XP_NULL; - nde->val = xp_strtolong (XP_STR_BUF(&awk->token.name)); + nde->val = xp_awk_strtolong (XP_STR_BUF(&awk->token.name), 0); xp_assert ( XP_STR_LEN(&awk->token.name) == @@ -1489,7 +1489,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk) nde->type = XP_AWK_NDE_REAL; nde->next = XP_NULL; - nde->val = xp_strtoreal (XP_STR_BUF(&awk->token.name)); + nde->val = xp_awk_strtoreal (XP_STR_BUF(&awk->token.name)); xp_assert ( XP_STR_LEN(&awk->token.name) == diff --git a/ase/awk/sa.c b/ase/awk/sa.c index 89609e0f..55253ddc 100644 --- a/ase/awk/sa.c +++ b/ase/awk/sa.c @@ -1,5 +1,5 @@ /* - * $Id: sa.c,v 1.13 2006-03-31 16:35:37 bacon Exp $ + * $Id: sa.c,v 1.14 2006-04-04 16:03:14 bacon Exp $ */ #include @@ -66,26 +66,6 @@ int xp_strcmp (const xp_char_t* s1, const xp_char_t* s2) return 0; } -xp_long_t xp_strtolong (xp_char_t* str) -{ - xp_long_t n = 0; - - while (xp_isdigit(*str)) - { - n = n * 10 + (*str - XP_CHAR('0')); - str++; - } - - return n; -} - -xp_real_t xp_strtoreal (xp_char_t* str) -{ - /* TODO: */ - return (xp_real_t)0.0; -} - - int xp_printf (const xp_char_t* fmt, ...) { int n; diff --git a/ase/awk/sa.h b/ase/awk/sa.h index e3829e4d..a2f639f2 100644 --- a/ase/awk/sa.h +++ b/ase/awk/sa.h @@ -1,5 +1,5 @@ /* - * $Id: sa.h,v 1.18 2006-04-04 06:26:56 bacon Exp $ + * $Id: sa.h,v 1.19 2006-04-04 16:03:14 bacon Exp $ */ #ifndef _XP_AWK_SA_H_ @@ -99,12 +99,6 @@ xp_size_t xp_strxncpy ( #define xp_strcmp xp_awk_strcmp 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); - -#define xp_strtoreal xp_awk_strtoreal -xp_real_t xp_strtoreal (xp_char_t* str); - #define xp_printf xp_awk_printf int xp_printf (const xp_char_t* fmt, ...);