*** empty log message ***

This commit is contained in:
hyung-hwan 2007-01-03 04:16:15 +00:00
parent c454dfde89
commit 06a33d01bd
5 changed files with 130 additions and 44 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h,v 1.177 2007-01-02 12:25:18 bacon Exp $
* $Id: awk.h,v 1.178 2007-01-03 04:16:14 bacon Exp $
*/
#ifndef _ASE_AWK_AWK_H_
@ -208,7 +208,10 @@ enum
ASE_AWK_STRIPSPACES = (1 << 12),
/* enable the nextoutfile keyword */
ASE_AWK_NEXTOFILE = (1 << 13)
ASE_AWK_NEXTOFILE = (1 << 13),
/* cr + lf by default */
ASE_AWK_CRLF = (1 << 14)
};
/* error code */

View File

@ -1,5 +1,5 @@
/*
* $Id: extio.c,v 1.69 2007-01-02 12:25:18 bacon Exp $
* $Id: extio.c,v 1.70 2007-01-03 04:16:14 bacon Exp $
*/
#include <ase/awk/awk_i.h>
@ -83,6 +83,7 @@ int ase_awk_readextio (
ase_char_t* rs_ptr;
ase_size_t rs_len;
ase_size_t line_len = 0;
ase_char_t c = ASE_T('\0'), pc;
ASE_AWK_ASSERT (run->awk,
in_type >= 0 && in_type <= ASE_COUNTOF(__in_type_map));
@ -206,8 +207,6 @@ int ase_awk_readextio (
/* call the io handler */
while (1)
{
ase_char_t c;
if (p->in.pos >= p->in.len)
{
ase_ssize_t n;
@ -238,18 +237,34 @@ int ase_awk_readextio (
p->in.pos = 0;
}
pc = c;
c = p->in.buf[p->in.pos++];
if (rs_ptr == ASE_NULL)
{
/* separate by a new line */
/* TODO: handle different line terminator like \r\n */
if (c == ASE_T('\n')) break;
if (c == ASE_T('\n'))
{
if (pc == ASE_T('\r') &&
ASE_AWK_STR_LEN(buf) > 0)
{
ASE_AWK_STR_LEN(buf) -= 1;
}
break;
}
}
else if (rs_len == 0)
{
/* separate by a blank line */
/* TODO: handle different line terminator like \r\n */
if (c == ASE_T('\n'))
{
if (pc == ASE_T('\r') &&
ASE_AWK_STR_LEN(buf) > 0)
{
ASE_AWK_STR_LEN(buf) -= 1;
}
}
if (line_len == 0 && c == ASE_T('\n'))
{
if (ASE_AWK_STR_LEN(buf) <= 0)
@ -264,9 +279,7 @@ int ase_awk_readextio (
/* when a blank line is encountered,
* it needs to snip off the line
* terminator of the previous line */
/* TODO: handle different line terminator like \r\n */
ASE_AWK_STR_LEN(buf) -= 1;
break;
}
}
@ -281,7 +294,6 @@ int ase_awk_readextio (
ASE_AWK_ASSERT (run->awk, run->global.rs != ASE_NULL);
/* TODO: safematchrex */
n = ase_awk_matchrex (
run->awk, run->global.rs,
((run->global.ignorecase)? ASE_AWK_REX_IGNORECASE: 0),
@ -920,8 +932,7 @@ void ase_awk_clearextio (ase_awk_run_t* run)
n = handler (ASE_AWK_IO_CLOSE, run->extio.chain, ASE_NULL, 0);
if (n <= -1)
{
/* TODO:
* some warning actions need to be taken */
/* TODO: some warnings needs to be shown */
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.234 2006-12-30 08:54:01 bacon Exp $
* $Id: parse.c,v 1.235 2007-01-03 04:16:14 bacon Exp $
*/
#include <ase/awk/awk_i.h>
@ -4537,7 +4537,6 @@ static int __get_token (ase_awk_t* awk)
}
else if (c == ASE_T(';'))
{
/* TODO: more check on the newline terminator... */
SET_TOKEN_TYPE (awk, TOKEN_SEMICOLON);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR (awk);
@ -5142,8 +5141,20 @@ static int __deparse (ase_awk_t* awk)
EXIT_DEPARSE (ASE_AWK_ESOUTWR);
}
if (ase_awk_putsrcstr (awk, ASE_T(";\n\n")) == -1)
EXIT_DEPARSE (ASE_AWK_ESOUTWR);
if (awk->option & ASE_AWK_CRLF)
{
if (ase_awk_putsrcstr (awk, ASE_T(";\r\n\r\n")) == -1)
{
EXIT_DEPARSE (ASE_AWK_ESOUTWR);
}
}
else
{
if (ase_awk_putsrcstr (awk, ASE_T(";\n\n")) == -1)
{
EXIT_DEPARSE (ASE_AWK_ESOUTWR);
}
}
}
df.awk = awk;
@ -5163,6 +5174,12 @@ static int __deparse (ase_awk_t* awk)
if (ase_awk_prnpt (awk, awk->tree.begin) == -1)
EXIT_DEPARSE (ASE_AWK_ESOUTWR);
if (awk->option & ASE_AWK_CRLF)
{
if (__put_char (awk, ASE_T('\r')) == -1)
EXIT_DEPARSE (ASE_AWK_ESOUTWR);
}
if (__put_char (awk, ASE_T('\n')) == -1)
EXIT_DEPARSE (ASE_AWK_ESOUTWR);
}
@ -5179,6 +5196,12 @@ static int __deparse (ase_awk_t* awk)
if (chain->action == ASE_NULL)
{
/* blockless pattern */
if (awk->option & ASE_AWK_CRLF)
{
if (__put_char (awk, ASE_T('\r')) == -1)
EXIT_DEPARSE (ASE_AWK_ESOUTWR);
}
if (__put_char (awk, ASE_T('\n')) == -1)
EXIT_DEPARSE (ASE_AWK_ESOUTWR);
}
@ -5193,6 +5216,12 @@ static int __deparse (ase_awk_t* awk)
EXIT_DEPARSE (ASE_AWK_ESOUTWR);
}
if (awk->option & ASE_AWK_CRLF)
{
if (__put_char (awk, ASE_T('\r')) == -1)
EXIT_DEPARSE (ASE_AWK_ESOUTWR);
}
if (__put_char (awk, ASE_T('\n')) == -1)
EXIT_DEPARSE (ASE_AWK_ESOUTWR);
@ -5248,10 +5277,19 @@ static int __deparse_func (ase_awk_pair_t* pair, void* arg)
if (ase_awk_putsrcstr (df->awk, ASE_T(", ")) == -1) return -1;
}
if (ase_awk_putsrcstr (df->awk, ASE_T(")\n")) == -1) return -1;
if (ase_awk_putsrcstr (df->awk, ASE_T(")")) == -1) return -1;
if (df->awk->option & ASE_AWK_CRLF)
{
if (__put_char (df->awk, ASE_T('\r')) == -1) return -1;
}
if (__put_char (df->awk, ASE_T('\n')) == -1) return -1;
if (ase_awk_prnpt (df->awk, afn->body) == -1) return -1;
if (ase_awk_putsrcstr (df->awk, ASE_T("\n")) == -1) return -1;
if (df->awk->option & ASE_AWK_CRLF)
{
if (__put_char (df->awk, ASE_T('\r')) == -1) return -1;
}
if (__put_char (df->awk, ASE_T('\n')) == -1) return -1;
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.317 2007-01-03 03:18:58 bacon Exp $
* $Id: run.c,v 1.318 2007-01-03 04:16:15 bacon Exp $
*/
#include <ase/awk/awk_i.h>
@ -31,6 +31,7 @@ enum exit_level_t
#define DEFAULT_OFMT ASE_T("%.6g")
#define DEFAULT_OFS ASE_T(" ")
#define DEFAULT_ORS ASE_T("\n")
#define DEFAULT_ORS_CRLF ASE_T("\r\n")
#define DEFAULT_SUBSEP ASE_T("\034")
/* the index of a positional variable should be a positive interger
@ -964,7 +965,8 @@ static void __deinit_run (ase_awk_run_t* run)
}
if (run->global.ors.ptr != ASE_NULL &&
run->global.ors.ptr != DEFAULT_ORS)
run->global.ors.ptr != DEFAULT_ORS &&
run->global.ors.ptr != DEFAULT_ORS_CRLF)
{
ASE_AWK_FREE (run->awk, run->global.ors.ptr);
run->global.ors.ptr = ASE_NULL;
@ -1173,7 +1175,7 @@ static int __set_globals_to_default (ase_awk_run_t* run)
const ase_char_t* str;
};
static struct __gtab_t gtab[] =
struct __gtab_t gtab[] =
{
{ ASE_AWK_GLOBAL_CONVFMT, DEFAULT_CONVFMT },
{ ASE_AWK_GLOBAL_FILENAME, ASE_NULL },
@ -1187,6 +1189,12 @@ static int __set_globals_to_default (ase_awk_run_t* run)
ase_awk_val_t* tmp;
ase_size_t i, j;
if (run->awk->option & ASE_AWK_CRLF)
{
/* ugly */
gtab[5].str = DEFAULT_ORS_CRLF;
}
for (i = 0; i < ASE_COUNTOF(gtab); i++)
{
if (gtab[i].str == ASE_NULL || gtab[i].str[0] == ASE_T('\0'))

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.c,v 1.98 2006-12-13 14:16:12 bacon Exp $
* $Id: tree.c,v 1.99 2007-01-03 04:16:15 bacon Exp $
*/
#include <ase/awk/awk_i.h>
@ -85,6 +85,12 @@ static const ase_char_t* __print_outop_str[] =
#define PUT_SRCSTR(awk,str) \
do { if (ase_awk_putsrcstr (awk, str) == -1) return -1; } while (0)
#define PUT_NEWLINE(awk) \
do { \
if (awk->option & ASE_AWK_CRLF) PUT_SRCSTR (awk, ASE_T("\r")); \
PUT_SRCSTR (awk, ASE_T("\n")); \
} while (0)
#define PUT_SRCSTRX(awk,str,len) \
do { if (ase_awk_putsrcstrx (awk, str, len) == -1) return -1; } while (0)
@ -570,7 +576,8 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
case ASE_AWK_NDE_NULL:
{
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T(";\n"));
PUT_SRCSTR (awk, ASE_T(";"));
PUT_NEWLINE (awk);
break;
}
@ -581,7 +588,8 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
ase_awk_nde_blk_t* px = (ase_awk_nde_blk_t*)p;
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("{\n"));
PUT_SRCSTR (awk, ASE_T("{"));
PUT_NEWLINE (awk);
if (px->nlocals > 0)
{
@ -601,12 +609,14 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
n = ase_awk_longtostr (
i, 10, ASE_NULL, tmp, ASE_COUNTOF(tmp));
PUT_SRCSTRX (awk, tmp, n);
PUT_SRCSTR (awk, ASE_T(";\n"));
PUT_SRCSTR (awk, ASE_T(";"));
PUT_NEWLINE (awk);
}
PRINT_STATEMENTS (awk, px->body, depth + 1);
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("}\n"));
PUT_SRCSTR (awk, ASE_T("}"));
PUT_NEWLINE (awk);
break;
}
@ -617,7 +627,8 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("if ("));
PRINT_EXPRESSION (awk, px->test);
PUT_SRCSTR (awk, ASE_T(")\n"));
PUT_SRCSTR (awk, ASE_T(")"));
PUT_NEWLINE (awk);
ASE_AWK_ASSERT (awk, px->then_part != ASE_NULL);
if (px->then_part->type == ASE_AWK_NDE_BLK)
@ -628,7 +639,8 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
if (px->else_part != ASE_NULL)
{
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("else\n"));
PUT_SRCSTR (awk, ASE_T("else"));
PUT_NEWLINE (awk);
if (px->else_part->type == ASE_AWK_NDE_BLK)
PRINT_STATEMENTS (awk, px->else_part, depth);
else
@ -644,7 +656,8 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("while ("));
PRINT_EXPRESSION (awk, px->test);
PUT_SRCSTR (awk, ASE_T(")\n"));
PUT_SRCSTR (awk, ASE_T(")"));
PUT_NEWLINE (awk);
if (px->body->type == ASE_AWK_NDE_BLK)
{
PRINT_STATEMENTS (awk, px->body, depth);
@ -661,7 +674,8 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p;
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("do\n"));
PUT_SRCSTR (awk, ASE_T("do"));
PUT_NEWLINE (awk);
if (px->body->type == ASE_AWK_NDE_BLK)
{
PRINT_STATEMENTS (awk, px->body, depth);
@ -674,7 +688,8 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("while ("));
PRINT_EXPRESSION (awk, px->test);
PUT_SRCSTR (awk, ASE_T(");\n"));
PUT_SRCSTR (awk, ASE_T(");"));
PUT_NEWLINE (awk);
break;
}
@ -698,7 +713,8 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
{
PRINT_EXPRESSION (awk, px->incr);
}
PUT_SRCSTR (awk, ASE_T(")\n"));
PUT_SRCSTR (awk, ASE_T(")"));
PUT_NEWLINE (awk);
if (px->body->type == ASE_AWK_NDE_BLK)
{
@ -718,7 +734,7 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("for "));
PRINT_EXPRESSION (awk, px->test);
PUT_SRCSTR (awk, ASE_T("\n"));
PUT_NEWLINE (awk);
if (px->body->type == ASE_AWK_NDE_BLK)
{
PRINT_STATEMENTS (awk, px->body, depth);
@ -733,14 +749,16 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
case ASE_AWK_NDE_BREAK:
{
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("break;\n"));
PUT_SRCSTR (awk, ASE_T("break;"));
PUT_NEWLINE (awk);
break;
}
case ASE_AWK_NDE_CONTINUE:
{
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("continue;\n"));
PUT_SRCSTR (awk, ASE_T("continue;"));
PUT_NEWLINE (awk);
break;
}
@ -749,7 +767,8 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
PRINT_TABS (awk, depth);
if (((ase_awk_nde_return_t*)p)->val == ASE_NULL)
{
PUT_SRCSTR (awk, ASE_T("return;\n"));
PUT_SRCSTR (awk, ASE_T("return;"));
PUT_NEWLINE (awk);
}
else
{
@ -757,7 +776,8 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
ASE_AWK_ASSERT (awk, ((ase_awk_nde_return_t*)p)->val->next == ASE_NULL);
PRINT_EXPRESSION (awk, ((ase_awk_nde_return_t*)p)->val);
PUT_SRCSTR (awk, ASE_T(";\n"));
PUT_SRCSTR (awk, ASE_T(";"));
PUT_NEWLINE (awk);
}
break;
}
@ -769,14 +789,16 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
if (px->val == ASE_NULL)
{
PUT_SRCSTR (awk, ASE_T("exit;\n"));
PUT_SRCSTR (awk, ASE_T("exit;"));
PUT_NEWLINE (awk);
}
else
{
PUT_SRCSTR (awk, ASE_T("exit "));
ASE_AWK_ASSERT (awk, px->val->next == ASE_NULL);
PRINT_EXPRESSION (awk, px->val);
PUT_SRCSTR (awk, ASE_T(";\n"));
PUT_SRCSTR (awk, ASE_T(";"));
PUT_NEWLINE (awk);
}
break;
}
@ -784,14 +806,16 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
case ASE_AWK_NDE_NEXT:
{
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("next;\n"));
PUT_SRCSTR (awk, ASE_T("next;"));
PUT_NEWLINE (awk);
break;
}
case ASE_AWK_NDE_NEXTFILE:
{
PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("nextfile;\n"));
PUT_SRCSTR (awk, ASE_T("nextfile;"));
PUT_NEWLINE (awk);
break;
}
@ -828,7 +852,8 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
PRINT_EXPRESSION (awk, px->out);
}
PUT_SRCSTR (awk, ASE_T(";\n"));
PUT_SRCSTR (awk, ASE_T(";"));
PUT_NEWLINE (awk);
break;
}
@ -836,7 +861,8 @@ static int __print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
{
PRINT_TABS (awk, depth);
PRINT_EXPRESSION (awk, p);
PUT_SRCSTR (awk, ASE_T(";\n"));
PUT_SRCSTR (awk, ASE_T(";"));
PUT_NEWLINE (awk);
}
}