From 2a9fabebb6d0c025e84fa14144a8b1e12971376c Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 9 Sep 2009 01:05:48 +0000 Subject: [PATCH] improved cmd/sed/sed.c --- qse/cmd/sed/sed.c | 72 ++++++------- qse/regress/awk/regress.out | 204 ++++++++++++++++++------------------ qse/regress/awk/regress.sh | 24 ++++- qse/regress/sed/regress.sh | 135 ++++++++++++++++++++++++ 4 files changed, 292 insertions(+), 143 deletions(-) create mode 100755 qse/regress/sed/regress.sh diff --git a/qse/cmd/sed/sed.c b/qse/cmd/sed/sed.c index 3ab3f7aa..d71df8c8 100644 --- a/qse/cmd/sed/sed.c +++ b/qse/cmd/sed/sed.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -36,44 +37,38 @@ static qse_ssize_t in ( switch (cmd) { case QSE_SED_IO_OPEN: - if (arg->path == QSE_NULL || - arg->path[0] == QSE_T('\0')) + { + const qse_char_t* file; + + if (arg->path == QSE_NULL || arg->path[0] == QSE_T('\0')) { - if (g_infile) - { - arg->handle = qse_fopen (g_infile, QSE_T("r")); - if (arg->handle == QSE_NULL) - { - qse_cstr_t errarg; - errarg.ptr = g_infile; - errarg.len = qse_strlen(g_infile); - qse_sed_seterror (sed, QSE_SED_EIOFIL, &errarg, QSE_NULL); - return -1; - } - } - else arg->handle = QSE_STDIN; + file = (g_infile == QSE_NULL)? QSE_NULL: g_infile; } + else file = arg->path; + + + if (file == QSE_NULL) arg->handle = qse_sio_in; else { - arg->handle = qse_fopen (arg->path, QSE_T("r")); + arg->handle = qse_sio_open ( + qse_sed_getmmgr(sed), + 0, + file, + QSE_SIO_READ + ); + if (arg->handle == QSE_NULL) return -1; } + return 1; + } case QSE_SED_IO_CLOSE: - if (arg->handle != QSE_STDIN) - qse_fclose (arg->handle); + if (arg->handle != qse_sio_in) qse_sio_close (arg->handle); return 0; case QSE_SED_IO_READ: - { - qse_cint_t c; - /* TODO: read more characters */ - c = qse_fgetc (arg->handle); - if (c == QSE_CHAR_EOF) return 0; - buf[0] = c; - return 1; - } + return qse_sio_getsn (arg->handle, buf, size); default: return -1; @@ -86,30 +81,31 @@ static qse_ssize_t out ( switch (cmd) { case QSE_SED_IO_OPEN: - if (arg->path == QSE_NULL || - arg->path[0] == QSE_T('\0')) + if (arg->path == QSE_NULL || arg->path[0] == QSE_T('\0')) { - arg->handle = QSE_STDOUT; + arg->handle = qse_sio_out; } else { - arg->handle = qse_fopen (arg->path, QSE_T("w")); + arg->handle = qse_sio_open ( + qse_sed_getmmgr(sed), + 0, + arg->path, + QSE_SIO_WRITE | + QSE_SIO_CREATE | + QSE_SIO_TRUNCATE + ); + if (arg->handle == QSE_NULL) return -1; } return 1; case QSE_SED_IO_CLOSE: - if (arg->handle != QSE_STDOUT) - qse_fclose (arg->handle); + if (arg->handle != qse_sio_out) qse_sio_close (arg->handle); return 0; case QSE_SED_IO_WRITE: - { - qse_size_t i = 0; - for (i = 0; i < len; i++) - qse_fputc (data[i], arg->handle); - return len; - } + return qse_sio_putsn (arg->handle, data, len); default: return -1; diff --git a/qse/regress/awk/regress.out b/qse/regress/awk/regress.out index 49b34906..30f1b6f8 100644 --- a/qse/regress/awk/regress.out +++ b/qse/regress/awk/regress.out @@ -1,5 +1,5 @@ -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-001.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-001.awk cou.dat &1 -------------------------------------------------------------------------------- USSR 275 Canada 25 @@ -13,7 +13,7 @@ Japan 120 Germany 61 England 56 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-002.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-002.awk cou.dat &1 -------------------------------------------------------------------------------- COUNTRY AREA POP CONTINENT @@ -31,44 +31,44 @@ England 56 TOTAL 25681 2819 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-003.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-003.awk cou.dat &1 -------------------------------------------------------------------------------- India 1267 746 Asia Japan 144 120 Asia Germany 96 61 Europe England 94 56 Europe -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-004.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-004.awk cou.dat &1 -------------------------------------------------------------------------------- USSR 8649 275 Asia USA 3615 237 North America Mexico 762 78 North America -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-005.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-005.awk cou.dat &1 -------------------------------------------------------------------------------- Canada 3852 25 North America Brazil 3286 134 South America Mexico 762 78 North America England 94 56 Europe -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-006.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-006.awk cou.dat &1 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-007.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-007.awk cou.dat &1 -------------------------------------------------------------------------------- USSR 8649 275 Asia China 3705 1032 Asia India 1267 746 Asia Japan 144 120 Asia -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-008.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-008.awk cou.dat &1 -------------------------------------------------------------------------------- USSR 8649 275 Asia China 3705 1032 Asia India 1267 746 Asia Japan 144 120 Asia -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-009.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-009.awk cou.dat &1 -------------------------------------------------------------------------------- Canada 3852 25 North America USA 3615 237 North America @@ -78,22 +78,22 @@ France 211 55 Europe Germany 96 61 Europe England 94 56 Europe -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-010.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-010.awk cou.dat &1 -------------------------------------------------------------------------------- USSR 8649 275 Asia China 3705 1032 Asia India 1267 746 Asia Japan 144 120 Asia -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-011.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-011.awk cou.dat &1 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-012.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-012.awk cou.dat &1 -------------------------------------------------------------------------------- China 3705 1032 Asia India 1267 746 Asia -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-013.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-013.awk cou.dat &1 -------------------------------------------------------------------------------- USSR 8649 275 Asia China 3705 1032 Asia @@ -103,7 +103,7 @@ Japan 144 120 Asia Germany 96 61 Europe England 94 56 Europe -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-014.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-014.awk cou.dat &1 -------------------------------------------------------------------------------- USSR 8649 275 Asia China 3705 1032 Asia @@ -113,7 +113,7 @@ Japan 144 120 Asia Germany 96 61 Europe England 94 56 Europe -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-015.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-015.awk cou.dat &1 -------------------------------------------------------------------------------- USSR 8649 275 Asia China 3705 1032 Asia @@ -123,7 +123,7 @@ Japan 144 120 Asia Germany 96 61 Europe England 94 56 Europe -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-016.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-016.awk cou.dat &1 -------------------------------------------------------------------------------- USSR 8649 275 Asia China 3705 1032 Asia @@ -133,16 +133,16 @@ Japan 144 120 Asia Germany 96 61 Europe England 94 56 Europe -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-017.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-017.awk cou.dat &1 -------------------------------------------------------------------------------- Canada 3852 25 North America China 3705 1032 Asia USA 3615 237 North America -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-018.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-018.awk cou.dat &1 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-019.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-019.awk cou.dat &1 -------------------------------------------------------------------------------- cou.dat: USSR 8649 275 Asia cou.dat: Canada 3852 25 North America @@ -150,7 +150,7 @@ cou.dat: China 3705 1032 Asia cou.dat: USA 3615 237 North America cou.dat: Brazil 3286 134 South America -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-020.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-020.awk cou.dat &1 -------------------------------------------------------------------------------- cou.dat: USSR 8649 275 Asia cou.dat: Canada 3852 25 North America @@ -158,14 +158,14 @@ cou.dat: China 3705 1032 Asia cou.dat: USA 3615 237 North America cou.dat: Brazil 3286 134 South America -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-021.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-021.awk cou.dat &1 -------------------------------------------------------------------------------- USSR 8649000 China 3705000 India 1267000 Japan 144000 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-022.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-022.awk cou.dat &1 -------------------------------------------------------------------------------- USSR 8649 275 Asia Canada 3852 25 NA @@ -179,7 +179,7 @@ Japan 144 120 Asia Germany 96 61 Europe England 94 56 Europe -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-023.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-023.awk cou.dat &1 -------------------------------------------------------------------------------- USSR 8649 275 Asia 31.7956 Canada 3852 25 North America 6.49013 @@ -193,42 +193,42 @@ Japan 144 120 Asia 833.333 Germany 96 61 Europe 635.417 England 94 56 Europe 595.745 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-024.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-024.awk cou.dat &1 -------------------------------------------------------------------------------- Total population of the 4 Asian countries is 2173 million. -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-025.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-025.awk cou.dat &1 -------------------------------------------------------------------------------- Asian population is 2173 million. European population is 172 million. -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-026.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-026.awk cou.dat &1 -------------------------------------------------------------------------------- Asia 2173 Europe 172 North America 340 South America 134 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f cou-027.awk cou.dat &1 + ../../cmd/awk/.libs/qseawk -f cou-027.awk cou.dat &1 -------------------------------------------------------------------------------- Asia 2173 North America 340 Europe 172 South America 134 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-001.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-001.awk emp.dat &1 -------------------------------------------------------------------------------- Kathy 40 Mark 100 Mary 121 Susie 76.5 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-002.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-002.awk emp.dat &1 -------------------------------------------------------------------------------- Beth Dan -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-003.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-003.awk emp.dat &1 -------------------------------------------------------------------------------- 3 Beth 0 3 Dan 0 @@ -237,7 +237,7 @@ Dan 3 Mary 22 3 Susie 18 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-004.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-004.awk emp.dat &1 -------------------------------------------------------------------------------- 1 Beth 4.00 0 2 Dan 3.74 0 @@ -246,7 +246,7 @@ Dan 5 Mary 5.50 22 6 Susie 4.25 18 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-005.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-005.awk emp.dat &1 -------------------------------------------------------------------------------- total pay for Beth is 0 total pay for Dan is 0 @@ -255,7 +255,7 @@ total pay for Mark is 100 total pay for Mary is 121 total pay for Susie is 76.5 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-006.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-006.awk emp.dat &1 -------------------------------------------------------------------------------- total pay for Beth is $0.00 total pay for Dan is $0.00 @@ -264,7 +264,7 @@ total pay for Mark is $100.00 total pay for Mary is $121.00 total pay for Susie is $76.50 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-007.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-007.awk emp.dat &1 -------------------------------------------------------------------------------- Beth $ 0.00 Dan $ 0.00 @@ -273,26 +273,26 @@ Mark $100.00 Mary $121.00 Susie $ 76.50 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-008.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-008.awk emp.dat &1 -------------------------------------------------------------------------------- Mark 5.00 20 Mary 5.50 22 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-009.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-009.awk emp.dat &1 -------------------------------------------------------------------------------- $100.00 for Mark $121.00 for Mary $76.50 for Susie -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-010.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-010.awk emp.dat &1 -------------------------------------------------------------------------------- Susie 4.25 18 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-011.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-011.awk emp.dat &1 -------------------------------------------------------------------------------- Susie 4.25 18 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-012.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-012.awk emp.dat &1 -------------------------------------------------------------------------------- Beth 4.00 0 Kathy 4.00 10 @@ -300,7 +300,7 @@ Mark 5.00 20 Mary 5.50 22 Susie 4.25 18 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-013.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-013.awk emp.dat &1 -------------------------------------------------------------------------------- Beth 4.00 0 Kathy 4.00 10 @@ -310,7 +310,7 @@ Mary 5.50 22 Mary 5.50 22 Susie 4.25 18 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-014.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-014.awk emp.dat &1 -------------------------------------------------------------------------------- Beth 4.00 0 Kathy 4.00 10 @@ -318,10 +318,10 @@ Mark 5.00 20 Mary 5.50 22 Susie 4.25 18 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-015.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-015.awk emp.dat &1 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-016.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-016.awk emp.dat &1 -------------------------------------------------------------------------------- NAME RATE HOURS @@ -332,33 +332,33 @@ Mark 5.00 20 Mary 5.50 22 Susie 4.25 18 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-017.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-017.awk emp.dat &1 -------------------------------------------------------------------------------- 3 employees worked more than 15 hours -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-018.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-018.awk emp.dat &1 -------------------------------------------------------------------------------- 6 employees -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-019.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-019.awk emp.dat &1 -------------------------------------------------------------------------------- 6 employees total pay is 337.5 average pay is 56.25 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-020.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-020.awk emp.dat &1 -------------------------------------------------------------------------------- highest hourly rage: 5.50 for Mary -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-021.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-021.awk emp.dat &1 -------------------------------------------------------------------------------- Beth Dan Kathy Mark Mary Susie -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-022.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-022.awk emp.dat &1 -------------------------------------------------------------------------------- Susie 4.25 18 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-023.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-023.awk emp.dat &1 -------------------------------------------------------------------------------- Beth 4 Dan 3 @@ -367,15 +367,15 @@ Mark 4 Mary 4 Susie 5 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-024.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-024.awk emp.dat &1 -------------------------------------------------------------------------------- 6 lines, 18 words, 77 characters -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-025.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-025.awk emp.dat &1 -------------------------------------------------------------------------------- no employees are paid more than $6/hour -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-026.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-026.awk emp.dat &1 -------------------------------------------------------------------------------- Susie 4.25 18 Mary 5.50 22 @@ -384,7 +384,7 @@ Kathy 4.00 10 Dan 3.74 0 Beth 4.00 0 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f emp-027.awk emp.dat &1 + ../../cmd/awk/.libs/qseawk -f emp-027.awk emp.dat &1 -------------------------------------------------------------------------------- Susie 4.25 18 Mary 5.50 22 @@ -393,18 +393,18 @@ Kathy 4.00 10 Dan 3.74 0 Beth 4.00 0 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f adr-001.awk adr.dat &1 + ../../cmd/awk/.libs/qseawk -f adr-001.awk adr.dat &1 -------------------------------------------------------------------------------- James Brown 012-345-678 Richie Ren 02-3473-9192 Toh WeeKung 9102-1203 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f adr-002.awk adr.dat &1 + ../../cmd/awk/.libs/qseawk -f adr-002.awk adr.dat &1 -------------------------------------------------------------------------------- James Brown Somewhere over the rainbow 012-345-678 Toh WeeKung Singapore 9102-1203 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f unr-001.awk unr.dat &1 + ../../cmd/awk/.libs/qseawk -f unr-001.awk unr.dat &1 -------------------------------------------------------------------------------- Beth 4 0 Dan 3.74 0 @@ -413,7 +413,7 @@ Mark 5.00 20 Mary 5.5 22 Susie 4.25 18 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --strictnaming=off --newline=on -o- -f lang-001.awk &1 + ../../cmd/awk/.libs/qseawk --strictnaming=off --newline=on -o- -f lang-001.awk &1 -------------------------------------------------------------------------------- function f (__p0) { @@ -426,7 +426,7 @@ BEGIN { hello -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-002.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-002.awk &1 -------------------------------------------------------------------------------- function f (__p0) { @@ -939,7 +939,7 @@ my hello my hello ERROR: CODE 15 LINE 6 COLUMN 1 - block nested too deeply -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-003.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-003.awk &1 -------------------------------------------------------------------------------- function fn (__p0) { @@ -954,11 +954,11 @@ BEGIN { 50 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-004.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-004.awk &1 -------------------------------------------------------------------------------- ERROR: CODE 42 LINE 3 COLUMN 9 - function 'a' redefined -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --implicit=off --explicit=on --newline=on -o- -f lang-005.awk &1 + ../../cmd/awk/.libs/qseawk --implicit=off --explicit=on --newline=on -o- -f lang-005.awk &1 -------------------------------------------------------------------------------- function a (__p0) { @@ -982,11 +982,11 @@ BEGIN { 50 100 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --implicit=off --explicit=on --newline=on -o- -f lang-006.awk &1 + ../../cmd/awk/.libs/qseawk --implicit=off --explicit=on --newline=on -o- -f lang-006.awk &1 -------------------------------------------------------------------------------- ERROR: CODE 43 LINE 5 COLUMN 10 - global variable 'a' redefined -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --implicit=on --explicit=on --newline=on -o- -f lang-007.awk &1 + ../../cmd/awk/.libs/qseawk --implicit=on --explicit=on --newline=on -o- -f lang-007.awk &1 -------------------------------------------------------------------------------- global __g17; @@ -1005,7 +1005,7 @@ BEGIN { 20 30 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --implicit=off --explicit=on --newline=on -o- -f lang-008.awk &1 + ../../cmd/awk/.libs/qseawk --implicit=off --explicit=on --newline=on -o- -f lang-008.awk &1 -------------------------------------------------------------------------------- global x; @@ -1027,7 +1027,7 @@ BEGIN { 2 1 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --implicit=off --explicit=on --newline=on --strictnaming=off -o- -f lang-009.awk lang-009.awk &1 + ../../cmd/awk/.libs/qseawk --implicit=off --explicit=on --newline=on --strictnaming=off -o- -f lang-009.awk lang-009.awk &1 -------------------------------------------------------------------------------- function a (__p0) { @@ -1044,7 +1044,7 @@ END { } 1000 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-010.awk this is just a test &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-010.awk this is just a test &1 -------------------------------------------------------------------------------- BEGIN { print "ARGC=",ARGC; @@ -1101,7 +1101,7 @@ ARGC [+10124.1123000000] is positive [A ] [-000000000000000000000000000000000000000000000001] abc10 000000000000000000000000000040 g good K -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-011.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-011.awk &1 -------------------------------------------------------------------------------- BEGIN { a[1,2,3] = 20; @@ -1144,7 +1144,7 @@ BEGIN { (1,2,3) in a ==> 20 (4,5) not in a -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-012.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-012.awk &1 -------------------------------------------------------------------------------- BEGIN { OFS = " "; @@ -1345,7 +1345,7 @@ a < " " : 1 -0.123 122.877 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-013.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-013.awk &1 -------------------------------------------------------------------------------- BEGIN { CONVFMT = "%s"; @@ -1354,7 +1354,7 @@ BEGIN { ERROR: CODE 103 LINE 3 COLUMN 2 - recursion detected in format conversion -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-014.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-014.awk &1 -------------------------------------------------------------------------------- BEGIN { a = (10 + 20); @@ -1365,11 +1365,11 @@ BEGIN { 30 30 30 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-015.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-015.awk &1 -------------------------------------------------------------------------------- ERROR: CODE 15 LINE 3 COLUMN 50 - block nested too deeply -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-016.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-016.awk &1 -------------------------------------------------------------------------------- BEGIN { printf "[[[[[%s]]]]\n",sprintf ("abc %s abc",sprintf ("def %s %s",sprintf ("%s %s %s","xyz",1.2342,"xyz"),sprintf ("ttt %s tttt",123.12))); @@ -1379,7 +1379,7 @@ BEGIN { [[[[[abc def xyz 1.2342 xyz ttt 123.12 tttt abc]]]] [[[[ttt 123.12 tttt]]]] -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-017.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-017.awk &1 -------------------------------------------------------------------------------- function gety () { @@ -1430,7 +1430,7 @@ END { END OF PROGRAM END OF PROGRAM 2 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --call main --newline=on -o- -f lang-017.awk &1 + ../../cmd/awk/.libs/qseawk --call main --newline=on -o- -f lang-017.awk &1 -------------------------------------------------------------------------------- function gety () { @@ -1479,31 +1479,31 @@ END { 0 2 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-018.awk &1 + ../../cmd/awk/.libs/qseawk --explicit=on --newline=on -o- -f lang-018.awk &1 -------------------------------------------------------------------------------- ERROR: CODE 47 LINE 1 COLUMN 8 - duplicate global variable 'ARGV' -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-019.awk &1 + ../../cmd/awk/.libs/qseawk --explicit=on --newline=on -o- -f lang-019.awk &1 -------------------------------------------------------------------------------- ERROR: CODE 49 LINE 1 COLUMN 15 - '+' not a valid parameter name -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-020.awk &1 + ../../cmd/awk/.libs/qseawk --explicit=on --newline=on -o- -f lang-020.awk &1 -------------------------------------------------------------------------------- ERROR: CODE 50 LINE 1 COLUMN 8 - '+' not a valid variable name -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-021.awk &1 + ../../cmd/awk/.libs/qseawk --explicit=on --newline=on -o- -f lang-021.awk &1 -------------------------------------------------------------------------------- ERROR: CODE 50 LINE 3 COLUMN 8 - '+' not a valid variable name -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-022.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-022.awk &1 -------------------------------------------------------------------------------- ERROR: CODE 23 LINE 2 COLUMN 9 - left parenthesis expected in place of '=' -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-023.awk &1 + ../../cmd/awk/.libs/qseawk --explicit=on --newline=on -o- -f lang-023.awk &1 -------------------------------------------------------------------------------- ERROR: CODE 28 LINE 5 COLUMN 20 - colon expected in place of ';' -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-024.awk &1 + ../../cmd/awk/.libs/qseawk --explicit=on --newline=on -o- -f lang-024.awk &1 -------------------------------------------------------------------------------- BEGIN { local __l0; @@ -1513,7 +1513,7 @@ BEGIN { 1 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-025.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-025.awk &1 -------------------------------------------------------------------------------- BEGIN { iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix = 20; @@ -1522,7 +1522,7 @@ BEGIN { ERROR: CODE 78 LINE 3 COLUMN 9 - variable 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix' not deletable -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-026.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-026.awk &1 -------------------------------------------------------------------------------- BEGIN { abc[20] = "abc"; @@ -1534,19 +1534,19 @@ BEGIN { abc ERROR: CODE 86 LINE 4 COLUMN 2 - map 'abc' not assignable with a scalar -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-027.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-027.awk &1 -------------------------------------------------------------------------------- ERROR: CODE 17 LINE 2 COLUMN 1 - invalid character '' -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-028.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-028.awk &1 -------------------------------------------------------------------------------- ERROR: CODE 41 LINE 2 COLUMN 10 - intrinsic function 'substr' redefined -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --explicit=on --newline=on -o- -f lang-029.awk &1 + ../../cmd/awk/.libs/qseawk --explicit=on --newline=on -o- -f lang-029.awk &1 -------------------------------------------------------------------------------- ERROR: CODE 42 LINE 9 COLUMN 9 - function 'abc' redefined -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-030.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-030.awk &1 -------------------------------------------------------------------------------- BEGIN { print (1 + 0); @@ -1598,7 +1598,7 @@ BEGIN { 0 0 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-031.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-031.awk &1 -------------------------------------------------------------------------------- BEGIN { print match ("hhhheeeo",/e+/); @@ -1632,7 +1632,7 @@ BEGIN { 0 -1 -------------------------- -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-032.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-032.awk &1 -------------------------------------------------------------------------------- BEGIN { a = 91; @@ -1654,7 +1654,7 @@ BEGIN { --------------------- 9210 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-033.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-033.awk &1 -------------------------------------------------------------------------------- BEGIN { while ((("cat lang-033.awk" | getline x) > 0)) @@ -1666,7 +1666,7 @@ BEGIN { print x } -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on --rwpipe=on -o- -f lang-034.awk &1 + ../../cmd/awk/.libs/qseawk --newline=on --rwpipe=on -o- -f lang-034.awk &1 -------------------------------------------------------------------------------- BEGIN { print "15" || "sort"; @@ -1687,7 +1687,7 @@ xx: 13 xx: 14 xx: 15 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -vdatafile=lang-035.dat1 -vgroupname=lang-035 -f lang-035.awk lang-035.dat2 &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -vdatafile=lang-035.dat1 -vgroupname=lang-035 -f lang-035.awk lang-035.dat2 &1 -------------------------------------------------------------------------------- BEGIN { max_cid_vars = 100; @@ -1931,7 +1931,7 @@ lease 10.218.255.151 { uid "\001\000\033[\234\220\000"; } -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-036.awk lang-036.dat &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-036.awk lang-036.dat &1 -------------------------------------------------------------------------------- { if (($0 ~ /^-+$/)) @@ -1963,7 +1963,7 @@ pq...r AAA2 kbs ddd dif cccc -------------------------------------------------------------------------------- -../../cmd/awk/qseawk --newline=on -o- -f lang-037.awk lang-037.dat &1 + ../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-037.awk lang-037.dat &1 -------------------------------------------------------------------------------- BEGIN { RS = "\n-+\n"; @@ -1991,7 +1991,7 @@ pq...r AAA2 kbs ddd dif cccc -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f quicksort.awk quicksort.dat &1 + ../../cmd/awk/.libs/qseawk -f quicksort.awk quicksort.dat &1 -------------------------------------------------------------------------------- 0.0000000000 0.11111111111111111111111111111 @@ -2010,7 +2010,7 @@ dif cccc 1.E12 99X -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f quicksort2.awk quicksort2.dat &1 + ../../cmd/awk/.libs/qseawk -f quicksort2.awk quicksort2.dat &1 -------------------------------------------------------------------------------- 0.0000000000 0.11111111111111111111111111111 @@ -2029,11 +2029,11 @@ dif cccc 1.E12 99X -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f asm.awk asm.s &1 + ../../cmd/awk/.libs/qseawk -f asm.awk asm.s &1 -------------------------------------------------------------------------------- 549 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f stripcomment.awk stripcomment.dat &1 + ../../cmd/awk/.libs/qseawk -f stripcomment.awk stripcomment.dat &1 -------------------------------------------------------------------------------- @@ -2045,7 +2045,7 @@ int main () return 0; } -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f wordfreq.awk wordfreq.awk &1 + ../../cmd/awk/.libs/qseawk -f wordfreq.awk wordfreq.awk &1 -------------------------------------------------------------------------------- distinctions 1 list 1 @@ -2073,7 +2073,7 @@ print 2 frequencies 1 case 1 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f hanoi.awk &1 + ../../cmd/awk/.libs/qseawk -f hanoi.awk &1 -------------------------------------------------------------------------------- 0 54321 1 @@ -2204,7 +2204,7 @@ case 1 2 -------------------------------------------------------------------------------- -../../cmd/awk/qseawk -f indent.awk indent.dat &1 + ../../cmd/awk/.libs/qseawk -f indent.awk indent.dat &1 -------------------------------------------------------------------------------- #!/bin/sh diff --git a/qse/regress/awk/regress.sh b/qse/regress/awk/regress.sh index 6fed91be..b137931b 100755 --- a/qse/regress/awk/regress.sh +++ b/qse/regress/awk/regress.sh @@ -36,7 +36,15 @@ print_usage() # MAIN # ################### -QSEAWK=${QSEAWK:=../../cmd/awk/qseawk} +[ -z "${QSEAWK}" ] && { + QSEAWK=../../cmd/awk/.libs/qseawk + [ -f "${QSEAWK}" ] || QSEAWK=../../cmd/awk/qseawk +} +[ -f "${QSEAWK}" -a -x "${QSEAWK}" ] || { + echo_so "the executable '${QSEAWK}' is not found or not executable" + exit 1 +} + TMPFILE="${TMPFILE:=./regress.temp}" OUTFILE="${OUTFILE:=./regress.out}" @@ -158,6 +166,7 @@ PROGS=" run_scripts() { + local valgrind="${1}" echo "${PROGS}" > "${TMPFILE}" while read prog @@ -181,8 +190,8 @@ run_scripts() [ -z "${redinfile}" ] && redinfile="/dev/stdin" - echo_title "${QSEAWK} ${awkopts} -f ${orgscript} ${datafile} <${redinfile} 2>&1" - ${QSEAWK} -o "${script}.dp" ${awkopts} -f ${script} ${datafile} <${redinfile} 2>&1 + echo_title "${valgrind} ${QSEAWK} ${awkopts} -f ${orgscript} ${datafile} <${redinfile} 2>&1" + ${valgrind} ${QSEAWK} -o "${script}.dp" ${awkopts} -f ${script} ${datafile} <${redinfile} 2>&1 done < "${TMPFILE}" @@ -226,6 +235,15 @@ test) rm -f "${OUTFILE}.test" echo_so "TEST OK" ;; +leakcheck) + valgrind="`which valgrind 2> /dev/null || echo ""`" + [ -z "${valgrind}" ] && { + echo_so "valgrind not found. cannot perform this test" + exit 1 + } + run_scripts "${valgrind} --leak-check=full --show-reachable=yes --track-fds=yes" 2>&1 > "${OUTFILE}.test" + echo_so "Inspect the '${OUTFILE}.test' file for any memory and file descriptor leaks." + ;; *) echo_so "USAGE: $0 init" echo_so " $0 test" diff --git a/qse/regress/sed/regress.sh b/qse/regress/sed/regress.sh new file mode 100755 index 00000000..b1028c9a --- /dev/null +++ b/qse/regress/sed/regress.sh @@ -0,0 +1,135 @@ +#!/bin/sh + +echo_so() +{ + tput smso + while [ $# -gt 0 ] + do + echo -n "$1 " + shift + done + echo + tput rmso +} + +echo_title() +{ + echo "--------------------------------------------------------------------------------" + while [ $# -gt 0 ] + do + echo -n "$1 " + echo -n "$1 " >/dev/stderr + shift + done + echo + echo > /dev/stderr + echo "--------------------------------------------------------------------------------" +} + +print_usage() +{ + echo_so "Usage: $0 init" + echo_so " $0 test" +} + +################### +# MAIN # +################### + +[ -z "${QSESED}" ] && { + QSESED=../../cmd/sed/.libs/qsesed + [ -f "${QSESED}" ] || QSESED=../../cmd/sed/qsesed +} +[ -f "${QSESED}" -a -x "${QSESED}" ] || { + echo_so "the executable '${QSESED}' is not found or not executable" + exit 1 +} + +TMPFILE="${TMPFILE:=./regress.temp}" +OUTFILE="${OUTFILE:=./regress.out}" + +PROGS=" + 001.sed/001.dat//-n + 002.sed/002.dat// + 003.sed/003.dat// + 004.sed/004.dat// +" + +[ -x "${QSESED}" ] || +{ + echo "ERROR: ${QSESED} not found" + exit 1; +} + +run_scripts() +{ + local valgrind="$1" + echo "${PROGS}" > "${TMPFILE}" + + while read prog + do + [ -z "${prog}" ] && continue + + local script="`echo ${prog} | cut -d/ -f1`" + local datafile="`echo ${prog} | cut -d/ -f2`" + local redinfile="`echo ${prog} | cut -d/ -f3`" + local options="`echo ${prog} | cut -d/ -f4`" + + [ -z "${script}" ] && continue + + [ -f "${script}" ] || + { + echo_so "${script} not found" + continue + } + + [ -z "${redinfile}" ] && redinfile="/dev/stdin" + + echo_title "${valgrind} ${QSESED} ${options} -f ${script} ${datafile} <${redinfile} 2>&1" + ${valgrind} ${QSESED} ${options} -f ${script} ${datafile} <${redinfile} 2>&1 + + done < "${TMPFILE}" + + rm -f "${TMPFILE}" +} + +case $1 in +init) + rm -f *.dp + run_scripts > "${OUTFILE}" + rm -f *.dp + echo_so "INIT OK" + ;; +test) + run_scripts > "${OUTFILE}.test" + + # diff -q is not supported on old platforms. + # redirect output to /dev/null instead. + diff "${OUTFILE}" "${OUTFILE}.test" > /dev/null || { + echo_so "ERROR: Difference is found between expected output and actual output." + echo_so " The expected output is stored in '${OUTFILE}'." + echo_so " The actual output is stored in '${OUTFILE}.test'." + echo_so " You may execute 'diff ${OUTFILE} ${OUTFILE}.test' for more info." + exit 1 + } + rm -f "${OUTFILE}.test" + echo_so "TEST OK" + ;; +leakcheck) + valgrind="`which valgrind 2> /dev/null || echo ""`" + [ -z "${valgrind}" ] && { + echo_so "valgrind not found. cannot perform this test" + exit 1 + } + run_scripts "${valgrind} --leak-check=full --show-reachable=yes --track-fds=yes" 2>&1 > "${OUTFILE}.test" + echo_so "Inspect the '${OUTFILE}.test' file for any memory and file descriptor leaks." + ;; +*) + echo_so "USAGE: $0 init" + echo_so " $0 test" + echo_so " $0 leakcheck" + exit 1 + ;; +esac + +exit 0