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.
This commit is contained in:
Cody Boone Ferguson committed 2023-11-13 14:36:24 -08:00
1 parent a979195d7b
commit 211a27769e
8 files changed
+125 -14

No files matched your search

+1
View File
@@ -1,4 +1,5 @@
tomx
tomx.alt
mkentry
tomx.orig
prog.orig
+5 -2
View File
@@ -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}
+26 -11
View File
@@ -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.
+23
View File
@@ -0,0 +1,23 @@
#include <stdio.h>
#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"
Regular → Executable
View File
File mode changed.
+23
View File
@@ -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
+34
View File
@@ -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
+13 -1
View File
@@ -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