*** empty log message ***

This commit is contained in:
hyung-hwan 2006-08-21 14:51:32 +00:00
parent bb7a22e049
commit 2b0bd1eb4f
3 changed files with 98 additions and 23 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: func.c,v 1.24 2006-08-20 15:49:06 bacon Exp $ * $Id: func.c,v 1.25 2006-08-21 14:49:08 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -20,6 +20,7 @@
#endif #endif
static int __bfn_close (xp_awk_t* awk, void* run); static int __bfn_close (xp_awk_t* awk, void* run);
static int __bfn_fflush (xp_awk_t* awk, void* run);
static int __bfn_index (xp_awk_t* awk, void* run); static int __bfn_index (xp_awk_t* awk, void* run);
static int __bfn_length (xp_awk_t* awk, void* run); static int __bfn_length (xp_awk_t* awk, void* run);
static int __bfn_substr (xp_awk_t* awk, void* run); static int __bfn_substr (xp_awk_t* awk, void* run);
@ -32,8 +33,9 @@ static int __bfn_sin (xp_awk_t* awk, void* run);
/* TODO: move it under the awk structure... */ /* TODO: move it under the awk structure... */
static xp_awk_bfn_t __sys_bfn[] = static xp_awk_bfn_t __sys_bfn[] =
{ {
/* ensure that this matches XP_AWK_BNF_XXX in func.h */ /* io functions */
{ XP_T("close"), 5, XP_AWK_EXTIO, 1, 1, XP_NULL, __bfn_close }, { XP_T("close"), 5, XP_AWK_EXTIO, 1, 1, XP_NULL, __bfn_close },
{ XP_T("fflush"), 6, XP_AWK_EXTIO, 0, 1, XP_NULL, __bfn_fflush },
/* string functions */ /* string functions */
{ XP_T("index"), 5, 0, 2, 2, XP_NULL, __bfn_index }, { XP_T("index"), 5, 0, 2, 2, XP_NULL, __bfn_index },
@ -43,6 +45,7 @@ static xp_awk_bfn_t __sys_bfn[] =
{ XP_T("tolower"), 7, 0, 1, 1, XP_NULL, __bfn_tolower }, { XP_T("tolower"), 7, 0, 1, 1, XP_NULL, __bfn_tolower },
{ XP_T("toupper"), 7, 0, 1, 1, XP_NULL, __bfn_toupper }, { XP_T("toupper"), 7, 0, 1, 1, XP_NULL, __bfn_toupper },
/* TODO: remove these two functions */
{ XP_T("system"), 6, 0, 1, 1, XP_NULL, __bfn_system }, { XP_T("system"), 6, 0, 1, 1, XP_NULL, __bfn_system },
{ XP_T("sin"), 3, 0, 1, 1, XP_NULL, __bfn_sin }, { XP_T("sin"), 3, 0, 1, 1, XP_NULL, __bfn_sin },
@ -139,7 +142,6 @@ xp_awk_bfn_t* xp_awk_getbfn (xp_awk_t* awk, const xp_char_t* name)
static int __bfn_close (xp_awk_t* awk, void* run) static int __bfn_close (xp_awk_t* awk, void* run)
{ {
xp_size_t nargs; xp_size_t nargs;
xp_str_t buf;
xp_awk_val_t* v, * a0; xp_awk_val_t* v, * a0;
int errnum, n; int errnum, n;
@ -160,22 +162,12 @@ static int __bfn_close (xp_awk_t* awk, void* run)
} }
else else
{ {
if (xp_str_open (&buf, 256) == XP_NULL) name = xp_awk_valtostr (a0, &errnum, xp_true, XP_NULL, &len);
if (name == XP_NULL)
{ {
xp_awk_seterrnum (run, XP_AWK_ENOMEM);
return -1;
}
if (xp_awk_valtostr (
a0, &errnum, xp_true, &buf, XP_NULL) == XP_NULL)
{
xp_str_close (&buf);
xp_awk_seterrnum (run, errnum); xp_awk_seterrnum (run, errnum);
return -1; return -1;
} }
name = XP_STR_BUF(&buf);
len = XP_STR_LEN(&buf);
} }
if (len == 0) if (len == 0)
@ -188,7 +180,7 @@ static int __bfn_close (xp_awk_t* awk, void* run)
* an empty string for its identification because closeextio * an empty string for its identification because closeextio
* closes any extios that match the name given unlike * closes any extios that match the name given unlike
* closeextio_read or closeextio_write. */ * closeextio_read or closeextio_write. */
if (a0->type != XP_AWK_VAL_STR) xp_str_close (&buf); if (a0->type != XP_AWK_VAL_STR) xp_free (name);
n = -1; n = -1;
/* TODO: need to set ERRNO??? */ /* TODO: need to set ERRNO??? */
goto skip_close; goto skip_close;
@ -200,7 +192,7 @@ static int __bfn_close (xp_awk_t* awk, void* run)
{ {
/* the name contains a null string. /* the name contains a null string.
* make close return -1 */ * make close return -1 */
if (a0->type != XP_AWK_VAL_STR) xp_str_close (&buf); if (a0->type != XP_AWK_VAL_STR) xp_free (name);
n = -1; n = -1;
/* TODO: need to set ERRNO??? */ /* TODO: need to set ERRNO??? */
goto skip_close; goto skip_close;
@ -210,12 +202,12 @@ static int __bfn_close (xp_awk_t* awk, void* run)
n = xp_awk_closeextio (run, name, &errnum); n = xp_awk_closeextio (run, name, &errnum);
if (n == -1 && errnum != XP_AWK_ENOERR) if (n == -1 && errnum != XP_AWK_ENOERR)
{ {
if (a0->type != XP_AWK_VAL_STR) xp_str_close (&buf); if (a0->type != XP_AWK_VAL_STR) xp_free (name);
xp_awk_seterrnum (run, errnum); xp_awk_seterrnum (run, errnum);
return -1; return -1;
} }
if (a0->type != XP_AWK_VAL_STR) xp_str_close (&buf); if (a0->type != XP_AWK_VAL_STR) xp_free (name);
skip_close: skip_close:
v = xp_awk_makeintval (run, n); v = xp_awk_makeintval (run, n);
@ -229,6 +221,66 @@ skip_close:
return 0; return 0;
} }
static int __bfn_fflush (xp_awk_t* awk, void* run)
{
xp_size_t nargs;
xp_awk_val_t* a0;
xp_char_t* str0;
xp_size_t len0;
int errnum, n;
nargs = xp_awk_getnargs (run);
xp_assert (nargs >= 0 && nargs <= 1);
if (nargs == 0)
{
/* flush the console output */
n = 0;
}
else
{
a0 = xp_awk_getarg (run, 0);
if (a0->type == XP_AWK_VAL_STR)
{
str0 = ((xp_awk_val_str_t*)a0)->buf;
len0 = ((xp_awk_val_str_t*)a0)->len;
}
else
{
str0 = xp_awk_valtostr (
a0, &errnum, xp_true, XP_NULL, &len0);
if (str0 == XP_NULL)
{
xp_awk_seterrnum (run, errnum);
return -1;
}
}
if (len0 == 0)
{
/* flush all open files and pipes */
}
else
{
/* flush the given extio */
}
if (a0->type != XP_AWK_VAL_STR) xp_free (str0);
n = 0;
}
a0 = xp_awk_makeintval (run, (xp_long_t)n);
if (a0 == XP_NULL)
{
xp_awk_seterrnum (run, XP_AWK_ENOMEM);
return -1;
}
xp_awk_setretval (run, a0);
return 0;
}
static int __bfn_index (xp_awk_t* awk, void* run) static int __bfn_index (xp_awk_t* awk, void* run)
{ {
xp_size_t nargs; xp_size_t nargs;
@ -275,7 +327,6 @@ static int __bfn_index (xp_awk_t* awk, void* run)
} }
} }
ptr = xp_strxnstr (str0, len0, str1, len1); ptr = xp_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);

24
ase/awk/parse.h Normal file
View File

@ -0,0 +1,24 @@
/*
* $Id: parse.h,v 1.1 2006-08-21 14:51:32 bacon Exp $
*/
#ifndef _XP_AWK_PARSE_H_
#define _XP_AWK_PARSE_H_
#ifndef _XP_AWK_AWK_H_
#error Never include this file directly. Include <xp/awk/awk.h> instead
#endif
#ifdef __cplusplus
extern "C" {
#endif
int xp_awk_putsrcstr (xp_awk_t* awk, const xp_char_t* str);
int xp_awk_putsrcstrx (
xp_awk_t* awk, const xp_char_t* str, xp_size_t len);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.c,v 1.70 2006-08-06 15:02:55 bacon Exp $ * $Id: tree.c,v 1.71 2006-08-21 14:51:32 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -87,10 +87,10 @@ static const xp_char_t* __print_outop_str[] =
}; };
#define PUT_SRCSTR(awk,str) \ #define PUT_SRCSTR(awk,str) \
do { if (xp_awk_putsrcstr (awk, str) == -1) return- 1; } while (0) do { if (xp_awk_putsrcstr (awk, str) == -1) return -1; } while (0)
#define PUT_SRCSTRX(awk,str,len) \ #define PUT_SRCSTRX(awk,str,len) \
do { if (xp_awk_putsrcstrx (awk, str, len) == -1) return- 1; } while (0) do { if (xp_awk_putsrcstrx (awk, str, len) == -1) return -1; } while (0)
#define PRINT_TABS(awk,depth) \ #define PRINT_TABS(awk,depth) \
do { if (__print_tabs(awk,depth) == -1) return -1; } while (0) do { if (__print_tabs(awk,depth) == -1) return -1; } while (0)