diff --git a/1996/westley/README.md b/1996/westley/README.md index 7151738c3..2008caeb6 100644 --- a/1996/westley/README.md +++ b/1996/westley/README.md @@ -1,53 +1,55 @@ # Best One Liner - Brian Westley (Merlyn LeRoy on Usenet) - 1906 James Ave. - St. Paul, MN 55105 - USA - - http://www.westley.org +Brian Westley (Merlyn LeRoy on Usenet) +1906 James Ave. +St. Paul, MN 55105 +USA + ## To build: - make all +```sh +make all +``` [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed a segfault in this entry as well as it displaying environmental variables. Although the -scripts showed correct output these also segfaulted but with the fix they no -longer do. Now if argc < 5 (argv[4] is referenced) it will not do anything and -it will not segfault either (this was caused by the body of the for() loop which -is now empty (it doesn't appear to be needed at all). Note that this does make -some of the author's explanations / portability notes no longer valid but we -have kept them there for the interested. Thank you Cody for your assistance! +scripts showed correct output, it somewhat lessened the usability because they +segfaulted. With the fix they no longer do. If argc < 5 (argv[4] is referenced) +it will not do anything and it will not segfault either - this was caused by the +body of the for() loop which is now empty (it doesn't appear to be needed at +all). Note that you should check the [westley.alt.c](westley.alt.c) file when +reading the author's comments. To see how to use the original see below. Thank +you Cody for your assistance! ## To run: - sh ./clock1 +```sh +sh ./clock1 +``` ## Try: - sh ./clock2 - -Also try: - - - sh ./clock2 +```sh +sh ./clock2 +``` And for a good time, try: - - sh ./clock3 +```sh +sh ./clock3 +``` ### Alternate code: -An alternate version of this entry, `westley.alt.c`, is provided. -The original is in [westley.alt.c](westley.alt.c) does not contain -the above mentioned fixes. +An alternate version of this entry, [westley.alt.c](westley.alt.c), is provided. +This version is the original code [westley.alt.c](westley.alt.c) and does not +contain the above mentioned fixes. To compile this alternate version: @@ -55,6 +57,15 @@ To compile this alternate version: make alt ``` +To use it with the scripts try: + +```sh +WESTLEY=./westley.alt ./clock1 +WESTLEY=./westley.alt ./clock2 +WESTLEY=./westley.alt ./clock3 +``` + + ## Judges' remarks: Time and time again, Brian Westley seems to come up with a winner! @@ -74,37 +85,39 @@ clock that runs backwards, and a linear-style clock. The program makes the following (possibly non-portable) assumptions: -1. Command line strings can be written to +1. Command line strings can be written to. -2. `argv[0]` can be written to as if it were a `long *` +2. `argv[0]` can be written to as if it were a `long *`. 3. The first three elements of the struct * returned by localtime() are seconds, -minutes, hours, and all are ints +minutes, hours, and all are ints. 4. My sample scripts assume ASCII, though this is not inherent in the code, just -my sample scripts +my sample scripts. -These assumptions are pretty reasonable. 2) can be eliminated -by makes the code larger. +These assumptions are pretty reasonable. 2) can be eliminated but makes the code +larger. The code is simple; the arguments passed are: - prog minute_map hour_map hand_symbol clock_image +```sh +./westley minute_map hour_map hand_symbol clock_image +``` The program merely takes the minute (0-59) and the hour (0-23) values, looks up the offsets in `minute_map` and `hour_map` and writes the `hand_symbol` for each into the `clock_image` string. This string is then printed. -The for() loop starts by calling time() with argv[0], so +The for() loop starts by calling `time()` with `argv[0]`, so the time value (a long) is written into the program name. -The for() control value is argc, which starts at 5, but -the /=2 statement is executed before the test, so the for() -loop is executed twice, with h=2, then h=1 (for hour & minute). +The for() control value is `argc`, which starts at `5`, but +the `/=2` statement is executed before the test, so the for() +loop is executed twice, with `h=2`, then `h=1` (for hour & minute). The statement of the for() loop takes the hour or minute -field of the struct returned by localtime() by casting it -to an int* and dereferencing element [h]. It is slightly +field of the struct returned by `localtime()` by casting it +to an `int *` and dereferencing element `[h]`. It is slightly smaller to use the trick `h[(int*)localtime(*m)]` instead of `((int*)localtime(*m))[h]`. diff --git a/1996/westley/clock1 b/1996/westley/clock1 index c79d1fbb4..d05dd1611 100755 --- a/1996/westley/clock1 +++ b/1996/westley/clock1 @@ -1,5 +1,6 @@ #!/usr/bin/env sh -./westley \ +${WESTLEY:=./westley} +${WESTLEY} \ "%%%&&&'''666EEESSSaaannn{{{zzzyyyxxxwwwhhhYYYKKK===000###\$\$\$" \ "34CQ_lkj[M?234CQ_lkj[M?2" \ " .*" \ diff --git a/1996/westley/clock2 b/1996/westley/clock2 index b2d779f9e..dc4bf21a9 100755 --- a/1996/westley/clock2 +++ b/1996/westley/clock2 @@ -1,5 +1,6 @@ #!/usr/bin/env sh -./westley \ +${WESTLEY:=./westley} +${WESTLEY} \ "%%%\$\$\$###000===KKKYYYhhhwwwxxxyyyzzz{{{nnnaaaSSSEEE666'''&&&" \ "32?M[jkl_QC432?M[jkl_QC4" \ " xX" \ diff --git a/1996/westley/clock3 b/1996/westley/clock3 index 5c4119ebd..4c8e544dc 100755 --- a/1996/westley/clock3 +++ b/1996/westley/clock3 @@ -1,5 +1,6 @@ #!/usr/bin/env sh -./westley \ +${WESTLEY:=./westley} +${WESTLEY} \ "123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijkl" \ "/\$%&'()*+,-./\$%&'()*+,-." \ " ||" \