Check-in by ben on 2025-04-11 21:24:26

 Make sure to create output directories before using them. Link
 to source code on chiselapp.com instead of a local .zip file.
 Bump to version 4

 INSERTED    DELETED
       74         33 periodic.awk
       74         33 TOTAL over 1 changed file

Index: periodic.awk
==================================================================
--- periodic.awk
+++ periodic.awk
@@ -1,6 +1,6 @@
-# periodic.awk version 3 by Ben Collver
+# periodic.awk version 4 by Ben Collver
#
# Generate static gopher content for the periodic table of elements.
#
# Edit gopher_dir, gopher_host, and gopher_port in function main()
#
@@ -48,11 +48,11 @@
    close(cmd)
    FS = OLDFS
    return
}

-function dir(str,    retval) {
+function format_dir(str,    retval) {
    retval = tolower(str)
    gsub(/ /, "-", retval)
    return retval
}

@@ -143,14 +143,22 @@
    table["cols"] = cols
    table["rows"] = rows
    return
}

-function print_element_gph(element,    cmd, count, f, i, key, label, \
-    mass, name, path, source_list, source, str, symbol)
+function mkdir(dir) {
+    system("mkdir -p \"" dir "\"")
+    return
+}
+
+function print_element_gph(element,    cmd, count, dir, f, i, key, \
+    label, mass, name, path, source_list, source, str, symbol)
{
-    f = outdir "/element/" element "/index.gph"
+    dir = outdir "/element/" element
+    mkdir(dir)
+
+    f = dir "/index.gph"
    key = element "_Atomic Mass"
    mass = elements[key]
    key = element "_Name"
    name = elements[key]
    key = element "_Symbol"
@@ -258,11 +266,11 @@
    print format_field(f, element, "Boiling Point") >>f
    print format_field(f, element, "Density") >>f

    str = format_field(f, element, "Family")
    key = element "_Family"
-    path = gopher_dir "/family/" dir(elements[key]) "/"
+    path = gopher_dir "/family/" format_dir(elements[key]) "/"
    printf "[1|%s|%s|%s|%s]\n", str, path, gopher_host, gopher_port >>f

    print format_field(f, element, "Year Discovered") >>f
    print format_field(f, element, "Number of Neutrons") >>f
    print format_field(f, element, "Number of Protons") >>f
@@ -375,20 +383,25 @@
        print_element_txt(i)
    }
    return
}

-function print_families(    family_id, fdir, i, key, len, name, outfile) {
-    outfile = outdir "/family/index.gph"
+function print_families(    dir, family_id, fdir, i, key, len, name, \
+    outfile)
+{
+    dir = outdir "/family"
+    mkdir(dir)
+
+    outfile = dir "/index.gph"
    printf "# Families\n\n" >outfile
    len = families["length"]
    for (i = 1; i <= len; i++) {
        key = i "_Family"
        family_id = families[key]
        key = i "_Name"
        name = families[key]
-        fdir = dir(family_id)
+        fdir = format_dir(family_id)
        printf "[1|%s|%s/family/%s/|%s|%s]\n", name, gopher_dir, fdir, \
            gopher_host, gopher_port >>outfile
        select_clear()
        select_family(family_id)
        print_family_gph(i, family_id, name, fdir)
@@ -396,17 +409,20 @@
    }
    close(outfile)
    return
}

-function print_family_gph(family, family_id, name, fdir,    descr, i, \
-    f, key, label, len, path, symbol)
+function print_family_gph(family, family_id, name, fdir,    descr, \
+    dir, i, f, key, label, len, path, symbol)
{
    key = family "_Description"
    descr = families[key]

-    f = outdir "/family/" fdir "/index.gph"
+    dir = outdir "/family/" fdir
+    mkdir(dir)
+
+    f = dir "/index.gph"

    label = sprintf("Family: %s", name)
    path = sprintf("%s/family/%s/index.txt", gopher_dir, fdir)
    printf "[0|%s|%s|%s|%s]\n\n", label, path, gopher_host, gopher_port >f

@@ -469,12 +485,15 @@

    close(f)
    return
}

-function print_list_atomic(    f, i, key, label, name, path, symbol) {
-    f = outdir "/list/atomic/index.gph"
+function print_list_atomic(    dir, f, i, key, label, name, path, symbol) {
+    dir = outdir "/list/atomic"
+    mkdir(dir)
+
+    f = dir "/index.gph"
    printf "# List Elements By Atomic Number\n\n" >f
    len = elements["length"]
    for (i = 1; i <= len; i++) {
        key = i "_Name"
        name = elements[key]
@@ -498,16 +517,20 @@

    close(f)
    return
}

-function print_list_name(    element, f, i, key, label, len, map, \
-    name, order, path, symbol)
+function print_list_name(    dir, element, f, i, key, label, len, \
+    map, name, order, path, symbol)
{
    delete map
    delete order
-    f = outdir "/list/name/index.gph"
+
+    dir = outdir "/list/name"
+    mkdir(dir)
+
+    f = dir "/index.gph"
    printf "# List Elements By Name\n\n" >f
    len = elements["length"]
    for (i = 1; i <= len; i++) {
        key = i "_Name"
        name = elements[key]
@@ -537,16 +560,20 @@
    printf "[1|%s|%s|%s|%s]\n", label, path, gopher_host, gopher_port >>f

    return
}

-function print_list_symbol(    element, f, i, key, label, len, map, \
-    name, order, path, symbol)
+function print_list_symbol(    dir, element, f, i, key, label, len, \
+    map, name, order, path, symbol)
{
    delete map
    delete order
-    f = outdir "/list/symbol/index.gph"
+
+    dir = outdir "/list/symbol"
+    mkdir(dir)
+
+    f = dir "/index.gph"
    printf "# List Elements By Symbol\n\n" >f
    len = elements["length"]
    for (i = 1; i <= len; i++) {
        key = i "_Symbol"
        symbol = elements[key]
@@ -583,12 +610,15 @@
    print_list_name()
    print_list_symbol()
    return
}

-function print_shells(    i, key, len, name, outfile, shell_id) {
-    outfile = outdir "/shell/index.gph"
+function print_shells(    dir, i, key, len, name, outfile, shell_id) {
+    dir = outdir "/shell"
+    mkdir(dir)
+
+    outfile = dir "/index.gph"
    printf "# Shells\n\n" >outfile
    len = shells["length"]
    for (i = 1; i <= len; i++) {
        key = i "_Shell"
        shell_id = shells[key]
@@ -603,17 +633,20 @@
    }
    close(outfile)
    return
}

-function print_shell_gph(shell, shell_id, name,    descr, i, \
-    f, key, label, len, path, symbol)
+function print_shell_gph(shell, shell_id, name,    descr, dir, i, f, \
+    key, label, len, path, symbol)
{
    key = shell "_Description"
    descr = shells[key]

-    f = outdir "/shell/" shell_id "/index.gph"
+    dir = outdir "/shell/" shell_id
+    mkdir(dir)
+
+    f = dir "/index.gph"

    label = sprintf("Shell: %s", name)
    path = sprintf("%s/shell/%s/index.txt", gopher_dir, shell_id)
    printf "[0|%s|%s|%s|%s]\n\n", label, path, gopher_host, gopher_port >f

@@ -676,12 +709,15 @@

    close(f)
    return
}

-function print_sources(    i, key, len, name, outfile, source_id) {
-    outfile = outdir "/source/index.gph"
+function print_sources(    dir, i, key, len, name, outfile, source_id) {
+    dir = outdir "/source"
+    mkdir(dir)
+
+    outfile = dir "/index.gph"
    printf "# Sources\n\n" >outfile
    len = sources["length"]
    for (i = 1; i <= len; i++) {
        key = i "_Source"
        source_id = sources[key]
@@ -696,14 +732,17 @@
    }
    close(outfile)
    return
}

-function print_source_gph(source, source_id, name,    i, \
-    f, key, label, len, path, symbol)
+function print_source_gph(source, source_id, name,    dir, i, f, key, \
+    label, len, path, symbol)
{
-    f = outdir "/source/" source_id "/index.gph"
+    dir = outdir "/source/" source_id
+    mkdir(dir)
+
+    f = dir "/index.gph"

    label = sprintf("Source: %s", name)
    path = sprintf("%s/source/%s/index.txt", gopher_dir, source_id)
    printf "[0|%s|%s|%s|%s]\n\n", label, path, gopher_host, gopher_port >f

@@ -794,20 +833,22 @@
        printf "\n" >>f
    }
    return
}

-function print_top(    f) {
+function print_top(    f, uri) {
+    mkdir(outdir)
    f = outdir "/index.gph"
+
+    uri = "https://chiselapp.com/user/bencollver/repository/periodic/"
    select_clear()
    printf "             Periodic Table Of The Elements\n\n" >f
    print_table(f)
    printf "\n" >>f
    printf "[1|List All|%s/list/atomic/|%s|%s]\n", gopher_dir,
        gopher_host, gopher_port >>f
-    printf "[9|Code (.zip)|%s/periodic.zip|%s|%s]\n", gopher_dir,
-        gopher_host, gopher_port >>f
+    printf "[h|Source Code|URL:%s|tilde.pink|70]\n", uri >>f
    close(f)
    return
}

function print_wiki_item(f, label, id) {