home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / misc / inter41 / l2wh / l2whglos.awk < prev    next >
Encoding:
Text File  |  1994-05-22  |  7.8 KB  |  271 lines

  1. # L2WHGLOS.awk glossary.lst
  2. #    create a rtf-file for the glossary
  3. #      to be shown in a secondary Help-window (HPJ: [WINDOWS])
  4. #  pattern is:
  5. #   <empty line>
  6. #   <glossary term>
  7. #   \tab<description>
  8. #   ... empty line of next pattern
  9. #
  10. #  order is lexical order of glossary terms, starting /w 'A'
  11. #
  12. #  1st line of description might start with mmenomic expansion:
  13. #     \tab/(.*) /
  14. #  last line of description might have reference field:
  15. #    /[Ss]ee (also )?\(.*\)\.?$/ 
  16. #      reffield might be commaseperated list
  17. #        refitems /^INT/ do not refer to glossary term, but
  18. #          have pattern: INT 21h Function 5D(06)?h( and INT...)?
  19.  
  20. function suboem(s) {  # -- escape RTF specials
  21.   sos=s; s=""
  22.   gsub(/\\/,"\\\\",sos);  gsub(/\{/,"\\{",sos); gsub(/\}/,"\\}",sos)
  23.   gsub(/\\'/,"\\.'",sos)  # HC31.EXE V3.10.445 knows no \[rl](dbl)?quote !
  24.   gsub(/\0201/,"{\\'FC}",sos)  # -- german u umlaut ibm-oem 0x81=129d
  25.   gsub(/[\0177-\0377]/,".",sos)  # -- ibm-oem 0x7F-0xFF
  26.   return sos
  27. }
  28.  
  29. function disbtnout(afile) {
  30.   print ""ftn["!"]"{DisableButton(\"btn_Group\")}}" >> afile
  31. }
  32.  
  33. function crnewpage(afile) { # -- name should have been: crnewrtf
  34.   system("copy l2whcrtf.npg "afile" >> \\dev\\nul")
  35. }
  36.  
  37. function wreortf(afile) { # -- appends end-of-page and '}' to rtf-file      
  38.   printf "\n\\par"pardtx"\\page\n}\n" >> afile
  39. }
  40.  
  41. function escre(s) {     # -- kill regexp specials
  42.   sos=s; s=""
  43.   gsub(/[\$\{\}\*\+\(\)\/\\]/,".",sos)
  44.   gsub(/[\,\&\|\"\?\[\]\^]/,".",sos)
  45.   return sos
  46. }
  47.  
  48. function newchar(achar) {
  49.   curcharno=0
  50.   print "\\par{\\b\\fs24 "achar"}\\par" >> glosfile
  51. }
  52.  
  53. function getlookupterm(aterm) {
  54.   g_luterm=toupper(aterm); gsub(/[\-\\\/\, \t]/,"_",g_luterm);
  55.   return g_luterm
  56. }
  57.  
  58. function newterm(aterm,  termid) {
  59.   ++curcharno
  60.   termid=""curchar""curcharno""
  61.   termsindex[""getlookupterm(aterm)""]=""termid""
  62.   aterm=suboem(aterm)
  63.   print "{\\ul{"aterm"}}{\\v glos_"termid"}\\par" >> glosfile
  64.   print "\n"ftn["#"]"glos_"termid"}" >> popsfile
  65.   print ""ftn["$"]""aterm"}" >> popsfile
  66.   print ""ftn["K"]"{"aterm";Terms;Glossary}}" >> popsfile
  67.   print ""ftn["+"]"Glos}" >> popsfile
  68.   print "{\\fs24\\b\\cf4 "aterm"}\\par" >> popsfile
  69. }
  70.  
  71. function prexpansion(aexp) {
  72.   print "{\\i ("suboem(aexp)")}\\par" >> popsfile
  73. }
  74.  
  75. function prtermout(aterm, asep) { # -- flag for 2nd pass
  76. #   print ""aterm"" >> "terms.out"
  77.   print ""linkflag"" >> popsfile
  78.   print ""asep"" >> popsfile
  79.   print ""aterm"" >> popsfile
  80. }
  81.  
  82. function cvtterm(aterm, asep,   luterm, intid,s,e,t,i,a) {
  83.   if (""aterm"" ~ /^INT/) {
  84.     intid="INT "substr(aterm,5,2)""
  85.     i=match(aterm,/Function [0-9A-F][0-9A-F]/)
  86.     if (i+0 > 3) {
  87.       s=i; e=i+RLENGTH-2; t=substr(aterm,e)
  88.       a="AH"; i=index(t,"h")
  89.       if (i+0 >4) {
  90.         a="AX"; i=4
  91.       } else {
  92.         i=2
  93.       }
  94.       intid=""intid"\/"a"="substr(t,1,i)
  95.       printf asep"{\\strike{"suboem(aterm)"}}" >> popsfile
  96.       printf "{\\v !JumpKeyWord(\"INTERRUP.HLP\"," >> popsfile
  97.       print "\""intid"h\")}" >> popsfile # -- is this to "main" ?
  98.     } else
  99.       printf asep""suboem(aterm)"" >> popsfile
  100.   } else { 
  101.     luterm=getlookupterm(aterm)
  102.     if (""luterm"" in termsindex)
  103.       printf asep"{\\ul{"suboem(aterm)"}}{\\v glos_"termsindex[luterm]"}" >> popsfile
  104.     else
  105.       printf asep""suboem(aterm)"" >> popsfile
  106.   }
  107. }
  108.  
  109. function prlastlines(  line, term, i,j,pts,pte,terms,luterm,n ) {
  110.   line=""lastlines["befl"]""lastlines["last"]"" # -- concat them
  111.   if (""line"" !~ /^[ \t\r]?$/) {
  112.     i=match(line,/[Ss]ee (also )?/)  # -- sets RSTART and RLENGTH
  113.     if (i+0 > 0) {
  114.       if (i+0 > 1) {
  115.         print ""suboem(substr(line,1,i-1))"" >> popsfile
  116.         line=substr(line,i)
  117.       }
  118.       # -- parse term, set start and end
  119.       pts=RLENGTH+1 # -- startposition of term in line
  120.       term=""substr(line,pts)""
  121.       j=index(term,"\.")
  122.       if (j+0 > 0) { # -- endposition of term in line
  123.         pte=pts+j-1; term=substr(term,1,j-1)
  124.       } else pte=0
  125.       printf ""suboem(substr(line,1,pts-1))"" >> popsfile
  126.       # might be list of terms seperated by ", "s
  127.       n=split(term,terms,"\, "); prtermout(terms[1],"")
  128.       for (i=2; i <= n; i++) prtermout(terms[i],", ")
  129.       if (pte+0 != 0)
  130.         printf ""suboem(substr(line,pte))"" >> popsfile
  131.       printf "\n" >> popsfile
  132.       terms="" # -- destroy array
  133.     } else {
  134.       print ""suboem(line)"" >> popsfile
  135.     }
  136.     lastlines["befl"]=""; lastlines["last"]=""
  137.   }
  138.   print "\\par\\pard\\page" >> popsfile
  139. }
  140.  
  141. BEGIN {
  142.   console="\\dev\\con"
  143.   hpjfile="interrup.hpj"
  144.  
  145.   basename=ARGV[ARGC-1]
  146.   if ((i=index(basename,"\.")) > 0) basename=substr(basename,1,i-1)
  147.  
  148.   glosfile=basename".idx" # -- lexically grouped list of glossary terms
  149.   popsfile=basename".rtf" # -- glossary popups (item descriptions)
  150.   tmpfile=basename".tmp"
  151.   hlpfile=basename".hlp"
  152.   hexdigits="0123456789ABCDEF"; linkflag="!!L2WHCRTF!!"
  153.   glosid="id_Glossary"
  154.   about="About Interrupt List"
  155.   ftnt="{\\footnote "
  156.   ftn["#"]="#"ftnt; ftn["$"]="$"ftnt
  157.   ftn["K"]="K"ftnt; ftn["!"]="!"ftnt; ftn["+"]="+"ftnt
  158.   pardtx="\\pard\\tx960\\tx1920\\tx2880\\tx3840\\tx4800"
  159.  
  160.   print "Creating glossary in "glosfile" and "popsfile"" >> console
  161.  
  162.   crnewpage(glosfile)
  163.   print ""ftn["#"]glosid"}" >> glosfile
  164.   s="Glossary"
  165.   print ""ftn["$"]""s"}" >> glosfile
  166.   print ""ftn["K"]"{"s";Terms;"about"}}" >> glosfile
  167.  #  print ""ftn["+"]"Seq}" >> glosfile
  168.  #  disbtnout(glosfile)
  169.   close(glosfile)
  170.  
  171.   crnewpage(popsfile)
  172.  
  173.   # termsindex=""
  174.   lastlines["befl"]="" # -- before last
  175.   lastlines["last"]="" # -- to be scanned for /[Ss]ee (also )?/
  176.   curchar="X"; lineprefx=""
  177.   curcharno=0
  178.   doheader="T"
  179.   termscnt=0
  180. }
  181.  
  182. doheader ~ /T/ { # -- ignore 1st line
  183.   print "{\\fs24\\b\\cf4{"s"}}{" >> glosfile
  184.   if ((getline s)+0 <= 0) exit 3  # -- 2nd line: last change date
  185.   print ", "suboem(s)"}\\par" >> glosfile
  186.   print "{\\pard\\tx240\\li240\\fi-240}" >> glosfile
  187.   doheader="F"
  188.   next
  189. }
  190.  
  191. /\r$/ { # -- why do I need to strip off CR now ?
  192.   $0=substr($0,1,length($0)-1)
  193. }
  194.  
  195.  
  196. /^$/ { # -- empty line
  197.   prlastlines()
  198.   if (getline+0 > 0) { # get next line
  199.     printf ""$0"         \r" >> console
  200.     nterm=$0
  201.     if (""toupper(substr(nterm,1,1))"" !~ "^"curchar"$") {
  202.       curchar=toupper(substr(nterm,1,1))""
  203.       newchar(curchar)
  204.     }
  205.     newterm(nterm); termscnt++
  206.     next    
  207.   } else {
  208.     exit 4
  209.   }
  210.   lineprefx=""
  211. }
  212.  
  213. /^\t\(/ { # -- 1st line of description /w mnemonic expansion
  214.   # -- strip off expansion: assume expansion is on this line only
  215.   i=index($0,")")
  216.   if (i+0 > 3) prexpansion(substr($0,3,i-3))
  217.   else i=1
  218.   $0=substr($0,i+2)
  219.   lineprefx=""
  220. }
  221.  
  222. /^\t/ { # -- 1st line of description
  223.   $0=substr($0,2) # -- strip off leading tab
  224.   lineprefx=""
  225. }
  226.  
  227.   { # -- a line of the description: update last2lines
  228.   $0=""lineprefx""$0"";    lineprefx=" "
  229.   if (""lastlines["befl"]"" !~ /^ ?\r?$/)
  230.     print ""lastlines["befl"]"" >> popsfile
  231.   lastlines["befl"]=lastlines["last"]
  232.   lastlines["last"]=""$0""
  233.   next
  234. }
  235.  
  236.  
  237. END {
  238.   prlastlines()
  239.  
  240.   printf("\n\\par"pardtx"\\page\n}\n") >> glosfile
  241.   close(glosfile)
  242.  
  243.   print "\n"pardtx"\n}\n" >> popsfile
  244.   close(popsfile)
  245.  
  246.   # -- start 2nd pass to resolve links
  247.   print "Resolving links...     " >> console
  248.   system("copy "popsfile" "tmpfile"")
  249.   printf "" > popsfile # -- rewrite file
  250.   while (getline < tmpfile > 0) {
  251.     if (""$0"" ~ ""linkflag"$") {
  252.       i=match($0,""linkflag"")
  253.       if (i+0 > 2) printf ""substr($0,1,i-1) >> popsfile
  254.       getline sep < tmpfile
  255.       getline term < tmpfile
  256.       cvtterm(term,sep)
  257.     } else
  258.       print ""$0"" >> popsfile
  259.   }
  260.   close(tmpfile)
  261.   close(popsfile)
  262.  
  263.  # system("del "tmpfile"")
  264.   print ""glosfile"  ; Glossary index" >> hpjfile
  265.   print ""popsfile"  ; Glossary topics" >> hpjfile
  266.   print "Found "termscnt" terms         " >> console
  267.   print "Done" >> console
  268. }
  269.  
  270.  
  271.