*** empty log message ***
This commit is contained in:
		@ -1,5 +1,5 @@
 | 
			
		||||
/* 
 | 
			
		||||
 * $Id: awk.h,v 1.100 2006-08-23 15:41:45 bacon Exp $
 | 
			
		||||
 * $Id: awk.h,v 1.101 2006-08-24 03:30:06 bacon Exp $
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef _XP_AWK_AWK_H_
 | 
			
		||||
@ -293,9 +293,10 @@ int xp_awk_getrunerrnum (xp_awk_t* awk, void* run, int* errnum);
 | 
			
		||||
/* functions to access internal stack structure */
 | 
			
		||||
xp_size_t xp_awk_getnargs (void* run);
 | 
			
		||||
xp_awk_val_t* xp_awk_getarg (void* run, xp_size_t idx);
 | 
			
		||||
void xp_awk_setretval (void* run, xp_awk_val_t* val);
 | 
			
		||||
xp_awk_val_t* xp_awk_getglobal (void* run, xp_size_t idx);
 | 
			
		||||
void xp_awk_setglobal (void* run, xp_size_t idx, xp_awk_val_t* val);
 | 
			
		||||
void xp_awk_seterrnum (void* run, int errnum);
 | 
			
		||||
void xp_awk_setretval (void* run, xp_awk_val_t* val);
 | 
			
		||||
 | 
			
		||||
/* utility functions exported by awk.h */
 | 
			
		||||
xp_long_t xp_awk_strtolong (
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
/*
 | 
			
		||||
 * $Id: extio.c,v 1.31 2006-08-23 15:45:11 bacon Exp $
 | 
			
		||||
 * $Id: extio.c,v 1.32 2006-08-24 03:30:07 bacon Exp $
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <xp/awk/awk_i.h>
 | 
			
		||||
@ -88,7 +88,10 @@ int xp_awk_readextio (
 | 
			
		||||
{
 | 
			
		||||
	xp_awk_extio_t* p = run->extio.chain;
 | 
			
		||||
	xp_awk_io_t handler;
 | 
			
		||||
	int extio_type, extio_mode, extio_mask, n;
 | 
			
		||||
	int extio_type, extio_mode, extio_mask, n, ret;
 | 
			
		||||
	xp_awk_val_t* rs;
 | 
			
		||||
	xp_char_t* rs_ptr;
 | 
			
		||||
	xp_size_t rs_len;
 | 
			
		||||
 | 
			
		||||
	xp_assert (in_type >= 0 && in_type <= xp_countof(__in_type_map));
 | 
			
		||||
	xp_assert (in_type >= 0 && in_type <= xp_countof(__in_mode_map));
 | 
			
		||||
@ -168,9 +171,37 @@ int xp_awk_readextio (
 | 
			
		||||
		if (n == 0) return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* read a line */
 | 
			
		||||
	/* ready to read a line */
 | 
			
		||||
	xp_str_clear (buf);
 | 
			
		||||
 | 
			
		||||
	/* get the record separator */
 | 
			
		||||
	rs = xp_awk_getglobal (run, XP_AWK_GLOBAL_RS);
 | 
			
		||||
	xp_awk_refupval (rs);
 | 
			
		||||
 | 
			
		||||
	if (rs->type == XP_AWK_VAL_NIL)
 | 
			
		||||
	{
 | 
			
		||||
		rs_ptr = XP_NULL;
 | 
			
		||||
		rs_len = 0;
 | 
			
		||||
	}
 | 
			
		||||
	else if (rs->type == XP_AWK_VAL_STR)
 | 
			
		||||
	{
 | 
			
		||||
		rs_ptr = ((xp_awk_val_str_t*)rs)->buf;
 | 
			
		||||
		rs_len = ((xp_awk_val_str_t*)rs)->len;
 | 
			
		||||
	}
 | 
			
		||||
	else 
 | 
			
		||||
	{
 | 
			
		||||
		rs_ptr = xp_awk_valtostr (
 | 
			
		||||
			rs, errnum, xp_true, XP_NULL, &rs_len);
 | 
			
		||||
		if (rs_ptr == XP_NULL)
 | 
			
		||||
		{
 | 
			
		||||
			xp_awk_refdownval (run, rs);
 | 
			
		||||
			return -1;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ret = 1;
 | 
			
		||||
 | 
			
		||||
	/* call the io handler */
 | 
			
		||||
	while (1)
 | 
			
		||||
	{
 | 
			
		||||
		xp_char_t c;
 | 
			
		||||
@ -181,7 +212,7 @@ int xp_awk_readextio (
 | 
			
		||||
 | 
			
		||||
			if (p->in.eof)
 | 
			
		||||
			{
 | 
			
		||||
				if (XP_STR_LEN(buf) == 0) return 0;
 | 
			
		||||
				if (XP_STR_LEN(buf) == 0) ret = 0;
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@ -195,13 +226,14 @@ int xp_awk_readextio (
 | 
			
		||||
					XP_AWK_GLOBAL_ERRNO, xp_awk_val_one);
 | 
			
		||||
 | 
			
		||||
				*errnum = XP_AWK_EIOHANDLER;
 | 
			
		||||
				return -1;
 | 
			
		||||
				ret = -1;
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (n == 0) 
 | 
			
		||||
			{
 | 
			
		||||
				p->in.eof = xp_true;
 | 
			
		||||
				if (XP_STR_LEN(buf) == 0) return 0;
 | 
			
		||||
				if (XP_STR_LEN(buf) == 0) ret = 0;
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@ -210,16 +242,38 @@ int xp_awk_readextio (
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		c = p->in.buf[p->in.pos++];
 | 
			
		||||
		if (c == XP_C('\n')) break; 
 | 
			
		||||
 | 
			
		||||
		if (rs_ptr == XP_NULL)
 | 
			
		||||
		{
 | 
			
		||||
			/* separate by a new line */
 | 
			
		||||
			if (c == XP_C('\n')) break; 
 | 
			
		||||
		}
 | 
			
		||||
		else if (rs_len == 0)
 | 
			
		||||
		{
 | 
			
		||||
			/* TODO: */
 | 
			
		||||
			/* separate by a blank line */
 | 
			
		||||
		}
 | 
			
		||||
		else if (rs_len == 1)
 | 
			
		||||
		{
 | 
			
		||||
			if (c == rs_ptr[0]) break;
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			/* TODO: */
 | 
			
		||||
			/* regular expression */
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (xp_str_ccat (buf, c) == (xp_size_t)-1)
 | 
			
		||||
		{
 | 
			
		||||
			*errnum = XP_AWK_ENOMEM;
 | 
			
		||||
			return -1;
 | 
			
		||||
			ret = -1;
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return 1;
 | 
			
		||||
	if (rs_ptr != XP_NULL && rs->type != XP_AWK_VAL_STR) xp_free (rs_ptr);
 | 
			
		||||
	xp_awk_refdownval (run, rs);
 | 
			
		||||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int xp_awk_writeextio (
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
/*
 | 
			
		||||
 * $Id: func.c,v 1.30 2006-08-23 15:46:03 bacon Exp $
 | 
			
		||||
 * $Id: func.c,v 1.31 2006-08-24 03:30:07 bacon Exp $
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <xp/awk/awk_i.h>
 | 
			
		||||
@ -44,6 +44,7 @@ static xp_awk_bfn_t __sys_bfn[] =
 | 
			
		||||
	{ XP_T("split"),   5, 0,            2,  3,  XP_T("vrv"), __bfn_split },
 | 
			
		||||
	{ XP_T("tolower"), 7, 0,            1,  1,  XP_NULL, __bfn_tolower },
 | 
			
		||||
	{ XP_T("toupper"), 7, 0,            1,  1,  XP_NULL, __bfn_toupper },
 | 
			
		||||
	//{ XP_T("gsub"),    4, 0,            2,  3,  XP_T("vrr"), __bfn_gsub },
 | 
			
		||||
 | 
			
		||||
	/* TODO: remove these two functions */
 | 
			
		||||
	{ XP_T("system"),  6, 0,            1,  1,  XP_NULL, __bfn_system },
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
/*
 | 
			
		||||
 * $Id: run.c,v 1.178 2006-08-23 15:47:28 bacon Exp $
 | 
			
		||||
 * $Id: run.c,v 1.179 2006-08-24 03:30:07 bacon Exp $
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <xp/awk/awk_i.h>
 | 
			
		||||
@ -209,20 +209,15 @@ xp_awk_val_t* xp_awk_getarg (void* run, xp_size_t idx)
 | 
			
		||||
	return STACK_ARG ((xp_awk_run_t*)run, idx);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void xp_awk_setretval (void* run, xp_awk_val_t* val)
 | 
			
		||||
xp_awk_val_t* xp_awk_getglobal (void* run, xp_size_t idx)
 | 
			
		||||
{
 | 
			
		||||
	xp_awk_run_t* r = (xp_awk_run_t*)run;
 | 
			
		||||
	xp_awk_refdownval (r, STACK_RETVAL(r));
 | 
			
		||||
	STACK_RETVAL(r) = val;
 | 
			
		||||
	/* should use the same trick as __run_return_statement */
 | 
			
		||||
	xp_awk_refupval (val); 
 | 
			
		||||
	return STACK_GLOBAL(((xp_awk_run_t*)run),idx);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void xp_awk_setglobal (void* run, xp_size_t idx, xp_awk_val_t* val)
 | 
			
		||||
{
 | 
			
		||||
	xp_awk_run_t* r = (xp_awk_run_t*)run;
 | 
			
		||||
	xp_awk_refdownval (run, STACK_GLOBAL(r,idx));
 | 
			
		||||
	STACK_GLOBAL(r,idx) = val;
 | 
			
		||||
	xp_awk_refdownval (run, STACK_GLOBAL(((xp_awk_run_t*)run),idx));
 | 
			
		||||
	STACK_GLOBAL(((xp_awk_run_t*)run),idx) = val;
 | 
			
		||||
	xp_awk_refupval (val);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -232,6 +227,15 @@ void xp_awk_seterrnum (void* run, int errnum)
 | 
			
		||||
	r->errnum = errnum;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void xp_awk_setretval (void* run, xp_awk_val_t* val)
 | 
			
		||||
{
 | 
			
		||||
	xp_awk_run_t* r = (xp_awk_run_t*)run;
 | 
			
		||||
	xp_awk_refdownval (r, STACK_RETVAL(r));
 | 
			
		||||
	STACK_RETVAL(r) = val;
 | 
			
		||||
	/* should use the same trick as __run_return_statement */
 | 
			
		||||
	xp_awk_refupval (val); 
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int xp_awk_run (xp_awk_t* awk, xp_awk_runios_t* runios, xp_awk_runcbs_t* runcbs)
 | 
			
		||||
{
 | 
			
		||||
	xp_awk_run_t* run;
 | 
			
		||||
@ -4480,7 +4484,6 @@ static int __read_record (xp_awk_run_t* run)
 | 
			
		||||
 | 
			
		||||
	__clear_record (run, xp_false);
 | 
			
		||||
 | 
			
		||||
	/*TODO: use RS */
 | 
			
		||||
	n = xp_awk_readextio (
 | 
			
		||||
		run, XP_AWK_IN_CONSOLE, 
 | 
			
		||||
		XP_T(""), &run->inrec.line, &errnum);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								ase/test/awk/t31.awk
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								ase/test/awk/t31.awk
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
			
		||||
BEGIN { /*RS="";*/ }
 | 
			
		||||
{ print $0; }
 | 
			
		||||
		Reference in New Issue
	
	Block a user