diff --git a/usr.bin/awk/proctab.c b/usr.bin/awk/proctab.c new file mode 100644 index 0000000..305769b --- /dev/null +++ b/usr.bin/awk/proctab.c @@ -0,0 +1,207 @@ +/* $Id: proctab.c,v 1.1 1998/04/07 17:03:52 tribby Exp $ */ + +#include +#include "awk.h" +#include "ytab.h" + +static char *printname[92] = { + (char *) "FIRSTTOKEN", /* 257 */ + (char *) "PROGRAM", /* 258 */ + (char *) "PASTAT", /* 259 */ + (char *) "PASTAT2", /* 260 */ + (char *) "XBEGIN", /* 261 */ + (char *) "XEND", /* 262 */ + (char *) "NL", /* 263 */ + (char *) "ARRAY", /* 264 */ + (char *) "MATCH", /* 265 */ + (char *) "NOTMATCH", /* 266 */ + (char *) "MATCHOP", /* 267 */ + (char *) "FINAL", /* 268 */ + (char *) "DOT", /* 269 */ + (char *) "ALL", /* 270 */ + (char *) "CCL", /* 271 */ + (char *) "NCCL", /* 272 */ + (char *) "CHAR", /* 273 */ + (char *) "OR", /* 274 */ + (char *) "STAR", /* 275 */ + (char *) "QUEST", /* 276 */ + (char *) "PLUS", /* 277 */ + (char *) "AND", /* 278 */ + (char *) "BOR", /* 279 */ + (char *) "APPEND", /* 280 */ + (char *) "EQ", /* 281 */ + (char *) "GE", /* 282 */ + (char *) "GT", /* 283 */ + (char *) "LE", /* 284 */ + (char *) "LT", /* 285 */ + (char *) "NE", /* 286 */ + (char *) "IN", /* 287 */ + (char *) "ARG", /* 288 */ + (char *) "BLTIN", /* 289 */ + (char *) "BREAK", /* 290 */ + (char *) "CLOSE", /* 291 */ + (char *) "CONTINUE", /* 292 */ + (char *) "DELETE", /* 293 */ + (char *) "DO", /* 294 */ + (char *) "EXIT", /* 295 */ + (char *) "FOR", /* 296 */ + (char *) "FUNC", /* 297 */ + (char *) "SUB", /* 298 */ + (char *) "GSUB", /* 299 */ + (char *) "IF", /* 300 */ + (char *) "INDEX", /* 301 */ + (char *) "LSUBSTR", /* 302 */ + (char *) "MATCHFCN", /* 303 */ + (char *) "NEXT", /* 304 */ + (char *) "NEXTFILE", /* 305 */ + (char *) "ADD", /* 306 */ + (char *) "MINUS", /* 307 */ + (char *) "MULT", /* 308 */ + (char *) "DIVIDE", /* 309 */ + (char *) "MOD", /* 310 */ + (char *) "ASSIGN", /* 311 */ + (char *) "ASGNOP", /* 312 */ + (char *) "ADDEQ", /* 313 */ + (char *) "SUBEQ", /* 314 */ + (char *) "MULTEQ", /* 315 */ + (char *) "DIVEQ", /* 316 */ + (char *) "MODEQ", /* 317 */ + (char *) "POWEQ", /* 318 */ + (char *) "PRINT", /* 319 */ + (char *) "PRINTF", /* 320 */ + (char *) "SPRINTF", /* 321 */ + (char *) "ELSE", /* 322 */ + (char *) "INTEST", /* 323 */ + (char *) "CONDEXPR", /* 324 */ + (char *) "POSTINCR", /* 325 */ + (char *) "PREINCR", /* 326 */ + (char *) "POSTDECR", /* 327 */ + (char *) "PREDECR", /* 328 */ + (char *) "VAR", /* 329 */ + (char *) "IVAR", /* 330 */ + (char *) "VARNF", /* 331 */ + (char *) "CALL", /* 332 */ + (char *) "NUMBER", /* 333 */ + (char *) "STRING", /* 334 */ + (char *) "REGEXPR", /* 335 */ + (char *) "GETLINE", /* 336 */ + (char *) "RETURN", /* 337 */ + (char *) "SPLIT", /* 338 */ + (char *) "SUBSTR", /* 339 */ + (char *) "WHILE", /* 340 */ + (char *) "CAT", /* 341 */ + (char *) "NOT", /* 342 */ + (char *) "UMINUS", /* 343 */ + (char *) "POWER", /* 344 */ + (char *) "DECR", /* 345 */ + (char *) "INCR", /* 346 */ + (char *) "INDIRECT", /* 347 */ + (char *) "LASTTOKEN", /* 348 */ +}; + + +Cell *(*proctab[92])(Node **, int) = { + nullproc, /* FIRSTTOKEN */ + program, /* PROGRAM */ + pastat, /* PASTAT */ + dopa2, /* PASTAT2 */ + nullproc, /* XBEGIN */ + nullproc, /* XEND */ + nullproc, /* NL */ + array, /* ARRAY */ + matchop, /* MATCH */ + matchop, /* NOTMATCH */ + nullproc, /* MATCHOP */ + nullproc, /* FINAL */ + nullproc, /* DOT */ + nullproc, /* ALL */ + nullproc, /* CCL */ + nullproc, /* NCCL */ + nullproc, /* CHAR */ + nullproc, /* OR */ + nullproc, /* STAR */ + nullproc, /* QUEST */ + nullproc, /* PLUS */ + boolop, /* AND */ + boolop, /* BOR */ + nullproc, /* APPEND */ + relop, /* EQ */ + relop, /* GE */ + relop, /* GT */ + relop, /* LE */ + relop, /* LT */ + relop, /* NE */ + instat, /* IN */ + arg, /* ARG */ + bltin, /* BLTIN */ + jump, /* BREAK */ + closefile, /* CLOSE */ + jump, /* CONTINUE */ + awkdelete, /* DELETE */ + dostat, /* DO */ + jump, /* EXIT */ + forstat, /* FOR */ + nullproc, /* FUNC */ + sub, /* SUB */ + gsub, /* GSUB */ + ifstat, /* IF */ + sindex, /* INDEX */ + nullproc, /* LSUBSTR */ + matchop, /* MATCHFCN */ + jump, /* NEXT */ + jump, /* NEXTFILE */ + arith, /* ADD */ + arith, /* MINUS */ + arith, /* MULT */ + arith, /* DIVIDE */ + arith, /* MOD */ + assign, /* ASSIGN */ + nullproc, /* ASGNOP */ + assign, /* ADDEQ */ + assign, /* SUBEQ */ + assign, /* MULTEQ */ + assign, /* DIVEQ */ + assign, /* MODEQ */ + assign, /* POWEQ */ + printstat, /* PRINT */ + awkprintf, /* PRINTF */ + awksprintf, /* SPRINTF */ + nullproc, /* ELSE */ + intest, /* INTEST */ + condexpr, /* CONDEXPR */ + incrdecr, /* POSTINCR */ + incrdecr, /* PREINCR */ + incrdecr, /* POSTDECR */ + incrdecr, /* PREDECR */ + nullproc, /* VAR */ + nullproc, /* IVAR */ + getnf, /* VARNF */ + call, /* CALL */ + nullproc, /* NUMBER */ + nullproc, /* STRING */ + nullproc, /* REGEXPR */ + getline, /* GETLINE */ + jump, /* RETURN */ + split, /* SPLIT */ + substr, /* SUBSTR */ + whilestat, /* WHILE */ + cat, /* CAT */ + boolop, /* NOT */ + arith, /* UMINUS */ + arith, /* POWER */ + nullproc, /* DECR */ + nullproc, /* INCR */ + indirect, /* INDIRECT */ + nullproc, /* LASTTOKEN */ +}; + +char *tokname(int n) +{ + static char buf[100]; + + if (n < FIRSTTOKEN || n > LASTTOKEN) { + sprintf(buf, "token %d", n); + return buf; + } + return printname[n-FIRSTTOKEN]; +} diff --git a/usr.bin/awk/tests/addr.1 b/usr.bin/awk/tests/addr.1 new file mode 100644 index 0000000..e8cb2af --- /dev/null +++ b/usr.bin/awk/tests/addr.1 @@ -0,0 +1,16 @@ +Adam Smith +1234 Wall St., Apt. 5C +New York, NY 10021 +212 555-4321 + +David W. Copperfield +221 Dickens Lane +Monterey, CA 93940 +408 555-0041 +work phone 408 555-6532 +Mary, birthday January 30 + +Canadian Consulate +555 Fifth Ave +New York, NY +212 586-2400 diff --git a/usr.bin/awk/tests/array.awk b/usr.bin/awk/tests/array.awk new file mode 100644 index 0000000..97067d0 --- /dev/null +++ b/usr.bin/awk/tests/array.awk @@ -0,0 +1,19 @@ +# Read values into an array + +$1 == "REMOVE" { delete value[$2]; next } + +$1 == "RESET" {delete value; next} + +$1 == "SKIP" {nextfile} + +$1 == "PRINT" {printarray(value); next} + +{ value[$1] = $2 } + +END { printarray(value) } + +function printarray(A, key) { + print "Values in array"; + for (key in A) print " ",key,A[key]; + print " "; +} diff --git a/usr.bin/awk/tests/array1.data b/usr.bin/awk/tests/array1.data new file mode 100644 index 0000000..8e0dea5 --- /dev/null +++ b/usr.bin/awk/tests/array1.data @@ -0,0 +1,21 @@ +one 1 +two 2 +three 3 +four 4 +five 5 +six 6 +seven 7 +eight 8 +nine 9 +PRINT +REMOVE nine +REMOVE bad +PRINT +RESET +one I +two II +three III +four IIII +SKIP +badentry BAD +PRINT diff --git a/usr.bin/awk/tests/array2.data b/usr.bin/awk/tests/array2.data new file mode 100644 index 0000000..c169834 --- /dev/null +++ b/usr.bin/awk/tests/array2.data @@ -0,0 +1,3 @@ +four IV +five V +six VI diff --git a/usr.bin/awk/tests/asm b/usr.bin/awk/tests/asm new file mode 100644 index 0000000..cb086b7 --- /dev/null +++ b/usr.bin/awk/tests/asm @@ -0,0 +1,48 @@ +# asm - assembler and interpreter for simple computer +# usage: awk -f asm program-file data-files... + +BEGIN { + srcfile = ARGV[1] + ARGV[1] = "" # remaining files are data + tempfile = "/tmp/asm.temp" + n = split("const get put ld st add sub jpos jz j halt", x) + for (i = 1; i <= n; i++) # create table of op codes + op[x[i]] = i-1 + +# ASSEMBLER PASS 1 + FS = "[ \t]+" + while (getline 0) { + sub(/#.*/, "") # strip comments + symtab[$1] = nextmem # remember label location + if ($2 != "") { # save op, addr if present + print $2 "\t" $3 >tempfile + nextmem++ + } + } + close(tempfile) + +# ASSEMBLER PASS 2 + nextmem = 0 + while (getline 0) { + if ($2 !~ /^[0-9]*$/) # if symbolic addr, + $2 = symtab[$2] # replace by numeric value + mem[nextmem++] = 1000 * op[$1] + $2 # pack into word + } + +# INTERPRETER + for (pc = 0; pc >= 0; ) { + addr = mem[pc] % 1000 + code = int(mem[pc++] / 1000) + if (code == op["get"]) { getline acc } + else if (code == op["put"]) { print acc } + else if (code == op["st"]) { mem[addr] = acc } + else if (code == op["ld"]) { acc = mem[addr] } + else if (code == op["add"]) { acc += mem[addr] } + else if (code == op["sub"]) { acc -= mem[addr] } + else if (code == op["jpos"]) { if (acc > 0) pc = addr } + else if (code == op["jz"]) { if (acc == 0) pc = addr } + else if (code == op["j"]) { pc = addr } + else if (code == op["halt"]) { pc = -1 } + else { pc = -1 } + } +} diff --git a/usr.bin/awk/tests/asm.print b/usr.bin/awk/tests/asm.print new file mode 100644 index 0000000..a2cbcd3 --- /dev/null +++ b/usr.bin/awk/tests/asm.print @@ -0,0 +1,37 @@ +# asm - assembler and interpreter for simple computer +# usage: awk -f asm program-file data-files... + +# this is a special version to produce a listing + +BEGIN { + srcfile = ARGV[1] + ARGV[1] = "" # remaining files are data + tempfile = "/tmp/asm.temp" + n = split("const get put ld st add sub jpos jz j halt", x) + for (i = 1; i <= n; i++) # create table of op codes + op[x[i]] = i-1 + +# ASSEMBLER PASS 1 + nextmem = 0 # new + FS = "[ \t]+" + while (getline 0) { + input[nextmem] = $0 # new: remember source line + sub(/#.*/, "") # strip comments + symtab[$1] = nextmem # remember label location + if ($2 != "") { # save op, addr if present + print $2 "\t" $3 >tempfile + nextmem++ + } + } + close(tempfile) + +# ASSEMBLER PASS 2 + nextmem = 0 + while (getline 0) { + if ($2 !~ /^[0-9]*$/) # if symbolic addr, + $2 = symtab[$2] # replace by numeric value + mem[nextmem++] = 1000 * op[$1] + $2 # pack into word + } + for (i = 0; i < nextmem; i++) # new: print memory + printf("%3d: %05d %s\n", i, mem[i], input[i]) # new +} diff --git a/usr.bin/awk/tests/awk.parser b/usr.bin/awk/tests/awk.parser new file mode 100644 index 0000000..e341feb --- /dev/null +++ b/usr.bin/awk/tests/awk.parser @@ -0,0 +1,171 @@ +# awk.parser - recursive-descent translator for part of awk +# input: awk program (very restricted subset) +# output: C code to implement the awk program + +BEGIN { program() } + +function advance() { # lexical analyzer; returns next token + if (tok == "(eof)") return "(eof)" + while (length(line) == 0) + if (getline line == 0) + return tok = "(eof)" + sub(/^[ \t]+/, "", line) # remove white space + if (match(line, /^[A-Za-z_][A-Za-z_0-9]*/) || # identifier + match(line, /^-?([0-9]+\.?[0-9]*|\.[0-9]+)/) || # number + match(line, /^(<|<=|==|!=|>=|>)/) || # relational + match(line, /^./)) { # everything else + tok = substr(line, 1, RLENGTH) + line = substr(line, RLENGTH+1) + return tok + } + error("line " NR " incomprehensible at " line) +} +function gen(s) { # print s with nt leading tabs + printf("%s%s\n", substr("\t\t\t\t\t\t\t\t\t", 1, nt), s) +} +function eat(s) { # read next token if s == tok + if (tok != s) error("line " NF ": saw " tok ", expected " s) + advance() +} +function nl() { # absorb newlines and semicolons + while (tok == "\n" || tok == ";") + advance() +} +function error(s) { print "Error: " s | "cat 1>&2"; exit 1 } + +function program() { + advance() + if (tok == "BEGIN") { eat("BEGIN"); statlist() } + pastats() + if (tok == "END") { eat("END"); statlist() } + if (tok != "(eof)") error("program continues after END") +} +function pastats() { + gen("while (getrec()) {"); nt++ + while (tok != "END" && tok != "(eof)") pastat() + nt--; gen("}") +} +function pastat() { # pattern-action statement + if (tok == "{") # action only + statlist() + else { # pattern-action + gen("if (" pattern() ") {"); nt++ + if (tok == "{") statlist() + else # default action is print $0 + gen("print(field(0));") + nt--; gen("}") + } +} +function pattern() { return expr() } + +function statlist() { + eat("{"); nl(); while (tok != "}") stat(); eat("}"); nl() +} + +function stat() { + if (tok == "print") { eat("print"); gen("print(" exprlist() ");") } + else if (tok == "if") ifstat() + else if (tok == "while") whilestat() + else if (tok == "{") statlist() + else gen(simplestat() ";") + nl() +} + +function ifstat() { + eat("if"); eat("("); gen("if (" expr() ") {"); eat(")"); nl(); nt++ + stat() + if (tok == "else") { # optional else + eat("else") + nl(); nt--; gen("} else {"); nt++ + stat() + } + nt--; gen("}") +} + +function whilestat() { + eat("while"); eat("("); gen("while (" expr() ") {"); eat(")"); nl() + nt++; stat(); nt--; gen("}") +} + +function simplestat( lhs) { # ident = expr | name(exprlist) + lhs = ident() + if (tok == "=") { + eat("=") + return "assign(" lhs ", " expr() ")" + } else return lhs +} + +function exprlist( n, e) { # expr , expr , ... + e = expr() # has to be at least one + for (n = 1; tok == ","; n++) { + advance() + e = e ", " expr() + } + return e +} + +function expr(e) { # rel | rel relop rel + e = rel() + while (tok ~ /<|<=|==|!=|>=|>/) { + op = tok + advance() + e = sprintf("eval(\"%s\", %s, %s)", op, e, rel()) + } + return e +} + +function rel(op, e) { # term | term [+-] term + e = term() + while (tok == "+" || tok == "-") { + op = tok + advance() + e = sprintf("eval(\"%s\", %s, %s)", op, e, term()) + } + return e +} + +function term(op, e) { # fact | fact [*/%] fact + e = fact() + while (tok == "*" || tok == "/" || tok == "%") { + op = tok + advance() + e = sprintf("eval(\"%s\", %s, %s)", op, e, fact()) + } + return e +} + +function fact( e) { # (expr) | $fact | ident | number + if (tok == "(") { + eat("("); e = expr(); eat(")") + return "(" e ")" + } else if (tok == "$") { + eat("$") + return "field(" fact() ")" + } else if (tok ~ /^[A-Za-z][A-Za-z0-9]*/) { + return ident() + } else if (tok ~ /^-?([0-9]+\.?[0-9]*|\.[0-9]+)/) { + e = tok + advance() + return "num((float)" e ")" + } else + error("unexpected " tok " at line " NR) +} + +function ident( id, e) { # name | name[expr] | name(exprlist) + if (!match(tok, /^[A-Za-z_][A-Za-z_0-9]*/)) + error("unexpected " tok " at line " NR) + id = tok + advance() + if (tok == "[") { # array + eat("["); e = expr(); eat("]") + return "array(" id ", " e ")" + } else if (tok == "(") { # function call + eat("(") + if (tok != ")") { + e = exprlist() + eat(")") + } else eat(")") + return id "(" e ")" # calls are statements + } else + return id # variable +} diff --git a/usr.bin/awk/tests/bigpop b/usr.bin/awk/tests/bigpop new file mode 100644 index 0000000..638da49 --- /dev/null +++ b/usr.bin/awk/tests/bigpop @@ -0,0 +1,6 @@ +USSR 275 +China 1032 +USA 237 +Brazil 134 +India 746 +Japan 120 diff --git a/usr.bin/awk/tests/bridge.ans b/usr.bin/awk/tests/bridge.ans new file mode 100644 index 0000000..2660464 --- /dev/null +++ b/usr.bin/awk/tests/bridge.ans @@ -0,0 +1,58 @@ +# bridge - generate random bridge hands + +BEGIN { split(permute(52,52), deck) # generate a random deck + sort(1,13); sort(14,26); sort(27,39); sort(40,52) # sort hands + prhands() # format and print the four hands +} + +function permute(k, n, i, p, r) { # generate a random permutation + srand(1); # leave out "1" for more randomness + p = " " # of k integers between 1 and n + for (i = n-k+1; i <= n; i++) + if (p ~ " " (r = int(i*rand())+1) " " ) + sub(" " r " ", " " r " " i " ", p) # put i after r in p + else p = " " r p # put r at beginning of p + return p +} + +function sort(left,right, i,j,t) { # sort hand in deck[left..right] + for (i = left+1; i <= right; i++) + for (j = i; j > left && deck[j-1] < deck[j]; j--) { + t = deck[j-1]; deck[j-1] = deck[j]; deck[j] = t + } +} + +function prhands() { # print the four hands + b = sprintf("%20s", " "); b40 = sprintf("%40s", " ") + card = 1 # global index into deck + suits(13); print b " NORTH" + print b spds; print b hrts; print b dnds; print b clbs + suits(26) # create the west hand from deck[14..26] + ws = spds substr(b40, 1, 40 - length(spds)) + wh = hrts substr(b40, 1, 40 - length(hrts)) + wd = dnds substr(b40, 1, 40 - length(dnds)) + wc = clbs substr(b40, 1, 40 - length(clbs)) + suits(39); print " WEST" sprintf("%36s", " ") "EAST" + print ws spds; print wh hrts; print wd dnds; print wc clbs + suits(52); print b " SOUTH" + print b spds; print b hrts; print b dnds; print b clbs +} + +function suits(j) { # collect suits of hand in deck[j-12..j] + for (spds = "S:"; deck[card] > 39 && card <= j; card++) + spds = spds " " fvcard(deck[card]) + for (hrts = "H:"; deck[card] > 26 && card <= j; card++) + hrts = hrts " " fvcard(deck[card]) + for (dnds = "D:"; deck[card] > 13 && card <= j; card++) + dnds = dnds " " fvcard(deck[card]) + for (clbs = "C:"; card <= j; card++) + clbs = clbs " " fvcard(deck[card]) +} + +function fvcard(i) { # compute face value of card i + if (i % 13 == 0) return "A" + else if (i % 13 == 12) return "K" + else if (i % 13 == 11) return "Q" + else if (i % 13 == 10) return "J" + else return (i % 13) + 1 +} diff --git a/usr.bin/awk/tests/bundle b/usr.bin/awk/tests/bundle new file mode 100644 index 0000000..9e5239d --- /dev/null +++ b/usr.bin/awk/tests/bundle @@ -0,0 +1,3 @@ +# bundle - combine multiple files into one + +{ print FILENAME, $0 } diff --git a/usr.bin/awk/tests/capitals b/usr.bin/awk/tests/capitals new file mode 100644 index 0000000..a9dd38a --- /dev/null +++ b/usr.bin/awk/tests/capitals @@ -0,0 +1,11 @@ +USSR Moscow +Canada Ottawa +China Beijing +USA Washington +Brazil Brasilia +India New Delhi +Mexico Mexico City +France Paris +Japan Tokyo +Germany Bonn +England London diff --git a/usr.bin/awk/tests/capitals.sort b/usr.bin/awk/tests/capitals.sort new file mode 100644 index 0000000..44c50c1 --- /dev/null +++ b/usr.bin/awk/tests/capitals.sort @@ -0,0 +1,11 @@ +Brazil Brasilia +Canada Ottawa +China Beijing +England London +France Paris +Germany Bonn +India New Delhi +Japan Tokyo +Mexico Mexico City +USA Washington +USSR Moscow diff --git a/usr.bin/awk/tests/ch1p11a.awk b/usr.bin/awk/tests/ch1p11a.awk new file mode 100644 index 0000000..82f5b90 --- /dev/null +++ b/usr.bin/awk/tests/ch1p11a.awk @@ -0,0 +1 @@ +{ printf("%-8s $%6.2f\n", $1, $2 * $3) } diff --git a/usr.bin/awk/tests/ch1p11b.awk b/usr.bin/awk/tests/ch1p11b.awk new file mode 100644 index 0000000..07325b0 --- /dev/null +++ b/usr.bin/awk/tests/ch1p11b.awk @@ -0,0 +1,2 @@ +{ product = $2 * $3; +print $1, $2, $3, product } diff --git a/usr.bin/awk/tests/ch1p12.awk b/usr.bin/awk/tests/ch1p12.awk new file mode 100644 index 0000000..73c4bd7 --- /dev/null +++ b/usr.bin/awk/tests/ch1p12.awk @@ -0,0 +1 @@ +$2 >= 5 diff --git a/usr.bin/awk/tests/ch1p13.awk b/usr.bin/awk/tests/ch1p13.awk new file mode 100644 index 0000000..7cf90e3 --- /dev/null +++ b/usr.bin/awk/tests/ch1p13.awk @@ -0,0 +1 @@ +$2 * $3 > 50 { printf("$%.2f for %s\n", $2 * $3, $1) } diff --git a/usr.bin/awk/tests/ch1p22.awk b/usr.bin/awk/tests/ch1p22.awk new file mode 100644 index 0000000..a210459 --- /dev/null +++ b/usr.bin/awk/tests/ch1p22.awk @@ -0,0 +1 @@ +!($2 < 4 && $3 < 20) diff --git a/usr.bin/awk/tests/ch1p28.awk b/usr.bin/awk/tests/ch1p28.awk new file mode 100644 index 0000000..fc8f3e1 --- /dev/null +++ b/usr.bin/awk/tests/ch1p28.awk @@ -0,0 +1 @@ +{ print NF, $1, $NF } diff --git a/usr.bin/awk/tests/ch1p30.awk b/usr.bin/awk/tests/ch1p30.awk new file mode 100644 index 0000000..30544df --- /dev/null +++ b/usr.bin/awk/tests/ch1p30.awk @@ -0,0 +1,2 @@ +BEGIN { print "NAME RATE HOURS"; print "" } + { print } diff --git a/usr.bin/awk/tests/ch1p31.awk b/usr.bin/awk/tests/ch1p31.awk new file mode 100644 index 0000000..d9dbdb1 --- /dev/null +++ b/usr.bin/awk/tests/ch1p31.awk @@ -0,0 +1,2 @@ +$3 > 15 { emp = emp + 1 } +END { print emp, "employees worked more than 15 hours" } diff --git a/usr.bin/awk/tests/ch1p32.awk b/usr.bin/awk/tests/ch1p32.awk new file mode 100644 index 0000000..1cc2d85 --- /dev/null +++ b/usr.bin/awk/tests/ch1p32.awk @@ -0,0 +1,5 @@ + { pay = pay + $2 * $3 } +END { print NR, "employees" + print "total pay is", pay + print "average pay is", pay/NR + } diff --git a/usr.bin/awk/tests/ch1p33.awk b/usr.bin/awk/tests/ch1p33.awk new file mode 100644 index 0000000..776c4a4 --- /dev/null +++ b/usr.bin/awk/tests/ch1p33.awk @@ -0,0 +1,2 @@ +$2 > maxrate { maxrate = $2; maxemp = $1 } +END { print "highest hourly rate:", maxrate, "for", maxemp } diff --git a/usr.bin/awk/tests/ch1p33a.awk b/usr.bin/awk/tests/ch1p33a.awk new file mode 100644 index 0000000..3be9851 --- /dev/null +++ b/usr.bin/awk/tests/ch1p33a.awk @@ -0,0 +1,2 @@ + { last = $0 } +END { print last } diff --git a/usr.bin/awk/tests/ch1p34.awk b/usr.bin/awk/tests/ch1p34.awk new file mode 100644 index 0000000..901a7a6 --- /dev/null +++ b/usr.bin/awk/tests/ch1p34.awk @@ -0,0 +1,2 @@ + { names = names $1 " " } +END { print names } diff --git a/usr.bin/awk/tests/ch1p40a.awk b/usr.bin/awk/tests/ch1p40a.awk new file mode 100644 index 0000000..edf891a --- /dev/null +++ b/usr.bin/awk/tests/ch1p40a.awk @@ -0,0 +1,4 @@ + { nc = nc + length($0) + 1 + nw = nw + NF + } +END { print NR, "lines,", nw, "words,", nc, "characters" } diff --git a/usr.bin/awk/tests/ch1p41.awk b/usr.bin/awk/tests/ch1p41.awk new file mode 100644 index 0000000..e5ae510 --- /dev/null +++ b/usr.bin/awk/tests/ch1p41.awk @@ -0,0 +1,7 @@ +$2 > 6 { n = n + 1; pay = pay + $2 * $3 } +END { if (n > 0) + print n, "employees, total pay is", pay, + "average pay is", pay/n + else + print "no employees are paid more than $6/hour" + } diff --git a/usr.bin/awk/tests/ch1p51.awk b/usr.bin/awk/tests/ch1p51.awk new file mode 100644 index 0000000..c1ed4a2 --- /dev/null +++ b/usr.bin/awk/tests/ch1p51.awk @@ -0,0 +1,7 @@ +# reverse - print input in reverse order by line + + { line[NR] = $0 } # remember each input line + +END { for (i = NR; i > 0; i = i - 1) + print line[i] + } diff --git a/usr.bin/awk/tests/ch1p63.awk b/usr.bin/awk/tests/ch1p63.awk new file mode 100644 index 0000000..c7077dc --- /dev/null +++ b/usr.bin/awk/tests/ch1p63.awk @@ -0,0 +1,2 @@ + { field = $NF} +END { print field } diff --git a/usr.bin/awk/tests/ch1p67.awk b/usr.bin/awk/tests/ch1p67.awk new file mode 100644 index 0000000..6923f2b --- /dev/null +++ b/usr.bin/awk/tests/ch1p67.awk @@ -0,0 +1,2 @@ + { nf = nf + NF } +END { print nf } diff --git a/usr.bin/awk/tests/ch1p69.awk b/usr.bin/awk/tests/ch1p69.awk new file mode 100644 index 0000000..b0eecc0 --- /dev/null +++ b/usr.bin/awk/tests/ch1p69.awk @@ -0,0 +1,2 @@ +$1 > max { max = $1; maxline = $0 } +END { print max, maxline } diff --git a/usr.bin/awk/tests/ch1p78.awk b/usr.bin/awk/tests/ch1p78.awk new file mode 100644 index 0000000..760b9db --- /dev/null +++ b/usr.bin/awk/tests/ch1p78.awk @@ -0,0 +1,4 @@ +{ sum = 0 + for (i = 1; i <= NF; i = i + 1) sum = sum + $i + print sum +} diff --git a/usr.bin/awk/tests/ch1p79.awk b/usr.bin/awk/tests/ch1p79.awk new file mode 100644 index 0000000..07a8542 --- /dev/null +++ b/usr.bin/awk/tests/ch1p79.awk @@ -0,0 +1,2 @@ + { for (i = 1; i <= NF; i = i + 1) sum = sum + $i } +END { print sum } diff --git a/usr.bin/awk/tests/ch2p11.awk b/usr.bin/awk/tests/ch2p11.awk new file mode 100644 index 0000000..7f54f05 --- /dev/null +++ b/usr.bin/awk/tests/ch2p11.awk @@ -0,0 +1,11 @@ +# print countries with column headers and totals + +BEGIN { FS = "\t" # make tab the field separator + 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) } diff --git a/usr.bin/awk/tests/ch2p20.awk b/usr.bin/awk/tests/ch2p20.awk new file mode 100644 index 0000000..84fe747 --- /dev/null +++ b/usr.bin/awk/tests/ch2p20.awk @@ -0,0 +1 @@ +$4 ~ /^(Asia|Europe)$/ diff --git a/usr.bin/awk/tests/ch2p20a.awk b/usr.bin/awk/tests/ch2p20a.awk new file mode 100644 index 0000000..8afea30 --- /dev/null +++ b/usr.bin/awk/tests/ch2p20a.awk @@ -0,0 +1 @@ +/Asia/ || /Europe/ diff --git a/usr.bin/awk/tests/ch2p20b.awk b/usr.bin/awk/tests/ch2p20b.awk new file mode 100644 index 0000000..b8c94a0 --- /dev/null +++ b/usr.bin/awk/tests/ch2p20b.awk @@ -0,0 +1 @@ +/Asia|Europe/ diff --git a/usr.bin/awk/tests/ch2p21.awk b/usr.bin/awk/tests/ch2p21.awk new file mode 100644 index 0000000..44e4942 --- /dev/null +++ b/usr.bin/awk/tests/ch2p21.awk @@ -0,0 +1 @@ +/Europe/, /Africa/ diff --git a/usr.bin/awk/tests/ch2p22.awk b/usr.bin/awk/tests/ch2p22.awk new file mode 100644 index 0000000..ad7f7f1 --- /dev/null +++ b/usr.bin/awk/tests/ch2p22.awk @@ -0,0 +1 @@ +FNR == 1, FNR == 5 { print FILENAME ": " $0 } diff --git a/usr.bin/awk/tests/ch2p32.awk b/usr.bin/awk/tests/ch2p32.awk new file mode 100644 index 0000000..d9bfeea --- /dev/null +++ b/usr.bin/awk/tests/ch2p32.awk @@ -0,0 +1,4 @@ +$4 == "Asia" { pop = pop + $3; n = n + 1 } +END { print "Total population of the", n, + "Asian countries is", pop, "million." + } diff --git a/usr.bin/awk/tests/ch2p34.awk b/usr.bin/awk/tests/ch2p34.awk new file mode 100644 index 0000000..0d9d3a6 --- /dev/null +++ b/usr.bin/awk/tests/ch2p34.awk @@ -0,0 +1,4 @@ +$3 > maxpop { maxpop = $3; country = $1 } +END { print "country with largest population:", + country, maxpop + } diff --git a/usr.bin/awk/tests/ch2p35.awk b/usr.bin/awk/tests/ch2p35.awk new file mode 100644 index 0000000..e3ddbfc --- /dev/null +++ b/usr.bin/awk/tests/ch2p35.awk @@ -0,0 +1 @@ +{ print NR ":" $0 } diff --git a/usr.bin/awk/tests/ch2p36.awk b/usr.bin/awk/tests/ch2p36.awk new file mode 100644 index 0000000..6c45944 --- /dev/null +++ b/usr.bin/awk/tests/ch2p36.awk @@ -0,0 +1 @@ +{ gsub(/USA/, "United States"); print } diff --git a/usr.bin/awk/tests/ch2p39.awk b/usr.bin/awk/tests/ch2p39.awk new file mode 100644 index 0000000..8733283 --- /dev/null +++ b/usr.bin/awk/tests/ch2p39.awk @@ -0,0 +1 @@ +{ $1 = substr($1, 1, 3); print $0 } diff --git a/usr.bin/awk/tests/ch2p40.awk b/usr.bin/awk/tests/ch2p40.awk new file mode 100644 index 0000000..feab588 --- /dev/null +++ b/usr.bin/awk/tests/ch2p40.awk @@ -0,0 +1,2 @@ + { s = s substr($1, 1, 3) " " } +END { print s } diff --git a/usr.bin/awk/tests/ch2p42.awk b/usr.bin/awk/tests/ch2p42.awk new file mode 100644 index 0000000..d654094 --- /dev/null +++ b/usr.bin/awk/tests/ch2p42.awk @@ -0,0 +1,4 @@ +BEGIN { FS = OFS = "\t" } +$4 == "North America" { $4 = "NA" } +$4 == "South America" { $4 = "SA" } + { print } diff --git a/usr.bin/awk/tests/ch2p44.awk b/usr.bin/awk/tests/ch2p44.awk new file mode 100644 index 0000000..609a4bd --- /dev/null +++ b/usr.bin/awk/tests/ch2p44.awk @@ -0,0 +1,15 @@ +# seq - print sequences of integers +# input: arguments q, p q, or p q r; q >= p; r > 0 +# output: integers 1 to q, p to q, or p to q in steps of r + +BEGIN { + if (ARGC == 2) + for (i = 1; i <= ARGV[1]; i++) + print i + else if (ARGC == 3) + for (i = ARGV[1]; i <= ARGV[2]; i++) + print i + else if (ARGC == 4) + for (i = ARGV[1]; i <= ARGV[2]; i += ARGV[3]) + print i +} diff --git a/usr.bin/awk/tests/ch2p45.awk b/usr.bin/awk/tests/ch2p45.awk new file mode 100644 index 0000000..75ee25c --- /dev/null +++ b/usr.bin/awk/tests/ch2p45.awk @@ -0,0 +1,6 @@ +{ i = 1 + while (i <= NF) { + print $i + i++ + } +} diff --git a/usr.bin/awk/tests/ch2p46.awk b/usr.bin/awk/tests/ch2p46.awk new file mode 100644 index 0000000..f45ffe4 --- /dev/null +++ b/usr.bin/awk/tests/ch2p46.awk @@ -0,0 +1,3 @@ +{ for (i = 1; i <= NF; i++) + print $i +} diff --git a/usr.bin/awk/tests/ch2p47.awk b/usr.bin/awk/tests/ch2p47.awk new file mode 100644 index 0000000..cad6959 --- /dev/null +++ b/usr.bin/awk/tests/ch2p47.awk @@ -0,0 +1,7 @@ +/Asia/ { pop["Asia"] += $3 } +/Europe/ { pop["Europe"] += $3 } +END { print "Asian population is", + pop["Asia"], "million." + print "European population is", + pop["Europe"], "million." + } diff --git a/usr.bin/awk/tests/ch2p48.awk b/usr.bin/awk/tests/ch2p48.awk new file mode 100644 index 0000000..61d68fc --- /dev/null +++ b/usr.bin/awk/tests/ch2p48.awk @@ -0,0 +1,5 @@ +BEGIN { FS = "\t" } + { pop[$4] += $3 } +END { for (name in pop) + print name, pop[name] + } diff --git a/usr.bin/awk/tests/ch2p52.awk b/usr.bin/awk/tests/ch2p52.awk new file mode 100644 index 0000000..44b2e4b --- /dev/null +++ b/usr.bin/awk/tests/ch2p52.awk @@ -0,0 +1,2 @@ +BEGIN { OFS = ":"; ORS = "\n\n" } + { print $1, $2 } diff --git a/usr.bin/awk/tests/ch2p53a.awk b/usr.bin/awk/tests/ch2p53a.awk new file mode 100644 index 0000000..c4ce032 --- /dev/null +++ b/usr.bin/awk/tests/ch2p53a.awk @@ -0,0 +1 @@ +{ print($1, $3) > ($3 > 100 ? "/tmp/out2/bigpop" : "/tmp/out2/smallpop") } diff --git a/usr.bin/awk/tests/ch2p54.awk b/usr.bin/awk/tests/ch2p54.awk new file mode 100644 index 0000000..36977b4 --- /dev/null +++ b/usr.bin/awk/tests/ch2p54.awk @@ -0,0 +1,7 @@ +# print continents and populations, sorted by population + +BEGIN { FS = "\t" } + { pop[$4] += $3 } +END { for (c in pop) + printf("%15s\t%6d\n", c, pop[c]) | "sort -t'\t' +1rn" + } diff --git a/usr.bin/awk/tests/ch2p60.awk b/usr.bin/awk/tests/ch2p60.awk new file mode 100644 index 0000000..6859146 --- /dev/null +++ b/usr.bin/awk/tests/ch2p60.awk @@ -0,0 +1,9 @@ +# include - replace #include "f" by contents of file f + +/^#include/ { + gsub(/"/, "", $2) + while (getline x <$2 > 0) + print x + next +} +{ print } diff --git a/usr.bin/awk/tests/ch2p61.awk b/usr.bin/awk/tests/ch2p61.awk new file mode 100644 index 0000000..b7cd4cd --- /dev/null +++ b/usr.bin/awk/tests/ch2p61.awk @@ -0,0 +1,7 @@ +# echo - print command-line arguments + +BEGIN { + for (i = 1; i < ARGC; i++) + printf "%s ", ARGV[i] + printf "\n" +} diff --git a/usr.bin/awk/tests/ch2p62.awk b/usr.bin/awk/tests/ch2p62.awk new file mode 100644 index 0000000..bbfc813 --- /dev/null +++ b/usr.bin/awk/tests/ch2p62.awk @@ -0,0 +1,2 @@ +$1 == "#include" { gsub(/"/, "", $2); system("cat " $2); next } + { print } diff --git a/usr.bin/awk/tests/check1 b/usr.bin/awk/tests/check1 new file mode 100644 index 0000000..7625a62 --- /dev/null +++ b/usr.bin/awk/tests/check1 @@ -0,0 +1,19 @@ +# check1 - print total deposits and checks + +/^check/ { ck = 1; next } +/^deposit/ { dep = 1; next } +/^amount/ { amt = $2; next } +/^$/ { addup() } + +END { addup() + printf("deposits $%.2f, checks $%.2f\n", + deposits, checks) + } + +function addup() { + if (ck) + checks += amt + else if (dep) + deposits += amt + ck = dep = amt = 0 +} diff --git a/usr.bin/awk/tests/check3a b/usr.bin/awk/tests/check3a new file mode 100644 index 0000000..0a88185 --- /dev/null +++ b/usr.bin/awk/tests/check3a @@ -0,0 +1,16 @@ +# check3 - print check information +# check3a modified to print in format that prchecks can use + +BEGIN { RS = ""; FS = "\n" } +/(^|\n)check/ { + for (i = 1; i <= NF; i++) { + split($i, f, "\t") + val[f[1]] = f[2] + } + printf("%5d\t%s\t%s\n", + val["check"], + sprintf("%.2f", val["amount"]), + val["to"]) + for (i in val) + delete val[i] +} diff --git a/usr.bin/awk/tests/checkfix.ans b/usr.bin/awk/tests/checkfix.ans new file mode 100644 index 0000000..9265b8e --- /dev/null +++ b/usr.bin/awk/tests/checkfix.ans @@ -0,0 +1,58 @@ +# prchecks - print formatted checks +# input: number \t amount \t payee +# output: eight lines of text for preprinted check forms + +BEGIN { + FS = "\t" + dashes = sp45 = sprintf("%45s", " ") + gsub(/ /, "-", dashes) # to protect the payee + ### Just use a fixed date: to avoid pipe and to ensure consistency + ## "date" | getline date # get today's date + ## split(date, d, " ") + ## date = d[2] ". " d[3] ", " d[6] + date = "Mar. 7, 1998" + initnum() # set up tables for number conversion +} +NF != 3 { + printf("\nrec %d has %d fields:\n|%s|\n\nVOID\nVOID\n\n\n", + NR, NF, $0) + next +} +{ printf("\n") # nothing on line 1 + printf("%s%s\n", sp45, $1) # number, indented 45 spaces + printf("%s%s\n", sp45, date) # date, indented 45 spaces + amt = sprintf("%.2f", $2) # formatted amount + printf("Pay to %45.45s $%s\n", $3 dashes, amt) # line 4 + printf("the sum of %s\n", numtowords(amt)) # line 5 + printf("\n\n\n") # lines 6, 7 and 8 +} +function numtowords(n, cents, dols, s) { # n has 2 decimal places + cents = substr(n, length(n)-1, 2) + dols = substr(n, 1, length(n)-3) + if (dols == 0) + s = "zero dollars and " cents " cents exactly" + else + s = intowords(dols) " dollars and " cents " cents exactly" + sub(/^one dollars/, "one dollar", s) + gsub(/ +/, " ", s) + return s +} +function intowords(n) { + n = int(n) + if (n >= 1000000) + return("VOID") + if (n >= 1000) + return intowords(n/1000) " thousand " intowords(n%1000) + if (n >= 100) + return intowords(n/100) " hundred " intowords(n%100) + if (n >= 20) + return tens[int(n/10)] " " intowords(n%10) + return nums[n] +} +function initnum() { + split("one two three four five six seven eight nine " \ + "ten eleven twelve thirteen fourteen fifteen " \ + "sixteen seventeen eighteen nineteen", nums, " ") + split("ten twenty thirty forty fifty sixty " \ + "seventy eighty ninety", tens, " ") +} diff --git a/usr.bin/awk/tests/checks.data b/usr.bin/awk/tests/checks.data new file mode 100644 index 0000000..95d589f --- /dev/null +++ b/usr.bin/awk/tests/checks.data @@ -0,0 +1,30 @@ +check 1021 +to Champagne Unlimited +amount 123.10 +date 1/1/87 + +deposit +amount 500.00 +date 1/1/87 + +check 1022 +date 1/2/87 +amount 45.10 +to Getwell Drug Store +tax medical + +check 1023 +amount 125.00 +to International Travel +date 1/3/87 + +amount 50.00 +to Carnegie Hall +date 1/3/87 +check 1024 +tax charitable contribution + +to American Express +check 1025 +amount 75.75 +date 1/5/87 diff --git a/usr.bin/awk/tests/codesize.awk b/usr.bin/awk/tests/codesize.awk new file mode 100644 index 0000000..e46e66b --- /dev/null +++ b/usr.bin/awk/tests/codesize.awk @@ -0,0 +1,33 @@ +# awk program to parse the output of "lseg -d " and calculate +# 1. The total size of code in each object file +# 2. The name of any procedure that uses over "maxseg" bytes (default=100) + +BEGIN { + # If maxseg was not set on command line, use default + if (maxseg <= 0) maxseg = 100; +} + +/ Code / { + # Is this the beginning of a new file's statistics? + if ($1 != filename) { + if (codesize > 0) { + sizes[filename] = codesize; + } + filename = $1; + codesize = 0; + } + codesize += $3; + # If there are > 4 fields, fourth one is the stack size + if ($4 > maxseg) print $5," in file ", $1," uses ",$4," stack bytes" +} + +END { + # Print the report + print "Code file Code bytes" + for (fname in sizes) { + printf "%s", fname; + i = length(fname); + while (i++ < 20) printf " "; + printf " %6d\n", sizes[fname]; + } +} diff --git a/usr.bin/awk/tests/codesize.txt b/usr.bin/awk/tests/codesize.txt new file mode 100644 index 0000000..7c235ea --- /dev/null +++ b/usr.bin/awk/tests/codesize.txt @@ -0,0 +1,177 @@ +File Type Size Stack Name +-------------------- ------------------ -------- ------ ---------------- +../main.o Code 3467 22 "main" +../main.o Code 669 14 "pgetc" +../main.o Code 38 "~GLOBALS" +../main.o Code 80 "~ARRAYS" +../b.o Code 1151 20 "makedfa" +../b.o Code 841 22 "mkdfa" +../b.o Code 1657 12 "makeinit" +../b.o Code 759 8 "penter" +../b.o Code 586 8 "freetr" +../b.o Code 377 16 "hexstr" +../b.o Code 506 16 "quoted" +../b.o Code 1151 24 "cclenter" +../b.o Code 89 2 "overflo" +../b.o Code 1400 14 "cfoll" +../b.o Code 1277 14 "first" +../b.o Code 333 12 "follow" +../b.o Code 87 8 "member" +../b.o Code 354 16 "match" +../b.o Code 1552 24 "pmatch" +../b.o Code 1525 24 "nematch" +../b.o Code 281 10 "reparse" +../b.o Code 43 6 "regexp" +../b.o Code 815 12 "primary" +../b.o Code 128 8 "concat" +../b.o Code 96 6 "alt" +../b.o Code 199 8 "unary" +../b.o Code 1270 20 "relex" +../b.o Code 3513 22 "cgoto" +../b.o Code 1123 8 "freefa" +../b.o Code 51 "~GLOBALS" +../b.o Code 80 "~ARRAYS" +../lib.o Code 537 6 "recinit" +../lib.o Code 392 58 "makefields" +../lib.o Code 182 12 "initgetrec" +../lib.o Code 1879 20 "getrec" +../lib.o Code 88 "nextfile" +../lib.o Code 1801 26 "readrec" +../lib.o Code 188 64 "getargv" +../lib.o Code 318 18 "setclvar" +../lib.o Code 3069 31 "fldbld" +../lib.o Code 240 12 "cleanfld" +../lib.o Code 97 6 "newfld" +../lib.o Code 180 10 "fieldadr" +../lib.o Code 214 8 "growfldtab" +../lib.o Code 1208 22 "refldbld" +../lib.o Code 1581 22 "recbld" +../lib.o Code 343 6 "yyerror" +../lib.o Code 73 2 "fpecatch" +../lib.o Code 112 4 "bracecheck" +../lib.o Code 363 6 "bcheck2" +../lib.o Code 838 6 "error" +../lib.o Code 3866 20 "eprint" +../lib.o Code 102 4 "bclass" +../lib.o Code 268 10 "errcheck" +../lib.o Code 303 12 "isclvar" +../lib.o Code 301 20 "isnumber" +../lib.o Code 46 "~GLOBALS" +../lib.o Code 450 "~ARRAYS" +../proctab.o Code 188 10 "tokname" +../proctab.o Code 1 "~GLOBALS" +../proctab.o Code 1380 "~ARRAYS" +../tran.o Code 1112 6 "syminit" +../tran.o Code 358 62 "arginit" +../tran.o Code 406 14 "envinit" +../tran.o Code 250 18 "makesymtab" +../tran.o Code 560 20 "freesymtab" +../tran.o Code 503 20 "freeelem" +../tran.o Code 830 16 "setsymtab" +../tran.o Code 144 12 "hash" +../tran.o Code 408 24 "rehash" +../tran.o Code 243 20 "lookup" +../tran.o Code 378 20 "setfval" +../tran.o Code 319 6 "funnyvar" +../tran.o Code 585 20 "setsval" +../tran.o Code 410 18 "getfval" +../tran.o Code 618 122 "getsval" +../tran.o Code 190 10 "tostring" +../tran.o Code 1031 24 "qstring" +../tran.o Code 105 "~GLOBALS" +../lex.o Code 37 10 "peek" +../lex.o Code 1379 24 "gettok" +../lex.o Code 3792 14 "yylex" +../lex.o Code 1919 128 "string" +../lex.o Code 203 16 "binsearch" +../lex.o Code 885 18 "word" +../lex.o Code 7 "startreg" +../lex.o Code 702 14 "regexpr" +../lex.o Code 303 10 "input" +../lex.o Code 320 6 "unput" +../lex.o Code 123 8 "unputstr" +../lex.o Code 43 "~GLOBALS" +../lex.o Code 991 "~ARRAYS" +../parse.o Code 209 14 "nodealloc" +../parse.o Code 44 10 "exptostat" +../parse.o Code 133 14 "node1" +../parse.o Code 200 14 "node2" +../parse.o Code 265 14 "node3" +../parse.o Code 332 14 "node4" +../parse.o Code 66 14 "stat1" +../parse.o Code 70 14 "stat2" +../parse.o Code 74 14 "stat3" +../parse.o Code 78 14 "stat4" +../parse.o Code 66 14 "op1" +../parse.o Code 70 14 "op2" +../parse.o Code 74 14 "op3" +../parse.o Code 78 14 "op4" +../parse.o Code 101 14 "celltonode" +../parse.o Code 51 6 "rectonode" +../parse.o Code 344 14 "makearr" +../parse.o Code 172 14 "pa2stat" +../parse.o Code 231 14 "linkum" +../parse.o Code 283 12 "defn" +../parse.o Code 209 14 "isarg" +../parse.o Code 3 "~GLOBALS" +../parse.o Code 100 "~ARRAYS" +../run.o Code 353 16 "adjbuf" +../run.o Code 31 2 "run" +../run.o Code 854 22 "execute" +../run.o Code 940 14 "program" +../run.o Code 2949 54 "call" +../run.o Code 238 14 "copycell" +../run.o Code 351 10 "arg" +../run.o Code 881 20 "jump" +../run.o Code 1323 32 "getline" +../run.o Code 91 10 "getnf" +../run.o Code 1085 42 "array" +../run.o Code 944 38 "adelete" +../run.o Code 1073 42 "intest" +../run.o Code 821 40 "matchop" +../run.o Code 587 22 "boolop" +../run.o Code 805 30 "relop" +../run.o Code 306 6 "tfree" +../run.o Code 387 16 "gettemp" +../run.o Code 327 20 "indirect" +../run.o Code 1171 34 "substr" +../run.o Code 550 50 "sindex" +../run.o Code 3191 44 "format" +../run.o Code 482 24 "awksprintf" +../run.o Code 911 30 "awkprintf" +../run.o Code 1335 48 "arith" +../run.o Code 285 22 "ipow" +../run.o Code 425 28 "incrdecr" +../run.o Code 1466 48 "assign" +../run.o Code 530 30 "cat" +../run.o Code 321 14 "pastat" +../run.o Code 558 16 "dopa2" +../run.o Code 3051 101 "split" +../run.o Code 283 14 "condexpr" +../run.o Code 354 14 "ifstat" +../run.o Code 392 14 "whilestat" +../run.o Code 412 14 "dostat" +../run.o Code 616 14 "forstat" +../run.o Code 704 36 "instat" +../run.o Code 1848 46 "bltin" +../run.o Code 670 22 "printstat" +../run.o Code 65 6 "nullproc" +../run.o Code 209 22 "redirect" +../run.o Code 1458 22 "openfile" +../run.o Code 206 12 "filename" +../run.o Code 1262 18 "closefile" +../run.o Code 686 10 "closeall" +../run.o Code 1890 48 "sub" +../run.o Code 2844 54 "gsub" +../run.o Code 706 14 "backsub" +../run.o Code 55 "~GLOBALS" +../run.o Code 689 "~ARRAYS" +../ytab.o Code 16 4 "yywrap" +../ytab.o Code 214 6 "setfname" +../ytab.o Code 134 8 "constnode" +../ytab.o Code 108 10 "strnode" +../ytab.o Code 140 12 "notnull" +../ytab.o Code 222 10 "checkdup" +../ytab.o Code 17185 32 "yyparse" +../ytab.o Code 45 "~GLOBALS" +../ytab.o Code 13274 "~ARRAYS" diff --git a/usr.bin/awk/tests/columns.data b/usr.bin/awk/tests/columns.data new file mode 100644 index 0000000..ae81960 --- /dev/null +++ b/usr.bin/awk/tests/columns.data @@ -0,0 +1,23 @@ +605 506 156 3292 133 1054 608 6605 Comment +502 31296 1926 672 933 2167 1706 168 +1868 186 737 197 1308 856 4637 71392 +456 1038 6380 1089 1800 588 2206 232 +1279 3008 678 163 1517 450 207 432 +1265 4853 3288 2335 847 3817 224 4204 +1541 6431 2635 1904 1295 4830 1658 2615 +4593 1933 545 2269 4247 8784 1354 2341 Nice! +1429 12451 711 661 6757 9831 702 15964 +4284 10646 2082 2254 2066 2386 216 2148 +14795 264 3200 476 6383 791 739 929 +145 1165 1985 385 336 3263 3900 268 +14954 268 131 2863 784 20472 579 2340 +3371 1092 163 882 6248 3124 14806 3695 +1334 557 3984 8215 12075 6579 2648 167 +15805 4533 33468 16518 9353 141 2936 3459 +157 1715 2155 1508 8735 149 167 1343 +1925 1807 65901 16015 36833 20737 35547 2166 +225 574 14016 11902 181 181 4761 1619 +181 186 186 196 272 261 1129 3164 +178 3740 368 3335 1564 1506 78880 142 +169 176 6619 176 181 408 9510 207 +790 441 251 167 1274 3794 3708 4132 diff --git a/usr.bin/awk/tests/comb.ans b/usr.bin/awk/tests/comb.ans new file mode 100644 index 0000000..8c83d96 --- /dev/null +++ b/usr.bin/awk/tests/comb.ans @@ -0,0 +1,12 @@ +# print k distinct random integers between 1 and n + +{ random($1, $2) } + +function random(k, n, A, i, r) { + for (i = n-k+1; i <= n; i++) + ((r = randint(i)) in A) ? A[i] : A[r] + for (i in A) + print i +} + +function randint(n) { return int(n*rand())+1 } diff --git a/usr.bin/awk/tests/countries b/usr.bin/awk/tests/countries new file mode 100644 index 0000000..e973031 --- /dev/null +++ b/usr.bin/awk/tests/countries @@ -0,0 +1,11 @@ +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 diff --git a/usr.bin/awk/tests/countries.sort b/usr.bin/awk/tests/countries.sort new file mode 100644 index 0000000..9b05ca0 --- /dev/null +++ b/usr.bin/awk/tests/countries.sort @@ -0,0 +1,11 @@ +Brazil 3286 134 South America +Canada 3852 25 North America +China 3705 1032 Asia +England 94 56 Europe +France 211 55 Europe +Germany 96 61 Europe +India 1267 746 Asia +Japan 144 120 Asia +Mexico 762 78 North America +USA 3615 237 North America +USSR 8649 275 Asia diff --git a/usr.bin/awk/tests/date.data b/usr.bin/awk/tests/date.data new file mode 100644 index 0000000..190558e --- /dev/null +++ b/usr.bin/awk/tests/date.data @@ -0,0 +1,5 @@ +013042 mary's birthday +032772 mark's birthday +052470 anniversary +061209 mother's birthday +110175 elizabeth's birthday diff --git a/usr.bin/awk/tests/datecvt b/usr.bin/awk/tests/datecvt new file mode 100644 index 0000000..edd838a --- /dev/null +++ b/usr.bin/awk/tests/datecvt @@ -0,0 +1,3 @@ +# date convert - convert mmddyy into yymmdd in $1 + +{ $1 = substr($1,5,2) substr($1,1,2) substr($1,3,2); print } diff --git a/usr.bin/awk/tests/dotests b/usr.bin/awk/tests/dotests new file mode 100644 index 0000000..68b6343 --- /dev/null +++ b/usr.bin/awk/tests/dotests @@ -0,0 +1,1206 @@ +# ------------------------------------------------------------------- +# +# GNO/ME awk tests +# Collected/Written by Dave Tribby * March 1998 +# $Id: dotests,v 1.1 1998/04/07 17:06:01 tribby Exp $ +# +# ------------------------------------------------------------------- + +# ### --------------------------------------------------------------- +# ### Note: several test cases are commented-out with "# ###" because +# ### they use features such as pipes and the sort utility that +# ### are not working or implemented. When those features are +# ### available, the test cases should be run. +# ### --------------------------------------------------------------- + +# Location of awk command to be tested +set testcmd=/obj/gno/usr.bin/awk/awk + +# GNO's rm command is implemented under the cp command +set RM="cp -p rm" + +# Use either cmp or diff for comparing files +set compare="diff" + +# Create directory under /tmp to hold results +$RM -rf /tmp/out >& /tmp/err.list +mkdir /tmp/out + +# Create directory under /tmp to hold commands +$RM -rf /tmp/cmd >& /tmp/err.list +mkdir /tmp/cmd + + +# Record starting time +echo -n "Start testing command $testcmd at" +date + +# ------------------------------------------------------------------- +# sed Regression Tests rewritten to use awk +# ------------------------------------------------------------------- + +# Create two data files (/tmp/lines1 and /tmp/lines2) + +echo 'BEGIN {' > /tmp/cmd/mklist.awk +echo 'for (i=1; i<15; i++)' >> /tmp/cmd/mklist.awk +echo 'print "l1_"i}' >> /tmp/cmd/mklist.awk +$testcmd -f /tmp/cmd/mklist.awk > /tmp/lines1 + +echo 'BEGIN {' > /tmp/cmd/mklist.awk +echo 'for (i=1; i<10; i++)' >> /tmp/cmd/mklist.awk +echo 'print "l2_"i}' >> /tmp/cmd/mklist.awk +$testcmd -f /tmp/cmd/mklist.awk > /tmp/lines2 + + +# Create an empty /tmp/null to simulate /dev/null +$testcmd 'BEGIN{}' > /tmp/null + +# ## test_args + +set tnum='1.2' +echo "awk test $tnum" +## $SED -n 's/^/e1_/p' /tmp/lines1 > /tmp/out/out.$tnum +echo '{sub("^","e1_");print}' > /tmp/cmd/cmd.awk +$testcmd -f /tmp/cmd/cmd.awk /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='1.4' +echo "awk test $tnum" +## $SED -n 's/^/e1_/p' /tmp/out/out.$tnum +$testcmd '{sub("^","e1_")}{print}' /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +## echo 's/^/s1_/p' >/tmp/cmd/script1 +## echo 's/^/s2_/p' >/tmp/cmd/script2 +echo '{sub("^","s1_");' > /tmp/cmd/script1 +echo 'print }' >> /tmp/cmd/script1 + +echo '{sub("^","s1_");' > /tmp/cmd/script12 +echo 'print;' >> /tmp/cmd/script12 +echo 'sub("^","s2_");' >> /tmp/cmd/script12 +echo 'print' >> /tmp/cmd/script12 +echo 'print }' >> /tmp/cmd/script12 + +set tnum='1.9' +echo "awk test $tnum" +## $SED -n -f /tmp/cmd/script1 /tmp/lines1 > /tmp/out/out.$tnum +$testcmd -f /tmp/cmd/script1 /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='1.10' +echo "awk test $tnum" +## $SED -n -f /tmp/cmd/script1 /tmp/out/out.$tnum +$testcmd -f /tmp/cmd/script1 /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='1.11' +echo "awk test $tnum" +## $SED -n -e 's/^/e1_/p' /tmp/lines1 > /tmp/out/out.$tnum +$testcmd '{sub("^","e1_")}{print}' /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='1.12' +echo "awk test $tnum" +## $SED -n -e 's/^/e1_/p' /tmp/out/out.$tnum +$testcmd '{sub("^","e1_")}{print}' /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='1.13' +echo "awk test $tnum" +## $SED -e 's/^/e1_/p' -e 's/^/e2_/p' /tmp/lines1 > /tmp/out/out.$tnum +$testcmd '{sub("^","e1_")}{print}{sub("^","e2_")}{print}{print}' /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='1.14' +echo "awk test $tnum" +## $SED -f /tmp/cmd/script1 -f /tmp/cmd/script2 /tmp/lines1 > /tmp/out/out.$tnum +$testcmd -f /tmp/cmd/script12 /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='1.16' +echo "awk test $tnum" +## $SED -e 's/^/e1_/p' /tmp/lines1 /tmp/lines1 > /tmp/out/out.$tnum +$testcmd '{sub("^","e1_")}{print}{print}' /tmp/lines1 /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +echo '#n' > /tmp/cmd/awk.cmd1 +echo '# A comment' >> /tmp/cmd/awk.cmd1 +echo '' >> /tmp/cmd/awk.cmd1 +echo '{print}' >> /tmp/cmd/awk.cmd1 + +set tnum='1.18' +echo "awk test $tnum" +## $SED -f /tmp/cmd/awk.cmd1 /tmp/out/out.$tnum +$testcmd -f /tmp/cmd/awk.cmd1 /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + + +# ## test_addr +echo "Testing address ranges" +set tnum='2.1' +echo "awk test $tnum" +## $SED -n -e '4p' /tmp/lines1 > /tmp/out/out.$tnum +$testcmd '{if (NR==4) print}' /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='2.2' +echo "awk test $tnum" +## $SED -n -e '20p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum +$testcmd '{if (NR==20) print}' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='2.3' +echo "awk test $tnum" +echo '{ s = $0 }' > /tmp/cmd/printlast.awk +echo 'END {print s}' >> /tmp/cmd/printlast.awk +## $SED -n -e '$p' /tmp/lines1 > /tmp/out/out.$tnum +$testcmd -f /tmp/cmd/printlast.awk /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='2.4' +echo "awk test $tnum" +## $SED -n -e '$p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum +$testcmd -f /tmp/cmd/printlast.awk /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +# Should not print anything +set tnum='2.7' +echo "awk test $tnum" +## $SED -n -e '20p' /tmp/lines1 > /tmp/out/out.$tnum +$testcmd '{if (NR==20) print}' /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare /tmp/out/out.$tnum /tmp/null +echo " $tnum comparison status = $status" +echo "" + +set tnum='2.9' +echo "awk test $tnum" +## $SED -n '/l1_7/p' /tmp/lines1 > /tmp/out/out.$tnum +$testcmd '/l1_7/{print}' /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='2.12' +echo "awk test $tnum" +## $SED -n '1,4p' /tmp/lines1 > /tmp/out/out.$tnum +$testcmd '{if (NR < 5) print}' /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='2.13' +echo "awk test $tnum" +## $SED -n '1,$p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum +$testcmd '{print}' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='2.17' +echo "awk test $tnum" +## $SED -n '/4/,/10/p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum +$testcmd '/4/,/10/{print}' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + + +# ## test_group +echo "Brace and other grouping" +set tnum='3.1' +echo "awk test $tnum" +echo 'NR >= 4 && NR <= 12 {' > /tmp/cmd/awk.cmd1 +echo ' sub("^","^")' >> /tmp/cmd/awk.cmd1 +echo ' sub("$","$")' >> /tmp/cmd/awk.cmd1 +echo ' sub("_","T") }' >> /tmp/cmd/awk.cmd1 +echo '{ print }' >> /tmp/cmd/awk.cmd1 +## $SED -f /tmp/cmd/awk.cmd1 /tmp/lines1 > /tmp/out/out.$tnum +$testcmd -f /tmp/cmd/awk.cmd1 /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +# ## test_subst +echo "Testing substitution commands" +set tnum='8.1' +echo "awk test $tnum" +## $SED -e 's/./X/g' /tmp/lines1 > /tmp/out/out.$tnum +$testcmd '{gsub(".","X")}{print}' /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +set tnum='8.12' +echo "awk test $tnum" +## $SED -e 's/[123]/X/g' /tmp/lines1 > /tmp/out/out.$tnum +$testcmd '{gsub("[123]","X")}{print}' /tmp/lines1 > /tmp/out/out.$tnum +echo " Completion status = $status" +echo "Checking results against control file (no differences expected)" +$compare out/out.$tnum /tmp/out/out.$tnum +echo " $tnum comparison status = $status" +echo "" + +# ------------------------------------------------------------------- +# Tests originally written for tr command; modified to test awk +# ------------------------------------------------------------------- + +set src="file1.mixed" +set cmp="file1.UPPER" +set dest="/tmp/$cmp" +echo "Upshifting all characters in $src" +$testcmd '{print toupper($0)}' < $src > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" +echo "" + +set cmp="file1.novowel" +set dest="/tmp/$cmp" +echo "Removing lower-case vowels in $src" +## $SED -e's/[aeiouy]//g' < $src > $dest +echo '{gsub("[aeiouy]",""); print}' > /tmp/cmd/cmd.awk +$testcmd -f /tmp/cmd/cmd.awk < $src > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" +echo "" + +set cmp="file1.nolower" +set dest="/tmp/$cmp" +echo "Removing lower-case letters and squeezing spaces in $src" +## $SED -e's/[a-z]//g' -e's/ */ /g' < $src > $dest +echo '{gsub("[a-z]",""); gsub(" *"," "); print}' > /tmp/cmd/cmd.awk +$testcmd -f /tmp/cmd/cmd.awk < $src > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" +echo "" + + +# ---------------------------------------------------------------------- +# Tests selected from examples in The AWK Programming Language by +# Aho, Kernighan, and Weinberger; taken from +# http://plan9.bell-labs.com/who/bwk/ +# ---------------------------------------------------------------------- + +# Create directory under /tmp to hold results +$RM -rf /tmp/out2 >& /tmp/err.list +mkdir /tmp/out2 + +# ----- Chapter 1 ----- + +set cmp="out2/ch1p11a.out" +set dest="/tmp/$cmp" +echo Testing ch1p11a.awk +$testcmd -f ch1p11a.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p12.out" +set dest="/tmp/$cmp" +echo Testing ch1p12.awk +$testcmd -f ch1p12.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p13.out" +set dest="/tmp/$cmp" +echo Testing ch1p13.awk +$testcmd -f ch1p13.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p22.out" +set dest="/tmp/$cmp" +echo Testing ch1p22.awk +$testcmd -f ch1p22.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p28.out" +set dest="/tmp/$cmp" +echo Testing ch1p28.awk +$testcmd -f ch1p28.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p30.out" +set dest="/tmp/$cmp" +echo Testing ch1p30.awk +$testcmd -f ch1p30.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p31.out" +set dest="/tmp/$cmp" +echo Testing ch1p31.awk +$testcmd -f ch1p31.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p32.out" +set dest="/tmp/$cmp" +echo Testing ch1p32.awk +$testcmd -f ch1p32.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p33.out" +set dest="/tmp/$cmp" +echo Testing ch1p33.awk +$testcmd -f ch1p33.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p33a.out" +set dest="/tmp/$cmp" +echo Testing ch1p33a.awk +$testcmd -f ch1p33a.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p34.out" +set dest="/tmp/$cmp" +echo Testing ch1p34.awk +$testcmd -f ch1p34.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p40a.out" +set dest="/tmp/$cmp" +echo Testing ch1p40a.awk +$testcmd -f ch1p40a.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p41.out" +set dest="/tmp/$cmp" +echo Testing ch1p41.awk +$testcmd -f ch1p41.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p51.out" +set dest="/tmp/$cmp" +echo Testing ch1p51.awk +$testcmd -f ch1p51.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p63.out" +set dest="/tmp/$cmp" +echo Testing ch1p63.awk +$testcmd -f ch1p63.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p67.out" +set dest="/tmp/$cmp" +echo Testing ch1p67.awk +$testcmd -f ch1p67.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p69.out" +set dest="/tmp/$cmp" +echo Testing ch1p69.awk +$testcmd -f ch1p69.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p78.out" +set dest="/tmp/$cmp" +echo Testing ch1p78.awk +$testcmd -f ch1p78.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch1p79.out" +set dest="/tmp/$cmp" +echo Testing ch1p79.awk +$testcmd -f ch1p79.awk emp.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +# ----- Chapter 2 ----- + +set cmp="out2/ch2p11.out" +set dest="/tmp/$cmp" +echo Testing ch2p11.awk +$testcmd -f ch2p11.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p20.out" +set dest="/tmp/$cmp" +echo Testing ch2p20.awk +$testcmd -f ch2p20.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +# 20a and 20b should produce the same results as 20 +set dest="/tmp/out2/ch2p20a.out" +echo Testing ch2p20a.awk +$testcmd -f ch2p20a.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set dest="/tmp/out2/ch2p20b.out" +echo Testing ch2p20b.awk +$testcmd -f ch2p20b.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p21.out" +set dest="/tmp/$cmp" +echo Testing ch2p21.awk +$testcmd -f ch2p21.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p22.out" +set dest="/tmp/$cmp" +echo Testing ch2p22.awk +$testcmd -f ch2p22.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p32.out" +set dest="/tmp/$cmp" +echo Testing ch2p32.awk +$testcmd -f ch2p32.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p34.out" +set dest="/tmp/$cmp" +echo Testing ch2p34.awk +$testcmd -f ch2p34.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p35.out" +set dest="/tmp/$cmp" +echo Testing ch2p35.awk +$testcmd -f ch2p35.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p36.out" +set dest="/tmp/$cmp" +echo Testing ch2p36.awk +$testcmd -f ch2p36.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p39.out" +set dest="/tmp/$cmp" +echo Testing ch2p39.awk +$testcmd -f ch2p39.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p40.out" +set dest="/tmp/$cmp" +echo Testing ch2p40.awk +$testcmd -f ch2p40.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p42.out" +set dest="/tmp/$cmp" +echo Testing ch2p42.awk +$testcmd -f ch2p42.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p44.out" +set dest="/tmp/$cmp" +echo Testing ch2p44.awk +$testcmd -f ch2p44.awk 0 50 10 > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p45.out" +set dest="/tmp/$cmp" +echo Testing ch2p45.awk +$testcmd -f ch2p45.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p46.out" +set dest="/tmp/$cmp" +echo Testing ch2p46.awk +$testcmd -f ch2p46.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p47.out" +set dest="/tmp/$cmp" +echo Testing ch2p47.awk +$testcmd -f ch2p47.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p48.out" +set dest="/tmp/$cmp" +echo Testing ch2p48.awk +$testcmd -f ch2p48.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p52.out" +set dest="/tmp/$cmp" +echo Testing ch2p52.awk +$testcmd -f ch2p52.awk countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +echo Testing ch2p53a.awk +$testcmd -f ch2p53a.awk countries +echo " Completion status = $status" +set cmp="bigpop" +set dest="/tmp/out2/$cmp" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" +set cmp="smallpop" +set dest="/tmp/out2/$cmp" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +# ### ------------------------------------------------------------------ +# ### ch2p54.awk does not work due to use of (a) pipe and (b) sort +# ### ------------------------------------------------------------------ +# ### set cmp="out2/ch2p54.out" +# ### set dest="/tmp/$cmp" +# ### echo Testing ch2p54.awk +# ### $testcmd -f ch2p54.awk countries > $dest +# ### echo " Completion status = $status" +# ### echo "Checking results against control file $cmp (no differences expected)" +# ### $compare $cmp $dest +# ### echo " comparison status = $status" + +set cmp="out2/ch2p60.out" +set dest="/tmp/$cmp" +echo Testing ch2p60.awk +$testcmd -f ch2p60.awk include.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set dest="/tmp/out2/ch2p62.out" +echo Testing ch2p62.awk +$testcmd -f ch2p62.awk include.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/ch2p61.out" +set dest="/tmp/$cmp" +echo Testing ch2p61.awk +$testcmd -f ch2p61.awk p1 p2 "param 3" p4 > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +# ----- Chapter 3 ----- + + +set cmp="out2/sum3.out" +set dest="/tmp/$cmp" +echo Testing sum3 +$testcmd -f sum3 columns.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/percent.out" +set dest="/tmp/$cmp" +echo Testing percent +$testcmd -f percent columns.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/histo.out" +set dest="/tmp/$cmp" +set hold="/tmp/out2/holdrand" +echo Testing genrand.awk and histogram +$testcmd -f genrand.awk > $hold +echo " Completion status = $status" +$testcmd -f histogram < $hold > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set dest="${dest}2" +echo Testing histans1.awk +$testcmd -f histans1.awk < $hold > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/datecvt.out" +set dest="/tmp/$cmp" +echo Testing datecvt +$testcmd -f datecvt date.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/checkfix.out" +set dest="/tmp/$cmp" +set hold="/tmp/out2/awk.hold" +echo Testing check3a/checkfix.ans +$testcmd -f check3a < checks.data > $hold +echo " Completion status = $status" +$testcmd -f checkfix.ans < $hold > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/check1.out" +set dest="/tmp/$cmp" +echo Testing check1 +$testcmd -f check1 checks.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/bundle.out" +set dest="/tmp/$cmp" +echo Testing bundle +cp bundle unbundle /tmp +$testcmd -f bundle /tmp/bundle /tmp/unbundle > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" +$RM -f /tmp/bundle /tmp/unbundle + +echo Testing unbundle +$testcmd -f unbundle $dest +echo " Completion status = $status" +set cmp="bundle" +echo "Checking results against original file $cmp (no differences expected)" +$compare $cmp /tmp/$cmp +echo " comparison status = $status" +set cmp="unbundle" +echo "Checking results against original file $cmp (no differences expected)" +$compare $cmp /tmp/$cmp +echo " comparison status = $status" +$RM -f /tmp/bundle /tmp/unbundle + + +set cmp="out2/ny2.out" +set dest="/tmp/$cmp" +echo Testing ny2.awk +$testcmd -f ny2.awk addr.1 > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +# ----- Chapter 4 ----- + +# ### ------------------------------------------------------------------ +# ### prep1 does not work due to use of (a) pipe and (b) sort +# ### ------------------------------------------------------------------ +# ### set cmp="out2/form1.out" +# ### set dest="/tmp/$cmp" +# ### echo Testing prep1 and form1 +# ### $testcmd -f prep1 countries | $testcmd -f form1 > $dest +# ### echo " Completion status = $status" +# ### echo "Checking results against control file $cmp (no differences expected)" +# ### $compare $cmp $dest +# ### echo " comparison status = $status" + +# ### ------------------------------------------------------------------ +# ### prep2 does not work due to use of (a) pipe and (b) sort +# ### ------------------------------------------------------------------ +# ### set cmp="out2/form2.out" +# ### set dest="/tmp/$cmp" +# ### echo Testing prep2 and form2 +# ### $testcmd -f prep2 countries | $testcmd -f form2 > $dest +# ### echo " Completion status = $status" +# ### echo "Checking results against control file $cmp (no differences expected)" +# ### $compare $cmp $dest +# ### echo " comparison status = $status" + +set cmp="out2/infoG.out" +set dest="/tmp/$cmp" +echo "Testing info.awk (Germany)" +$testcmd -f info.awk Germany < countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/infoUS.out" +set dest="/tmp/$cmp" +echo "Testing info.awk (US)" +$testcmd -f info.awk US < countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/form.gen.out" +set dest="/tmp/$cmp" +echo "Testing form.gen (England)" +$testcmd -f form.gen England < countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/table.out" +set dest="/tmp/$cmp" +echo Testing table +$testcmd -f table numbers.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/table1.out" +set dest="/tmp/$cmp" +echo Testing table1 +$testcmd -f table1 numbers.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/avgarea.out" +set dest="/tmp/$cmp" +echo "Testing avgarea.awk (from command line)" +$testcmd '{ area += $3 }; END { print area/NR }' countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/join.out" +set dest="/tmp/$cmp" +echo Testing join.awk +$testcmd -f join.awk countries.sort capitals.sort > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/merge.out" +set dest="/tmp/$cmp" +echo Testing merge.awk +$testcmd -f merge.awk capitals countries > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + + +# ----- Chapter 5 ----- + + +set cmp="out2/comb.out" +set dest="/tmp/$cmp" +echo "Testing comb.ans" +echo "5 10" | $testcmd -f comb.ans > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/bridge.out" +set dest="/tmp/$cmp" +echo "Testing bridge.ans" +$testcmd -f bridge.ans > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/sentgen.out" +set dest="/tmp/$cmp" +echo "Testing sentgen" +$testcmd -f sentgen sentgen.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" +set dest="/tmp/$cmp" + +set dest="${dest}2" +echo "Testing sentgen2" +$testcmd -f sentgen2 sentgen.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +# ----- Chapter 6 ----- + +set cmp="out2/sum.list.out" +set dest="/tmp/$cmp" +echo "Testing sum.asm (listing)" +$testcmd -f asm.print sum.asm sum.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +diff $cmp $dest +echo " comparison status = $status" + +set cmp="out2/sum.out" +set dest="/tmp/$cmp" +echo "Testing sum.asm (execution)" +$testcmd -f asm sum.asm sum.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/sortgen.out" +set dest="/tmp/$cmp" +echo "Testing sortgen" +$testcmd -f sortgen sortgen.in > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +# ### ------------------------------------------------------------------ +# ### This test causes a system halt; perhaps due to use of pipe +# ### ------------------------------------------------------------------ +# ### set cmp="out2/parser.out" +# ### set dest="/tmp/$cmp" +# ### echo "Testing awk.parser" +# ### $testcmd -f awk.parser parser.in > $dest +# ### echo " Completion status = $status" +# ### echo "Checking results against control file $cmp (no differences expected)" +# ### $compare $cmp $dest +# ### echo " comparison status = $status" + + +# ---------------------------------------------------------------------- +# Additional test cases based upon man page and analysis +# ---------------------------------------------------------------------- + +set cmp="out2/printenv.out" +set dest="/tmp/$cmp" +setenv TestVal="MixedCase" +setenv TESTVAL="UPPERONLY" +setenv testval="loweronly" +echo "Testing printenv.awk" +$testcmd -f printenv.awk TestVal badname > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/split1.out" +set dest="/tmp/$cmp" +echo "Testing split with default FS" +echo "f1:f2 f3:f4" | $testcmd '{print $1,$2}' > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/split2.out" +set dest="/tmp/$cmp" +echo "Testing split with -F ':'" +echo "f1:f2 f3:f4" | $testcmd -F':' '{print $1,$2}' > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set dest="/tmp/$cmp.2" +echo "Testing split with FS = ':'" +echo "f1:f2 f3:f4" | $testcmd -v FS=':' '{print $1,$2}' > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/array.out" +set dest="/tmp/$cmp" +echo "Testing array.awk" +$testcmd -f array.awk array1.data array2.data > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/factorial.out" +set dest="/tmp/$cmp" +echo "Testing recursion with factorial.awk" +$testcmd -f factorial.awk 10 > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="out2/codesize.out" +set dest="/tmp/$cmp" +echo "Testing codesize.awk" +$testcmd -f codesize.awk codesize.txt > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +set cmp="/tmp/out2/wc1.out" +wc [d-z]*.awk > $cmp +set dest="/tmp/out2/wc2.out" +echo "Testing wc emulation with wc.awk" +$testcmd -f wc.awk [d-z]*.awk > $dest +echo " Completion status = $status" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + + +# ---------------------------------------------------------------------- +# Syntax error messages +# ---------------------------------------------------------------------- +echo "***** Syntax Error Messages *****" + +set cmp="out2/extra1.err" +set dest="/tmp/$cmp" +echo "Testing error message: extra }" +$testcmd '{}}' >& $dest +echo " Completion status = $status (expected 2)" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/extra2.err" +set dest="/tmp/$cmp" +echo "Testing error message: extra )" +$testcmd '{)}' >& $dest +echo " Completion status = $status (expected 2)" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/extra3.err" +set dest="/tmp/$cmp" +echo "Testing error message: extra ]" +$testcmd '{]}' >& $dest +echo " Completion status = $status (expected 2)" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +set cmp="out2/return.err" +set dest="/tmp/$cmp" +echo "Testing error message: return not in function" +$testcmd '{return}' >& $dest +echo " Completion status = $status (expected 2)" +echo "Checking results against control file $cmp (no differences expected)" +$compare $cmp $dest +echo " comparison status = $status" + +# ------------------------------------------------------------------- +# Error messages +# ------------------------------------------------------------------- +echo "***** Error Messages *****" + +set dest="/tmp/err.cond" + +echo "" +echo "Expected error: unknown option" +$testcmd -x < /tmp/null > $dest +echo " Error completion status = $status (expected: 2)" + +echo "" +set src="badname" +echo "Expected error: can't open file $src" +$testcmd -f $src > $dest +echo " Error completion status = $status (expected: 2)" + +# Record ending time +echo -n "Done testing command $testcmd at" +date diff --git a/usr.bin/awk/tests/emp.data b/usr.bin/awk/tests/emp.data new file mode 100644 index 0000000..ae4a62a --- /dev/null +++ b/usr.bin/awk/tests/emp.data @@ -0,0 +1,6 @@ +Beth 4.00 0 +Dan 3.75 0 +Kathy 4.00 10 +Mark 5.00 20 +Mary 5.50 22 +Susie 4.25 18 diff --git a/usr.bin/awk/tests/factorial.awk b/usr.bin/awk/tests/factorial.awk new file mode 100644 index 0000000..b4957f7 --- /dev/null +++ b/usr.bin/awk/tests/factorial.awk @@ -0,0 +1,22 @@ +# Calculate factorial of command-line argument + +BEGIN { + # Get the command-line argument + if (ARGC < 2) { + print "ERROR: please provide number as command-line parameter" + exit 1 + } + n = ARGV[1]; ARGV[1] = ""; + # Print heading + print "Calculating",n,"factorial" + # Start the recursion + nf = factorial(n); + # All done; print the result + print "Result:",nf; +} + +# Recursive function +function factorial(n) { + if (n <= 1) return 1; + else return n*factorial(n-1); + } diff --git a/usr.bin/awk/tests/file1.UPPER b/usr.bin/awk/tests/file1.UPPER new file mode 100644 index 0000000..beffde5 --- /dev/null +++ b/usr.bin/awk/tests/file1.UPPER @@ -0,0 +1,19 @@ +# CREATE THE TEST ENVIRONMENT FOR TR + +# COMPILE AND LOAD FLAGS PASSED TO OCC +# -V: VERBOSE +# -I: ADD DIRECTORY TO HEADER PATH +CFLAGS += -V -I /USR/INCLUDE +LDFLAGS += -V + +# DEFAULT TARGET, "ALL," GENERATES THE FILES +ALL: FILE2.BIN1 GENBIN + +# FILES DEPEND UPON PROGRAM +FILE2.BIN1: GENBIN + ./GENBIN + +# REMOVE INTERMEDIATE FILES +CLEAN: + $(RM) -F *.O + $(RM) -F *.ROOT diff --git a/usr.bin/awk/tests/file1.mixed b/usr.bin/awk/tests/file1.mixed new file mode 100644 index 0000000..4cf2644 --- /dev/null +++ b/usr.bin/awk/tests/file1.mixed @@ -0,0 +1,19 @@ +# Create the test environment for tr + +# Compile and load flags passed to occ +# -v: verbose +# -I: add directory to header path +CFLAGS += -v -I /usr/include +LDFLAGS += -v + +# Default target, "all," generates the files +all: file2.bin1 genbin + +# Files depend upon program +file2.bin1: genbin + ./genbin + +# Remove intermediate files +clean: + $(RM) -f *.o + $(RM) -f *.root diff --git a/usr.bin/awk/tests/file1.nolower b/usr.bin/awk/tests/file1.nolower new file mode 100644 index 0000000..1e1de75 --- /dev/null +++ b/usr.bin/awk/tests/file1.nolower @@ -0,0 +1,19 @@ +# C + +# C +# -: +# -I: +CFLAGS += - -I // +LDFLAGS += - + +# D , "," +: 2.1 + +# F +2.1: + ./ + +# R +: + $(RM) - *. + $(RM) - *. diff --git a/usr.bin/awk/tests/file1.novowel b/usr.bin/awk/tests/file1.novowel new file mode 100644 index 0000000..2bb30f6 --- /dev/null +++ b/usr.bin/awk/tests/file1.novowel @@ -0,0 +1,19 @@ +# Crt th tst nvrnmnt fr tr + +# Cmpl nd ld flgs pssd t cc +# -v: vrbs +# -I: dd drctr t hdr pth +CFLAGS += -v -I /sr/ncld +LDFLAGS += -v + +# Dflt trgt, "ll," gnrts th fls +ll: fl2.bn1 gnbn + +# Fls dpnd pn prgrm +fl2.bn1: gnbn + ./gnbn + +# Rmv ntrmdt fls +cln: + $(RM) -f *. + $(RM) -f *.rt diff --git a/usr.bin/awk/tests/form.gen b/usr.bin/awk/tests/form.gen new file mode 100644 index 0000000..636b2be --- /dev/null +++ b/usr.bin/awk/tests/form.gen @@ -0,0 +1,22 @@ +# form.gen - generate form letters +# input: prototype file letter.text; data lines +# output: one form letter per data line + +BEGIN { + oldfs = FS; + FS = ":" + while (getline <"letter.text" > 0) # read form letter + form[++n] = $0 + FS = oldfs; + # get country name from command-line argument + pat = ARGV[1]; ARGV[1] = "-" +} + +$1 ~ pat { for (i = 1; i <= n; i++) { # read data line for country + temp = form[i] + for (j = 1; j <= 3; j++) + gsub("#" j, $j, temp) + gsub("#4", $2/$3, temp) + print temp + } +} diff --git a/usr.bin/awk/tests/form1 b/usr.bin/awk/tests/form1 new file mode 100644 index 0000000..3b59473 --- /dev/null +++ b/usr.bin/awk/tests/form1 @@ -0,0 +1,10 @@ +# form1 - format countries data by continent, pop. den. + +BEGIN { FS = ":" + printf("%-15s %-10s %10s %7s %12s\n", + "CONTINENT", "COUNTRY", "POPULATION", + "AREA", "POP. DEN.") + } + { printf("%-15s %-10s %7d %10d %10.1f\n", + $1, $2, $3, $4, $5) + } diff --git a/usr.bin/awk/tests/form2 b/usr.bin/awk/tests/form2 new file mode 100644 index 0000000..c3a38c1 --- /dev/null +++ b/usr.bin/awk/tests/form2 @@ -0,0 +1,15 @@ +# form2 - format countries by continent, pop. den. + +BEGIN { FS = ":" + printf("%-15s %-10s %10s %7s %12s\n", + "CONTINENT", "COUNTRY", "POPULATION", + "AREA", "POP. DEN.") + } + { if ($1 != prev) { + print "" + prev = $1 + } else + $1 = "" + printf("%-15s %-10s %7d %10d %10.1f\n", + $1, $2, $3, $4, $5) + } diff --git a/usr.bin/awk/tests/genrand.awk b/usr.bin/awk/tests/genrand.awk new file mode 100644 index 0000000..bd3651a --- /dev/null +++ b/usr.bin/awk/tests/genrand.awk @@ -0,0 +1,4 @@ +# generate random integers +BEGIN { for (i = 1; i <= 200; i++) + print int(101*rand()) + } diff --git a/usr.bin/awk/tests/grammar b/usr.bin/awk/tests/grammar new file mode 100644 index 0000000..6811c8d --- /dev/null +++ b/usr.bin/awk/tests/grammar @@ -0,0 +1,10 @@ +Sentence -> Nounphrase Verbphrase +Nounphrase -> the boy +Nounphrase -> the girl +Verbphrase -> Verb Modlist Adverb +Verb -> runs +Verb -> walks +Modlist -> +Modlist -> very Modlist +Adverb -> quickly +Adverb -> slowly diff --git a/usr.bin/awk/tests/histans1.awk b/usr.bin/awk/tests/histans1.awk new file mode 100644 index 0000000..6248aaa --- /dev/null +++ b/usr.bin/awk/tests/histans1.awk @@ -0,0 +1,19 @@ + + { x[int($1/10)]++ } +END { max = MAXSTARS = 25 + for (i = 0; i <= 10; i++) + if (x[i] > max) + max = x[i] + for (i = 0; i <= 10; i++) + y[i] = x[i]/max * MAXSTARS + for (i = 0; i < 10; i++) + printf(" %2d - %2d: %3d %s\n", + 10*i, 10*i+9, x[i], rep(y[i],"*")) + printf("100: %3d %s\n", x[10], rep(y[10],"*")) + } + +function rep(n,s, t) { # return string of n s's + while (n-- > 0) + t = t s + return t +} diff --git a/usr.bin/awk/tests/histogram b/usr.bin/awk/tests/histogram new file mode 100644 index 0000000..0430179 --- /dev/null +++ b/usr.bin/awk/tests/histogram @@ -0,0 +1,17 @@ +# histogram +# input: numbers between 0 and 100 +# output: histogram of deciles + + { x[int($1/10)]++ } + +END { for (i = 0; i < 10; i++) + printf(" %2d - %2d: %3d %s\n", + 10*i, 10*i+9, x[i], rep(x[i],"*")) + printf("100: %3d %s\n", x[10], rep(x[10],"*")) + } + +function rep(n,s, t) { # return string of n s's + while (n-- > 0) + t = t s + return t +} diff --git a/usr.bin/awk/tests/include.data b/usr.bin/awk/tests/include.data new file mode 100644 index 0000000..fe01548 --- /dev/null +++ b/usr.bin/awk/tests/include.data @@ -0,0 +1,4 @@ +This is a testfile for the awk test ch2p62.awk + +#include bigpop +#include smallpop diff --git a/usr.bin/awk/tests/info.awk b/usr.bin/awk/tests/info.awk new file mode 100644 index 0000000..127ae36 --- /dev/null +++ b/usr.bin/awk/tests/info.awk @@ -0,0 +1,7 @@ +BEGIN { FS = "\t"; pat = ARGV[1]; ARGV[1] = "-" } +$1 ~ pat { + printf("%s:\n", $1) + printf("\t%d million people\n", $3) + printf("\t%.3f million sq. mi.\n", $2/1000) + printf("\t%.1f people per sq. mi.\n", 1000*$3/$2) +} diff --git a/usr.bin/awk/tests/join.awk b/usr.bin/awk/tests/join.awk new file mode 100644 index 0000000..343f976 --- /dev/null +++ b/usr.bin/awk/tests/join.awk @@ -0,0 +1,46 @@ +# join - join file1 file2 on first field +# input: two sorted files, tab-separated fields +# output: natural join of lines with common first field + +BEGIN { + OFS = sep = "\t" + file2 = ARGV[2] + ARGV[2] = "" # read file1 implicitly, file2 explicitly + eofstat = 1 # end of file status for file2 + if ((ng = getgroup()) <= 0) + exit # file2 is empty +} + +{ while (prefix($0) > prefix(gp[1])) + if ((ng = getgroup()) <= 0) + exit # file2 exhausted + if (prefix($0) == prefix(gp[1])) # 1st attributes in file1 + for (i = 1; i <= ng; i++) # and file2 match + print $0, suffix(gp[i]) # print joined line +} + +function getgroup() { # put equal prefix group into gp[1..ng] + if (getone(file2, gp, 1) <= 0) # end of file + return 0 + for (ng = 2; getone(file2, gp, ng) > 0; ng++) + if (prefix(gp[ng]) != prefix(gp[1])) { + unget(gp[ng]) # went too far + return ng-1 + } + return ng-1 +} + +function getone(f, gp, n) { # get next line in gp[n] + if (eofstat <= 0) # eof or error has occurred + return 0 + if (ungot) { # return lookahead line if it exists + gp[n] = ungotline + ungot = 0 + return 1 + } + return eofstat = (getline gp[n] x { if (x == y+1) { + x = 1 + y = x * 2 + } else + print x, z[x] + } + +NR > 1 { print $1 } + +END { print NR } + diff --git a/usr.bin/awk/tests/percent b/usr.bin/awk/tests/percent new file mode 100644 index 0000000..47d5b0b --- /dev/null +++ b/usr.bin/awk/tests/percent @@ -0,0 +1,10 @@ +# percent +# input: a column of nonnegative numbers +# output: each number and its percentage of the total + + { x[NR] = $1; sum += $1 } + +END { if (sum != 0) + for (i = 1; i <= NR; i++) + printf("%10.2f %5.1f\n", x[i], 100*x[i]/sum) + } diff --git a/usr.bin/awk/tests/prep1 b/usr.bin/awk/tests/prep1 new file mode 100644 index 0000000..da7c9bd --- /dev/null +++ b/usr.bin/awk/tests/prep1 @@ -0,0 +1,6 @@ +# prep1 - prepare countries by continent and pop. den. + +BEGIN { FS = "\t" } + { printf("%s:%s:%d:%d:%.1f\n", + $4, $1, $3, $2, 1000*$3/$2) | "sort -t: +0 -1 +4rn" + } diff --git a/usr.bin/awk/tests/prep2 b/usr.bin/awk/tests/prep2 new file mode 100644 index 0000000..e069625 --- /dev/null +++ b/usr.bin/awk/tests/prep2 @@ -0,0 +1,7 @@ +# prep2 - prepare countries by continent, inverse pop. den. + +BEGIN { FS = "\t"} + { den = 1000*$3/$2 + printf("%-15s:%12.8f:%s:%d:%d:%.1f\n", + $4, 1/den, $1, $3, $2, den) | "sort" + } diff --git a/usr.bin/awk/tests/printenv.awk b/usr.bin/awk/tests/printenv.awk new file mode 100644 index 0000000..f95faa5 --- /dev/null +++ b/usr.bin/awk/tests/printenv.awk @@ -0,0 +1,23 @@ + +# Print environment variables' values; names passed on command line + +BEGIN { + if (ARGC < 2) { + print "Error: provide environment variable name on command line" + exit 1; + } + i = 1; + do { + rawname = ARGV[i]; + upname = toupper(rawname); + loname = tolower(rawname); + printf "%s = '%s'", rawname,ENVIRON[rawname]; + if (rawname != upname) + printf "; %s = '%s'", upname,ENVIRON[upname]; + if (rawname != loname) + printf "; %s = '%s'", loname,ENVIRON[loname]; + printf "\n" + i++; + } while (i < ARGC) + +} diff --git a/usr.bin/awk/tests/sentgen b/usr.bin/awk/tests/sentgen new file mode 100644 index 0000000..5deb02f --- /dev/null +++ b/usr.bin/awk/tests/sentgen @@ -0,0 +1,30 @@ +# sentgen - random sentence generator +# input: grammar file; sequence of nonterminals +# output: a random sentence for each nonterminal + +BEGIN { # read rules from grammar file + while (getline < "grammar" > 0) + if ($2 == "->") { + i = ++lhs[$1] # count lhs + rhscnt[$1, i] = NF-2 # how many in rhs + for (j = 3; j <= NF; j++) # record them + rhslist[$1, i, j-2] = $j + } else + print "illegal production: " $0 +} + +{ if ($1 in lhs) { # nonterminal to expand + gen($1) + printf("\n") + } else + print "unknown nonterminal: " $0 +} + +function gen(sym, i, j) { + if (sym in lhs) { # a nonterminal + i = int(lhs[sym] * rand()) + 1 # random production + for (j = 1; j <= rhscnt[sym, i]; j++) # expand rhs's + gen(rhslist[sym, i, j]) + } else + printf("%s ", sym) +} diff --git a/usr.bin/awk/tests/sentgen.data b/usr.bin/awk/tests/sentgen.data new file mode 100644 index 0000000..6ae2ecf --- /dev/null +++ b/usr.bin/awk/tests/sentgen.data @@ -0,0 +1,7 @@ +Sentence +Sentence +Nounphrase +Verb +Adverb +BadElement +Sentence diff --git a/usr.bin/awk/tests/sentgen2 b/usr.bin/awk/tests/sentgen2 new file mode 100644 index 0000000..a9837f8 --- /dev/null +++ b/usr.bin/awk/tests/sentgen2 @@ -0,0 +1,38 @@ +# sentgen2 - random sentence generator (nonrecursive) +# input: grammar file; sequence of nonterminals +# output: random sentences generated by the grammar + +BEGIN { # read rules from grammar file + while (getline < "grammar" > 0) + if ($2 == "->") { + i = ++lhs[$1] # count lhs + rhscnt[$1, i] = NF-2 # how many in rhs + for (j = 3; j <= NF; j++) # record them + rhslist[$1, i, j-2] = $j + } else + print "illegal production: " $0 +} + +{ if ($1 in lhs) { # nonterminal to expand + push($1) + gen() + printf("\n") + } else + print "unknown nonterminal: " $0 +} + +function gen( i, j) { + while (stp >= 1) { + sym = pop() + if (sym in lhs) { # a nonterminal + i = int(lhs[sym] * rand()) + 1 # random production + for (j = rhscnt[sym, i]; j >= 1; j--) # expand rhs's + push(rhslist[sym, i, j]) + } else + printf("%s ", sym) + } +} + +function push(s) { stack[++stp] = s } + +function pop() { return stack[stp--] } diff --git a/usr.bin/awk/tests/smallpop b/usr.bin/awk/tests/smallpop new file mode 100644 index 0000000..e69f21d --- /dev/null +++ b/usr.bin/awk/tests/smallpop @@ -0,0 +1,5 @@ +Canada 25 +Mexico 78 +France 55 +Germany 61 +England 56 diff --git a/usr.bin/awk/tests/sortgen b/usr.bin/awk/tests/sortgen new file mode 100644 index 0000000..fa5bbdf --- /dev/null +++ b/usr.bin/awk/tests/sortgen @@ -0,0 +1,58 @@ +# sortgen - generate sort command +# input: sequence of lines describing sorting options +# output: Unix sort command with appropriate arguments + +BEGIN { key = 0 } + +/no |not |n't / { print "error: can't do negatives:", $0; ok = 1 } + +# rules for global options + { ok = 0 } +/uniq|discard.*(iden|dupl)/ { uniq = " -u"; ok = 1 } +/separ.*tab|tab.*sep/ { sep = "t'\t'"; ok = 1 } +/separ/ { for (i = 1; i <= NF; i++) + if (length($i) == 1) + sep = "t'" $i "'" + ok = 1 + } +/key/ { key++; dokey(); ok = 1 } # new key; must come in order + +# rules for each key + +/dict/ { dict[key] = "d"; ok = 1 } +/ignore.*(space|blank)/ { blank[key] = "b"; ok = 1 } +/fold|case/ { fold[key] = "f"; ok = 1 } +/num/ { num[key] = "n"; ok = 1 } +/rev|descend|decreas|down|oppos/ { rev[key] = "r"; ok = 1 } +/forward|ascend|increas|up|alpha/ { next } # this is sort's default +!ok { print "error: can't understand:", $0 } + +END { # print flags for each key + cmd = "sort" uniq + flag = dict[0] blank[0] fold[0] rev[0] num[0] sep + if (flag) cmd = cmd " -" flag + for (i = 1; i <= key; i++) + if (pos[i] != "") { + flag = pos[i] dict[i] blank[i] fold[i] rev[i] num[i] + if (flag) cmd = cmd " +" flag + if (pos2[i]) cmd = cmd " -" pos2[i] + } + print cmd +} + +function dokey( i) { # determine position of key + for (i = 1; i <= NF; i++) + if ($i ~ /^[0-9]+$/) { + pos[key] = $i - 1 # sort uses 0-origin + break + } + for (i++; i <= NF; i++) + if ($i ~ /^[0-9]+$/) { + pos2[key] = $i + break + } + if (pos[key] == "") + printf("error: invalid key specification: %s\n", $0) + if (pos2[key] == "") + pos2[key] = pos[key] + 1 +} diff --git a/usr.bin/awk/tests/sortgen.in b/usr.bin/awk/tests/sortgen.in new file mode 100644 index 0000000..0e17ec7 --- /dev/null +++ b/usr.bin/awk/tests/sortgen.in @@ -0,0 +1,5 @@ +field separator is : +primary key is field 1 + increasing alphabetic +secondary key is field 5 + reverse numeric diff --git a/usr.bin/awk/tests/sum.asm b/usr.bin/awk/tests/sum.asm new file mode 100644 index 0000000..a4b0c9f --- /dev/null +++ b/usr.bin/awk/tests/sum.asm @@ -0,0 +1,16 @@ +# print sum of input numbers (terminated by zero) + + ld zero # initialize sum to zero + st sum +loop get # read a number + jz done # no more input if number is zero + add sum # add in accumulated sum + st sum # store new value back in sum + j loop # go back and read another number + +done ld sum # print sum + put + halt + +zero const 0 +sum const diff --git a/usr.bin/awk/tests/sum.data b/usr.bin/awk/tests/sum.data new file mode 100644 index 0000000..a71d0f9 --- /dev/null +++ b/usr.bin/awk/tests/sum.data @@ -0,0 +1,4 @@ +100 +2 +3 +0 diff --git a/usr.bin/awk/tests/sum3 b/usr.bin/awk/tests/sum3 new file mode 100644 index 0000000..c424698 --- /dev/null +++ b/usr.bin/awk/tests/sum3 @@ -0,0 +1,25 @@ +# sum3 - print sums of numeric columns +# input: rows of integers and strings +# output: sums of numeric columns +# assumes every line has same layout + +NR==1 { nfld = NF + for (i = 1; i <= NF; i++) + numcol[i] = isnum($i) + } + + { for (i = 1; i <= NF; i++) + if (numcol[i]) + sum[i] += $i + } + +END { for (i = 1; i <= nfld; i++) { + if (numcol[i]) + printf("%g", sum[i]) + else + printf("--") + printf(i < nfld ? "\t" : "\n") + } + } + +function isnum(n) { return n ~ /^[+-]?[0-9]+$/ } diff --git a/usr.bin/awk/tests/table b/usr.bin/awk/tests/table new file mode 100644 index 0000000..68509c6 --- /dev/null +++ b/usr.bin/awk/tests/table @@ -0,0 +1,33 @@ +# table - simple table formatter + +BEGIN { + FS = "\t"; blanks = sprintf("%100s", " ") + number = "^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)$" +} + +{ row[NR] = $0 + for (i = 1; i <= NF; i++) { + if ($i ~ number) + nwid[i] = max(nwid[i], length($i)) + wid[i] = max(wid[i], length($i)) + } +} + +END { + for (r = 1; r <= NR; r++) { + n = split(row[r], d) + for (i = 1; i <= n; i++) { + sep = (i < n) ? " " : "\n" + if (d[i] ~ number) + printf("%" wid[i] "s%s", numjust(i,d[i]), sep) + else + printf("%-" wid[i] "s%s", d[i], sep) + } + } +} + +function max(x, y) { return (x > y) ? x : y } + +function numjust(n, s) { # position s in field n + return s substr(blanks, 1, int((wid[n]-nwid[n])/2)) +} diff --git a/usr.bin/awk/tests/table1 b/usr.bin/awk/tests/table1 new file mode 100644 index 0000000..0d84521 --- /dev/null +++ b/usr.bin/awk/tests/table1 @@ -0,0 +1,39 @@ +# table1 - single column formatter +# input: one column of strings and decimal numbers +# output: aligned column + +BEGIN { + blanks = sprintf("%100s", " ") + number = "^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)$" + left = "^[+-]?[0-9]*" + right = "[.][0-9]*" +} + +{ row[NR] = $1 + if ($1 ~ number) { + match($1, left) # matches the empty string, so RLENGTH>=0 + lwid = max(lwid, RLENGTH) + if (!match($1, right)) + RLENGTH = 0 + rwid = max(rwid, RLENGTH) + wid = max(wid, lwid + rwid) + } else + wid = max(wid, length($1)) +} + +END { + for (r = 1; r <= NR; r++) { + if (row[r] ~ number) + printf("%" wid "s\n", numjust(row[r])) + else + printf("%-" wid "s\n", row[r]) + } +} + +function max(x, y) { return (x > y) ? x : y } + +function numjust(s) { # position s + if (!match(s, right)) + RLENGTH = 0 + return s substr(blanks, 1, int(rwid-RLENGTH+(wid-(lwid+rwid))/2)) +} diff --git a/usr.bin/awk/tests/unbundle b/usr.bin/awk/tests/unbundle new file mode 100644 index 0000000..d35b60a --- /dev/null +++ b/usr.bin/awk/tests/unbundle @@ -0,0 +1,4 @@ +# unbundle - unpack a bundle into separate files + +$1 != prev { close(prev); prev = $1 } + { print substr($0, index($0, " ") + 1) >$1 } diff --git a/usr.bin/awk/tests/wc.awk b/usr.bin/awk/tests/wc.awk new file mode 100644 index 0000000..cb11501 --- /dev/null +++ b/usr.bin/awk/tests/wc.awk @@ -0,0 +1,26 @@ +# awk program to emulate the wc command +{ + # Has input file changed? + if (FILENAME != file) { + if (startup == 0) { + # This is just the first time through + startup = 1; + } + else { + printf " %7d %7d %7d %s\n", nl, nw, nc, file; + tnl += nl; tnw += nw; tnc += nc; + nl = 0; nw = 0; nc = 0; + } + file = FILENAME; + numfiles++ + } + nl++; nw += NF; nc += length($0)+1; +} + +END { + printf " %7d %7d %7d %s\n", nl, nw, nc, file; + if (numfiles > 1) { + tnl += nl; tnw += nw; tnc += nc; + printf " %7d %7d %7d total\n", tnl, tnw, tnc; + } +}