Add 2020/kurdyukov1/try.sh + format/typo checks
The try.sh script tries to find md5sum and if it does not succeed it tries for openssl. If it is openssl it uses the subcommand md5; otherwise it just uses md5sum. Whatever the case if either is found it writes the checksum of prog.c to md5.txt and then it uses prog to write the checksum to prog.md5.txt. Then it uses diff -s on the two. If neither tool is found it just skips that check. Format/typo check README.md file.
This commit is contained in:
1 parent
057cb9469a
commit
6e08da7f56
3 files changed
+128
-22
No files matched your search
Executable
+65
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate IOCCC winner 2020/kurdyukov1
|
||||
#
|
||||
|
||||
# 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
|
||||
|
||||
# try and find an md5sum tool
|
||||
MD5SUM="$(type -P md5sum)"
|
||||
if [[ -z "$MD5SUM" ]]; then
|
||||
MD5SUM="$(type -P openssl)"
|
||||
fi
|
||||
|
||||
read -r -n 1 -p "Press any key to run: echo IOCCC | ./prog: "
|
||||
echo 1>&2
|
||||
echo IOCCC | ./prog
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./prog < prog.c: "
|
||||
echo 1>&2
|
||||
./prog < prog.c
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./prog < prog: "
|
||||
echo 1>&2
|
||||
./prog < prog
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./prog < prog.x86.asm: "
|
||||
echo 1>&2
|
||||
./prog < prog.x86.asm
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./prog < prog.x86_64.asm: "
|
||||
echo 1>&2
|
||||
./prog < prog.x86_64.asm
|
||||
|
||||
rm -f md5.txt prog.md5.txt
|
||||
if [[ -n "$MD5SUM" ]]; then
|
||||
if [[ "$(basename $MD5SUM)" == "openssl" ]]; then
|
||||
echo "$ $MD5SUM md5 prog.c | cut -f 2 -d' ' > md5.txt" 1>&2
|
||||
"$MD5SUM" md5 prog.c | cut -f 2 -d' ' > md5.txt
|
||||
echo "$ ./prog < prog.c > prog.md5.txt" 1>&2
|
||||
./prog < prog.c > prog.md5.txt
|
||||
else
|
||||
echo "$ $MD5SUM prog.c | cut -f1 -d' ' > md5.txt" 1>&2
|
||||
"$MD5SUM" prog.c | cut -f1 -d' ' > md5.txt
|
||||
echo "$ ./prog < prog.c > prog.md5.txt" 1>&2
|
||||
./prog < prog.c > prog.md5.txt
|
||||
fi
|
||||
read -r -n 1 -p "Press any key to compare the two files md5.txt and prog.md5.txt: "
|
||||
echo 1>&2
|
||||
diff -s md5.txt prog.md5.txt
|
||||
fi
|
||||
rm -f md5.txt prog.md5.txt
|
||||
Reference in new issue
Block a user