diff --git a/ase/awk/rex.c b/ase/awk/rex.c index 6f88bb9b..dea18038 100644 --- a/ase/awk/rex.c +++ b/ase/awk/rex.c @@ -1,5 +1,5 @@ /* - * $Id: rex.c,v 1.67 2007-02-23 10:33:20 bacon Exp $ + * $Id: rex.c,v 1.68 2007-02-23 10:57:09 bacon Exp $ * * {License} */ @@ -139,13 +139,13 @@ typedef const ase_byte_t* (*atom_matcher_t) ( #define ADD_CODE(rex,data,len) \ do { if (__add_code(rex,data,len) == -1) return -1; } while (0) -/* #if defined(__sparc) || defined(__sparc__) +#if defined(__sparc) || defined(__sparc__) #define GET_CODE(rex,pos,type) __get_code(rex,pos) #define SET_CODE(rex,pos,type,code) __set_code(rex,pos,code) -#else */ +#else #define GET_CODE(rex,pos,type) (*((type*)&(rex)->code.buf[pos])) #define SET_CODE(rex,pos,type,code) (GET_CODE(rex,pos,type) = (code)) -/* #endif */ +#endif static int __build_pattern (__builder_t* rex); static int __build_pattern0 (__builder_t* rex); diff --git a/ase/lsp/err.c b/ase/lsp/err.c index bcbd653d..00e99c87 100644 --- a/ase/lsp/err.c +++ b/ase/lsp/err.c @@ -1,5 +1,5 @@ /* - * $Id: err.c,v 1.11 2007-02-11 07:36:54 bacon Exp $ + * $Id: err.c,v 1.12 2007-02-23 10:53:38 bacon Exp $ * * {License} */ @@ -63,14 +63,14 @@ void ase_lsp_seterror ( switch (argcnt) { case 0: - lsp->prmfns.sprintf ( + lsp->prmfns.misc.sprintf ( lsp->errmsg, ASE_COUNTOF(lsp->errmsg), errfmt); return; case 1: - lsp->prmfns.sprintf ( + lsp->prmfns.misc.sprintf ( lsp->errmsg, ASE_COUNTOF(lsp->errmsg), errfmt, @@ -78,7 +78,7 @@ void ase_lsp_seterror ( return; case 2: - lsp->prmfns.sprintf ( + lsp->prmfns.misc.sprintf ( lsp->errmsg, ASE_COUNTOF(lsp->errmsg), errfmt, @@ -87,7 +87,7 @@ void ase_lsp_seterror ( return; case 3: - lsp->prmfns.sprintf ( + lsp->prmfns.misc.sprintf ( lsp->errmsg, ASE_COUNTOF(lsp->errmsg), errfmt, @@ -97,7 +97,7 @@ void ase_lsp_seterror ( return; case 4: - lsp->prmfns.sprintf ( + lsp->prmfns.misc.sprintf ( lsp->errmsg, ASE_COUNTOF(lsp->errmsg), errfmt, @@ -108,7 +108,7 @@ void ase_lsp_seterror ( return; case 5: - lsp->prmfns.sprintf ( + lsp->prmfns.misc.sprintf ( lsp->errmsg, ASE_COUNTOF(lsp->errmsg), errfmt, diff --git a/ase/lsp/lsp.c b/ase/lsp/lsp.c index 4f5da182..8e356209 100644 --- a/ase/lsp/lsp.c +++ b/ase/lsp/lsp.c @@ -1,5 +1,5 @@ /* - * $Id: lsp.c,v 1.24 2007-02-13 06:00:20 bacon Exp $ + * $Id: lsp.c,v 1.25 2007-02-23 10:53:38 bacon Exp $ * * {License} */ @@ -21,48 +21,41 @@ ase_lsp_t* ase_lsp_open ( if (prmfns == ASE_NULL) return ASE_NULL; - if (prmfns->malloc == ASE_NULL || - prmfns->realloc == ASE_NULL || - prmfns->free == ASE_NULL) return ASE_NULL; + if (prmfns->mmgr.malloc == ASE_NULL || + prmfns->mmgr.realloc == ASE_NULL || + prmfns->mmgr.free == ASE_NULL) return ASE_NULL; - if (prmfns->is_upper == ASE_NULL || - prmfns->is_lower == ASE_NULL || - prmfns->is_alpha == ASE_NULL || - prmfns->is_digit == ASE_NULL || - prmfns->is_xdigit == ASE_NULL || - prmfns->is_alnum == ASE_NULL || - prmfns->is_space == ASE_NULL || - prmfns->is_print == ASE_NULL || - prmfns->is_graph == ASE_NULL || - prmfns->is_cntrl == ASE_NULL || - prmfns->is_punct == ASE_NULL || - prmfns->to_upper == ASE_NULL || - prmfns->to_lower == ASE_NULL) return ASE_NULL; + if (prmfns->ccls.is_upper == ASE_NULL || + prmfns->ccls.is_lower == ASE_NULL || + prmfns->ccls.is_alpha == ASE_NULL || + prmfns->ccls.is_digit == ASE_NULL || + prmfns->ccls.is_xdigit == ASE_NULL || + prmfns->ccls.is_alnum == ASE_NULL || + prmfns->ccls.is_space == ASE_NULL || + prmfns->ccls.is_print == ASE_NULL || + prmfns->ccls.is_graph == ASE_NULL || + prmfns->ccls.is_cntrl == ASE_NULL || + prmfns->ccls.is_punct == ASE_NULL || + prmfns->ccls.to_upper == ASE_NULL || + prmfns->ccls.to_lower == ASE_NULL) return ASE_NULL; - if (prmfns->sprintf == ASE_NULL || - prmfns->aprintf == ASE_NULL || - prmfns->dprintf == ASE_NULL || - prmfns->abort == ASE_NULL) return ASE_NULL; + if (prmfns->misc.sprintf == ASE_NULL || + prmfns->misc.aprintf == ASE_NULL || + prmfns->misc.dprintf == ASE_NULL || + prmfns->misc.abort == ASE_NULL) return ASE_NULL; #if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) lsp = (ase_lsp_t*) malloc (ASE_SIZEOF(ase_lsp_t)); #else - lsp = (ase_lsp_t*) prmfns->malloc ( - ASE_SIZEOF(ase_lsp_t), prmfns->custom_data); + lsp = (ase_lsp_t*) prmfns->mmgr.malloc ( + &prmfns->mmgr, ASE_SIZEOF(ase_lsp_t)); #endif if (lsp == ASE_NULL) return ASE_NULL; /* it uses the built-in ase_lsp_memset because lsp is not * fully initialized yet */ - ase_lsp_memset (lsp, 0, ASE_SIZEOF(ase_lsp_t)); - - if (prmfns->memcpy == ASE_NULL) - { - ase_lsp_memcpy (&lsp->prmfns, prmfns, ASE_SIZEOF(lsp->prmfns)); - lsp->prmfns.memcpy = ase_lsp_memcpy; - } - else prmfns->memcpy (&lsp->prmfns, prmfns, ASE_SIZEOF(lsp->prmfns)); - if (prmfns->memset == ASE_NULL) lsp->prmfns.memset = ase_lsp_memset; + ase_memset (lsp, 0, ASE_SIZEOF(ase_lsp_t)); + ase_memcpy (&lsp->prmfns, prmfns, ASE_SIZEOF(lsp->prmfns)); if (ase_lsp_name_open(&lsp->token.name, 0, lsp) == ASE_NULL) { diff --git a/ase/lsp/lsp.h b/ase/lsp/lsp.h index a36ae9ed..1b8a1d65 100644 --- a/ase/lsp/lsp.h +++ b/ase/lsp/lsp.h @@ -1,5 +1,5 @@ /* - * $Id: lsp.h,v 1.38 2007-02-11 08:30:18 bacon Exp $ + * $Id: lsp.h,v 1.39 2007-02-23 10:53:38 bacon Exp $ * * {License} */ @@ -17,14 +17,6 @@ typedef struct ase_lsp_prmfns_t ase_lsp_prmfns_t; typedef ase_ssize_t (*ase_lsp_io_t) ( int cmd, void* arg, ase_char_t* data, ase_size_t count); -typedef void* (*ase_lsp_malloc_t) (ase_size_t n, void* custom_data); -typedef void* (*ase_lsp_realloc_t) (void* ptr, ase_size_t n, void* custom_data); -typedef void (*ase_lsp_free_t) (void* ptr, void* custom_data); -typedef void* (*ase_lsp_memcpy_t) (void* dst, const void* src, ase_size_t n); -typedef void* (*ase_lsp_memset_t) (void* dst, int val, ase_size_t n); - -typedef ase_bool_t (*ase_lsp_isctype_t) (ase_cint_t c); -typedef ase_cint_t (*ase_lsp_toctype_t) (ase_cint_t c); typedef ase_real_t (*ase_lsp_pow_t) (ase_real_t x, ase_real_t y); typedef int (*ase_lsp_sprintf_t) ( @@ -35,36 +27,19 @@ typedef void (*ase_lsp_abort_t) (void* custom_data); struct ase_lsp_prmfns_t { - /* memory */ - ase_lsp_malloc_t malloc; - ase_lsp_realloc_t realloc; - ase_lsp_free_t free; - - ase_lsp_memcpy_t memcpy; - ase_lsp_memset_t memset; - - /* character class */ - ase_lsp_isctype_t is_upper; - ase_lsp_isctype_t is_lower; - ase_lsp_isctype_t is_alpha; - ase_lsp_isctype_t is_digit; - ase_lsp_isctype_t is_xdigit; - ase_lsp_isctype_t is_alnum; - ase_lsp_isctype_t is_space; - ase_lsp_isctype_t is_print; - ase_lsp_isctype_t is_graph; - ase_lsp_isctype_t is_cntrl; - ase_lsp_isctype_t is_punct; - ase_lsp_toctype_t to_upper; - ase_lsp_toctype_t to_lower; + ase_mmgr_t mmgr; + ase_ccls_t ccls; /* utilities */ - ase_lsp_sprintf_t sprintf; - ase_lsp_aprintf_t aprintf; - ase_lsp_dprintf_t dprintf; - ase_lsp_abort_t abort; + struct + { + ase_lsp_sprintf_t sprintf; + ase_lsp_aprintf_t aprintf; + ase_lsp_dprintf_t dprintf; + ase_lsp_abort_t abort; + void* custom_data; + } misc; - void* custom_data; }; /* io function commands */ @@ -156,34 +131,6 @@ int ase_lsp_addprim ( ase_lsp_prim_t prim, ase_size_t min_args, ase_size_t max_args); int ase_lsp_removeprim (ase_lsp_t* lsp, const ase_char_t* name); -/* string functions exported by lsp.h */ -ase_char_t* ase_lsp_strdup (ase_lsp_t* lsp, const ase_char_t* str); -ase_char_t* ase_lsp_strxdup ( - ase_lsp_t* lsp, const ase_char_t* str, ase_size_t len); -ase_char_t* ase_lsp_strxdup2 ( - ase_lsp_t* lsp, - const ase_char_t* str1, ase_size_t len1, - const ase_char_t* str2, ase_size_t len2); - -ase_size_t ase_lsp_strlen (const ase_char_t* str); -ase_size_t ase_lsp_strcpy (ase_char_t* buf, const ase_char_t* str); -ase_size_t ase_lsp_strncpy (ase_char_t* buf, const ase_char_t* str, ase_size_t len); -int ase_lsp_strcmp (const ase_char_t* s1, const ase_char_t* s2); - -int ase_lsp_strxncmp ( - const ase_char_t* s1, ase_size_t len1, - const ase_char_t* s2, ase_size_t len2); - -int ase_lsp_strxncasecmp ( - ase_lsp_t* lsp, - const ase_char_t* s1, ase_size_t len1, - const ase_char_t* s2, ase_size_t len2); - -ase_char_t* ase_lsp_strxnstr ( - const ase_char_t* str, ase_size_t strsz, - const ase_char_t* sub, ase_size_t subsz); - - /* abort function for assertion. use ASE_LSP_ASSERT instead */ int ase_lsp_assertfail (ase_lsp_t* lsp, const ase_char_t* expr, const ase_char_t* desc, diff --git a/ase/lsp/lsp_i.h b/ase/lsp/lsp_i.h index 27076d5d..fb54653c 100644 --- a/ase/lsp/lsp_i.h +++ b/ase/lsp/lsp_i.h @@ -1,5 +1,5 @@ /* - * $Id: lsp_i.h,v 1.8 2007-02-11 07:36:55 bacon Exp $ + * $Id: lsp_i.h,v 1.9 2007-02-23 10:53:38 bacon Exp $ * * {License} */ @@ -7,6 +7,9 @@ #ifndef _ASE_LSP_LSPI_H_ #define _ASE_LSP_LSPI_H_ +#include +#include + #include #include #include @@ -19,38 +22,24 @@ #pragma warning (disable: 4996) #endif -#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) - #define _CRTDBG_MAP_ALLOC - #include - #define ASE_LSP_MALLOC(lsp,size) malloc (size) - #define ASE_LSP_REALLOC(lsp,ptr,size) realloc (ptr, size) - #define ASE_LSP_FREE(lsp,ptr) free (ptr) -#else - #define ASE_LSP_MALLOC(lsp,size) \ - (lsp)->prmfns.malloc (size, (lsp)->prmfns.custom_data) - #define ASE_LSP_REALLOC(lsp,ptr,size) \ - (lsp)->prmfns.realloc (ptr, size, (lsp)->prmfns.custom_data) - #define ASE_LSP_FREE(lsp,ptr) \ - (lsp)->prmfns.free (ptr, (lsp)->prmfns.custom_data) -#endif +#define ASE_LSP_MALLOC(lsp,size) ASE_MALLOC(&(lsp)->prmfns.mmgr,size) +#define ASE_LSP_REALLOC(lsp,ptr,size) ASE_REALLOC(&(lsp)->prmfns.mmgr,ptr,size) +#define ASE_LSP_FREE(lsp,ptr) ASE_FREE(&(lsp)->prmfns.mmgr,ptr) -#define ASE_LSP_ISUPPER(lsp,c) (lsp)->prmfns.is_upper(c) -#define ASE_LSP_ISLOWER(lsp,c) (lsp)->prmfns.is_lower(c) -#define ASE_LSP_ISALPHA(lsp,c) (lsp)->prmfns.is_alpha(c) -#define ASE_LSP_ISDIGIT(lsp,c) (lsp)->prmfns.is_digit(c) -#define ASE_LSP_ISXDIGIT(lsp,c) (lsp)->prmfns.is_xdigit(c) -#define ASE_LSP_ISALNUM(lsp,c) (lsp)->prmfns.is_alnum(c) -#define ASE_LSP_ISSPACE(lsp,c) (lsp)->prmfns.is_space(c) -#define ASE_LSP_ISPRINT(lsp,c) (lsp)->prmfns.is_print(c) -#define ASE_LSP_ISGRAPH(lsp,c) (lsp)->prmfns.is_graph(c) -#define ASE_LSP_ISCNTRL(lsp,c) (lsp)->prmfns.is_cntrl(c) -#define ASE_LSP_ISPUNCT(lsp,c) (lsp)->prmfns.is_punct(c) -#define ASE_LSP_TOUPPER(lsp,c) (lsp)->prmfns.to_upper(c) -#define ASE_LSP_TOLOWER(lsp,c) (lsp)->prmfns.to_lower(c) - -#define ASE_LSP_MEMCPY(lsp,dst,src,len) (lsp)->prmfns.memcpy (dst, src, len) -#define ASE_LSP_MEMSET(lsp,dst,val,len) (lsp)->prmfns.memset (dst, val, len) +#define ASE_LSP_ISUPPER(lsp,c) ASE_ISUPPER(&(lsp)->prmfns.ccls,c) +#define ASE_LSP_ISLOWER(lsp,c) ASE_ISLOWER(&(lsp)->prmfns.ccls,c) +#define ASE_LSP_ISALPHA(lsp,c) ASE_ISALPHA(&(lsp)->prmfns.ccls,c) +#define ASE_LSP_ISDIGIT(lsp,c) ASE_ISDIGIT(&(lsp)->prmfns.ccls,c) +#define ASE_LSP_ISXDIGIT(lsp,c) ASE_ISXDIGIT(&(lsp)->prmfns.ccls,c) +#define ASE_LSP_ISALNUM(lsp,c) ASE_ISALNUM(&(lsp)->prmfns.ccls,c) +#define ASE_LSP_ISSPACE(lsp,c) ASE_ISSPACE(&(lsp)->prmfns.ccls,c) +#define ASE_LSP_ISPRINT(lsp,c) ASE_ISPRINT(&(lsp)->prmfns.ccls,c) +#define ASE_LSP_ISGRAPH(lsp,c) ASE_ISGRAPH(&(lsp)->prmfns.ccls,c) +#define ASE_LSP_ISCNTRL(lsp,c) ASE_ISCNTRL(&(lsp)->prmfns.ccls,c) +#define ASE_LSP_ISPUNCT(lsp,c) ASE_ISPUNCT(&(lsp)->prmfns.ccls,c) +#define ASE_LSP_TOUPPER(lsp,c) ASE_TOUPPER(&(lsp)->prmfns.ccls,c) +#define ASE_LSP_TOLOWER(lsp,c) ASE_TOLOWER(&(lsp)->prmfns.ccls,c) struct ase_lsp_t { diff --git a/ase/lsp/mem.c b/ase/lsp/mem.c index d1a0bfaa..58bd0c44 100644 --- a/ase/lsp/mem.c +++ b/ase/lsp/mem.c @@ -1,5 +1,5 @@ /* - * $Id: mem.c,v 1.30 2007-02-13 06:00:20 bacon Exp $ + * $Id: mem.c,v 1.31 2007-02-23 10:53:38 bacon Exp $ * * {License} */ @@ -16,7 +16,7 @@ ase_lsp_mem_t* ase_lsp_openmem ( mem = (ase_lsp_mem_t*) ASE_LSP_MALLOC (lsp, ASE_SIZEOF(ase_lsp_mem_t)); if (mem == ASE_NULL) return ASE_NULL; - ASE_LSP_MEMSET (lsp, mem, 0, ASE_SIZEOF(ase_lsp_mem_t)); + ase_memset (mem, 0, ASE_SIZEOF(ase_lsp_mem_t)); mem->lsp = lsp; /* create a new root environment frame */ @@ -431,9 +431,10 @@ ase_lsp_obj_t* ase_lsp_makesym ( while (obj != ASE_NULL) { // if there is a symbol with the same name, it is just used. - if (ase_lsp_strxncmp ( + if (ase_strxncmp ( ASE_LSP_SYMPTR(obj), - ASE_LSP_SYMLEN(obj), str, len) == 0) return obj; + ASE_LSP_SYMLEN(obj), + str, len) == 0) return obj; obj = ASE_LSP_LINK(obj); } @@ -443,7 +444,7 @@ ase_lsp_obj_t* ase_lsp_makesym ( if (obj == ASE_NULL) return ASE_NULL; // fill in the symbol buffer - ase_lsp_strncpy (ASE_LSP_SYMPTR(obj), str, len); + ase_strncpy (ASE_LSP_SYMPTR(obj), str, len); return obj; } @@ -459,7 +460,7 @@ ase_lsp_obj_t* ase_lsp_makestr ( if (obj == ASE_NULL) return ASE_NULL; // fill in the string buffer - ase_lsp_strncpy (ASE_LSP_STRPTR(obj), str, len); + ase_strncpy (ASE_LSP_STRPTR(obj), str, len); return obj; } diff --git a/ase/lsp/misc.c b/ase/lsp/misc.c index a68e110a..0db97cba 100644 --- a/ase/lsp/misc.c +++ b/ase/lsp/misc.c @@ -1,40 +1,11 @@ /* - * $Id: misc.c,v 1.8 2007-02-03 10:51:52 bacon Exp $ + * $Id: misc.c,v 1.9 2007-02-23 10:53:39 bacon Exp $ * * {License} */ #include -void* ase_lsp_memcpy (void* dst, const void* src, ase_size_t n) -{ - void* p = dst; - void* e = (ase_byte_t*)dst + n; - - while (dst < e) - { - *(ase_byte_t*)dst = *(ase_byte_t*)src; - dst = (ase_byte_t*)dst + 1; - src = (ase_byte_t*)src + 1; - } - - return p; -} - -void* ase_lsp_memset (void* dst, int val, ase_size_t n) -{ - void* p = dst; - void* e = (ase_byte_t*)p + n; - - while (p < e) - { - *(ase_byte_t*)p = (ase_byte_t)val; - p = (ase_byte_t*)p + 1; - } - - return dst; -} - ase_long_t ase_lsp_strxtolong ( ase_lsp_t* lsp, const ase_char_t* str, ase_size_t len, int base, const ase_char_t** endptr) @@ -537,7 +508,7 @@ ase_size_t ase_lsp_longtostr ( ase_size_t len, ret, i; ase_size_t prefix_len; - prefix_len = (prefix != ASE_NULL)? ase_lsp_strlen(prefix): 0; + prefix_len = (prefix != ASE_NULL)? ase_strlen(prefix): 0; t = value; if (t == 0) @@ -602,172 +573,23 @@ ase_size_t ase_lsp_longtostr ( return ret; } -ase_char_t* ase_lsp_strdup (ase_lsp_t* lsp, const ase_char_t* str) -{ - ase_char_t* tmp; - - tmp = (ase_char_t*) ASE_LSP_MALLOC ( - lsp, (ase_lsp_strlen(str) + 1) * ASE_SIZEOF(ase_char_t)); - if (tmp == ASE_NULL) return ASE_NULL; - - ase_lsp_strcpy (tmp, str); - return tmp; -} - -ase_char_t* ase_lsp_strxdup (ase_lsp_t* lsp, const ase_char_t* str, ase_size_t len) -{ - ase_char_t* tmp; - - tmp = (ase_char_t*) ASE_LSP_MALLOC ( - lsp, (len + 1) * ASE_SIZEOF(ase_char_t)); - if (tmp == ASE_NULL) return ASE_NULL; - - ase_lsp_strncpy (tmp, str, len); - return tmp; -} - -ase_char_t* ase_lsp_strxdup2 ( - ase_lsp_t* lsp, - const ase_char_t* str1, ase_size_t len1, - const ase_char_t* str2, ase_size_t len2) -{ - ase_char_t* tmp; - - tmp = (ase_char_t*) ASE_LSP_MALLOC ( - lsp, (len1 + len2 + 1) * ASE_SIZEOF(ase_char_t)); - if (tmp == ASE_NULL) return ASE_NULL; - - ase_lsp_strncpy (tmp, str1, len1); - ase_lsp_strncpy (tmp + len1, str2, len2); - return tmp; -} - -ase_size_t ase_lsp_strlen (const ase_char_t* str) -{ - const ase_char_t* p = str; - while (*p != ASE_T('\0')) p++; - return p - str; -} - -ase_size_t ase_lsp_strcpy (ase_char_t* buf, const ase_char_t* str) -{ - ase_char_t* org = buf; - while ((*buf++ = *str++) != ASE_T('\0')); - return buf - org - 1; -} - -ase_size_t ase_lsp_strncpy (ase_char_t* buf, const ase_char_t* str, ase_size_t len) -{ - const ase_char_t* end = str + len; - while (str < end) *buf++ = *str++; - *buf = ASE_T('\0'); - return len; -} - -int ase_lsp_strcmp (const ase_char_t* s1, const ase_char_t* s2) -{ - while (*s1 == *s2) - { - if (*s1 == ASE_C('\0')) return 0; - s1++, s2++; - } - - return (*s1 > *s2)? 1: -1; -} - -int ase_lsp_strxncmp ( - const ase_char_t* s1, ase_size_t len1, - const ase_char_t* s2, ase_size_t len2) -{ - ase_char_t c1, c2; - const ase_char_t* end1 = s1 + len1; - const ase_char_t* end2 = s2 + len2; - - while (s1 < end1) - { - c1 = *s1; - if (s2 < end2) - { - c2 = *s2; - if (c1 > c2) return 1; - if (c1 < c2) return -1; - } - else return 1; - s1++; s2++; - } - - return (s2 < end2)? -1: 0; -} - -int ase_lsp_strxncasecmp ( - ase_lsp_t* lsp, - const ase_char_t* s1, ase_size_t len1, - const ase_char_t* s2, ase_size_t len2) -{ - ase_char_t c1, c2; - const ase_char_t* end1 = s1 + len1; - const ase_char_t* end2 = s2 + len2; - - while (s1 < end1) - { - c1 = ASE_LSP_TOUPPER (lsp, *s1); - if (s2 < end2) - { - c2 = ASE_LSP_TOUPPER (lsp, *s2); - if (c1 > c2) return 1; - if (c1 < c2) return -1; - } - else return 1; - s1++; s2++; - } - - return (s2 < end2)? -1: 0; -} - -ase_char_t* ase_lsp_strxnstr ( - const ase_char_t* str, ase_size_t strsz, - const ase_char_t* sub, ase_size_t subsz) -{ - const ase_char_t* end, * subp; - - if (subsz == 0) return (ase_char_t*)str; - if (strsz < subsz) return ASE_NULL; - - end = str + strsz - subsz; - subp = sub + subsz; - - while (str <= end) { - const ase_char_t* x = str; - const ase_char_t* y = sub; - - while (ase_true) { - if (y >= subp) return (ase_char_t*)str; - if (*x != *y) break; - x++; y++; - } - - str++; - } - - return ASE_NULL; -} - int ase_lsp_assertfail (ase_lsp_t* lsp, const ase_char_t* expr, const ase_char_t* desc, const ase_char_t* file, int line) { if (desc == ASE_NULL) { - lsp->prmfns.aprintf ( + lsp->prmfns.misc.aprintf ( ASE_T("ASSERTION FAILURE AT FILE %s LINE %d\n%s\n"), file, line, expr); } else { - lsp->prmfns.aprintf ( + lsp->prmfns.misc.aprintf ( ASE_T("ASSERTION FAILURE AT FILE %s LINE %d\n%s\n\nDESCRIPTION:\n%s\n"), file, line, expr, desc); } - lsp->prmfns.abort (lsp); + + lsp->prmfns.misc.abort (lsp->prmfns.misc.custom_data); return 0; } diff --git a/ase/lsp/name.c b/ase/lsp/name.c index 1b7e0afe..b1c883ed 100644 --- a/ase/lsp/name.c +++ b/ase/lsp/name.c @@ -1,5 +1,5 @@ /* - * $Id: name.c,v 1.14 2007-02-03 10:51:52 bacon Exp $ + * $Id: name.c,v 1.15 2007-02-23 10:53:39 bacon Exp $ * * {License} */ @@ -71,8 +71,7 @@ int ase_lsp_name_addc (ase_lsp_name_t* name, ase_cint_t c) if (space == ASE_NULL) return -1; /* don't need to copy up to the terminating null */ - ASE_LSP_MEMCPY (name->lsp, space, name->buf, - name->capa*ASE_SIZEOF(ase_char_t)); + ase_memcpy (space, name->buf, name->capa*ASE_SIZEOF(ase_char_t)); } else { diff --git a/ase/lsp/prim_compar.c b/ase/lsp/prim_compar.c index 2d929129..8a8b373f 100644 --- a/ase/lsp/prim_compar.c +++ b/ase/lsp/prim_compar.c @@ -1,5 +1,5 @@ /* - * $Id: prim_compar.c,v 1.13 2007-02-11 07:36:55 bacon Exp $ + * $Id: prim_compar.c,v 1.14 2007-02-23 10:53:39 bacon Exp $ * * {License} */ @@ -69,7 +69,7 @@ { \ if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_SYM) \ { \ - res = ase_lsp_strxncmp ( \ + res = ase_strxncmp ( \ ASE_LSP_SYMPTR(p1), ASE_LSP_SYMLEN(p1), \ ASE_LSP_SYMPTR(p2), ASE_LSP_SYMLEN(p2)) op 0; \ } \ @@ -85,7 +85,7 @@ { \ if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_STR) \ { \ - res = ase_lsp_strxncmp ( \ + res = ase_strxncmp ( \ ASE_LSP_STRPTR(p1), ASE_LSP_STRLEN(p1), \ ASE_LSP_STRPTR(p2), ASE_LSP_STRLEN(p2)) op 0; \ } \ diff --git a/ase/lsp/print.c b/ase/lsp/print.c index 76857b30..7d047dae 100644 --- a/ase/lsp/print.c +++ b/ase/lsp/print.c @@ -1,5 +1,5 @@ /* - * $Id: print.c,v 1.24 2007-02-17 15:27:19 bacon Exp $ + * $Id: print.c,v 1.25 2007-02-23 10:53:39 bacon Exp $ * * {License} */ @@ -8,7 +8,7 @@ #define OUTPUT_STR(lsp,str) \ do { \ - if (lsp->output_func(ASE_LSP_IO_WRITE, lsp->output_arg, (ase_char_t*)str, ase_lsp_strlen(str)) == -1) { \ + if (lsp->output_func(ASE_LSP_IO_WRITE, lsp->output_arg, (ase_char_t*)str, ase_strlen(str)) == -1) { \ ase_lsp_seterror (lsp, ASE_LSP_EOUTPUT, ASE_NULL, 0); \ return -1; \ } \ @@ -44,19 +44,19 @@ static int __print (ase_lsp_t* lsp, const ase_lsp_obj_t* obj, ase_bool_t prt_con case ASE_LSP_OBJ_INT: #if ASE_SIZEOF_LONG_LONG > 0 - lsp->prmfns.sprintf ( + lsp->prmfns.misc.sprintf ( buf, ASE_COUNTOF(buf), ASE_T("%lld"), (long long)ASE_LSP_IVAL(obj)); #elif ASE_SIZEOF___INT64 > 0 - lsp->prmfns.sprintf ( + lsp->prmfns.misc.sprintf ( buf, ASE_COUNTOF(buf), ASE_T("%I64d"), (__int64)ASE_LSP_IVAL(obj)); #elif ASE_SIZEOF_LONG > 0 - lsp->prmfns.sprintf ( + lsp->prmfns.misc.sprintf ( buf, ASE_COUNTOF(buf), ASE_T("%ld"), (long)ASE_LSP_IVAL(obj)); #elif ASE_SIZEOF_INT > 0 - lsp->prmfns.sprintf ( + lsp->prmfns.misc.sprintf ( buf, ASE_COUNTOF(buf), ASE_T("%d"), (int)ASE_LSP_IVAL(obj)); #else @@ -66,7 +66,7 @@ static int __print (ase_lsp_t* lsp, const ase_lsp_obj_t* obj, ase_bool_t prt_con break; case ASE_LSP_OBJ_REAL: - lsp->prmfns.sprintf (buf, ASE_COUNTOF(buf), + lsp->prmfns.misc.sprintf (buf, ASE_COUNTOF(buf), ASE_T("%Lf"), (long double)ASE_LSP_RVAL(obj)); OUTPUT_STR (lsp, buf); @@ -128,7 +128,7 @@ static int __print (ase_lsp_t* lsp, const ase_lsp_obj_t* obj, ase_bool_t prt_con break; default: - lsp->prmfns.sprintf (buf, ASE_COUNTOF(buf), + lsp->prmfns.misc.sprintf (buf, ASE_COUNTOF(buf), ASE_T("unknown object type: %d"), ASE_LSP_TYPE(obj)); OUTPUT_STR (lsp, buf); } diff --git a/ase/test/lsp/lsp.c b/ase/test/lsp/lsp.c index db4878c0..99e5cd5a 100644 --- a/ase/test/lsp/lsp.c +++ b/ase/test/lsp/lsp.c @@ -97,47 +97,37 @@ struct prmfns_data_t }; #endif -static void* lsp_malloc (ase_size_t n, void* custom_data) +static void* lsp_malloc (ase_mmgr_t* mmgr, ase_size_t n) { #ifdef _WIN32 - return HeapAlloc (((prmfns_data_t*)custom_data)->heap, 0, n); + return HeapAlloc (((prmfns_data_t*)mmgr->custom_data)->heap, 0, n); #else return malloc (n); #endif } -static void* lsp_realloc (void* ptr, ase_size_t n, void* custom_data) +static void* lsp_realloc (ase_mmgr_t* mmgr, void* ptr, ase_size_t n) { #ifdef _WIN32 /* HeapReAlloc behaves differently from realloc */ if (ptr == NULL) - return HeapAlloc (((prmfns_data_t*)custom_data)->heap, 0, n); + return HeapAlloc (((prmfns_data_t*)mmgr->custom_data)->heap, 0, n); else - return HeapReAlloc (((prmfns_data_t*)custom_data)->heap, 0, ptr, n); + return HeapReAlloc (((prmfns_data_t*)mmgr->custom_data)->heap, 0, ptr, n); #else return realloc (ptr, n); #endif } -static void lsp_free (void* ptr, void* custom_data) +static void lsp_free (ase_mmgr_t* mmgr, void* ptr) { #ifdef _WIN32 - HeapFree (((prmfns_data_t*)custom_data)->heap, 0, ptr); + HeapFree (((prmfns_data_t*)mmgr->custom_data)->heap, 0, ptr); #else free (ptr); #endif } -static void* lsp_memcpy (void* dst, const void* src, ase_size_t n) -{ - return memcpy (dst, src, n); -} - -static void* lsp_memset (void* dst, int val, ase_size_t n) -{ - return memset (dst, val, n); -} - static void lsp_abort (void* custom_data) { abort (); @@ -197,31 +187,10 @@ int lsp_main (int argc, ase_char_t* argv[]) } memset (&prmfns, 0, sizeof(prmfns)); - prmfns.malloc = lsp_malloc; - prmfns.realloc = lsp_realloc; - prmfns.free = lsp_free; - prmfns.memcpy = lsp_memcpy; - prmfns.memset = lsp_memset; - - prmfns.is_upper = (ase_lsp_isctype_t)ase_isupper; - prmfns.is_lower = (ase_lsp_isctype_t)ase_islower; - prmfns.is_alpha = (ase_lsp_isctype_t)ase_isalpha; - prmfns.is_digit = (ase_lsp_isctype_t)ase_isdigit; - prmfns.is_xdigit = (ase_lsp_isctype_t)ase_isxdigit; - prmfns.is_alnum = (ase_lsp_isctype_t)ase_isalnum; - prmfns.is_space = (ase_lsp_isctype_t)ase_isspace; - prmfns.is_print = (ase_lsp_isctype_t)ase_isprint; - prmfns.is_graph = (ase_lsp_isctype_t)ase_isgraph; - prmfns.is_cntrl = (ase_lsp_isctype_t)ase_iscntrl; - prmfns.is_punct = (ase_lsp_isctype_t)ase_ispunct; - prmfns.to_upper = (ase_lsp_toctype_t)ase_toupper; - prmfns.to_lower = (ase_lsp_toctype_t)ase_tolower; - - prmfns.sprintf = ase_sprintf; - prmfns.aprintf = lsp_aprintf; - prmfns.dprintf = lsp_dprintf; - prmfns.abort = lsp_abort; + prmfns.mmgr.malloc = lsp_malloc; + prmfns.mmgr.realloc = lsp_realloc; + prmfns.mmgr.free = lsp_free; #ifdef _WIN32 prmfns_data.heap = HeapCreate (0, 1000000, 1000000); if (prmfns_data.heap == NULL) @@ -230,9 +199,31 @@ int lsp_main (int argc, ase_char_t* argv[]) return -1; } - prmfns.custom_data = &prmfns_data; + prmfns.mmgr.custom_data = &prmfns_data; +#else + prmfns.mmgr.custom_data = ASE_NULL; #endif + prmfns.ccls.is_upper = ase_isupper; + prmfns.ccls.is_lower = ase_islower; + prmfns.ccls.is_alpha = ase_isalpha; + prmfns.ccls.is_digit = ase_isdigit; + prmfns.ccls.is_xdigit = ase_isxdigit; + prmfns.ccls.is_alnum = ase_isalnum; + prmfns.ccls.is_space = ase_isspace; + prmfns.ccls.is_print = ase_isprint; + prmfns.ccls.is_graph = ase_isgraph; + prmfns.ccls.is_cntrl = ase_iscntrl; + prmfns.ccls.is_punct = ase_ispunct; + prmfns.ccls.to_upper = ase_toupper; + prmfns.ccls.to_lower = ase_tolower; + prmfns.ccls.custom_data = ASE_NULL; + + prmfns.misc.sprintf = ase_sprintf; + prmfns.misc.aprintf = lsp_aprintf; + prmfns.misc.dprintf = lsp_dprintf; + prmfns.misc.abort = lsp_abort; + lsp = ase_lsp_open (&prmfns, mem, inc); if (lsp == ASE_NULL) { diff --git a/ase/test/lsp/makefile.in b/ase/test/lsp/makefile.in index 0eccf487..643e39be 100644 --- a/ase/test/lsp/makefile.in +++ b/ase/test/lsp/makefile.in @@ -3,8 +3,8 @@ OBJS = $(SRCS:.c=.o) CC = @CC@ CFLAGS = @CFLAGS@ -I@abs_top_builddir@/.. -LDFLAGS = @LDFLAGS@ -L@abs_top_builddir@/lsp -L@abs_top_builddir@/utl -LIBS = @LIBS@ -laselsp -laseutl -lm +LDFLAGS = @LDFLAGS@ -L@abs_top_builddir@/cmn -L@abs_top_builddir@/lsp -L@abs_top_builddir@/utl +LIBS = @LIBS@ -laseutl -laselsp -lasecmn -lm all: aselsp diff --git a/ase/utl/stdio.h b/ase/utl/stdio.h index 13779821..ac5241be 100644 --- a/ase/utl/stdio.h +++ b/ase/utl/stdio.h @@ -1,5 +1,5 @@ /* - * $Id: stdio.h,v 1.3 2007-02-22 14:32:08 bacon Exp $ + * $Id: stdio.h,v 1.4 2007-02-23 10:53:39 bacon Exp $ */ #ifndef _ASE_UTL_STDIO_H_ @@ -10,6 +10,7 @@ #include #include +#include #if defined(_WIN32) #include