Files
ioccc/1996/westley
Landon Curt Noll f29b37e49a improve HTML menus, add social.html, prep for IOCCC28 winners
Prepare for the winners of **IOCCC28**.

> However these are not the 2024 droids you are looking for.  :-)

The HTML menu (both JavaScript and non-JavaScript) has been updated.

The `Status -> Rules and guidelines' have been replaced with two
separate menus `Status -> IOCCC rules` and `Status -> IOCCC guidelines`.

Added a new top level `social.html` page: built from a new `social.md`.

Sorted rules for building specific web pages in the top level `Makefile`.
Added `make social` to make the `social.html` page from `social.md`.

The `bin/gen-top-html.sh` now is able to process a argument of **social**
to process the new top level `social.html` page.

Changed `bin/gen-top-html.sh` VERSION from "2.0.0 2025-03-13"
to "2.0.1 2025-07-25".

Below `About -> Home page` a new `About -> IOCCC social media` menu item
as added.

Because the menu change touched every HTML file, we changed the general
copyright date range for HTML files from "1984-2024" to "1984-2025"
due to the extensive changes made for **IOCCC28**.

Those markdown files that were modified in 2025 had their copyright date
range also changed from "1984-2024" to "1984-2025".

Rebuilt tarballs and sitemap due to the extensive HTML rebuilding.

Ran `make update` to perform the above.
2025-07-26 13:06:29 -07:00
..
2024-07-25 17:22:09 -07:00
2023-03-20 08:42:46 -07:00
2023-07-06 21:49:38 -07:00

To build:

    make all
    ```

There is another version which is the original entry. See [Alternate
code](#alternate-code) for details as to how to use and why it was made the
alt version.


## To use:

``` <!---sh-->
    ./clock1.sh
    ./clock2.sh
    ./clock3.sh

Try:

    ./try.sh

Alternate code:

The original version had a display problem in modern systems which somewhat affected the usability of the program. This alternate code, the original, is provided, to show the differences.

Alternate build:

    make alt

Alternate try:

    ./try.alt.sh

Judges' remarks:

Time and time again, Brian Westley seems to come up with a winning entry! We are amazed at how much is being done with only one relatively short line. We think you will as well if you take the time to understand it.

Author's remarks:

This 1-line program allows various analog ASCII clocks to print out the time; the ASCII clock is built from the command line arguments, so many different types of clocks can be generated. Three different scripts are supplied to print out a grandfather clock, a mantle clock that runs backwards, and a linear-style clock. (they are clock1.sh, clock2.sh, and clock3.sh.

The program makes the following (possibly non-portable) assumptions:

  1. Command line strings can be written to.

  2. argv[0] can be written to as if it were a long *.

  3. The first three elements of the struct * returned by localtime(3) are seconds, minutes, hours, and all are ints.

  4. My sample scripts assume ASCII, though this is not inherent in the code, just my sample scripts.

These assumptions are pretty reasonable. 2) can be eliminated but makes the code larger.

The code is simple; the arguments passed are:

    ./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 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 statement of the for() loop takes the hour or minute field of the struct returned by localtime(3) 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].

This value is in turn indexed into the hour_map or minute_map parameter to determine where the 'hand' symbol should be written into the clock_image.

Note that the hands move in a quantum fashion; 3:59 looks deceptively like 2:59, since the hour hand will be at the 3 position. It won't move until both hands click over at 4:00.