Add try.sh and try.alt.sh to 1996/westley
These scripts simplify running the three other scripts (that the author provided, renamed to have the extension '.sh') to show the three styles of clocks with both the fixed (for modern systems) version and the original version (the alt code). The README.md file has been format and typo checked. This should complete 1996/westley.
This commit is contained in:
1 parent
aee071cdf8
commit
c2b720f874
8 files changed
+65
-32
No files matched your search
@@ -39,7 +39,8 @@ include ../../var.mk
|
||||
# Common C compiler warnings to silence
|
||||
#
|
||||
CSILENCE= -Wno-char-subscripts -Wno-error -Wno-implicit-function-declaration \
|
||||
-Wno-int-to-pointer-cast -Wno-empty-body -Wno-deprecated-non-prototype
|
||||
-Wno-int-to-pointer-cast -Wno-empty-body -Wno-deprecated-non-prototype\
|
||||
-Wno-implicit-int
|
||||
|
||||
# Common C compiler warning flags
|
||||
#
|
||||
@@ -109,7 +110,7 @@ ENTRY= westley
|
||||
PROG= ${ENTRY}
|
||||
#
|
||||
OBJ= ${PROG}.o
|
||||
DATA= clock1 clock2 clock3
|
||||
DATA= clock1.sh clock2.sh clock3.sh
|
||||
TARGET= ${PROG}
|
||||
#
|
||||
ALT_OBJ= westley.alt.o
|
||||
|
||||
+27
-30
@@ -4,51 +4,46 @@
|
||||
make all
|
||||
```
|
||||
|
||||
There is another version which is the original entry. See [alternate
|
||||
version](#alternate-code) for details as to how to use and why it was made the
|
||||
alt version.
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
sh ./clock1
|
||||
./clock1.sh
|
||||
./clock2.sh
|
||||
./clock3.sh
|
||||
```
|
||||
|
||||
|
||||
NOTE: the original version had a display problem in modern systems which
|
||||
somewhat affected the usability of the program. See the Alternate code section
|
||||
for details on the original version.
|
||||
|
||||
|
||||
### Try:
|
||||
|
||||
```sh
|
||||
sh ./clock2
|
||||
```
|
||||
|
||||
|
||||
And for a good time, try:
|
||||
|
||||
```sh
|
||||
sh ./clock3
|
||||
./try.sh
|
||||
```
|
||||
|
||||
|
||||
## Alternate code:
|
||||
|
||||
An alternate version of this entry, [westley.alt.c](westley.alt.c), is provided.
|
||||
This version is the original code and does not contain the above mentioned
|
||||
fixes.
|
||||
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:
|
||||
|
||||
To compile this alternate version:
|
||||
|
||||
```sh
|
||||
make alt
|
||||
```
|
||||
|
||||
To use it with the scripts try:
|
||||
|
||||
### Alternate try:
|
||||
|
||||
```sh
|
||||
WESTLEY=./westley.alt ./clock1
|
||||
WESTLEY=./westley.alt ./clock2
|
||||
WESTLEY=./westley.alt ./clock3
|
||||
./try.alt.sh
|
||||
```
|
||||
|
||||
|
||||
@@ -66,7 +61,8 @@ 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`, `clock2`, and `clock3`)
|
||||
clock. (they are [clock1.sh](clock1.sh), [clock2.sh](clock2.sh), and
|
||||
[clock3.sh](clock3.sh))
|
||||
|
||||
The program makes the following (possibly non-portable) assumptions:
|
||||
|
||||
@@ -74,8 +70,8 @@ The program makes the following (possibly non-portable) assumptions:
|
||||
|
||||
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.
|
||||
3. The first three elements of the `struct *` returned by `localtime(3)` are
|
||||
seconds, minutes, hours, and all are `int`s.
|
||||
|
||||
4. My sample scripts assume ASCII, though this is not inherent in the code, just
|
||||
my sample scripts.
|
||||
@@ -83,6 +79,7 @@ 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:
|
||||
|
||||
```sh
|
||||
@@ -94,14 +91,14 @@ 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()
|
||||
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()` by casting it
|
||||
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]`.
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
make everything 1>/dev/null || exit 1
|
||||
|
||||
echo "Showing alt grandfather clock:" 1>&2
|
||||
WESTLEY=./westley.alt ./clock1.sh
|
||||
read -r -n 1 -p "Press any key to continue: " 1>&2
|
||||
|
||||
echo "Showing alt mantle clock that runs backwards:" 1>&2
|
||||
WESTLEY=./westley.alt ./clock2.sh
|
||||
read -r -n 1 -p "Press any key to continue: " 1>&2
|
||||
|
||||
echo "Showing alt linear style clock:" 1>&2
|
||||
WESTLEY=./westley.alt ./clock3.sh
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
make everything 1>/dev/null || exit 1
|
||||
|
||||
echo "Showing grandfather clock:" 1>&2
|
||||
WESTLEY=./westley ./clock1.sh
|
||||
read -r -n 1 -p "Press any key to continue: " 1>&2
|
||||
|
||||
echo "Showing mantle clock that runs backwards:" 1>&2
|
||||
WESTLEY=./westley ./clock2.sh
|
||||
read -r -n 1 -p "Press any key to continue: " 1>&2
|
||||
|
||||
echo "Showing linear style clock:" 1>&2
|
||||
WESTLEY=./westley ./clock3.sh
|
||||
Reference in new issue
Block a user