diff --git a/ase/awk/misc.c b/ase/awk/misc.c index 05cdef48..be321180 100644 --- a/ase/awk/misc.c +++ b/ase/awk/misc.c @@ -1,5 +1,5 @@ /* - * $Id: misc.c,v 1.43 2006-11-29 02:54:15 bacon Exp $ + * $Id: misc.c,v 1.44 2006-12-04 07:17:12 bacon Exp $ */ #include @@ -839,6 +839,11 @@ ase_char_t* ase_awk_strxntok ( } } } + + /* TODO: verify the following statement... */ + if (delim_mode == __DELIM_SPACES && + delim_len == 1 && + delim[0] != ASE_T(' ')) delim_mode = __DELIM_NOSPACES; } if (delim_mode == __DELIM_NULL) diff --git a/ase/awk/rec.c b/ase/awk/rec.c index 2ca080b1..3a8ffed5 100644 --- a/ase/awk/rec.c +++ b/ase/awk/rec.c @@ -1,5 +1,5 @@ /* - * $Id: rec.c,v 1.8 2006-11-29 02:54:16 bacon Exp $ + * $Id: rec.c,v 1.9 2006-12-04 07:17:12 bacon Exp $ */ #include @@ -10,7 +10,8 @@ static int __recomp_record_fields ( const ase_char_t* str, ase_size_t len); int ase_awk_setrec ( - ase_awk_run_t* run, ase_size_t idx, const ase_char_t* str, ase_size_t len) + ase_awk_run_t* run, ase_size_t idx, + const ase_char_t* str, ase_size_t len) { ase_awk_val_t* v; int errnum; diff --git a/ase/test/awk/cou-001.out b/ase/test/awk/cou-001.out new file mode 100644 index 00000000..b3842fbd --- /dev/null +++ b/ase/test/awk/cou-001.out @@ -0,0 +1,15 @@ +{ + print $1,$3; +} + +USSR 275 +Canada 25 +China 1032 +USA 237 +Brazil 134 +India 746 +Mexico 78 +France 55 +Japan 120 +Germany 61 +England 56 diff --git a/ase/test/awk/cou-002.out b/ase/test/awk/cou-002.out new file mode 100644 index 00000000..83c57fa9 --- /dev/null +++ b/ase/test/awk/cou-002.out @@ -0,0 +1,29 @@ +BEGIN { + __global7 = " "; + printf ("%10s %6s %5s %s\n\n","COUNTRY","AREA","POP","CONTINENT"); +} + +{ + printf ("%10s %6d %5d %s\n",$1,$2,$3,$4); + area = (area + $2); + pop = (pop + $3); +} + +END { + printf ("\n%10s %6d %5d\n","TOTAL",area,pop); +} + COUNTRY AREA POP CONTINENT + + USSR 8649 275 Asia + Canada 3852 25 North America + China 3705 1032 Asia + USA 3615 237 North America + Brazil 3286 134 South America + India 1267 746 Asia + Mexico 762 78 North America + France 211 55 Europe + Japan 144 120 Asia + Germany 96 61 Europe + England 94 56 Europe + + TOTAL 25681 2819 diff --git a/ase/test/awk/cou-003.out b/ase/test/awk/cou-003.out new file mode 100644 index 00000000..05417c26 --- /dev/null +++ b/ase/test/awk/cou-003.out @@ -0,0 +1,6 @@ +(($3 / $2) >= 0.5) + +India 1267 746 Asia +Japan 144 120 Asia +Germany 96 61 Europe +England 94 56 Europe diff --git a/ase/test/awk/cou-004.out b/ase/test/awk/cou-004.out new file mode 100644 index 00000000..bb237a77 --- /dev/null +++ b/ase/test/awk/cou-004.out @@ -0,0 +1,5 @@ +($0 >= "M") + +USSR 8649 275 Asia +USA 3615 237 North America +Mexico 762 78 North America diff --git a/ase/test/awk/cou-005.out b/ase/test/awk/cou-005.out new file mode 100644 index 00000000..345dae8f --- /dev/null +++ b/ase/test/awk/cou-005.out @@ -0,0 +1,6 @@ +($1 < $4) + +Canada 3852 25 North America +Brazil 3286 134 South America +Mexico 762 78 North America +England 94 56 Europe diff --git a/ase/test/awk/cou-006.out b/ase/test/awk/cou-006.out new file mode 100644 index 00000000..7de5b826 --- /dev/null +++ b/ase/test/awk/cou-006.out @@ -0,0 +1,5 @@ +($2 < $3) + +India 1267 746 Asia +Mexico 762 78 North America +France 211 55 Europe diff --git a/ase/test/awk/cou-007.out b/ase/test/awk/cou-007.out new file mode 100644 index 00000000..5b1f4af7 --- /dev/null +++ b/ase/test/awk/cou-007.out @@ -0,0 +1,6 @@ +/Asia/ + +USSR 8649 275 Asia +China 3705 1032 Asia +India 1267 746 Asia +Japan 144 120 Asia diff --git a/ase/test/awk/cou-008.out b/ase/test/awk/cou-008.out new file mode 100644 index 00000000..2155c8eb --- /dev/null +++ b/ase/test/awk/cou-008.out @@ -0,0 +1,6 @@ +($4 !~ /Asia/) + +USSR 8649 275 Asia +China 3705 1032 Asia +India 1267 746 Asia +Japan 144 120 Asia diff --git a/ase/test/awk/cou-009.out b/ase/test/awk/cou-009.out new file mode 100644 index 00000000..735cd69e --- /dev/null +++ b/ase/test/awk/cou-009.out @@ -0,0 +1,9 @@ +($4 + /Asia/) + +Canada 3852 25 North America +USA 3615 237 North America +Brazil 3286 134 South America +Mexico 762 78 North America +France 211 55 Europe +Germany 96 61 Europe +England 94 56 Europe diff --git a/ase/test/awk/cou-010.out b/ase/test/awk/cou-010.out new file mode 100644 index 00000000..b25d2248 --- /dev/null +++ b/ase/test/awk/cou-010.out @@ -0,0 +1,6 @@ +($0 !~ /Asia/) + +USSR 8649 275 Asia +China 3705 1032 Asia +India 1267 746 Asia +Japan 144 120 Asia diff --git a/ase/test/awk/cou-011.out b/ase/test/awk/cou-011.out new file mode 100644 index 00000000..78baafc0 --- /dev/null +++ b/ase/test/awk/cou-011.out @@ -0,0 +1,2 @@ +($2 + /^[0-9]+$/) + diff --git a/ase/test/awk/cou-012.awk b/ase/test/awk/cou-012.awk new file mode 100644 index 00000000..7147bc42 --- /dev/null +++ b/ase/test/awk/cou-012.awk @@ -0,0 +1 @@ +$4 == "Asia" && $3 > 500 diff --git a/ase/test/awk/cou-012.out b/ase/test/awk/cou-012.out new file mode 100644 index 00000000..636c837d --- /dev/null +++ b/ase/test/awk/cou-012.out @@ -0,0 +1,4 @@ +(($4 == "Asia") && ($3 > 500)) + +China 3705 1032 Asia +India 1267 746 Asia diff --git a/ase/test/awk/cou-013.awk b/ase/test/awk/cou-013.awk new file mode 100644 index 00000000..8926c135 --- /dev/null +++ b/ase/test/awk/cou-013.awk @@ -0,0 +1 @@ +$4 == "Asia" || $4 == "Europe" diff --git a/ase/test/awk/cou-013.out b/ase/test/awk/cou-013.out new file mode 100644 index 00000000..b0f594db --- /dev/null +++ b/ase/test/awk/cou-013.out @@ -0,0 +1,9 @@ +(($4 == "Asia") || ($4 == "Europe")) + +USSR 8649 275 Asia +China 3705 1032 Asia +India 1267 746 Asia +France 211 55 Europe +Japan 144 120 Asia +Germany 96 61 Europe +England 94 56 Europe diff --git a/ase/test/awk/cou-014.awk b/ase/test/awk/cou-014.awk new file mode 100644 index 00000000..84fe7474 --- /dev/null +++ b/ase/test/awk/cou-014.awk @@ -0,0 +1 @@ +$4 ~ /^(Asia|Europe)$/ diff --git a/ase/test/awk/cou-014.out b/ase/test/awk/cou-014.out new file mode 100644 index 00000000..36aefce0 --- /dev/null +++ b/ase/test/awk/cou-014.out @@ -0,0 +1,9 @@ +($4 !~ /^(Asia|Europe)$/) + +USSR 8649 275 Asia +China 3705 1032 Asia +India 1267 746 Asia +France 211 55 Europe +Japan 144 120 Asia +Germany 96 61 Europe +England 94 56 Europe diff --git a/ase/test/awk/cou-015.awk b/ase/test/awk/cou-015.awk new file mode 100644 index 00000000..8afea30d --- /dev/null +++ b/ase/test/awk/cou-015.awk @@ -0,0 +1 @@ +/Asia/ || /Europe/ diff --git a/ase/test/awk/cou-015.out b/ase/test/awk/cou-015.out new file mode 100644 index 00000000..28616eda --- /dev/null +++ b/ase/test/awk/cou-015.out @@ -0,0 +1,9 @@ +(/Asia/ || /Europe/) + +USSR 8649 275 Asia +China 3705 1032 Asia +India 1267 746 Asia +France 211 55 Europe +Japan 144 120 Asia +Germany 96 61 Europe +England 94 56 Europe diff --git a/ase/test/awk/cou-016.awk b/ase/test/awk/cou-016.awk new file mode 100644 index 00000000..b8c94a01 --- /dev/null +++ b/ase/test/awk/cou-016.awk @@ -0,0 +1 @@ +/Asia|Europe/ diff --git a/ase/test/awk/cou-016.out b/ase/test/awk/cou-016.out new file mode 100644 index 00000000..68a43190 --- /dev/null +++ b/ase/test/awk/cou-016.out @@ -0,0 +1,9 @@ +/Asia|Europe/ + +USSR 8649 275 Asia +China 3705 1032 Asia +India 1267 746 Asia +France 211 55 Europe +Japan 144 120 Asia +Germany 96 61 Europe +England 94 56 Europe diff --git a/ase/test/awk/cou-017.awk b/ase/test/awk/cou-017.awk new file mode 100644 index 00000000..bf01d88f --- /dev/null +++ b/ase/test/awk/cou-017.awk @@ -0,0 +1 @@ +/Canada/, /USA/ diff --git a/ase/test/awk/cou-017.out b/ase/test/awk/cou-017.out new file mode 100644 index 00000000..0beca645 --- /dev/null +++ b/ase/test/awk/cou-017.out @@ -0,0 +1,5 @@ +/Canada/,/USA/ + +Canada 3852 25 North America +China 3705 1032 Asia +USA 3615 237 North America diff --git a/ase/test/awk/cou-018.awk b/ase/test/awk/cou-018.awk new file mode 100644 index 00000000..851a3d3c --- /dev/null +++ b/ase/test/awk/cou-018.awk @@ -0,0 +1 @@ +/Eurpoe/, /Africa/ diff --git a/ase/test/awk/cou-018.out b/ase/test/awk/cou-018.out new file mode 100644 index 00000000..77442148 --- /dev/null +++ b/ase/test/awk/cou-018.out @@ -0,0 +1,2 @@ +/Eurpoe/,/Africa/ + diff --git a/ase/test/awk/cou-019.awk b/ase/test/awk/cou-019.awk new file mode 100644 index 00000000..e4f9bdf0 --- /dev/null +++ b/ase/test/awk/cou-019.awk @@ -0,0 +1 @@ +FNR == 1, FNR == 5 { print FILENAME ": " $0; } diff --git a/ase/test/awk/cou-019.out b/ase/test/awk/cou-019.out new file mode 100644 index 00000000..8597c04c --- /dev/null +++ b/ase/test/awk/cou-019.out @@ -0,0 +1,9 @@ +(__global6 == 1),(__global6 == 5) { + print ((__global5 ~ ": ") ~ $0); +} + +cou-en.data: USSR 8649 275 Asia +cou-en.data: Canada 3852 25 North America +cou-en.data: China 3705 1032 Asia +cou-en.data: USA 3615 237 North America +cou-en.data: Brazil 3286 134 South America diff --git a/ase/test/awk/cou-020.awk b/ase/test/awk/cou-020.awk new file mode 100644 index 00000000..fb1ac184 --- /dev/null +++ b/ase/test/awk/cou-020.awk @@ -0,0 +1 @@ +FNR <= 5 { print FILENAME ": " $0; } diff --git a/ase/test/awk/cou-020.out b/ase/test/awk/cou-020.out new file mode 100644 index 00000000..cedafc8f --- /dev/null +++ b/ase/test/awk/cou-020.out @@ -0,0 +1,9 @@ +(__global6 <= 5) { + print ((__global5 ~ ": ") ~ $0); +} + +cou-en.data: USSR 8649 275 Asia +cou-en.data: Canada 3852 25 North America +cou-en.data: China 3705 1032 Asia +cou-en.data: USA 3615 237 North America +cou-en.data: Brazil 3286 134 South America diff --git a/ase/test/awk/cou-021.awk b/ase/test/awk/cou-021.awk new file mode 100644 index 00000000..dfcc0b09 --- /dev/null +++ b/ase/test/awk/cou-021.awk @@ -0,0 +1 @@ +$4 == "Asia" { print $1, 1000 * $2; } diff --git a/ase/test/awk/cou-021.out b/ase/test/awk/cou-021.out new file mode 100644 index 00000000..7dfe4dad --- /dev/null +++ b/ase/test/awk/cou-021.out @@ -0,0 +1,8 @@ +($4 == "Asia") { + print $1,(1000 * $2); +} + +USSR 8649000 +China 3705000 +India 1267000 +Japan 144000 diff --git a/ase/test/awk/cou-022.awk b/ase/test/awk/cou-022.awk new file mode 100644 index 00000000..df0e5a32 --- /dev/null +++ b/ase/test/awk/cou-022.awk @@ -0,0 +1,6 @@ +BEGIN { FS = "\t"; OFS = "\t"; } +#BEGIN { FS = OFS = "\t"; } +$4 == "North America" { $4 = "NA"; } +$4 == "South America" { $4 = "SA"; } + { print; } + diff --git a/ase/test/awk/cou-022.out b/ase/test/awk/cou-022.out new file mode 100644 index 00000000..67a859cc --- /dev/null +++ b/ase/test/awk/cou-022.out @@ -0,0 +1,28 @@ +BEGIN { + __global7 = " "; + __global13 = " "; +} + +($4 == "North America") { + $4 = "NA"; +} + +($4 == "South America") { + $4 = "SA"; +} + +{ + print; +} + +USSR 8649 275 Asia +Canada 3852 25 NA +China 3705 1032 Asia +USA 3615 237 NA +Brazil 3286 134 SA +India 1267 746 Asia +Mexico 762 78 NA +France 211 55 Europe +Japan 144 120 Asia +Germany 96 61 Europe +England 94 56 Europe diff --git a/ase/test/awk/emp-021.out b/ase/test/awk/emp-021.out index 676a8bdc..fb93de1b 100644 --- a/ase/test/awk/emp-021.out +++ b/ase/test/awk/emp-021.out @@ -1,5 +1,5 @@ { - names = ((names $1) " "); + names = ((names ~ $1) ~ " "); } END {