qse/ase/awk/func.c

1352 lines
30 KiB
C
Raw Normal View History

2006-06-16 14:31:42 +00:00
/*
2006-12-17 14:56:07 +00:00
* $Id: func.c,v 1.85 2006-12-17 14:56:06 bacon Exp $
2006-06-16 14:31:42 +00:00
*/
2006-10-24 04:10:12 +00:00
#include <ase/awk/awk_i.h>
2006-06-16 14:31:42 +00:00
2006-11-28 04:30:57 +00:00
static int __bfn_close (ase_awk_run_t*, const ase_char_t*, ase_size_t);
static int __bfn_fflush (ase_awk_run_t*, const ase_char_t*, ase_size_t);
static int __bfn_index (ase_awk_run_t*, const ase_char_t*, ase_size_t);
static int __bfn_length (ase_awk_run_t*, const ase_char_t*, ase_size_t);
static int __bfn_substr (ase_awk_run_t*, const ase_char_t*, ase_size_t);
static int __bfn_split (ase_awk_run_t*, const ase_char_t*, ase_size_t);
static int __bfn_tolower (ase_awk_run_t*, const ase_char_t*, ase_size_t);
static int __bfn_toupper (ase_awk_run_t*, const ase_char_t*, ase_size_t);
static int __bfn_gsub (ase_awk_run_t*, const ase_char_t*, ase_size_t);
static int __bfn_sub (ase_awk_run_t*, const ase_char_t*, ase_size_t);
static int __bfn_match (ase_awk_run_t*, const ase_char_t*, ase_size_t);
static int __bfn_sprintf (ase_awk_run_t*, const ase_char_t*, ase_size_t);
2006-11-13 09:37:00 +00:00
#undef MAX
#define MAX ASE_TYPE_MAX(ase_size_t)
2006-09-14 06:40:06 +00:00
2006-10-24 04:10:12 +00:00
static ase_awk_bfn_t __sys_bfn[] =
2006-06-16 14:31:42 +00:00
{
2006-08-21 14:51:32 +00:00
/* io functions */
2006-11-29 03:19:49 +00:00
{ {ASE_T("close"), 5}, ASE_AWK_EXTIO, {1, 1, ASE_NULL}, __bfn_close},
{ {ASE_T("fflush"), 6}, ASE_AWK_EXTIO, {0, 1, ASE_NULL}, __bfn_fflush},
2006-07-17 04:17:40 +00:00
2006-08-17 03:49:30 +00:00
/* string functions */
2006-11-29 03:19:49 +00:00
{ {ASE_T("index"), 5}, 0, {2, 2, ASE_NULL}, __bfn_index},
{ {ASE_T("substr"), 6}, 0, {2, 3, ASE_NULL}, __bfn_substr},
{ {ASE_T("length"), 6}, 0, {1, 1, ASE_NULL}, __bfn_length},
{ {ASE_T("split"), 5}, 0, {2, 3, ASE_T("vrv")}, __bfn_split},
{ {ASE_T("tolower"), 7}, 0, {1, 1, ASE_NULL}, __bfn_tolower},
{ {ASE_T("toupper"), 7}, 0, {1, 1, ASE_NULL}, __bfn_toupper},
{ {ASE_T("gsub"), 4}, 0, {2, 3, ASE_T("xvr")}, __bfn_gsub},
{ {ASE_T("sub"), 3}, 0, {2, 3, ASE_T("xvr")}, __bfn_sub},
{ {ASE_T("match"), 5}, 0, {2, 2, ASE_T("vx")}, __bfn_match},
{ {ASE_T("sprintf"), 7}, 0, {1, MAX, ASE_NULL}, __bfn_sprintf},
{ {ASE_NULL, 0}, 0, {0, 0, ASE_NULL}, ASE_NULL}
2006-06-16 14:31:42 +00:00
};
2006-11-28 04:30:57 +00:00
void* ase_awk_addbfn (
2006-10-24 04:10:12 +00:00
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len,
int when_valid, ase_size_t min_args, ase_size_t max_args,
2006-11-28 04:30:57 +00:00
const ase_char_t* arg_spec,
int (*handler)(ase_awk_run_t*,const ase_char_t*,ase_size_t))
2006-06-16 14:31:42 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_bfn_t* p;
2006-07-14 04:19:22 +00:00
2006-11-28 15:09:53 +00:00
if (ase_awk_getbfn (awk, name, name_len) != ASE_NULL)
{
awk->errnum = ASE_AWK_EEXIST;
return ASE_NULL;
}
2006-11-29 02:54:17 +00:00
p = (ase_awk_bfn_t*) ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_bfn_t));
2006-11-27 15:11:14 +00:00
if (p == ASE_NULL)
{
awk->errnum = ASE_AWK_ENOMEM;
return ASE_NULL;
}
2006-07-14 04:19:22 +00:00
2006-11-27 15:11:14 +00:00
p->name.ptr = ase_awk_strxdup (awk, name, name_len);
if (p->name.ptr == ASE_NULL)
{
ASE_AWK_FREE (awk, p);
awk->errnum = ASE_AWK_ENOMEM;
return ASE_NULL;
}
2006-11-29 14:52:36 +00:00
2006-11-27 15:11:14 +00:00
p->name.len = name_len;
2006-07-14 04:19:22 +00:00
p->valid = when_valid;
2006-11-27 15:11:14 +00:00
p->arg.min = min_args;
p->arg.max = max_args;
if (arg_spec == ASE_NULL) p->arg.spec = ASE_NULL;
else
{
p->arg.spec = ase_awk_strdup (awk, arg_spec);
if (p->arg.spec == ASE_NULL)
{
ASE_AWK_FREE (awk, p->name.ptr);
ASE_AWK_FREE (awk, p);
awk->errnum = ASE_AWK_ENOMEM;
return ASE_NULL;
}
}
2006-07-14 04:19:22 +00:00
p->handler = handler;
p->next = awk->bfn.user;
awk->bfn.user = p;
return p;
}
2006-10-24 04:10:12 +00:00
int ase_awk_delbfn (ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len)
2006-07-14 04:19:22 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_bfn_t* p, * pp = ASE_NULL;
2006-07-14 04:19:22 +00:00
2006-11-29 14:52:36 +00:00
for (p = awk->bfn.user; p != ASE_NULL; p = p->next)
2006-07-14 04:19:22 +00:00
{
2006-11-27 15:11:14 +00:00
if (ase_awk_strxncmp (
p->name.ptr, p->name.len, name, name_len) == 0)
2006-07-14 04:19:22 +00:00
{
2006-10-24 04:10:12 +00:00
if (pp == ASE_NULL)
2006-07-14 04:19:22 +00:00
awk->bfn.user = p->next;
else pp->next = p->next;
2006-11-27 15:11:14 +00:00
if (p->arg.spec != ASE_NULL)
ASE_AWK_FREE (awk, p->arg.spec);
ASE_AWK_FREE (awk, p->name.ptr);
2006-10-24 04:10:12 +00:00
ASE_AWK_FREE (awk, p);
2006-07-14 04:19:22 +00:00
return 0;
}
pp = p;
}
2006-11-29 14:52:36 +00:00
awk->errnum = ASE_AWK_ENOENT;
2006-07-14 04:19:22 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
void ase_awk_clrbfn (ase_awk_t* awk)
2006-07-14 04:19:22 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_bfn_t* p, * np;
2006-07-14 04:19:22 +00:00
p = awk->bfn.user;
2006-10-24 04:10:12 +00:00
while (p != ASE_NULL)
2006-07-14 04:19:22 +00:00
{
2006-11-27 15:11:14 +00:00
np = p->next;
if (p->arg.spec != ASE_NULL)
ASE_AWK_FREE (awk, p->arg.spec);
ASE_AWK_FREE (awk, p->name.ptr);
2006-10-24 04:10:12 +00:00
ASE_AWK_FREE (awk, p);
2006-07-14 04:19:22 +00:00
p = np;
}
2006-10-24 04:10:12 +00:00
awk->bfn.user = ASE_NULL;
2006-06-21 15:37:51 +00:00
}
2006-10-24 04:10:12 +00:00
ase_awk_bfn_t* ase_awk_getbfn (
2006-11-28 04:30:57 +00:00
ase_awk_t* awk, const ase_char_t* name, ase_size_t len)
2006-06-21 15:37:51 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_bfn_t* p;
2006-06-16 14:31:42 +00:00
2006-11-27 15:11:14 +00:00
for (p = __sys_bfn; p->name.ptr != ASE_NULL; p++)
2006-07-13 15:43:39 +00:00
{
if (p->valid != 0 &&
2006-08-04 17:36:40 +00:00
(awk->option & p->valid) == 0) continue;
2006-07-13 15:43:39 +00:00
2006-10-24 04:10:12 +00:00
if (ase_awk_strxncmp (
2006-11-28 04:30:57 +00:00
p->name.ptr, p->name.len, name, len) == 0) return p;
2006-07-13 15:43:39 +00:00
}
2006-10-24 04:10:12 +00:00
for (p = awk->bfn.user; p != ASE_NULL; p = p->next)
2006-06-16 14:31:42 +00:00
{
2006-06-21 15:37:51 +00:00
if (p->valid != 0 &&
2006-08-04 17:36:40 +00:00
(awk->option & p->valid) == 0) continue;
2006-06-21 15:37:51 +00:00
2006-10-24 04:10:12 +00:00
if (ase_awk_strxncmp (
2006-11-28 04:30:57 +00:00
p->name.ptr, p->name.len, name, len) == 0) return p;
2006-06-16 14:31:42 +00:00
}
2006-10-24 04:10:12 +00:00
return ASE_NULL;
2006-06-16 14:31:42 +00:00
}
2006-06-20 15:27:50 +00:00
2006-11-28 04:30:57 +00:00
static int __bfn_close (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
2006-06-20 15:27:50 +00:00
{
2006-10-24 04:10:12 +00:00
ase_size_t nargs;
ase_awk_val_t* v, * a0;
2006-08-31 15:39:14 +00:00
int n;
2006-08-02 03:22:51 +00:00
2006-10-24 04:10:12 +00:00
ase_char_t* name;
ase_size_t len;
2006-06-20 15:27:50 +00:00
2006-10-24 04:10:12 +00:00
nargs = ase_awk_getnargs (run);
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, nargs == 1);
2006-06-21 15:37:51 +00:00
/* TODO: support close (xxx, "to"/"from") like gawk */
2006-06-21 11:45:26 +00:00
2006-10-24 04:10:12 +00:00
a0 = ase_awk_getarg (run, 0);
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, a0 != ASE_NULL);
2006-08-02 03:22:51 +00:00
2006-10-24 04:10:12 +00:00
if (a0->type == ASE_AWK_VAL_STR)
2006-06-21 11:45:26 +00:00
{
2006-10-24 04:10:12 +00:00
name = ((ase_awk_val_str_t*)a0)->buf;
len = ((ase_awk_val_str_t*)a0)->len;
2006-06-21 11:45:26 +00:00
}
2006-08-02 03:22:51 +00:00
else
2006-06-21 11:45:26 +00:00
{
2006-10-24 04:10:12 +00:00
name = ase_awk_valtostr (
run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len);
if (name == ASE_NULL) return -1;
2006-06-21 11:45:26 +00:00
}
2006-08-02 11:26:11 +00:00
if (len == 0)
{
/* getline or print doesn't allow an emptry for the
* input or output file name. so close should not allow
* it either.
2006-10-22 12:39:30 +00:00
* another reason for this is if close is called explicitly
2006-08-02 11:26:11 +00:00
* with an empty string, it may close the console that uses
* an empty string for its identification because closeextio
* closes any extios that match the name given unlike
* closeextio_read or closeextio_write. */
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, name);
2006-08-02 11:26:11 +00:00
n = -1;
goto skip_close;
}
2006-08-02 03:22:51 +00:00
while (len > 0)
{
2006-10-24 04:10:12 +00:00
if (name[--len] == ASE_T('\0'))
2006-08-02 03:22:51 +00:00
{
/* the name contains a null string.
* make close return -1 */
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR)
ASE_AWK_FREE (run->awk, name);
2006-08-02 03:22:51 +00:00
n = -1;
goto skip_close;
}
}
2006-10-24 04:10:12 +00:00
n = ase_awk_closeextio (run, name);
if (n == -1 && run->errnum != ASE_AWK_EIOHANDLER)
2006-06-21 11:45:26 +00:00
{
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR)
ASE_AWK_FREE (run->awk, name);
2006-06-21 11:45:26 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, name);
2006-06-21 11:45:26 +00:00
2006-08-02 03:22:51 +00:00
skip_close:
2006-10-24 04:10:12 +00:00
v = ase_awk_makeintval (run, n);
if (v == ASE_NULL)
2006-06-20 15:27:50 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-06-21 11:45:26 +00:00
return -1;
2006-06-20 15:27:50 +00:00
}
2006-10-24 04:10:12 +00:00
ase_awk_setretval (run, v);
2006-06-20 15:27:50 +00:00
return 0;
}
2006-07-17 04:17:40 +00:00
2006-08-27 15:29:21 +00:00
static int __flush_extio (
2006-10-24 04:10:12 +00:00
ase_awk_run_t* run, int extio, const ase_char_t* name, int n)
2006-08-27 15:29:21 +00:00
{
int n2;
2006-10-24 04:10:12 +00:00
if (run->extio.handler[extio] != ASE_NULL)
2006-08-27 15:29:21 +00:00
{
2006-10-24 04:10:12 +00:00
n2 = ase_awk_flushextio (run, extio, name);
2006-08-27 15:29:21 +00:00
if (n2 == -1)
{
2006-10-24 04:10:12 +00:00
if (run->errnum == ASE_AWK_EIOHANDLER) n = -1;
else if (run->errnum == ASE_AWK_ENOSUCHIO)
2006-08-27 15:29:21 +00:00
{
if (n != 0) n = -2;
}
else n = -99;
}
else if (n != -1) n = 0;
}
return n;
}
2006-11-28 04:30:57 +00:00
static int __bfn_fflush (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
2006-08-21 14:51:32 +00:00
{
2006-10-24 04:10:12 +00:00
ase_size_t nargs;
ase_awk_val_t* a0;
ase_char_t* str0;
ase_size_t len0;
2006-08-31 15:39:14 +00:00
int n;
2006-11-29 03:19:49 +00:00
2006-10-24 04:10:12 +00:00
nargs = ase_awk_getnargs (run);
2006-10-28 05:24:08 +00:00
ASE_AWK_ASSERT (run->awk, nargs == 0 || nargs == 1);
2006-08-21 14:51:32 +00:00
if (nargs == 0)
{
/* flush the console output */
2006-10-24 04:10:12 +00:00
n = ase_awk_flushextio (run, ASE_AWK_OUT_CONSOLE, ASE_T(""));
2006-08-23 15:42:16 +00:00
if (n == -1 &&
2006-10-24 04:10:12 +00:00
run->errnum != ASE_AWK_EIOHANDLER &&
run->errnum != ASE_AWK_ENOSUCHIO)
2006-08-22 15:11:13 +00:00
{
return -1;
}
2006-08-27 15:29:21 +00:00
/* fflush() should return -1 on EIOHANDLER and ENOSUCHIO */
2006-08-21 14:51:32 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
ase_char_t* ptr, * end;
2006-08-22 15:11:13 +00:00
2006-10-24 04:10:12 +00:00
a0 = ase_awk_getarg (run, 0);
if (a0->type == ASE_AWK_VAL_STR)
2006-08-21 14:51:32 +00:00
{
2006-10-24 04:10:12 +00:00
str0 = ((ase_awk_val_str_t*)a0)->buf;
len0 = ((ase_awk_val_str_t*)a0)->len;
2006-08-21 14:51:32 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
str0 = ase_awk_valtostr (
run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len0);
if (str0 == ASE_NULL) return -1;
2006-08-22 15:11:13 +00:00
}
/* the target name contains a null character.
2006-12-17 14:56:07 +00:00
* make fflush return -1 */
2006-08-22 15:11:13 +00:00
ptr = str0; end = str0 + len0;
while (ptr < end)
{
2006-10-24 04:10:12 +00:00
if (*ptr == ASE_T('\0'))
2006-08-22 15:11:13 +00:00
{
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR)
ASE_AWK_FREE (run->awk, str0);
2006-08-22 15:11:13 +00:00
n = -1;
goto skip_flush;
}
ptr++;
2006-08-21 14:51:32 +00:00
}
2006-08-23 15:42:16 +00:00
/* flush the given extio */
2006-08-27 15:29:21 +00:00
n = __flush_extio (
2006-10-24 04:10:12 +00:00
run, ASE_AWK_EXTIO_FILE,
((len0 == 0)? ASE_NULL: str0), 1);
2006-08-27 15:29:21 +00:00
if (n == -99) return -1;
n = __flush_extio (
2006-10-24 04:10:12 +00:00
run, ASE_AWK_EXTIO_PIPE,
((len0 == 0)? ASE_NULL: str0), n);
2006-08-27 15:29:21 +00:00
if (n == -99) return -1;
n = __flush_extio (
2006-10-24 04:10:12 +00:00
run, ASE_AWK_EXTIO_COPROC,
((len0 == 0)? ASE_NULL: str0), n);
2006-08-27 15:29:21 +00:00
if (n == -99) return -1;
2006-08-21 14:51:32 +00:00
2006-08-23 15:42:16 +00:00
/* if n remains 1, no ip handlers have been defined for
* file, pipe, and coproc. so make fflush return -1.
* if n is -2, no such named io has been found at all
* if n is -1, the io handler has returned an error */
if (n != 0) n = -1;
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str0);
2006-08-21 14:51:32 +00:00
}
2006-08-22 15:11:13 +00:00
skip_flush:
2006-10-24 04:10:12 +00:00
a0 = ase_awk_makeintval (run, (ase_long_t)n);
if (a0 == ASE_NULL)
2006-08-21 14:51:32 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-08-21 14:51:32 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
ase_awk_setretval (run, a0);
2006-08-21 14:51:32 +00:00
return 0;
}
2006-11-28 04:30:57 +00:00
static int __bfn_index (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
2006-08-13 16:05:04 +00:00
{
2006-10-24 04:10:12 +00:00
ase_size_t nargs;
ase_awk_val_t* a0, * a1;
ase_char_t* str0, * str1, * ptr;
ase_size_t len0, len1;
ase_long_t idx;
nargs = ase_awk_getnargs (run);
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, nargs == 2);
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
a0 = ase_awk_getarg (run, 0);
a1 = ase_awk_getarg (run, 1);
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
if (a0->type == ASE_AWK_VAL_STR)
2006-08-13 16:05:04 +00:00
{
2006-10-24 04:10:12 +00:00
str0 = ((ase_awk_val_str_t*)a0)->buf;
len0 = ((ase_awk_val_str_t*)a0)->len;
2006-08-13 16:05:04 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
str0 = ase_awk_valtostr (
run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len0);
if (str0 == ASE_NULL) return -1;
2006-08-13 16:05:04 +00:00
}
2006-10-24 04:10:12 +00:00
if (a1->type == ASE_AWK_VAL_STR)
2006-08-13 16:05:04 +00:00
{
2006-10-24 04:10:12 +00:00
str1 = ((ase_awk_val_str_t*)a1)->buf;
len1 = ((ase_awk_val_str_t*)a1)->len;
2006-08-13 16:05:04 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
str1 = ase_awk_valtostr (
run, a1, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len1);
if (str1 == ASE_NULL)
2006-08-13 16:05:04 +00:00
{
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR)
ASE_AWK_FREE (run->awk, str0);
2006-08-13 16:05:04 +00:00
return -1;
}
}
2006-10-24 04:10:12 +00:00
ptr = ase_awk_strxnstr (str0, len0, str1, len1);
idx = (ptr == ASE_NULL)? -1: (ase_long_t)(ptr - str0);
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
if (ase_awk_getopt(run->awk) & ASE_AWK_STRINDEXONE) idx = idx + 1;
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str0);
if (a1->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str1);
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
a0 = ase_awk_makeintval (run, idx);
if (a0 == ASE_NULL)
2006-08-13 16:05:04 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-08-13 16:05:04 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
ase_awk_setretval (run, a0);
2006-08-13 16:05:04 +00:00
return 0;
}
2006-11-28 04:30:57 +00:00
static int __bfn_length (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
2006-08-13 16:05:04 +00:00
{
2006-10-24 04:10:12 +00:00
ase_size_t nargs;
ase_awk_val_t* v;
ase_char_t* str;
ase_size_t len;
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
nargs = ase_awk_getnargs (run);
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, nargs == 1);
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
v = ase_awk_getarg (run, 0);
if (v->type == ASE_AWK_VAL_STR)
2006-08-13 16:05:04 +00:00
{
2006-10-24 04:10:12 +00:00
len = ((ase_awk_val_str_t*)v)->len;
2006-08-13 16:05:04 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
str = ase_awk_valtostr (
run, v, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len);
if (str == ASE_NULL) return -1;
ASE_AWK_FREE (run->awk, str);
2006-08-13 16:05:04 +00:00
}
2006-10-24 04:10:12 +00:00
v = ase_awk_makeintval (run, len);
if (v == ASE_NULL)
2006-08-13 16:05:04 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-08-13 16:05:04 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
ase_awk_setretval (run, v);
2006-08-13 16:05:04 +00:00
return 0;
}
2006-11-28 04:30:57 +00:00
static int __bfn_substr (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
2006-08-13 16:05:04 +00:00
{
2006-10-24 04:10:12 +00:00
ase_size_t nargs;
ase_awk_val_t* a0, * a1, * a2, * r;
ase_char_t* str;
ase_size_t len;
ase_long_t lindex, lcount;
ase_real_t rindex, rcount;
2006-08-31 15:39:14 +00:00
int n;
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
nargs = ase_awk_getnargs (run);
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, nargs >= 2 && nargs <= 3);
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
a0 = ase_awk_getarg (run, 0);
a1 = ase_awk_getarg (run, 1);
a2 = (nargs >= 3)? ase_awk_getarg (run, 2): ASE_NULL;
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
if (a0->type == ASE_AWK_VAL_STR)
2006-08-13 16:05:04 +00:00
{
2006-10-24 04:10:12 +00:00
str = ((ase_awk_val_str_t*)a0)->buf;
len = ((ase_awk_val_str_t*)a0)->len;
2006-08-13 16:05:04 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
str = ase_awk_valtostr (
run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len);
if (str == ASE_NULL) return -1;
2006-08-13 16:05:04 +00:00
}
2006-10-24 04:10:12 +00:00
n = ase_awk_valtonum (run, a1, &lindex, &rindex);
2006-08-13 16:05:04 +00:00
if (n == -1)
{
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str);
2006-08-13 16:05:04 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
if (n == 1) lindex = (ase_long_t)rindex;
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
if (a2 == ASE_NULL) lcount = (ase_long_t)len;
2006-08-13 16:05:04 +00:00
else
{
2006-10-24 04:10:12 +00:00
n = ase_awk_valtonum (run, a2, &lcount, &rcount);
2006-08-13 16:05:04 +00:00
if (n == -1)
{
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR)
ASE_AWK_FREE (run->awk, str);
2006-08-13 16:05:04 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
if (n == 1) lcount = (ase_long_t)rcount;
2006-08-13 16:05:04 +00:00
}
2006-10-24 04:10:12 +00:00
if (ase_awk_getopt(run->awk) & ASE_AWK_STRINDEXONE) lindex = lindex - 1;
2006-08-13 16:05:04 +00:00
if (lindex >= len) lindex = len;
else if (lindex < 0) lindex = 0;
if (lcount < 0) lcount = 0;
else if (lcount > len - lindex) lcount = len - lindex;
2006-10-24 04:10:12 +00:00
r = ase_awk_makestrval (run, &str[lindex], (ase_size_t)lcount);
if (r == ASE_NULL)
2006-08-13 16:05:04 +00:00
{
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-08-13 16:05:04 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str);
ase_awk_setretval (run, r);
2006-08-13 16:05:04 +00:00
return 0;
}
2006-11-28 04:30:57 +00:00
static int __bfn_split (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
2006-08-13 16:05:04 +00:00
{
2006-10-24 04:10:12 +00:00
ase_size_t nargs;
ase_awk_val_t* a0, * a1, * a2, * t1, * t2, ** a1_ref;
ase_char_t* str, * str_free, * p, * tok;
ase_size_t str_len, str_left, tok_len;
ase_long_t sta, num;
2006-11-29 02:54:17 +00:00
ase_char_t key[ASE_SIZEOF(ase_long_t)*8+2];
2006-10-24 04:10:12 +00:00
ase_size_t key_len;
ase_char_t* fs_ptr, * fs_free;
ase_size_t fs_len;
void* fs_rex = ASE_NULL;
void* fs_rex_free = ASE_NULL;
2006-09-05 04:11:11 +00:00
int errnum;
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
nargs = ase_awk_getnargs (run);
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, nargs >= 2 && nargs <= 3);
2006-08-13 16:05:04 +00:00
2006-10-24 04:10:12 +00:00
a0 = ase_awk_getarg (run, 0);
a1 = ase_awk_getarg (run, 1);
a2 = (nargs >= 3)? ase_awk_getarg (run, 2): ASE_NULL;
2006-08-13 16:05:04 +00:00
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, a1->type == ASE_AWK_VAL_REF);
2006-08-18 07:52:47 +00:00
2006-10-24 04:10:12 +00:00
if (((ase_awk_val_ref_t*)a1)->id >= ASE_AWK_VAL_REF_NAMEDIDX &&
((ase_awk_val_ref_t*)a1)->id <= ASE_AWK_VAL_REF_ARGIDX)
2006-08-13 16:05:04 +00:00
{
2006-08-20 15:49:48 +00:00
/* an indexed value should not be assigned another map */
2006-10-24 04:10:12 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_EIDXVALASSMAP);
2006-10-10 07:02:38 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
if (((ase_awk_val_ref_t*)a1)->id == ASE_AWK_VAL_REF_POS)
2006-10-10 07:02:38 +00:00
{
/* a positional should not be assigned a map */
2006-10-24 04:10:12 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_EPOSVALASSMAP);
2006-08-20 15:49:48 +00:00
return -1;
2006-08-13 16:05:04 +00:00
}
2006-10-24 04:10:12 +00:00
a1_ref = (ase_awk_val_t**)((ase_awk_val_ref_t*)a1)->adr;
if ((*a1_ref)->type != ASE_AWK_VAL_NIL &&
(*a1_ref)->type != ASE_AWK_VAL_MAP)
2006-08-17 14:10:21 +00:00
{
2006-08-20 15:49:48 +00:00
/* cannot change a scalar value to a map */
2006-10-24 04:10:12 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_ESCALARTOMAP);
2006-08-17 14:10:21 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
if (a0->type == ASE_AWK_VAL_STR)
2006-08-18 17:46:07 +00:00
{
2006-10-24 04:10:12 +00:00
str = ((ase_awk_val_str_t*)a0)->buf;
str_len = ((ase_awk_val_str_t*)a0)->len;
str_free = ASE_NULL;
2006-08-18 17:46:07 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
str = ase_awk_valtostr (
run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &str_len);
if (str == ASE_NULL) return -1;
2006-09-03 15:47:11 +00:00
str_free = str;
}
2006-10-24 04:10:12 +00:00
if (a2 == ASE_NULL)
2006-09-03 15:47:11 +00:00
{
/* get the value from FS */
2006-10-24 04:10:12 +00:00
t1 = ase_awk_getglobal (run, ASE_AWK_GLOBAL_FS);
if (t1->type == ASE_AWK_VAL_NIL)
2006-09-03 15:47:11 +00:00
{
2006-10-24 04:10:12 +00:00
fs_ptr = ASE_T(" ");
2006-09-03 15:47:11 +00:00
fs_len = 1;
2006-10-24 04:10:12 +00:00
fs_free = ASE_NULL;
2006-09-03 15:47:11 +00:00
}
2006-10-24 04:10:12 +00:00
else if (t1->type == ASE_AWK_VAL_STR)
2006-09-03 15:47:11 +00:00
{
2006-10-24 04:10:12 +00:00
fs_ptr = ((ase_awk_val_str_t*)t1)->buf;
fs_len = ((ase_awk_val_str_t*)t1)->len;
fs_free = ASE_NULL;
2006-09-03 15:47:11 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
fs_ptr = ase_awk_valtostr (
run, t1, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &fs_len);
if (fs_ptr == ASE_NULL)
2006-09-03 15:47:11 +00:00
{
2006-10-24 04:10:12 +00:00
if (str_free != ASE_NULL)
ASE_AWK_FREE (run->awk, str_free);
2006-09-03 15:47:11 +00:00
return -1;
}
fs_free = fs_ptr;
}
2006-09-05 04:11:11 +00:00
if (fs_len > 1)
{
2006-10-10 07:02:38 +00:00
fs_rex = run->global.fs;
2006-10-24 04:10:12 +00:00
fs_rex_free = ASE_NULL;
2006-09-05 04:11:11 +00:00
}
2006-09-03 15:47:11 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
if (a2->type == ASE_AWK_VAL_STR)
2006-09-03 15:47:11 +00:00
{
2006-10-24 04:10:12 +00:00
fs_ptr = ((ase_awk_val_str_t*)a2)->buf;
fs_len = ((ase_awk_val_str_t*)a2)->len;
fs_free = ASE_NULL;
2006-09-03 15:47:11 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
fs_ptr = ase_awk_valtostr (
run, a2, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &fs_len);
if (fs_ptr == ASE_NULL)
2006-09-03 15:47:11 +00:00
{
2006-10-24 04:10:12 +00:00
if (str_free != ASE_NULL)
ASE_AWK_FREE (run->awk, str_free);
2006-09-03 15:47:11 +00:00
return -1;
}
fs_free = fs_ptr;
}
2006-09-05 04:11:11 +00:00
if (fs_len > 1)
{
2006-10-24 04:10:12 +00:00
fs_rex = ase_awk_buildrex (
2006-10-10 07:02:38 +00:00
run->awk, fs_ptr, fs_len, &errnum);
2006-10-24 04:10:12 +00:00
if (fs_rex == ASE_NULL)
2006-09-05 04:11:11 +00:00
{
2006-10-24 04:10:12 +00:00
if (str_free != ASE_NULL)
ASE_AWK_FREE (run->awk, str_free);
if (fs_free != ASE_NULL)
ASE_AWK_FREE (run->awk, fs_free);
ase_awk_setrunerrnum (run, errnum);
2006-09-05 04:11:11 +00:00
return -1;
}
fs_rex_free = fs_rex;
}
2006-08-18 17:46:07 +00:00
}
2006-10-24 04:10:12 +00:00
t1 = ase_awk_makemapval (run);
if (t1 == ASE_NULL)
2006-08-18 17:46:07 +00:00
{
2006-10-24 04:10:12 +00:00
if (str_free != ASE_NULL)
ASE_AWK_FREE (run->awk, str_free);
if (fs_free != ASE_NULL)
ASE_AWK_FREE (run->awk, fs_free);
if (fs_rex_free != ASE_NULL)
ase_awk_freerex (run->awk, fs_rex_free);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-08-18 17:46:07 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
ase_awk_refdownval (run, *a1_ref);
2006-09-13 14:16:35 +00:00
*a1_ref = t1;
2006-11-16 11:53:16 +00:00
ase_awk_refupval (run, *a1_ref);
2006-08-19 16:34:24 +00:00
2006-10-16 08:48:19 +00:00
p = str; str_left = str_len;
2006-10-24 04:10:12 +00:00
sta = (ase_awk_getopt(run->awk) & ASE_AWK_STRINDEXONE)? 1: 0;
2006-10-16 08:48:19 +00:00
num = sta;
2006-10-24 04:10:12 +00:00
while (p != ASE_NULL)
2006-08-18 17:46:07 +00:00
{
2006-09-03 15:47:11 +00:00
if (fs_len <= 1)
{
2006-10-24 04:10:12 +00:00
p = ase_awk_strxntok (run,
2006-09-03 15:47:11 +00:00
p, str_len, fs_ptr, fs_len, &tok, &tok_len);
}
else
{
2006-10-24 04:10:12 +00:00
p = ase_awk_strxntokbyrex (run, p, str_len,
2006-09-05 04:11:11 +00:00
fs_rex, &tok, &tok_len, &errnum);
2006-10-24 04:10:12 +00:00
if (p == ASE_NULL && errnum != ASE_AWK_ENOERR)
2006-09-05 04:11:11 +00:00
{
2006-10-24 04:10:12 +00:00
if (str_free != ASE_NULL)
ASE_AWK_FREE (run->awk, str_free);
if (fs_free != ASE_NULL)
ASE_AWK_FREE (run->awk, fs_free);
if (fs_rex_free != ASE_NULL)
ase_awk_freerex (run->awk, fs_rex_free);
ase_awk_setrunerrnum (run, errnum);
2006-09-05 04:11:11 +00:00
return -1;
}
2006-09-03 15:47:11 +00:00
}
2006-08-18 17:46:07 +00:00
2006-10-24 04:10:12 +00:00
if (num == 0 && p == ASE_NULL && tok_len == 0)
2006-08-18 17:46:07 +00:00
{
/* no field at all*/
break;
}
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk,
2006-10-24 04:10:12 +00:00
(tok != ASE_NULL && tok_len > 0) || tok_len == 0);
2006-08-18 17:46:07 +00:00
/* create the field string */
2006-10-24 04:10:12 +00:00
t2 = ase_awk_makestrval (run, tok, tok_len);
if (t2 == ASE_NULL)
2006-08-18 17:46:07 +00:00
{
2006-10-24 04:10:12 +00:00
if (str_free != ASE_NULL)
ASE_AWK_FREE (run->awk, str_free);
if (fs_free != ASE_NULL)
ASE_AWK_FREE (run->awk, fs_free);
if (fs_rex_free != ASE_NULL)
ase_awk_freerex (run->awk, fs_rex_free);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-08-18 17:46:07 +00:00
return -1;
}
/* put it into the map */
2006-10-24 04:10:12 +00:00
key_len = ase_awk_longtostr (
2006-11-29 02:54:17 +00:00
num, 10, ASE_NULL, key, ASE_COUNTOF(key));
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, key_len != (ase_size_t)-1);
2006-08-18 17:46:07 +00:00
2006-10-11 03:19:08 +00:00
/* don't forget to update the reference count when you
* handle the assignment-like situation. anyway, it is
* incremented in advance as if the assignment was successful.
* it is decremented if the assignement fails. */
2006-11-16 11:53:16 +00:00
ase_awk_refupval (run, t2);
2006-10-11 03:19:08 +00:00
2006-10-24 04:10:12 +00:00
if (ase_awk_map_putx (
((ase_awk_val_map_t*)t1)->map,
key, key_len, t2, ASE_NULL) == -1)
2006-08-18 17:46:07 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_refdownval (run, t2);
if (str_free != ASE_NULL)
ASE_AWK_FREE (run->awk, str_free);
if (fs_free != ASE_NULL)
ASE_AWK_FREE (run->awk, fs_free);
if (fs_rex_free != ASE_NULL)
ase_awk_freerex (run->awk, fs_rex_free);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-08-18 17:46:07 +00:00
return -1;
}
num++;
2006-09-05 04:11:11 +00:00
str_len = str_left - (p - str);
2006-08-18 17:46:07 +00:00
}
2006-10-24 04:10:12 +00:00
if (str_free != ASE_NULL) ASE_AWK_FREE (run->awk, str_free);
if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free);
if (fs_rex_free != ASE_NULL) ase_awk_freerex (run->awk, fs_rex_free);
2006-08-18 17:46:07 +00:00
2006-10-16 08:48:19 +00:00
if (sta == 1) num--;
2006-10-24 04:10:12 +00:00
t1 = ase_awk_makeintval (run, num);
if (t1 == ASE_NULL)
2006-08-18 17:46:07 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-08-18 17:46:07 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
ase_awk_setretval (run, t1);
2006-08-18 17:46:07 +00:00
return 0;
}
2006-08-13 16:05:04 +00:00
2006-11-28 04:30:57 +00:00
static int __bfn_tolower (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
2006-08-17 03:49:30 +00:00
{
2006-10-24 04:10:12 +00:00
ase_size_t nargs;
ase_char_t* str;
ase_size_t len, i;
ase_awk_val_t* a0, * r;
2006-08-17 03:49:30 +00:00
2006-10-24 04:10:12 +00:00
nargs = ase_awk_getnargs (run);
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, nargs == 1);
2006-08-17 03:49:30 +00:00
2006-10-24 04:10:12 +00:00
a0 = ase_awk_getarg (run, 0);
2006-08-17 03:49:30 +00:00
2006-10-24 04:10:12 +00:00
if (a0->type == ASE_AWK_VAL_STR)
2006-08-17 03:49:30 +00:00
{
2006-10-24 04:10:12 +00:00
str = ((ase_awk_val_str_t*)a0)->buf;
len = ((ase_awk_val_str_t*)a0)->len;
2006-08-17 03:49:30 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
str = ase_awk_valtostr (
run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len);
if (str == ASE_NULL) return -1;
2006-08-17 03:49:30 +00:00
}
2006-10-24 04:10:12 +00:00
for (i = 0; i < len; i++) str[i] = ASE_AWK_TOLOWER (run->awk, str[i]);
2006-08-17 03:49:30 +00:00
2006-10-24 04:10:12 +00:00
r = ase_awk_makestrval (run, str, len);
if (r == ASE_NULL)
2006-08-17 03:49:30 +00:00
{
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-08-17 03:49:30 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str);
ase_awk_setretval (run, r);
2006-08-17 03:49:30 +00:00
return 0;
}
2006-11-28 04:30:57 +00:00
static int __bfn_toupper (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
2006-08-17 03:49:30 +00:00
{
2006-10-24 04:10:12 +00:00
ase_size_t nargs;
ase_char_t* str;
ase_size_t len, i;
ase_awk_val_t* a0, * r;
2006-08-17 03:49:30 +00:00
2006-10-24 04:10:12 +00:00
nargs = ase_awk_getnargs (run);
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, nargs == 1);
2006-08-17 03:49:30 +00:00
2006-10-24 04:10:12 +00:00
a0 = ase_awk_getarg (run, 0);
2006-08-17 03:49:30 +00:00
2006-10-24 04:10:12 +00:00
if (a0->type == ASE_AWK_VAL_STR)
2006-08-17 03:49:30 +00:00
{
2006-10-24 04:10:12 +00:00
str = ((ase_awk_val_str_t*)a0)->buf;
len = ((ase_awk_val_str_t*)a0)->len;
2006-08-17 03:49:30 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
str = ase_awk_valtostr (
run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len);
if (str == ASE_NULL) return -1;
2006-08-17 03:49:30 +00:00
}
2006-10-24 04:10:12 +00:00
for (i = 0; i < len; i++) str[i] = ASE_AWK_TOUPPER (run->awk, str[i]);
2006-08-17 03:49:30 +00:00
2006-10-24 04:10:12 +00:00
r = ase_awk_makestrval (run, str, len);
if (r == ASE_NULL)
2006-08-17 03:49:30 +00:00
{
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-08-17 03:49:30 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str);
ase_awk_setretval (run, r);
2006-08-17 03:49:30 +00:00
return 0;
}
2006-10-24 04:10:12 +00:00
static int __substitute (ase_awk_run_t* run, ase_long_t max_count)
2006-09-14 06:40:06 +00:00
{
2006-10-24 04:10:12 +00:00
ase_size_t nargs;
ase_awk_val_t* a0, * a1, * a2, ** a2_ref, * v;
ase_char_t* a0_ptr, * a1_ptr, * a2_ptr;
ase_size_t a0_len, a1_len, a2_len;
ase_char_t* a0_ptr_free = ASE_NULL;
ase_char_t* a1_ptr_free = ASE_NULL;
ase_char_t* a2_ptr_free = ASE_NULL;
2006-09-12 15:20:18 +00:00
void* rex;
int opt, n;
2006-10-24 04:10:12 +00:00
const ase_char_t* cur_ptr, * mat_ptr;
ase_size_t cur_len, mat_len, i, m;
ase_awk_str_t new;
ase_long_t sub_count;
2006-09-11 14:29:23 +00:00
2006-10-24 04:10:12 +00:00
nargs = ase_awk_getnargs (run);
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, nargs >= 2 && nargs <= 3);
2006-09-11 14:29:23 +00:00
2006-10-24 04:10:12 +00:00
a0 = ase_awk_getarg (run, 0);
a1 = ase_awk_getarg (run, 1);
a2 = (nargs >= 3)? ase_awk_getarg (run, 2): ASE_NULL;
2006-09-11 14:29:23 +00:00
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, a2 == ASE_NULL || a2->type == ASE_AWK_VAL_REF);
2006-09-11 14:29:23 +00:00
2006-09-14 06:40:06 +00:00
#define FREE_A_PTRS(awk) \
do { \
2006-10-24 04:10:12 +00:00
if (a2_ptr_free != ASE_NULL) ASE_AWK_FREE (awk, a2_ptr_free); \
if (a1_ptr_free != ASE_NULL) ASE_AWK_FREE (awk, a1_ptr_free); \
if (a0_ptr_free != ASE_NULL) ASE_AWK_FREE (awk, a0_ptr_free); \
2006-09-14 06:40:06 +00:00
} while (0)
#define FREE_A0_REX(awk,rex) \
do { \
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_REX) ase_awk_freerex (awk, rex); \
2006-09-14 06:40:06 +00:00
} while (0)
2006-10-24 04:10:12 +00:00
if (a0->type == ASE_AWK_VAL_REX)
2006-09-13 14:16:35 +00:00
{
2006-10-24 04:10:12 +00:00
rex = ((ase_awk_val_rex_t*)a0)->code;
2006-09-13 14:16:35 +00:00
}
2006-10-24 04:10:12 +00:00
else if (a0->type == ASE_AWK_VAL_STR)
2006-09-11 14:29:23 +00:00
{
2006-10-24 04:10:12 +00:00
a0_ptr = ((ase_awk_val_str_t*)a0)->buf;
a0_len = ((ase_awk_val_str_t*)a0)->len;
2006-09-11 14:29:23 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
a0_ptr = ase_awk_valtostr (
run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &a0_len);
if (a0_ptr == ASE_NULL)
2006-09-14 06:40:06 +00:00
{
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-09-14 06:40:06 +00:00
return -1;
}
2006-09-11 14:29:23 +00:00
a0_ptr_free = a0_ptr;
}
2006-10-24 04:10:12 +00:00
if (a1->type == ASE_AWK_VAL_STR)
2006-09-11 14:29:23 +00:00
{
2006-10-24 04:10:12 +00:00
a1_ptr = ((ase_awk_val_str_t*)a1)->buf;
a1_len = ((ase_awk_val_str_t*)a1)->len;
2006-09-11 14:29:23 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
a1_ptr = ase_awk_valtostr (
run, a1, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &a1_len);
if (a1_ptr == ASE_NULL)
2006-09-11 14:29:23 +00:00
{
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-09-11 14:29:23 +00:00
return -1;
}
a1_ptr_free = a1_ptr;
}
2006-10-24 04:10:12 +00:00
if (a2 == ASE_NULL)
2006-09-11 14:29:23 +00:00
{
2006-09-14 06:40:06 +00:00
/* is this correct? any needs to use inrec.d0? */
2006-10-24 04:10:12 +00:00
a2_ptr = ASE_AWK_STR_BUF(&run->inrec.line);
a2_len = ASE_AWK_STR_LEN(&run->inrec.line);
2006-10-02 14:54:32 +00:00
}
2006-10-24 04:10:12 +00:00
else if (((ase_awk_val_ref_t*)a2)->id == ASE_AWK_VAL_REF_POS)
2006-10-02 14:54:32 +00:00
{
2006-10-24 04:10:12 +00:00
ase_size_t idx;
2006-10-02 14:54:32 +00:00
2006-10-24 04:10:12 +00:00
idx = (ase_size_t)((ase_awk_val_ref_t*)a2)->adr;
2006-10-02 14:54:32 +00:00
if (idx == 0)
{
2006-10-24 04:10:12 +00:00
a2_ptr = ASE_AWK_STR_BUF(&run->inrec.line);
a2_len = ASE_AWK_STR_LEN(&run->inrec.line);
2006-10-02 14:54:32 +00:00
}
2006-10-10 07:02:38 +00:00
else if (idx <= run->inrec.nflds)
2006-10-02 14:54:32 +00:00
{
2006-10-10 07:02:38 +00:00
a2_ptr = run->inrec.flds[idx-1].ptr;
a2_len = run->inrec.flds[idx-1].len;
2006-10-02 14:54:32 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
a2_ptr = ASE_T("");
2006-10-02 14:54:32 +00:00
a2_len = 0;
}
2006-09-11 14:29:23 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
a2_ref = (ase_awk_val_t**)((ase_awk_val_ref_t*)a2)->adr;
2006-10-02 14:54:32 +00:00
2006-10-24 04:10:12 +00:00
if ((*a2_ref)->type == ASE_AWK_VAL_MAP)
2006-09-12 15:20:18 +00:00
{
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-09-14 06:40:06 +00:00
/* a map is not allowed as the third parameter */
2006-10-24 04:10:12 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_EMAPNOTALLOWED);
2006-09-14 06:40:06 +00:00
return -1;
2006-09-12 15:20:18 +00:00
}
2006-09-14 06:40:06 +00:00
2006-10-24 04:10:12 +00:00
if ((*a2_ref)->type == ASE_AWK_VAL_STR)
2006-09-13 14:16:35 +00:00
{
2006-10-24 04:10:12 +00:00
a2_ptr = ((ase_awk_val_str_t*)(*a2_ref))->buf;
a2_len = ((ase_awk_val_str_t*)(*a2_ref))->len;
2006-09-13 14:16:35 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
a2_ptr = ase_awk_valtostr (
run, *a2_ref, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &a2_len);
if (a2_ptr == ASE_NULL)
2006-09-13 14:16:35 +00:00
{
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-09-13 14:16:35 +00:00
return -1;
}
a2_ptr_free = a2_ptr;
}
2006-09-12 15:20:18 +00:00
}
2006-10-24 04:10:12 +00:00
if (ase_awk_str_open (&new, a2_len, run->awk) == ASE_NULL)
2006-09-14 06:40:06 +00:00
{
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-10-24 04:10:12 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-09-14 06:40:06 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_REX)
2006-09-12 15:20:18 +00:00
{
2006-10-24 04:10:12 +00:00
rex = ase_awk_buildrex (run->awk, a0_ptr, a0_len, &run->errnum);
if (rex == ASE_NULL)
2006-09-13 14:16:35 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_str_close (&new);
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-09-13 14:16:35 +00:00
return -1;
}
2006-09-12 15:20:18 +00:00
}
2006-10-24 04:10:12 +00:00
opt = (run->global.ignorecase)? ASE_AWK_REX_IGNORECASE: 0;
2006-09-12 15:20:18 +00:00
cur_ptr = a2_ptr;
cur_len = a2_len;
2006-09-13 14:16:35 +00:00
sub_count = 0;
2006-09-12 15:20:18 +00:00
while (1)
{
2006-09-14 06:40:06 +00:00
if (max_count == 0 || sub_count < max_count)
{
2006-10-24 04:10:12 +00:00
n = ase_awk_matchrex (
2006-10-10 07:02:38 +00:00
run->awk, rex, opt, cur_ptr, cur_len,
&mat_ptr, &mat_len, &run->errnum);
2006-09-14 06:40:06 +00:00
}
else n = 0;
2006-09-12 15:20:18 +00:00
if (n == -1)
{
2006-10-10 07:02:38 +00:00
FREE_A0_REX (run->awk, rex);
2006-10-24 04:10:12 +00:00
ase_awk_str_close (&new);
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-09-12 15:20:18 +00:00
return -1;
}
if (n == 0)
{
/* no more match found */
2006-10-24 04:10:12 +00:00
if (ase_awk_str_ncat (
&new, cur_ptr, cur_len) == (ase_size_t)-1)
2006-09-12 15:20:18 +00:00
{
2006-10-10 07:02:38 +00:00
FREE_A0_REX (run->awk, rex);
2006-10-24 04:10:12 +00:00
ase_awk_str_close (&new);
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-09-12 15:20:18 +00:00
return -1;
}
break;
}
2006-10-24 04:10:12 +00:00
if (ase_awk_str_ncat (
&new, cur_ptr, mat_ptr - cur_ptr) == (ase_size_t)-1)
2006-09-12 15:20:18 +00:00
{
2006-10-10 07:02:38 +00:00
FREE_A0_REX (run->awk, rex);
2006-10-24 04:10:12 +00:00
ase_awk_str_close (&new);
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-09-12 15:20:18 +00:00
return -1;
}
2006-09-14 06:40:06 +00:00
2006-09-16 12:58:38 +00:00
for (i = 0; i < a1_len; i++)
2006-09-12 15:20:18 +00:00
{
2006-09-16 12:58:38 +00:00
if ((i+1) < a1_len &&
2006-10-24 04:10:12 +00:00
a1_ptr[i] == ASE_T('\\') &&
a1_ptr[i+1] == ASE_T('&'))
2006-09-16 12:58:38 +00:00
{
2006-10-24 04:10:12 +00:00
m = ase_awk_str_ccat (&new, ASE_T('&'));
2006-09-16 12:58:38 +00:00
i++;
}
2006-10-24 04:10:12 +00:00
else if (a1_ptr[i] == ASE_T('&'))
2006-09-16 12:58:38 +00:00
{
2006-10-24 04:10:12 +00:00
m = ase_awk_str_ncat (&new, mat_ptr, mat_len);
2006-09-16 12:58:38 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
m = ase_awk_str_ccat (&new, a1_ptr[i]);
2006-09-16 12:58:38 +00:00
}
2006-10-24 04:10:12 +00:00
if (m == (ase_size_t)-1)
2006-09-16 12:58:38 +00:00
{
2006-10-10 07:02:38 +00:00
FREE_A0_REX (run->awk, rex);
2006-10-24 04:10:12 +00:00
ase_awk_str_close (&new);
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-09-16 12:58:38 +00:00
return -1;
}
2006-09-12 15:20:18 +00:00
}
2006-09-13 14:16:35 +00:00
sub_count++;
2006-09-16 12:58:38 +00:00
cur_len = cur_len - ((mat_ptr - cur_ptr) + mat_len);
2006-09-30 17:03:11 +00:00
cur_ptr = mat_ptr + mat_len;
2006-09-12 15:20:18 +00:00
}
2006-10-10 07:02:38 +00:00
FREE_A0_REX (run->awk, rex);
2006-09-12 15:20:18 +00:00
2006-10-02 14:54:32 +00:00
if (sub_count > 0)
2006-09-12 15:20:18 +00:00
{
2006-10-24 04:10:12 +00:00
if (a2 == ASE_NULL)
2006-09-12 15:20:18 +00:00
{
2006-10-24 04:10:12 +00:00
if (ase_awk_setrec (run, 0,
ASE_AWK_STR_BUF(&new), ASE_AWK_STR_LEN(&new)) == -1)
2006-10-02 14:54:32 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_str_close (&new);
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-10-02 14:54:32 +00:00
return -1;
}
2006-09-12 15:20:18 +00:00
}
2006-10-24 04:10:12 +00:00
else if (((ase_awk_val_ref_t*)a2)->id == ASE_AWK_VAL_REF_POS)
2006-09-13 14:16:35 +00:00
{
2006-10-02 14:54:32 +00:00
int n;
2006-10-24 04:10:12 +00:00
n = ase_awk_setrec (
run, (ase_size_t)((ase_awk_val_ref_t*)a2)->adr,
ASE_AWK_STR_BUF(&new), ASE_AWK_STR_LEN(&new));
2006-10-02 14:54:32 +00:00
if (n == -1)
{
2006-10-24 04:10:12 +00:00
ase_awk_str_close (&new);
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-10-02 14:54:32 +00:00
return -1;
}
2006-09-13 14:16:35 +00:00
}
2006-10-02 14:54:32 +00:00
else
{
2006-10-24 04:10:12 +00:00
v = ase_awk_makestrval (run,
ASE_AWK_STR_BUF(&new), ASE_AWK_STR_LEN(&new));
if (v == ASE_NULL)
2006-10-02 14:54:32 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_str_close (&new);
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-10-02 14:54:32 +00:00
return -1;
}
2006-09-13 14:16:35 +00:00
2006-10-24 04:10:12 +00:00
ase_awk_refdownval (run, *a2_ref);
2006-10-02 14:54:32 +00:00
*a2_ref = v;
2006-11-16 11:53:16 +00:00
ase_awk_refupval (run, *a2_ref);
2006-10-02 14:54:32 +00:00
}
2006-09-11 14:29:23 +00:00
}
2006-10-24 04:10:12 +00:00
ase_awk_str_close (&new);
2006-10-10 07:02:38 +00:00
FREE_A_PTRS (run->awk);
2006-09-11 14:29:23 +00:00
2006-09-14 06:40:06 +00:00
#undef FREE_A0_REX
#undef FREE_A_PTRS
2006-09-11 14:29:23 +00:00
2006-10-24 04:10:12 +00:00
v = ase_awk_makeintval (run, sub_count);
if (v == ASE_NULL)
2006-09-13 14:16:35 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-09-13 14:16:35 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
ase_awk_setretval (run, v);
2006-09-11 14:29:23 +00:00
return 0;
}
2006-11-28 04:30:57 +00:00
static int __bfn_gsub (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
2006-10-10 07:02:38 +00:00
{
return __substitute (run, 0);
}
2006-11-28 04:30:57 +00:00
static int __bfn_sub (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
2006-10-10 07:02:38 +00:00
{
return __substitute (run, 1);
}
2006-11-28 04:30:57 +00:00
static int __bfn_match (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
2006-10-18 14:06:47 +00:00
{
2006-10-24 04:10:12 +00:00
ase_size_t nargs;
ase_awk_val_t* a0, * a1;
ase_char_t* str0, * str1;
ase_size_t len0, len1;
ase_long_t idx;
2006-10-18 14:06:47 +00:00
void* rex;
int opt, n;
2006-10-24 04:10:12 +00:00
const ase_char_t* mat_ptr;
ase_size_t mat_len;
2006-10-18 14:06:47 +00:00
2006-10-24 04:10:12 +00:00
nargs = ase_awk_getnargs (run);
2006-10-26 09:31:28 +00:00
ASE_AWK_ASSERT (run->awk, nargs == 2);
2006-10-18 14:06:47 +00:00
2006-10-24 04:10:12 +00:00
a0 = ase_awk_getarg (run, 0);
a1 = ase_awk_getarg (run, 1);
2006-10-18 14:06:47 +00:00
2006-10-24 04:10:12 +00:00
if (a0->type == ASE_AWK_VAL_STR)
2006-10-18 14:06:47 +00:00
{
2006-10-24 04:10:12 +00:00
str0 = ((ase_awk_val_str_t*)a0)->buf;
len0 = ((ase_awk_val_str_t*)a0)->len;
2006-10-18 14:06:47 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
str0 = ase_awk_valtostr (
run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len0);
if (str0 == ASE_NULL) return -1;
2006-10-18 14:06:47 +00:00
}
2006-10-24 04:10:12 +00:00
if (a1->type == ASE_AWK_VAL_REX)
2006-10-18 14:06:47 +00:00
{
2006-10-24 04:10:12 +00:00
rex = ((ase_awk_val_rex_t*)a1)->code;
2006-10-18 14:06:47 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
if (a1->type == ASE_AWK_VAL_STR)
2006-10-18 14:06:47 +00:00
{
2006-10-24 04:10:12 +00:00
str1 = ((ase_awk_val_str_t*)a1)->buf;
len1 = ((ase_awk_val_str_t*)a1)->len;
2006-10-18 14:06:47 +00:00
}
else
{
2006-10-24 04:10:12 +00:00
str1 = ase_awk_valtostr (
run, a1, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len1);
if (str1 == ASE_NULL)
2006-10-18 14:06:47 +00:00
{
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR)
ASE_AWK_FREE (run->awk, str0);
2006-10-18 14:06:47 +00:00
return -1;
}
}
2006-10-24 04:10:12 +00:00
rex = ase_awk_buildrex (run->awk, str1, len1, &run->errnum);
if (rex == ASE_NULL)
2006-10-18 14:06:47 +00:00
{
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR)
ASE_AWK_FREE (run->awk, str0);
2006-10-18 14:06:47 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
if (a1->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str1);
2006-10-18 14:06:47 +00:00
}
2006-10-24 04:10:12 +00:00
opt = (run->global.ignorecase)? ASE_AWK_REX_IGNORECASE: 0;
n = ase_awk_matchrex (
2006-10-18 14:06:47 +00:00
run->awk, rex, opt, str0, len0,
&mat_ptr, &mat_len, &run->errnum);
2006-10-24 04:10:12 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str0);
if (a1->type != ASE_AWK_VAL_REX) ase_awk_freerex (run->awk, rex);
2006-10-18 14:06:47 +00:00
if (n == -1) return -1;
2006-10-24 04:10:12 +00:00
idx = (n == 0)? -1: (ase_long_t)(mat_ptr - str0);
if (ase_awk_getopt(run->awk) & ASE_AWK_STRINDEXONE) idx = idx + 1;
2006-10-18 14:06:47 +00:00
2006-10-24 04:10:12 +00:00
a0 = ase_awk_makeintval (run, idx);
if (a0 == ASE_NULL)
2006-10-18 14:06:47 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-10-18 14:06:47 +00:00
return -1;
}
2006-11-16 11:53:16 +00:00
ase_awk_refupval (run, a0);
2006-10-18 14:06:47 +00:00
2006-10-24 04:10:12 +00:00
a1 = ase_awk_makeintval (run,
((n == 0)? (ase_long_t)-1: (ase_long_t)mat_len));
if (a1 == ASE_NULL)
2006-10-18 14:06:47 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_refdownval (run, a0);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
2006-10-18 14:06:47 +00:00
return -1;
}
2006-11-16 11:53:16 +00:00
ase_awk_refupval (run, a1);
2006-10-18 14:06:47 +00:00
2006-10-24 04:10:12 +00:00
if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_RSTART, a0) == -1)
2006-10-18 14:06:47 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_refdownval (run, a1);
ase_awk_refdownval (run, a0);
2006-10-18 14:06:47 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_RLENGTH, a1) == -1)
2006-10-18 14:06:47 +00:00
{
2006-10-24 04:10:12 +00:00
ase_awk_refdownval (run, a1);
ase_awk_refdownval (run, a0);
2006-10-18 14:06:47 +00:00
return -1;
}
2006-10-24 04:10:12 +00:00
ase_awk_setretval (run, a0);
2006-10-18 14:06:47 +00:00
2006-10-24 04:10:12 +00:00
ase_awk_refdownval (run, a1);
ase_awk_refdownval (run, a0);
2006-10-18 14:06:47 +00:00
return 0;
}
2006-11-28 04:30:57 +00:00
static int __bfn_sprintf (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
2006-11-14 14:54:47 +00:00
{
ase_size_t nargs;
ase_awk_val_t* a0;
ase_char_t* str0, * ptr;
ase_size_t len0, len;
2006-11-16 15:16:25 +00:00
ase_awk_str_t out, fbu;
2006-11-14 14:54:47 +00:00
nargs = ase_awk_getnargs (run);
ASE_AWK_ASSERT (run->awk, nargs > 0);
2006-11-16 15:16:25 +00:00
if (ase_awk_str_open (&out, 256, run->awk) == ASE_NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1;
}
if (ase_awk_str_open (&fbu, 256, run->awk) == ASE_NULL)
{
ase_awk_str_close (&out);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1;
}
2006-11-14 14:54:47 +00:00
a0 = ase_awk_getarg (run, 0);
if (a0->type == ASE_AWK_VAL_STR)
{
str0 = ((ase_awk_val_str_t*)a0)->buf;
len0 = ((ase_awk_val_str_t*)a0)->len;
}
else
{
str0 = ase_awk_valtostr (
run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len0);
2006-11-16 15:16:25 +00:00
if (str0 == ASE_NULL)
{
ase_awk_str_close (&fbu);
ase_awk_str_close (&out);
return -1;
}
2006-11-14 14:54:47 +00:00
}
2006-11-18 15:36:57 +00:00
ptr = ase_awk_format (run,
2006-11-16 15:16:25 +00:00
&out, &fbu, str0, len0, nargs, ASE_NULL, &len);
2006-11-14 14:54:47 +00:00
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str0);
2006-11-16 15:16:25 +00:00
if (ptr == ASE_NULL)
{
ase_awk_str_close (&fbu);
ase_awk_str_close (&out);
return -1;
}
2006-11-14 14:54:47 +00:00
2006-11-16 15:16:25 +00:00
a0 = ase_awk_makestrval_nodup (run, ptr, len);
2006-11-14 14:54:47 +00:00
if (a0 == ASE_NULL)
{
2006-11-16 15:16:25 +00:00
ase_awk_str_close (&fbu);
ase_awk_str_close (&out);
2006-11-14 14:54:47 +00:00
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1;
}
2006-11-16 15:16:25 +00:00
ase_awk_str_close (&fbu);
ase_awk_str_forfeit (&out);
2006-11-14 14:54:47 +00:00
ase_awk_setretval (run, a0);
return 0;
2006-11-13 09:37:00 +00:00
}