Check-in by ben on 2025-04-11 21:04:36
Fix navigation to avoid moving the cursor to blank spots in the
periodic table. Add Wikipedia link when displaying an individual
element. Bump version to 2.
INSERTED DELETED
48 22 periodic.awk
48 22 TOTAL over 1 changed file
Index: periodic.awk
==================================================================
--- periodic.awk
+++ periodic.awk
@@ -1,6 +1,6 @@
-# periodic.awk version 1 by Ben Collver
+# periodic.awk version 2 by Ben Collver
#
# Generate static gopher content for the periodic table of elements.
#
# Edit gopher_dir, gopher_host, and gopher_port in function main()
#
@@ -165,47 +165,67 @@
# navigation
str = "Left"
if (table_col[element] > 1) {
- key = table_row[element] "_" (table_col[element] - 1)
- path = gopher_dir "/element/" table[key] "/"
- printf "[1|%s|%s|%s|%s]\n", str, path, gopher_host, gopher_port >>f
- } else {
- printf "%s\n", str >>f
+ for (i = table_col[element] - 1; i >= 1; i--) {
+ key = table_row[element] "_" i
+ if (length(table[key]) > 0) {
+ path = gopher_dir "/element/" table[key] "/"
+ str = sprintf("[1|Left|%s|%s|%s]", path, \
+ gopher_host, gopher_port)
+ break
+ }
+ }
}
+ print str >>f
str = "Up"
if (table_row[element] > 1) {
- key = (table_row[element] - 1) "_" table_col[element]
- path = gopher_dir "/element/" table[key] "/"
- printf "[1|%s|%s|%s|%s]\n", str, path, gopher_host, gopher_port >>f
- } else {
- printf "%s\n", str >>f
+ for (i = table_row[element] - 1; i >= 1; i--) {
+ key = i "_" table_col[element]
+ if (length(table[key]) > 0) {
+ path = gopher_dir "/element/" table[key] "/"
+ str = sprintf("[1|Up|%s|%s|%s]", path, gopher_host, \
+ gopher_port)
+ break
+ }
+ }
}
+ print str >>f
str = "Down"
if (table_row[element] < table["rows"]) {
- key = (table_row[element] + 1) "_" table_col[element]
- path = gopher_dir "/element/" table[key] "/"
- printf "[1|%s|%s|%s|%s]\n", str, path, gopher_host, gopher_port >>f
- } else {
- printf "%s\n", str >>f
+ for (i = table_row[element] + 1; i <= table["rows"]; i++) {
+ key = i "_" table_col[element]
+ if (length(table[key]) > 0) {
+ path = gopher_dir "/element/" table[key] "/"
+ str = sprintf("[1|Down|%s|%s|%s]", path, gopher_host, \
+ gopher_port)
+ break
+ }
+ }
}
+ print str >>f
str = "Right"
if (table_col[element] < table["cols"]) {
- key = table_row[element] "_" (table_col[element] + 1)
- path = gopher_dir "/element/" table[key] "/"
- printf "[1|%s|%s|%s|%s]\n", str, path, gopher_host, gopher_port >>f
- } else {
- printf "%s\n", str >>f
+ for (i = table_col[element] + 1; i <= table["cols"]; i++) {
+ key = table_row[element] "_" i
+ if (length(table[key]) > 0) {
+ path = gopher_dir "/element/" table[key] "/"
+ str = sprintf("[1|Right|%s|%s|%s]", path, \
+ gopher_host, gopher_port)
+ break
+ }
+ }
}
+ print str >>f
str = "List All"
path = gopher_dir "/list/atomic/"
- printf "[1|%s|%s|%s|%s]\n", str, path, gopher_host, gopher_port >>f
+ printf "[1|%s|%s|%s|%s]\n\n", str, path, gopher_host, gopher_port >>f
# element detail
cmd = "figlet " symbol
printf "+--------------------+\n" >>f
@@ -223,10 +243,12 @@
str = center(20, name)
printf "|%s|\n", str >>f
str = center(20, mass)
printf "|%s|\n", str >>f
printf "+--------------------+\n\n" >>f
+ str = sprintf("%-23s %s", "Wiki Article:", name)
+ print_wiki_item(f, str, name)
print format_field(f, element, "Electron Configuration") >>f
print format_field(f, element, "Electronegativity") >>f
print format_field(f, element, "Atomic Radius") >>f
print format_field(f, element, "Ionization Energy") >>f
print format_field(f, element, "Electron Affinity") >>f
@@ -825,10 +847,14 @@
printf "[9|Code (.zip)|%s/periodic.zip|%s|%s]\n", gopher_dir,
gopher_host, gopher_port >>f
close(f)
return
}
+
+function print_wiki_item(f, label, id) {
+ printf "[0|%s|/%s|gopherpedia.com|70]\n", label, id >>f
+}
function print_wrap(str, wraplen, outfile, after, before, buf, chunk) {
buf = str
while (length(buf) > wraplen) {
chunk = substr(buf, 0, wraplen)