home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / maj / 4266 / l2wh / l2whcrtf.awk < prev    next >
Text File  |  1994-05-22  |  21KB  |  697 lines

  1. # Usage of List To Windows Help Compiler Rich Text Format:
  2. #   X> AWK -fL2WHCRTF.AWK -vdosavestate="T" interrup.lst
  3. #   X> AWK -fL2WHCRTF.AWK interrup.lst
  4. #   X> AWK -fL2WHindx.AWK interrup.hpj
  5. #   X> AWK -fL2WHlink.AWK interrup.rtf
  6. #   X> HC31 INTERRUP
  7. # Fred de Jong - Heerlen - NL V1.2 20-May-95
  8. # Needs: l2whcrtf.hpj, .npg, .bmp, .grp, .ico, .1st
  9. #        DOS's comspec, sort.exe
  10.  
  11. function disbtnout(afile) {
  12.   print ""ftn["!"]"{DisableButton(\"btn_Group\")}}" >> afile
  13. }
  14.  
  15. function enbtnout(l_gid) {
  16.   printf ""ftn["!"]"{ChangeButtonBinding(\"btn_Group\"," >> rtfoutput
  17.   printf "\"JumpId(\\\\\""hlpfile"\\\\\",\\\\\"gid_"l_gid"\\\\\")\");\n" >> rtfoutput
  18.   print "EnableButton(\"btn_Group\")}}" >> rtfoutput
  19. }
  20.  
  21. function suboem(s) {  # -- escape RTF specials
  22.   sos=s; s=""
  23.   gsub(/\\/,"\\\\",sos);  gsub(/\{/,"\\{",sos); gsub(/\}/,"\\}",sos)
  24.   gsub(/\\'/,"\\.'",sos)  # HC31.EXE V3.10.445 knows no \[rl](dbl)?quote !
  25.   gsub(/\0201/,"{\\'FC}",sos)  # -- german u umlaut ibm-oem 0x81=129d
  26.   gsub(/[\0177-\0377]/,".",sos)  # -- ibm-oem 0x7F-0xFF
  27.   return sos
  28. }
  29.  
  30. function dopard() {
  31.   printf("\n"pardtx"\\par") >> rtfoutput
  32. }
  33.  
  34. function crnewpage(afile) {
  35.   system("copy l2whcrtf.npg "afile" > \\dev\\nul")
  36. }
  37.  
  38. function wreortf(afile) { # -- appends end-of-page and '}' to rtf-file      
  39.   printf "\n\\par"pardtx"\\page\n\}\n" >> afile
  40. }
  41.  
  42. function hex2dec(ahexs,   i, m) {
  43.   adecs=0 ;  m=1
  44.   for (i=length(ahexs); i > 0; i--) {
  45.     adecs = adecs + 0 + (m * \
  46.              (index(hexdigits,toupper(substr(ahexs,i,1)))-1)+0)
  47.     m = 16 * m
  48.   }
  49.   ahexs=""; i=""; m=""
  50.   return adecs""
  51. }
  52.  
  53. function copy2rtf(somestr)   {
  54.  # -- this is also for Notes , SeeAlsos and Returns
  55.   if ( substr(somestr,1,1) ~ /[ \t]/ ) {
  56.     somestr=substr(somestr,2)
  57.     print "\\par "somestr"" >> rtfoutput
  58.   }
  59.   else
  60.     print " "somestr"" >> rtfoutput
  61.   somestr=""
  62. }
  63.  
  64. function asplit(str, arr, n, i) {  # make an assoc array from str
  65.   n = split(str, fields)
  66.   for (i = 1; i <= n; i++) {
  67.     arr[fields[i]]=1 ; delete fields[i]
  68.   }
  69.   fields=""
  70.   return arr
  71. }
  72.  
  73. function cvtareg(regline,aline,  reg) {
  74.  # -convert AX=1234h , AL=34h or AH=12h to '1234', '__34', or '12__'
  75.   aline=""
  76.   reg=substr(regline,1,2)
  77.   if (reg in aregs) {
  78.     if (reg ~ /AX/) aline=substr(regline,4,4)
  79.     else if (reg ~ /AH/) aline=substr(regline,4,2)"__"
  80.     else if (reg ~ /AL/) aline="__"substr(regline,4,2)
  81.   } else aline="____"
  82.   reg=""; regline=""
  83.   return aline
  84. }
  85.  
  86. function cvtnareg(regfield,aline,   nareg) {
  87.  # -- convert a RX=1234h or RH=34h or RL=12h line to RR1234,RH34
  88.   aline=""
  89.   nareg=substr(regfield,1,2)
  90.   if (nareg in xregs) aline=nareg""substr(regfield,4,4)
  91.   else aline=nareg""substr(regfield,4,2)
  92.   nareg=""; regfield=""
  93.   return aline
  94. }
  95.  
  96. function cvtregs(saline,ridline,   regi, nregs, fields, aline)  {
  97.  # -- convert SeeAlso regs into topicid-format (of divide-lines)
  98.   ridline=""
  99.   nregs=split(saline,fields,"\/")
  100.   if (nregs > 0) {
  101.     ridline=cvtareg(fields[1],aline)
  102.     regi=1
  103.     if (substr(fields[1],1,2) in aregs) ++regi
  104.     for (; regi <= nregs; regi++) {
  105.       ridline=ridline""cvtnareg(fields[regi],aline)
  106.       delete fields[regi]
  107.     }
  108.     if (sub(/_+$/,"_",ridline) > 0) # -- strip ending '_'
  109.       ridline=substr(ridline,1,length(ridline)-1)
  110.   }
  111.   saline=""; fields=""; nregs=""; regi=""
  112.   return ridline
  113. }
  114.  
  115. function mkxrffilenm(anid) {
  116.   l_xrfn=""intdir""substr(anid,1,2)
  117.   return l_xrfn
  118. }
  119.  
  120. function mkgrpfilenm(idxchr,i) { # - compose temp.filename for groups
  121.   l_gfn=""grpdir""idxchr""sprintf("%3.3x",i+0)
  122.   idxchr=""; i=""
  123.   return l_gfn
  124. }
  125.  
  126. function mkgrpidxfn(idxchr) {
  127.   sub(/.$/,idxchr"",basegrpidxfn)
  128.   l_gifn=basegrpidxfn
  129.   idxchr=""
  130.   return l_gifn
  131. }
  132.  
  133. function getgrpidx(grpname) {
  134.   l_indexchr=toupper(substr(grpname,1,1))
  135.   if (""l_indexchr !~ /[A-Z0-9]/) l_indexchr="_"
  136.   return l_indexchr
  137. }
  138.  
  139. function escre(as) {     # -- kill regexp specials
  140.   sos=as; as=""
  141.   gsub(/[\$\{\}\*\+\(\)\/\\]/,".",sos)
  142.   gsub(/[\,\|\"\?\[\]\^]/,".",sos)
  143.   return sos
  144. }
  145.  
  146. function neatgrptpc(s) {
  147.   return suboem(toupper(substr(s,1,1))""tolower(substr(s,2))"")
  148. }
  149.  
  150. function addgroup(grpnm,tid,atopic,  idxchr,l_gid,escgrpnm,astr,i)  {
  151.   # -- lookup / create group using groupnames in group index files
  152.   #     if new group create new groupfile and write RTF-footnotes
  153.   if (""grpnm"" ~ /^IRQ/) {
  154.     if (""grpnm"" ~ /^IRQ *[0-9A-F]+$/) grpnm="IRQ"
  155.     else
  156.     if (""grpnm"" ~ /^IRQ[0-9A-F]+ relocated by/) {
  157.       grpnm=substr(grpnm,index(grpnm,"rel"))    
  158.       grpnm="IRQ "grpnm
  159.     }
  160.   }
  161.   if (""grpnm"" ~ /^IBM (PC ?)?3270/)
  162.     grpnm="IBM 3270 Emulation Program"
  163.   else {
  164.     for (i=1; i<= nfixedgroups; i++)
  165.       if (""grpnm"" ~ "^"fixedgroups[i]"") break
  166.     if (i <= nfixedgroups) grpnm=""fixedgroups[i]""
  167.     else {  # ignore last version word for grouping
  168.       # -- do not strip INT XX groupnames
  169.       if (""grpnm"" !~ /^INT/ && ""grpnm"" ~ / v?[0-9]+(\.[0-9]+)?[\+xf]?$/) {
  170.         n=split(""grpnm"",fields," ")
  171.         if (n > 1) {
  172.           grpnm=fields[1]
  173.           for (i=2; i < n; i++) grpnm=grpnm" "fields[i]
  174.           atopic=atopic" "fields[n]""
  175.         }
  176.         for (i in fields) delete fields[i]
  177.         fields=""
  178.       }
  179.     }
  180.   }
  181.   idxchr=getgrpidx(grpnm)
  182.   sub(/.$/,idxchr"",basegrpidxfn)
  183.   i=1; l_gid="NO"     # -- equals lineno in grpidxfile
  184.   if ((index(grpindices"",idxchr"")+0) > 0) {
  185.     escgrpnm="^"escre(""grpnm"")"$"
  186.     while ( getline astr < basegrpidxfn > 0 ) { # grpidxfile
  187.       if (""astr"" ~ escgrpnm) {
  188.         l_gid=""idxchr""i; break
  189.       }
  190.       ++i
  191.     }
  192.     close(basegrpidxfn); astr=""
  193.   } else 
  194.     grpindices=grpindices""idxchr
  195.  
  196.   grpfile=mkgrpfilenm(idxchr,i)
  197.   if (l_gid ~ /^NO/) {
  198.     l_gid=""idxchr""i
  199.     ++groupcnt
  200.     # -- create new group RTF-page file and register it in grpidx
  201.   printf "New Group          \r" >> console
  202.     print ""grpnm"" >> basegrpidxfn
  203.     close(basegrpidxfn)
  204.     print ""grpfile"  ; Group "grpnm"" >> hpjfile
  205.     close(hpjfile)
  206.     crnewpage(grpfile)
  207.     print "\n"ftn["#"]"gid_"l_gid"}" >> grpfile
  208.     grpnm=suboem(grpnm)
  209.     print ""ftn["$"]"{GROUP: "grpnm"}}" >> grpfile
  210.     print ""ftn["K"]"{GROUP: "grpnm"}}" >> grpfile
  211.     disbtnout(grpfile); keycnt++
  212.     print "\\keepn{\\fs22\\b\\cf4 GROUP: "grpnm"}\\par"pardtx"" >> grpfile
  213.   } else
  214.     printf "\\par" >> grpfile
  215.   print "{\\strike{"neatgrptpc(atopic)" ("tid")}}{\\v id_"tid"}" >> grpfile
  216.   atopic=""; grpnm=""
  217.   close(grpfile); grpfile=""
  218.   if (l_gid != "") enbtnout(l_gid)
  219.   else  disbtnout(rtfoutput)
  220.   idxchr=""; l_gid=""; escgrpnm=""; i=""
  221. }
  222.  
  223. function savestate(statefile, statedivline) {
  224.   printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", \
  225.          statedivline,grpindices,seealsocnt,seerefcnt, \
  226.          topiccnt,groupcnt,previntnuma,deftidcnt) > statefile
  227.   printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n", \
  228.          eqtidcnt,intnum,intnuma,topicid, \
  229.          intno,previntno,xrffile) >> statefile
  230.   close(statefile)
  231. }
  232.  
  233. function restorestate(statefile, statedivline) {  # -- get state from statefile
  234.   if ( ( getline statedivline < statefile ) > 0 ) {
  235.     getline grpindices < statefile; getline seealsocnt < statefile
  236.     getline seerefcnt < statefile; getline topiccnt < statefile
  237.     getline groupcnt < statefile; getline previntnuma < statefile
  238.     getline deftidcnt < statefile; getline eqtidcnt < statefile
  239.     getline intnum < statefile; getline intnuma < statefile
  240.     getline topicid < statefile; getline intno < statefile
  241.     getline previntno < statefile; getline xrffile < statefile
  242.     close(statefile); rc=0
  243.   } else rc=99
  244.   return rc
  245. }
  246.  
  247. function getaddkeys(ina,r) {
  248.   # -- add a key for INT XX/AH=XX like constructs
  249.   gaddkey=""
  250.   if (ah != "") gaddkey="AH="ah"h"
  251.   else if (al != "") gaddkey="AL="al"h"
  252.   else if (ax != "") gaddkey="AX="ax"h"
  253.   if (length(intnuma) > 6)  { # -- format to INT 44/AX=37DFh/BL=78h
  254.     ina=substr(intnuma,7)
  255.     while (length(ina) > 3) {
  256.       r=substr(ina,1,2)
  257.       if (r in xregs) {
  258.         if (length(ina)<6) break
  259.         gaddkey=(gaddkey"/"r"="substr(ina,3,4))"h"; ina=substr(ina,7)
  260.       } else {
  261.         gaddkey=(gaddkey"/"r"="substr(ina,3,2))"h"; ina=substr(ina,5)
  262.       } 
  263.     }
  264.   }
  265.   ina=""; r=""
  266.   return gaddkey
  267. }
  268.  
  269. function keysandgroup(   keys,groupname,addkey,i) {
  270.   keys=""$0""; gsub(/;/,"|",keys); gsub(/\, /,";",keys)
  271.   i=gsub(/ +- +/,";",keys)+0; keycnt=keycnt+i+1
  272.   if ((i=match(keys,/;[^;]*\?\?\?$/))+0 > 1) {
  273.      keys=substr(keys,1,i-1); keycnt--
  274.   }
  275.   # -- add ref to group page via btn_group
  276.   groupname=keys
  277.   if ((i=index(groupname,";"))+0 > 0)
  278.     groupname=substr(groupname,i+1)
  279.   if ((i=match(groupname,/;.*$/))+0 > 1)
  280.     groupname=substr(groupname,1,i-1)
  281.   addkey=""
  282.   if (""intno"" == $2"") addkey=getaddkeys()
  283.   print ""ftn["K"]"{"suboem(keys)"" >> rtfoutput
  284.   if (addkey != "") {
  285.     print ";INT "intno"/"addkey"" >> rtfoutput
  286.     addkey=""
  287.     keycnt++
  288.   }
  289.   print "}}" >> rtfoutput
  290.  
  291.   keys=""
  292.   addgroup(groupname,topicid,topic)
  293.   groupname="";  topic=""
  294.   printf "\\keepn{\\b\\cf4 " >> rtfoutput
  295.   print ""suboem($0)"}\\par"pardtx"" >> rtfoutput
  296.   # close(rtfoutput)
  297.  
  298. }
  299.  
  300. function printbold(astr) {
  301.   print "\\par\\par{\\b "astr"}\\par" >> rtfoutput
  302. }
  303.  
  304.  
  305. BEGIN  {
  306.   # dosavestate="T"
  307.   if (linkcachesize == "") linkcachesize=40
  308.   console="\\dev\\con"
  309.  
  310.   grpdir="g\\"; intdir="i\\";  lstfile=ARGV[ARGC-1]
  311.   basename=lstfile
  312.   if ((i=index(basename,"\.")) > 0) basename=substr(basename,1,i-1)
  313.   rtfoutput=basename".rtf"; statefile=basename".sta"
  314.   hpjfile=basename".hpj"; fmtsfile=basename".fmt"
  315.   hlpfile=basename".hlp"; grpidxfile=""grpdir""basename".grp"
  316.   basegrpidxfn=""grpdir"IG.~"; allgroupsfile=basename".idx"
  317.   hexdigits="0123456789ABCDEF"; linkflag="!!L2WHCRTF!!"
  318.   lnkrtffile=basename".ltf"; contentsid="id_Index"
  319.   about="About Interrupt List"
  320.   ftnt="{\\footnote "; decint2164=100
  321.   ftn["#"]="#"ftnt; ftn["$"]="$"ftnt
  322.   ftn["K"]="K"ftnt; ftn["!"]="!"ftnt; ftn["+"]="+"ftnt
  323.   pardtx="\\pard\\tx960\\tx1920\\tx2880\\tx3840\\tx4800"
  324.  
  325.   nfixedgroups=0
  326.   while (getline s < "l2whcrtf.grp" > 0) {
  327.     if (length(s) > 1) fixedgroups[++nfixedgroups]=escre(s)
  328.   }
  329.   close("l2whcrtf.grp")
  330.   print "Using "nfixedgroups" groups from l2whcrtf.grp" >> console
  331.   if (dosavestate ~ /T/) {
  332.     # --- first part
  333.     printf("Creating subdir g ") >> console
  334.     system("mkdir g"); system("del g\\ig.?"); system("del g\\????")
  335.     printf("\nCreating subdir i ") >> console
  336.     system("mkdir i"); system("del i\\???")
  337.     print " " >> console
  338.     grpindices=""
  339.     seealsocnt=0; seerefcnt=0; topiccnt=0; groupcnt=0; keycnt=0
  340.     previntnuma=""; deftidcnt=1; eqtidcnt=""
  341.     intnum=""; intnuma=""
  342.     topicid=""; intno="XX"; previntno="XX"
  343.     xrffile=mkxrffilenm("00")
  344.   } else {
  345.     print "Restoring state" >> console
  346.     if (restorestate(statefile) != 0) {
  347.       print "ERROR: no state" >> console
  348.       exit
  349.     }
  350.   }
  351.   topic=""; sa=""
  352.   asplit("BX CX DX BP SI DI CS DS ES AX",xregs)
  353.   asplit("AL AH BL BH CL CH DL DH SF",hregs) 
  354.   asplit("AL AH AX",aregs)
  355.  
  356.   chkaxregline="F"
  357.  
  358.   if (dosavestate ~ /T/) {
  359.     skiptostate=""
  360.     # -- create the Help Compiler project file
  361.    print "Creating HC project "hpjfile >> console
  362.     system("copy l2whcrtf.HPJ "hpjfile)
  363.     # -- append hpj later with summary and group files
  364.     # -- create the 1st pass RTF file (on rtfoutput)
  365.    print "Creating "rtfoutput" from "lstfile >> console
  366.     system("copy /b l2whcrtf.npg+l2whcrtf.1st "rtfoutput" > \\dev\\nul")
  367.   } else {
  368.     # -- skip to last broken state
  369.     skiptostate="T"
  370.   }
  371.   skippar="T"; metainfo="F"
  372. } # -- end BEGIN
  373.  
  374. # ------------------------- $0 ---------------------------------
  375.  
  376. skippar ~ /^T/ { # -- skipping to next dividerline
  377.   if (""$0"" ~ /^--------/) {
  378.     skippar="F"
  379.     if (metainfo ~ /^T/) {
  380.       metainfo="F";  print "\\f0" >> rtfoutput
  381.     } 
  382.   }
  383.   else {
  384.     if (metainfo ~ /^T/) { # -- print literally
  385.       print "\\par "suboem($0)"" >> rtfoutput 
  386.     }
  387.     next
  388.   }
  389. }
  390.  
  391.  {
  392.   $0=suboem($0)
  393.   if (skiptostate ~ /T/) {
  394.     print "Skipping to INT 2F ..." >> console
  395.     i=1; statedivline=suboem(statedivline)
  396.     while (skiptostate ~ /T/ && ""$0"" !~ "^----------2F") {
  397.       if (getline > 0) {
  398.         while (""$0"" !~ /^-/) { # substr($0,1,1)
  399.           if (getline > 0) i++
  400.           else {
  401.             skiptostate="F"; break
  402.           }
  403.         } 
  404.         # $0=suboem($0)
  405.         printf ""i"\r" >> console
  406.       } else {
  407.         skiptostate="F"; break
  408.      }
  409.     }
  410.     print "Skipped to line # "i" in "lstfile"" >> console
  411.     skiptostate="F"
  412.   }
  413.   # -- continue with following patterns/actions for current $0
  414. }
  415.  
  416. /^Fo/ {
  417.   if (""$0"" ~ /^Format of /) {
  418.     printf(""topicid" %s\n",substr($0,11,length($0)-11)) >> fmtsfile
  419.     printf("%s\n",intline) >> fmtsfile
  420.     close(fmtsfile)
  421.   }
  422. }
  423.    
  424. /^Format/ || /^Bitfields/ || /^Values/ {
  425.   print "\\par{\\b "$0"}\\par" >> rtfoutput
  426.  
  427. # -- if Format then next line is 'Offset\tab Size\tab Description'
  428.   if (""$0"" ~ /^F/) isformat="T"
  429.   else isformat="F"
  430. # -- if Bitfields then next line is 'Bit(s)\tab Description'
  431.   if (""$0"" !~ /^Values/) {
  432.     if (getline > 0) {
  433.       sa=suboem($0); gsub(/\t/,"\\tab\\ul ",sa)
  434.       print "{\\ul "sa"}"pardtx"\\par" >> rtfoutput
  435.     }
  436.   }
  437.  
  438.   while ((i = getline) > 0) {
  439.     if (isformat ~ /^T/) { # adjust unaligned '[N0-9]+ BYTEs' Size
  440.       if (NF+0 > 2) {
  441.         if (""substr($0,1,1)"" ~ / /) $0=""substr(""$0"",2)""
  442.         if (""$3"" ~ /(BYTE|WORD)s$/) {
  443.           j=match(""$0"",/ +/)
  444.           if (j+0 > 0) {
  445.             index($0," "); sa=substr(""$0"",j+RLENGTH)
  446.             sa=""$1"\t"sa""; $0=sa
  447.           }
  448.         }
  449.       }
  450.     }
  451.     $0=suboem($0) # -- force recalc of NF and $1,2...
  452.     if ($0 ~ /^[ \t]*$/ || $1 ~ /^-----/ || \
  453.         $1 ~ /^Notes?:/ || $1 ~ /all.*with:$/) break
  454.     else {
  455.       if ($0 ~ /^[ \t]*---[^\-]/) { # --function
  456.         if ((i=match($0,/[^ \t\-]/))+0 > 0) {
  457.           sa=substr($0,i)
  458.           if ((i=match(sa,/---[ \t]*$/))+0 > 1) sa=substr(sa,1,i-1)
  459.           print "\\par\\par{\\f1 "sa"\\f0}\\par"pardtx"" >> rtfoutput
  460.           continue
  461.         } 
  462.       }
  463.       print "\\par "$0"" >> rtfoutput
  464.     }
  465.   }
  466.   if (i <= 0) exit # goto END
  467.   if ($1 !~ /^-----/ && $1 !~ /^Notes?:/ && $1 !~ /all.*with:$/) {
  468.     dopard()
  469.     next
  470.   }
  471. }
  472.  
  473. /^--------(.+)-+$/  {
  474.   # -- divider line format =  '^--------C-IIAHALRRVV(VVRRVV(VV)?)?-+$'
  475.   if (dosavestate ~ /T/) {
  476.     if (substr(""$0"",11,2) ~ /2F/) {
  477.       savestate(statefile,""$0""); exit # -- goto END
  478.     }
  479.   }
  480.   # class=substr($0,9,1)
  481.   divl=substr($0,11);  $0=""
  482.   previntno=intno; intno=substr(divl,1,2)
  483.   ah=substr(divl,3,2); al=substr(divl,5,2)
  484.   if (ah ~ /--/) ah="" ;  if (al ~ /--/) al=""
  485.   if (ah != "" && al != "") { ax=ah""al""; ah=""; al="" } else ax=""
  486.   intnuma=divl
  487.   if ((i=match(intnuma,/-+$/))+0 > 1) intnuma=""substr(intnuma,1,i-1)
  488.   else intnuma=""
  489.   # -- assign topicid, decrease probability of duplicate topicids
  490.   #    assuming equal divider-line fields exist only sequential 
  491.   #    NB: intnuma is also used later to generate keys  
  492.   if (intnuma == "") {
  493.     topicid="def_"deftidcnt; deftidcnt++
  494.   } else {
  495.     gsub(/-/,"_",intnuma)
  496.     if (""previntnuma == ""intnuma) { # -- matches previous topicid ?
  497.       if (eqtidcnt != "") {
  498.         topicid=""intnuma"_"eqtidcnt; ++eqtidcnt        
  499.       } else {
  500.         topicid=""intnuma"_1"; eqtidcnt=2
  501.       }
  502.     } else {
  503.       topicid=intnuma; eqtidcnt=""
  504.     }
  505.   }
  506.   previntnuma=intnuma
  507.  
  508.   gsub("-","_",topicid)  # '-' are not allowed in context strings
  509.   if (topicid ~ /^def/) { # -- ignore comments
  510.     skippar="T"; next
  511.   }
  512.   topiccnt++
  513. # printf("%d          \r",0topiccnt) >> console
  514.   print ""pardtx"\\par\\page\n" >> rtfoutput
  515. printf topicid"                \r" >> console
  516.   print ""ftn["#"]"id_"topicid"}" >> rtfoutput
  517.   print ""ftn["+"]"Seq}" >> rtfoutput
  518.   if (topicid ~ /^__[A-Z]/) { # -- no INT line expected
  519.     topic=topicid
  520.     if (""topic"" ~ /^__/) topic=substr(topic,3)
  521.     # -- add to group about ('CONTACTINFO', etc)
  522.     print ""ftn["$"]""topic"}" >> rtfoutput
  523.     print ""ftn["K"]"{"topic";"about"}}" >> rtfoutput
  524.     disbtnout(rtfoutput)
  525.     dopard()
  526.     print "{\\ul\\b\\cf4 "substr(topic,1,1)""tolower(substr(topic,2))"\\par}\\keep" >> rtfoutput
  527.     # ---- read & print literally up to next divline
  528.     skippar="T"; metainfo="T"
  529.   }
  530.   next
  531. }  
  532.  
  533. /^[ \t]*---[^\-]/ { # --- subdivider
  534.   if ((i=match($0,/[^ \t\-]/))+0 > 0) {
  535.     sa=substr($0,i)
  536.     if ((i=match(sa,/---[ \t]*$/))+0 > 1) sa=substr(sa,1,i-1)
  537.     print "\\par\\par{\\f1 "sa"\\f0}\\par"pardtx"" >> rtfoutput
  538.     next
  539.   }
  540. }
  541.  
  542.  
  543. chkaxregline ~ /T/ && $1 ~ /^A[HX]$/ && $2 == "=" {
  544.   sa=substr($0,index($0,"A"))
  545.   printf("\\par{\\b %s}\n",sa) >> rtfoutput
  546.   chkaxregline="F"
  547.   next
  548. }
  549.  
  550.  
  551. /^INT [0-9A-F][0-9A-F] [UuPRCO]?/ {  # -- Ralf's Flags
  552.   # -- uses current topicid
  553.   intline=$0
  554.   if ((i=split(""$0"",fields," - "))+0 > 0) {
  555.     topic=fields[i] # last field in INT-line
  556.     if (i+0 > 1) {
  557.       if (fields[2] ~ /^VIRUS$/) {
  558.         topic=substr($0,match($0,/VIRUS/))
  559.       }
  560.     } 
  561.     fields=""
  562.   } else topic=""$0""
  563.   print ""ftn["$"]"{"suboem(topic)"}}" >> rtfoutput
  564.   if (length(topic) == 3) { # prevent '???' topics
  565.     if (""topic"" ~ /\?\?\?/) topic=suboem(""$0"")
  566.   }
  567.   # -- register cross-ref
  568.   if (""previntno"" !~ "^"intno"$") xrffile=mkxrffilenm(topicid)
  569.   printf(""topicid" %s\n",$0) >> xrffile
  570.   close(xrffile)
  571.  
  572.   keysandgroup()  # uses $0,intno,topic,topicid; topic is reset
  573.  
  574.   chkaxregline="T"
  575.   next
  576. }
  577.  
  578. /^$/ {
  579.   dopard()
  580.   next
  581. }
  582.  
  583. /^Desc:/ {
  584.   printbold("Description:")
  585.   sa=""$0"";  sub(/^Desc:[ \t]*/,"\t",sa)
  586.   copy2rtf(sa); sa=""
  587.   next
  588. }
  589.  
  590. /all.*with:$/ {
  591.   printbold($0)
  592.   next
  593. }
  594.  
  595. /^Program:/ {
  596.   printbold("Program:")
  597.   sa=""$0""; sub(/^Program:[ \t]*/,"\t",sa)
  598.   copy2rtf(sa); sa=""
  599.   next
  600. }
  601.  
  602. /^BUGS?:/ {
  603.   printbold("Bugs:")
  604.   sa=""$0""; sub(/^BUGS?:[ \t]*/,"\t",sa)
  605.   copy2rtf(sa); sa=""
  606.   next
  607. }
  608.  
  609. /^Index:/ { # -- skip line
  610.  #  printbold("Index:")
  611.  #  sa=""$0""; sub(/^Index:[ \t]*/,"\t",sa)
  612.  #  copy2rtf(sa); sa=""
  613.   next
  614. }
  615.  
  616. /^Notes?:/  {
  617.   printbold("Notes:")
  618.   sa=""$0"";  sub(/^Notes?:[ \t]*/,"\t",sa)
  619.   copy2rtf(sa); sa=""
  620.   next
  621. }
  622.  
  623. /^SeeAlso:/ {
  624.   seealsocnt++
  625.   printbold("See also:"); print "\\par" >> rtfoutput
  626.   sa=""$0""; sub(/^SeeAlso:[ \t]*/,"\t",sa)
  627.   # -- flag hyperlinks here for second pass using xrffile
  628.   #     and current topicid for intnum
  629.   #  formats:  AH=B0h, AX=3040h, AH=12h/BH=04h
  630.   #            AH=04h"Amstrad",AH=05h"Amstrad"
  631.   #            AX=1012h,AX=1051h
  632.   #            INT 09"MATH", INT 71
  633.   #            INT 15/AH=4Fh ... (seperator is ',')
  634.   nsa=split(sa,fields,","); sa=""
  635.   if (nsa > 0) {
  636.     lastintref=substr(intnuma,1,2)
  637.     lastaxref=substr(intnuma,3,4) 
  638.     for (i=1; i <= nsa; i++) {
  639.       linkid=""; hint=""
  640.       sa=fields[i]; osa=sa
  641.       if ((j=match(sa,/[^ \t]/)) > 0) sa=substr(sa,j)
  642.       if ((j=match(sa,/[ \t]+$/)) > 0) sa=substr(sa,1,j-1)
  643.       if ((j=index(sa,"\"")) > 0) {
  644.         hint=substr(sa,j+1); sa=substr(sa,1,j-1)
  645.         if ((j=index(hint,"\"")) > 0) {
  646.           hint="\""substr(hint,1,j)
  647.         } else hint=""
  648.       }
  649.       if (sa ~ /^INT/) {
  650.         sa=substr(sa,4)
  651.         if ((j=match(sa,/[^ \t]/)) > 0) sa=substr(sa,j)
  652.         linkid=substr(sa,1,2); lastintref=linkid
  653.         sa=substr(sa,3)
  654.         if (sa ~ /^\//) sa=substr(sa,2)
  655.       } else linkid=lastintref 
  656.       ridline=""
  657.       linkid=linkid""cvtregs(sa,ridline) # --- '/' seperated regs ?
  658.  printf ""linkid" "hint"     \r"  >> console
  659.       printf("{\\v{%s %s HINT=%s LNKTEXT=}}%s \n",
  660.              linkflag,linkid,hint,osa) >> rtfoutput
  661.       seerefcnt++
  662.     }
  663.   for (i in fields) delete fields[i]
  664.   fields=""; sa=""
  665.   } 
  666.   next
  667. }
  668.  
  669. /^Return:/ {
  670.   printbold("Return:"); sa=""$0""
  671.   sub(/^Return:[ \t]*/,"\t",sa)
  672.   copy2rtf(sa); sa=""
  673.   next
  674. }
  675.  
  676.  {
  677.   copy2rtf($0)
  678.   #  next
  679. }
  680.  
  681. END {
  682.   if (xrffile != "") close(xrffile)
  683.   # close(hpjfile)
  684.       # close(basegrpidxfn) # close(grpidxfile)
  685.   if (dosavestate ~ /T/) {
  686.     close(rtfoutput)
  687.     print "\nState saved in "statefile >> console
  688.     exit 0
  689.   }
  690.   wreortf(rtfoutput)
  691.   close(rtfoutput)
  692.   printf "Found: topics="topiccnt", refs="seerefcnt"" >> console
  693.   print ", groups="groupcnt", keys="keycnt"" >> console
  694.   print "Done" >> console
  695.   exit 0
  696. }
  697.