Fixes to 2001/westley
The Makefile now always regenerates the .sort.c and the .punch.c versions if westley.c has been modified. The try.sh script had a typo (not in a command that ends up being run but rather showing what would be run). Add bugs and (mis)features section with two statuses. Format/typo check README.md file. It is not clear to me just yet if this completes the review of the entry but it might.
This commit is contained in:
1 parent
d0b2db5220
commit
b917158c37
4 files changed
+88
-34
No files matched your search
+14
-4
@@ -145,10 +145,6 @@ westley2: westley2.c
|
|||||||
westley3: westley3.c
|
westley3: westley3.c
|
||||||
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
||||||
|
|
||||||
${PROG}.sort: ${PROG}.sort.c
|
|
||||||
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
|
||||||
|
|
||||||
|
|
||||||
# alternative executable
|
# alternative executable
|
||||||
#
|
#
|
||||||
alt: data ${ALT_TARGET}
|
alt: data ${ALT_TARGET}
|
||||||
@@ -157,6 +153,20 @@ alt: data ${ALT_TARGET}
|
|||||||
${PROG}.alt: ${PROG}.alt.c
|
${PROG}.alt: ${PROG}.alt.c
|
||||||
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
||||||
|
|
||||||
|
${PROG}.sort.c: ${PROG}
|
||||||
|
${SORT} -b ${PROG}.c > $@
|
||||||
|
|
||||||
|
${PROG}.sort: ${PROG}.sort.c
|
||||||
|
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
||||||
|
|
||||||
|
${PROG}.punch.c: ${PROG}
|
||||||
|
${SORT} ${PROG}.c > $@
|
||||||
|
|
||||||
|
${PROG}.punch: ${PROG}.punch.c
|
||||||
|
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# data files
|
# data files
|
||||||
#
|
#
|
||||||
data: ${DATA}
|
data: ${DATA}
|
||||||
|
|||||||
+56
-29
@@ -4,19 +4,37 @@
|
|||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
|
||||||
|
There are two additional programs based on the author's remarks and the original
|
||||||
|
version, provided as alternate code as it might be less portable. See [sorted
|
||||||
|
code](#sorted-code), [punch card code](#punch-card-code) and [alternate
|
||||||
|
code](#alternate-code) below.
|
||||||
|
|
||||||
|
|
||||||
|
### Bugs and (Mis)features:
|
||||||
|
|
||||||
|
The current status of this entry is:
|
||||||
|
|
||||||
|
```
|
||||||
|
STATUS: uses gets() - change to fgets() if possible
|
||||||
|
STATUS: missing files - please provide them
|
||||||
|
```
|
||||||
|
|
||||||
|
For more detailed information see [2001 westley in bugs.md](/bugs.md#2001-westley).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## To use:
|
## To use:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./westley
|
./westley 2>/dev/null
|
||||||
# enter some input, terminate with EOF
|
# enter some input, terminate with EOF
|
||||||
|
|
||||||
echo foo | ./westley
|
echo foo | ./westley 2>/dev/null
|
||||||
|
|
||||||
./westley < westley.c
|
./westley < westley.c 2>/dev/null
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Try:
|
### Try:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -24,40 +42,49 @@ echo foo | ./westley
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Alternate code:
|
## Sorted code:
|
||||||
|
|
||||||
An alternate version of this entry, [westley.alt.c](westley.alt.c), is provided.
|
The author stated that one can sort (ignoring leading blanks i.e. `sort -b`) the
|
||||||
This alternate code might be less portable.
|
code by line and it will always sort the order of the input.
|
||||||
|
|
||||||
To compile this alternate version:
|
This is compiled by default; use `westley.sort` as you would `westley` above.
|
||||||
|
|
||||||
```sh
|
|
||||||
make alt
|
|
||||||
```
|
|
||||||
|
|
||||||
Use `westley.alt` as you would `westley` above.
|
## Punch card code:
|
||||||
|
|
||||||
### Sorted code:
|
|
||||||
|
|
||||||
The author stated that one can sort (with ignoring leading blanks i.e. `sort
|
|
||||||
-b`) the code by line and it will always sort the order of the input.
|
|
||||||
|
|
||||||
Use `westley.sort` as you would `westley` above.
|
|
||||||
|
|
||||||
### Punch card code:
|
|
||||||
|
|
||||||
The author also stated that if you just sort the code you'll get the with
|
The author also stated that if you just sort the code you'll get the with
|
||||||
`sort`) version that just prints out the punch card. The
|
`sort`) version that just prints out the punch card. The
|
||||||
[westley.punch.c](westley.punch.c) code is specifically so that Westley can punch
|
[westley.punch.c](westley.punch.c) code is specifically so that Westley can punch
|
||||||
everyone in the face! :-) This is also compiled by default.
|
everyone in the face! :-) This is also compiled by default.
|
||||||
|
|
||||||
To use, try:
|
|
||||||
|
### Punch card try:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
echo 'Brian Westley does it again!' | ./westley.punch 2>/dev/null
|
echo 'Brian Westley does it again!' | ./westley.punch 2>/dev/null
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Alternate code:
|
||||||
|
|
||||||
|
An alternate version of this entry, [westley.alt.c](westley.alt.c), is provided.
|
||||||
|
This alternate code might be less portable.
|
||||||
|
|
||||||
|
|
||||||
|
### Alternate build:
|
||||||
|
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make alt
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Alternate use:
|
||||||
|
|
||||||
|
Use `westley.alt` as you would `westley` above.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Judges' remarks:
|
## Judges' remarks:
|
||||||
|
|
||||||
Try copying the source to a new file and changing around the
|
Try copying the source to a new file and changing around the
|
||||||
@@ -66,11 +93,11 @@ order of the lines. Does it produce the exact same output?
|
|||||||
By changing the order of the source, figure out in how many different
|
By changing the order of the source, figure out in how many different
|
||||||
ways this program can transform input to output.
|
ways this program can transform input to output.
|
||||||
|
|
||||||
This assortment obfuscated lines takes position-independent code
|
This assortment of obfuscated lines takes [position-independent
|
||||||
to a new level! :-)
|
code](https://en.wikipedia.org/wiki/Position-independent_code) to a new level! :-)
|
||||||
|
|
||||||
We find it amazing that with just 28 lines of code (not counting comments and
|
We find it amazing that with just 28 lines of code (not counting comments and
|
||||||
blank lines) there are `28!` or ``304,888,344,611,713,860,501,504,000,000``
|
blank lines) there are `28!` or `304,888,344,611,713,860,501,504,000,000`
|
||||||
versions of the program, all valid C!
|
versions of the program, all valid C!
|
||||||
|
|
||||||
|
|
||||||
@@ -116,7 +143,7 @@ main(){if (test(0,1)) printf("T"); else printf("F");}
|
|||||||
This program will print out `T` if the `#define` statement
|
This program will print out `T` if the `#define` statement
|
||||||
falls between the declaration of `test()` and its use in
|
falls between the declaration of `test()` and its use in
|
||||||
`main()`, otherwise it will print out `F`. Furthermore,
|
`main()`, otherwise it will print out `F`. Furthermore,
|
||||||
you can use the same call to test() repeatedly in
|
you can use the same call to `test()` repeatedly in
|
||||||
different lines to return different values:
|
different lines to return different values:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
@@ -184,7 +211,7 @@ produce the version that just reverses the line order, and
|
|||||||
the routines in the code are in a sensible order.
|
the routines in the code are in a sensible order.
|
||||||
|
|
||||||
This program should work on EBCDIC computers. It assumes
|
This program should work on EBCDIC computers. It assumes
|
||||||
that the `time_t` ptr param to `time()` will work with an `int`
|
that the `time_t` ptr param to `time(3)` will work with an `int`
|
||||||
ptr, and that "passing through" a `char[][]` array as a simple
|
ptr, and that "passing through" a `char[][]` array as a simple
|
||||||
`char *` is OK. Your compiler MUST understand trigraphs, or it
|
`char *` is OK. Your compiler MUST understand trigraphs, or it
|
||||||
will miss the trigraph backslash before the double quote in
|
will miss the trigraph backslash before the double quote in
|
||||||
@@ -201,9 +228,9 @@ comment), there are technically `28!` different programs, or
|
|||||||
all legal C.
|
all legal C.
|
||||||
|
|
||||||
```
|
```
|
||||||
\* except in Florida voting machines
|
* except in Florida voting machines
|
||||||
|
|
||||||
\*\* all cards must be face down, nine-edge first, of course.
|
** all cards must be face down, nine-edge first, of course.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ printf "1\n4\n5" | ./westley 2>/dev/null
|
|||||||
echo
|
echo
|
||||||
# SC2028 (info): echo may not expand escape sequences. Use printf.
|
# SC2028 (info): echo may not expand escape sequences. Use printf.
|
||||||
# shellcheck disable=SC2028
|
# shellcheck disable=SC2028
|
||||||
echo "printf \"1\n\4\n5\" | ./westley 2>/dev/null"
|
echo "printf \"1\n4\n5\" | ./westley 2>/dev/null"
|
||||||
printf "1\n4\n5" | ./westley 2>/dev/null
|
printf "1\n4\n5" | ./westley 2>/dev/null
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|||||||
@@ -1940,6 +1940,23 @@ details and a workaround.
|
|||||||
There's also no way to escape meta characters.
|
There's also no way to escape meta characters.
|
||||||
|
|
||||||
|
|
||||||
|
## 2001 westley
|
||||||
|
|
||||||
|
|
||||||
|
### STATUS: uses gets() - change to fgets() if possible
|
||||||
|
### Source code: [2001/westley/westley.c](2001/westley/westley.c)
|
||||||
|
### Information: [2001/westley/README.md](2001/westley/README.md)
|
||||||
|
|
||||||
|
This function uses `gets(3)` but it would be ideal if it used `fgets(3)`. This
|
||||||
|
one is rather complicated and will be looked at later but you are welcome to try
|
||||||
|
and fix this if you wish.
|
||||||
|
|
||||||
|
### STATUS: missing files - please provide them
|
||||||
|
|
||||||
|
The author referred to a file `card.gif` but this file is missing. Do you have
|
||||||
|
it? Please provide it!
|
||||||
|
|
||||||
|
|
||||||
# 2002
|
# 2002
|
||||||
|
|
||||||
There was no IOCCC in 2002.
|
There was no IOCCC in 2002.
|
||||||
|
|||||||
Reference in new issue
Block a user