*** empty log message ***
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c,v 1.99 2006-12-15 14:58:14 bacon Exp $
|
||||
* $Id: awk.c,v 1.100 2006-12-16 14:43:49 bacon Exp $
|
||||
*/
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
@ -116,7 +116,6 @@ ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns, int* errnum)
|
||||
awk->errnum = ASE_AWK_ENOERR;
|
||||
|
||||
awk->parse.nlocals_max = 0;
|
||||
awk->parse.nl_semicolon = 0;
|
||||
|
||||
awk->tree.nglobals = 0;
|
||||
awk->tree.nbglobals = 0;
|
||||
@ -126,7 +125,9 @@ ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns, int* errnum)
|
||||
awk->tree.chain_tail = ASE_NULL;
|
||||
awk->tree.chain_size = 0;
|
||||
|
||||
awk->token.prev = 0;
|
||||
awk->token.prev.type = 0;
|
||||
awk->token.prev.line = 0;
|
||||
awk->token.prev.column = 0;
|
||||
awk->token.type = 0;
|
||||
awk->token.line = 0;
|
||||
awk->token.column = 0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h,v 1.166 2006-12-15 14:58:14 bacon Exp $
|
||||
* $Id: awk.h,v 1.167 2006-12-16 14:43:50 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ASE_AWK_AWK_H_
|
||||
@ -126,9 +126,9 @@ struct ase_awk_runios_t
|
||||
struct ase_awk_runcbs_t
|
||||
{
|
||||
void (*on_start) (
|
||||
ase_awk_t* awk, void* handle, void* custom_data);
|
||||
ase_awk_t* awk, ase_awk_run_t* run, void* custom_data);
|
||||
void (*on_end) (
|
||||
ase_awk_t* awk, void* handle, int errnum, void* custom_data);
|
||||
ase_awk_t* awk, ase_awk_run_t* run, int errnum, void* custom_data);
|
||||
void* custom_data;
|
||||
};
|
||||
|
||||
@ -439,8 +439,12 @@ int ase_awk_setofilename (
|
||||
|
||||
ase_awk_t* ase_awk_getrunawk (ase_awk_run_t* awk);
|
||||
void* ase_awk_getruncustomdata (ase_awk_run_t* awk);
|
||||
|
||||
/* functions to manipulate the run-time error */
|
||||
int ase_awk_getrunerrnum (ase_awk_run_t* run);
|
||||
const ase_char_t* ase_awk_getrunerrmsg (ase_awk_run_t* run);
|
||||
void ase_awk_setrunerrnum (ase_awk_run_t* run, int errnum);
|
||||
void ase_awk_setrunerrmsg (ase_awk_run_t* run, const ase_char_t* msg);
|
||||
|
||||
/* functions to manipulate built-in functions */
|
||||
void* ase_awk_addbfn (
|
||||
@ -485,7 +489,10 @@ ase_char_t* ase_awk_strxdup2 (
|
||||
|
||||
ase_size_t ase_awk_strlen (const ase_char_t* str);
|
||||
ase_size_t ase_awk_strcpy (ase_char_t* buf, const ase_char_t* str);
|
||||
ase_size_t ase_awk_strncpy (ase_char_t* buf, const ase_char_t* str, ase_size_t len);
|
||||
ase_size_t ase_awk_strxcpy (
|
||||
ase_char_t* buf, ase_size_t bsz, const ase_char_t* str);
|
||||
ase_size_t ase_awk_strncpy (
|
||||
ase_char_t* buf, const ase_char_t* str, ase_size_t len);
|
||||
int ase_awk_strcmp (const ase_char_t* s1, const ase_char_t* s2);
|
||||
|
||||
int ase_awk_strxncmp (
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk_i.h,v 1.90 2006-12-13 14:13:07 bacon Exp $
|
||||
* $Id: awk_i.h,v 1.91 2006-12-16 14:43:50 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ASE_AWK_AWKI_H_
|
||||
@ -135,8 +135,6 @@ struct ase_awk_t
|
||||
ase_awk_tab_t params;
|
||||
ase_size_t nlocals_max;
|
||||
|
||||
int nl_semicolon;
|
||||
|
||||
ase_awk_nde_t* (*parse_block) (ase_awk_t*,ase_bool_t);
|
||||
} parse;
|
||||
|
||||
@ -166,7 +164,13 @@ struct ase_awk_t
|
||||
/* token */
|
||||
struct
|
||||
{
|
||||
int prev;
|
||||
struct
|
||||
{
|
||||
int type;
|
||||
ase_size_t line;
|
||||
ase_size_t column;
|
||||
} prev;
|
||||
|
||||
int type;
|
||||
ase_awk_str_t name;
|
||||
ase_size_t line;
|
||||
@ -325,6 +329,8 @@ struct ase_awk_run_t
|
||||
} depth;
|
||||
|
||||
int errnum;
|
||||
ase_char_t errmsg[256];
|
||||
|
||||
void* custom_data;
|
||||
ase_awk_t* awk;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: jni.c,v 1.41 2006-12-15 14:58:15 bacon Exp $
|
||||
* $Id: jni.c,v 1.42 2006-12-16 14:43:50 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@ -329,8 +329,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj)
|
||||
except = (*env)->FindClass (env, CLASS_EXCEPTION);
|
||||
if (except == NULL) return;
|
||||
|
||||
n = snprintf (msg, sizeof(msg), "parse error at line %d: %S",
|
||||
ase_awk_getsrcline(awk),
|
||||
n = snprintf (msg, sizeof(msg),
|
||||
"parse error at line %d: %S",
|
||||
ase_awk_getsrcline(awk),
|
||||
ase_awk_geterrstr(ase_awk_geterrnum(awk)));
|
||||
if (n < 0 || n >= sizeof(msg)) msg[sizeof(msg)-1] = '\0';
|
||||
|
||||
|
@ -42,9 +42,6 @@ lib: $(C_OBJS)
|
||||
jni: lib $(JNI_OBJS) $(JAVA_OBJS)
|
||||
$(LD) $(LDFLAGS) $(STARTUP) $(JNI_OBJS),$(OUT).dll,,$(JNI_LIBS),jni.def,
|
||||
|
||||
ada:
|
||||
gnatmake -I.. ase-awk
|
||||
|
||||
clean:
|
||||
-del $(OBJS) $(OUT).lib $(OUT).dll *.obj *.class
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: misc.c,v 1.46 2006-12-13 14:16:12 bacon Exp $
|
||||
* $Id: misc.c,v 1.47 2006-12-16 14:43:50 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
@ -670,7 +670,25 @@ ase_size_t ase_awk_strcpy (ase_char_t* buf, const ase_char_t* str)
|
||||
return buf - org - 1;
|
||||
}
|
||||
|
||||
ase_size_t ase_awk_strncpy (ase_char_t* buf, const ase_char_t* str, ase_size_t len)
|
||||
ase_size_t ase_awk_strxcpy (
|
||||
ase_char_t* buf, ase_size_t bsz, const ase_char_t* str)
|
||||
{
|
||||
ase_char_t* p, * p2;
|
||||
|
||||
p = buf; p2 = buf + bsz - 1;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (*str == ASE_T('\0')) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
if (bsz > 0) *p = ASE_T('\0');
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
ase_size_t ase_awk_strncpy (
|
||||
ase_char_t* buf, const ase_char_t* str, ase_size_t len)
|
||||
{
|
||||
const ase_char_t* end = str + len;
|
||||
while (str < end) *buf++ = *str++;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parse.c,v 1.222 2006-12-15 14:58:15 bacon Exp $
|
||||
* $Id: parse.c,v 1.223 2006-12-16 14:43:50 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
@ -300,11 +300,15 @@ static struct __bvent __bvtab[] =
|
||||
c = (awk)->src.lex.curc; \
|
||||
} while(0)
|
||||
|
||||
/*
|
||||
#define SET_TOKEN_TYPE(awk,code) \
|
||||
do { \
|
||||
(awk)->token.prev = (awk)->token.type; \
|
||||
(awk)->token.prev.type = (awk)->token.type; \
|
||||
(awk)->token.type = (code); \
|
||||
} while (0);
|
||||
} while (0)
|
||||
*/
|
||||
#define SET_TOKEN_TYPE(awk,code) \
|
||||
do { (awk)->token.type = (code); } while (0)
|
||||
|
||||
#define ADD_TOKEN_CHAR(awk,c) \
|
||||
do { \
|
||||
@ -890,7 +894,8 @@ static ase_awk_chain_t* __parse_pattern_block (
|
||||
if (nde == ASE_NULL) return ASE_NULL;
|
||||
}
|
||||
|
||||
chain = (ase_awk_chain_t*) ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_chain_t));
|
||||
chain = (ase_awk_chain_t*)
|
||||
ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_chain_t));
|
||||
if (chain == ASE_NULL)
|
||||
{
|
||||
ase_awk_clrpt (awk, nde);
|
||||
@ -998,7 +1003,8 @@ static ase_awk_nde_t* __parse_block (ase_awk_t* awk, ase_bool_t is_top)
|
||||
curr = nde;
|
||||
}
|
||||
|
||||
block = (ase_awk_nde_blk_t*) ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_blk_t));
|
||||
block = (ase_awk_nde_blk_t*)
|
||||
ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_blk_t));
|
||||
if (block == ASE_NULL)
|
||||
{
|
||||
ase_awk_tab_remove (
|
||||
@ -1018,6 +1024,7 @@ static ase_awk_nde_t* __parse_block (ase_awk_t* awk, ase_bool_t is_top)
|
||||
/* if (head == ASE_NULL) tmp = 0; */
|
||||
|
||||
block->type = ASE_AWK_NDE_BLK;
|
||||
//block->line =
|
||||
block->next = ASE_NULL;
|
||||
block->body = head;
|
||||
|
||||
@ -1252,11 +1259,22 @@ static ase_awk_nde_t* __parse_statement (ase_awk_t* awk)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the statement id held in awk->parse.id.stmnt denotes
|
||||
* the token id of the statement currently being parsed.
|
||||
* the current statement id is saved here because the
|
||||
* statement id can be changed in __parse_statement_nb.
|
||||
* it will, in turn, call __parse_statement which will
|
||||
* eventually change the statement id. */
|
||||
int old_id = awk->parse.id.stmnt;
|
||||
|
||||
/* set the current statement id */
|
||||
awk->parse.id.stmnt = awk->token.type;
|
||||
|
||||
/* proceed parsing the statement */
|
||||
nde = __parse_statement_nb (awk);
|
||||
|
||||
/* restore the statement id saved previously */
|
||||
awk->parse.id.stmnt = old_id;
|
||||
awk->parse.nl_semicolon = 0;
|
||||
}
|
||||
|
||||
return nde;
|
||||
@ -1293,7 +1311,6 @@ static ase_awk_nde_t* __parse_statement_nb (ase_awk_t* awk)
|
||||
return nde;
|
||||
}
|
||||
|
||||
awk->parse.nl_semicolon = 1;
|
||||
/* keywords that require a terminating semicolon */
|
||||
if (MATCH(awk,TOKEN_DO))
|
||||
{
|
||||
@ -1360,8 +1377,6 @@ awk->parse.nl_semicolon = 1;
|
||||
nde = __parse_expression(awk);
|
||||
}
|
||||
|
||||
/* TODO: newline ... */
|
||||
awk->parse.nl_semicolon = 0;
|
||||
if (nde == ASE_NULL) return ASE_NULL;
|
||||
|
||||
/* check if a statement ends with a semicolon */
|
||||
@ -2191,6 +2206,7 @@ static ase_awk_nde_t* __parse_primary (ase_awk_t* awk)
|
||||
/* the regular expression is tokenized here because
|
||||
* of the context-sensitivity of the slash symbol */
|
||||
SET_TOKEN_TYPE (awk, TOKEN_REX);
|
||||
|
||||
ase_awk_str_clear (&awk->token.name);
|
||||
if (__get_rexstr (awk) == -1) return ASE_NULL;
|
||||
ASE_AWK_ASSERT (awk, MATCH(awk,TOKEN_REX));
|
||||
@ -2203,8 +2219,7 @@ static ase_awk_nde_t* __parse_primary (ase_awk_t* awk)
|
||||
nde->next = ASE_NULL;
|
||||
|
||||
nde->len = ASE_AWK_STR_LEN(&awk->token.name);
|
||||
nde->buf = ase_awk_strxdup (
|
||||
awk,
|
||||
nde->buf = ase_awk_strxdup (awk,
|
||||
ASE_AWK_STR_BUF(&awk->token.name),
|
||||
ASE_AWK_STR_LEN(&awk->token.name));
|
||||
if (nde->buf == ASE_NULL)
|
||||
@ -2213,8 +2228,7 @@ static ase_awk_nde_t* __parse_primary (ase_awk_t* awk)
|
||||
PANIC (awk, ASE_AWK_ENOMEM);
|
||||
}
|
||||
|
||||
nde->code = ase_awk_buildrex (
|
||||
awk,
|
||||
nde->code = ase_awk_buildrex (awk,
|
||||
ASE_AWK_STR_BUF(&awk->token.name),
|
||||
ASE_AWK_STR_LEN(&awk->token.name),
|
||||
&errnum);
|
||||
@ -3282,8 +3296,8 @@ static ase_awk_nde_t* __parse_print (ase_awk_t* awk, int type)
|
||||
}
|
||||
|
||||
/* print 1 > 2 would print 1 to the file named 2.
|
||||
* print (1 > 2) would print (1 > 2) in the console */
|
||||
if (awk->token.prev != TOKEN_RPAREN &&
|
||||
* print (1 > 2) would print (1 > 2) on the console */
|
||||
if (awk->token.prev.type != TOKEN_RPAREN &&
|
||||
args_tail->type == ASE_AWK_NDE_EXP_BIN)
|
||||
{
|
||||
ase_awk_nde_exp_t* ep = (ase_awk_nde_exp_t*)args_tail;
|
||||
@ -3430,6 +3444,11 @@ static int __get_token (ase_awk_t* awk)
|
||||
int n;
|
||||
|
||||
line = awk->token.line;
|
||||
|
||||
awk->token.prev.type = awk->token.type;
|
||||
awk->token.prev.line = awk->token.line;
|
||||
awk->token.prev.column = awk->token.column;
|
||||
|
||||
do
|
||||
{
|
||||
if (__skip_spaces(awk) == -1) return -1;
|
||||
@ -3840,8 +3859,7 @@ static int __get_token (ase_awk_t* awk)
|
||||
ADD_TOKEN_CHAR (awk, c);
|
||||
GET_CHAR (awk);
|
||||
}
|
||||
else if (c == ASE_T(';') ||
|
||||
(c == ASE_T('\n') && (awk->option & ASE_AWK_NEWLINE)))
|
||||
else if (c == ASE_T(';'))
|
||||
{
|
||||
/* TODO: more check on the newline terminator... */
|
||||
SET_TOKEN_TYPE (awk, TOKEN_SEMICOLON);
|
||||
@ -4206,16 +4224,7 @@ static int __unget_char (ase_awk_t* awk, ase_cint_t c)
|
||||
static int __skip_spaces (ase_awk_t* awk)
|
||||
{
|
||||
ase_cint_t c = awk->src.lex.curc;
|
||||
|
||||
if (awk->option & ASE_AWK_NEWLINE && awk->parse.nl_semicolon)
|
||||
{
|
||||
while (c != ASE_T('\n') &&
|
||||
ASE_AWK_ISSPACE (awk, c)) GET_CHAR_TO (awk, c);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (ASE_AWK_ISSPACE (awk, c)) GET_CHAR_TO (awk, c);
|
||||
}
|
||||
while (ASE_AWK_ISSPACE (awk, c)) GET_CHAR_TO (awk, c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.c,v 1.300 2006-12-13 14:15:24 bacon Exp $
|
||||
* $Id: run.c,v 1.301 2006-12-16 14:43:51 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
@ -547,9 +547,23 @@ int ase_awk_getrunerrnum (ase_awk_run_t* run)
|
||||
return run->errnum;
|
||||
}
|
||||
|
||||
const ase_char_t* ase_awk_getrunerrmsg (ase_awk_run_t* run)
|
||||
{
|
||||
if (run->errmsg[0] == ASE_T('\0'))
|
||||
return ase_awk_geterrstr (run->errnum);
|
||||
|
||||
return run->errmsg;
|
||||
}
|
||||
|
||||
void ase_awk_setrunerrnum (ase_awk_run_t* run, int errnum)
|
||||
{
|
||||
run->errnum = errnum;
|
||||
run->errmsg[0] = ASE_T('\0');
|
||||
}
|
||||
|
||||
void ase_awk_setrunerrmsg (ase_awk_run_t* run, const ase_char_t* msg)
|
||||
{
|
||||
ase_awk_strxcpy (run->errmsg, ASE_COUNTOF(run->errmsg), msg);
|
||||
}
|
||||
|
||||
int ase_awk_run (ase_awk_t* awk,
|
||||
@ -562,65 +576,82 @@ int ase_awk_run (ase_awk_t* awk,
|
||||
ase_awk_run_t* run;
|
||||
int n, errnum;
|
||||
|
||||
/* clear the awk error code */
|
||||
awk->errnum = ASE_AWK_ENOERR;
|
||||
|
||||
/* check if the code has ever been parsed */
|
||||
if (awk->tree.nglobals == 0 &&
|
||||
awk->tree.begin == ASE_NULL &&
|
||||
awk->tree.end == ASE_NULL &&
|
||||
awk->tree.chain_size == 0 &&
|
||||
ase_awk_map_getsize(&awk->tree.afns) == 0)
|
||||
{
|
||||
/* the code has not been parsed. deny the run */
|
||||
/* if not, deny the run */
|
||||
awk->errnum = ASE_AWK_EACCES;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* allocate the storage for the run object */
|
||||
run = (ase_awk_run_t*) ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_run_t));
|
||||
if (run == ASE_NULL)
|
||||
{
|
||||
/* if it fails, the failure is reported thru
|
||||
* the awk object */
|
||||
awk->errnum = ASE_AWK_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* clear the run object space */
|
||||
ASE_AWK_MEMSET (awk, run, 0, ASE_SIZEOF(ase_awk_run_t));
|
||||
|
||||
/* add the run object to the awk object */
|
||||
__add_run (awk, run);
|
||||
|
||||
/* initialize the run object */
|
||||
if (__init_run (run, awk, runios, custom_data, &errnum) == -1)
|
||||
{
|
||||
/* if it fails, the failure is still reported thru
|
||||
* the awk object */
|
||||
awk->errnum = errnum;
|
||||
__del_run (awk, run);
|
||||
|
||||
ASE_AWK_FREE (awk, run);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (runcbs != ASE_NULL && runcbs->on_start != ASE_NULL)
|
||||
{
|
||||
runcbs->on_start (awk, run, runcbs->custom_data);
|
||||
}
|
||||
/* clear the run error code */
|
||||
run->errnum = ASE_AWK_ENOERR;
|
||||
|
||||
/* execute the start callback if it exists */
|
||||
if (runcbs != ASE_NULL && runcbs->on_start != ASE_NULL)
|
||||
runcbs->on_start (awk, run, runcbs->custom_data);
|
||||
|
||||
/* enter the main run loop */
|
||||
n = __run_main (run, main, runarg);
|
||||
if (n == -1)
|
||||
{
|
||||
/* if no callback is specified, awk's error number
|
||||
* is updated with the run's error number */
|
||||
awk->errnum = (runcbs == ASE_NULL)? run->errnum: ASE_AWK_ERUNTIME;
|
||||
awk->errnum = (runcbs == ASE_NULL)?
|
||||
run->errnum: ASE_AWK_ERUNTIME;
|
||||
}
|
||||
|
||||
/* the run loop ended. execute the end callback if it exists */
|
||||
if (runcbs != ASE_NULL && runcbs->on_end != ASE_NULL)
|
||||
{
|
||||
runcbs->on_end (awk, run,
|
||||
((n == -1)? run->errnum: ASE_AWK_ENOERR),
|
||||
runcbs->custom_data);
|
||||
|
||||
/* when using callbacks, the function always returns 0 after
|
||||
* the start callbacks has been triggered */
|
||||
/* when using callbacks, this function always returns 0
|
||||
* after the start callbacks has been triggered */
|
||||
n = 0;
|
||||
}
|
||||
|
||||
|
||||
/* uninitialize the run object */
|
||||
__deinit_run (run);
|
||||
__del_run (awk, run);
|
||||
|
||||
ASE_AWK_FREE (awk, run);
|
||||
return n;
|
||||
}
|
||||
@ -2441,10 +2472,12 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
(nde->out_type == ASE_AWK_OUT_FILE_APPEND && nde->out != ASE_NULL) ||
|
||||
(nde->out_type == ASE_AWK_OUT_CONSOLE && nde->out == ASE_NULL));
|
||||
|
||||
/* check if destination has been specified. */
|
||||
if (nde->out != ASE_NULL)
|
||||
{
|
||||
ase_size_t len;
|
||||
|
||||
/* if so, resolve the destination name */
|
||||
v = __eval_expression (run, nde->out);
|
||||
if (v == ASE_NULL) return -1;
|
||||
|
||||
@ -2454,42 +2487,42 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
if (out == ASE_NULL)
|
||||
{
|
||||
ase_awk_refdownval (run, v);
|
||||
//ase_awk_setrunerrline (nde->line);
|
||||
return -1;
|
||||
}
|
||||
ase_awk_refdownval (run, v);
|
||||
|
||||
if (len <= 0)
|
||||
{
|
||||
/* the output destination name is empty. */
|
||||
/* if the destination name is empty, it skips the
|
||||
* writing and flags an error and ERRNO */
|
||||
ASE_AWK_FREE (run->awk, out);
|
||||
n = -1;
|
||||
ase_awk_setglobal (run, ASE_AWK_GLOBAL_ERRNO, ase_awk_val_negone);
|
||||
goto skip_write;
|
||||
}
|
||||
|
||||
/* it needs to check if the destination name contains
|
||||
* any invalid characters to the underlying system */
|
||||
while (len > 0)
|
||||
{
|
||||
if (out[--len] == ASE_T('\0'))
|
||||
{
|
||||
/* the output destination name contains a null
|
||||
* character. */
|
||||
/* if so, the error is flagged thru ERRNO */
|
||||
ASE_AWK_FREE (run->awk, out);
|
||||
n = -1;
|
||||
ase_awk_setglobal (run, ASE_AWK_GLOBAL_ERRNO, ase_awk_val_negone);
|
||||
goto skip_write;
|
||||
/* TODO: how to handle error???
|
||||
* make print return -1??? not possible.
|
||||
* throw an exception??
|
||||
* set ERRNO or what??? this seems most
|
||||
* reasonable. or can it have a global
|
||||
* flag variable for print/printf such
|
||||
* as PRINT_ERRNO? */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* transforms the destination to suit the usage with extio */
|
||||
dst = (out == ASE_NULL)? ASE_T(""): out;
|
||||
|
||||
/* check if print is followed by any arguments */
|
||||
if (nde->args == ASE_NULL)
|
||||
{
|
||||
/* if it doesn't have any arguments, print the entire
|
||||
* input record */
|
||||
n = ase_awk_writeextio_str (
|
||||
run, nde->out_type, dst,
|
||||
ASE_AWK_STR_BUF(&run->inrec.line),
|
||||
@ -2497,6 +2530,7 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
if (n < 0 && run->errnum != ASE_AWK_EIOHANDLER)
|
||||
{
|
||||
if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out);
|
||||
//ase_awk_setrunerrline (nde->line);
|
||||
return -1;
|
||||
}
|
||||
/* TODO: how to handle n == -1 && errnum == ASE_AWK_EIOHANDLER.
|
||||
@ -2504,6 +2538,8 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if it has any arguments, print the arguments separated by
|
||||
* the value OFS */
|
||||
ase_awk_nde_t* head, * np;
|
||||
|
||||
if (nde->args->type == ASE_AWK_NDE_GRP)
|
||||
@ -2525,6 +2561,7 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
if (n < 0 && run->errnum != ASE_AWK_EIOHANDLER)
|
||||
{
|
||||
if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out);
|
||||
//ase_awk_setrunerrline (nde->line);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -2533,6 +2570,7 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
if (v == ASE_NULL)
|
||||
{
|
||||
if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out);
|
||||
//ase_awk_setrunerrline (nde->line);
|
||||
return -1;
|
||||
}
|
||||
ase_awk_refupval (run, v);
|
||||
@ -2542,6 +2580,7 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
{
|
||||
if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out);
|
||||
ase_awk_refdownval (run, v);
|
||||
//ase_awk_setrunerrline (nde->line);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -2553,12 +2592,14 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
}
|
||||
}
|
||||
|
||||
/* print the value ORS to terminate the operation */
|
||||
n = ase_awk_writeextio_str (
|
||||
run, nde->out_type, dst,
|
||||
run->global.ors.ptr, run->global.ors.len);
|
||||
if (n < 0 && run->errnum != ASE_AWK_EIOHANDLER)
|
||||
{
|
||||
if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out);
|
||||
//ase_awk_setrunerrline (nde->line);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -2566,6 +2607,7 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
* that is the user handler returned an error... */
|
||||
|
||||
if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out);
|
||||
ase_awk_setglobal (run, ASE_AWK_GLOBAL_ERRNO, ase_awk_val_zero);
|
||||
|
||||
skip_write:
|
||||
return 0;
|
||||
@ -2607,7 +2649,7 @@ static int __run_printf (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
{
|
||||
/* the output destination name is empty. */
|
||||
ASE_AWK_FREE (run->awk, out);
|
||||
n = -1;
|
||||
ase_awk_setglobal (run, ASE_AWK_GLOBAL_ERRNO, ase_awk_val_negone);
|
||||
goto skip_write;
|
||||
}
|
||||
|
||||
@ -2618,15 +2660,8 @@ static int __run_printf (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
/* the output destination name contains a null
|
||||
* character. */
|
||||
ASE_AWK_FREE (run->awk, out);
|
||||
n = -1;
|
||||
ase_awk_setglobal (run, ASE_AWK_GLOBAL_ERRNO, ase_awk_val_negone);
|
||||
goto skip_write;
|
||||
/* TODO: how to handle error???
|
||||
* make print return -1??? not possible.
|
||||
* throw an exception??
|
||||
* set ERRNO or what??? this seems most
|
||||
* reasonable. or can it have a global
|
||||
* flag variable for print/printf such
|
||||
* as PRINT_ERRNO? */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: tree.h,v 1.83 2006-11-28 04:30:22 bacon Exp $
|
||||
* $Id: tree.h,v 1.84 2006-12-16 14:43:51 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ASE_AWK_TREE_H_
|
||||
@ -130,6 +130,7 @@ struct ase_awk_afn_t
|
||||
|
||||
#define ASE_AWK_NDE_HDR \
|
||||
int type; \
|
||||
ase_size_t line; \
|
||||
ase_awk_nde_t* next
|
||||
|
||||
struct ase_awk_nde_t
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: val.c,v 1.98 2006-12-13 14:16:12 bacon Exp $
|
||||
* $Id: val.c,v 1.99 2006-12-16 14:43:51 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
@ -38,6 +38,7 @@ static ase_awk_val_int_t __awk_int[] =
|
||||
{ ASE_AWK_VAL_INT, 0, 9, ASE_NULL }
|
||||
};
|
||||
|
||||
ase_awk_val_t* ase_awk_val_negone = (ase_awk_val_t*)&__awk_int[0];
|
||||
ase_awk_val_t* ase_awk_val_zero = (ase_awk_val_t*)&__awk_int[1];
|
||||
ase_awk_val_t* ase_awk_val_one = (ase_awk_val_t*)&__awk_int[2];
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: val.h,v 1.56 2006-12-04 12:58:24 bacon Exp $
|
||||
* $Id: val.h,v 1.57 2006-12-16 14:43:51 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ASE_AWK_VAL_H_
|
||||
@ -138,6 +138,7 @@ extern "C" {
|
||||
extern ase_awk_val_t* ase_awk_val_nil;
|
||||
extern ase_awk_val_t* ase_awk_val_zls;
|
||||
extern ase_awk_val_t* ase_awk_val_nl;
|
||||
extern ase_awk_val_t* ase_awk_val_negone;
|
||||
extern ase_awk_val_t* ase_awk_val_zero;
|
||||
extern ase_awk_val_t* ase_awk_val_one;
|
||||
|
||||
|
Reference in New Issue
Block a user