aboutsummaryrefslogtreecommitdiff
path: root/games/pks.awk
blob: 2219872bc50dee470616cf69ccc2854e2b59d0f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Ha, ha, ha! Awk!

# Process arguments
BEGIN {

    # Look for options; keep a count of non-option args
    ac = ARGC
    for (i = 1; i <= ARGC; i++) {

        # Show a pic of Phil
        if (ARGV[i] == "--phil") {
            pic = 1
            ARGV[i] = ""
            ac--
        }

        # End-of-options
        if (ARGV[i] == "--") {
            break
            ARGV[i] = ""
            ac--
        }
    }

    # If no arguments left, assume a dictionary file
    if (ac == 1) {
        ARGC = 2
        if ("DICT" in ENVIRON)
            ARGV[1] = ENVIRON["DICT"]
        else
            ARGV[1] = "/usr/share/dict/words"
    }

    # Seed the random number generator
    "rnds 2>/dev/null" | getline seed
    if (length(seed))
        srand(seed)
    else
        srand()
}

# Iterate over the lines, randomly assigning the first field of each one with a
# decreasing probability; this method
$1 ~ /[[:alpha:]]/ && rand() * ++n < 1 { wr = $1 }

# Ha, ha, ha! Incompetent!
END {

    # Check that we processed at least one line
    if (!NR)
        exit 1

    # Strip trailing possessives and punctuation
    sub(/[^[:alpha:]]+s*$/, "", wr)

    # Two or three "ha"s? Important decisions here folks
    hr = int(rand()*2+1)
    for (ha = "Ha"; hi < hr; hi++)
        ha = ha ", ha"

    # Capitalise the word
    wr = toupper(substr(wr,1,1)) substr(wr,2)

    # Return the laughter and the word
    if (pic)
        dopic(ha, wr)
    else
        printf "%s! %s!\n", ha, wr
}

# Ha, ha! Low-res!
function dopic(ha, wr) {
    print ""
    print "        " ha "! " wr "!"
    print "                 \\"
    print "                      .''''''''''''''''''''''.."
    print "                    .'''''''''''''''''''''''''''"
    print "                   .'''''''''''''''''''''''''''''"
    print "                  ,'''''''''''''''''''''''''''''''"
    print "                  '''''''''''''''''''''''''''''''':"
    print "                 ,'''''''''''##`'''''''''''''''.'''`"
    print "                 ;''''''''.###########,'''''',###'''"
    print "                 ;'''''';#################:'#####.''"
    print "                 `:''''''#########################'."
    print "                 ::`   ,'+########################';"
    print "                 ''''''':   .#####################''"
    print "                 ''''''''.####` `;#############;##'"
    print "                 ;''''''',####,###:  +############."
    print "               ,###''''''#############` ;##:#######"
    print "               ,#:##''';+#####+   :######  +##+    +"
    print "               ,'#;#,''#####',+###` ;####`+         "
    print "               ,#'#,#';############++. ,`##         "
    print "               :#####+:#######,@,``@@,#####'        "
    print "               ;#+#+#############++++##.#+##       +"
    print "                ###+################'####'##        "
    print "                 #######+###################.#   :."
    print "                   ######'########################'"
    print "                   ,+#####;#######################"
    print "                   ,#######;############'####+###:"
    print "                   ,#######################+#####'"
    print "                   ,###############' `   #'#  +'#"
    print "                  #,##.###########'##+##'###'####"
    print "                ``@.############## `+#@@@@@######"
    print "              +```@@################ ,,. .  ####."
    print "             ;````@@,##.##############':..:######"
    print "            ;`````@@@########.##################"
    print "         +````````@@@@#####;####################:"
    print "      +`````.`````@@@@######`###################```+"
    print "   +````````,`````'@@@@@##'#####################`````."
    print "+ ``````````.``````@@@@@@##'###'################```````` +"
    print "```````````````````@@@@@@@'#####;##########,##'`````````````.+"
    print "```````````````````@@@@@@@@@+#####':####+:+'````````````````````,"
    print "```````````````````,@@@@@@@@@#:#########'@@@``````````````````````"
    print "```````````.````````@@@@@@@@@@@@#'#####@@@@@```````````````````````"
    print "```````````.````````@@@@@@@@@@@@@@'  @@@@@@@.``````````````````````"
}