*** empty log message ***
This commit is contained in:
parent
b4d8b06a66
commit
0f31bffe69
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h,v 1.168 2006-12-16 16:12:07 bacon Exp $
|
||||
* $Id: awk.h,v 1.169 2006-12-17 14:56:05 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ASE_AWK_AWK_H_
|
||||
@ -319,14 +319,14 @@ enum
|
||||
ASE_AWK_ESCALARTOMAP, /* cannot change a scalar value to a map */
|
||||
ASE_AWK_EMAPNOTALLOWED, /* a map is not allowed */
|
||||
ASE_AWK_EVALTYPE, /* wrong value type */
|
||||
ASE_AWK_EPIPE, /* pipe operation error */
|
||||
ASE_AWK_ENEXTCALL, /* next called from BEGIN or END */
|
||||
ASE_AWK_ENEXTFILECALL, /* nextfile called from BEGIN or END */
|
||||
ASE_AWK_EIOIMPL, /* wrong user io handler implementation */
|
||||
ASE_AWK_EBFNIMPL, /* wrong builtin function implementation */
|
||||
ASE_AWK_EBFNFAIL, /* builtin function handler failed */
|
||||
ASE_AWK_ENOSUCHIO, /* no such io name found */
|
||||
ASE_AWK_EIOHANDLER, /* io handler has returned an error */
|
||||
ASE_AWK_EIOHANDLER, /* i/o callback returned an error */
|
||||
ASE_AWK_EIONAME, /* invalid i/o name */
|
||||
ASE_AWK_EFMTARG, /* arguments to format string not sufficient */
|
||||
ASE_AWK_EFMTCONV, /* recursion detected in format conversion */
|
||||
ASE_AWK_ECONVFMTCHAR, /* an invalid character found in CONVFMT */
|
||||
@ -451,9 +451,12 @@ 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);
|
||||
int ase_awk_getrunerrlin (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);
|
||||
void ase_awk_setrunerror (
|
||||
ase_awk_run_t* run, int errnum,
|
||||
ase_size_t errlin, const ase_char_t* msg);
|
||||
|
||||
/* functions to manipulate built-in functions */
|
||||
void* ase_awk_addbfn (
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk_i.h,v 1.92 2006-12-16 16:12:07 bacon Exp $
|
||||
* $Id: awk_i.h,v 1.93 2006-12-17 14:56:06 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ASE_AWK_AWKI_H_
|
||||
@ -329,6 +329,7 @@ struct ase_awk_run_t
|
||||
} depth;
|
||||
|
||||
int errnum;
|
||||
ase_size_t errlin;
|
||||
ase_char_t errmsg[256];
|
||||
|
||||
void* custom_data;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: err.c,v 1.60 2006-12-16 16:12:07 bacon Exp $
|
||||
* $Id: err.c,v 1.61 2006-12-17 14:56:06 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
@ -117,14 +117,14 @@ const ase_char_t* ase_awk_geterrstr (int errnum)
|
||||
ASE_T("cannot change a scalar value to a map"),
|
||||
ASE_T("a map is not allowed"),
|
||||
ASE_T("wrong value type"),
|
||||
ASE_T("pipe operation error"),
|
||||
ASE_T("next cannot be called from the BEGIN or END block"),
|
||||
ASE_T("nextfile cannot be called from the BEGIN or END block"),
|
||||
ASE_T("wrong implementation of user-defined io handler"),
|
||||
ASE_T("wrong implementation of built-in function handler"),
|
||||
ASE_T("built-in function handler returned an error"),
|
||||
ASE_T("no such io name found"),
|
||||
ASE_T("io handler has returned an error"),
|
||||
ASE_T("i/o handler returned an error"),
|
||||
ASE_T("invalid i/o name"),
|
||||
ASE_T("not sufficient arguments to formatting sequence"),
|
||||
ASE_T("recursion detected in format conversion"),
|
||||
ASE_T("invalid character in CONVFMT"),
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: extio.c,v 1.66 2006-12-09 11:49:03 bacon Exp $
|
||||
* $Id: extio.c,v 1.67 2006-12-17 14:56:06 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
@ -147,12 +147,6 @@ int ase_awk_readextio (
|
||||
{
|
||||
ASE_AWK_FREE (run->awk, p->name);
|
||||
ASE_AWK_FREE (run->awk, p);
|
||||
|
||||
/* TODO: use meaningful error code */
|
||||
if (ase_awk_setglobal (
|
||||
run, ASE_AWK_GLOBAL_ERRNO,
|
||||
ase_awk_val_one) == -1) return -1;
|
||||
|
||||
run->errnum = ASE_AWK_EIOHANDLER;
|
||||
return -1;
|
||||
}
|
||||
@ -229,18 +223,8 @@ int ase_awk_readextio (
|
||||
if (n <= -1)
|
||||
{
|
||||
/* handler error. getline should return -1 */
|
||||
/* TODO: use meaningful error code */
|
||||
if (ase_awk_setglobal (
|
||||
run, ASE_AWK_GLOBAL_ERRNO,
|
||||
ase_awk_val_one) == -1)
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
run->errnum = ASE_AWK_EIOHANDLER;
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -481,12 +465,6 @@ int ase_awk_writeextio_str (
|
||||
{
|
||||
ASE_AWK_FREE (run->awk, p->name);
|
||||
ASE_AWK_FREE (run->awk, p);
|
||||
|
||||
/* TODO: use meaningful error code */
|
||||
if (ase_awk_setglobal (
|
||||
run, ASE_AWK_GLOBAL_ERRNO,
|
||||
ase_awk_val_one) == -1) return -1;
|
||||
|
||||
run->errnum = ASE_AWK_EIOHANDLER;
|
||||
return -1;
|
||||
}
|
||||
@ -526,11 +504,6 @@ int ase_awk_writeextio_str (
|
||||
|
||||
if (n <= -1)
|
||||
{
|
||||
/* TODO: use meaningful error code */
|
||||
if (ase_awk_setglobal (
|
||||
run, ASE_AWK_GLOBAL_ERRNO,
|
||||
ase_awk_val_one) == -1) return -1;
|
||||
|
||||
run->errnum = ASE_AWK_EIOHANDLER;
|
||||
return -1;
|
||||
}
|
||||
@ -586,11 +559,6 @@ int ase_awk_flushextio (
|
||||
|
||||
if (n <= -1)
|
||||
{
|
||||
/* TODO: use meaningful error code */
|
||||
if (ase_awk_setglobal (
|
||||
run, ASE_AWK_GLOBAL_ERRNO,
|
||||
ase_awk_val_one) == -1) return -1;
|
||||
|
||||
run->errnum = ASE_AWK_EIOHANDLER;
|
||||
return -1;
|
||||
}
|
||||
@ -604,10 +572,6 @@ int ase_awk_flushextio (
|
||||
if (ok) return 0;
|
||||
|
||||
/* there is no corresponding extio for name */
|
||||
/* TODO: use meaningful error code. but is this needed? */
|
||||
if (ase_awk_setglobal (
|
||||
run, ASE_AWK_GLOBAL_ERRNO, ase_awk_val_one) == -1) return -1;
|
||||
|
||||
run->errnum = ASE_AWK_ENOSUCHIO;
|
||||
return -1;
|
||||
}
|
||||
@ -805,7 +769,6 @@ int ase_awk_closeextio_read (
|
||||
if (handler (ASE_AWK_IO_CLOSE, p, ASE_NULL, 0) <= -1)
|
||||
{
|
||||
/* this is not a run-time error.*/
|
||||
/* TODO: set ERRNO */
|
||||
run->errnum = ASE_AWK_EIOHANDLER;
|
||||
return -1;
|
||||
}
|
||||
@ -868,7 +831,6 @@ int ase_awk_closeextio_write (
|
||||
if (handler (ASE_AWK_IO_CLOSE, p, ASE_NULL, 0) <= -1)
|
||||
{
|
||||
/* this is not a run-time error.*/
|
||||
/* TODO: set ERRNO */
|
||||
run->errnum = ASE_AWK_EIOHANDLER;
|
||||
return -1;
|
||||
}
|
||||
@ -887,7 +849,6 @@ int ase_awk_closeextio_write (
|
||||
}
|
||||
|
||||
/* this is not a run-time error */
|
||||
/* TODO: set ERRNO */
|
||||
run->errnum = ASE_AWK_EIOHANDLER;
|
||||
return -1;
|
||||
}
|
||||
@ -910,7 +871,6 @@ int ase_awk_closeextio (ase_awk_run_t* run, const ase_char_t* name)
|
||||
if (handler (ASE_AWK_IO_CLOSE, p, ASE_NULL, 0) <= -1)
|
||||
{
|
||||
/* this is not a run-time error.*/
|
||||
/* TODO: set ERRNO */
|
||||
run->errnum = ASE_AWK_EIOHANDLER;
|
||||
return -1;
|
||||
}
|
||||
@ -929,7 +889,6 @@ int ase_awk_closeextio (ase_awk_run_t* run, const ase_char_t* name)
|
||||
}
|
||||
|
||||
/* this is not a run-time error */
|
||||
/* TODO: set ERRNO */
|
||||
run->errnum = ASE_AWK_EIOHANDLER;
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: func.c,v 1.84 2006-11-29 14:52:06 bacon Exp $
|
||||
* $Id: func.c,v 1.85 2006-12-17 14:56:06 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
@ -206,7 +206,6 @@ static int __bfn_close (
|
||||
* closeextio_read or closeextio_write. */
|
||||
if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, name);
|
||||
n = -1;
|
||||
/* TODO: need to set ERRNO??? */
|
||||
goto skip_close;
|
||||
}
|
||||
|
||||
@ -219,7 +218,6 @@ static int __bfn_close (
|
||||
if (a0->type != ASE_AWK_VAL_STR)
|
||||
ASE_AWK_FREE (run->awk, name);
|
||||
n = -1;
|
||||
/* TODO: need to set ERRNO??? */
|
||||
goto skip_close;
|
||||
}
|
||||
}
|
||||
@ -313,7 +311,7 @@ static int __bfn_fflush (
|
||||
}
|
||||
|
||||
/* the target name contains a null character.
|
||||
* make fflush return -1 and set ERRNO accordingly */
|
||||
* make fflush return -1 */
|
||||
ptr = str0; end = str0 + len0;
|
||||
while (ptr < end)
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parse.c,v 1.223 2006-12-16 14:43:50 bacon Exp $
|
||||
* $Id: parse.c,v 1.224 2006-12-17 14:56:06 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
@ -273,7 +273,6 @@ static struct __bvent __bvtab[] =
|
||||
{ ASE_T("ARGV"), 4, 0 },
|
||||
{ ASE_T("CONVFMT"), 7, 0 },
|
||||
{ ASE_T("ENVIRON"), 7, 0 },
|
||||
{ ASE_T("ERRNO"), 5, 0 },
|
||||
{ ASE_T("FILENAME"), 8, 0 },
|
||||
{ ASE_T("FNR"), 3, 0 },
|
||||
{ ASE_T("FS"), 2, 0 },
|
||||
@ -1024,7 +1023,6 @@ 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;
|
||||
|
||||
@ -3253,8 +3251,11 @@ static ase_awk_nde_t* __parse_print (ase_awk_t* awk, int type)
|
||||
ase_awk_nde_print_t* nde;
|
||||
ase_awk_nde_t* args = ASE_NULL;
|
||||
ase_awk_nde_t* out = ASE_NULL;
|
||||
ase_size_t line;
|
||||
int out_type;
|
||||
|
||||
line = awk->token.prev.line;
|
||||
|
||||
if (!MATCH(awk,TOKEN_SEMICOLON) &&
|
||||
!MATCH(awk,TOKEN_GT) &&
|
||||
!MATCH(awk,TOKEN_RSHIFT) &&
|
||||
@ -3391,6 +3392,7 @@ static ase_awk_nde_t* __parse_print (ase_awk_t* awk, int type)
|
||||
}
|
||||
|
||||
nde->type = type;
|
||||
nde->line = line;
|
||||
nde->next = ASE_NULL;
|
||||
nde->args = args;
|
||||
nde->out_type = out_type;
|
||||
|
172
ase/awk/run.c
172
ase/awk/run.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.c,v 1.303 2006-12-16 16:22:05 bacon Exp $
|
||||
* $Id: run.c,v 1.304 2006-12-17 14:56:06 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk_i.h>
|
||||
@ -547,6 +547,11 @@ int ase_awk_getrunerrnum (ase_awk_run_t* run)
|
||||
return run->errnum;
|
||||
}
|
||||
|
||||
int ase_awk_getrunerrlin (ase_awk_run_t* run)
|
||||
{
|
||||
return run->errlin;
|
||||
}
|
||||
|
||||
const ase_char_t* ase_awk_getrunerrmsg (ase_awk_run_t* run)
|
||||
{
|
||||
if (run->errmsg[0] == ASE_T('\0'))
|
||||
@ -558,12 +563,18 @@ const ase_char_t* ase_awk_getrunerrmsg (ase_awk_run_t* run)
|
||||
void ase_awk_setrunerrnum (ase_awk_run_t* run, int errnum)
|
||||
{
|
||||
run->errnum = errnum;
|
||||
run->errlin = 0;
|
||||
run->errmsg[0] = ASE_T('\0');
|
||||
}
|
||||
|
||||
void ase_awk_setrunerrmsg (ase_awk_run_t* run, const ase_char_t* msg)
|
||||
void ase_awk_setrunerror (
|
||||
ase_awk_run_t* run, int errnum,
|
||||
ase_size_t errlin, const ase_char_t* msg)
|
||||
{
|
||||
ase_awk_strxcpy (run->errmsg, ASE_COUNTOF(run->errmsg), msg);
|
||||
run->errnum = errnum;
|
||||
run->errlin = errlin;
|
||||
if (msg == ASE_NULL) run->errmsg[0] = ASE_T('\0');
|
||||
else ase_awk_strxcpy (run->errmsg, ASE_COUNTOF(run->errmsg), msg);
|
||||
}
|
||||
|
||||
int ase_awk_run (ase_awk_t* awk,
|
||||
@ -619,8 +630,10 @@ int ase_awk_run (ase_awk_t* awk,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* clear the run error code */
|
||||
/* clear the run error */
|
||||
run->errnum = ASE_AWK_ENOERR;
|
||||
run->errlin = 0;
|
||||
run->errmsg[0] = ASE_T('\0');
|
||||
|
||||
/* execute the start callback if it exists */
|
||||
if (runcbs != ASE_NULL && runcbs->on_start != ASE_NULL)
|
||||
@ -1494,7 +1507,7 @@ static int __run_pattern_blocks (ase_awk_run_t* run)
|
||||
}
|
||||
|
||||
/* In case of getline, the code would make getline return -1,
|
||||
* set ERRNO, make this function return 0 after having checked
|
||||
* and make this function return 0 after having checked
|
||||
* if closextio has returned -1 and errnum has been set to
|
||||
* ASE_AWK_EIOHANDLER. But this part of the code ends the input for
|
||||
* the implicit pattern-block loop, which is totally different
|
||||
@ -2479,7 +2492,12 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
|
||||
/* if so, resolve the destination name */
|
||||
v = __eval_expression (run, nde->out);
|
||||
if (v == ASE_NULL) return -1;
|
||||
if (v == ASE_NULL)
|
||||
{
|
||||
ase_awk_setrunerror (
|
||||
run, run->errnum, nde->line, ASE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_refupval (run, v);
|
||||
out = ase_awk_valtostr (
|
||||
@ -2487,65 +2505,35 @@ 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);
|
||||
ase_awk_setrunerror (
|
||||
run, run->errnum, nde->line, ASE_NULL);
|
||||
return -1;
|
||||
}
|
||||
ase_awk_refdownval (run, v);
|
||||
|
||||
if (len <= 0)
|
||||
{
|
||||
/* if the destination name is empty, it skips the
|
||||
* writing and flags an error and ERRNO */
|
||||
|
||||
ase_awk_val_t* no;
|
||||
/* the destination name is empty */
|
||||
ASE_AWK_FREE (run->awk, out);
|
||||
|
||||
no = ase_awk_makeintval (run, ASE_AWK_ENOENT);
|
||||
if (no == ASE_NULL)
|
||||
{
|
||||
run->errnum = ASE_AWK_ENOMEM;
|
||||
ase_awk_setrunerror (
|
||||
run, ASE_AWK_EIONAME, nde->line,
|
||||
ASE_T("destination name empty in print"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_refupval (run, no);
|
||||
if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_ERRNO, no) == -1)
|
||||
{
|
||||
ase_awk_refdownval (run, no);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_refdownval (run, no);
|
||||
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'))
|
||||
{
|
||||
/* if so, the error is flagged thru ERRNO */
|
||||
|
||||
ase_awk_val_t* no;
|
||||
/* if so, it skips writing */
|
||||
ASE_AWK_FREE (run->awk, out);
|
||||
|
||||
no = ase_awk_makeintval (run, ASE_AWK_ENOENT);
|
||||
if (no == ASE_NULL)
|
||||
{
|
||||
run->errnum = ASE_AWK_ENOMEM;
|
||||
ase_awk_setrunerror (
|
||||
run, ASE_AWK_EIONAME, nde->line,
|
||||
ASE_T("destination name containing a null character in print"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_refupval (run, no);
|
||||
if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_ERRNO, no) == -1)
|
||||
{
|
||||
ase_awk_refdownval (run, no);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_refdownval (run, no);
|
||||
goto skip_write;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2561,14 +2549,13 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
run, nde->out_type, dst,
|
||||
ASE_AWK_STR_BUF(&run->inrec.line),
|
||||
ASE_AWK_STR_LEN(&run->inrec.line));
|
||||
if (n < 0 && run->errnum != ASE_AWK_EIOHANDLER)
|
||||
if (n < 0 /*&& run->errnum != ASE_AWK_EIOHANDLER*/)
|
||||
{
|
||||
if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out);
|
||||
//ase_awk_setrunerrline (nde->line);
|
||||
ase_awk_setrunerror (
|
||||
run, run->errnum, nde->line, ASE_NULL);
|
||||
return -1;
|
||||
}
|
||||
/* TODO: how to handle n == -1 && errnum == ASE_AWK_EIOHANDLER.
|
||||
* that is the user handler returned an error... */
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2592,10 +2579,11 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
run, nde->out_type, dst,
|
||||
run->global.ofs.ptr,
|
||||
run->global.ofs.len);
|
||||
if (n < 0 && run->errnum != ASE_AWK_EIOHANDLER)
|
||||
if (n < 0 /*&& run->errnum != ASE_AWK_EIOHANDLER*/)
|
||||
{
|
||||
if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out);
|
||||
//ase_awk_setrunerrline (nde->line);
|
||||
ase_awk_setrunerror (
|
||||
run, run->errnum, nde->line, ASE_NULL);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -2604,25 +2592,23 @@ 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);
|
||||
ase_awk_setrunerror (
|
||||
run, run->errnum, nde->line, ASE_NULL);
|
||||
return -1;
|
||||
}
|
||||
ase_awk_refupval (run, v);
|
||||
|
||||
n = ase_awk_writeextio_val (run, nde->out_type, dst, v);
|
||||
if (n < 0 && run->errnum != ASE_AWK_EIOHANDLER)
|
||||
if (n < 0 /*&& run->errnum != ASE_AWK_EIOHANDLER*/)
|
||||
{
|
||||
if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out);
|
||||
ase_awk_refdownval (run, v);
|
||||
//ase_awk_setrunerrline (nde->line);
|
||||
ase_awk_setrunerror (
|
||||
run, run->errnum, nde->line, ASE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_refdownval (run, v);
|
||||
|
||||
|
||||
/* TODO: how to handle n == -1 && run->errnum == ASE_AWK_EIOHANDLER.
|
||||
* that is the user handler returned an error... */
|
||||
}
|
||||
}
|
||||
|
||||
@ -2630,18 +2616,14 @@ static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
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 (n < 0 /*&& run->errnum != ASE_AWK_EIOHANDLER*/)
|
||||
{
|
||||
if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out);
|
||||
//ase_awk_setrunerrline (nde->line);
|
||||
ase_awk_setrunerror (run, run->errnum, nde->line, ASE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* TODO: how to handle n == -1 && errnum == ASE_AWK_EIOHANDLER.
|
||||
* 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;
|
||||
@ -2667,7 +2649,12 @@ static int __run_printf (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
ase_size_t len;
|
||||
|
||||
v = __eval_expression (run, nde->out);
|
||||
if (v == ASE_NULL) return -1;
|
||||
if (v == ASE_NULL)
|
||||
{
|
||||
ase_awk_setrunerror (
|
||||
run, run->errnum, nde->line, ASE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_refupval (run, v);
|
||||
out = ase_awk_valtostr (
|
||||
@ -2675,6 +2662,8 @@ static int __run_printf (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
if (out == ASE_NULL)
|
||||
{
|
||||
ase_awk_refdownval (run, v);
|
||||
ase_awk_setrunerror (
|
||||
run, run->errnum, nde->line, ASE_NULL);
|
||||
return -1;
|
||||
}
|
||||
ase_awk_refdownval (run, v);
|
||||
@ -2682,54 +2671,25 @@ static int __run_printf (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
if (len <= 0)
|
||||
{
|
||||
/* the output destination name is empty. */
|
||||
ase_awk_val_t* no;
|
||||
ASE_AWK_FREE (run->awk, out);
|
||||
|
||||
no = ase_awk_makeintval (run, ASE_AWK_ENOENT);
|
||||
if (no == ASE_NULL)
|
||||
{
|
||||
run->errnum = ASE_AWK_ENOMEM;
|
||||
ase_awk_setrunerror (
|
||||
run, ASE_AWK_EIONAME, nde->line,
|
||||
ASE_T("destination name empty in printf"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_refupval (run, no);
|
||||
if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_ERRNO, no) == -1)
|
||||
{
|
||||
ase_awk_refdownval (run, no);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_refdownval (run, no);
|
||||
goto skip_write;
|
||||
}
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
if (out[--len] == ASE_T('\0'))
|
||||
{
|
||||
/* the output destination name contains a null
|
||||
* character. */
|
||||
|
||||
ase_awk_val_t* no;
|
||||
ASE_AWK_FREE (run->awk, out);
|
||||
|
||||
no = ase_awk_makeintval (run, ASE_AWK_ENOENT);
|
||||
if (no == ASE_NULL)
|
||||
{
|
||||
run->errnum = ASE_AWK_ENOMEM;
|
||||
ase_awk_setrunerror (
|
||||
run, ASE_AWK_EIONAME, nde->line,
|
||||
ASE_T("destination name containing a null character in printf"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_refupval (run, no);
|
||||
if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_ERRNO, no) == -1)
|
||||
{
|
||||
ase_awk_refdownval (run, no);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_refdownval (run, no);
|
||||
goto skip_write;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2753,6 +2713,7 @@ static int __run_printf (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_setrunerror (run, run->errnum, nde->line, ASE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -2762,10 +2723,12 @@ static int __run_printf (ase_awk_run_t* run, ase_awk_nde_print_t* nde)
|
||||
/* the remaining arguments are ignored as the format cannot
|
||||
* contain any % characters */
|
||||
n = ase_awk_writeextio_val (run, nde->out_type, dst, v);
|
||||
if (n < 0 && run->errnum != ASE_AWK_EIOHANDLER)
|
||||
if (n < 0 /*&& run->errnum != ASE_AWK_EIOHANDLER*/)
|
||||
{
|
||||
if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out);
|
||||
ase_awk_refdownval (run, v);
|
||||
ase_awk_setrunerror (
|
||||
run, run->errnum, nde->line, ASE_NULL);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -2780,6 +2743,8 @@ static int __run_printf (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_setrunerror (
|
||||
run, run->errnum, nde->line, ASE_NULL);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -2804,7 +2769,7 @@ static int __formatted_output (
|
||||
if (ptr == ASE_NULL) return -1;
|
||||
|
||||
n = ase_awk_writeextio_str (run, out_type, dst, ptr, len);
|
||||
if (n < 0 && run->errnum != ASE_AWK_EIOHANDLER) return -1;
|
||||
if (n < 0 /*&& run->errnum != ASE_AWK_EIOHANDLER*/) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -5552,7 +5517,6 @@ static ase_awk_val_t* __eval_getline (ase_awk_run_t* run, ase_awk_nde_t* nde)
|
||||
{
|
||||
/* the input source name contains a null
|
||||
* character. make getline return -1 */
|
||||
/* TODO: set ERRNO */
|
||||
ASE_AWK_FREE (run->awk, in);
|
||||
n = -1;
|
||||
goto skip_read;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.h,v 1.29 2006-12-04 06:04:07 bacon Exp $
|
||||
* $Id: run.h,v 1.30 2006-12-17 14:56:07 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ASE_AWK_RUN_H_
|
||||
@ -85,7 +85,6 @@ enum ase_awk_global_id_t
|
||||
ASE_AWK_GLOBAL_ARGV,
|
||||
ASE_AWK_GLOBAL_CONVFMT,
|
||||
ASE_AWK_GLOBAL_ENVIRON,
|
||||
ASE_AWK_GLOBAL_ERRNO,
|
||||
ASE_AWK_GLOBAL_FILENAME,
|
||||
ASE_AWK_GLOBAL_FNR,
|
||||
ASE_AWK_GLOBAL_FS,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c,v 1.142 2006-12-17 13:12:08 bacon Exp $
|
||||
* $Id: awk.c,v 1.143 2006-12-17 14:56:07 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk.h>
|
||||
@ -281,7 +281,7 @@ static ase_ssize_t process_extio_pipe (
|
||||
else if (epa->mode == ASE_AWK_EXTIO_PIPE_WRITE)
|
||||
mode = ASE_T("w");
|
||||
else return -1; /* TODO: any way to set the error number? */
|
||||
awk_dprintf (ASE_T("opending %s of type %d (pipe)\n"), epa->name, epa->type);
|
||||
awk_dprintf (ASE_T("opening %s of type %d (pipe)\n"), epa->name, epa->type);
|
||||
handle = awk_popen (epa->name, mode);
|
||||
if (handle == NULL) return -1;
|
||||
epa->handle = (void*)handle;
|
||||
@ -349,7 +349,7 @@ static ase_ssize_t process_extio_file (
|
||||
mode = ASE_T("a");
|
||||
else return -1; /* TODO: any way to set the error number? */
|
||||
|
||||
awk_dprintf (ASE_T("opending %s of type %d (file)\n"), epa->name, epa->type);
|
||||
awk_dprintf (ASE_T("opening %s of type %d (file)\n"), epa->name, epa->type);
|
||||
handle = awk_fopen (epa->name, mode);
|
||||
if (handle == NULL) return -1;
|
||||
|
||||
@ -648,10 +648,11 @@ static void on_run_end (
|
||||
{
|
||||
if (errnum != ASE_AWK_ENOERR)
|
||||
{
|
||||
//const ase_awk_t* errmsg = ase_awk_getrunerrmsg (run);
|
||||
awk_dprintf (
|
||||
ASE_T("AWK ABOUT TO END WITH AN ERROR - [%d] %s\n"),
|
||||
errnum, ase_awk_getrunerrmsg (run));
|
||||
awk_dprintf (ASE_T("AWK ENDED WITH AN ERROR\n"));
|
||||
awk_dprintf (ASE_T("CODE [%d] LINE [%u] %s\n"),
|
||||
errnum,
|
||||
(unsigned int)ase_awk_getrunerrlin(run),
|
||||
ase_awk_getrunerrmsg(run));
|
||||
}
|
||||
else awk_dprintf (ASE_T("AWK ENDED SUCCESSFULLY\n"));
|
||||
|
||||
|
@ -25,5 +25,7 @@ BEGIN {
|
||||
|
||||
print .0;
|
||||
print 10;
|
||||
|
||||
print fflush ("abc");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user