plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

format (1613B)


      1 awk ' # format
      2 #   Input:  sort key (tab) string (tab) numlist
      3 #   Output: troff format, commands interpreted
      4 
      5 BEGIN {	FS = "\t"
      6 	s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz "
      7 	# set upper["a"] = "A"
      8 	for (i = 1; i <= 27; i++) upper[substr(s,i+27,1)] = substr(s,i,1)
      9 	# set lower["a"] =  lower["A"] ="a"
     10 	for (i = 1; i <= 27; i++) {
     11 		lower[substr(s,i,1)] = substr(s,i+27,1)
     12 		lower[substr(s,i+27,1)] = substr(s,i+27,1)
     13 	}
     14 }
     15 { # mark change between letters with .YY
     16 	# find first non-punctuation char
     17 	for (i = 1; (c = substr($1,i,1)) != ""; i++)
     18 		if (c ~ /[a-zA-Z0-9 ]/)
     19 			break
     20 	this = c
     21 	if (!(this in lower)) lower[this] = " "
     22 	this = lower[this]
     23 	if (this != last)  # && this != " ")
     24 		print ".YY", this, upper[last=this]
     25 	quoted = 0
     26 
     27   # interpret font change language
     28 
     29 	if ($2 ~ /^   /)	# different macro, to avoid bad breaks in hier
     30 		print ".ZZ"
     31 	else
     32 		print ".XX"
     33 	if (NF == 3)
     34 		$0 = $2 "," "  " $3	# discard sort key, leave term .. numlist
     35 	else
     36 		$0 = $2
     37 
     38 	if ($0 ~ /%/) {
     39 		quoted = 1
     40 		gsub(/%%/,  "QQ0QQ", $0)
     41 		gsub(/%\[/, "QQ1QQ", $0)
     42 		gsub(/%\]/, "QQ2QQ", $0)
     43 		gsub(/%\{/, "QQ3QQ", $0)
     44 		gsub(/%\}/, "QQ4QQ", $0)
     45 		gsub(/%~/,  "QQ5QQ", $0)
     46 	}
     47 	gsub(/%e/, "\\e", $0) # %e -> \e
     48 	gsub(/~/, " ", $0)    # unpaddable spaces go away at last
     49 	if (gsub(/\[/, "\\\\&\\f(CW", $0))
     50 		gsub(/\]/, "\\fP",   $0)
     51 	if (gsub(/\{/, "\\f2",   $0))
     52 		gsub(/\}/, "\\fP",   $0)
     53 	if (quoted) {
     54 		gsub(/%/, "", $0)
     55 		gsub(/QQ0QQ/, "%", $0)
     56 		gsub(/QQ1QQ/, "[", $0)
     57 		gsub(/QQ2QQ/, "]", $0)
     58 		gsub(/QQ3QQ/, "{", $0)
     59 		gsub(/QQ4QQ/, "}", $0)
     60 		gsub(/QQ5QQ/, "~", $0)
     61 	}
     62 	printf "\\&%s\n", $0
     63 }
     64 ' $*