Annotation of researchv10dc/vol2/anim/compile, revision 1.1

1.1     ! root        1: # compile: make fname.o (intermediate output) from fname.t (troff), if needed
        !             2: awk '
        !             3: function warn(s) {
        !             4:        print "compile error: " s >"/dev/stderr"
        !             5: }
        !             6: function fatal(s) {
        !             7:        print "compile fatal error: " s >"/dev/stderr"
        !             8:        exit 1
        !             9: }
        !            10: 
        !            11: BEGIN {
        !            12:        lsfile = "/tmp/compile.ls"
        !            13:        missingfile = "/tmp/compile.miss"
        !            14:        system("rm -f " lsfile " " missingfile)
        !            15:        for (i = 1; i < ARGC; i++) dofile(ARGV[i])
        !            16: }
        !            17: 
        !            18: function dofile(infile,   outfile, langname, i) {
        !            19:    # STARTUP
        !            20:        if (infile !~ /\.t$/) {
        !            21:                warn("usage: compile filename.t")
        !            22:                return
        !            23:        }
        !            24:        if ((getline < infile) == -1) {
        !            25:                warn("cannot open file " infile)
        !            26:                return
        !            27:        }
        !            28:        close(infile)
        !            29:        outfile = infile; sub(/\.t$/, ".o", outfile)
        !            30:        for (i in langs) delete x[i]
        !            31:        for (i in files) delete files[i]
        !            32:    # READ FILE  (if too expensive, grep first, as in doctype)
        !            33:        langname = ""
        !            34:        while ((getline <infile) > 0) {
        !            35:                sub(/^\.EQ[ \t]?/, ".begin eqn ")
        !            36:                sub(/^\.EN[ \t]?/, ".end ")
        !            37:                sub(/^\.PS[ \t]?/, ".begin pic ")
        !            38:                sub(/^\.PE[ \t]?/, ".end ")
        !            39:                sub(/^\.G1[ \t]?/, ".begin grap ")
        !            40:                sub(/^\.G2[ \t]?/, ".end ")
        !            41:                if (langname == "") { # outside .begin/.end
        !            42:                        if (/^\.begin[ \t]/) {
        !            43:                                langname = $2
        !            44:                                langs[langname]++
        !            45:                        }
        !            46:                } else { # inside ``.begin langname''
        !            47:                        if (/^\.end/) {
        !            48:                                langname = ""
        !            49:                        } else if ($1 == "file") {
        !            50:                                files[$2]++
        !            51:                        }
        !            52:                }
        !            53:        }
        !            54:        close(infile)
        !            55:    # CLEANUP
        !            56:       # Check currency and return if okay
        !            57:        filestr = ""
        !            58:        for (i in files) filestr = filestr " " i
        !            59:        system("ls -t " outfile " " infile\
        !            60:                filestr " >" lsfile " 2>" missingfile)
        !            61:        if ((getline < missingfile) == 0) {
        !            62:                getline newest < lsfile
        !            63:                close(lsfile)
        !            64:                if (newest == outfile) return
        !            65:        }
        !            66:        close(missingfile)
        !            67:       # Make and execute system call
        !            68:        need["chem"] = need["newman"] = need["stills"] = need["dformat"] \
        !            69:                = need["grap"] = need["scatter"] = need["swizzle"] = "pic"
        !            70:        need["dot"] = "grap"
        !            71:        n = split("dot grap scatter newman stills dformat " \
        !            72:                  "swizzle chem pic eqn", pname)
        !            73:        for (i = 1; i <= n; i++) {
        !            74:                s = pname[i]
        !            75:                if (langs[s]) {
        !            76:                        pipe = pipe " | " s
        !            77:                        langs[need[s]]++
        !            78:                }
        !            79:        }
        !            80:        system("cat " infile pipe " > " outfile)
        !            81: }
        !            82: ' $*

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.