Help: getVersion(): use 'uname -s' (-o is not a valid option on OS X)

####################################################################
# Help.awk                                                         #
####################################################################

# Return version as a string.
function getVersion(    build, gitHead, platform) {
    initAudioPlayer()
    initPager()
    platform = detectProgram("uname", "-s", 1)
    if (ENVIRON["TRANS_BUILD"])
        build = "-" ENVIRON["TRANS_BUILD"]
    else {
        gitHead = getGitHead()
        build = gitHead ? "-git:" gitHead : ""
    }

    return ansi("bold", sprintf("%-22s%s%s\n\n", Name, Version, build)) \
        sprintf("%-22s%s\n", "platform", platform)                      \
        sprintf("%-22s%s\n", "gawk (GNU Awk)", PROCINFO["version"])     \
        sprintf("%s\n", FriBidi ? FriBidi :
                "fribidi (GNU FriBidi) [NOT INSTALLED]")                \
        sprintf("%-22s%s\n", "audio player", AudioPlayer ? AudioPlayer :
                "[NOT INSTALLED]")                                      \
        sprintf("%-22s%s\n", "terminal pager", Pager ? Pager :
                "[NOT INSTALLED]")                                      \
        sprintf("%-22s%s\n", "terminal type", ENVIRON["TERM"])          \
        sprintf("%-22s%s (%s)\n", "user locale", UserLocale, getName(UserLang)) \
        sprintf("%-22s%s\n", "home language", Option["hl"])             \
        sprintf("%-22s%s\n", "source language", Option["sl"])           \
        sprintf("%-22s%s\n", "target language", join(Option["tl"], "+")) \
        sprintf("%-22s%s\n", "theme", Option["theme"])                  \
        sprintf("%-22s%s\n", "init file", InitScript ? InitScript : "[NONE]") \
        sprintf("\n%-22s%s", "Report bugs to:", "https://github.com/soimort/translate-shell/issues")
}

# Return help message as a string.
function getHelp() {
    return "Usage:  " ansi("bold", Command)                             \
        " [" ansi("underline", "OPTIONS") "]"                           \
        " [" ansi("underline", "SOURCE") "]"                            \
        ":[" ansi("underline", "TARGETS") "]"                           \
        " [" ansi("underline", "TEXT") "]..." RS                        \
        RS "Information options:" RS                                    \
        ins(1, ansi("bold", "-V") ", " ansi("bold", "-version")) RS     \
        ins(2, "Print version and exit.") RS                            \
        ins(1, ansi("bold", "-H") ", " ansi("bold", "-help")) RS        \
        ins(2, "Print help message and exit.") RS                       \
        ins(1, ansi("bold", "-M") ", " ansi("bold", "-man")) RS         \
        ins(2, "Show man page and exit.") RS                            \
        ins(1, ansi("bold", "-T") ", " ansi("bold", "-reference")) RS   \
        ins(2, "Print reference table of languages and exit.") RS       \
        ins(1, ansi("bold", "-R") ", " ansi("bold", "-reference-english")) RS \
        ins(2, "Print reference table of languages (in English names) and exit.") RS \
        ins(1, ansi("bold", "-L ") ansi("underline", "CODES")           \
            ", " ansi("bold", "-list ") ansi("underline", "CODES")) RS  \
        ins(2, "Print details of languages and exit.") RS               \
        ins(1, ansi("bold", "-U") ", " ansi("bold", "-upgrade")) RS     \
        ins(2, "Check for upgrade of this program.") RS                 \
        RS "Display options:" RS                                        \
        ins(1, ansi("bold", "-verbose")) RS                             \
        ins(2, "Verbose mode. (default)") RS                            \
        ins(1, ansi("bold", "-b") ", " ansi("bold", "-brief")) RS       \
        ins(2, "Brief mode.") RS                                        \
        ins(1, ansi("bold", "-d") ", " ansi("bold", "-dictionary")) RS  \
        ins(2, "Dictionary mode.") RS                                   \
        ins(1, ansi("bold", "-show-original ") ansi("underline", "Y/n")) RS \
        ins(2, "Show original text or not.") RS                         \
        ins(1, ansi("bold", "-show-original-phonetics ") ansi("underline", "Y/n")) RS \
        ins(2, "Show phonetic notation of original text or not.") RS    \
        ins(1, ansi("bold", "-show-translation ") ansi("underline", "Y/n")) RS \
        ins(2, "Show translation or not.") RS                           \
        ins(1, ansi("bold", "-show-translation-phonetics ") ansi("underline", "Y/n")) RS \
        ins(2, "Show phonetic notation of translation or not.") RS      \
        ins(1, ansi("bold", "-show-prompt-message ") ansi("underline", "Y/n")) RS \
        ins(2, "Show prompt message or not.") RS                        \
        ins(1, ansi("bold", "-show-languages ") ansi("underline", "Y/n")) RS \
        ins(2, "Show source and target languages or not.") RS           \
        ins(1, ansi("bold", "-show-original-dictionary ") ansi("underline", "y/N")) RS \
        ins(2, "Show dictionary entry of original text or not.") RS     \
        ins(1, ansi("bold", "-show-dictionary ") ansi("underline", "Y/n")) RS \
        ins(2, "Show dictionary entry of translation or not.") RS       \
        ins(1, ansi("bold", "-show-alternatives ") ansi("underline", "Y/n")) RS \
        ins(2, "Show alternative translations or not.") RS              \
        ins(1, ansi("bold", "-w ") ansi("underline", "NUM")             \
            ", " ansi("bold", "-width ") ansi("underline", "NUM")) RS   \
        ins(2, "Specify the screen width for padding.") RS              \
        ins(1, ansi("bold", "-indent ") ansi("underline", "NUM")) RS    \
        ins(2, "Specify the size of indent (number of spaces).") RS     \
        ins(1, ansi("bold", "-theme ") ansi("underline", "FILENAME")) RS \
        ins(2, "Specify the theme to use.") RS                          \
        ins(1, ansi("bold", "-no-theme")) RS                            \
        ins(2, "Do not use any other theme than default.") RS           \
        ins(1, ansi("bold", "-no-ansi")) RS                             \
        ins(2, "Do not use ANSI escape codes.") RS                      \
        RS "Audio options:" RS                                          \
        ins(1, ansi("bold", "-p, -play")) RS                            \
        ins(2, "Listen to the translation.") RS                         \
        ins(1, ansi("bold", "-player ") ansi("underline", "PROGRAM")) RS \
        ins(2, "Specify the audio player to use, and listen to the translation.") RS \
        ins(1, ansi("bold", "-no-play")) RS                             \
        ins(2, "Do not listen to the translation.") RS                  \
        RS "Terminal paging and browsing options:" RS                   \
        ins(1, ansi("bold", "-v") ", " ansi("bold", "-view")) RS        \
        ins(2, "View the translation in a terminal pager.") RS          \
        ins(1, ansi("bold", "-pager ") ansi("underline", "PROGRAM")) RS \
        ins(2, "Specify the terminal pager to use, and view the translation.") RS \
        ins(1, ansi("bold", "-no-view")) RS                             \
        ins(2, "Do not view the translation in a terminal pager.") RS   \
        ins(1, ansi("bold", "-browser ") ansi("underline", "PROGRAM")) RS \
        ins(2, "Specify the web browser to use.") RS                    \
        RS "Networking options:" RS                                     \
        ins(1, ansi("bold", "-x ") ansi("underline", "HOST:PORT")       \
            ", " ansi("bold", "-proxy ") ansi("underline", "HOST:PORT")) RS \
        ins(2, "Use HTTP proxy on given port.") RS                      \
        ins(1, ansi("bold", "-u ") ansi("underline", "STRING")          \
            ", " ansi("bold", "-user-agent ") ansi("underline", "STRING")) RS \
        ins(2, "Specify the User-Agent to identify as.") RS             \
        RS "Interactive shell options:" RS                              \
        ins(1, ansi("bold", "-I") ", " ansi("bold", "-interactive") ", " ansi("bold", "-shell")) RS \
        ins(2, "Start an interactive shell.") RS                        \
        ins(1, ansi("bold", "-E") ", " ansi("bold", "-emacs")) RS       \
        ins(2, "Start the GNU Emacs front-end for an interactive shell.") RS \
        ins(1, ansi("bold", "-no-rlwrap")) RS                           \
        ins(2, "Do not invoke rlwrap when starting an interactive shell.") RS \
        RS "I/O options:" RS                                            \
        ins(1, ansi("bold", "-i ") ansi("underline", "FILENAME")        \
            ", " ansi("bold", "-input ") ansi("underline", "FILENAME")) RS \
        ins(2, "Specify the input file.") RS                            \
        ins(1, ansi("bold", "-o ") ansi("underline", "FILENAME")        \
            ", " ansi("bold", "-output ") ansi("underline", "FILENAME")) RS \
        ins(2, "Specify the output file.") RS                           \
        RS "Language preference options:" RS                            \
        ins(1, ansi("bold", "-l ") ansi("underline", "CODE")            \
            ", " ansi("bold", "-hl ") ansi("underline", "CODE")         \
            ", " ansi("bold", "-lang ") ansi("underline", "CODE")) RS   \
        ins(2, "Specify your home language.") RS                        \
        ins(1, ansi("bold", "-s ") ansi("underline", "CODE")            \
            ", " ansi("bold", "-sl ") ansi("underline", "CODE")         \
            ", " ansi("bold", "-source ") ansi("underline", "CODE")) RS \
        ins(2, "Specify the source language.") RS                       \
        ins(1, ansi("bold", "-t ") ansi("underline", "CODES")           \
            ", " ansi("bold", "-tl ") ansi("underline", "CODE")         \
            ", " ansi("bold", "-target ") ansi("underline", "CODES")) RS \
        ins(2, "Specify the target language(s), joined by '+'.") RS     \
        RS "Other options:" RS                                          \
        ins(1, ansi("bold", "-no-init")) RS                             \
        ins(2, "Do not load any initialization script.") RS             \
        RS "See the man page " Command "(1) for more information."
}

# Show man page.
function showMan(    temp) {
    if (ENVIRON["TRANS_MANPAGE"]) {
        initPager()
        Groff = detectProgram("groff", "--version")
        if (Pager && Groff) {
            temp = "echo -E \"${TRANS_MANPAGE}\""
            temp = temp PIPE                                            \
                Groff " -Wall -mtty-char -mandoc -Tutf8 "               \
                "-rLL=" Option["width"] "n -rLT=" Option["width"] "n"
            switch (Pager) {
            case "less":
                temp = temp PIPE                                        \
                    Pager " -s -P\"\\ \\Manual page " Command "(1) line %lt (press h for help or q to quit)\""
                break
            case "most":
                temp = temp PIPE Pager " -Cs"
                break
            default: # more
                temp = temp PIPE Pager
            }
            system(temp)
            return
        }
    }
    if (fileExists("man/" Command ".1"))
        system("man man/" Command ".1" SUPERR)
    else if (system("man " Command SUPERR))
        print getHelp()
}

# Return a reference table of languages as a string.
# Parameters:
#     displayName = "endonym" or "name"
function getReference(displayName,
                      ####
                      code, col, cols, i, j, name, r, rows, saveSortedIn, t, tt) {
    rows = int(length(Locale) / 3) + 1
    cols[0][0] = cols[1][0] = cols[2][0] = NULLSTR
    i = 0
    saveSortedIn = PROCINFO["sorted_in"]
    PROCINFO["sorted_in"] = displayName == "endonym" ? "@ind_num_asc" :
        "compName"
    for (code in Locale) {
        col = int(i / rows)
        append(cols[col], code)
        i++
    }
    PROCINFO["sorted_in"] = saveSortedIn

    if (displayName == "endonym") {
        r = "┌" replicate("─", 22) "┬" replicate("─", 23) "┬" replicate("─", 23) "┐" RS
        for (i = 0; i < rows; i++) {
            r = r "│ "
            for (j = 0; j < 3; j++) {
                if (cols[j][i]) {
                    t = cols[j][i] == "bo" ||
                        cols[j][i] == "dz" ||
                        cols[j][i] == "he" ||
                        cols[j][i] == "hi" ||
                        cols[j][i] == "hu" ||
                        cols[j][i] == "la" ||
                        cols[j][i] == "ml" ||
                        cols[j][i] == "mn" ||
                        cols[j][i] == "ne" ||
                        cols[j][i] == "ny" ||
                        cols[j][i] == "pa" ||
                        cols[j][i] == "pl" ||
                        cols[j][i] == "ro" ||
                        cols[j][i] == "sr" ||
                        cols[j][i] == "te" ||
                        cols[j][i] == "tg" ||
                        cols[j][i] == "tr" ||
                        cols[j][i] == "ur" ||
                        cols[j][i] == "wo" ||
                        cols[j][i] == "yi" ||
                        cols[j][i] == "yo" ||
                        (cols[j][i] != "zh-CN" && cols[j][i] != "zh-TW" &&
                         length(getEndonym(cols[j][i])) < 6) ? "\t\t " :
                        cols[j][i] == "id" ? "" :
                        "\t "
                    tt = length(cols[j][i]) == 3 ? " │" :
                        (cols[j][i] != "zh-CN" && cols[j][i] != "zh-TW") ? "  │" : ""
                    r = r getDisplay(cols[j][i]) t "- " ansi("bold", cols[j][i]) tt " "
                } else
                    r = r "\t\t       │"
            }
            r = r RS
        }
        r = r "└" replicate("─", 22) "┴" replicate("─", 23) "┴" replicate("─", 23) "┘"
    } else {
        r = "┌" replicate("─", 22) "┬" replicate("─", 23) "┬" replicate("─", 23) "┐" RS
        for (i = 0; i < rows; i++) {
            r = r "│ "
            for (j = 0; j < 3; j++) {
                if (cols[j][i]) {
                    t = cols[j][i] == "he" ||
                        cols[j][i] == "kk" ||
                        cols[j][i] == "ko" ||
                        cols[j][i] == "ky" ||
                        cols[j][i] == "ne" ||
                        cols[j][i] == "pl" ||
                        cols[j][i] == "ps" ||
                        cols[j][i] == "sd" ||
                        cols[j][i] == "sk" ||
                        cols[j][i] == "sm" ||
                        cols[j][i] == "so" ||
                        cols[j][i] == "te" ||
                        cols[j][i] == "ug" ||
                        cols[j][i] == "yo" ||
                        (cols[j][i] != "zh-CN" && cols[j][i] != "zh-TW" &&
                         length(getName(cols[j][i])) < 6) ? "\t\t " :
                        cols[j][i] == "fy" ||
                        cols[j][i] == "gd" ||
                        cols[j][i] == "ht" ? " " :
                        "\t "
                    tt = length(cols[j][i]) == 3 ? " │" :
                        (cols[j][i] != "zh-CN" && cols[j][i] != "zh-TW") ? "  │" : ""
                    name = getName(cols[j][i])
                    if (cols[j][i] == "zh-CN" ||
                        cols[j][i] == "zh-TW")
                        name = substr(name, 1, 12) "."
                    r = r name t "- " ansi("bold", cols[j][i]) tt " "
                } else
                    r = r "\t\t       │"
            }
            r = r RS
        }
        r = r "└" replicate("─", 22) "┴" replicate("─", 23) "┴" replicate("─", 23) "┘"
    }
    return r
}

# Return detailed information of languages as a string.
function getList(codes,    code, i, r, saveSortedIn) {
    r = NULLSTR
    if (!isarray(codes))
        r = getDetails(codes)
    else if (anything(codes)) {
        saveSortedIn = PROCINFO["sorted_in"]
        PROCINFO["sorted_in"] = "@ind_num_asc"
        for (i in codes)
            r = (r ? r RS prettify("target-seperator", replicate(Option["chr-target-seperator"], Option["width"])) RS \
                 : r) getDetails(codes[i])
        PROCINFO["sorted_in"] = saveSortedIn
    } else
        r = getDetails(Option["hl"])
    return r
}

####################################################################
# Help.awk                                                         #
####################################################################

# Return version as a string.
function getVersion(    build, gitHead, platform) {
    initAudioPlayer()
    initPager()
    platform = detectProgram("uname", "-o", 1)
    if (ENVIRON["TRANS_BUILD"])
        build = "-" ENVIRON["TRANS_BUILD"]
    else {
        gitHead = getGitHead()
        build = gitHead ? "-git:" gitHead : ""
    }

    return ansi("bold", sprintf("%-22s%s%s\n\n", Name, Version, build)) \
        sprintf("%-22s%s\n", "platform", platform)                      \
        sprintf("%-22s%s\n", "gawk (GNU Awk)", PROCINFO["version"])     \
        sprintf("%s\n", FriBidi ? FriBidi :
                "fribidi (GNU FriBidi) [NOT INSTALLED]")                \
        sprintf("%-22s%s\n", "audio player", AudioPlayer ? AudioPlayer :
                "[NOT INSTALLED]")                                      \
        sprintf("%-22s%s\n", "terminal pager", Pager ? Pager :
                "[NOT INSTALLED]")                                      \
        sprintf("%-22s%s\n", "terminal type", ENVIRON["TERM"])          \
        sprintf("%-22s%s (%s)\n", "user locale", UserLocale, getName(UserLang)) \
        sprintf("%-22s%s\n", "home language", Option["hl"])             \
        sprintf("%-22s%s\n", "source language", Option["sl"])           \
        sprintf("%-22s%s\n", "target language", join(Option["tl"], "+")) \
        sprintf("%-22s%s\n", "theme", Option["theme"])                  \
        sprintf("%-22s%s\n", "init file", InitScript ? InitScript : "[NONE]") \
        sprintf("\n%-22s%s", "Report bugs to:", "https://github.com/soimort/translate-shell/issues")
}

# Return help message as a string.
function getHelp() {
    return "Usage:  " ansi("bold", Command)                             \
        " [" ansi("underline", "OPTIONS") "]"                           \
        " [" ansi("underline", "SOURCE") "]"                            \
        ":[" ansi("underline", "TARGETS") "]"                           \
        " [" ansi("underline", "TEXT") "]..." RS                        \
        RS "Information options:" RS                                    \
        ins(1, ansi("bold", "-V") ", " ansi("bold", "-version")) RS     \
        ins(2, "Print version and exit.") RS                            \
        ins(1, ansi("bold", "-H") ", " ansi("bold", "-help")) RS        \
        ins(2, "Print help message and exit.") RS                       \
        ins(1, ansi("bold", "-M") ", " ansi("bold", "-man")) RS         \
        ins(2, "Show man page and exit.") RS                            \
        ins(1, ansi("bold", "-T") ", " ansi("bold", "-reference")) RS   \
        ins(2, "Print reference table of languages and exit.") RS       \
        ins(1, ansi("bold", "-R") ", " ansi("bold", "-reference-english")) RS \
        ins(2, "Print reference table of languages (in English names) and exit.") RS \
        ins(1, ansi("bold", "-L ") ansi("underline", "CODES")           \
            ", " ansi("bold", "-list ") ansi("underline", "CODES")) RS  \
        ins(2, "Print details of languages and exit.") RS               \
        ins(1, ansi("bold", "-U") ", " ansi("bold", "-upgrade")) RS     \
        ins(2, "Check for upgrade of this program.") RS                 \
        RS "Display options:" RS                                        \
        ins(1, ansi("bold", "-verbose")) RS                             \
        ins(2, "Verbose mode. (default)") RS                            \
        ins(1, ansi("bold", "-b") ", " ansi("bold", "-brief")) RS       \
        ins(2, "Brief mode.") RS                                        \
        ins(1, ansi("bold", "-d") ", " ansi("bold", "-dictionary")) RS  \
        ins(2, "Dictionary mode.") RS                                   \
        ins(1, ansi("bold", "-show-original ") ansi("underline", "Y/n")) RS \
        ins(2, "Show original text or not.") RS                         \
        ins(1, ansi("bold", "-show-original-phonetics ") ansi("underline", "Y/n")) RS \
        ins(2, "Show phonetic notation of original text or not.") RS    \
        ins(1, ansi("bold", "-show-translation ") ansi("underline", "Y/n")) RS \
        ins(2, "Show translation or not.") RS                           \
        ins(1, ansi("bold", "-show-translation-phonetics ") ansi("underline", "Y/n")) RS \
        ins(2, "Show phonetic notation of translation or not.") RS      \
        ins(1, ansi("bold", "-show-prompt-message ") ansi("underline", "Y/n")) RS \
        ins(2, "Show prompt message or not.") RS                        \
        ins(1, ansi("bold", "-show-languages ") ansi("underline", "Y/n")) RS \
        ins(2, "Show source and target languages or not.") RS           \
        ins(1, ansi("bold", "-show-original-dictionary ") ansi("underline", "y/N")) RS \
        ins(2, "Show dictionary entry of original text or not.") RS     \
        ins(1, ansi("bold", "-show-dictionary ") ansi("underline", "Y/n")) RS \
        ins(2, "Show dictionary entry of translation or not.") RS       \
        ins(1, ansi("bold", "-show-alternatives ") ansi("underline", "Y/n")) RS \
        ins(2, "Show alternative translations or not.") RS              \
        ins(1, ansi("bold", "-w ") ansi("underline", "NUM")             \
            ", " ansi("bold", "-width ") ansi("underline", "NUM")) RS   \
        ins(2, "Specify the screen width for padding.") RS              \
        ins(1, ansi("bold", "-indent ") ansi("underline", "NUM")) RS    \
        ins(2, "Specify the size of indent (number of spaces).") RS     \
        ins(1, ansi("bold", "-theme ") ansi("underline", "FILENAME")) RS \
        ins(2, "Specify the theme to use.") RS                          \
        ins(1, ansi("bold", "-no-theme")) RS                            \
        ins(2, "Do not use any other theme than default.") RS           \
        ins(1, ansi("bold", "-no-ansi")) RS                             \
        ins(2, "Do not use ANSI escape codes.") RS                      \
        RS "Audio options:" RS                                          \
        ins(1, ansi("bold", "-p, -play")) RS                            \
        ins(2, "Listen to the translation.") RS                         \
        ins(1, ansi("bold", "-player ") ansi("underline", "PROGRAM")) RS \
        ins(2, "Specify the audio player to use, and listen to the translation.") RS \
        ins(1, ansi("bold", "-no-play")) RS                             \
        ins(2, "Do not listen to the translation.") RS                  \
        RS "Terminal paging and browsing options:" RS                   \
        ins(1, ansi("bold", "-v") ", " ansi("bold", "-view")) RS        \
        ins(2, "View the translation in a terminal pager.") RS          \
        ins(1, ansi("bold", "-pager ") ansi("underline", "PROGRAM")) RS \
        ins(2, "Specify the terminal pager to use, and view the translation.") RS \
        ins(1, ansi("bold", "-no-view")) RS                             \
        ins(2, "Do not view the translation in a terminal pager.") RS   \
        ins(1, ansi("bold", "-browser ") ansi("underline", "PROGRAM")) RS \
        ins(2, "Specify the web browser to use.") RS                    \
        RS "Networking options:" RS                                     \
        ins(1, ansi("bold", "-x ") ansi("underline", "HOST:PORT")       \
            ", " ansi("bold", "-proxy ") ansi("underline", "HOST:PORT")) RS \
        ins(2, "Use HTTP proxy on given port.") RS                      \
        ins(1, ansi("bold", "-u ") ansi("underline", "STRING")          \
            ", " ansi("bold", "-user-agent ") ansi("underline", "STRING")) RS \
        ins(2, "Specify the User-Agent to identify as.") RS             \
        RS "Interactive shell options:" RS                              \
        ins(1, ansi("bold", "-I") ", " ansi("bold", "-interactive") ", " ansi("bold", "-shell")) RS \
        ins(2, "Start an interactive shell.") RS                        \
        ins(1, ansi("bold", "-E") ", " ansi("bold", "-emacs")) RS       \
        ins(2, "Start the GNU Emacs front-end for an interactive shell.") RS \
        ins(1, ansi("bold", "-no-rlwrap")) RS                           \
        ins(2, "Do not invoke rlwrap when starting an interactive shell.") RS \
        RS "I/O options:" RS                                            \
        ins(1, ansi("bold", "-i ") ansi("underline", "FILENAME")        \
            ", " ansi("bold", "-input ") ansi("underline", "FILENAME")) RS \
        ins(2, "Specify the input file.") RS                            \
        ins(1, ansi("bold", "-o ") ansi("underline", "FILENAME")        \
            ", " ansi("bold", "-output ") ansi("underline", "FILENAME")) RS \
        ins(2, "Specify the output file.") RS                           \
        RS "Language preference options:" RS                            \
        ins(1, ansi("bold", "-l ") ansi("underline", "CODE")            \
            ", " ansi("bold", "-hl ") ansi("underline", "CODE")         \
            ", " ansi("bold", "-lang ") ansi("underline", "CODE")) RS   \
        ins(2, "Specify your home language.") RS                        \
        ins(1, ansi("bold", "-s ") ansi("underline", "CODE")            \
            ", " ansi("bold", "-sl ") ansi("underline", "CODE")         \
            ", " ansi("bold", "-source ") ansi("underline", "CODE")) RS \
        ins(2, "Specify the source language.") RS                       \
        ins(1, ansi("bold", "-t ") ansi("underline", "CODES")           \
            ", " ansi("bold", "-tl ") ansi("underline", "CODE")         \
            ", " ansi("bold", "-target ") ansi("underline", "CODES")) RS \
        ins(2, "Specify the target language(s), joined by '+'.") RS     \
        RS "Other options:" RS                                          \
        ins(1, ansi("bold", "-no-init")) RS                             \
        ins(2, "Do not load any initialization script.") RS             \
        RS "See the man page " Command "(1) for more information."
}

# Show man page.
function showMan(    temp) {
    if (ENVIRON["TRANS_MANPAGE"]) {
        initPager()
        Groff = detectProgram("groff", "--version")
        if (Pager && Groff) {
            temp = "echo -E \"${TRANS_MANPAGE}\""
            temp = temp PIPE                                            \
                Groff " -Wall -mtty-char -mandoc -Tutf8 "               \
                "-rLL=" Option["width"] "n -rLT=" Option["width"] "n"
            switch (Pager) {
            case "less":
                temp = temp PIPE                                        \
                    Pager " -s -P\"\\ \\Manual page " Command "(1) line %lt (press h for help or q to quit)\""
                break
            case "most":
                temp = temp PIPE Pager " -Cs"
                break
            default: # more
                temp = temp PIPE Pager
            }
            system(temp)
            return
        }
    }
    if (fileExists("man/" Command ".1"))
        system("man man/" Command ".1" SUPERR)
    else if (system("man " Command SUPERR))
        print getHelp()
}

# Return a reference table of languages as a string.
# Parameters:
#     displayName = "endonym" or "name"
function getReference(displayName,
                      ####
                      code, col, cols, i, j, name, r, rows, saveSortedIn, t, tt) {
    rows = int(length(Locale) / 3) + 1
    cols[0][0] = cols[1][0] = cols[2][0] = NULLSTR
    i = 0
    saveSortedIn = PROCINFO["sorted_in"]
    PROCINFO["sorted_in"] = displayName == "endonym" ? "@ind_num_asc" :
        "compName"
    for (code in Locale) {
        col = int(i / rows)
        append(cols[col], code)
        i++
    }
    PROCINFO["sorted_in"] = saveSortedIn

    if (displayName == "endonym") {
        r = "┌" replicate("─", 22) "┬" replicate("─", 23) "┬" replicate("─", 23) "┐" RS
        for (i = 0; i < rows; i++) {
            r = r "│ "
            for (j = 0; j < 3; j++) {
                if (cols[j][i]) {
                    t = cols[j][i] == "bo" ||
                        cols[j][i] == "dz" ||
                        cols[j][i] == "he" ||
                        cols[j][i] == "hi" ||
                        cols[j][i] == "hu" ||
                        cols[j][i] == "la" ||
                        cols[j][i] == "ml" ||
                        cols[j][i] == "mn" ||
                        cols[j][i] == "ne" ||
                        cols[j][i] == "ny" ||
                        cols[j][i] == "pa" ||
                        cols[j][i] == "pl" ||
                        cols[j][i] == "ro" ||
                        cols[j][i] == "sr" ||
                        cols[j][i] == "te" ||
                        cols[j][i] == "tg" ||
                        cols[j][i] == "tr" ||
                        cols[j][i] == "ur" ||
                        cols[j][i] == "wo" ||
                        cols[j][i] == "yi" ||
                        cols[j][i] == "yo" ||
                        (cols[j][i] != "zh-CN" && cols[j][i] != "zh-TW" &&
                         length(getEndonym(cols[j][i])) < 6) ? "\t\t " :
                        cols[j][i] == "id" ? "" :
                        "\t "
                    tt = length(cols[j][i]) == 3 ? " │" :
                        (cols[j][i] != "zh-CN" && cols[j][i] != "zh-TW") ? "  │" : ""
                    r = r getDisplay(cols[j][i]) t "- " ansi("bold", cols[j][i]) tt " "
                } else
                    r = r "\t\t       │"
            }
            r = r RS
        }
        r = r "└" replicate("─", 22) "┴" replicate("─", 23) "┴" replicate("─", 23) "┘"
    } else {
        r = "┌" replicate("─", 22) "┬" replicate("─", 23) "┬" replicate("─", 23) "┐" RS
        for (i = 0; i < rows; i++) {
            r = r "│ "
            for (j = 0; j < 3; j++) {
                if (cols[j][i]) {
                    t = cols[j][i] == "he" ||
                        cols[j][i] == "kk" ||
                        cols[j][i] == "ko" ||
                        cols[j][i] == "ky" ||
                        cols[j][i] == "ne" ||
                        cols[j][i] == "pl" ||
                        cols[j][i] == "ps" ||
                        cols[j][i] == "sd" ||
                        cols[j][i] == "sk" ||
                        cols[j][i] == "sm" ||
                        cols[j][i] == "so" ||
                        cols[j][i] == "te" ||
                        cols[j][i] == "ug" ||
                        cols[j][i] == "yo" ||
                        (cols[j][i] != "zh-CN" && cols[j][i] != "zh-TW" &&
                         length(getName(cols[j][i])) < 6) ? "\t\t " :
                        cols[j][i] == "fy" ||
                        cols[j][i] == "gd" ||
                        cols[j][i] == "ht" ? " " :
                        "\t "
                    tt = length(cols[j][i]) == 3 ? " │" :
                        (cols[j][i] != "zh-CN" && cols[j][i] != "zh-TW") ? "  │" : ""
                    name = getName(cols[j][i])
                    if (cols[j][i] == "zh-CN" ||
                        cols[j][i] == "zh-TW")
                        name = substr(name, 1, 12) "."
                    r = r name t "- " ansi("bold", cols[j][i]) tt " "
                } else
                    r = r "\t\t       │"
            }
            r = r RS
        }
        r = r "└" replicate("─", 22) "┴" replicate("─", 23) "┴" replicate("─", 23) "┘"
    }
    return r
}

# Return detailed information of languages as a string.
function getList(codes,    code, i, r, saveSortedIn) {
    r = NULLSTR
    if (!isarray(codes))
        r = getDetails(codes)
    else if (anything(codes)) {
        saveSortedIn = PROCINFO["sorted_in"]
        PROCINFO["sorted_in"] = "@ind_num_asc"
        for (i in codes)
            r = (r ? r RS prettify("target-seperator", replicate(Option["chr-target-seperator"], Option["width"])) RS \
                 : r) getDetails(codes[i])
        PROCINFO["sorted_in"] = saveSortedIn
    } else
        r = getDetails(Option["hl"])
    return r
}


ndc hardcodes 'named' instead of using $named_program from rc.conf

PR:		7425
Reviewed by:	phk
Submitted by:	frf <frf@xocolatl.com>

# $Id: ndcedit.awk,v 1.7 1998/05/03 05:14:04 peter Exp $
NR == 3 {
	print "#"
	print "# This file is generated automatically, do not edit it here!"
	print "# Please change src/usr.sbin/ndc/ndcedit.awk instead"
	print "#"
	print ""

	print "# If there is a global system configuration file, suck it in."
	print "if [ -f /etc/rc.conf ]; then"
	print "\t. /etc/rc.conf"
	print "fi\n"
}
{
	if ($1 == "named") {
		printf "\t\t# $named_flags is imported from /etc/rc.conf\n"
		printf "\t\tif [ \"X${named_enable}\" = X\"YES\" ]; then\n"
		printf "\t\t\t${named_program} ${named_flags} && {\n"
		getline
		printf "\t%s\n", $0
		getline
		printf "\t%s\n", $0
		getline
		printf "\t%s\n", $0
		printf "\t\tfi\n"
	} else if (/PS=`/) {
		printf "\tif [ -f /proc/$PID/status ]; then\n"
		printf "\t\tPS=`cat /proc/$PID/status 2>/dev/null | grep named`\n"
		printf "\telse\n"
		gsub("\t", "\t\t", $0);
		print;
		printf "\tfi\n"
	} else {
	        if (/PATH=/) {
			gsub(":/usr/ucb:", ":", $0);
		}
		print;
	}
}

# $Id: ndcedit.awk,v 1.6 1997/06/18 01:55:19 jkh Exp $
NR == 3 {
	print "#"
	print "# This file is generated automatically, do not edit it here!"
	print "# Please change src/usr.sbin/ndc/ndcedit.awk instead"
	print "#"
	print ""

	print "# If there is a global system configuration file, suck it in."
	print "if [ -f /etc/rc.conf ]; then"
	print "\t. /etc/rc.conf"
	print "fi\n"
}
{
	if ($1 == "named") {
		printf "\t\t# $named_flags is imported from /etc/rc.conf\n"
		printf "\t\tif [ \"X${named_enable}\" = X\"YES\" ]; then\n"
		printf "\t\t\tnamed ${named_flags} && {\n"
		getline
		printf "\t%s\n", $0
		getline
		printf "\t%s\n", $0
		getline
		printf "\t%s\n", $0
		printf "\t\tfi\n"
	} else if (/PS=`/) {
		printf "\tif [ -f /proc/$PID/status ]; then\n"
		printf "\t\tPS=`cat /proc/$PID/status 2>/dev/null | grep named`\n"
		printf "\telse\n"
		gsub("\t", "\t\t", $0);
		print;
		printf "\tfi\n"
	} else {
	        if (/PATH=/) {
			gsub(":/usr/ucb:", ":", $0);
		}
		print;
	}
}


Changing back to "sleep 1"

Changing back to "sleep 1"

#!/usr/bin/awk -f

BEGIN {
	HUGE_STRING = "\n\
PING registro.br (200.160.2.3) 56(84) bytes of data.\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=1 ttl=56 time=25.5 ms\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=2 ttl=56 time=55.7 ms\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=3 ttl=56 time=75.2 ms\n\
ping: sendto: Network is down\n\
ping: sendto: No route to host\n\
ping: sendto: No route to host\n\
ping: sendto: No route to host\n\
ping: sendto: No route to host\n\
ping: sendto: No route to host\n\
Request timeout for icmp_seq 4\n\
Request timeout for icmp_seq 5\n\
Request timeout for icmp_seq 6\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=7 ttl=56 time=123 ms\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=8 ttl=56 time=149 ms\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=9 ttl=56 time=183 ms\n\
Request timeout for icmp_seq 10\n\
Request timeout for icmp_seq 11\n\
Request timeout for icmp_seq 12\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=13 ttl=56 time=123 ms\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=14 ttl=56 time=149 ms\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=15 ttl=56 time=183 ms\n\
\n\
--- registro.br ping statistics ---\n\
3 packets transmitted, 3 received, 0% packet loss, time 2000ms\n\
rtt min/avg/max/mdev = 36.750/38.535/40.048/1.360 ms\n\
"

	LEN = split(HUGE_STRING, ARRAY, "\n")

	for (i = 0; i < LEN; i++) {
		print ARRAY[i]
		system("sleep 1")
	}
}

#!/usr/bin/awk -f

BEGIN {
	HUGE_STRING = "\n\
PING registro.br (200.160.2.3) 56(84) bytes of data.\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=1 ttl=56 time=25.5 ms\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=2 ttl=56 time=55.7 ms\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=3 ttl=56 time=75.2 ms\n\
ping: sendto: Network is down\n\
ping: sendto: No route to host\n\
ping: sendto: No route to host\n\
ping: sendto: No route to host\n\
ping: sendto: No route to host\n\
ping: sendto: No route to host\n\
Request timeout for icmp_seq 4\n\
Request timeout for icmp_seq 5\n\
Request timeout for icmp_seq 6\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=7 ttl=56 time=123 ms\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=8 ttl=56 time=149 ms\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=9 ttl=56 time=183 ms\n\
Request timeout for icmp_seq 10\n\
Request timeout for icmp_seq 11\n\
Request timeout for icmp_seq 12\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=13 ttl=56 time=123 ms\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=14 ttl=56 time=149 ms\n\
64 bytes from registro.br (200.160.2.3): icmp_seq=15 ttl=56 time=183 ms\n\
\n\
--- registro.br ping statistics ---\n\
3 packets transmitted, 3 received, 0% packet loss, time 2000ms\n\
rtt min/avg/max/mdev = 36.750/38.535/40.048/1.360 ms\n\
"

	LEN = split(HUGE_STRING, ARRAY, "\n")

	for (i = 0; i < LEN; i++) {
		print ARRAY[i]
		system("sleep 0")
	}
}


Error for no seasons in MHz

Error for no seasons in MHz

# Generate series URLs, Titles, Number of Seasons from MHz "Browse" page
#
# INVOCATION:
#       curl -s https://mhzchoice.vhx.tv/series https://mhzchoice.vhx.tv/series?page=2 \
#           | awk -v URL_FILE=$URL_FILE -v TITLE_FILE=$TITLE_FILE \
#           -v NUM_SEASONS_FILE=$NUM_SEASONS_FILE -v ERROR_FILE=$ERROR_FILE \
#           -f getMHzFrom-browsePage.awk
#
# INPUT:
#       A French Village
#   ---
#
6 seasons

#
# OUTPUT:
#       $URL_FILE, $TITLE_FILE, $NUM_SEASONS_FILE

/https:\/\/mhzchoice.vhx.tv\/.*strong title/ {
    split ($0,fld,"\"")
    URL = fld[2]
    TITLE = fld[4]
    print URL >> URL_FILE

    # Canonicalize Title
    gsub (/'/,"'",TITLE)
    gsub (/"/,"\"\"",TITLE)
    if (match (TITLE, /^The /)) {
        TITLE = substr(TITLE, 5) ", The"
    }
    print TITLE >> TITLE_FILE
    next
}

/h4 class="transparent.*media-count/ {
    sub (/.*media-count'>/,"")
    sub (/ season.*$/,"")
    if ((numSeasons + 0) == 0)
        print "==> No seasons: " TITLE >> ERROR_FILE
    print $0 >> NUM_SEASONS_FILE
}

# Generate series URLs, Titles, Number of Seasons from MHz "Browse" page
#
# INVOCATION:
#       curl -s https://mhzchoice.vhx.tv/series https://mhzchoice.vhx.tv/series?page=2 \
#           | awk -v URL_FILE=$URL_FILE -v TITLE_FILE=$TITLE_FILE \
#           -v NUM_SEASONS_FILE=$NUM_SEASONS_FILE -v ERROR_FILE=$ERROR_FILE \
#           -f getMHzFrom-browsePage.awk
#
# INPUT:
#       A French Village
#   ---
#
6 seasons

#
# OUTPUT:
#       $URL_FILE, $TITLE_FILE, $NUM_SEASONS_FILE

/https:\/\/mhzchoice.vhx.tv\/.*strong title/ {
    split ($0,fld,"\"")
    URL = fld[2]
    TITLE = fld[4]
    print URL >> URL_FILE

    # Canonicalize Title
    gsub (/'/,"'",TITLE)
    gsub (/"/,"\"\"",TITLE)
    if (match (TITLE, /^The /)) {
        TITLE = substr(TITLE, 5) ", The"
    }
    print TITLE >> TITLE_FILE
    next
}

/h4 class="transparent.*media-count/ {
    sub (/.*media-count'>/,"")
    sub (/ season.*$/,"")
    print $0 >> NUM_SEASONS_FILE
}


works with Apples variable column count

works with Apples variable column count

function unquote(input) {
	gsub("\"", "", input);
	return input;
}

BEGIN {
	FS=",";
  sum = 0;
}

# first line
(NR == 1) {
  strContainingPeriod = unquote($0);
  periodParanthesisOpen = index(strContainingPeriod, "(");
  periodParanthesisClose = index(strContainingPeriod, ")");
  period = substr(strContainingPeriod, periodParanthesisOpen + 1, periodParanthesisClose - periodParanthesisOpen - 1);
  printf "Rechnungszeitraum: %s \\\\\n", period;
  print "\n\\begin{longtable}{|l|r|r|r|r|} \\hline";
  printf "Region oder Typ & Stückzahl & Gesamtpreis & Quellensteuern und Abgaben & Gesamtpreis \\\\ \\hline \\hline\n";
}

# column labels
(NR == 3) {
	for (i = 1; i <= NF; i++) {
		col[$i] = i;
	}
}

(NR > 3) {
	unitsSold = unquote($col["Units Sold"]);
	if (length(unitsSold) > 0 && (unitsSold > 0 || unitsSold == "-")) {
	  regionOrType = unquote($col["Region (Currency)"]);
	  localCurrency = substr(regionOrType, index(regionOrType, "(") + 1, 3);
		earned = unquote($col["Earned"]);
		inputTax = unquote($col["Input Tax"]);
		adjustments = unquote($col["Adjustments"]);
		withholdingTax = unquote($col["Withholding Tax"]);
		taxTotal = inputTax + adjustments + withholdingTax;
		proceeds = unquote($col["Proceeds"]);
		targetCurrency = unquote($col["Bank Account Currency"]);
	  printf "%s & %s & %.2f %s & %.2f %s & %.2f %s \\\\ \\hline \n", regionOrType, unitsSold, earned, localCurrency, taxTotal, localCurrency, proceeds, targetCurrency;
	  sum += proceeds;
	}
}

END {
	print "\\end{longtable}";
	print "\n\n";
  printf "\\begin{flushright} \\textbf{Zu zahlender Betrag %.2f %s} \\end{flushright} \n\n", sum, targetCurrency;
}

function unquote(input) {
	gsub("\"", "", input);
	return input;
}

BEGIN {
	FS=",";
  sum = 0;
  targetCurrency = "";
}

# first line
match($0, /iTunes Connect - Payments and Financial Reports/){

  strContainingPeriod = unquote($0);
  periodParanthesisOpen = index(strContainingPeriod, "(");
  periodParanthesisClose = index(strContainingPeriod, ")");
  period = substr(strContainingPeriod, periodParanthesisOpen + 1, periodParanthesisClose - periodParanthesisOpen - 1);
  printf "Rechnungszeitraum: %s \\\\\n", period;
  print "\n\\begin{longtable}{|l|r|r|r|r|} \\hline";
  printf "Region oder Typ & Stückzahl & Gesamtpreis & Quellensteuern und Abgaben & Gesamtpreis \\\\ \\hline \\hline\n";
}

match($3, /\"[0-9]*\.[0-9]+\"/) {
  regionOrType = unquote($1);
  localCurrency = substr(regionOrType, index(regionOrType, "(") + 1, 3);
  targetCurrency = unquote($11);
  printf "%s & %i & %.2f %s & %.2f %s & %.2f %s \\\\ \\hline \n", regionOrType, unquote($2), unquote($4), localCurrency, unquote($5) + unquote($6) + unquote($7), localCurrency, unquote($10), targetCurrency;
  sum += unquote($10);
}

END {
	print "\\end{longtable}";
	print "\n\n";
  printf "\\begin{flushright} \\textbf{Zu zahlender Betrag %.2f %s} \\end{flushright} \n\n", sum, targetCurrency;
}


fixed bug that incorrect computed dash times

function DU_read_dashes(dfile, dash_keys, dash_vals, dash_fields, dash_sizes,   n_dash_lines, line, nf, ary, f) {

	dash_sizes["n_dash_keys"] = 0
	dash_sizes["n_dash_fields"] = 0

	for(n_dash_lines = 0; (getline line < dfile) > 0; ){
		n_dash_lines++
		nf = split(line, ary, "\t")
		if(n_dash_lines == 1){
			dash_sizes["n_dash_fields"] = nf
			for(f = 1; f <= nf; f++)
				dash_fields[ary[f]] = f
		}
		dash_keys[n_dash_lines - 1] = ary[1]
		dash_vals[n_dash_lines - 1] = line
	}
	dash_sizes["n_dash_keys"] = n_dash_lines - 1
	close(dfile)

	return n_dash_lines - 1
}

function DU_find_dash_cands(key, n_ktab, ktab, k_idx,   i, j, k, k1) {

	k_idx["start"] = -1
	k_idx["end"]   = -1

	i = 1 ; j = n_ktab
	for( ; i <= j; ){
		k = int((i + j)/2)
		if(ktab[k] < key){
			i = k + 1
		}else if(ktab[k] > key){
			j = k - 1
		}else{
			# keys can have > 1 value
			for(k1 = k; k1 - 1 >= 1; ){
				if(ktab[k1 - 1] != key)
					break;
				k1--
			}
			k_idx["start"] = k1

			for(k1 = k; k1 + 1 <= n_ktab; ){
				if(ktab[k1 + 1] != key)
					break
				k1++
			}
			k_idx["end"]   = k1

			return 1
		}
	}
	return 0
}

function DU_job_in_dash(b_job, e_job, b_dash, e_dash,   bj_min, ej_min, bd_min, ed_min) {

	bj_min = 60 * substr(b_job, 1, 2) + substr(b_job, 4, 2)
	if(e_job != "")
		ej_min = 60 * substr(e_job, 1, 2) + substr(e_job, 4, 2)

	bd_min = 60 * substr(b_dash, 1, 2) + substr(b_dash, 4, 2)
	ed_min = 60 * substr(e_dash, 1, 2) + substr(e_dash, 4, 2)

	if(e_job != "")
		return bj_min >= bd_min && ej_min <= ed_min
	else
		return bj_min >= bd_min && bj_min <= ed_min
}

function DU_read_dashes(dfile, dash_keys, dash_vals, dash_fields, dash_sizes,   n_dash_lines, line, nf, ary, f) {

	dash_sizes["n_dash_keys"] = 0
	dash_sizes["n_dash_fields"] = 0

	for(n_dash_lines = 0; (getline line < dfile) > 0; ){
		n_dash_lines++
		nf = split(line, ary, "\t")
		if(n_dash_lines == 1){
			dash_sizes["n_dash_fields"] = nf
			for(f = 1; f <= nf; f++)
				dash_fields[ary[f]] = f
		}
		dash_keys[n_dash_lines - 1] = ary[1]
		dash_vals[n_dash_lines - 1] = line
	}
	dash_sizes["n_dash_keys"] = n_dash_lines - 1
	close(dfile)

	return n_dash_lines - 1
}

function DU_find_dash_cands(key, n_ktab, ktab, k_idx,   i, j, k, k1) {

	k_idx["start"] = -1
	k_idx["end"]   = -1

	i = 1 ; j = n_ktab
	for( ; i <= j; ){
		k = int((i + j)/2)
		if(ktab[k] < key){
			i = k + 1
		}else if(ktab[k] > key){
			j = k - 1
		}else{
			# keys can have > 1 value
			for(k1 = k; k1 - 1 >= 1; ){
				if(ktab[k1 - 1] != key)
					break;
				k1--
			}
			k_idx["start"] = k1

			for(k1 = k; k1 + 1 <= n_ktab; ){
				if(ktab[k1 + 1] != key)
					break
				k1++
			}
			k_idx["end"]   = k1

			return 1
		}
	}
	return 0
}

function DU_job_in_dash(b_job, e_job, b_dash, e_dash,   bj_min, ej_min, bd_min, ed_min) {

	bj_min = 60 * substr(b_job, 1, 2) + substr(b_job, 3, 2)
	if(e_job != "")
		ej_min = 60 * substr(e_job, 1, 2) + substr(e_job, 3, 2)

	bd_min = 60 * substr(b_dash, 1, 2) + substr(b_dash, 3, 2)
	ed_min = 60 * substr(e_dash, 1, 2) + substr(e_dash, 3, 2)

	if(e_job != "")
		return bj_min >= bd_min && ej_min <= ed_min
	else
		return bj_min >= bd_min && bj_min <= ed_min
}