Introduce GOPHER2HTML_TYPE envirnoment variable to parse text entries - gopher2html - AWK script that converts a Gopher response to HTML
 (HTM) hg clone https://bitbucket.org/iamleot/gopher2html
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) changeset 7c9f4b178fb0b53d982afd6f0adcf86501fa6c3e
 (DIR) parent de173f5d913b0f22ed83b59b9c93bf6941c2cf83
 (HTM) Author: Leonardo Taccari <iamleot@gmail.com>
       Date:   Mon, 15 Jan 2018 21:31:42 
       
       Introduce GOPHER2HTML_TYPE envirnoment variable to parse text entries
       
       Previously text entries were euristically parsed when the number of fields was
       not 4... This was very fragile.
       Instead make the cgi-bin responsable to set GOPHER2HTML_TYPE variable to `file'
       when handling text entries (i.e. when the gopher URL matches `*/0/*' pattern).
       
       Refactor printing of header and footer in separate functions and check that
       GOPHER2HTML_TYPE is not `file' in order to print them.
       
       Diffstat:
        gopher2html.awk |  36 +++++++++++++++++++++++++-----------
        1 files changed, 25 insertions(+), 11 deletions(-)
       ---
       diff -r de173f5d913b -r 7c9f4b178fb0 gopher2html.awk
       --- a/gopher2html.awk   Mon Jan 15 09:11:02 2018 +0100
       +++ b/gopher2html.awk   Mon Jan 15 21:31:42 2018 +0100
       @@ -16,6 +16,26 @@
               return html
        }
        
       +function header()
       +{
       +       if (ENVIRON["GOPHER2HTML_TYPE"] != "file") {
       +               # Print the header
       +               print "<html>"
       +               print "<body>"
       +               print "<pre>"
       +       }
       +}
       +
       +function footer()
       +{
       +       if (ENVIRON["GOPHER2HTML_TYPE"] != "file") {
       +               # Print the footer
       +               print "</pre>"
       +               print "</body>"
       +               print "</html>"
       +       }
       +}
       +
        BEGIN {
               FS = "\t"
               # XXX: Strictly speaking RS should be `\r\n'. However, in the wild it
       @@ -32,10 +52,7 @@
               TYPE["picture"] = "p"
               TYPE["sound"] = "s"
        
       -       # Print the header
       -       print "<html>"
       -       print "<body>"
       -       print "<pre>"
       +       header()
        }
        
        {
       @@ -54,9 +71,9 @@
               next
        }
        
       -# Text entry (euristically!)
       -NF != 4 {
       -       printf("%s\n", encode($0))
       +# Text entry
       +ENVIRON["GOPHER2HTML_TYPE"] == "file" {
       +       printf("%s\n", $0)
               next
        }
        
       @@ -90,8 +107,5 @@
        }
        
        END {
       -       # Print the footer
       -       print "</pre>"
       -       print "</body>"
       -       print "</html>"
       +       footer()
        }