This commit is contained in:
parent
059ee04507
commit
754c2970af
@ -646,7 +646,7 @@ static struct
|
|||||||
{ ASE_T("idiv"), TestAwk::OPT_IDIV },
|
{ ASE_T("idiv"), TestAwk::OPT_IDIV },
|
||||||
{ ASE_T("strconcat"), TestAwk::OPT_STRCONCAT },
|
{ ASE_T("strconcat"), TestAwk::OPT_STRCONCAT },
|
||||||
{ ASE_T("extio"), TestAwk::OPT_EXTIO },
|
{ ASE_T("extio"), TestAwk::OPT_EXTIO },
|
||||||
{ ASE_T("blockless"), TestAwk::OPT_BLOCKLESS },
|
{ ASE_T("newline"), TestAwk::OPT_NEWLINE },
|
||||||
{ ASE_T("baseone"), TestAwk::OPT_BASEONE },
|
{ ASE_T("baseone"), TestAwk::OPT_BASEONE },
|
||||||
{ ASE_T("stripspaces"), TestAwk::OPT_STRIPSPACES },
|
{ ASE_T("stripspaces"), TestAwk::OPT_STRIPSPACES },
|
||||||
{ ASE_T("nextofile"), TestAwk::OPT_NEXTOFILE },
|
{ ASE_T("nextofile"), TestAwk::OPT_NEXTOFILE },
|
||||||
|
@ -869,7 +869,7 @@ static struct
|
|||||||
{ ASE_T("idiv"), ASE_AWK_IDIV },
|
{ ASE_T("idiv"), ASE_AWK_IDIV },
|
||||||
{ ASE_T("strconcat"), ASE_AWK_STRCONCAT },
|
{ ASE_T("strconcat"), ASE_AWK_STRCONCAT },
|
||||||
{ ASE_T("extio"), ASE_AWK_EXTIO },
|
{ ASE_T("extio"), ASE_AWK_EXTIO },
|
||||||
{ ASE_T("blockless"), ASE_AWK_BLOCKLESS },
|
{ ASE_T("newline"), ASE_AWK_NEWLINE },
|
||||||
{ ASE_T("baseone"), ASE_AWK_BASEONE },
|
{ ASE_T("baseone"), ASE_AWK_BASEONE },
|
||||||
{ ASE_T("stripspaces"), ASE_AWK_STRIPSPACES },
|
{ ASE_T("stripspaces"), ASE_AWK_STRIPSPACES },
|
||||||
{ ASE_T("nextofile"), ASE_AWK_NEXTOFILE },
|
{ ASE_T("nextofile"), ASE_AWK_NEXTOFILE },
|
||||||
@ -877,8 +877,7 @@ static struct
|
|||||||
{ ASE_T("argstomain"), ASE_AWK_ARGSTOMAIN },
|
{ ASE_T("argstomain"), ASE_AWK_ARGSTOMAIN },
|
||||||
{ ASE_T("reset"), ASE_AWK_RESET },
|
{ ASE_T("reset"), ASE_AWK_RESET },
|
||||||
{ ASE_T("maptovar"), ASE_AWK_MAPTOVAR },
|
{ ASE_T("maptovar"), ASE_AWK_MAPTOVAR },
|
||||||
{ ASE_T("pablock"), ASE_AWK_PABLOCK },
|
{ ASE_T("pablock"), ASE_AWK_PABLOCK }
|
||||||
{ ASE_T("newline"), ASE_AWK_NEWLINE }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void print_usage (const ase_char_t* argv0)
|
static void print_usage (const ase_char_t* argv0)
|
||||||
@ -1001,7 +1000,7 @@ static int awk_main (int argc, ase_char_t* argv[])
|
|||||||
|
|
||||||
opt = ASE_AWK_IMPLICIT |
|
opt = ASE_AWK_IMPLICIT |
|
||||||
ASE_AWK_EXTIO |
|
ASE_AWK_EXTIO |
|
||||||
ASE_AWK_BLOCKLESS |
|
ASE_AWK_NEWLINE |
|
||||||
ASE_AWK_BASEONE |
|
ASE_AWK_BASEONE |
|
||||||
ASE_AWK_PABLOCK;
|
ASE_AWK_PABLOCK;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.hpp 240 2008-07-11 14:41:16Z baconevi $
|
* $Id: Awk.hpp 245 2008-07-15 05:56:32Z baconevi $
|
||||||
*
|
*
|
||||||
* {License}
|
* {License}
|
||||||
*/
|
*/
|
||||||
@ -545,7 +545,10 @@ public:
|
|||||||
OPT_STRCONCAT = ASE_AWK_STRCONCAT,
|
OPT_STRCONCAT = ASE_AWK_STRCONCAT,
|
||||||
OPT_EXTIO = ASE_AWK_EXTIO,
|
OPT_EXTIO = ASE_AWK_EXTIO,
|
||||||
OPT_COPROC = ASE_AWK_COPROC,
|
OPT_COPROC = ASE_AWK_COPROC,
|
||||||
OPT_BLOCKLESS = ASE_AWK_BLOCKLESS,
|
|
||||||
|
/** Can terminate a statement with a new line */
|
||||||
|
OPT_NEWLINE = ASE_AWK_NEWLINE,
|
||||||
|
|
||||||
OPT_BASEONE = ASE_AWK_BASEONE,
|
OPT_BASEONE = ASE_AWK_BASEONE,
|
||||||
OPT_STRIPSPACES = ASE_AWK_STRIPSPACES,
|
OPT_STRIPSPACES = ASE_AWK_STRIPSPACES,
|
||||||
|
|
||||||
@ -564,9 +567,7 @@ public:
|
|||||||
/** Allows the assignment of a map value to a variable */
|
/** Allows the assignment of a map value to a variable */
|
||||||
OPT_MAPTOVAR = ASE_AWK_MAPTOVAR,
|
OPT_MAPTOVAR = ASE_AWK_MAPTOVAR,
|
||||||
/** Allows BEGIN, END, pattern-action blocks */
|
/** Allows BEGIN, END, pattern-action blocks */
|
||||||
OPT_PABLOCK = ASE_AWK_PABLOCK,
|
OPT_PABLOCK = ASE_AWK_PABLOCK
|
||||||
/** Can terminate a statement with a new line */
|
|
||||||
OPT_NEWLINE = ASE_AWK_NEWLINE
|
|
||||||
};
|
};
|
||||||
// end of enum Option
|
// end of enum Option
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h 239 2008-07-11 11:07:17Z baconevi $
|
* $Id: awk.h 245 2008-07-15 05:56:32Z baconevi $
|
||||||
*
|
*
|
||||||
* {License}
|
* {License}
|
||||||
*/
|
*/
|
||||||
@ -189,8 +189,8 @@ enum ase_awk_option_t
|
|||||||
/* support co-process - NOT IMPLEMENTED YET */
|
/* support co-process - NOT IMPLEMENTED YET */
|
||||||
ASE_AWK_COPROC = (1 << 8),
|
ASE_AWK_COPROC = (1 << 8),
|
||||||
|
|
||||||
/* support blockless patterns */
|
/* can terminate a statement with a new line */
|
||||||
ASE_AWK_BLOCKLESS = (1 << 9),
|
ASE_AWK_NEWLINE = (1 << 9),
|
||||||
|
|
||||||
/* use 1 as the start index for string operations and ARGV */
|
/* use 1 as the start index for string operations and ARGV */
|
||||||
ASE_AWK_BASEONE = (1 << 10),
|
ASE_AWK_BASEONE = (1 << 10),
|
||||||
@ -226,10 +226,7 @@ enum ase_awk_option_t
|
|||||||
ASE_AWK_MAPTOVAR = (1 << 16),
|
ASE_AWK_MAPTOVAR = (1 << 16),
|
||||||
|
|
||||||
/* allows BEGIN, END, pattern-action blocks */
|
/* allows BEGIN, END, pattern-action blocks */
|
||||||
ASE_AWK_PABLOCK = (1 << 17),
|
ASE_AWK_PABLOCK = (1 << 17)
|
||||||
|
|
||||||
/* can terminate a statement with a new line */
|
|
||||||
ASE_AWK_NEWLINE = (1 << 18)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* error code */
|
/* error code */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.cpp 237 2008-07-09 13:20:08Z baconevi $
|
* $Id: Awk.cpp 245 2008-07-15 05:56:32Z baconevi $
|
||||||
*
|
*
|
||||||
* {License}
|
* {License}
|
||||||
*/
|
*/
|
||||||
@ -1181,7 +1181,7 @@ int Awk::open ()
|
|||||||
int opt =
|
int opt =
|
||||||
OPT_IMPLICIT |
|
OPT_IMPLICIT |
|
||||||
OPT_EXTIO |
|
OPT_EXTIO |
|
||||||
OPT_BLOCKLESS |
|
OPT_NEWLINE |
|
||||||
OPT_BASEONE |
|
OPT_BASEONE |
|
||||||
OPT_PABLOCK;
|
OPT_PABLOCK;
|
||||||
ase_awk_setoption (awk, opt);
|
ase_awk_setoption (awk, opt);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: parse.c 243 2008-07-14 13:53:31Z baconevi $
|
* $Id: parse.c 245 2008-07-15 05:56:32Z baconevi $
|
||||||
*
|
*
|
||||||
* {License}
|
* {License}
|
||||||
*/
|
*/
|
||||||
@ -324,9 +324,7 @@ static global_t gtab[] =
|
|||||||
/* output field separator for 'print' */
|
/* output field separator for 'print' */
|
||||||
{ ASE_T("OFS"), 3, ASE_AWK_EXTIO },
|
{ ASE_T("OFS"), 3, ASE_AWK_EXTIO },
|
||||||
|
|
||||||
/* output record separator. used for 'print' and blockless output
|
/* output record separator. used for 'print' and blockless output */
|
||||||
* ASE_AWK_BLOCKLESS desn't have to be specified becuase
|
|
||||||
* it requires ASE_AWK_EXTIO to be ON. */
|
|
||||||
{ ASE_T("ORS"), 3, ASE_AWK_EXTIO },
|
{ ASE_T("ORS"), 3, ASE_AWK_EXTIO },
|
||||||
|
|
||||||
{ ASE_T("RLENGTH"), 7, 0 },
|
{ ASE_T("RLENGTH"), 7, 0 },
|
||||||
@ -636,10 +634,9 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk)
|
|||||||
awk->parse.id.block = PARSE_BEGIN;
|
awk->parse.id.block = PARSE_BEGIN;
|
||||||
if (get_token(awk) == -1) return ASE_NULL;
|
if (get_token(awk) == -1) return ASE_NULL;
|
||||||
|
|
||||||
if ((awk->option & ASE_AWK_BLOCKLESS) &&
|
if (MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF))
|
||||||
(MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF)))
|
|
||||||
{
|
{
|
||||||
/* when the blockless pattern is supported
|
/* when ASE_AWK_NEWLINE is set,
|
||||||
* BEGIN and { should be located on the same line */
|
* BEGIN and { should be located on the same line */
|
||||||
SETERRLIN (awk, ASE_AWK_EBLKBEG, awk->token.prev.line);
|
SETERRLIN (awk, ASE_AWK_EBLKBEG, awk->token.prev.line);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
@ -673,10 +670,9 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk)
|
|||||||
awk->parse.id.block = PARSE_END;
|
awk->parse.id.block = PARSE_END;
|
||||||
if (get_token(awk) == -1) return ASE_NULL;
|
if (get_token(awk) == -1) return ASE_NULL;
|
||||||
|
|
||||||
if ((awk->option & ASE_AWK_BLOCKLESS) &&
|
if (MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF))
|
||||||
(MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF)))
|
|
||||||
{
|
{
|
||||||
/* when the blockless pattern is supported
|
/* when ASE_AWK_NEWLINE is set,
|
||||||
* END and { should be located on the same line */
|
* END and { should be located on the same line */
|
||||||
SETERRLIN (awk, ASE_AWK_EBLKEND, awk->token.prev.line);
|
SETERRLIN (awk, ASE_AWK_EBLKEND, awk->token.prev.line);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
@ -746,16 +742,14 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((awk->option & ASE_AWK_BLOCKLESS) &&
|
if (MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF))
|
||||||
(MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF)))
|
|
||||||
{
|
{
|
||||||
/* blockless pattern */
|
/* blockless pattern */
|
||||||
ase_bool_t newline = MATCH(awk,TOKEN_NEWLINE);
|
ase_bool_t newline = MATCH(awk,TOKEN_NEWLINE);
|
||||||
ase_size_t tline = awk->token.prev.line;
|
ase_size_t tline = awk->token.prev.line;
|
||||||
|
|
||||||
awk->parse.id.block = PARSE_ACTION_BLOCK;
|
awk->parse.id.block = PARSE_ACTION_BLOCK;
|
||||||
if (parse_pattern_block (
|
if (parse_pattern_block(awk,ptn,ASE_TRUE) == ASE_NULL)
|
||||||
awk, ptn, ASE_TRUE) == ASE_NULL)
|
|
||||||
{
|
{
|
||||||
ase_awk_clrpt (awk, ptn);
|
ase_awk_clrpt (awk, ptn);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
@ -763,7 +757,7 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk)
|
|||||||
|
|
||||||
if (newline)
|
if (newline)
|
||||||
{
|
{
|
||||||
if (get_token (awk) == -1)
|
if (get_token(awk) == -1)
|
||||||
{
|
{
|
||||||
/* ptn has been added to the chain.
|
/* ptn has been added to the chain.
|
||||||
* it doesn't have to be cleared here
|
* it doesn't have to be cleared here
|
||||||
@ -1108,7 +1102,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
|
|||||||
/* duplicate functions should have been detected previously */
|
/* duplicate functions should have been detected previously */
|
||||||
ASE_ASSERT (n != 0);
|
ASE_ASSERT (n != 0);
|
||||||
|
|
||||||
afn->name = ASE_PAIR_KEYPTR(pair); /* do some trick to save a string. */
|
afn->name = ASE_PAIR_KEYPTR(pair); /* do some trick to save a string. */
|
||||||
afn->name_len = ASE_PAIR_KEYLEN(pair);
|
afn->name_len = ASE_PAIR_KEYLEN(pair);
|
||||||
ASE_AWK_FREE (awk, name_dup);
|
ASE_AWK_FREE (awk, name_dup);
|
||||||
|
|
||||||
@ -4534,20 +4528,6 @@ static int get_token (ase_awk_t* awk)
|
|||||||
awk->token.line = awk->src.lex.line;
|
awk->token.line = awk->src.lex.line;
|
||||||
awk->token.column = awk->src.lex.column;
|
awk->token.column = awk->src.lex.column;
|
||||||
|
|
||||||
/* TODO; remove this
|
|
||||||
if (line != 0 && (awk->option & ASE_AWK_BLOCKLESS) &&
|
|
||||||
(awk->parse.id.block == PARSE_PATTERN ||
|
|
||||||
awk->parse.id.block == PARSE_BEGIN ||
|
|
||||||
awk->parse.id.block == PARSE_END))
|
|
||||||
{
|
|
||||||
if (awk->token.line != line)
|
|
||||||
{
|
|
||||||
SET_TOKEN_TYPE (awk, TOKEN_NEWLINE);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
c = awk->src.lex.curc;
|
c = awk->src.lex.curc;
|
||||||
|
|
||||||
if (c == ASE_CHAR_EOF)
|
if (c == ASE_CHAR_EOF)
|
||||||
@ -4979,7 +4959,6 @@ static int get_token (ase_awk_t* awk)
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_token_ok:
|
get_token_ok:
|
||||||
wprintf (L"token = [%S]\n", awk->token.name.buf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5386,7 +5365,7 @@ static int skip_comment (ase_awk_t* awk)
|
|||||||
}
|
}
|
||||||
while (c != ASE_T('\n') && c != ASE_CHAR_EOF);
|
while (c != ASE_T('\n') && c != ASE_CHAR_EOF);
|
||||||
|
|
||||||
GET_CHAR (awk);
|
if (!(awk->option & ASE_AWK_NEWLINE)) GET_CHAR (awk);
|
||||||
return 1; /* comment by # */
|
return 1; /* comment by # */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user