Plan 9 from Bell Labs’s /usr/web/sources/contrib/anothy/bin/rc/a2b

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

# ascii to baudot
# from boyd roberts' sh version, /n/sources/contrib/boyd/sys/src/cmd/a2b.html

# must turn bel into ~ for awk

tr -d '~' | tr '\007[a-z]' '~[A-Z]' | awk ' 
BEGIN   {
        baudot["A"] =           "| o o .       |"
        baudot["-"] =           "| o o .       |"
        baudot["B"] =           "| o   .   o o |"
        baudot["?"] =           "| o   .   o o |"
        baudot["C"] =           "|   o . o o   |"
        baudot[":"] =           "|   o . o o   |"
        baudot["D"] =           "| o   .   o   |"
        baudot["$"] =           "| o   .   o   |"
        baudot["E"] =           "| o   .       |"
        baudot["3"] =           "| o   .       |"
        baudot["F"] =           "| o   . o o   |"
        baudot["!"] =           "| o   . o o   |"
        baudot["G"] =           "|   o .   o o |"
        baudot["&"] =           "|   o .   o o |"
        baudot["H"] =           "|     . o   o |"
        baudot["STOP"] =        "|     . o   o |"
        baudot["I"] =           "|   o . o     |"
        baudot["8"] =           "|   o . o     |"
        baudot["J"] =           "| o o .   o   |"
        baudot["\''"] =        "| o o .   o   |"
        baudot["K"] =           "| o o . o o   |"
        baudot["("] =           "| o o . o o   |"
        baudot["L"] =           "|   o .     o |"
        baudot[")"] =           "|   o .     o |"
        baudot["M"] =           "|     . o o o |"
        baudot["."] =           "|     . o o o |"
        baudot["N"] =           "|     . o o   |"
        baudot[","] =           "|     . o o   |"
        baudot["O"] =           "|     .   o o |"
        baudot["9"] =           "|     .   o o |"
        baudot["P"] =           "|   o . o   o |"
        baudot["0"] =           "|   o . o   o |"
        baudot["Q"] =           "| o o . o   o |"
        baudot["1"] =           "| o o . o   o |"
        baudot["R"] =           "|   o .   o   |"
        baudot["4"] =           "|   o .   o   |"
        baudot["S"] =           "| o   . o     |"
        baudot["BELL"] =        "| o   . o     |"
        baudot["T"] =           "|     .     o |"
        baudot["5"] =           "|     .     o |"
        baudot["U"] =           "| o o . o     |"
        baudot["7"] =           "| o o . o     |"
        baudot["V"] =           "|   o . o o o |"
        baudot[";"] =           "|   o . o o o |"
        baudot["W"] =           "| o o .     o |"
        baudot["2"] =           "| o o .     o |"
        baudot["X"] =           "| o   . o o o |"
        baudot["/"] =           "| o   . o o o |"
        baudot["Y"] =           "| o   . o   o |"
        baudot["6"] =           "| o   . o   o |"
        baudot["Z"] =           "| o   .     o |"
        baudot["\""] =          "| o   .     o |"
        baudot[""] =            "|     .       |"
        baudot[""] =            "|     .       |"
        baudot["\r"] =          "|     .   o   |"
        baudot["\n"] =          "|   o .       |"
        baudot[" "] =           "|     . o     |"
        baudot["LTRS"] =        "| o o . o o o |"
        baudot["FIGS"] =        "| o o .   o o |"
        end =                   "|-------------|"

        figchars = "-?:$3!&8\''().,901457;2/6\"\r\n "
        bell = "~"
        figs = 0
        print end
}

{
        for (i = 1; i <= length($0); i++)
        {
                c = substr($0, i, 1)

                if (c ~ /[A-Z]/)
                {
                        if (figs)
                        {
                                print baudot["LTRS"]
                                figs = 0
                        }
                }       
                else if (index(figchars, c) > 0 || c == bell)
                {
                        if (c == bell)
                                c = "BELL";

                        if (!figs)
                        {
                                print baudot["FIGS"]
                                figs = 1
                        }
                }
                else if (c == "\t")
                        c = " "
                else
                        continue

                print baudot[c]
        }

        print baudot["\n"]
}

END     {
        print end
}
'

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].