summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-03-27 15:42:52 +0200
committerlonkaars <loek@pipeframe.xyz>2023-03-27 15:42:52 +0200
commit446f7a2761b3f15e52f396ec337799d788efac97 (patch)
tree5ac72ae3a92470eb6b2f875506438385d3f7be4c
parent1ea23e3b923ea89b97a51edc75e1a8d13264e758 (diff)
add manpage and check requirements
-rw-r--r--license21
-rw-r--r--os1eindopdracht/readme.md3
-rwxr-xr-xos1eindopdracht/uhm8
-rw-r--r--os1eindopdracht/uhm.154
-rwxr-xr-xos1eindopdracht/uhm.awk22
5 files changed, 89 insertions, 19 deletions
diff --git a/license b/license
new file mode 100644
index 0000000..a86647f
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 lonkaars
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/os1eindopdracht/readme.md b/os1eindopdracht/readme.md
deleted file mode 100644
index 42a91b1..0000000
--- a/os1eindopdracht/readme.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# uhm (ultra hangman)
-
-
diff --git a/os1eindopdracht/uhm b/os1eindopdracht/uhm
index 324a863..5d13a13 100755
--- a/os1eindopdracht/uhm
+++ b/os1eindopdracht/uhm
@@ -1,4 +1,4 @@
-#!/bin/dash
+#!/bin/sh
WORD=""
DICT="/usr/share/dict/words"
ARGC=0
@@ -28,11 +28,13 @@ done
if [ -z "$WORD" ]; then
# check if dictionary file exists
[ ! -e "$DICT" ] && echo "dictionary file doesn't exist!" && exit 1
+ # check if dictionary file is a regular file (not directory, block device, etc.)
+ [ ! -f "$DICT" ] && echo "dictionary file isn't a regular file!" && exit 1
# check if dictionary file contains at least one line
[ ! "`wc -l "$DICT" | cut -d' ' -f1`" -gt "0" ] && echo "dictionary file is empty!" && exit 1
- # filter words containing apostrophe or words longer than 12 characters
- WORD="`sed -e "/'/d" -e '/.\{13\}/d' "$DICT" | sort -R | head -n1`"
+ # filter words containing apostrophe or space, or words longer than 12 characters
+ WORD="`sed -e "/' /d" -e '/.\{13\}/d' "$DICT" | sort -R | head -n1`"
# check if word is empty
[ -z "$WORD" ] && echo "no usable words found in dictionary" && exit 1
fi
diff --git a/os1eindopdracht/uhm.1 b/os1eindopdracht/uhm.1
new file mode 100644
index 0000000..ab15eff
--- /dev/null
+++ b/os1eindopdracht/uhm.1
@@ -0,0 +1,54 @@
+\# vim: ft=groff
+.TH uhm 1
+.SH NAME
+uhm \- ultra hangman
+.SH SYNPOSIS
+uhm [-h] [-w \fIword\fP] [-d \fIfile\fP]
+.SH DESCRIPTION
+Play a game of hangman, optionally using a custom dictionary or custom word.
+The terminal screen will always get cleared before playing.
+
+The player can input a single letter per turn. The player's turn is indicated
+by a caret '> ' prompt. When the word contains the input letter, the player
+keeps the same amount of turns. When the word does not contain the input
+letter, the player loses a turn. The game exits once all turns are depleted, or
+the player has guessed the word.
+.SH OPTIONS
+.TP
+\fB-h\fP
+show help
+.TP
+\fB-w \fIword\fP
+set custom word to \fIword\fP
+.TP
+\fB-d \fIfile\fP
+load random word from dictionary \fIfile\fP. Any words containing spaces,
+apostrophes, or words longer than 12 characters will get filtered. \fIfile\fP
+must be a regular file.
+.SH AUTHOR
+Written by Loek Le Blansch.
+.SH COPYRIGHT
+MIT License
+
+Copyright (c) 2023 lonkaars
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+.SH NOTES
+The main game logic is programmed in \fBawk\fR(1), so this implementation also
+supports non-ascii words.
diff --git a/os1eindopdracht/uhm.awk b/os1eindopdracht/uhm.awk
index c34333f..c57f7c5 100755
--- a/os1eindopdracht/uhm.awk
+++ b/os1eindopdracht/uhm.awk
@@ -1,7 +1,5 @@
#!/bin/awk -f
-function prompt() {
- printf "> "
-}
+function prompt() { printf "> " }
BEGIN {
word=word
@@ -11,15 +9,6 @@ BEGIN {
prompt()
}
-function header() {
- printf "\n\n\n"
- hidden_word = word
- # replace all characters not in set `guessed_letters` with "_"
- gsub("[^'"guessed_letters"]", "_", hidden_word)
- print "current word: " hidden_word
- print "you have " guesses " guess" (guesses == 1 ? "" : "es") " left"
-}
-
function guess(a) {
if (index(guessed_letters, a) != 0) {
print "already guessed " a "!"
@@ -41,7 +30,14 @@ function guess(a) {
exit 0
}
- header()
+ # print header
+ printf "\n\n\n"
+ hidden_word = word
+ # replace all characters not in set `guessed_letters` with "_"
+ gsub("[^'"guessed_letters"]", "_", hidden_word)
+ print "current word: " hidden_word
+ print "guessed letters: " guessed_letters
+ print "you have " guesses " guess" (guesses == 1 ? "" : "es") " left"
}
{