aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2021-08-01 01:49:50 +1200
committerTom Ryder <tom@sanctum.geek.nz>2021-08-01 01:49:50 +1200
commit7a2628cb2e6e81cded2da702467c7b68b953f685 (patch)
tree7b12ccba3937bb2e953bcca71e74897a5cc8cf19
parentPare down Makefile for tests (diff)
downloaddoomsh-7a2628cb2e6e81cded2da702467c7b68b953f685.tar.gz
doomsh-7a2628cb2e6e81cded2da702467c7b68b953f685.zip
Use tabs for indentation
-rw-r--r--doomsh.bash98
-rw-r--r--tests/files.c18
-rw-r--r--tests/mem.c18
-rw-r--r--tests/stack.c10
-rw-r--r--tests/write.c32
5 files changed, 88 insertions, 88 deletions
diff --git a/doomsh.bash b/doomsh.bash
index 5c48aed..13d0dc9 100644
--- a/doomsh.bash
+++ b/doomsh.bash
@@ -21,19 +21,19 @@ self=doomsh
# Don't try to play doomsh if already playing doomsh
if [[ $DOOMSH ]] ; then
- printf '%s: Already playing doomsh!\n' \
- "$self" >&2
- exit 2
+ printf '%s: Already playing doomsh!\n' \
+ "$self" >&2
+ exit 2
fi
# Show the coloured logo; thanks to Frans P. de Vries for the classic ASCII art
# <http://www.gamers.org/~fpv/doombann.html>
printf >&2 %s "$( {
- tput AF 3 || tput setaf 3
- tput md || tput bold
+ tput AF 3 || tput setaf 3
+ tput md || tput bold
} 2>/dev/null )"
while IFS= read -r line ; do
- printf >&2 '%s\n' "$line"
+ printf >&2 '%s\n' "$line"
done <<EOF
______ _____ _____ __ ___
| __ \ _ | _ | \ / |
@@ -41,10 +41,10 @@ ______ _____ _____ __ ___
| | / | \_/ | \_/ | |\ /| |
| |/ / \ / \ /| | V | |
| ' / \_/ \_/ \_| | |
-|__/ \_|
+|__/ \_|
EOF
printf >&2 %s "$( {
- tput me || tput sgr0
+ tput me || tput sgr0
} 2>/dev/null )"
# Need to figure out a skill level
@@ -52,14 +52,14 @@ declare -i skill
# If we have an argument, that must be the skill level
if (($#)) ; then
- skill=$1
- shift
+ skill=$1
+ shift
# Otherwise, we'll give the user a menu to choose from
else
- while IFS= read -r line ; do
- printf >&2 '%s\n' "$line"
- done <<EOF
+ while IFS= read -r line ; do
+ printf >&2 '%s\n' "$line"
+ done <<EOF
1. I'm too young to die
2. Hey, not too rough
@@ -68,41 +68,41 @@ else
5. Nightmare!
EOF
- read -er -p '[1-5]: ' skill
+ read -er -p '[1-5]: ' skill
- # If the user chose "Nightmare!" mode, get them to confirm, in the true
- # spirit of things; otherwise, quit
- if ((skill == 5)) ; then
- while IFS= read -r line ; do
- printf '%s\n' "$line" >&2
- done <<EOF
+ # If the user chose "Nightmare!" mode, get them to confirm, in the true
+ # spirit of things; otherwise, quit
+ if ((skill == 5)) ; then
+ while IFS= read -r line ; do
+ printf '%s\n' "$line" >&2
+ done <<EOF
Are you sure? This skill level isn't even remotely fair.
EOF
- read -er -p '[y/N]: ' confirm
- [[ $confirm == [Yy]* ]] || exit 1
- fi
+ read -er -p '[y/N]: ' confirm
+ [[ $confirm == [Yy]* ]] || exit 1
+ fi
fi
# Don't accept any other skill level settings
case $skill in
- 1|2|3|4|5)
- ;;
- *)
- printf '%s: Unknown skill level\n' \
- "$self" >&2
- exit 2
+ 1|2|3|4|5)
+ ;;
+ *)
+ printf '%s: Unknown skill level\n' \
+ "$self" >&2
+ exit 2
esac
# Form a red prompt (hopefully) using terminal escapes
ps1=$(printf '%sdoomsh[%u]\$%s ' \
- "$( {
- tput AF 1 || tput setaf 1
- } 2>/dev/null )" \
- "$skill" \
- "$( {
- tput me || tput sgr0
- } 2>/dev/null )"
+ "$( {
+ tput AF 1 || tput setaf 1
+ } 2>/dev/null )" \
+ "$skill" \
+ "$( {
+ tput me || tput sgr0
+ } 2>/dev/null )"
)
# Set the limits based on the skill level
@@ -115,13 +115,13 @@ memory=$((1 << (19 - skill)))
# Display the limits
printf >&2 '\n'
printf >&2 'File size writing limit: %u blocks\n' \
- "$filesize"
+ "$filesize"
printf >&2 'Open files limit: %u\n' \
- "$files"
+ "$files"
printf >&2 'Stack size: %u kbytes\n' \
- "$stack"
+ "$stack"
printf >&2 'Memory size: %u kbytes\n' \
- "$memory"
+ "$memory"
printf >&2 '\n'
# Record the current seconds since shell start, so we can tell how long the
@@ -131,16 +131,16 @@ start=$SECONDS
# Open a subshell so that the ulimit settings don't persist after the fork
(
- # We only proceed if the ulimit call succeeds
- ulimit \
- -f "$filesize" \
- -n "$files" \
- -s "$stack" \
- -v "$memory" \
- || exit 2
- DOOMSH=$skill PS1=$ps1 bash --norc
+ # We only proceed if the ulimit call succeeds
+ ulimit \
+ -f "$filesize" \
+ -n "$files" \
+ -s "$stack" \
+ -v "$memory" \
+ || exit 2
+ DOOMSH=$skill PS1=$ps1 bash --norc
)
# Give the user some statistics about their performance
printf >&2 '%s: You lasted %u seconds at skill level %u!\n' \
- "$self" "$((SECONDS - start))" "$skill"
+ "$self" "$((SECONDS - start))" "$skill"
diff --git a/tests/files.c b/tests/files.c
index 9f85bfc..d11d530 100644
--- a/tests/files.c
+++ b/tests/files.c
@@ -22,13 +22,13 @@
/* files.c -- Open as many files as we can */
int main(void) {
- FILE *fp = NULL;
- int i = 0;
- for (;;i++) {
- if ((fp = tmpfile()) == NULL) {
- fprintf(stderr, "Created %u files\n", i);
- perror("tmpfile");
- raise(SIGABRT);
- }
- }
+ FILE *fp = NULL;
+ int i = 0;
+ for (;;i++) {
+ if ((fp = tmpfile()) == NULL) {
+ fprintf(stderr, "Created %u files\n", i);
+ perror("tmpfile");
+ raise(SIGABRT);
+ }
+ }
}
diff --git a/tests/mem.c b/tests/mem.c
index 2083949..025446d 100644
--- a/tests/mem.c
+++ b/tests/mem.c
@@ -29,13 +29,13 @@
* you really want to actually use the memory. Do you trust your OOM though?
*/
int main(void){
- void *ptr = NULL;
- unsigned long mb = 5;
- for (;;mb += 5) {
- fprintf(stderr, "%lu MB\n", mb);
- if ((ptr = realloc(ptr, mb * 1000000)) == NULL) {
- raise(SIGABRT);
- }
- /* memset(ptr, 0, mb * 1000000); */
- }
+ void *ptr = NULL;
+ unsigned long mb = 5;
+ for (;;mb += 5) {
+ fprintf(stderr, "%lu MB\n", mb);
+ if ((ptr = realloc(ptr, mb * 1000000)) == NULL) {
+ raise(SIGABRT);
+ }
+ /* memset(ptr, 0, mb * 1000000); */
+ }
}
diff --git a/tests/stack.c b/tests/stack.c
index 7c6846b..86bf042 100644
--- a/tests/stack.c
+++ b/tests/stack.c
@@ -23,11 +23,11 @@ void rec(int *ip);
/* stack.c -- Cause a stack overflow */
int main(void) {
- int i = 0;
- rec(&i);
+ int i = 0;
+ rec(&i);
}
void rec(int *ip) {
- char i[256];
- printf("%u\n", (*ip)++);
- rec(ip);
+ char i[256];
+ printf("%u\n", (*ip)++);
+ rec(ip);
}
diff --git a/tests/write.c b/tests/write.c
index 104cfdc..e503951 100644
--- a/tests/write.c
+++ b/tests/write.c
@@ -20,20 +20,20 @@
#include <stdio.h>
int main(void) {
- FILE *fp = NULL;
- int b = 1;
- char c = '\0';
- if ((fp = tmpfile()) == NULL) {
- perror("tmpfile");
- raise(SIGABRT);
- }
- for (;;b++) {
- if (fwrite(&c, 1, 1, fp) == 0) {
- perror("fwrite");
- raise(SIGABRT);
- }
- if (b % 1000 == 0) {
- fprintf(stderr, "Wrote %u octets\n", b);
- }
- }
+ FILE *fp = NULL;
+ int b = 1;
+ char c = '\0';
+ if ((fp = tmpfile()) == NULL) {
+ perror("tmpfile");
+ raise(SIGABRT);
+ }
+ for (;;b++) {
+ if (fwrite(&c, 1, 1, fp) == 0) {
+ perror("fwrite");
+ raise(SIGABRT);
+ }
+ if (b % 1000 == 0) {
+ fprintf(stderr, "Wrote %u octets\n", b);
+ }
+ }
}