# dbTeX.awk - a simple preprocessor for generating TeX output from # database files # Version 1.1.beta (1991-02-12) dr. w. kraml, KPMG Alpen-Treuhand Wien # see dbTeX.tex for documentation! BEGIN { console_msg("This is dbTeX Version 1.1.beta (1991-02-12)") printf("%% dbTeX (1.1.beta) Output generated " ctime() "\n") # ^ PolyAwk specific! printf("%% dbTeX Input file: %s\n", ARGV[1]) # a number of initialisations and defs follow here: FieldS = FS RecordS = RS NRincluded = 0 example_flag = 0 buffer = "" STANDARD = 0 STRING = 1 TEMPLATE = 2 ID = 3 USER = 1 } # main loop - do this for each line in script { if ($0 ~ /^%!/) { # embedded dbTeX-command in_template = 0 buffer = substr($0,3) print $0 # output for reference dbTeX_command() } else if ($0 ~ /^%_/) { # template contin. line print $0 if (in_template) { # start cont. with newlines nl = length(template[t_name]) ? "\n" : "" template[t_name] = template[t_name] nl substr($0,3) } else error_msg("INVALID CONTINUATION") } else if (example_flag) { # embedded examples in_template = 0 print "%" $0 } else { in_template = 0 print $0 # original TeX line } } END { s = NR " line(s) input, " NRincluded " record(s) included, " s = s (errors+0) " error(s)" info_msg(s) } # functions performing helpful tasks with various messages function console_msg(s) { # output to console print s > "/dev/tty" } function error_msg(msg, s) { # print error on console s = "% (dbTeX) Error: " msg "!" # and in output file ++errors print s console_msg(s " -> line " NR ":") console_msg($0) } function info_msg(msg, s) { # print info on console s = "% (dbTeX) Info: " msg "." # and in output file print s console_msg(s) } # dbTeX functions function dbTeX_command() { # the dbTeX main function advance(ID) example_flag = 0 if (tok == "examples") example_flag = 1 # %! examples else if (tok == "record") { # %! record [] if (advance(ID)) { if (tok ~ /^%[0-9]+%$/) { # data-named template templ_typ = 1 templ_field = substr(tok,2,length(tok)-2) } else { # script-named template templ_typ = 0 templ_name = tok } } FieldS = advance(STRING) ? tok : FS RecordS = advance(STRING) ? tok : RS } else if (tok=="template") { # %! template