From 2cebde672fd89c7074967664cd2641cb0b1c00de Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 25 Aug 2006 03:31:09 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/extio.c | 31 ++++++++++++++++++++++++++---- ase/test/awk/awk.c | 45 ++++++++++++++++---------------------------- ase/test/awk/t32.awk | 2 ++ 3 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 ase/test/awk/t32.awk diff --git a/ase/awk/extio.c b/ase/awk/extio.c index 792aed51..68d2b817 100644 --- a/ase/awk/extio.c +++ b/ase/awk/extio.c @@ -1,5 +1,5 @@ /* - * $Id: extio.c,v 1.32 2006-08-24 03:30:07 bacon Exp $ + * $Id: extio.c,v 1.33 2006-08-25 03:30:38 bacon Exp $ */ #include @@ -92,6 +92,7 @@ int xp_awk_readextio ( xp_awk_val_t* rs; xp_char_t* rs_ptr; xp_size_t rs_len; + xp_size_t line_len = 0; xp_assert (in_type >= 0 && in_type <= xp_countof(__in_type_map)); xp_assert (in_type >= 0 && in_type <= xp_countof(__in_mode_map)); @@ -138,7 +139,7 @@ int xp_awk_readextio ( p->mode = extio_mode; p->handle = XP_NULL; - p->in.buf[0] = XP_C('\0'); + p->in.buf[0] = XP_T('\0'); p->in.pos = 0; p->in.len = 0; p->in.eof = xp_false; @@ -246,12 +247,30 @@ int xp_awk_readextio ( if (rs_ptr == XP_NULL) { /* separate by a new line */ - if (c == XP_C('\n')) break; + if (c == XP_T('\n')) break; } else if (rs_len == 0) { - /* TODO: */ /* separate by a blank line */ + /* TODO: handle different line terminator like \r\n */ + if (line_len == 0 && c == XP_T('\n')) + { + if (XP_STR_LEN(buf) <= 0) + { + /* if the record is empty when a blank + * line is encountered, the line + * terminator should not be added to + * the record */ + continue; + } + + /* 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 */ + XP_STR_LEN(buf) -= 1; + break; + } } else if (rs_len == 1) { @@ -269,6 +288,10 @@ int xp_awk_readextio ( ret = -1; break; } + + /* TODO: handle difference line terminator like \r\n */ + if (c == XP_T('\n')) line_len = 0; + else line_len = line_len + 1; } if (rs_ptr != XP_NULL && rs->type != XP_AWK_VAL_STR) xp_free (rs_ptr); diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index a8fa722c..b7d271e3 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.74 2006-08-23 15:42:16 bacon Exp $ + * $Id: awk.c,v 1.75 2006-08-25 03:30:38 bacon Exp $ */ #include @@ -544,7 +544,7 @@ static int __main (int argc, xp_char_t* argv[]) xp_awk_runcbs_t runcbs; xp_awk_runios_t runios; struct src_io src_io = { NULL, NULL }; - int opt; + int opt, i, file_count = 0; if ((awk = xp_awk_open(XP_NULL)) == XP_NULL) { @@ -556,45 +556,32 @@ static int __main (int argc, xp_char_t* argv[]) XP_AWK_SHADING | XP_AWK_IMPLICIT | XP_AWK_SHIFT | XP_AWK_EXTIO | XP_AWK_BLOCKLESS | XP_AWK_STRINDEXONE; - if (argc == 2) + for (i = 1; i < argc; i++) { #if defined(__STAND_ALONE) && !defined(_WIN32) - if (strcmp(argv[1], "-m") == 0) + if (strcmp(argv[i], "-m") == 0) #else - if (xp_strcmp(argv[1], XP_T("-m")) == 0) -#endif - { - xp_awk_close (awk); - xp_printf (XP_T("Usage: %s [-m] source_file\n"), argv[0]); - return -1; - } - - src_io.input_file = argv[1]; - } - else if (argc == 3) - { -#if defined(__STAND_ALONE) && !defined(_WIN32) - if (strcmp(argv[1], "-m") == 0) -#else - if (xp_strcmp(argv[1], XP_T("-m")) == 0) + if (xp_strcmp(argv[i], XP_T("-m")) == 0) #endif { opt |= XP_AWK_RUNMAIN; } + else if (file_count == 0) + { + src_io.input_file = argv[i]; + file_count++; + } + else if (file_count == 1) + { + infiles[0] = argv[i]; + file_count++; + } else { xp_awk_close (awk); - xp_printf (XP_T("Usage: %s [-m] source_file\n"), argv[0]); + xp_printf (XP_T("Usage: %s [-m] source_file [data_file]\n"), argv[0]); return -1; } - - src_io.input_file = argv[2]; - } - else - { - xp_awk_close (awk); - xp_printf (XP_T("Usage: %s [-m] source_file\n"), argv[0]); - return -1; } xp_awk_setopt (awk, opt); diff --git a/ase/test/awk/t32.awk b/ase/test/awk/t32.awk new file mode 100644 index 00000000..8bbafa04 --- /dev/null +++ b/ase/test/awk/t32.awk @@ -0,0 +1,2 @@ +BEGIN { RS = ""; } +{ print "record: ", $0; }