improved line number handling

This commit is contained in:
hyung-hwan 2009-08-20 08:04:15 +00:00
parent 0f9d553ff8
commit b6ca96214a
12 changed files with 278 additions and 254 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp 257 2009-08-17 12:10:30Z hyunghwan.chung $
* $Id: Awk.hpp 258 2009-08-19 14:04:15Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -97,10 +97,9 @@ public:
ERR_EXPRNST = QSE_AWK_EEXPRNST,
ERR_LXCHR = QSE_AWK_ELXCHR,
ERR_LXDIG = QSE_AWK_ELXDIG,
ERR_ENDSRC = QSE_AWK_EENDSRC,
ERR_ECMNTNC = QSE_AWK_ECMNTNC,
ERR_ENDSTR = QSE_AWK_EENDSTR,
ERR_ENDREX = QSE_AWK_EENDREX,
ERR_EOF = QSE_AWK_EEOF,
ERR_CMTNC = QSE_AWK_ECMTNC,
ERR_STRNC = QSE_AWK_ESTRNC,
ERR_LBRACE = QSE_AWK_ELBRACE,
ERR_LPAREN = QSE_AWK_ELPAREN,
ERR_RPAREN = QSE_AWK_ERPAREN,

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.hpp 254 2009-08-13 13:26:46Z hyunghwan.chung $
* $Id: StdAwk.hpp 258 2009-08-19 14:04:15Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -22,6 +22,7 @@
#include <qse/awk/Awk.hpp>
/** @file
* Standard AWK Interpreter
*
* @example awk05.cpp
* This program demonstrates how to use QSE::StdAwk::loop().

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 257 2009-08-17 12:10:30Z hyunghwan.chung $
* $Id: awk.h 258 2009-08-19 14:04:15Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -651,10 +651,9 @@ enum qse_awk_errnum_t
QSE_AWK_ELXCHR, /**< invalid character '${0}' */
QSE_AWK_ELXDIG, /**< invalid digit '${0}' */
QSE_AWK_EENDSRC, /**< unexpected end of source */
QSE_AWK_ECMNTNC, /**< comment not closed properly */
QSE_AWK_EENDSTR, /**< string or regular expression not closed */
QSE_AWK_EENDREX, /**< unexpected end of regular expression */
QSE_AWK_EEOF, /**< unexpected end of source */
QSE_AWK_ECMTNC, /**< comment not closed properly */
QSE_AWK_ESTRNC, /**< string or regular expression not closed */
QSE_AWK_ELBRACE, /**< left brace expected in place of '${0}' */
QSE_AWK_ELPAREN, /**< left parenthesis expected in place of '${0}' */
QSE_AWK_ERPAREN, /**< right parenthesis expected in place of '${0}' */
@ -1034,7 +1033,7 @@ const qse_char_t* qse_awk_geterrmsg (
/**
* The qse_awk_geterrinf() function copies error information into memory
* pointed to by @a errinf.
* pointed to by @a errinf from @a awk.
*/
void qse_awk_geterrinf (
qse_awk_t* awk, /**< awk object */
@ -1533,11 +1532,21 @@ const qse_char_t* qse_awk_rtx_geterrmsg (
qse_awk_rtx_t* rtx /**< runtime context */
);
/**
* The qse_awk_rtx_geterrinf() function copies error information into memory
* pointed to by @a errinf from a runtime context @a rtx.
*/
void qse_awk_rtx_geterrinf (
qse_awk_rtx_t* rtx, /**< runtime context */
qse_awk_errinf_t* errinf /**< error information */
);
/**
* The qse_awk_rtx_geterror() function retrieves error information from a
* runtime context @rtx. The error number is stored into memory pointed
* to by @a errnum; the error message pointer into memory pointed to by
* @a errmsg; the error line into memory pointed to by @a errlin.
*/
void qse_awk_rtx_geterror (
qse_awk_rtx_t* rtx, /**< runtime context */
qse_awk_errnum_t* errnum, /**< error number */

View File

@ -1,5 +1,5 @@
/*
* $Id: std.h 239 2009-07-18 12:02:24Z hyunghwan.chung $
* $Id: std.h 258 2009-08-19 14:04:15Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -134,11 +134,11 @@ int qse_awk_parsestd (
* the lifetime of the runtime context created.
*/
qse_awk_rtx_t* qse_awk_rtx_openstd (
qse_awk_t* awk,
qse_size_t xtn,
const qse_char_t* id,
const qse_char_t*const* icf,
const qse_char_t*const* ocf
qse_awk_t* awk,
qse_size_t xtn,
const qse_char_t* id,
const qse_char_t** icf,
const qse_char_t** ocf
);
/**

View File

@ -1,5 +1,5 @@
/*
* $Id: Sed.hpp 257 2009-08-17 12:10:30Z hyunghwan.chung $
* $Id: Sed.hpp 258 2009-08-19 14:04:15Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -23,7 +23,7 @@
#include <qse/sed/sed.h>
/** @file
* A stream editor
* Stream Editor
*/
/////////////////////////////////

View File

@ -1,5 +1,5 @@
/*
* $Id: StdSed.hpp 254 2009-08-13 13:26:46Z hyunghwan.chung $
* $Id: StdSed.hpp 258 2009-08-19 14:04:15Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -22,7 +22,7 @@
#include <qse/sed/Sed.hpp>
/** @file
* standard sed
* Standard Stream Editor
*/
/////////////////////////////////

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.cpp 257 2009-08-17 12:10:30Z hyunghwan.chung $
* $Id: StdAwk.cpp 258 2009-08-19 14:04:15Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -821,7 +821,7 @@ int StdAwk::SourceFile::open (Data& io)
char_t fbuf[64];
char_t* dbuf = QSE_NULL;
if (dir.len > 0)
if (dir.len > 0 && ioname[0] != QSE_T('/'))
{
size_t tmplen, totlen;

View File

@ -1,5 +1,5 @@
/*
* $Id: err.c 257 2009-08-17 12:10:30Z hyunghwan.chung $
* $Id: err.c 258 2009-08-19 14:04:15Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -46,10 +46,9 @@ const qse_char_t* qse_awk_dflerrstr (qse_awk_t* awk, qse_awk_errnum_t errnum)
QSE_T("invalid character '${0}'"),
QSE_T("invalid digit '${0}'"),
QSE_T("unexpected end of source"),
QSE_T("unexpected end of input"),
QSE_T("comment not closed properly"),
QSE_T("string or regular expression not closed"),
QSE_T("unexpected end of regular expression"),
QSE_T("left brace expected in place of '${0}'"),
QSE_T("left parenthesis expected in place of '${0}'"),
QSE_T("right parenthesis expected in place of '${0}'"),

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c 257 2009-08-17 12:10:30Z hyunghwan.chung $
* $Id: run.c 258 2009-08-19 14:04:15Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -435,7 +435,8 @@ static int set_global (
if (shorten_record (run, (qse_size_t)lv) == -1)
{
/* adjust the error line */
if (var != QSE_NULL) run->errinf.lin = var->line;
if (var != QSE_NULL)
run->errinf.lin = var->line;
return -1;
}
}
@ -1543,7 +1544,7 @@ static int run_pattern_blocks (qse_awk_rtx_t* run)
{
int n;
#define ADJUST_ERROR_LINE(run) \
#define ADJUST_ERROR(run) \
if (run->awk->tree.chain != QSE_NULL) \
{ \
if (run->awk->tree.chain->pattern != QSE_NULL) \
@ -1568,14 +1569,14 @@ static int run_pattern_blocks (qse_awk_rtx_t* run)
n = read_record (run);
if (n == -1)
{
ADJUST_ERROR_LINE (run);
ADJUST_ERROR (run);
return -1; /* error */
}
if (n == 0) break; /* end of input */
if (update_fnr (run, run->gbl.fnr+1, run->gbl.nr+1) == -1)
{
ADJUST_ERROR_LINE (run);
ADJUST_ERROR (run);
return -1;
}
@ -1586,7 +1587,7 @@ static int run_pattern_blocks (qse_awk_rtx_t* run)
}
}
#undef ADJUST_ERROR_LINE
#undef ADJUST_ERROR
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: std.c 256 2009-08-16 13:44:20Z hyunghwan.chung $
* $Id: std.c 258 2009-08-19 14:04:15Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -219,7 +219,7 @@ static qse_ssize_t sf_in_open (
qse_char_t fbuf[64];
qse_char_t* dbuf = QSE_NULL;
if (xtn->s.in.dir.len > 0)
if (xtn->s.in.dir.len > 0 && arg->name[0] != QSE_T('/'))
{
qse_size_t tmplen, totlen;
@ -1066,11 +1066,11 @@ static qse_ssize_t awk_rio_console (
}
qse_awk_rtx_t* qse_awk_rtx_openstd (
qse_awk_t* awk,
qse_size_t xtnsize,
const qse_char_t* id,
const qse_char_t*const* icf,
const qse_char_t*const* ocf)
qse_awk_t* awk,
qse_size_t xtnsize,
const qse_char_t* id,
const qse_char_t** icf,
const qse_char_t** ocf)
{
qse_awk_rtx_t* rtx;
qse_awk_rio_t rio;

View File

@ -956,7 +956,7 @@ BEGIN {
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --newline=on -o- -f lang-004.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
ERROR: CODE [43] LINE [3] function 'a' redefined
ERROR: CODE [42] LINE [3] function 'a' redefined
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --implicit=off --explicit=on --newline=on -o- -f lang-005.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
@ -984,7 +984,7 @@ BEGIN {
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --implicit=off --explicit=on --newline=on -o- -f lang-006.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
ERROR: CODE [44] LINE [5] global variable 'a' redefined
ERROR: CODE [43] LINE [5] global variable 'a' redefined
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --implicit=on --explicit=on --newline=on -o- -f lang-007.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
@ -1352,7 +1352,7 @@ BEGIN {
printf ("%s\n",10.34);
}
ERROR: CODE [104] LINE [3] recursion detected in format conversion
ERROR: CODE [103] LINE [3] recursion detected in format conversion
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --newline=on -o- -f lang-014.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
@ -1481,27 +1481,27 @@ END {
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-018.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
ERROR: CODE [48] LINE [1] duplicate global variable 'ARGV'
ERROR: CODE [47] LINE [1] duplicate global variable 'ARGV'
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-019.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
ERROR: CODE [50] LINE [1] '+' not a valid parameter name
ERROR: CODE [49] LINE [1] '+' not a valid parameter name
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-020.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
ERROR: CODE [51] LINE [1] '+' not a valid variable name
ERROR: CODE [50] LINE [1] '+' not a valid variable name
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-021.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
ERROR: CODE [51] LINE [3] '+' not a valid variable name
ERROR: CODE [50] LINE [3] '+' not a valid variable name
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --newline=on -o- -f lang-022.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
ERROR: CODE [24] LINE [2] left parenthesis expected in place of '='
ERROR: CODE [23] LINE [2] left parenthesis expected in place of '='
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-023.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
ERROR: CODE [29] LINE [5] colon expected in place of ';'
ERROR: CODE [28] LINE [5] colon expected in place of ';'
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-024.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
@ -1520,7 +1520,7 @@ BEGIN {
delete iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix;
}
ERROR: CODE [79] LINE [3] variable 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix' not deletable
ERROR: CODE [78] LINE [3] variable 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix' not deletable
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --newline=on -o- -f lang-026.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
@ -1532,7 +1532,7 @@ BEGIN {
}
abc
ERROR: CODE [87] LINE [4] map 'abc' not assignable with a scalar
ERROR: CODE [86] LINE [4] map 'abc' not assignable with a scalar
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --newline=on -o- -f lang-027.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
@ -1540,11 +1540,11 @@ ERROR: CODE [17] LINE [2] invalid character '<NUL>'
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --newline=on -o- -f lang-028.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
ERROR: CODE [42] LINE [2] intrinsic function 'substr' redefined
ERROR: CODE [41] LINE [2] intrinsic function 'substr' redefined
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-029.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
ERROR: CODE [43] LINE [9] function 'abc' redefined
ERROR: CODE [42] LINE [9] function 'abc' redefined
--------------------------------------------------------------------------------
../../cmd/awk/qseawk --newline=on -o- -f lang-030.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------