From 66e54fac9bd9cd5c55246b459330f9e5bb577025 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Mon, 9 Oct 2023 04:03:22 -0700 Subject: [PATCH] Updates and fixes to 2013/dlowe Added fun.c and make make all compile it: this is what the judges suggested one try compiling with different compilers and checking the results. I added how to specify the compiler. Added slen.sh script, corrected for shellcheck, which runs the command the author suggested (and which the judges added to their remarks), to make it simpler for viewers of the entry. Added INABIAF section to README.md: if no args are specified it will very likely crash or do something funny. A similar such thing is in bugs.md as well. Updated .gitignore. Format fix README.md. --- 2013/dlowe/.gitignore | 2 + 2013/dlowe/Makefile | 5 ++- 2013/dlowe/README.md | 91 +++++++++++++++++++++++++++++++++++++------ 2013/dlowe/demo.sh | 21 ++++++++++ 2013/dlowe/fun.c | 5 +++ 2013/dlowe/slen.sh | 3 ++ bugs.md | 13 +++++++ thanks-for-fixes.md | 19 +++++++++ 8 files changed, 146 insertions(+), 13 deletions(-) create mode 100755 2013/dlowe/demo.sh create mode 100644 2013/dlowe/fun.c create mode 100755 2013/dlowe/slen.sh diff --git a/2013/dlowe/.gitignore b/2013/dlowe/.gitignore index 54b04a50b..359a2057a 100644 --- a/2013/dlowe/.gitignore +++ b/2013/dlowe/.gitignore @@ -1,3 +1,5 @@ dlowe dlowe.orig +fun prog.orig +sparkl diff --git a/2013/dlowe/Makefile b/2013/dlowe/Makefile index b5ff4a318..8406028d7 100644 --- a/2013/dlowe/Makefile +++ b/2013/dlowe/Makefile @@ -109,7 +109,7 @@ PROG= ${ENTRY} # OBJ= ${PROG}.o DATA= -TARGET= ${PROG} +TARGET= ${PROG} sparkl fun # ALT_OBJ= ALT_TARGET= @@ -129,6 +129,9 @@ all: data ${TARGET} ${PROG}: ${PROG}.c ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} +sparkl: ${PROG} + ${LN} -sf ${PROG} $@ + # alternative executable # alt: data ${ALT_TARGET} diff --git a/2013/dlowe/README.md b/2013/dlowe/README.md index a67ec7921..ec2ee2b79 100644 --- a/2013/dlowe/README.md +++ b/2013/dlowe/README.md @@ -22,11 +22,49 @@ make ```sh ./dlowe 0 1 2 3 4 5 6 7 ./dlowe 16 32 64 128 - -echo sparkline of file sizes: `wc -c * | awk '{print $1}' | xargs ./dlowe` +./dlowe 16 32 64 128 256 +./dlowe 16 32 64 128 256 512 ./dlowe 0 + +echo "sparkline of file sizes: $(wc -c * | awk '{print $1}' | xargs ./dlowe)" # or ./slen.sh ``` +Alternatively, for the lazy or those short on time, try: + +```sh +./demo.sh +``` + +What is different about the above if you do something like: + +```sh +echo 'IOCCC 2013' > ioccc.txt +./demo.sh +rm -f ioccc.txt +``` + +? + +To make it simpler to see try showing just the last two lines: + +```sh +./demo.sh | tail -n 2 > 1.txt +echo 'IOCCC 2013' > ioccc.txt +./demo.sh | tail -n 2 > 2.txt +rm -f ioccc.txt +diff 1.txt 2.txt +rm 1.txt 2.txt +``` + +## INABIAF - it's not a bug it's a feature! :-) + +This program will very likely crash or draw something funny with 0 args. Then +again it might not. :-) This is not a bug and should NOT be fixed. + +Ask yourself the following questions: when will it crash, when will it draw +something funny (or will it ? :-) ) and when will it do nothing? + + ## Judges' remarks: We liked how this entry used Unicode, specifically UTF-8, in a somewhat obfuscated way. @@ -34,7 +72,7 @@ We liked how this entry used Unicode, specifically UTF-8, in a somewhat obfuscat Also, why doesn't it crash, and produces a correct output when called with one argument or when all arguments are equal? -For extra fun, compile and run +For extra fun, compile and run [fun.c](fun.c): ```c #include @@ -45,37 +83,66 @@ int main() { with gcc and clang. + With GCC (4.7.2), we get - -2147483648 -2147483648 -2147483648 +``` +-2147483648 -2147483648 -2147483648 +``` and with clang (3.3), we get - -2147483648 0 2147483647 +``` +-2147483648 0 2147483647 +``` + +and with Apple clang version 15.0.0 (clang-1500.0.40.1) we get: + +``` +1840985120 -2033041452 35979112 +``` Which one is correct? :) +NOTE: `make all` will compile [fun.c](fun.c) but to provide a different compiler +you can do something like: + + +```sh +make CC=clang fun +``` + + ## Author's remarks: ### sparkl -A tiny implementation of command-line 'sparkline' data visualization. +A tiny implementation of command-line +[sparkline](https://en.wikipedia.org/wiki/Sparkline) data visualization. ### Synopsis ```sh -$ sparkl 0 1 2 3 4 5 6 7 +$ ./sparkl 0 1 2 3 4 5 6 7 ▁▂▃▄▅▆▇▉ -$ echo sparkline of file lengths: `wc -c * | awk '{print $1}' | xargs sparkl` +$ echo "sparkline of file lengths: $(wc -c * | awk '{print $1}' | xargs ./sparkl)" sparkline of file sizes: ▁▁▁▃▃▂▁▂▁▁▉ ``` +NOTE: this has been provided in [slen.sh](slen.sh) so you can try: + +```sh +./slen.sh +``` + +instead. + ### Description This is a handy little tool for visualizing numeric series from the -command-line, using 'sparklines'. Pass it a numeric series as arguments, and -sparkl will display a sparkline graph, which you can use to very quickly get a +command line, using sparklines. Pass it a numeric series as arguments, and +`sparkl` will display a sparkline graph, which you can use to very quickly get a sense of the shape of your data. ### Limitations @@ -83,7 +150,7 @@ sense of the shape of your data. * Crashes with 0 arguments. It'd be trivial to fix, but adds a few bytes to the code. * Produces bogus graphs when given > about 5000 arguments. -* Only works if your terminal is utf-8 and your font supports the 8 glyphs +* Only works if your terminal is UTF-8 and your font supports the 8 glyphs used. * Produces a few harmless compiler warnings. @@ -92,7 +159,7 @@ sense of the shape of your data. The code is very terse. I was torn between submitting this version, and a one-line version compressed using a couple more -D flags. -Hand-rolled utf-8 sequence, magic numbers (what's that 7 for?), meaningless +Hand-rolled UTF-8 sequence, magic numbers (what's that 7 for?), meaningless variable names, reused variables, and so on. ### Acknowledgements diff --git a/2013/dlowe/demo.sh b/2013/dlowe/demo.sh new file mode 100755 index 000000000..daebfe6e6 --- /dev/null +++ b/2013/dlowe/demo.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +make clobber all || exit 1 + +echo "$ ./dlowe 0 1 2 3 4 5 6 7" +./dlowe 0 1 2 3 4 5 6 7 +echo +echo "$ ./dlowe 16 32 64 128" +./dlowe 16 32 64 128 +echo +echo "$ ./dlowe 16 32 64 128 256" +./dlowe 16 32 64 128 256 +echo +echo "$ ./dlowe 16 32 64 128 256 512" +./dlowe 16 32 64 128 256 512 +echo +echo "$ ./dlowe 0" +./dlowe 0 +echo +echo "$ ./slen.sh" +./slen.sh diff --git a/2013/dlowe/fun.c b/2013/dlowe/fun.c new file mode 100644 index 000000000..cdcd0ae10 --- /dev/null +++ b/2013/dlowe/fun.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("%d %d %d\n", (int)(-1.0/0.0), (int)(0.0/0.0), (int)(1.0/0.0)); +} + diff --git a/2013/dlowe/slen.sh b/2013/dlowe/slen.sh new file mode 100755 index 000000000..83461efb8 --- /dev/null +++ b/2013/dlowe/slen.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo "sparkline of file lengths: $(wc -c ./* | awk '{print $1}' | xargs ./sparkl)" diff --git a/bugs.md b/bugs.md index e7e751a27..7eda8c0d9 100644 --- a/bugs.md +++ b/bugs.md @@ -1840,6 +1840,19 @@ The file is `hd.img`. Do you have it? Please provide it! +## [2013/dlowe](2013/dlowe/dlowe.c) ([README.md](2013/dlowe/README.md)) +## STATUS: INABIAF - please **DO NOT** fix + +This program will very likely crash or draw something strange with 0 args. Then +again it might not. :-) This is easy to fix but would add bytes and since the +author noted it is a feature and not a bug. You of course can try and fix it +yourself but please do NOT open a pull request for this: just do it as an +exercise to see if you understand the code. + +You can try and answer the questions, too: when will it crash? When will it draw +something funny (or will it? :-) ) and when will it just do nothing? + + # 2014 diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 1790598d2..74833cd1b 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -1610,6 +1610,25 @@ Finally Cody provided the [bios.asm](2013/cable3/bios.asm) that the author referred to, found at the [GitHub repo for the entry](https://github.com/adriancable/8086tiny/tree/master). +## [2013/dlowe](2013/dlowe/dlowe.c) ([README.md](2013/dlowe/README.md)) + +Cody added the source code that we suggested one should compile and run with +different compilers as [fun.c](2013/dlowe/fun.c). He modified the Makefile so +that running `make all` will compile it, saving you the effort. + +He also provided the script [slen.sh](2013/dlowe/slen.sh) which is based on the +author's remarks, giving a script that shows the spark line of the file lengths +(as in `wc -c`), fixing it for shellcheck. These fixes were applied in the +author's remarks as well. + +Since the author called the program `sparkl` Cody modified the Makefile so that +running `make all` will create a symlink to `dlowe` as `sparkl`. Running `make +clobber` will delete both and running `make clobber all` will ensure that the +symlink is created. + +Cody also added the [demo.sh](2013/dlowe/demo.sh) script to more easily try the +program. + ## [2013/hou](2013/hou/hou.c) ([README.md](2013/hou/README.md)) After the file 2013/hou/doc/example.markdown was moved to