From 211a27769e0c00bb8102d1fb4eb7ada533a88f77 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Mon, 13 Nov 2023 14:36:24 -0800 Subject: [PATCH] Add alt code, scripts + format fixes in 2000/tomx The alt code is based on the author's remarks with a fix so that it actually works (I presume it once did work but it no longer did). This compiles mkentry.c and running tomx.alt ends up running mkentry! The try.sh script shows the different ways tomx.c can be used: as a script, as a compiled file and as a Makefile. 'tomx.c' as a shell script compiles itself and as a Makefile it does the same thing! The try.alt.sh does more or less the same thing as try.sh but it works for the alt code which works with mkentry.c (see above). Format/typo fix README.md. Although the try.sh and try.alt.sh script both chmod +x the source code the code here in the repo is now +x as well because it can be used as a script and a Makefile as well as compiled as C. I believe this completes the review of 2000/tomx. --- 2000/tomx/.gitignore | 1 + 2000/tomx/Makefile | 7 +++++-- 2000/tomx/README.md | 37 ++++++++++++++++++++++++++----------- 2000/tomx/tomx.alt.c | 23 +++++++++++++++++++++++ 2000/tomx/tomx.c | 0 2000/tomx/try.alt.sh | 23 +++++++++++++++++++++++ 2000/tomx/try.sh | 34 ++++++++++++++++++++++++++++++++++ thanks-for-fixes.md | 14 +++++++++++++- 8 files changed, 125 insertions(+), 14 deletions(-) create mode 100755 2000/tomx/tomx.alt.c mode change 100644 => 100755 2000/tomx/tomx.c create mode 100755 2000/tomx/try.alt.sh create mode 100755 2000/tomx/try.sh diff --git a/2000/tomx/.gitignore b/2000/tomx/.gitignore index 6d96ee23d..0bec0a937 100644 --- a/2000/tomx/.gitignore +++ b/2000/tomx/.gitignore @@ -1,4 +1,5 @@ tomx +tomx.alt mkentry tomx.orig prog.orig diff --git a/2000/tomx/Makefile b/2000/tomx/Makefile index 31eeb183f..c5a8f1658 100644 --- a/2000/tomx/Makefile +++ b/2000/tomx/Makefile @@ -111,8 +111,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# @@ -135,6 +135,9 @@ ${PROG}: ${PROG}.c alt: data ${ALT_TARGET} @${TRUE} +${PROG}.alt: ${PROG}.alt.c + ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} + # data files # data: ${DATA} diff --git a/2000/tomx/README.md b/2000/tomx/README.md index 206280726..01e431be5 100644 --- a/2000/tomx/README.md +++ b/2000/tomx/README.md @@ -4,6 +4,9 @@ make ``` +There is an alternate version that compiles [mkentry.c](mkentry.c). See +[alternate code](#alternate-code). + ## To use: @@ -15,18 +18,29 @@ make ### Try: ```sh -rm -f ./tomx -chmod +x ./tomx.c -./tomx.c -./tomx +./try.sh ``` -as well as: + +## Alternate code: + +This alternate code is based on the author's remarks with a slight fix so that +it will do what it once did, compile and run [mkentry.c](mkentry.c). You can use +it in a similar way as [tomx.c](tomx.c), both executing the source file and +using it as a Makefile and running the code ends up running `mkentry`. + + +### Alternate build: ```sh -rm -f ./tomx -make -f tomx.c -./tomx +make alt +``` + + +### Alternate try: + +```sh +./try.alt.sh ``` @@ -45,14 +59,15 @@ changes don't change the shell code or the Makefile. This program works as a C source file, a Makefile and also as a shell (`/bin/sh`) script. But unlike some other multi-language programs, this one is -NOT meant to print "Hello, world" in all 3 cases (At least in the true sense -;-)). The C, make and shell code build upon each other to create a C program (?) +NOT meant to print `Hello, world` in all 3 cases (At least in the true sense +;-)). The C, Makefile and shell code build upon each other to create a C program (?) which when executed as a shell script will compile itself through the C compiler using a Makefile! - Pretty useful, Eh? Probably, this is the first entry ever to fully satisfy Rule #1 ("Your entry must be a complete program") in the strictest sense;-) + ### Top 5 reasons (IMHO) why this code is an entry for IOCCC 1. A glance at the source itself will tell you that most of the @@ -67,7 +82,7 @@ C (But again, there was NO obfuscated make/shscript contest) obfuscation should be in C and not elsewhere???. Mmmmm...). 3. Extending Argument #2... Obfuscation done in the C code -(comments?) create obfuscated code for the other 2 languages. +(comments?) creates obfuscated code for the other 2 languages. This opens new possibilities to be explored in depth in future `IOCCC`s. diff --git a/2000/tomx/tomx.alt.c b/2000/tomx/tomx.alt.c new file mode 100755 index 000000000..ca751d090 --- /dev/null +++ b/2000/tomx/tomx.alt.c @@ -0,0 +1,23 @@ +#include +#define true + +true /*:all + +CC=cc +PROG=mkentry + +false : + make -f $0 $1 + exit 0 + +all: $(PROG) + +%:%.c + $(CC) $< -o $@ + +clean: + rm $(PROG) + +.PHONY: /* true clean */ +#undef true +#include "mkentry.c" diff --git a/2000/tomx/tomx.c b/2000/tomx/tomx.c old mode 100644 new mode 100755 diff --git a/2000/tomx/try.alt.sh b/2000/tomx/try.alt.sh new file mode 100755 index 000000000..1d8f730d8 --- /dev/null +++ b/2000/tomx/try.alt.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# +# try.sh - script to show 2000/tomx + +echo "Using tomx.alt.c to compile mkentry.c directly:" 1>&2 +echo "$ chmod +x tomx.alt.c" 1>&2 +chmod +x tomx.alt.c +echo "$ rm -f mkentry" 1>&2 +rm -f mkentry +echo "$ ./tomx.alt.c" 1>&2 +./tomx.alt.c +echo 1>&2 + +echo "Using tomx.alt.c as a Makefile to compile mkentry.c:" 1>&2 +echo "$ rm -f mkentry" +rm mkentry +echo "$ make -f tomx.alt.c" 1>&2 +make -f tomx.alt.c +echo 1>&2 + +echo "Running mkentry via tomx.alt:" 1>&2 +echo "$ ./tomx.alt" 1>&2 +./tomx.alt diff --git a/2000/tomx/try.sh b/2000/tomx/try.sh new file mode 100755 index 000000000..db719b5b8 --- /dev/null +++ b/2000/tomx/try.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# try.sh - script to show 2000/tomx + +if [[ ! -f "tomx" || ! -e "tomx" ]]; then + echo "Compiling tomx.c:" 1>&2 + make all || exit 1 +fi + +echo "Running tomx:" 1>&2 +echo "$ ./tomx" 1>&2 +./tomx +echo 1>&2 + +echo "Using source code to compile tomx.c: " 1>&2 +echo "$ rm -f tomx" 1>&2 +rm -f tomx +echo "$ chmod +x tomx.c" 1>&2 +chmod +x tomx.c +echo "$ ./tomx.c" 1>&2 +./tomx.c +echo "Running tomx again:" 1>&2 +echo "$ ./tomx" 1>&2 +./tomx + +echo 1>&2 +echo "Using tomx.c as a Makefile:" 1>&2 +echo "$ rm -f tomx" 1>&2 +rm -f tomx +echo "$ make -f tomx.c" 1>&2 +make -f tomx.c +echo "Running tomx again:" 1>&2 +echo "$ ./tomx" +./tomx diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index ca6e039e4..b37f0cc3e 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -2248,7 +2248,8 @@ commands that we recommended. Cody changed this entry to use `fgets()` instead of `gets()` to make it safer and to prevent annoying warnings from showing up at compiling, linking and/or -runtime, the latter interspersed with the output of the program. +runtime, the latter interspersed with the output of the program. This involved +changing the `K` arg to `gets(3)` to `&K` in `fgets(3)`. Cody later improved the fix to use `gets()` by redefining `gets()` so that the code looks like before. @@ -2330,6 +2331,17 @@ the curses and the SDL versions as Cody does not have a DOS system to test the other version in. +## [2000/tomx](2000/tomx/tomx.c) ([README.md](2000/tomx/README.md])) + +Cody added the [alt code](2000/tomx/README.md#alternate-code) based on the +author's remarks with a fix for modern systems and he also added the two +scripts, [try.sh](2000/tomx/try.sh) and [try.alt.sh](2000/tomx/try.alt.sh) for +the main code and the alt code respectively. + +And although the scripts do `chmod +x` on the source code (see the README.md for +details) the source code is now executable by default. + + ## [2001/anonymous](2001/anonymous/anonymous.c) ([README.md](2001/anonymous/README.md])) Cody fixed both the supplementary program and the program itself (both of which