Fixes recursion bug in disambiguate_in().
[ohcount] / test / expected_dir / awk1.awk
1 awk     comment # prchecks - print formatted checks
2 awk     comment #   input:  number \t amount \t payee
3 awk     comment #   output: eight lines of text for preprinted check forms
4 awk     blank   
5 awk     code    BEGIN {
6 awk     code        FS = "\t"
7 awk     code        dashes = sp45 = sprintf("%45s", " ")
8 awk     code        gsub(/ /, "-", dashes)        # to protect the payee
9 awk     code        "date" | getline date         # get today's date
10 awk     code        split(date, d, " ")
11 awk     code        date = d[2] " " d[3] ", " d[6]
12 awk     code        initnum()    # set up tables for number conversion
13 awk     code    }
14 awk     code    NF != 3 || $2 >= 1000000 {        # illegal data
15 awk     code        printf("\nline %d illegal:\n%s\n\nVOID\nVOID\n\n\n", NR, $0)
16 awk     code        next                          # no check printed
17 awk     code    }
18 awk     code    {   printf("\n")                  # nothing on line 1
19 awk     code        printf("%s%s\n", sp45, $1)    # number, indented 45 spaces
20 awk     code        printf("%s%s\n", sp45, date)  # date, indented 45 spaces
21 awk     code        amt = sprintf("%.2f", $2)     # formatted amount
22 awk     code        printf("Pay to %45.45s   $%s\n", $3 dashes, amt)  # line 4
23 awk     code        printf("the sum of %s\n", numtowords(amt))        # line 5
24 awk     code        printf("\n\n\n")              # lines 6, 7 and 8
25 awk     code    }
26 awk     blank   
27 awk     code    function numtowords(n,   cents, dols) { # n has 2 decimal places
28 awk     code        cents = substr(n, length(n)-1, 2)
29 awk     code        dols = substr(n, 1, length(n)-3)
30 awk     code        if (dols == 0)
31 awk     code            return "zero dollars and " cents " cents exactly"
32 awk     code        return intowords(dols) " dollars and " cents " cents exactly"
33 awk     code    }
34 awk     blank   
35 awk     code    function intowords(n) {
36 awk     code        n = int(n)
37 awk     code        if (n >= 1000)
38 awk     code            return intowords(n/1000) " thousand " intowords(n%1000)
39 awk     code        if (n >= 100)
40 awk     code            return intowords(n/100) " hundred " intowords(n%100)
41 awk     code        if (n >= 20)
42 awk     code            return tens[int(n/10)] " " intowords(n%10)
43 awk     code        return nums[n]
44 awk     code    }
45 awk     blank   
46 awk     code    function initnum() {
47 awk     code        split("one two three four five six seven eight nine " \
48 awk     code                            prchecks           "ten eleven twelve thirteen fourteen fifteen " \
49 awk     code                            prchecks           "sixteen seventeen eighteen nineteen", nums, " ")
50 awk     code        split("ten twenty thirty forty fifty sixty " \
51 awk     code             prchecks           "seventy eighty ninety", tens, " ")
52 awk     code    }
53 awk     blank