forked from ioccc-src/winner
-
Notifications
You must be signed in to change notification settings - Fork 6
/
try.sh
executable file
·170 lines (136 loc) · 4.11 KB
/
try.sh
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC entry 2019/yang
#
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
# this way allows us to have the user specify a different compiler in an easy
# way.
if [[ -z "$CC" ]]; then
CC="cc"
fi
make CC="$CC" all >/dev/null || exit 1
# clear screen after compilation so that only the entry is shown
clear
echo "$ ./prog ioccc.txt a b c d e" 1>&2
read -r -n 1 -p "Press any key to scramble ioccc.txt into five files: "
echo 1>&2
./prog ioccc.txt a b c d e
read -r -n 1 -p "Press any key to unscramble part a with: cat a: "
clear
cat a
read -r -n 1 -p "Press any key to unscramble part b with: cat b: "
clear
cat b
read -r -n 1 -p "Press any key to unscramble part c with: cat c: "
clear
cat c
read -r -n 1 -p "Press any key to unscramble part d with: cat d: "
clear
cat d
read -r -n 1 -p "Press any key to unscramble part e with: cat e: "
clear
cat e
echo "$ cat a b c d e | ./prog" 1>&2
read -r -n 1 -p "Press any key to unscramble all parts: "
echo 1>&2
cat a b c d e | ./prog
echo 1>&2
read -r -n 1 -p "Press any key to run: cat a b c d e | ./prog | diff -s - ioccc.txt: "
echo 1>&2
cat a b c d e | ./prog | diff -s - ioccc.txt
LINES="$(tput lines)"
COLS="$(tput cols)"
if [[ "$COLS" -lt 75 || "$LINES" -lt 13 ]]; then
# if screen size < 75 x 13 then exit
exit 0
fi
echo 1>&2
echo "$ ./prog sample_input.txt a b c d e" 1>&2
read -r -n 1 -p "Press any key to scramble sample_input.txt into five files: "
echo 1>&2
./prog sample_input.txt a b c d e
read -r -n 1 -p "Press any key to unscramble part a with: cat a: "
clear
cat a
read -r -n 1 -p "Press any key to unscramble part b with: cat b: "
clear
cat b
read -r -n 1 -p "Press any key to unscramble part c with: cat c: "
clear
cat c
read -r -n 1 -p "Press any key to unscramble part d with: cat d: "
clear
cat d
read -r -n 1 -p "Press any key to unscramble part e with: cat e: "
clear
cat e
echo "$ cat a b c d e | ./prog" 1>&2
read -r -n 1 -p "Press any key to unscramble all parts: "
echo 1>&2
cat a b c d e | ./prog
echo 1>&2
read -r -n 1 -p "Press any key to run: cat a b c d e | ./prog | diff -s - sample_input.txt: "
echo 1>&2
cat a b c d e | ./prog | diff -s - sample_input.txt
echo 1>&2
if [[ "$COLS" -lt 80 || "$LINES" -lt 25 ]]; then
# if screen size < 80 x 25 then exit
exit 0
fi
read -r -n 1 -p "Press any key to run: cat prog.c: "
echo 1>&2
cat prog.c
echo 1>&2
echo "$ ./prog prog.c a b c d e" 1>&2
read -r -n 1 -p "Press any key to scramble prog.c into five files: "
echo 1>&2
./prog prog.c a b c d e
read -r -n 1 -p "Press any key to unscramble part a with: cat a: "
clear
cat a
read -r -n 1 -p "Press any key to unscramble part b with: cat b: "
clear
cat b
read -r -n 1 -p "Press any key to unscramble part c with: cat c: "
clear
cat c
read -r -n 1 -p "Press any key to unscramble part d with: cat d: "
clear
cat d
read -r -n 1 -p "Press any key to unscramble part e with: cat e: "
clear
cat e
echo "$ cat a b c d e | ./prog" 1>&2
read -r -n 1 -p "Press any key to unscramble all parts: "
echo 1>&2
cat a b c d e | ./prog
echo 1>&2
read -r -n 1 -p "Press any key to run: cat a b c d e | ./prog | diff -s - prog.c: "
echo 1>&2
cat a b c d e | ./prog | diff -s - prog.c
echo 1>&2
# For the next three we have to see if ruby is installed
RUBY="$(type -P ruby)"
if [[ -n "$RUBY" ]]; then
read -r -p "Do you want to see the slow scrambling: ./prog prog.c | ruby prog.c (Y/N)? "
echo 1>&2
if [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]; then
echo "This may take a while, hit ctrl-c to exit script." 1>&2
echo 1>&2
./prog prog.c | ruby prog.c
fi
read -r -p "Do you want to see the slow scrambling: ./prog violet.c | ruby prog.c (Y/N)? "
echo 1>&2
if [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]; then
echo "This may take a while, hit ctrl-c to exit script." 1>&2
echo 1>&2
./prog violet.c | ruby prog.c
fi
read -r -p "Do you want to see the slow scrambling: ./prog violet.c | ruby violet.c (Y/N)? "
echo 1>&2
if [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]; then
echo "This may take a while, hit ctrl-c to exit script." 1>&2
echo 1>&2
./prog violet.c | ruby violet.c
fi
fi