*** empty log message ***

This commit is contained in:
hyung-hwan 2006-09-01 06:23:58 +00:00
parent a4833392b7
commit 069a25f54f
25 changed files with 683 additions and 702 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h,v 1.105 2006-09-01 03:44:16 bacon Exp $ * $Id: awk.h,v 1.106 2006-09-01 06:22:11 bacon Exp $
*/ */
#ifndef _XP_AWK_AWK_H_ #ifndef _XP_AWK_AWK_H_
@ -59,6 +59,21 @@ struct xp_awk_syscas_t
xp_awk_lk_t lock; xp_awk_lk_t lock;
xp_awk_lk_t unlock; xp_awk_lk_t unlock;
/* character class */
xp_bool_t (*is_upper) (xp_cint_t c);
xp_bool_t (*is_lower) (xp_cint_t c);
xp_bool_t (*is_alpha) (xp_cint_t c);
xp_bool_t (*is_digit) (xp_cint_t c);
xp_bool_t (*is_xdigit) (xp_cint_t c);
xp_bool_t (*is_alnum) (xp_cint_t c);
xp_bool_t (*is_space) (xp_cint_t c);
xp_bool_t (*is_print) (xp_cint_t c);
xp_bool_t (*is_graph) (xp_cint_t c);
xp_bool_t (*is_cntrl) (xp_cint_t c);
xp_bool_t (*is_punct) (xp_cint_t c);
xp_cint_t (*to_upper) (xp_cint_t c);
xp_cint_t (*to_lower) (xp_cint_t c);
void* custom_data; void* custom_data;
}; };
@ -317,8 +332,10 @@ void xp_awk_setretval (void* run, xp_awk_val_t* val);
/* utility functions exported by awk.h */ /* utility functions exported by awk.h */
xp_long_t xp_awk_strtolong ( xp_long_t xp_awk_strtolong (
const xp_char_t* str, int base, const xp_char_t** endptr); xp_awk_t* awk, const xp_char_t* str,
xp_real_t xp_awk_strtoreal (const xp_char_t* str); int base, const xp_char_t** endptr);
xp_real_t xp_awk_strtoreal (
xp_awk_t* awk, const xp_char_t* str);
/* string functions exported by awk.h */ /* string functions exported by awk.h */
xp_char_t* xp_awk_strdup ( xp_char_t* xp_awk_strdup (
@ -330,6 +347,38 @@ xp_char_t* xp_awk_strxdup2 (
const xp_char_t* str1, xp_size_t len1, const xp_char_t* str1, xp_size_t len1,
const xp_char_t* str2, xp_size_t len2); const xp_char_t* str2, xp_size_t len2);
xp_size_t xp_awk_strlen (const xp_char_t* str);
xp_size_t xp_awk_strcpy (xp_char_t* buf, const xp_char_t* str);
xp_size_t xp_awk_strncpy (xp_char_t* buf, const xp_char_t* str, xp_size_t len);
int xp_awk_strcmp (const xp_char_t* s1, const xp_char_t* s2);
int xp_awk_strxncmp (
const xp_char_t* s1, xp_size_t len1,
const xp_char_t* s2, xp_size_t len2);
xp_char_t* xp_awk_strxnstr (
const xp_char_t* str, xp_size_t strsz,
const xp_char_t* sub, xp_size_t subsz);
xp_char_t* xp_awk_strtok (
xp_awk_t* awk, const xp_char_t* s,
const xp_char_t* delim, xp_char_t** tok, xp_size_t* tok_len);
xp_char_t* xp_awk_strxtok (
xp_awk_t* awk, const xp_char_t* s, xp_size_t len,
const xp_char_t* delim, xp_char_t** tok, xp_size_t* tok_len);
xp_char_t* xp_awk_strxntok (
xp_awk_t* awk, const xp_char_t* s, xp_size_t len,
const xp_char_t* delim, xp_size_t delim_len,
xp_char_t** tok, xp_size_t* tok_len);
int xp_awk_printf (xp_awk_t* awk, const xp_char_t* fmt, ...);
int xp_awk_sprintf (
xp_awk_t* awk, xp_char_t* buf,
xp_size_t size, const xp_char_t* fmt, ...);
/* utility functions to convert an error number ot a string */ /* utility functions to convert an error number ot a string */
const xp_char_t* xp_awk_geterrstr (int errnum); const xp_char_t* xp_awk_geterrstr (int errnum);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk_i.h,v 1.52 2006-09-01 04:03:28 bacon Exp $ * $Id: awk_i.h,v 1.53 2006-09-01 06:22:11 bacon Exp $
*/ */
#ifndef _XP_AWK_AWKI_H_ #ifndef _XP_AWK_AWKI_H_
@ -12,7 +12,40 @@ typedef struct xp_awk_tree_t xp_awk_tree_t;
#include <xp/awk/awk.h> #include <xp/awk/awk.h>
#ifdef XP_AWK_STAND_ALONE #ifdef XP_AWK_STAND_ALONE
#include <xp/awk/sa.h>
#if !defined(XP_CHAR_IS_MCHAR) && !defined(XP_CHAR_IS_WCHAR)
#error Neither XP_CHAR_IS_MCHAR nor XP_CHAR_IS_WCHAR is defined.
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
#ifdef XP_CHAR_IS_MCHAR
#include <ctype.h>
#else
#include <ctype.h>
#include <wchar.h>
#if !defined(__BEOS__)
#include <wctype.h>
#endif
#endif
#define xp_assert assert
#define xp_memset(dst,fill,len) memset(dst,fill,len)
#define xp_memcpy(dst,src,len) memcpy(dst,src,len)
#define xp_memmove(dst,src,len) memmove(dst,src,len)
#define xp_memcmp(src1,src2,len) memcmp(src1,src2,len)
#define xp_memzero(dst,len) memset(dst,0,len)
#define xp_va_start(pvar,param) va_start(pvar,param)
#define xp_va_list va_list
#define xp_va_end(pvar) va_end(pvar)
#define xp_va_arg(pvar,type) va_arg(pvar,type)
#endif #endif
#include <xp/awk/str.h> #include <xp/awk/str.h>
@ -54,16 +87,30 @@ typedef struct xp_awk_tree_t xp_awk_tree_t;
#define XP_AWK_LOCK(awk) \ #define XP_AWK_LOCK(awk) \
do { \ do { \
if (awk->syscas != XP_NULL && awk->syscas->lock != XP_NULL) \ if ((awk)->syscas != XP_NULL && (awk)->syscas->lock != XP_NULL) \
awk->syscas->lock (awk, awk->syscas->custom_data); \ (awk)->syscas->lock (awk, (awk)->syscas->custom_data); \
} while (0) } while (0)
#define XP_AWK_UNLOCK(awk) \ #define XP_AWK_UNLOCK(awk) \
do { \ do { \
if (awk->syscas != XP_NULL && awk->syscas->unlock != XP_NULL) \ if ((awk)->syscas != XP_NULL && (awk)->syscas->unlock != XP_NULL) \
awk->syscas->unlock (awk, awk->syscas->custom_data); \ (awk)->syscas->unlock (awk, (awk)->syscas->custom_data); \
} while (0) } while (0)
#define XP_AWK_ISUPPER(awk,c) (awk)->syscas->is_upper(c)
#define XP_AWK_ISLOWER(awk,c) (awk)->syscas->is_lower(c)
#define XP_AWK_ISALPHA(awk,c) (awk)->syscas->is_alpha(c)
#define XP_AWK_ISDIGIT(awk,c) (awk)->syscas->is_digit(c)
#define XP_AWK_ISXDIGIT(awk,c) (awk)->syscas->is_xdigit(c)
#define XP_AWK_ISALNUM(awk,c) (awk)->syscas->is_alnum(c)
#define XP_AWK_ISSPACE(awk,c) (awk)->syscas->is_space(c)
#define XP_AWK_ISPRINT(awk,c) (awk)->syscas->is_print(c)
#define XP_AWK_ISGRAPH(awk,c) (awk)->syscas->is_graph(c)
#define XP_AWK_ISCNTRL(awk,c) (awk)->syscas->is_cntrl(c)
#define XP_AWK_ISPUNCT(awk,c) (awk)->syscas->is_punct(c)
#define XP_AWK_TOUPPER(awk,c) (awk)->syscas->to_upper(c)
#define XP_AWK_TOLOWER(awk,c) (awk)->syscas->to_lower(c)
struct xp_awk_tree_t struct xp_awk_tree_t
{ {
xp_size_t nglobals; /* total number of globals */ xp_size_t nglobals; /* total number of globals */

View File

@ -1,5 +1,5 @@
/* /*
* $Id: extio.c,v 1.43 2006-09-01 03:44:16 bacon Exp $ * $Id: extio.c,v 1.44 2006-09-01 06:22:11 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -114,7 +114,7 @@ int xp_awk_readextio (
while (p != XP_NULL) while (p != XP_NULL)
{ {
if (p->type == (extio_type | extio_mask) && if (p->type == (extio_type | extio_mask) &&
xp_strcmp(p->name,name) == 0) break; xp_awk_strcmp(p->name,name) == 0) break;
p = p->next; p = p->next;
} }
@ -340,14 +340,10 @@ int xp_awk_readextio (
nr = xp_awk_getglobal (run, XP_AWK_GLOBAL_NR); nr = xp_awk_getglobal (run, XP_AWK_GLOBAL_NR);
xp_awk_refupval (nr); xp_awk_refupval (nr);
n = xp_awk_valtonum (nr, &lv, &rv); n = xp_awk_valtonum (run, nr, &lv, &rv);
xp_awk_refdownval (run, nr); xp_awk_refdownval (run, nr);
if (n == -1) if (n == -1) ret = -1;
{
run->errnum = XP_AWK_EVALTYPE;
ret = -1;
}
else else
{ {
if (n == 1) lv = (xp_long_t)rv; if (n == 1) lv = (xp_long_t)rv;
@ -439,7 +435,7 @@ static int __writeextio (
* print "1111" > "1.tmp" * print "1111" > "1.tmp"
*/ */
if (p->type == (extio_type | extio_mask) && if (p->type == (extio_type | extio_mask) &&
xp_strcmp (p->name, name) == 0) break; xp_awk_strcmp (p->name, name) == 0) break;
p = p->next; p = p->next;
} }
@ -574,7 +570,7 @@ int xp_awk_flushextio (
while (p != XP_NULL) while (p != XP_NULL)
{ {
if (p->type == (extio_type | extio_mask) && if (p->type == (extio_type | extio_mask) &&
(name == XP_NULL || xp_strcmp (p->name, name) == 0)) (name == XP_NULL || xp_awk_strcmp (p->name, name) == 0))
{ {
n = handler (XP_AWK_IO_FLUSH, p, XP_NULL, 0); n = handler (XP_AWK_IO_FLUSH, p, XP_NULL, 0);
@ -633,7 +629,7 @@ int xp_awk_nextextio_read (
while (p != XP_NULL) while (p != XP_NULL)
{ {
if (p->type == (extio_type | extio_mask) && if (p->type == (extio_type | extio_mask) &&
xp_strcmp(p->name,name) == 0) break; xp_awk_strcmp(p->name,name) == 0) break;
p = p->next; p = p->next;
} }
@ -682,7 +678,7 @@ int xp_awk_closeextio_read (
while (p != XP_NULL) while (p != XP_NULL)
{ {
if (p->type == (extio_type | extio_mask) && if (p->type == (extio_type | extio_mask) &&
xp_strcmp (p->name, name) == 0) xp_awk_strcmp (p->name, name) == 0)
{ {
xp_awk_io_t handler; xp_awk_io_t handler;
@ -742,7 +738,7 @@ int xp_awk_closeextio_write (
while (p != XP_NULL) while (p != XP_NULL)
{ {
if (p->type == (extio_type | extio_mask) && if (p->type == (extio_type | extio_mask) &&
xp_strcmp (p->name, name) == 0) xp_awk_strcmp (p->name, name) == 0)
{ {
xp_awk_io_t handler; xp_awk_io_t handler;
@ -784,7 +780,7 @@ int xp_awk_closeextio (xp_awk_run_t* run, const xp_char_t* name)
{ {
/* it handles the first that matches the given name /* it handles the first that matches the given name
* regardless of the extio type */ * regardless of the extio type */
if (xp_strcmp (p->name, name) == 0) if (xp_awk_strcmp (p->name, name) == 0)
{ {
xp_awk_io_t handler; xp_awk_io_t handler;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: func.c,v 1.39 2006-09-01 03:44:16 bacon Exp $ * $Id: func.c,v 1.40 2006-09-01 06:22:11 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -55,7 +55,7 @@ static xp_awk_bfn_t __sys_bfn[] =
}; };
xp_awk_bfn_t* xp_awk_addbfn ( xp_awk_bfn_t* xp_awk_addbfn (
xp_awk_t* awk, const xp_char_t* name, int when_valid, xp_awk_t* awk, const xp_char_t* name, size_t name_len, int when_valid,
xp_size_t min_args, xp_size_t max_args, const xp_char_t* arg_spec, xp_size_t min_args, xp_size_t max_args, const xp_char_t* arg_spec,
int (*handler)(xp_awk_t*,void*)) int (*handler)(xp_awk_t*,void*))
{ {
@ -68,6 +68,7 @@ xp_awk_bfn_t* xp_awk_addbfn (
/* NOTE: make sure that name is a constant string */ /* NOTE: make sure that name is a constant string */
p->name = name; p->name = name;
p->name_len = name_len;
p->valid = when_valid; p->valid = when_valid;
p->min_args = min_args; p->min_args = min_args;
p->max_args = max_args; p->max_args = max_args;
@ -80,13 +81,13 @@ xp_awk_bfn_t* xp_awk_addbfn (
return p; return p;
} }
int xp_awk_delbfn (xp_awk_t* awk, const xp_char_t* name) int xp_awk_delbfn (xp_awk_t* awk, const xp_char_t* name, size_t name_len)
{ {
xp_awk_bfn_t* p, * pp = XP_NULL; xp_awk_bfn_t* p, * pp = XP_NULL;
for (p = awk->bfn.user; p != XP_NULL; p++) for (p = awk->bfn.user; p != XP_NULL; p++)
{ {
if (xp_strcmp(p->name, name) == 0) if (xp_awk_strxncmp(p->name, p->name_len, name, name_len) == 0)
{ {
if (pp == XP_NULL) if (pp == XP_NULL)
awk->bfn.user = p->next; awk->bfn.user = p->next;
@ -117,7 +118,8 @@ void xp_awk_clrbfn (xp_awk_t* awk)
awk->bfn.user = XP_NULL; awk->bfn.user = XP_NULL;
} }
xp_awk_bfn_t* xp_awk_getbfn (xp_awk_t* awk, const xp_char_t* name) xp_awk_bfn_t* xp_awk_getbfn (
xp_awk_t* awk, const xp_char_t* name, size_t name_len)
{ {
xp_awk_bfn_t* p; xp_awk_bfn_t* p;
@ -126,16 +128,18 @@ xp_awk_bfn_t* xp_awk_getbfn (xp_awk_t* awk, const xp_char_t* name)
if (p->valid != 0 && if (p->valid != 0 &&
(awk->option & p->valid) == 0) continue; (awk->option & p->valid) == 0) continue;
if (xp_strcmp (p->name, name) == 0) return p; if (xp_awk_strxncmp (
p->name, p->name_len, name, name_len) == 0) return p;
} }
/* TODO: */ /* TODO: user-added builtin functions... */
for (p = awk->bfn.user; p != XP_NULL; p = p->next) for (p = awk->bfn.user; p != XP_NULL; p = p->next)
{ {
if (p->valid != 0 && if (p->valid != 0 &&
(awk->option & p->valid) == 0) continue; (awk->option & p->valid) == 0) continue;
if (xp_strcmp (p->name, name) == 0) return p; if (xp_awk_strxncmp (
p->name, p->name_len, name, name_len) == 0) return p;
} }
return XP_NULL; return XP_NULL;
@ -375,7 +379,7 @@ static int __bfn_index (xp_awk_t* awk, void* run)
} }
} }
ptr = xp_strxnstr (str0, len0, str1, len1); ptr = xp_awk_strxnstr (str0, len0, str1, len1);
idx = (ptr == XP_NULL)? -1: (xp_long_t)(ptr - str0); idx = (ptr == XP_NULL)? -1: (xp_long_t)(ptr - str0);
if (xp_awk_getopt(awk) & XP_AWK_STRINDEXONE) idx = idx + 1; if (xp_awk_getopt(awk) & XP_AWK_STRINDEXONE) idx = idx + 1;
@ -456,11 +460,10 @@ static int __bfn_substr (xp_awk_t* awk, void* run)
if (str == XP_NULL) return -1; if (str == XP_NULL) return -1;
} }
n = xp_awk_valtonum (a1, &lindex, &rindex); n = xp_awk_valtonum (run, a1, &lindex, &rindex);
if (n == -1) if (n == -1)
{ {
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str); if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_seterrnum (run, XP_AWK_EVALTYPE);
return -1; return -1;
} }
if (n == 1) lindex = (xp_long_t)rindex; if (n == 1) lindex = (xp_long_t)rindex;
@ -468,11 +471,10 @@ static int __bfn_substr (xp_awk_t* awk, void* run)
if (a2 == XP_NULL) lcount = (xp_long_t)len; if (a2 == XP_NULL) lcount = (xp_long_t)len;
else else
{ {
n = xp_awk_valtonum (a2, &lcount, &rcount); n = xp_awk_valtonum (run, a2, &lcount, &rcount);
if (n == -1) if (n == -1)
{ {
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str); if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_seterrnum (run, XP_AWK_EVALTYPE);
return -1; return -1;
} }
if (n == 1) lcount = (xp_long_t)rcount; if (n == 1) lcount = (xp_long_t)rcount;
@ -560,7 +562,8 @@ static int __bfn_split (xp_awk_t* awk, void* run)
while (p != XP_NULL) while (p != XP_NULL)
{ {
/* TODO: use FS when a2 is missing. apply a difference scheme */ /* TODO: use FS when a2 is missing. apply a difference scheme */
p = xp_strxtok (p, left, XP_T(" \t"), &tok, &tok_len); p = xp_awk_strxtok (
awk, p, left, XP_T(" \t"), &tok, &tok_len);
if (num == 0 && p == XP_NULL && tok_len == 0) if (num == 0 && p == XP_NULL && tok_len == 0)
{ {
@ -593,7 +596,7 @@ static int __bfn_split (xp_awk_t* awk, void* run)
if (xp_awk_map_putx ( if (xp_awk_map_putx (
((xp_awk_val_map_t*)t1)->map, ((xp_awk_val_map_t*)t1)->map,
key, xp_strlen(key), t2, XP_NULL) == -1) key, xp_awk_strlen(key), t2, XP_NULL) == -1)
{ {
if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str); if (a0->type != XP_AWK_VAL_STR) XP_AWK_FREE (awk, str);
xp_awk_seterrnum (run, XP_AWK_ENOMEM); xp_awk_seterrnum (run, XP_AWK_ENOMEM);
@ -645,7 +648,7 @@ static int __bfn_tolower (xp_awk_t* awk, void* run)
if (str == XP_NULL) return -1; if (str == XP_NULL) return -1;
} }
for (i = 0; i < len; i++) str[i] = xp_tolower(str[i]); for (i = 0; i < len; i++) str[i] = XP_AWK_TOLOWER (awk, str[i]);
r = xp_awk_makestrval (run, str, len); r = xp_awk_makestrval (run, str, len);
if (r == XP_NULL) if (r == XP_NULL)
@ -683,7 +686,7 @@ static int __bfn_toupper (xp_awk_t* awk, void* run)
if (str == XP_NULL) return -1; if (str == XP_NULL) return -1;
} }
for (i = 0; i < len; i++) str[i] = xp_toupper(str[i]); for (i = 0; i < len; i++) str[i] = XP_AWK_TOUPPER (awk, str[i]);
r = xp_awk_makestrval (run, str, len); r = xp_awk_makestrval (run, str, len);
if (r == XP_NULL) if (r == XP_NULL)
@ -744,12 +747,10 @@ static int __bfn_sin (xp_awk_t* awk, void* run)
nargs = xp_awk_getnargs (run); nargs = xp_awk_getnargs (run);
xp_assert (nargs == 1); xp_assert (nargs == 1);
n = xp_awk_valtonum ( n = xp_awk_valtonum (run, xp_awk_getarg(run, 0), &lv, &rv);
xp_awk_getarg(run, 0), &lv, &rv);
if (n == -1) if (n == -1)
{ {
/* wrong value */ /* wrong value */
xp_awk_seterrnum (run, XP_AWK_EVALTYPE);
return -1; return -1;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: func.h,v 1.9 2006-08-13 16:04:32 bacon Exp $ * $Id: func.h,v 1.10 2006-09-01 06:22:11 bacon Exp $
*/ */
#ifndef _XP_AWK_FUNC_H_ #ifndef _XP_AWK_FUNC_H_
@ -42,15 +42,16 @@ extern "C" {
#endif #endif
xp_awk_bfn_t* xp_awk_addbfn ( xp_awk_bfn_t* xp_awk_addbfn (
xp_awk_t* awk, const xp_char_t* name, int when_valid, xp_awk_t* awk, const xp_char_t* name, size_t name_len, int when_valid,
xp_size_t min_args, xp_size_t max_args, const xp_char_t* arg_spec, xp_size_t min_args, xp_size_t max_args, const xp_char_t* arg_spec,
int (*handler)(xp_awk_t*,void*)); int (*handler)(xp_awk_t*,void*));
int xp_awk_delbfn (xp_awk_t* awk, const xp_char_t* name); int xp_awk_delbfn (xp_awk_t* awk, const xp_char_t* name, size_t name_len);
void xp_awk_clrbfn (xp_awk_t* awk); void xp_awk_clrbfn (xp_awk_t* awk);
xp_awk_bfn_t* xp_awk_getbfn (xp_awk_t* awk, const xp_char_t* name); xp_awk_bfn_t* xp_awk_getbfn (
xp_awk_t* awk, const xp_char_t* name, size_t name_len);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,5 +1,5 @@
SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c \ SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c \
run.c sa.c val.c func.c misc.c extio.c rex.c run.c val.c func.c misc.c extio.c rex.c
OBJS = $(SRCS:.c=.obj) OBJS = $(SRCS:.c=.obj)
OUT = xpawk.lib OUT = xpawk.lib

View File

@ -1,7 +1,6 @@
SRCS = \ SRCS = \
awk.c err.c tree.c str.c tab.c map.c parse.c \ awk.c err.c tree.c str.c tab.c map.c parse.c \
run.c sa.c val.c func.c misc.c extio.c rex.c run.c val.c func.c misc.c extio.c rex.c
OBJS = $(SRCS:.c=.obj) OBJS = $(SRCS:.c=.obj)
OUT = xpawk OUT = xpawk

View File

@ -1,5 +1,5 @@
SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c \ SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c \
run.c sa.c val.c func.c misc.c extio.c rex.c run.c val.c func.c misc.c extio.c rex.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
OUT = libxpawk.a OUT = libxpawk.a

View File

@ -1,5 +1,5 @@
SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c \ SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c \
run.c sa.c val.c func.c misc.c extio.c rex.c run.c val.c func.c misc.c extio.c rex.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
OUT = libxpawk.a OUT = libxpawk.a

View File

@ -1,5 +1,5 @@
SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c run.c sa.c val.c misc.c SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c run.c val.c misc.c
OBJS = awk.obj err.obj tree.obj str.obj tab.obj map.obj parse.obj run.obj sa.obj val.obj misc.obj OBJS = awk.obj err.obj tree.obj str.obj tab.obj map.obj parse.obj run.obj val.obj misc.obj
OUT = xpawk.lib OUT = xpawk.lib
CC = lcc CC = lcc

View File

@ -1,4 +1,4 @@
SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c run.c sa.c val.c func.c misc.c extio.c SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c run.c val.c func.c misc.c extio.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
OUT = libxpawk.a OUT = libxpawk.a

View File

@ -1,4 +1,4 @@
SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c run.c sa.c val.c misc.c SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c run.c val.c misc.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
OUT = libxpawk.a OUT = libxpawk.a

View File

@ -1,4 +1,4 @@
SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c run.c sa.c val.c misc.c extio.c rex.c SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c run.c val.c misc.c extio.c rex.c
OBJS = $(SRCS:.c=.obj) OBJS = $(SRCS:.c=.obj)
OUT = xpawk.lib OUT = xpawk.lib

View File

@ -1,5 +1,5 @@
/* /*
* $Id: map.c,v 1.22 2006-09-01 03:44:16 bacon Exp $ * $Id: map.c,v 1.23 2006-09-01 06:22:12 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -96,7 +96,7 @@ xp_awk_pair_t* xp_awk_map_get (
while (pair != XP_NULL) while (pair != XP_NULL)
{ {
if (xp_strxncmp ( if (xp_awk_strxncmp (
pair->key, pair->key_len, pair->key, pair->key_len,
key, key_len) == 0) return pair; key, key_len) == 0) return pair;
@ -129,7 +129,8 @@ int xp_awk_map_putx (
while (pair != XP_NULL) while (pair != XP_NULL)
{ {
if (xp_strxncmp (pair->key, pair->key_len, key, key_len) == 0) if (xp_awk_strxncmp (
pair->key, pair->key_len, key, key_len) == 0)
{ {
if (px != XP_NULL) if (px != XP_NULL)
*px = xp_awk_map_setpair (map, pair, val); *px = xp_awk_map_setpair (map, pair, val);
@ -176,7 +177,8 @@ xp_awk_pair_t* xp_awk_map_set (
while (pair != XP_NULL) while (pair != XP_NULL)
{ {
if (xp_strxncmp (pair->key, pair->key_len, key, key_len) == 0) if (xp_awk_strxncmp (
pair->key, pair->key_len, key, key_len) == 0)
{ {
return xp_awk_map_setpair (map, pair, val); return xp_awk_map_setpair (map, pair, val);
} }
@ -225,7 +227,8 @@ int xp_awk_map_remove (xp_awk_map_t* map, xp_char_t* key, xp_size_t key_len)
while (pair != XP_NULL) while (pair != XP_NULL)
{ {
if (xp_strxncmp (pair->key, pair->key_len, key, key_len) == 0) if (xp_awk_strxncmp (
pair->key, pair->key_len, key, key_len) == 0)
{ {
if (prev == XP_NULL) if (prev == XP_NULL)
map->buck[hc] = pair->next; map->buck[hc] = pair->next;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: misc.c,v 1.8 2006-09-01 03:44:16 bacon Exp $ * $Id: misc.c,v 1.9 2006-09-01 06:22:12 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -9,8 +9,17 @@
#include <xp/bas/assert.h> #include <xp/bas/assert.h>
#endif #endif
static int __vprintf (
xp_awk_t* awk, const xp_char_t* fmt, xp_va_list ap);
static int __vsprintf (
xp_awk_t* awk, xp_char_t* buf, xp_size_t size,
const xp_char_t* fmt, xp_va_list ap);
static xp_char_t* __adjust_format (xp_awk_t* awk, const xp_char_t* format);
xp_long_t xp_awk_strtolong ( xp_long_t xp_awk_strtolong (
const xp_char_t* str, int base, const xp_char_t** endptr) xp_awk_t* awk, const xp_char_t* str,
int base, const xp_char_t** endptr)
{ {
xp_long_t n = 0; xp_long_t n = 0;
const xp_char_t* p; const xp_char_t* p;
@ -18,7 +27,7 @@ xp_long_t xp_awk_strtolong (
xp_assert (base < 37); xp_assert (base < 37);
p = str; while (xp_isspace(*p)) p++; p = str; while (XP_AWK_ISSPACE(awk,*p)) p++;
while (*p != XP_T('\0')) while (*p != XP_T('\0'))
{ {
@ -101,7 +110,7 @@ xp_long_t xp_awk_strtolong (
#define MAX_EXPONENT 511 #define MAX_EXPONENT 511
xp_real_t xp_awk_strtoreal (const xp_char_t* str) xp_real_t xp_awk_strtoreal (xp_awk_t* awk, const xp_char_t* str)
{ {
/* /*
* Table giving binary powers of 10. Entry is 10^2^i. * Table giving binary powers of 10. Entry is 10^2^i.
@ -135,7 +144,7 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str)
p = str; p = str;
/* Strip off leading blanks and check for a sign */ /* Strip off leading blanks and check for a sign */
while (xp_isspace(*p)) p++; while (XP_AWK_ISSPACE(awk,*p)) p++;
while (*p != XP_T('\0')) while (*p != XP_T('\0'))
{ {
@ -153,7 +162,7 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str)
decPt = -1; decPt = -1;
for (mantSize = 0; ; mantSize++) { for (mantSize = 0; ; mantSize++) {
c = *p; c = *p;
if (!xp_isdigit(c)) { if (!XP_AWK_ISDIGIT (awk, c)) {
if ((c != XP_T('.')) || (decPt >= 0)) break; if ((c != XP_T('.')) || (decPt >= 0)) break;
decPt = mantSize; decPt = mantSize;
} }
@ -237,12 +246,12 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str)
if (*p == XP_T('+')) p++; if (*p == XP_T('+')) p++;
expSign = 0; expSign = 0;
} }
if (!xp_isdigit(*p)) if (!XP_AWK_ISDIGIT (awk, *p))
{ {
/* p = pExp; */ /* p = pExp; */
goto done; goto done;
} }
while (xp_isdigit(*p)) while (XP_AWK_ISDIGIT (awk, *p))
{ {
exp = exp * 10 + (*p - XP_T('0')); exp = exp * 10 + (*p - XP_T('0'));
p++; p++;
@ -286,10 +295,10 @@ xp_char_t* xp_awk_strdup (xp_awk_t* awk, const xp_char_t* str)
xp_char_t* tmp; xp_char_t* tmp;
tmp = (xp_char_t*) XP_AWK_MALLOC ( tmp = (xp_char_t*) XP_AWK_MALLOC (
awk, (xp_strlen(str) + 1) * xp_sizeof(xp_char_t)); awk, (xp_awk_strlen(str) + 1) * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) return XP_NULL; if (tmp == XP_NULL) return XP_NULL;
xp_strcpy (tmp, str); xp_awk_strcpy (tmp, str);
return tmp; return tmp;
} }
@ -301,7 +310,7 @@ xp_char_t* xp_awk_strxdup (xp_awk_t* awk, const xp_char_t* str, xp_size_t len)
awk, (len + 1) * xp_sizeof(xp_char_t)); awk, (len + 1) * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) return XP_NULL; if (tmp == XP_NULL) return XP_NULL;
xp_strncpy (tmp, str, len); xp_awk_strncpy (tmp, str, len);
return tmp; return tmp;
} }
@ -316,8 +325,394 @@ xp_char_t* xp_awk_strxdup2 (
awk, (len1 + len2 + 1) * xp_sizeof(xp_char_t)); awk, (len1 + len2 + 1) * xp_sizeof(xp_char_t));
if (tmp == XP_NULL) return XP_NULL; if (tmp == XP_NULL) return XP_NULL;
xp_strncpy (tmp, str1, len1); xp_awk_strncpy (tmp, str1, len1);
xp_strncpy (tmp + len1, str2, len2); xp_awk_strncpy (tmp + len1, str2, len2);
return tmp;
}
xp_size_t xp_awk_strlen (const xp_char_t* str)
{
const xp_char_t* p = str;
while (*p != XP_T('\0')) p++;
return p - str;
}
xp_size_t xp_awk_strcpy (xp_char_t* buf, const xp_char_t* str)
{
xp_char_t* org = buf;
while ((*buf++ = *str++) != XP_T('\0'));
return buf - org - 1;
}
xp_size_t xp_awk_strncpy (xp_char_t* buf, const xp_char_t* str, xp_size_t len)
{
const xp_char_t* end = str + len;
while (str < end) *buf++ = *str++;
*buf = XP_T('\0');
return len;
}
int xp_awk_strcmp (const xp_char_t* s1, const xp_char_t* s2)
{
while (*s1 == *s2)
{
if (*s1 == XP_C('\0')) return 0;
s1++, s2++;
}
return (*s1 > *s2)? 1: -1;
}
int xp_awk_strxncmp (
const xp_char_t* s1, xp_size_t len1,
const xp_char_t* s2, xp_size_t len2)
{
const xp_char_t* end1 = s1 + len1;
const xp_char_t* end2 = s2 + len2;
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;
}
xp_char_t* xp_awk_strxnstr (
const xp_char_t* str, xp_size_t strsz,
const xp_char_t* sub, xp_size_t subsz)
{
const xp_char_t* end, * subp;
if (subsz == 0) return (xp_char_t*)str;
if (strsz < subsz) return XP_NULL;
end = str + strsz - subsz;
subp = sub + subsz;
while (str <= end) {
const xp_char_t* x = str;
const xp_char_t* y = sub;
while (xp_true) {
if (y >= subp) return (xp_char_t*)str;
if (*x != *y) break;
x++; y++;
}
str++;
}
return XP_NULL;
}
xp_char_t* xp_awk_strtok (
xp_awk_t* awk, const xp_char_t* s,
const xp_char_t* delim, xp_char_t** tok, xp_size_t* tok_len)
{
return xp_awk_strxntok (
awk, s, xp_awk_strlen(s),
delim, xp_awk_strlen(delim), tok, tok_len);
}
xp_char_t* xp_awk_strxtok (
xp_awk_t* awk, const xp_char_t* s, xp_size_t len,
const xp_char_t* delim, xp_char_t** tok, xp_size_t* tok_len)
{
return xp_awk_strxntok (
awk, s, len, delim, xp_awk_strlen(delim), tok, tok_len);
}
xp_char_t* xp_awk_strxntok (
xp_awk_t* awk, const xp_char_t* s, xp_size_t len,
const xp_char_t* delim, xp_size_t delim_len,
xp_char_t** tok, xp_size_t* tok_len)
{
const xp_char_t* p = s, *d;
const xp_char_t* end = s + len;
const xp_char_t* sp = XP_NULL, * ep = XP_NULL;
const xp_char_t* delim_end = delim + delim_len;
xp_char_t c;
int delim_mode;
/* skip preceding space xp_char_tacters */
while (p < end && XP_AWK_ISSPACE(awk,*p)) p++;
if (delim == XP_NULL) delim_mode = 0;
else
{
delim_mode = 1;
for (d = delim; d < delim_end; d++)
if (!XP_AWK_ISSPACE(awk,*d)) delim_mode = 2;
}
if (delim_mode == 0)
{
/* when XP_NULL is given as "delim", it has an effect of cutting
preceding and trailing space xp_char_tacters off "s". */
while (p < end)
{
c = *p;
if (!XP_AWK_ISSPACE(awk,c))
{
if (sp == XP_NULL) sp = p;
ep = p;
}
p++;
}
}
else if (delim_mode == 1)
{
while (p < end)
{
c = *p;
if (XP_AWK_ISSPACE(awk,c)) break;
if (sp == XP_NULL) sp = p;
ep = p++;
}
}
else /* if (delim_mode == 2) */
{
while (p < end)
{
c = *p;
if (XP_AWK_ISSPACE(awk,c))
{
p++;
continue;
}
for (d = delim; d < delim_end; d++)
{
if (c == *d) goto exit_loop;
}
if (sp == XP_NULL) sp = p;
ep = p++;
}
}
exit_loop:
if (sp == XP_NULL)
{
*tok = XP_NULL;
*tok_len = (xp_size_t)0;
}
else
{
*tok = (xp_char_t*)sp;
*tok_len = ep - sp + 1;
}
return (p >= end)? XP_NULL: ((xp_char_t*)++p);
}
int xp_awk_printf (xp_awk_t* awk, const xp_char_t* fmt, ...)
{
int n;
xp_va_list ap;
xp_va_start (ap, fmt);
n = __vprintf (awk, fmt, ap);
xp_va_end (ap);
return n;
}
static int __vprintf (xp_awk_t* awk, const xp_char_t* fmt, xp_va_list ap)
{
int n;
xp_char_t* nf = __adjust_format (awk, fmt);
if (nf == XP_NULL) return -1;
#ifdef XP_CHAR_IS_MCHAR
n = vprintf (nf, ap);
#else
n = vwprintf (nf, ap);
#endif
XP_AWK_FREE (awk, nf);
return n;
}
int xp_awk_sprintf (
xp_awk_t* awk, xp_char_t* buf, xp_size_t size,
const xp_char_t* fmt, ...)
{
int n;
xp_va_list ap;
xp_va_start (ap, fmt);
n = __vsprintf (awk, buf, size, fmt, ap);
xp_va_end (ap);
return n;
}
static int __vsprintf (
xp_awk_t* awk, xp_char_t* buf, xp_size_t size,
const xp_char_t* fmt, xp_va_list ap)
{
int n;
xp_char_t* nf = __adjust_format (awk, fmt);
if (nf == XP_NULL) return -1;
#if defined(dos) || defined(__dos)
n = vsprintf (buf, nf, ap); /* TODO: write your own vsnprintf */
#elif defined(XP_CHAR_IS_MCHAR)
n = vsnprintf (buf, size, nf, ap);
#elif defined(_WIN32)
n = _vsnwprintf (buf, size, nf, ap);
#else
n = vswprintf (buf, size, nf, ap);
#endif
XP_AWK_FREE (awk, nf);
return n;
}
#define MOD_SHORT 1
#define MOD_LONG 2
#define MOD_LONGLONG 3
#define ADDC(str,c) \
do { \
if (xp_awk_str_ccat(&str, c) == (xp_size_t)-1) { \
xp_awk_str_close (&str); \
return XP_NULL; \
} \
} while (0)
static xp_char_t* __adjust_format (xp_awk_t* awk, const xp_char_t* format)
{
const xp_char_t* fp = format;
xp_char_t* tmp;
xp_awk_str_t str;
xp_char_t ch;
int modifier;
if (xp_awk_str_open (&str, 256, awk) == XP_NULL) return XP_NULL;
while (*fp != XP_T('\0'))
{
while (*fp != XP_T('\0') && *fp != XP_T('%'))
{
ADDC (str, *fp++);
}
if (*fp == XP_T('\0')) break;
xp_assert (*fp == XP_T('%'));
ch = *fp++;
ADDC (str, ch); /* add % */
ch = *fp++;
/* flags */
for (;;)
{
if (ch == XP_T(' ') || ch == XP_T('+') ||
ch == XP_T('-') || ch == XP_T('#'))
{
ADDC (str, ch);
}
else if (ch == XP_T('0'))
{
ADDC (str, ch);
ch = *fp++;
break;
}
else break;
ch = *fp++;
}
/* check the width */
if (ch == XP_T('*')) ADDC (str, ch);
else
{
while (XP_AWK_ISDIGIT (awk, ch))
{
ADDC (str, ch);
ch = *fp++;
}
}
/* precision */
if (ch == XP_T('.'))
{
ADDC (str, ch);
ch = *fp++;
if (ch == XP_T('*')) ADDC (str, ch);
else
{
while (XP_AWK_ISDIGIT (awk, ch))
{
ADDC (str, ch);
ch = *fp++;
}
}
}
/* modifier */
for (modifier = 0;;)
{
if (ch == XP_T('h')) modifier = MOD_SHORT;
else if (ch == XP_T('l'))
{
modifier = (modifier == MOD_LONG)? MOD_LONGLONG: MOD_LONG;
}
else break;
ch = *fp++;
}
/* type */
if (ch == XP_T('%')) ADDC (str, ch);
else if (ch == XP_T('c') || ch == XP_T('s'))
{
#if !defined(XP_CHAR_IS_MCHAR) && !defined(_WIN32)
ADDC (str, 'l');
#endif
ADDC (str, ch);
}
else if (ch == XP_T('C') || ch == XP_T('S'))
{
#ifdef _WIN32
ADDC (str, ch);
#else
#ifdef XP_CHAR_IS_MCHAR
ADDC (str, 'l');
#endif
ADDC (str, xp_tolower(ch));
#endif
}
else if (ch == XP_T('d') || ch == XP_T('i') ||
ch == XP_T('o') || ch == XP_T('u') ||
ch == XP_T('x') || ch == XP_T('X'))
{
if (modifier == MOD_SHORT)
{
ADDC (str, 'h');
}
else if (modifier == MOD_LONG)
{
ADDC (str, 'l');
}
else if (modifier == MOD_LONGLONG)
{
#if defined(_WIN32) && !defined(__LCC__)
ADDC (str, 'I');
ADDC (str, '6');
ADDC (str, '4');
#else
ADDC (str, 'l');
ADDC (str, 'l');
#endif
}
ADDC (str, ch);
}
else if (ch == XP_T('\0')) break;
else ADDC (str, ch);
}
tmp = XP_AWK_STR_BUF(&str);
xp_awk_str_forfeit (&str);
return tmp; return tmp;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c,v 1.175 2006-09-01 03:44:16 bacon Exp $ * $Id: parse.c,v 1.176 2006-09-01 06:22:12 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -655,7 +655,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
if (awk->option & XP_AWK_UNIQUE) if (awk->option & XP_AWK_UNIQUE)
{ {
/* check if a parameter conflicts with a function */ /* check if a parameter conflicts with a function */
if (xp_strxncmp (name_dup, name_len, param, param_len) == 0 || if (xp_awk_strxncmp (name_dup, name_len, param, param_len) == 0 ||
xp_awk_map_get (&awk->tree.afns, param, param_len) != XP_NULL) xp_awk_map_get (&awk->tree.afns, param, param_len) != XP_NULL)
{ {
XP_AWK_FREE (awk, name_dup); XP_AWK_FREE (awk, name_dup);
@ -1944,11 +1944,11 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
nde->type = XP_AWK_NDE_INT; nde->type = XP_AWK_NDE_INT;
nde->next = XP_NULL; nde->next = XP_NULL;
nde->val = xp_awk_strtolong ( nde->val = xp_awk_strtolong (
XP_AWK_STR_BUF(&awk->token.name), 0, XP_NULL); awk, XP_AWK_STR_BUF(&awk->token.name), 0, XP_NULL);
xp_assert ( xp_assert (
XP_AWK_STR_LEN(&awk->token.name) == XP_AWK_STR_LEN(&awk->token.name) ==
xp_strlen(XP_AWK_STR_BUF(&awk->token.name))); xp_awk_strlen(XP_AWK_STR_BUF(&awk->token.name)));
if (__get_token(awk) == -1) if (__get_token(awk) == -1)
{ {
@ -1968,11 +1968,12 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
nde->type = XP_AWK_NDE_REAL; nde->type = XP_AWK_NDE_REAL;
nde->next = XP_NULL; nde->next = XP_NULL;
nde->val = xp_awk_strtoreal (XP_AWK_STR_BUF(&awk->token.name)); nde->val = xp_awk_strtoreal (
awk, XP_AWK_STR_BUF(&awk->token.name));
xp_assert ( xp_assert (
XP_AWK_STR_LEN(&awk->token.name) == XP_AWK_STR_LEN(&awk->token.name) ==
xp_strlen(XP_AWK_STR_BUF(&awk->token.name))); xp_awk_strlen(XP_AWK_STR_BUF(&awk->token.name)));
if (__get_token(awk) == -1) if (__get_token(awk) == -1)
{ {
@ -2250,7 +2251,7 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
} }
/* check if name_dup is a built-in function name */ /* check if name_dup is a built-in function name */
bfn = xp_awk_getbfn (awk, name_dup); bfn = xp_awk_getbfn (awk, name_dup, name_len);
if (bfn != XP_NULL) if (bfn != XP_NULL)
{ {
xp_awk_nde_t* nde; xp_awk_nde_t* nde;
@ -3251,11 +3252,11 @@ static int __get_token (xp_awk_t* awk)
{ {
SET_TOKEN_TYPE (awk, TOKEN_EOF); SET_TOKEN_TYPE (awk, TOKEN_EOF);
} }
else if (xp_isdigit(c)) else if (XP_AWK_ISDIGIT (awk, c))
{ {
if (__get_number(awk) == -1) return -1; if (__get_number (awk) == -1) return -1;
} }
else if (xp_isalpha(c) || c == XP_T('_')) else if (XP_AWK_ISALPHA (awk, c) || c == XP_T('_'))
{ {
int type; int type;
@ -3265,7 +3266,8 @@ static int __get_token (xp_awk_t* awk)
ADD_TOKEN_CHAR (awk, c); ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
} }
while (xp_isalpha(c) || c == XP_T('_') || xp_isdigit(c)); while (XP_AWK_ISALPHA (awk, c) ||
c == XP_T('_') || XP_AWK_ISDIGIT(awk,c));
type = __classify_ident (awk, type = __classify_ident (awk,
XP_AWK_STR_BUF(&awk->token.name), XP_AWK_STR_BUF(&awk->token.name),
@ -3630,7 +3632,7 @@ static int __get_number (xp_awk_t* awk)
ADD_TOKEN_CHAR (awk, c); ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
} }
while (xp_isxdigit(c)); while (XP_AWK_ISXDIGIT (awk, c));
return 0; return 0;
} }
@ -3659,7 +3661,7 @@ static int __get_number (xp_awk_t* awk)
} }
} }
while (xp_isdigit(c)) while (XP_AWK_ISDIGIT (awk, c))
{ {
ADD_TOKEN_CHAR (awk, c); ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
@ -3673,7 +3675,7 @@ static int __get_number (xp_awk_t* awk)
ADD_TOKEN_CHAR (awk, c); ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
while (xp_isdigit(c)) while (XP_AWK_ISDIGIT (awk, c))
{ {
ADD_TOKEN_CHAR (awk, c); ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
@ -3693,7 +3695,7 @@ static int __get_number (xp_awk_t* awk)
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
} }
while (xp_isdigit(c)) while (XP_AWK_ISDIGIT (awk, c))
{ {
ADD_TOKEN_CHAR (awk, c); ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
@ -3943,7 +3945,7 @@ static int __skip_spaces (xp_awk_t* awk)
{ {
xp_cint_t c = awk->src.lex.curc; xp_cint_t c = awk->src.lex.curc;
while (xp_isspace(c)) GET_CHAR_TO (awk, c); while (XP_AWK_ISSPACE (awk, c)) GET_CHAR_TO (awk, c);
return 0; return 0;
} }
@ -4025,7 +4027,7 @@ static int __classify_ident (
if (kwp->valid != 0 && if (kwp->valid != 0 &&
(awk->option & kwp->valid) == 0) continue; (awk->option & kwp->valid) == 0) continue;
if (xp_strxncmp (kwp->name, kwp->name_len, name, len) == 0) if (xp_awk_strxncmp (kwp->name, kwp->name_len, name, len) == 0)
{ {
return kwp->type; return kwp->type;
} }
@ -4206,7 +4208,7 @@ static int __deparse_func (xp_awk_pair_t* pair, void* arg)
xp_awk_afn_t* afn = (xp_awk_afn_t*)pair->val; xp_awk_afn_t* afn = (xp_awk_afn_t*)pair->val;
xp_size_t i; xp_size_t i;
xp_assert (xp_strxncmp ( xp_assert (xp_awk_strxncmp (
pair->key, pair->key_len, afn->name, afn->name_len) == 0); pair->key, pair->key_len, afn->name, afn->name_len) == 0);
if (xp_awk_putsrcstr (df->awk, XP_T("function ")) == -1) return -1; if (xp_awk_putsrcstr (df->awk, XP_T("function ")) == -1) return -1;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.192 2006-09-01 04:03:28 bacon Exp $ * $Id: run.c,v 1.193 2006-09-01 06:22:12 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -1357,7 +1357,7 @@ static int __walk_foreach (xp_awk_pair_t* pair, void* arg)
xp_awk_val_t* str; xp_awk_val_t* str;
str = (xp_awk_val_t*) xp_awk_makestrval ( str = (xp_awk_val_t*) xp_awk_makestrval (
w->run, pair->key, xp_strlen(pair->key)); w->run, pair->key, xp_awk_strlen(pair->key));
if (str == XP_NULL) PANIC_I (w->run, XP_AWK_ENOMEM); if (str == XP_NULL) PANIC_I (w->run, XP_AWK_ENOMEM);
xp_awk_refupval (str); xp_awk_refupval (str);
@ -2225,7 +2225,7 @@ static xp_awk_val_t* __do_assignment_pos (
if (v == XP_NULL) return XP_NULL; if (v == XP_NULL) return XP_NULL;
xp_awk_refupval (v); xp_awk_refupval (v);
n = xp_awk_valtonum (v, &lv, &rv); n = xp_awk_valtonum (run, v, &lv, &rv);
xp_awk_refdownval (run, v); xp_awk_refdownval (run, v);
if (n == -1) PANIC (run, XP_AWK_EPOSIDX); if (n == -1) PANIC (run, XP_AWK_EPOSIDX);
@ -2681,7 +2681,7 @@ static xp_awk_val_t* __eval_binop_eq (
else if (left->type == XP_AWK_VAL_STR && else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR) right->type == XP_AWK_VAL_STR)
{ {
r = xp_strxncmp ( r = xp_awk_strxncmp (
((xp_awk_val_str_t*)left)->buf, ((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len, ((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf, ((xp_awk_val_str_t*)right)->buf,
@ -2736,7 +2736,7 @@ static xp_awk_val_t* __eval_binop_ne (
else if (left->type == XP_AWK_VAL_STR && else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR) right->type == XP_AWK_VAL_STR)
{ {
r = xp_strxncmp ( r = xp_awk_strxncmp (
((xp_awk_val_str_t*)left)->buf, ((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len, ((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf, ((xp_awk_val_str_t*)right)->buf,
@ -2785,7 +2785,7 @@ static xp_awk_val_t* __eval_binop_gt (
else if (left->type == XP_AWK_VAL_STR && else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR) right->type == XP_AWK_VAL_STR)
{ {
r = xp_strxncmp ( r = xp_awk_strxncmp (
((xp_awk_val_str_t*)left)->buf, ((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len, ((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf, ((xp_awk_val_str_t*)right)->buf,
@ -2834,7 +2834,7 @@ static xp_awk_val_t* __eval_binop_ge (
else if (left->type == XP_AWK_VAL_STR && else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR) right->type == XP_AWK_VAL_STR)
{ {
r = xp_strxncmp ( r = xp_awk_strxncmp (
((xp_awk_val_str_t*)left)->buf, ((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len, ((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf, ((xp_awk_val_str_t*)right)->buf,
@ -2883,7 +2883,7 @@ static xp_awk_val_t* __eval_binop_lt (
else if (left->type == XP_AWK_VAL_STR && else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR) right->type == XP_AWK_VAL_STR)
{ {
r = xp_strxncmp ( r = xp_awk_strxncmp (
((xp_awk_val_str_t*)left)->buf, ((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len, ((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf, ((xp_awk_val_str_t*)right)->buf,
@ -2932,7 +2932,7 @@ static xp_awk_val_t* __eval_binop_le (
else if (left->type == XP_AWK_VAL_STR && else if (left->type == XP_AWK_VAL_STR &&
right->type == XP_AWK_VAL_STR) right->type == XP_AWK_VAL_STR)
{ {
r = xp_strxncmp ( r = xp_awk_strxncmp (
((xp_awk_val_str_t*)left)->buf, ((xp_awk_val_str_t*)left)->buf,
((xp_awk_val_str_t*)left)->len, ((xp_awk_val_str_t*)left)->len,
((xp_awk_val_str_t*)right)->buf, ((xp_awk_val_str_t*)right)->buf,
@ -2956,8 +2956,8 @@ static xp_awk_val_t* __eval_binop_lshift (
xp_real_t r1, r2; xp_real_t r1, r2;
xp_awk_val_t* res; xp_awk_val_t* res;
n1 = xp_awk_valtonum (left, &l1, &r1); n1 = xp_awk_valtonum (run, left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2); n2 = xp_awk_valtonum (run, right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND); if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -2981,8 +2981,8 @@ static xp_awk_val_t* __eval_binop_rshift (
xp_real_t r1, r2; xp_real_t r1, r2;
xp_awk_val_t* res; xp_awk_val_t* res;
n1 = xp_awk_valtonum (left, &l1, &r1); n1 = xp_awk_valtonum (run, left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2); n2 = xp_awk_valtonum (run, right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND); if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -3006,8 +3006,8 @@ static xp_awk_val_t* __eval_binop_plus (
xp_real_t r1, r2; xp_real_t r1, r2;
xp_awk_val_t* res; xp_awk_val_t* res;
n1 = xp_awk_valtonum (left, &l1, &r1); n1 = xp_awk_valtonum (run, left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2); n2 = xp_awk_valtonum (run, right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND); if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
/* /*
@ -3036,8 +3036,8 @@ static xp_awk_val_t* __eval_binop_minus (
xp_real_t r1, r2; xp_real_t r1, r2;
xp_awk_val_t* res; xp_awk_val_t* res;
n1 = xp_awk_valtonum (left, &l1, &r1); n1 = xp_awk_valtonum (run, left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2); n2 = xp_awk_valtonum (run, right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND); if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -3060,8 +3060,8 @@ static xp_awk_val_t* __eval_binop_mul (
xp_real_t r1, r2; xp_real_t r1, r2;
xp_awk_val_t* res; xp_awk_val_t* res;
n1 = xp_awk_valtonum (left, &l1, &r1); n1 = xp_awk_valtonum (run, left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2); n2 = xp_awk_valtonum (run, right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND); if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -3084,8 +3084,8 @@ static xp_awk_val_t* __eval_binop_div (
xp_real_t r1, r2; xp_real_t r1, r2;
xp_awk_val_t* res; xp_awk_val_t* res;
n1 = xp_awk_valtonum (left, &l1, &r1); n1 = xp_awk_valtonum (run, left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2); n2 = xp_awk_valtonum (run, right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND); if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -3121,8 +3121,8 @@ static xp_awk_val_t* __eval_binop_mod (
xp_real_t r1, r2; xp_real_t r1, r2;
xp_awk_val_t* res; xp_awk_val_t* res;
n1 = xp_awk_valtonum (left, &l1, &r1); n1 = xp_awk_valtonum (run, left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2); n2 = xp_awk_valtonum (run, right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND); if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -3146,8 +3146,8 @@ static xp_awk_val_t* __eval_binop_exp (
xp_real_t r1, r2; xp_real_t r1, r2;
xp_awk_val_t* res; xp_awk_val_t* res;
n1 = xp_awk_valtonum (left, &l1, &r1); n1 = xp_awk_valtonum (run, left, &l1, &r1);
n2 = xp_awk_valtonum (right, &l2, &r2); n2 = xp_awk_valtonum (run, right, &l2, &r2);
if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND); if (n1 == -1 || n2 == -1) PANIC (run, XP_AWK_EOPERAND);
@ -3515,7 +3515,7 @@ static xp_awk_val_t* __eval_incpre (xp_awk_run_t* run, xp_awk_nde_t* nde)
xp_real_t v2; xp_real_t v2;
int n; int n;
n = xp_awk_valtonum (left, &v1, &v2); n = xp_awk_valtonum (run, left, &v1, &v2);
if (n == -1) if (n == -1)
{ {
xp_awk_refdownval (run, left); xp_awk_refdownval (run, left);
@ -3567,7 +3567,7 @@ static xp_awk_val_t* __eval_incpre (xp_awk_run_t* run, xp_awk_nde_t* nde)
xp_real_t v2; xp_real_t v2;
int n; int n;
n = xp_awk_valtonum (left, &v1, &v2); n = xp_awk_valtonum (run, left, &v1, &v2);
if (n == -1) if (n == -1)
{ {
xp_awk_refdownval (run, left); xp_awk_refdownval (run, left);
@ -3675,7 +3675,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_run_t* run, xp_awk_nde_t* nde)
xp_real_t v2; xp_real_t v2;
int n; int n;
n = xp_awk_valtonum (left, &v1, &v2); n = xp_awk_valtonum (run, left, &v1, &v2);
if (n == -1) if (n == -1)
{ {
xp_awk_refdownval (run, left); xp_awk_refdownval (run, left);
@ -3763,7 +3763,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_run_t* run, xp_awk_nde_t* nde)
xp_real_t v2; xp_real_t v2;
int n; int n;
n = xp_awk_valtonum (left, &v1, &v2); n = xp_awk_valtonum (run, left, &v1, &v2);
if (n == -1) if (n == -1)
{ {
xp_awk_refdownval (run, left); xp_awk_refdownval (run, left);
@ -4414,7 +4414,7 @@ static xp_awk_val_t* __eval_pos (xp_awk_run_t* run, xp_awk_nde_t* nde)
if (v == XP_NULL) return XP_NULL; if (v == XP_NULL) return XP_NULL;
xp_awk_refupval (v); xp_awk_refupval (v);
n = xp_awk_valtonum (v, &lv, &rv); n = xp_awk_valtonum (run, v, &lv, &rv);
xp_awk_refdownval (run, v); xp_awk_refdownval (run, v);
if (n == -1) PANIC (run, XP_AWK_EPOSIDX); if (n == -1) PANIC (run, XP_AWK_EPOSIDX);
@ -4710,7 +4710,8 @@ static int __split_record (xp_awk_run_t* run)
if (fs->type == XP_AWK_VAL_NIL) if (fs->type == XP_AWK_VAL_NIL)
{ {
#endif #endif
p = xp_strxtok (p, len, XP_T(" \t"), &tok, &tok_len); p = xp_awk_strxtok (
run->awk, p, len, XP_T(" \t"), &tok, &tok_len);
#if 0 #if 0
} }
else if (fs_len == 0) else if (fs_len == 0)
@ -4718,7 +4719,8 @@ static int __split_record (xp_awk_run_t* run)
} }
else if (fs_len == 1) else if (fs_len == 1)
{ {
p = xp_strxntok (p, len, p = xp_awk_strxntok (
run->awk, p, len,
fs_ptr, fs_len, &tok, &tok_len); fs_ptr, fs_len, &tok, &tok_len);
} }
else else
@ -4774,7 +4776,8 @@ static int __split_record (xp_awk_run_t* run)
while (p != XP_NULL) while (p != XP_NULL)
{ {
p = xp_strxtok (p, len, XP_T(" \t"), &tok, &tok_len); p = xp_awk_strxtok (
run->awk, p, len, XP_T(" \t"), &tok, &tok_len);
xp_assert ((tok != XP_NULL && tok_len > 0) || tok_len == 0); xp_assert ((tok != XP_NULL && tok_len > 0) || tok_len == 0);

View File

@ -1,393 +0,0 @@
/*
* $Id: sa.c,v 1.33 2006-09-01 03:44:16 bacon Exp $
*/
#include <xp/awk/awk_i.h>
#ifdef XP_AWK_STAND_ALONE
static xp_char_t* __adjust_format (xp_awk_t* awk, const xp_char_t* format);
xp_size_t xp_strlen (const xp_char_t* str)
{
const xp_char_t* p = str;
while (*p != XP_T('\0')) p++;
return p - str;
}
xp_size_t xp_strcpy (xp_char_t* buf, const xp_char_t* str)
{
xp_char_t* org = buf;
while ((*buf++ = *str++) != XP_T('\0'));
return buf - org - 1;
}
xp_size_t xp_strncpy (xp_char_t* buf, const xp_char_t* str, xp_size_t len)
{
const xp_char_t* end = str + len;
while (str < end) *buf++ = *str++;
*buf = XP_T('\0');
return len;
}
int xp_strcmp (const xp_char_t* s1, const xp_char_t* s2)
{
while (*s1 == *s2)
{
if (*s1 == XP_C('\0')) return 0;
s1++, s2++;
}
return (*s1 > *s2)? 1: -1;
}
int xp_strxncmp (
const xp_char_t* s1, xp_size_t len1,
const xp_char_t* s2, xp_size_t len2)
{
const xp_char_t* end1 = s1 + len1;
const xp_char_t* end2 = s2 + len2;
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;
}
xp_char_t* xp_strxnstr (
const xp_char_t* str, xp_size_t strsz,
const xp_char_t* sub, xp_size_t subsz)
{
const xp_char_t* end, * subp;
if (subsz == 0) return (xp_char_t*)str;
if (strsz < subsz) return XP_NULL;
end = str + strsz - subsz;
subp = sub + subsz;
while (str <= end) {
const xp_char_t* x = str;
const xp_char_t* y = sub;
while (xp_true) {
if (y >= subp) return (xp_char_t*)str;
if (*x != *y) break;
x++; y++;
}
str++;
}
return XP_NULL;
}
xp_char_t* xp_strtok (const xp_char_t* s,
const xp_char_t* delim, xp_char_t** tok, xp_size_t* tok_len)
{
return xp_strxntok (
s, xp_strlen(s), delim, xp_strlen(delim), tok, tok_len);
}
xp_char_t* xp_strxtok (const xp_char_t* s, xp_size_t len,
const xp_char_t* delim, xp_char_t** tok, xp_size_t* tok_len)
{
return xp_strxntok (s, len, delim, xp_strlen(delim), tok, tok_len);
}
xp_char_t* xp_strxntok (
const xp_char_t* s, xp_size_t len,
const xp_char_t* delim, xp_size_t delim_len,
xp_char_t** tok, xp_size_t* tok_len)
{
const xp_char_t* p = s, *d;
const xp_char_t* end = s + len;
const xp_char_t* sp = XP_NULL, * ep = XP_NULL;
const xp_char_t* delim_end = delim + delim_len;
xp_char_t c;
int delim_mode;
/* skip preceding space xp_char_tacters */
while (p < end && xp_isspace(*p)) p++;
if (delim == XP_NULL) delim_mode = 0;
else
{
delim_mode = 1;
for (d = delim; d < delim_end; d++)
if (!xp_isspace(*d)) delim_mode = 2;
}
if (delim_mode == 0)
{
/* when XP_NULL is given as "delim", it has an effect of cutting
preceding and trailing space xp_char_tacters off "s". */
while (p < end)
{
c = *p;
if (!xp_isspace(c))
{
if (sp == XP_NULL) sp = p;
ep = p;
}
p++;
}
}
else if (delim_mode == 1)
{
while (p < end)
{
c = *p;
if (xp_isspace(c)) break;
if (sp == XP_NULL) sp = p;
ep = p++;
}
}
else /* if (delim_mode == 2) */
{
while (p < end)
{
c = *p;
if (xp_isspace(c))
{
p++;
continue;
}
for (d = delim; d < delim_end; d++)
{
if (c == *d) goto exit_loop;
}
if (sp == XP_NULL) sp = p;
ep = p++;
}
}
exit_loop:
if (sp == XP_NULL)
{
*tok = XP_NULL;
*tok_len = (xp_size_t)0;
}
else
{
*tok = (xp_char_t*)sp;
*tok_len = ep - sp + 1;
}
return (p >= end)? XP_NULL: ((xp_char_t*)++p);
}
int xp_awk_printf (xp_awk_t* awk, const xp_char_t* fmt, ...)
{
int n;
xp_va_list ap;
xp_va_start (ap, fmt);
n = xp_awk_vprintf (awk, fmt, ap);
xp_va_end (ap);
return n;
}
int xp_awk_vprintf (xp_awk_t* awk, const xp_char_t* fmt, xp_va_list ap)
{
int n;
xp_char_t* nf = __adjust_format (awk, fmt);
if (nf == XP_NULL) return -1;
#ifdef XP_CHAR_IS_MCHAR
n = vprintf (nf, ap);
#else
n = vwprintf (nf, ap);
#endif
XP_AWK_FREE (awk, nf);
return n;
}
int xp_awk_sprintf (
xp_awk_t* awk, xp_char_t* buf, xp_size_t size,
const xp_char_t* fmt, ...)
{
int n;
xp_va_list ap;
xp_va_start (ap, fmt);
n = xp_awk_vsprintf (awk, buf, size, fmt, ap);
xp_va_end (ap);
return n;
}
int xp_awk_vsprintf (
xp_awk_t* awk, xp_char_t* buf, xp_size_t size,
const xp_char_t* fmt, xp_va_list ap)
{
int n;
xp_char_t* nf = __adjust_format (awk, fmt);
if (nf == XP_NULL) return -1;
#if defined(dos) || defined(__dos)
n = vsprintf (buf, nf, ap); /* TODO: write your own vsnprintf */
#elif defined(XP_CHAR_IS_MCHAR)
n = vsnprintf (buf, size, nf, ap);
#elif defined(_WIN32)
n = _vsnwprintf (buf, size, nf, ap);
#else
n = vswprintf (buf, size, nf, ap);
#endif
XP_AWK_FREE (awk, nf);
return n;
}
#define MOD_SHORT 1
#define MOD_LONG 2
#define MOD_LONGLONG 3
#define ADDC(str,c) \
do { \
if (xp_awk_str_ccat(&str, c) == (xp_size_t)-1) { \
xp_awk_str_close (&str); \
return XP_NULL; \
} \
} while (0)
static xp_char_t* __adjust_format (xp_awk_t* awk, const xp_char_t* format)
{
const xp_char_t* fp = format;
xp_char_t* tmp;
xp_awk_str_t str;
xp_char_t ch;
int modifier;
if (xp_awk_str_open (&str, 256, awk) == XP_NULL) return XP_NULL;
while (*fp != XP_T('\0'))
{
while (*fp != XP_T('\0') && *fp != XP_T('%'))
{
ADDC (str, *fp++);
}
if (*fp == XP_T('\0')) break;
xp_assert (*fp == XP_T('%'));
ch = *fp++;
ADDC (str, ch); /* add % */
ch = *fp++;
/* flags */
for (;;)
{
if (ch == XP_T(' ') || ch == XP_T('+') ||
ch == XP_T('-') || ch == XP_T('#'))
{
ADDC (str, ch);
}
else if (ch == XP_T('0'))
{
ADDC (str, ch);
ch = *fp++;
break;
}
else break;
ch = *fp++;
}
/* check the width */
if (ch == XP_T('*')) ADDC (str, ch);
else
{
while (xp_isdigit(ch))
{
ADDC (str, ch);
ch = *fp++;
}
}
/* precision */
if (ch == XP_T('.'))
{
ADDC (str, ch);
ch = *fp++;
if (ch == XP_T('*')) ADDC (str, ch);
else
{
while (xp_isdigit(ch))
{
ADDC (str, ch);
ch = *fp++;
}
}
}
/* modifier */
for (modifier = 0;;)
{
if (ch == XP_T('h')) modifier = MOD_SHORT;
else if (ch == XP_T('l'))
{
modifier = (modifier == MOD_LONG)? MOD_LONGLONG: MOD_LONG;
}
else break;
ch = *fp++;
}
/* type */
if (ch == XP_T('%')) ADDC (str, ch);
else if (ch == XP_T('c') || ch == XP_T('s'))
{
#if !defined(XP_CHAR_IS_MCHAR) && !defined(_WIN32)
ADDC (str, 'l');
#endif
ADDC (str, ch);
}
else if (ch == XP_T('C') || ch == XP_T('S'))
{
#ifdef _WIN32
ADDC (str, ch);
#else
#ifdef XP_CHAR_IS_MCHAR
ADDC (str, 'l');
#endif
ADDC (str, xp_tolower(ch));
#endif
}
else if (ch == XP_T('d') || ch == XP_T('i') ||
ch == XP_T('o') || ch == XP_T('u') ||
ch == XP_T('x') || ch == XP_T('X'))
{
if (modifier == MOD_SHORT)
{
ADDC (str, 'h');
}
else if (modifier == MOD_LONG)
{
ADDC (str, 'l');
}
else if (modifier == MOD_LONGLONG)
{
#if defined(_WIN32) && !defined(__LCC__)
ADDC (str, 'I');
ADDC (str, '6');
ADDC (str, '4');
#else
ADDC (str, 'l');
ADDC (str, 'l');
#endif
}
ADDC (str, ch);
}
else if (ch == XP_T('\0')) break;
else ADDC (str, ch);
}
tmp = XP_AWK_STR_BUF(&str);
xp_awk_str_forfeit (&str);
return tmp;
}
#endif

View File

@ -1,149 +0,0 @@
/*
* $Id: sa.h,v 1.36 2006-09-01 03:44:16 bacon Exp $
*/
#ifndef _XP_AWK_SA_H_
#define _XP_AWK_SA_H_
#ifndef _XP_AWK_AWK_H_
#error Never include this file directly. Include <xp/awk/awk.h> instead
#endif
#ifdef XP_AWK_STAND_ALONE
#if !defined(XP_CHAR_IS_MCHAR) && !defined(XP_CHAR_IS_WCHAR)
#error Neither XP_CHAR_IS_MCHAR nor XP_CHAR_IS_WCHAR is defined.
#endif
#ifdef XP_AWK_NTDDK
#include <ntddk.h>
#include <stdarg.h>
#define xp_assert ASSERT
#define xp_memset(dst,fill,len) RtlFillMemory(dst,len,fill)
#define xp_memcpy(dst,src,len) RtlCopyMemory(dst,src,len)
#define xp_memmove(dst,src,len) RtlMoveMemory(dst,src,len)
#define xp_memcmp(src1,src2,len) RtlCompareMemory(src1,src2,len)
#define xp_memzero(dst,len) RtlZeroMemory(dst,len)
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
#ifdef XP_CHAR_IS_MCHAR
#include <ctype.h>
#else
#include <ctype.h>
#include <wchar.h>
#if !defined(__BEOS__)
#include <wctype.h>
#endif
#endif
#define xp_assert assert
#define xp_memset(dst,fill,len) memset(dst,fill,len)
#define xp_memcpy(dst,src,len) memcpy(dst,src,len)
#define xp_memmove(dst,src,len) memmove(dst,src,len)
#define xp_memcmp(src1,src2,len) memcmp(src1,src2,len)
#define xp_memzero(dst,len) memset(dst,0,len)
#ifdef XP_CHAR_IS_MCHAR
#define xp_isdigit isdigit
#define xp_isxdigit isxdigit
#define xp_isalpha isalpha
#define xp_isalnum isalnum
#define xp_isspace isspace
#define xp_iscntrl iscntrl
#define xp_isgraph isgraph
#define xp_islower islower
#define xp_isupper isupper
#define xp_isprint isprint
#define xp_ispunct ispunct
#define xp_toupper toupper
#define xp_tolower tolower
#else
#define xp_isdigit iswdigit
#define xp_isxdigit iswxdigit
#define xp_isalpha iswalpha
#define xp_isalnum iswalnum
#define xp_isspace iswspace
#define xp_iscntrl iswcntrl
#define xp_isgraph iswgraph
#define xp_islower iswlower
#define xp_isupper iswupper
#define xp_isprint iswprint
#define xp_ispunct iswpunct
#define xp_toupper towupper
#define xp_tolower towlower
#endif
#endif
#define xp_va_start(pvar,param) va_start(pvar,param)
#define xp_va_list va_list
#define xp_va_end(pvar) va_end(pvar)
#define xp_va_arg(pvar,type) va_arg(pvar,type)
#ifdef __cplusplus
extern "C" {
#endif
#define xp_strlen xp_awk_strlen
xp_size_t xp_strlen (const xp_char_t* str);
#define xp_strcpy xp_awk_strcpy
xp_size_t xp_strcpy (xp_char_t* buf, const xp_char_t* str);
#define xp_strncpy xp_awk_strncpy
xp_size_t xp_strncpy (xp_char_t* buf, 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);
#define xp_strxncmp xp_awk_strxncmp
int xp_strxncmp (
const xp_char_t* s1, xp_size_t len1,
const xp_char_t* s2, xp_size_t len2);
#define xp_strxnstr xp_awk_strxnstr
xp_char_t* xp_strxnstr (
const xp_char_t* str, xp_size_t strsz,
const xp_char_t* sub, xp_size_t subsz);
#define xp_strtok xp_awk_strtok
xp_char_t* xp_strtok (const xp_char_t* s,
const xp_char_t* delim, xp_char_t** tok, xp_size_t* tok_len);
#define xp_strxtok xp_awk_strxtok
xp_char_t* xp_strxtok (const xp_char_t* s, xp_size_t len,
const xp_char_t* delim, xp_char_t** tok, xp_size_t* tok_len);
#define xp_strxntok xp_awk_strxntok
xp_char_t* xp_strxntok (
const xp_char_t* s, xp_size_t len,
const xp_char_t* delim, xp_size_t delim_len,
xp_char_t** tok, xp_size_t* tok_len);
int xp_awk_printf (xp_awk_t* awk, const xp_char_t* fmt, ...);
int xp_awk_vprintf (xp_awk_t* awk, const xp_char_t* fmt, xp_va_list ap);
int xp_awk_sprintf (
xp_awk_t* awk, xp_char_t* buf,
xp_size_t size, const xp_char_t* fmt, ...);
int xp_awk_vsprintf (
xp_awk_t* awk, xp_char_t* buf, xp_size_t size,
const xp_char_t* fmt, xp_va_list ap);
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@ -1,5 +1,5 @@
/* /*
* $Id: str.c,v 1.1 2006-08-31 16:00:19 bacon Exp $ * $Id: str.c,v 1.2 2006-09-01 06:22:13 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -51,7 +51,7 @@ void xp_awk_str_forfeit (xp_awk_str_t* str)
xp_size_t xp_awk_str_cpy (xp_awk_str_t* str, const xp_char_t* s) xp_size_t xp_awk_str_cpy (xp_awk_str_t* str, const xp_char_t* s)
{ {
/* TODO: improve it */ /* TODO: improve it */
return xp_awk_str_ncpy (str, s, xp_strlen(s)); return xp_awk_str_ncpy (str, s, xp_awk_strlen(s));
} }
xp_size_t xp_awk_str_ncpy (xp_awk_str_t* str, const xp_char_t* s, xp_size_t len) xp_size_t xp_awk_str_ncpy (xp_awk_str_t* str, const xp_char_t* s, xp_size_t len)
@ -69,7 +69,7 @@ xp_size_t xp_awk_str_ncpy (xp_awk_str_t* str, const xp_char_t* s, xp_size_t len)
str->buf = buf; str->buf = buf;
} }
str->size = xp_strncpy (str->buf, s, len); str->size = xp_awk_strncpy (str->buf, s, len);
str->buf[str->size] = XP_T('\0'); str->buf[str->size] = XP_T('\0');
return str->size; return str->size;
} }
@ -77,7 +77,7 @@ xp_size_t xp_awk_str_ncpy (xp_awk_str_t* str, const xp_char_t* s, xp_size_t len)
xp_size_t xp_awk_str_cat (xp_awk_str_t* str, const xp_char_t* s) xp_size_t xp_awk_str_cat (xp_awk_str_t* str, const xp_char_t* s)
{ {
/* TODO: improve it */ /* TODO: improve it */
return xp_awk_str_ncat (str, s, xp_strlen(s)); return xp_awk_str_ncat (str, s, xp_awk_strlen(s));
} }
xp_size_t xp_awk_str_ncat (xp_awk_str_t* str, const xp_char_t* s, xp_size_t len) xp_size_t xp_awk_str_ncat (xp_awk_str_t* str, const xp_char_t* s, xp_size_t len)
@ -116,7 +116,7 @@ xp_size_t xp_awk_str_ncat (xp_awk_str_t* str, const xp_char_t* s, xp_size_t len)
str->buf = tmp; str->buf = tmp;
} }
str->size += xp_strncpy (&str->buf[str->size], s, len); str->size += xp_awk_strncpy (&str->buf[str->size], s, len);
str->buf[str->size] = XP_T('\0'); str->buf[str->size] = XP_T('\0');
return str->size; return str->size;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tab.c,v 1.14 2006-09-01 03:44:16 bacon Exp $ * $Id: tab.c,v 1.15 2006-09-01 06:22:13 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -198,7 +198,7 @@ xp_size_t xp_awk_tab_find (
for (i = index; i < tab->size; i++) for (i = index; i < tab->size; i++)
{ {
if (xp_strxncmp ( if (xp_awk_strxncmp (
tab->buf[i].name, tab->buf[i].name_len, tab->buf[i].name, tab->buf[i].name_len,
str, len) == 0) return i; str, len) == 0) return i;
} }
@ -216,7 +216,7 @@ xp_size_t xp_awk_tab_rfind (
for (i = index + 1; i-- > 0; ) for (i = index + 1; i-- > 0; )
{ {
if (xp_strxncmp ( if (xp_awk_strxncmp (
tab->buf[i].name, tab->buf[i].name_len, tab->buf[i].name, tab->buf[i].name_len,
str, len) == 0) return i; str, len) == 0) return i;
} }
@ -234,7 +234,7 @@ xp_size_t xp_awk_tab_rrfind (
for (i = tab->size - index; i-- > 0; ) for (i = tab->size - index; i-- > 0; )
{ {
if (xp_strxncmp ( if (xp_awk_strxncmp (
tab->buf[i].name, tab->buf[i].name_len, tab->buf[i].name, tab->buf[i].name_len,
str, len) == 0) return i; str, len) == 0) return i;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.c,v 1.57 2006-09-01 03:44:21 bacon Exp $ * $Id: val.c,v 1.58 2006-09-01 06:22:13 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -89,7 +89,7 @@ xp_awk_val_t* xp_awk_makerealval (xp_awk_run_t* run, xp_real_t v)
xp_awk_val_t* xp_awk_makestrval0 (xp_awk_run_t* run, const xp_char_t* str) xp_awk_val_t* xp_awk_makestrval0 (xp_awk_run_t* run, const xp_char_t* str)
{ {
return xp_awk_makestrval (run, str, xp_strlen(str)); return xp_awk_makestrval (run, str, xp_awk_strlen(str));
} }
xp_awk_val_t* xp_awk_makestrval ( xp_awk_val_t* xp_awk_makestrval (
@ -512,7 +512,7 @@ xp_char_t* xp_awk_valtostr (
return XP_NULL; return XP_NULL;
} }
if (len != XP_NULL) *len = xp_strlen(tmp); if (len != XP_NULL) *len = xp_awk_strlen(tmp);
} }
else else
{ {
@ -575,7 +575,8 @@ xp_printf (XP_T("*** ERROR: WRONG VALUE TYPE [%d] in xp_awk_valtostr v=> %p***\n
return XP_NULL; return XP_NULL;
} }
int xp_awk_valtonum (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r) int xp_awk_valtonum (
xp_awk_run_t* run, xp_awk_val_t* v, xp_long_t* l, xp_real_t* r)
{ {
if (v->type == XP_AWK_VAL_NIL) if (v->type == XP_AWK_VAL_NIL)
{ {
@ -600,13 +601,15 @@ int xp_awk_valtonum (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r)
const xp_char_t* endptr; const xp_char_t* endptr;
/* don't care about val->len */ /* don't care about val->len */
*l = xp_awk_strtolong (((xp_awk_val_str_t*)v)->buf, 0, &endptr); *l = xp_awk_strtolong (
run->awk, ((xp_awk_val_str_t*)v)->buf, 0, &endptr);
if (*endptr == XP_T('.') || if (*endptr == XP_T('.') ||
*endptr == XP_T('E') || *endptr == XP_T('E') ||
*endptr == XP_T('e')) *endptr == XP_T('e'))
{ {
*r = xp_awk_strtoreal (((xp_awk_val_str_t*)v)->buf); *r = xp_awk_strtoreal (
run->awk, ((xp_awk_val_str_t*)v)->buf);
return 1; /* real */ return 1; /* real */
} }
@ -614,6 +617,7 @@ int xp_awk_valtonum (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r)
} }
xp_printf (XP_T("*** ERROR: WRONG VALUE TYPE [%d] in xp_awk_valtonum v=> %p***\n"), v->type, v); xp_printf (XP_T("*** ERROR: WRONG VALUE TYPE [%d] in xp_awk_valtonum v=> %p***\n"), v->type, v);
run->errnum = XP_AWK_EVALTYPE;
return -1; /* error */ return -1; /* error */
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.h,v 1.39 2006-08-31 16:00:20 bacon Exp $ * $Id: val.h,v 1.40 2006-09-01 06:22:13 bacon Exp $
*/ */
#ifndef _XP_AWK_VAL_H_ #ifndef _XP_AWK_VAL_H_
@ -151,7 +151,8 @@ xp_bool_t xp_awk_valtobool (xp_awk_val_t* val);
xp_char_t* xp_awk_valtostr ( xp_char_t* xp_awk_valtostr (
xp_awk_run_t* run, xp_awk_val_t* val, xp_awk_run_t* run, xp_awk_val_t* val,
xp_bool_t clear_buf, xp_awk_str_t* buf, xp_size_t* len); xp_bool_t clear_buf, xp_awk_str_t* buf, xp_size_t* len);
int xp_awk_valtonum (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r); int xp_awk_valtonum (
xp_awk_run_t* run, xp_awk_val_t* v, xp_long_t* l, xp_real_t* r);
void xp_awk_printval (xp_awk_val_t* val); void xp_awk_printval (xp_awk_val_t* val);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.83 2006-09-01 04:03:13 bacon Exp $ * $Id: awk.c,v 1.84 2006-09-01 06:23:57 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk.h>
@ -34,17 +34,8 @@
#endif #endif
#ifdef __STAND_ALONE #ifdef __STAND_ALONE
#define xp_strcmp xp_awk_strcmp
extern int xp_awk_strcmp (const xp_char_t* s1, const xp_char_t* s2);
#define xp_strlen xp_awk_strlen
extern int xp_awk_strlen (const xp_char_t* s);
#include <assert.h> #include <assert.h>
#define xp_assert assert #define xp_assert assert
#include <stdlib.h>
#define xp_malloc malloc
#define xp_free free
#endif #endif
#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) #if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG)
@ -223,7 +214,7 @@ xp_printf (XP_TEXT("closing %s of type (pipe) %d\n"), epa->name, epa->type);
{ {
if (fgets_t (data, size, (FILE*)epa->handle) == XP_NULL) if (fgets_t (data, size, (FILE*)epa->handle) == XP_NULL)
return 0; return 0;
return xp_strlen(data); return xp_awk_strlen(data);
} }
case XP_AWK_IO_WRITE: case XP_AWK_IO_WRITE:
@ -287,7 +278,7 @@ xp_printf (XP_TEXT("closing %s of type %d (file)\n"), epa->name, epa->type);
{ {
if (fgets_t (data, size, (FILE*)epa->handle) == XP_NULL) if (fgets_t (data, size, (FILE*)epa->handle) == XP_NULL)
return 0; return 0;
return xp_strlen(data); return xp_awk_strlen(data);
} }
case XP_AWK_IO_WRITE: case XP_AWK_IO_WRITE:
@ -390,7 +381,7 @@ xp_printf (XP_TEXT("open the next console [%s]\n"), infiles[infile_no]);
infile_no++; infile_no++;
} }
return xp_strlen(data); return xp_awk_strlen(data);
} }
else if (cmd == XP_AWK_IO_WRITE) else if (cmd == XP_AWK_IO_WRITE)
{ {
@ -618,7 +609,7 @@ static int __main (int argc, xp_char_t* argv[])
#if defined(__STAND_ALONE) && !defined(_WIN32) #if defined(__STAND_ALONE) && !defined(_WIN32)
if (strcmp(argv[i], "-m") == 0) if (strcmp(argv[i], "-m") == 0)
#else #else
if (xp_strcmp(argv[i], XP_T("-m")) == 0) if (xp_awk_strcmp(argv[i], XP_T("-m")) == 0)
#endif #endif
{ {
opt |= XP_AWK_RUNMAIN; opt |= XP_AWK_RUNMAIN;
@ -645,9 +636,40 @@ static int __main (int argc, xp_char_t* argv[])
syscas.malloc = __awk_malloc; syscas.malloc = __awk_malloc;
syscas.realloc = __awk_realloc; syscas.realloc = __awk_realloc;
syscas.free = __awk_free; syscas.free = __awk_free;
syscas.lock = NULL; syscas.lock = NULL;
syscas.unlock = NULL; syscas.unlock = NULL;
#ifdef XP_CHAR_IS_MCHAR
syscas.is_upper = isupper;
syscas.is_lower = islower;
syscas.is_alpha = isalpha;
syscas.is_digit = isdigit;
syscas.is_xdigit = isxdigit;
syscas.is_alnum = isalnum;
syscas.is_space = isspace;
syscas.is_print = isprint;
syscas.is_graph = isgraph;
syscas.is_cntrl = iscntrl;
syscas.is_punct = ispunct;
syscas.to_upper = toupper;
syscas.to_lower = tolower;
#else
syscas.is_upper = iswupper;
syscas.is_lower = iswlower;
syscas.is_alpha = iswalpha;
syscas.is_digit = iswdigit;
syscas.is_xdigit = iswxdigit;
syscas.is_alnum = iswalnum;
syscas.is_space = iswspace;
syscas.is_print = iswprint;
syscas.is_graph = iswgraph;
syscas.is_cntrl = iswcntrl;
syscas.is_punct = iswpunct;
syscas.to_upper = towupper;
syscas.to_lower = towlower;
#endif
#ifdef _WIN32 #ifdef _WIN32
syscas_data.heap = HeapCreate (0, 1000000, 1000000); syscas_data.heap = HeapCreate (0, 1000000, 1000000);
if (syscas_data.heap == NULL) if (syscas_data.heap == NULL)

View File

@ -2,9 +2,9 @@ global a;
BEGIN { BEGIN {
local b; local b;
//a = 20; #a = 20;
//a[1] = 20; #a[1] = 20;
//a[2] = 30; #a[2] = 30;
/* /*
b["xxx"] = 20; b["xxx"] = 20;