*** empty log message ***

This commit is contained in:
hyung-hwan 2006-07-13 15:43:39 +00:00
parent e1d5b43bae
commit b6c7322571
8 changed files with 86 additions and 38 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.57 2006-06-27 10:53:04 bacon Exp $
* $Id: awk.c,v 1.58 2006-07-13 15:43:39 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -89,6 +89,9 @@ xp_awk_t* xp_awk_open (void)
for (i = 0; i < xp_countof(awk->extio); i++) awk->extio[i] = XP_NULL;
awk->bfn.sys = XP_NULL;
awk->bfn.user = XP_NULL;
return awk;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: awk_i.h,v 1.29 2006-07-07 09:48:23 bacon Exp $
* $Id: awk_i.h,v 1.30 2006-07-13 15:43:39 bacon Exp $
*/
#ifndef _XP_AWK_AWKI_H_
@ -129,6 +129,13 @@ struct xp_awk_t
xp_size_t column;
} token;
/* builtin functions */
struct
{
xp_awk_bfn_t* sys;
xp_awk_bfn_t* user;
} bfn;
/* housekeeping */
int errnum;
};

View File

@ -1,5 +1,5 @@
/*
* $Id: func.c,v 1.7 2006-07-13 03:10:35 bacon Exp $
* $Id: func.c,v 1.8 2006-07-13 15:43:39 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -14,25 +14,37 @@
static int __bfn_close (void* run);
/* TODO: move it under the awk structure... */
static xp_awk_bfn_t __bfn[] =
static xp_awk_bfn_t __sys_bfn[] =
{
{ XP_T("system"), (1 << 5), 1, 1, XP_NULL },
{ XP_T("close"), XP_AWK_EXTIO, 1, 1, __bfn_close },
{ XP_NULL, 0, 0, 0, XP_NULL }
};
static xp_awk_bfn_t* __usr_bfn = XP_NULL;
xp_awk_bfn_t* xp_awk_addbfn (
xp_awk_t* awk, const xp_char_t* name, int when_valid,
xp_size_t min_args, xp_size_t max_args, int (*handler)(void*))
{
/* TODO */
return XP_NULL;
}
xp_awk_bfn_t* xp_awk_getbfn (xp_awk_t* awk, const xp_char_t* name)
{
xp_awk_bfn_t* p;
for (p = __bfn; p->name != XP_NULL; p++)
for (p = __sys_bfn; p->name != XP_NULL; p++)
{
if (p->valid != 0 &&
(awk->opt.parse & p->valid) == 0) continue;
if (xp_strcmp (p->name, name) == 0) return p;
}
/* TODO: */
for (p = awk->bfn.user; p != XP_NULL; p = p->next)
{
if (p->valid != 0 &&
(awk->opt.parse & p->valid) == 0) continue;

View File

@ -1,5 +1,5 @@
/*
* $Id: func.h,v 1.3 2006-06-21 15:37:51 bacon Exp $
* $Id: func.h,v 1.4 2006-07-13 15:43:39 bacon Exp $
*/
#ifndef _XP_AWK_FUNC_H_
@ -19,6 +19,8 @@ struct xp_awk_bfn_t
xp_size_t min_args;
xp_size_t max_args;
int (*handler) (void* run);
xp_awk_bfn_t* next;
};
#ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.132 2006-07-13 03:10:35 bacon Exp $
* $Id: run.c,v 1.133 2006-07-13 15:43:39 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -1772,6 +1772,8 @@ static xp_awk_val_t* __do_assignment_pos (
}
xp_free (str);
/* TODO: consider if "val" of a non-string type should be
* converted into a string value */
xp_awk_refdownval (run, run->inrec.d0);
run->inrec.d0 = val;
xp_awk_refupval (val);
@ -3758,8 +3760,10 @@ static void __clear_record (xp_awk_run_t* run, xp_bool_t noline)
static int __recomp_record_fields (xp_awk_run_t* run,
xp_size_t lv, xp_char_t* str, xp_size_t len, int* errnum)
{
xp_size_t max, i, nflds;
xp_awk_val_t* v;
xp_char_t* ofsp = XP_NULL, * ofs;
xp_size_t ofs_len;
xp_size_t max, i, nflds;
xp_assert (lv > 0);
max = (lv > run->inrec.nflds)? lv: run->inrec.nflds;
@ -3769,7 +3773,11 @@ static int __recomp_record_fields (xp_awk_run_t* run,
{
void* tmp = xp_realloc (
run->inrec.flds, xp_sizeof(*run->inrec.flds) * max);
if (tmp == XP_NULL) PANIC_I (run, XP_AWK_ENOMEM);
if (tmp == XP_NULL)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
run->inrec.flds = tmp;
run->inrec.maxflds = max;
@ -3779,14 +3787,33 @@ static int __recomp_record_fields (xp_awk_run_t* run,
xp_str_clear (&run->inrec.line);
if (max > 1)
{
v = STACK_GLOBAL(run, XP_AWK_GLOBAL_OFS);
if (v != xp_awk_val_nil)
{
ofsp = xp_awk_valtostr (v, errnum, XP_NULL, &ofs_len);
if (ofsp == XP_NULL) return -1;
ofs = ofsp;
}
else
{
/* OFS not set */
ofs = XP_T(" ");
ofs_len = 1;
}
}
for (i = 0; i < max; i++)
{
if (i > 0)
{
/* TODO: use OFS */
if (xp_str_ccat (
&run->inrec.line, XP_T(' ')) == (xp_size_t)-1)
if (xp_str_ncat (
&run->inrec.line, ofs, ofs_len) == (xp_size_t)-1)
{
if (ofsp != XP_NULL) xp_free (ofsp);
*errnum = XP_AWK_ENOMEM;
return -1;
}
@ -3804,6 +3831,7 @@ static int __recomp_record_fields (xp_awk_run_t* run,
if (xp_str_ncat (
&run->inrec.line, str, len) == (xp_size_t)-1)
{
if (ofsp != XP_NULL) xp_free (ofsp);
*errnum = XP_AWK_ENOMEM;
return -1;
}
@ -3811,6 +3839,7 @@ static int __recomp_record_fields (xp_awk_run_t* run,
tmp = xp_awk_makestrval (str,len);
if (tmp == XP_NULL)
{
if (ofsp != XP_NULL) xp_free (ofsp);
*errnum = XP_AWK_ENOMEM;
return -1;
}
@ -3831,10 +3860,14 @@ static int __recomp_record_fields (xp_awk_run_t* run,
if (xp_str_cat (
&run->inrec.line, XP_T("")) == (xp_size_t)-1)
{
if (ofsp != XP_NULL) xp_free (ofsp);
*errnum = XP_AWK_ENOMEM;
return -1;
}
/* xp_awk_refdownval should not be called over
* run->inrec.flds[i].val as it is not initialized
* to any valid values */
/*xp_awk_refdownval (run, run->inrec.flds[i].val);*/
run->inrec.flds[i].val = xp_awk_val_zls;
xp_awk_refupval (xp_awk_val_zls);
@ -3854,18 +3887,26 @@ static int __recomp_record_fields (xp_awk_run_t* run,
if (xp_str_ncat (&run->inrec.line,
tmp->buf, tmp->len) == (xp_size_t)-1)
{
if (ofsp != XP_NULL) xp_free (ofsp);
*errnum = XP_AWK_ENOMEM;
return -1;
}
}
}
if (ofsp != XP_NULL) xp_free (ofsp);
v = STACK_GLOBAL(run, XP_AWK_GLOBAL_NF);
xp_assert (v->type == XP_AWK_VAL_INT);
if (((xp_awk_val_int_t*)v)->val != max)
{
v = xp_awk_makeintval (run, (xp_long_t)max);
if (v == XP_NULL) PANIC_I (run, XP_AWK_ENOMEM);
if (v == XP_NULL)
{
*errnum = XP_AWK_ENOMEM;
return -1;
}
xp_awk_setglobal (run, XP_AWK_GLOBAL_NF, v);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.h,v 1.57 2006-07-01 16:07:06 bacon Exp $
* $Id: tree.h,v 1.58 2006-07-13 15:43:39 bacon Exp $
*/
#ifndef _XP_AWK_TREE_H_
@ -81,6 +81,7 @@ enum
XP_AWK_OUT_CONSOLE
};
/* afn (awk function defined with the keyword function) */
typedef struct xp_awk_afn_t xp_awk_afn_t;
typedef struct xp_awk_nde_t xp_awk_nde_t;

View File

@ -1,24 +1,5 @@
/*
{
print "1111111111111";
}
{
print "22222222222222";
next;
}
{
print "33333333333333333";
}
END
{
print "\a";
}
*/
global x, y;
{
print "NF = " NF;
for (i = 0; i < 10; i++)
@ -33,6 +14,7 @@ global x, y;
//$3 = $2;
//$2 = $2;
OFS["1234"]=":";
$20 = 10;
print $0;
print "--------------------";

View File

@ -1 +1 @@
{ $0=" "; /*print NF;*/ print "a" $0 "b"; x = $1; }
{ $0=" "; print NF; print "a" $0 "b"; x = $1; }