From f60184867b480bba44e5d4470dd8d58882195832 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 2 Jul 2017 01:40:32 +1200 Subject: Break pks(6df) and philsay(6df) in two Looks like awk(1) implementations vary in how they interpret option arguments. --- .gitignore | 1 + Makefile | 1 + README.markdown | 1 + games/philsay.sh | 47 ++++++++++++++++++++++++++++++ games/pks.awk | 80 ++++------------------------------------------------ man/man6/philsay.6df | 28 ++++++++++++++++++ man/man6/pks.6df | 6 ++-- 7 files changed, 86 insertions(+), 78 deletions(-) create mode 100644 games/philsay.sh create mode 100644 man/man6/philsay.6df diff --git a/.gitignore b/.gitignore index 7e2ae706..deccfe5e 100644 --- a/.gitignore +++ b/.gitignore @@ -149,6 +149,7 @@ games/chkl games/dr games/drakon games/kvlt +games/philsay games/pks games/rndn games/rot13 diff --git a/Makefile b/Makefile index a5af63a9..6cfee7a1 100644 --- a/Makefile +++ b/Makefile @@ -226,6 +226,7 @@ GAMES = games/aaf \ games/dr \ games/drakon \ games/kvlt \ + games/philsay \ games/pks \ games/rndn \ games/rot13 \ diff --git a/README.markdown b/README.markdown index 830ca51d..adc4c73a 100644 --- a/README.markdown +++ b/README.markdown @@ -554,6 +554,7 @@ There's some silly stuff in `install-games`: * `squ(6df)` makes a reduced Latin square out of each line of input. * `kvlt(6df)` translates input to emulate a style of typing unique to black metal communities on the internet. +* `philsay(6df)` shows a picture to accompany `pks(6df)` output. * `pks(6df)` laughs at a randomly selected word. * `rndn(6df)` implements an esoteric random number generation algorithm. * `strik(6df)` outputs s̶t̶r̶i̶k̶e̶d̶ ̶o̶u̶t̶ struck out text. diff --git a/games/philsay.sh b/games/philsay.sh new file mode 100644 index 00000000..dac2ae6e --- /dev/null +++ b/games/philsay.sh @@ -0,0 +1,47 @@ +#!/bin/shp +speech=$(pks "$@") || exit +printf '\n%066s\n' '( '"$speech"' )' +cat <<'EOF' + / + + .''''''''''''''''''''''.. + .''''''''''''''''''''''''''' + .''''''''''''''''''''''''''''' + ,''''''''''''''''''''''''''''''' + '''''''''''''''''''''''''''''''': + ,'''''''''''##`'''''''''''''''.'''` + ;''''''''.###########,'''''',###''' + ;'''''';#################:'#####.'' + `:''''''#########################'. + ::` ,'+########################'; + ''''''': .#####################'' + ''''''''.####` `;#############;##' + ;''''''',####,###: +############. + ,###''''''#############` ;##:####### + ,#:##''';+#####+ :###### +##+ + + ,'#;#,''#####',+###` ;####`+ + ,#'#,#';############++. ,`## + :#####+:#######,@,``@@,#####' + ;#+#+#############++++##.#+## + + ###+################'####'## + #######+###################.# :. + ######'########################' + ,+#####;####################### + ,#######;############'####+###: + ,#######################+#####' + ,###############' ` #'# +'# + #,##.###########'##+##'###'#### + ``@.############## `+#@@@@@###### + +```@@################ ,,. . ####. + ;````@@,##.##############':..:###### + ;`````@@@########.################## + +````````@@@@#####;####################: + +`````.`````@@@@######`###################```+ + +````````,`````'@@@@@##'#####################`````. ++ ``````````.``````@@@@@@##'###'################```````` + +```````````````````@@@@@@@'#####;##########,##'`````````````.+ +```````````````````@@@@@@@@@+#####':####+:+'````````````````````, +```````````````````,@@@@@@@@@#:#########'@@@`````````````````````` +```````````.````````@@@@@@@@@@@@#'#####@@@@@``````````````````````` +```````````.````````@@@@@@@@@@@@@@' @@@@@@@.`````````````````````` +EOF diff --git a/games/pks.awk b/games/pks.awk index 2219872b..06aad75f 100644 --- a/games/pks.awk +++ b/games/pks.awk @@ -3,27 +3,8 @@ # 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) { + if (ARGC == 1) { ARGC = 2 if ("DICT" in ENVIRON) ARGV[1] = ENVIRON["DICT"] @@ -40,10 +21,11 @@ BEGIN { } # Iterate over the lines, randomly assigning the first field of each one with a -# decreasing probability; this method +# decreasing probability; this method allows a single pass over the input, +# though it requires a lot of random numbers $1 ~ /[[:alpha:]]/ && rand() * ++n < 1 { wr = $1 } -# Ha, ha, ha! Incompetent! +# Ha, ha! Conclusion! END { # Check that we processed at least one line @@ -61,56 +43,6 @@ END { # 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 "```````````.````````@@@@@@@@@@@@@@' @@@@@@@.``````````````````````" + # Print the laughter and the word + printf "%s! %s!\n", ha, wr } diff --git a/man/man6/philsay.6df b/man/man6/philsay.6df new file mode 100644 index 00000000..4de7c476 --- /dev/null +++ b/man/man6/philsay.6df @@ -0,0 +1,28 @@ +.TH PHILSAY 6df "July 2017" "Manual page for philsay" +.SH NAME +.B philsay +\- Ha, ha, ha! ASCII art! +.SH USAGE +.B philsay +.br +.B philsay +FILE1 FILE2 +.br +program | +.B philsay +- +.br +DICT=$HOME/dict +.B philsay +.SH DESCRIPTION +.B philsay +shows a picture of our founder, Phil Ken Sebben, saying the first word of a +line randomly chosen from the input using pks(6df). +.P +A hyphen character "-" can be given as an argument to select standard input. +.SH SEE ALSO +pks(6df), cowsay(1df) +.br + +.SH AUTHOR +Tom Ryder diff --git a/man/man6/pks.6df b/man/man6/pks.6df index 47ddf7aa..dc430eff 100644 --- a/man/man6/pks.6df +++ b/man/man6/pks.6df @@ -12,8 +12,6 @@ program | .B pks - .br -.B pks ---phil DICT=$HOME/dict .B pks .SH DESCRIPTION @@ -23,9 +21,9 @@ no files are given, it defaults to /usr/share/dict/words, or the value of DICT (ha, ha!) if specified in the environment. .P A hyphen character "-" can be given as an argument to select standard input. -.P -Adding --phil will show a picture of our founder, Phil Ken Sebben. .SH SEE ALSO +philsay(6df) +.br .SH AUTHOR Tom Ryder -- cgit v1.2.3