home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / docum / inter42.doc / int2whlp.inc < prev    next >
Encoding:
Text File  |  1994-07-20  |  25.0 KB  |  688 lines

  1. (* INT2WHLP Pascal Program Include File *)
  2.  
  3. (*
  4.   Interrupt List -> WinHelp converter (c) 1994 by Christian Müller-Planitz
  5.   ------------------------------------------------------------------------
  6. *)
  7.  
  8. (* v. 1.10 *)
  9.  
  10. type
  11.   stringPtr = ^string;
  12.   categoryStringPtrArr = array['!'..#126] of stringPtr;
  13.   titleStringPtrArr = array[byte] of stringPtr;
  14.   stringListPtr = ^stringList;
  15.   stringList = record next: stringListPtr; s: string; end;
  16.     (* NB! The program relies on "next" being the first field *)
  17.   stringListPtrPtr = ^stringListPtr;
  18.   aliasStringType = string[119];
  19.  
  20. var
  21.   flagStrings,categoryStrings,categoryKeyStrings: categoryStringPtrArr;
  22.   INTtitles: titleStringPtrArr;
  23.  
  24.   CONST InPath  : dirStr = '';
  25.     OutPath : dirStr = '';
  26.     OutFileCounter : Word = 0;
  27.     TopicNo : Word = 0;
  28.     LastSection : String[3] = '';    { stores number of last processed int }
  29.     IntTopicStr : String[7] = '';    { stores handle to page with subfunctions of the int's}
  30.     filterFileName: pathStr = '';
  31.     filtered: boolean = false;
  32.     compression: string[19] = 'NO';
  33.     emptyString: string[1] = '';
  34.     noteString: string[5] = 'note';
  35.     noneString: string[7] = '(none)';
  36.     buildExpr: string = '';
  37.     equStr: string[7] = ' Ax = ';
  38.     equBlanks: byte = 2;
  39.       (* These two variables can be changed to ' Ax=' and 0 by
  40.          program parameter -Q-. They control the format of search
  41.          strings as "INT nn AX = ahal" or "INT nn AX=ahal".
  42.          equStr[3] is assigned 'L', 'H', or 'X' by the program.
  43.       *)
  44.     tables: boolean = true; (* enables table cross referencing *)
  45.     backRef: boolean = false; (* disables the very first backward xref *)
  46.     missingTableCounter: word = 0;
  47.     missingTableLimit = 5; (* wait for user response when reached *)
  48.     indexColumns: integer = 1;
  49.     queuedEntry: string[127] = '';
  50.       (* stores an entry for the index, inserted by a call to insertQueued *)
  51.     notesCount: word = 0;    (* counts "Notes" entries in index *)
  52.     title: string[127] = ''; (* current "Notes" or "INT nn ... " *)
  53.     lastINTno: integer = -1;
  54.     firstAliasP: stringListPtr = NIL; (* aliases to be written to HPJ *)
  55.     nl: string[5] = '\par '; (* global NewLine string for AddTopic *)
  56.     indentIndex: string[7] = '\par   '; (* or '\par ' *)
  57.  
  58. const
  59.   (* The following typed constants controls some program behaviors. They
  60.      can all be set under configuration file and program parameter control.
  61.      The configuration section [OPTIONS] uses keys with the same names as
  62.      the typed constants, and the program parameters are listed for each
  63.      constant.
  64.   *)
  65.   singlesInMain: boolean = false;
  66.     (* There are two levels in the Interrupts index: A main index
  67.        with an entry for each interrupt, and a page for each interrupt
  68.        number. If "singlesInMain" is true, the entry in the main index
  69.        refers directly to the interrupt text if there is only one entry
  70.        in the table for that interrupt, if  "singlesInMain" is false, the
  71.        entry in the main index refers to a page with only one field.
  72.        Controlled by program parameter -1.
  73.     *)
  74.   twoIndexes: boolean = true;
  75.     (* If "twoIndexes" is true, the program mantains two indexes,
  76.        "Interrupt Index" with all the topics in the Interrupt List, and
  77.        "Interrupts" as described above. If the flag is false, only the
  78.        latter index is created.
  79.        Controlled by program parameter -2.
  80.     *)
  81.   errorLog: boolean = false;
  82.     (* controles whether HCxx error messages are written to a log file,
  83.        or to the screen only.
  84.        Controlled by program parameter -E.
  85.     *)
  86.   indexHeaders: boolean = true;
  87.     (* controles whether or not a heading "INT nn" is inserted for every
  88.        new interrupt number in the "Interrupt Index". Ignored if
  89.        "twoIndexes" is false.
  90.        Controlled by program parameter -H.
  91.     *)
  92.   markKeys: boolean = true;
  93.     (* If true, keywords (like "See also:", "Notes:") are bolded, if
  94.        false, they are not.
  95.        Controlled by program parameter -M.
  96.     *)
  97.   releaseNo: integer = 41;
  98.     (* This variable can be used to control program behavior and thus
  99.        facilitate compilation of older releases of the Interrupt List.
  100.        Currently it is used to:
  101.        Inhibit table as separate topics and table cross references if
  102.          releaseNo<41.
  103.        Controlled by program parameter -R.
  104.     *)
  105.   scrollIndexTitle: boolean = true;
  106.     (* Windows have a non-scroll area with the window title. Index
  107.        windows have an initial title part describing List release
  108.        number and help file compile date (inserted by specifying
  109.        "specialClassification" in the call to procedure "NewHlpPage").
  110.        If "scrollIndexTitle" is true, only the general part of the
  111.        title is in the non-scroll region, thus opening more space for
  112.        the scrolling part. If the flag is false, the whole title field
  113.        is made non-scrolable.
  114.        Controlled by program parameter -S.
  115.     *)
  116.   tableWindow: boolean = true;
  117.     (* If true, tables activated from a "#nnnn" hotspot appear in a
  118.        secondary window, if fase, in the main window.
  119.        Controlled by program parameter -T.
  120.     *)
  121.   expandedIndex: boolean = true;
  122.     (* controls whether the Interrupt Index initialy pops up in expanded
  123.        or compressed format.
  124.        Controlled by program parameter -X.
  125.     *)
  126.  
  127. (* Help windows topic titles and identifiers: *)
  128.     (* The following text describes windows titles as defined by the "$"
  129.        footnotes and topic identifiers (context strings) as defined by
  130.        the "#" footnotes. The identifiers can be used to open the List
  131.        at a given position by an external call to WINHELP.
  132.  
  133. window title        identifier    text
  134.  
  135. Contents:        CONTENTS    Main index.
  136. Interrupt Index        idIndex        Total list, only if "twoIndexes" is true.
  137. Interrupts            idInterrupts    Main interrupt index.
  138. INT NN List        nn_0        Index for INT NN, nn are two hex digits.
  139. INT NN AHAL - <header>    nn_1        First entry about INT NN, the following
  140.                     entries have consecutive identifiers
  141.                     ... nn_9, nn_10, ... . Aliases for
  142.                     Interrupt List topics can be compiled
  143.                     and written to the Help Project file.
  144.                     These aliases can be used to identify
  145.                     any (unique) topic.
  146. Tables            idTables    Table index.
  147. NN AHAL <table title>    tnnnn        Table No. nnnn, nnnn are the four
  148.                     decimal digits from the List. Aliases
  149.                     can be compiled based on table position
  150.                     and title.
  151.                     NN and AHAL in the title are the
  152.                     interrupt number and the register
  153.                     contents (sub function) where the table
  154.                     is defined.
  155. FILELIST        1        The initial part of the Interrrupt List.
  156. <notes>            n        Other notes have consecutive numbers as
  157.                     identifiers.
  158. INTERRUP.1ST File    id1st        INTERRUP.1ST file window.
  159. none            idPartComp    Partial compilation popup window if
  160.                     parameter -f<name>.
  161. Filter Method        idFlt_meth    Filter Method if parameter -f<name>.
  162. Filter File        idFlt_file    Filter File if parameter -f<name>.
  163. Credits            idCredits    The Credits window.
  164. none        Compressed_Index    This identifier is used as a marker.
  165.  
  166. The identifiers mentioned above are reserved for program use. Titles and
  167. identifiers for other windows are defined in the configuration file.
  168.  
  169. The program maintains 6 browse chains, as defined by the "+" footnotes:
  170.  
  171. The "main" chain:
  172.     m:1    the Credits window.
  173.     m:2    the Contents window.
  174.     m:3    the Interrupt Index window provided "twoIndexes" is true.
  175.     m:4    the Interrupts window.
  176.     m:5    the Tables window provided "releaseNo" >= 41.
  177.     m:9    index windows included as window type 2.
  178.  
  179. The "list" chain:
  180.     l:0    the interrupt list sub index windows.
  181.  
  182. The "interrupt" chain:
  183.     i:0    the interrupt windows.
  184.  
  185. The "file" chain:
  186.     f:0    files included by the program or as window type 1.
  187.  
  188. The "table" chain:
  189.     t:0    the table windows provided "releaseNo" >= 41.
  190.  
  191. The "ports" chain:
  192.     p:0    the sub windows compiled from window type 2 inclusion.
  193.  
  194. Window type 3 inclusions can link onto these chains or maintain their own
  195. chains under user control.
  196.  
  197. *)
  198.  
  199. (* Constants defining windows setup etc.
  200.    All the typed constants can be changed by the configuration file, and
  201.    some of them also by program parameters.
  202. *)
  203.  
  204. (* definitions for the *.HPJ file: *)
  205.     windowsTitle =     '"Ralf Brown''s Interrupt List"';
  206.     secWindowsTitle =  '"Interrupt List Tables"';
  207.     secWindow = 'ITW'; (* the name of the secondary window *)
  208.     mainW: string[5] = '>main'; (* or '' *)
  209.     tableW: string[((length(secWindow)+3) AND $FE) - 1] = '>'+secWindow;
  210.     windowsPosSize: string[21]   =   '';
  211.       (* or: '(xpos,ypos,width,heigth)' *)
  212.     secWindowsPosSize: string[21] =  '(43,0,980,1023)';
  213.       (* values must be defined for a secondary window *)
  214.     windowsMaximized = '0';      (* '0': no; '1': yes (overrides size) *)
  215.     windowsBackgr: string[19]    = ''; (* or: '(red,green,blue)' *)
  216.     windowsHdrBackgr: string[19] = ''; (* or: '(red,green,blue)' *)
  217.  
  218. (* definitions for fonts, attributes, and size: *)
  219.     headerFont: string[31]       = 'roman Times New Roman';
  220.       (* or 'swiss Arial' *)
  221.     textFont: string[31]         = 'modern Courier New';
  222.     deciPoints: word             = 90;
  223.       (* 10 times point size *)
  224.     headerDeciPoints: word       = 140;
  225.     header2ndDeciPoints: word    = 120;
  226.     headerAttrib =     '';       (*
  227.         \b   = bold
  228.         \i   = italics
  229.       *)
  230.     highlightInt =     '';       (* this attribute highlights specificly
  231.                        the "INT nn" part of the header *)
  232.     indent =           '1060';   (* left indent of header after line one *)
  233.       (* (in twips, whatever that is?) *)
  234.     dateSep =  '-';        (* for compile time YYYY-MM-DD string *)
  235.     timeSep =  ':';        (* for compile time H:MM string *)
  236.     (*.$define m_dd_yy *)  (* defines date format, default is yyyy-mm-dd *)
  237.     (*.$define d_mm_yy *)  (* defines date format if m_dd_yy is undefined *)
  238.     (*.$define yy_mm_dd *) (* defines date format to yy-mm-dd instead of
  239.                   yyyy-mm-dd if both m_dd_yy and d_mm_yy
  240.                   are undefined *)
  241.  
  242.   Var
  243.       ProcessTime    : Longint;
  244.       IndexFile      : Text;                    { stores *all* section names }
  245.       IntFile        : Text;                    { stores one entry per int-number }
  246.       SubIntFile     : Text;                    { stores all subfunctions of an int per page }
  247.       TableFile      : Text;                    { stores tables references (index) }
  248.       HPJ            : Text;                    { hlep compiler project file }
  249.       indexHeader    : string;                  { index and subindex header string }
  250.       compilationStr : string[119];             { compilation information }
  251.       TopicStr   : String[15];            { used in CheckKeyWords and ProcessList }
  252.       indexPages,indexRows: integer;
  253.       dateString: string[19];
  254.       fontSize, headerSize, header2ndSize: string[7];
  255.       aliasP,tableAliasP: stringListPtr;
  256.     (* aliases read from configuration file *)
  257.       aliasId,tableAliasId: string[19];
  258.       aliasString,tableAliasString: aliasStringType;
  259.       nextAliasPP: stringListPtrPtr;
  260.     (* stored aliases, to be written to the HPJ file *)
  261.       INTcounts: array[byte] of word;
  262.       currentDir,homeDir: dirStr;
  263.       currentTable: string[5];
  264.  
  265.   Const
  266.     (* classification characters < '!' do not insert a classification string as
  267.        a keyword.
  268.     *)
  269.     InvalidClassification = '-'; (* don't insert classification string as keyword *)
  270.     nullClassification = #0;     (* no title as keyword *)
  271.     specialClassification = #1;  (* use indexHeader in header *)
  272.     tableClassification = #2;    (* insert '#' + currentTable as keyword *)
  273.  
  274. function readKeyWd: word;
  275. (* Calls BIOS to read the keyboard, returns scan code in hi and char. in lo *)
  276.   inline($B4/$00/ {mov ah,0}  $CD/$16 {int $16});
  277.  
  278. procedure wl(s: string);
  279. (* a substitute for single-string "writeln" to screen (or "output") (saves
  280.    20 bytes of code per call).
  281. *)
  282.   begin writeln(s) end;
  283.  
  284. procedure errorExit(msg: string; err: byte);
  285. (* prints "msg" to screen and halts with errorlevel "err" *)
  286.   begin wl(msg); halt(err); end;
  287.  
  288. function exist(filename: pathStr): boolean;
  289. (* check the existance of "filename" *)
  290.   var b: boolean; t: text;
  291.   begin
  292. (*$I-*)
  293.     assign(t,filename);
  294.     reset(t);
  295.     b:=IOresult=0;
  296.     if b then close(t);
  297.     exist:=b;
  298. (*$I+*)
  299.   end; (* function exist *)
  300.  
  301. procedure defaultDir(var fileName: pathStr; var default: dirStr);
  302. (* if fileName has no drive, root, or current specification, then insert the
  303.    default directory.
  304. *)
  305.   begin
  306.     if (fileName[2]<>':') AND (fileName[1]<>'\') AND (fileName[1]<>'.') then
  307.       insert(default,filename,1);
  308.     fileName:=fExpand(fileName);
  309.   end; (* procedure defaultDir *)
  310.  
  311. (* Some of the following procedures are Windows getPrivateProfileXxx-like
  312.    routines to search the configuration file. If INT2WHLP.CFG is not found
  313.    in the current directory or in INT2WHLP.EXE's home directory, or if
  314.    the section or entry is not found in the file, the "value" parameter is
  315.    unchanged, otherwise the section/entry value is assigned to "value". A
  316.    boolean value is considered false if it is 0, and true otherwise.
  317. *)
  318.  
  319. function findProfile(var configFile: text; var section: dirStr): boolean;
  320. (* opens INT2WHLP.CFG on configFile and reads up to the specified section.
  321.    findProfile returns true if the configuration file was located, false
  322.    otherwise. If eof(configFile) returns true after a successful call
  323.    to findProfile this indicates that the section was not found, or it was
  324.    empty and last.
  325. *)
  326.   var i,l: integer; s: string;
  327.   begin
  328. (*$I-*)
  329.     findProfile:=false; (* suggest configuration file absent *)
  330.     if exist(progName+'.CFG') then assign(configFile,progName+'.CFG')
  331.     else assign(configFile,homeDir+progName+'.CFG');
  332.     reset(configFile);
  333.     if IOresult<>0 then exit;
  334.     findProfile:=true;
  335.     i:=1;
  336.     l:=length(section);
  337.     if l=0 then exit; (* we will interpret section='' as "open only" *)
  338.     while (i<=l) AND NOT eof(configFile) do begin
  339.       readln(configFile,s);
  340.       i:=1;
  341.       if (length(s)>=l+2) AND (s[1]='[') AND (s[l+2]=']') then
  342.     while (i<=l) AND (upcase(section[i])=upcase(s[succ(i)])) do inc(i);
  343.     end; (* while i<=l ... *)
  344. (*$I+*)
  345.   end; (* procedure findProfile *)
  346.  
  347. procedure profileList(section: dirStr; var listP: stringListPtr);
  348. (* reads all the entries in the specified section to a linked list and
  349.    assigns the beginning of the list to listP. Empty lines and lines
  350.    starting with a semicolon (;) are ignored.
  351. *)
  352.   label done,doneNC;
  353.   var listPP: ^stringListPtr; s: string; configFile: text;
  354.   begin
  355.     listPP:=@listP;
  356.     if NOT findProfile(configFile,section) then goto doneNC;
  357.       (* no configuration file *)
  358.     while NOT eof(configFile) do begin
  359.       readln(configFile,s);
  360.       if (s<>'') AND (s[1]<>';') then begin
  361.     if s[1]='[' then goto done;
  362.     getMem(listPP^,length(s)+1+sizeOf(pointer));
  363.     listPP^^.s:=s;
  364.     listPP:=@listPP^^.next;
  365.       end; (* if (s<>'')... *)
  366.     end; (* while NOT eof() *)
  367.   done:
  368.     close(configFile);
  369.   doneNC:
  370.     listPP^:=NIL;
  371.   end; (* procedure profileList *)
  372.  
  373. procedure freeStringRec(var p: stringListPtr);
  374. (* updates p to point to the next record, and frees the current one *)
  375.   var p1: stringListPtr;
  376.   begin
  377.     if p=NIL then exit;
  378.     p1:=p;
  379.     p:=p1^.next;
  380.     freeMem(p1,length(p1^.s)+1+sizeOf(pointer));
  381.   end; (* procedure freeStringRec *)
  382.  
  383. procedure profileString(section, entry: dirStr; var value: string;
  384.   bufferLen: integer);
  385.   label done;
  386.   var i,l: integer; s: string; configFile: text;
  387.   begin
  388. (*$I-*)
  389.     if (section='') OR (entry='') then exit;
  390.     if NOT findProfile(configFile,section) then exit;
  391.       (* no configuration file *)
  392.     i:=1;
  393.     l:=length(entry);
  394.     while (i<=l) AND NOT eof(configFile) do begin
  395.       readln(configFile,s);
  396.       if (s<>'') AND (s[1]='[') then goto done;
  397.       i:=1;
  398.       if (length(s)>l) AND (s[succ(l)]='=') then
  399.     while (i<=l) AND (upcase(entry[i])=upcase(s[i])) do inc(i);
  400.     end; (* while i<=l ... *)
  401.     if i>l then value:=copy(s,succ(i),bufferLen);
  402.   done:
  403.     close(configFile);
  404. (*$I+*)
  405.   end; (* procedure profileString *)
  406.  
  407. procedure profileInt(section, entry: dirStr; var value: integer);
  408.   var i,j: integer; s: string[19];
  409.   begin
  410.     s:='';
  411.     profileString(section,entry,s,pred(sizeOf(s)));
  412.     if s='' then exit;
  413.     val(s,i,j);
  414.     if j=0 then value:=i;
  415.   end; (* procedure profileInt *)
  416.  
  417. procedure profileBoolean(section, entry: dirStr; var value: boolean);
  418.   var i: integer;
  419.   begin
  420.     i:=ord(value);
  421.     profileInt(section,entry,i);
  422.     value:=i<>0;
  423.   end; (* procedure profileBoolean *)
  424.  
  425. procedure scan(line: string; var spa: categoryStringPtrArr);
  426. (* scans lines with format "xxx a - definition a, A - definition A" and
  427.    allocates memory and stores the definitions at appropriate index in spa.
  428. *)
  429.   var
  430.     p: integer;
  431.     c: char;
  432.     ok: boolean;
  433.   begin
  434.     repeat
  435.       p:=pos(' - ',line);
  436.       if p=0 then exit;
  437.       if p>1 then c:=line[p-1];
  438.       ok:=((p=2) OR ((p>2) AND (line[p-2]<=' '))) AND (c>' ') AND (c<#127);
  439.       delete(line,1,p+2);
  440.       if ok then begin
  441.     p:=pos(' - ',line);
  442.     if p=0 then p:=length(line)+1 else dec(p,2);
  443.     while line[p-1]<=' ' do dec(p);
  444.     if line[p-1]=',' then dec(p);
  445.     getmem(spa[c],p);
  446.     spa[c]^:=copy(line,1,p-1);
  447.     delete(line,1,p);
  448.       end; (* if ok *)
  449.     until false; (* terminated by exit *)
  450.   end; (* procedure scan *)
  451.  
  452. procedure check1st(var s: string);
  453. (* scans s for the occurence of 'INTERRUP.1ST' and inserts xref to id1st.
  454.    Letter case is ignored.
  455. *)
  456.   var p: byte; s1: string[119];
  457.   begin
  458.     s1[0]:=s[0];
  459.     for p:=1 to length(s) do s1[p]:=upcase(s[p]);
  460.     p:=pos('INTERRUP.1ST',s1);
  461.     if p<>0 then begin
  462.       insert('}{\v id1st}',s,p+12);
  463.       insert('{\uldb ',s,p);
  464.     end; (* if p<>0 *)
  465.   end; (* procedure check1st *)
  466.  
  467. procedure getINTtitle(var line: string; var titles: titleStringPtrArr);
  468. (* allocates memory and copies a line starting with "INT nn " to titles[nn]^ *)
  469.   type (* for type casts *)
  470.     lineRec = record l: byte; INT: longint; nn: word; spc: char; end;
  471.     hexRec = record l: byte; dollar: char; nn: word; end;
  472.   const
  473.     intC = ord('I')+ord('N')*$100+ord('T')*$10000+ord(' ')*$1000000;
  474.     intNumber: string[3] = '$nn'; (* preset length to 3 and [1] to '$' *)
  475.   var
  476.     lineR: lineRec absolute line; (* for typecast *)
  477.     intR: hexRec absolute intNumber; (* for typecast *)
  478.     n,j: integer;
  479.   begin
  480.     if (length(line)<8) OR (lineR.spc<>' ') OR (lineR.INT<>intC) then exit;
  481.     intR.nn:=lineR.nn; (* two characters typecasted to a word *)
  482.     val(intNumber,n,j);
  483.     if j<>0 then exit;
  484.     getmem(titles[n],succ(length(line)));
  485.     titles[n]^:=line;
  486.   end; (* procedure getINTtitle *)
  487.  
  488. procedure getNextAlias(var aliasP: stringListPtr;
  489.    var aliasId, aliasString: string);
  490. (* extract an alias string from the heap and free the heap memory *)
  491.   var n: integer;
  492.   begin
  493.     aliasString:='';
  494.     if aliasP=NIL then exit;
  495.     aliasString:=aliasP^.s;
  496.     freeStringRec(aliasP); (* free memory and update aliasP *)
  497.     n:=pos('=',aliasString);
  498.     if n<2 then errorExit('Missing alias Id in '+aliasString,1);
  499.     if n>pred(sizeOf(aliasId)) then errorExit('Alias Id too long in '+aliasString,1);
  500.     aliasId:=copy(aliasString,1,n);
  501.     delete(aliasString,1,n);
  502.   end; (* procedure getNextAlias *)
  503.  
  504. procedure saveAlias(var aPP: stringListPtrPtr; s: dirStr);
  505. (* allocates memory on the heap, stores information, and updates aPP *)
  506.   begin
  507.     getmem(aPP^,length(s)+1+sizeOf(pointer));
  508.     aPP^^.next:=NIL;
  509.     aPP^^.s:=s;
  510.     aPP:=@aPP^^.next
  511.   end; (* procedure saveAlias *)
  512.  
  513. procedure processAliasList(aP: stringListPtr);
  514.   begin
  515.     while aP<>NIL do begin
  516.       writeln(HPJ,aP^.s);
  517.       aP:=aP^.next;
  518.     end; (* while aP<>NIL *)
  519.   end; (* procedure processAliasList *)
  520.  
  521. procedure setTabs(var f: text; spaces, deciPoints, tabs: word);
  522. (* writes tab settings to file f, tabspacing approximately "spaces" character
  523.    columns width New Courier font with size 1/10*"deciPoints". Number of tab
  524.    settings = "tabs".
  525.    The tabs are valid until the next "\pard".
  526. *)
  527.   var i: integer; s: string[11];
  528.   begin
  529.     for i:=1 to tabs do begin
  530.       str(longint(i*spaces*deciPoints)*1170 DIV 1000,s);
  531.       (* tab spacing = (point size)*(column width)*11.70 *)
  532.     (* at least, this seems to fit pretty well *)
  533.       write(f,'\tx',s);
  534.     end; (* for i:=1 *)
  535.     writeln(f);
  536.   end; (* procedure setTabs *)
  537.  
  538. procedure writeIndex(s: string);
  539.   begin writeln(indexFile, s); end;
  540.  
  541.   procedure CreateHPJ;
  542.     var i,n: integer; bP: stringListPtr; s: dirStr;
  543.     begin
  544.       assign(HPJ, OutPath + hfName+'.HPJ');
  545.       rewrite(HPJ);
  546.       n:=0;
  547.       profileList('BUILDTAGS',bP);
  548.       if bP<>NIL then begin (* write [BuildTags] section *)
  549.     writeln(HPJ,'[BUILDTAGS]');
  550.     while bP<>NIL do begin
  551.       writeln(HPJ,bP^.s);
  552.       freeStringRec(bP); (* free memory and update bP *)
  553.     end; (* while bP<>NIL *)
  554.     writeln(HPJ);
  555.       end; (* if i>0 *)
  556.       s:=fExpand(OutPath);
  557.       if length(s)>3 then dec(s[0]); (* delete terminating '\' if not root *)
  558.       writeln(HPJ, '[OPTIONS]'#13#10'CONTENTS=CONTENTS'#13#10'COMPRESS=',compression);
  559.       writeln(HPJ,'REPORT=ON'#13#10'WARNING=2'#13#10'ROOT=',s);
  560.     (* warning=2 avoids the "Using old *.ph file" warning *)
  561.       if errorLog then writeln(HPJ,'ERRORLOG='+hfName+'.ERR');
  562.       if buildExpr<>'' then writeln(HPJ,'BUILD=',buildExpr);
  563.       writeln(HPJ, 'CITATION=Copied from Ralf Brown''s Interrupt List');
  564.       writeln(HPJ, 'COPYRIGHT='+hfName+' Layout: Christian Müller-Planitz');
  565.       writeln(HPJ, #13#10'[CONFIG]'#13#10'CreateButton("id_print","&Print","Print()")');
  566.       writeln(HPJ, 'CreateButton("id_copy","C&opy","CopyTopic()")'#13#10'BrowseButtons()');
  567.       writeln(HPJ, 'CreateButton("id_exit","E&xit","Exit()")');
  568.       if twoindexes AND NOT expandedIndex then
  569.     writeln(HPJ, 'SaveMark("Compressed_Index")');
  570.       writeln(HPJ, #13#10'[WINDOWS]'#13#10'main='+windowsTitle+',',windowsPosSize,
  571.     ','+windowsMaximized+',',windowsBackgr,',',windowsHdrBackgr);
  572.       if tableWindow then writeln(HPJ, secWindow+'='+secWindowsTitle+',',
  573.     secWindowsPosSize,','+windowsMaximized+',',windowsBackgr,',',
  574.     windowsHdrBackgr);
  575.       writeln(HPJ, #13#10'[FILES]');
  576.     end;
  577.  
  578.   Procedure OpenRTF(VAR F: Text; Name: String);
  579.     begin
  580.      {$I-}
  581.       assign(F, OutPath + Name);
  582.       rewrite(F);
  583.      {$I+}
  584.       if IOResult <> 0 then errorExit('Error craeting '+ OutPath + Name, 1);
  585.  
  586.       writeln(HPJ, Name);
  587.  
  588.       writeln(F, '{\rtf1\pc \deff1{\fonttbl{\f0\f',headerFont,';}');
  589.       writeln(F, '{\f1\f',textFont,';}}');
  590.       writeln(F, '{\colortbl \red255\green0\blue0;\red0\green0\blue0;');
  591.       writeln(F, '\red0\green0\blue255;\red255\green255\blue255;}');
  592.       writeln(F, '\plain',fontSize,'\pard\keep');
  593.     end;
  594.  
  595.  
  596.   Procedure CloseRTF(VAR F: Text);
  597.     begin
  598.       writeln(F, '}');
  599.       close(F);
  600.     end;
  601.  
  602.  
  603.   Procedure OpenOutFile(VAR FData: Text);
  604.       VAR Name : String;
  605.  
  606.       begin
  607.     STR(OutFileCounter, Name);
  608.     Name := hfName + Name + '.RTF';
  609.  
  610.     OpenRTF(FData, Name);
  611.     Inc(OutFileCounter);
  612.       end;
  613.  
  614.   Function HEX(b:byte):string;
  615.     Const h : array [0..15] of char = ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  616.     begin
  617.       Hex[0]:=#2; Hex[1]:=h[b shr 4]; Hex[2]:=h[b and 15];
  618.     end;
  619.  
  620.  
  621.   Procedure ReadLine(VAR F: Text; VAR S: String);
  622.     VAR q: Word;
  623.     c: Byte;
  624.  
  625.     begin
  626.       readln(F, S);
  627.  
  628.       q:= 1;
  629.       while q <= Length(s) do    { duplicate all '\' etc. }
  630.     begin
  631.       case s[q] of
  632.         '\', '{', '}': begin insert('\', s, q); inc(q); end;
  633.         #128..#255: begin
  634.           insert(#39+HEX(ord(s[q])), s, q+1);
  635.           s[q] := '\';
  636.           Inc(q,3);
  637.         end; (* case #128..#255 *)
  638.       end; (* case s[q] of *)
  639.       Inc(q);
  640.     end;
  641.  
  642.     end;
  643.  
  644.  
  645.  
  646.   Procedure OutLN(VAR F: Text; S : String);
  647.     begin
  648.       writeln(F, '\par ', S);
  649.     end;
  650.  
  651.  
  652.   Procedure Intro;
  653.     begin
  654.       wl(#10'Interrupt List-WinHelp preprocessor '+progname+' version '+progvers);
  655.       wl(copyright);
  656.       wl(e_mail+#13#10);
  657.       wl('Use "'+progname+' ?" for help.'#13#10);
  658.     end;
  659.  
  660.   Procedure Explain;
  661.     begin
  662.       wl('This program converts the Interrupt List written by Ralf Brown to a RTF-Format');
  663.       wl('that is used as an input format by the Microsoft WinHelp compiler.'#10);
  664.  
  665.       wl('In order to generate a Windows 3.1 helpfile you need the WinHelp compiler');
  666.       wl('"HC31.EXE", which is distributed with almost all Windows compilers and which');
  667.       wl('is also available on many Internet sites and FIDO BBS systems.'#10);
  668.  
  669.       wl('Please note that you also need a fast computer and a *lot* of free space on');
  670.       wl('your harddrive (18 MB at least). If you want to find out whether you are able');
  671.       wl('to compile a RTF file, I recomend to put only a few source files (e.g. only');
  672.       wl('"INTERRUP.A") in the source directory.'#10);
  673.  
  674.       wl('After this program finishes, you have to invoke the WinHelp compiler with');
  675.       writeln('the command "HC31 ',hfName,'.HPJ".'#10);
  676.  
  677.       wl('For more information about '+progName+' program options and configuration file,');
  678.       wl('read the I2W-OPT.TXT and I2W-CFG.TXT files.'#10);
  679.  
  680.       wl('Have fun ! --CMP'#10);
  681.  
  682.       wl('P.S. If you have problems building the helpfile or if you simply want to write');
  683.       wl('     an e-mail to me, please write to:');
  684.       wl('     '+e_mail+#13#10);
  685.       halt(0);
  686.     end;
  687.  
  688.