home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / dos / tools / inter47 / int2whlp / int2whlp.inc < prev    next >
Text File  |  1995-05-29  |  36KB  |  919 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.15 *)
  9.  
  10. const
  11.   tableArraySize = 250; (* elements in table arrays *)
  12.  
  13. type
  14.   stringPtr = ^string;
  15.   categoryStringPtrArr = array['!'..#126] of stringPtr;
  16.   titleStringPtrArr = array[byte] of stringPtr;
  17.   stringListPtr = ^stringList;
  18.   stringList = record next: stringListPtr; s: string; end;
  19.     (* NB! The program relies on "next" being the first field *)
  20.   stringListPtrPtr = ^stringListPtr;
  21.   aliasStringType = string[119];
  22.   tableArray = array[1..tableArraySize] of integer;
  23.  
  24. var
  25.   flagStrings,categoryStrings,categoryKeyStrings: categoryStringPtrArr;
  26.   INTtitles: titleStringPtrArr;
  27.  
  28.   CONST InPath  : dirStr = '';
  29.     OutPath : dirStr = '';
  30.     TopicNo : Word = 0;
  31.     LastSection : String[3] = '';    { stores number of last processed int }
  32.     IntTopicStr : String[7] = '';    { stores handle to page with subfunctions of the int's}
  33.     filterFileName: pathStr = '';
  34.     filtered: boolean = false;
  35.     compression: string[19] = 'NO';
  36.     emptyString: string[1] = '';
  37.     noteString: string[5] = 'note';
  38.     noneString: string[7] = '(none)';
  39.     buildExpr: string = '';
  40.     secReg: string[9] = ' '; (* secReg[1] = ' ' *)
  41.     equStr: string[7] = ' Ax = ';
  42.     equStr2: string[3] = ' = ';
  43.     equBlanks: byte = 2;
  44.       (* These two variables can be changed to ' Ax=' and 0 by
  45.          program parameter -Q-. They control the format of search
  46.          strings as "INT nn AX = ahal" or "INT nn AX=ahal".
  47.          equStr[3] is assigned 'L', 'H', or 'X' by the program.
  48.       *)
  49.     tables: boolean = true; (* enables table cross referencing *)
  50.     backRef: boolean = false; (* disables the very first backward xref *)
  51.     missingTableCounter: word = 0;
  52.     missingTableLimit = 5; (* wait for user response when reached *)
  53.     indexColumns: integer = 1;
  54.     queuedEntry: string[127] = '';
  55.       (* stores an entry for the index, inserted by a call to insertQueued *)
  56.     notesCount: word = 0;    (* counts "Notes" entries in index *)
  57.     title: string[127] = ''; (* current "Notes" or "INT nn ... " *)
  58.     lastINTno: integer = -1;
  59.     firstAliasP: stringListPtr = NIL; (* aliases to be written to HPJ *)
  60.     nl: string[5] = '\par '; (* global NewLine string for AddTopic *)
  61.     indentIndex: string[7] = '\par   '; (* or '\par ' *)
  62.     insertCounter: integer = 0; (* counts inserted table references *)
  63.     tabTop: integer = 0; (* current top of table array *)
  64.     maxTabTop: integer = 0; (* highest value of currentTabTop *)
  65.     refTop: integer = 0; (* current top of reference array *)
  66.     maxRefTop: integer = 0; (* highest value of currentRefTop *)
  67.     warnings: word = 0; (* counts issued warnings *)
  68.  
  69. const
  70.   (* The following typed constants controls some program behaviors. They
  71.      can all be set under configuration file and program parameter control.
  72.      The configuration section [OPTIONS] uses keys with the same names as
  73.      the typed constants, and the program parameters are listed for each
  74.      constant.
  75.   *)
  76.   singlesInMain: boolean = false;
  77.     (* There are two levels in the Interrupts index: A main index
  78.        with an entry for each interrupt, and a page for each interrupt
  79.        number. If "singlesInMain" is true, the entry in the main index
  80.        refers directly to the interrupt text if there is only one entry
  81.        in the table for that interrupt, if  "singlesInMain" is false, the
  82.        entry in the main index refers to a page with only one field.
  83.        Controlled by program parameter -1.
  84.     *)
  85.   twoIndexes: boolean = true;
  86.     (* If "twoIndexes" is true, the program mantains two indexes,
  87.        "Interrupt Index" with all the topics in the Interrupt List, and
  88.        "Interrupts" as described above. If the flag is false, only the
  89.        latter index is created.
  90.        Controlled by program parameter -2.
  91.     *)
  92.   errorLog: boolean = false;
  93.     (* controles whether HCxx error messages are written to a log file,
  94.        or to the screen only.
  95.        Controlled by program parameter -E.
  96.     *)
  97.   indexHeaders: boolean = true;
  98.     (* controles whether or not a heading "INT nn" is inserted for every
  99.        new interrupt number in the "Interrupt Index". Ignored if
  100.        "twoIndexes" is false.
  101.        Controlled by program parameter -H.
  102.     *)
  103.   markKeys: boolean = true;
  104.     (* If true, keywords (like "See also:", "Notes:") are bolded, if
  105.        false, they are not.
  106.        Controlled by program parameter -M.
  107.     *)
  108.   releaseNo: integer = 41;
  109.     (* This variable can be used to control program behavior and thus
  110.        facilitate compilation of older releases of the Interrupt List.
  111.        Currently it is used to:
  112.        Inhibit table as separate topics and table cross references if
  113.          releaseNo<41.
  114.        Controlled by program parameter -R.
  115.     *)
  116.   scrollIndexTitle: boolean = true;
  117.     (* Windows have a non-scroll area with the window title. Index
  118.        windows have an initial title part describing List release
  119.        number and help file compile date (inserted by specifying
  120.        "specialClassification" in the call to procedure "NewHlpPage").
  121.        If "scrollIndexTitle" is true, only the general part of the
  122.        title is in the non-scroll region, thus opening more space for
  123.        the scrolling part. If the flag is false, the whole title field
  124.        is made non-scrolable.
  125.        Controlled by program parameter -S.
  126.     *)
  127.   tableWindow: boolean = true;
  128.     (* If true, tables activated from a "#nnnn" hotspot appear in a
  129.        secondary window, if fase, in the main window.
  130.        Controlled by program parameter -T.
  131.     *)
  132.   expandedIndex: boolean = true;
  133.     (* controls whether the Interrupt Index initialy pops up in expanded
  134.        or compressed format.
  135.        Controlled by program parameter -X.
  136.     *)
  137.  
  138. (* Help windows topic titles and identifiers: *)
  139.     (* The following text describes windows titles as defined by the "$"
  140.        footnotes and topic identifiers (context strings) as defined by
  141.        the "#" footnotes. The identifiers can be used to open the List
  142.        at a given position by an external call to WINHELP.
  143.  
  144. window title        identifier    text
  145.  
  146. Contents:        CONTENTS    Main index.
  147. Interrupt Index        idIndex        Total list, only if "twoIndexes" is true.
  148. Interrupts            idInterrupts    Main interrupt index.
  149. INT NN List        nn_0        Index for INT NN, nn are two hex digits.
  150. INT NN AHAL - <header>    nn_1        First entry about INT NN, the following
  151.                     entries have consecutive identifiers
  152.                     ... nn_9, nn_10, ... . Aliases for
  153.                     Interrupt List topics can be compiled
  154.                     and written to the Help Project file.
  155.                     These aliases can be used to identify
  156.                     any (unique) topic.
  157. Tables            idTables    Table index.
  158. NN AHAL <table title>    tnnnn        Table No. nnnn, nnnn are the four
  159.                     decimal digits from the List. Aliases
  160.                     can be compiled based on table position
  161.                     and title.
  162.                     NN and AHAL in the title are the
  163.                     interrupt number and the register
  164.                     contents (sub function) where the table
  165.                     is defined.
  166. FILELIST        1        The initial part of the Interrrupt List.
  167. <notes>            n        Other notes have consecutive numbers as
  168.                     identifiers.
  169. INTERRUP.1ST File    id1st        INTERRUP.1ST file window.
  170. none            idPartComp    Partial compilation popup window if
  171.                     parameter -f<name>.
  172. Filter Method        idFlt_meth    Filter Method if parameter -f<name>.
  173. Filter File        idFlt_file    Filter File if parameter -f<name>.
  174. Credits            idCredits    The Credits window.
  175. none        Compressed_Index    This identifier is used as a marker.
  176.  
  177. The identifiers mentioned above are reserved for program use. Titles and
  178. identifiers for other windows are defined in the configuration file.
  179.  
  180. The program maintains 6 browse chains, as defined by the "+" footnotes:
  181.  
  182. The "main" chain:
  183.     m:1    the Credits window.
  184.     m:2    the Contents window.
  185.     m:3    the Interrupt Index window provided "twoIndexes" is true.
  186.     m:4    the Interrupts window.
  187.     m:5    the Tables window provided "releaseNo" >= 41.
  188.     m:9    index windows included as window type 2.
  189.  
  190. The "list" chain:
  191.     l:0    the interrupt list sub index windows.
  192.  
  193. The "interrupt" chain:
  194.     i:0    the interrupt windows.
  195.  
  196. The "file" chain:
  197.     f:0    files included by the program or as window type 1.
  198.  
  199. The "table" chain:
  200.     t:0    the table windows provided "releaseNo" >= 41.
  201.  
  202. The "ports" chain:
  203.     p:0    the sub windows compiled from window type 2 inclusion.
  204.  
  205. Window type 3 inclusions can link onto these chains or maintain their own
  206. chains under user control.
  207.  
  208. *)
  209.  
  210. (* Constants defining windows setup etc.
  211.    All the typed constants can be changed by the configuration file, and
  212.    some of them also by program parameters.
  213. *)
  214.  
  215. (* definitions for the *.HPJ file: *)
  216.     windowsTitle =     '"Ralf Brown''s Interrupt List"';
  217.     secWindowsTitle =  '"Interrupt List Tables"';
  218.     secWindow = 'ITW'; (* the name of the secondary window *)
  219.     mainW: string[5] = '>main'; (* or '' *)
  220.     tableW: string[((length(secWindow)+3) AND $FE) - 1] = '>'+secWindow;
  221.     windowsPosSize: string[21]   =   '';
  222.       (* or: '(xpos,ypos,width,heigth)' *)
  223.     secWindowsPosSize: string[21] =  '(43,0,980,1023)';
  224.       (* values must be defined for a secondary window *)
  225.     windowsMaximized = '0';      (* '0': no; '1': yes (overrides size) *)
  226.     windowsBackgr: string[19]    = ''; (* or: '(red,green,blue)' *)
  227.     windowsHdrBackgr: string[19] = ''; (* or: '(red,green,blue)' *)
  228.  
  229. (* definitions for fonts, attributes, and size: *)
  230.     headerFont: string[31]       = 'roman Times New Roman';
  231.       (* or 'swiss Arial' *)
  232.     textFont: string[31]         = 'modern Courier New';
  233.     deciPoints: word             = 90;
  234.       (* 10 times point size *)
  235.     headerDeciPoints: word       = 140;
  236.     header2ndDeciPoints: word    = 120;
  237.     headerAttrib =     '';       (*
  238.         \b   = bold
  239.         \i   = italics
  240.       *)
  241.     highlightInt =     '';       (* this attribute highlights specificly
  242.                        the "INT nn" part of the header *)
  243.     indent =           '1060';   (* left indent of header after line one *)
  244.       (* (in twips, twentieth of a point, 1/1440 of an inch) *)
  245.     dateSep =  '-';        (* for compile time YYYY-MM-DD string *)
  246.     timeSep =  ':';        (* for compile time H:MM string *)
  247.     (*.$define m_dd_yy *)  (* defines date format, default is yyyy-mm-dd *)
  248.     (*.$define d_mm_yy *)  (* defines date format if m_dd_yy is undefined *)
  249.     (*.$define yy_mm_dd *) (* defines date format to yy-mm-dd instead of
  250.                   yyyy-mm-dd if both m_dd_yy and d_mm_yy
  251.                   are undefined *)
  252.  
  253.   Var
  254.       ProcessTime    : Longint;
  255.       IndexFile      : Text;                    { stores one entry per int-number }
  256.       IntFile        : Text;                    { stores *all* section names }
  257.     { the function of these two files was reversed in version 1.15 }
  258.       SubIntFile     : Text;                    { stores all subfunctions of an int per page }
  259.       TableFile      : Text;                    { stores tables references (index) }
  260.       IntTopics      : Text;
  261.       TabTopics      : Text;
  262.       HPJ            : Text;                    { hlep compiler project file }
  263.       indexHeader    : string;                  { index and subindex header string }
  264.       compilationStr : string[159];             { compilation information }
  265.       TopicStr   : String[15];            { used in CheckKeyWords and ProcessList }
  266.       indexPages,indexRows: integer;
  267.       dateString: string[19];
  268.       fontSize, headerSize, header2ndSize: string[7];
  269.       aliasP,tableAliasP: stringListPtr;
  270.     (* aliases read from configuration file *)
  271.       aliasId,tableAliasId: string[19];
  272.       aliasString,tableAliasString: aliasStringType;
  273.       nextAliasPP: stringListPtrPtr;
  274.     (* stored aliases, to be written to the HPJ file *)
  275.       INTcounts: array[byte] of word;
  276.       currentDir,homeDir: dirStr;
  277.       currentTable: string[5];
  278.       lineCount  : word; (* for error report *)
  279.       tabArray: tableArray; (* tables found in current interrupt *)
  280.       refArray: tableArray; (* tables referenced in current interrupt *)
  281.  
  282.   Const
  283.     (* classification characters < '!' do not insert a classification string as
  284.        a keyword.
  285.     *)
  286.     InvalidClassification = '-'; (* don't insert classification string as keyword *)
  287.     nullClassification = #0;     (* no title as keyword *)
  288.     specialClassification = #1;  (* use indexHeader in header *)
  289.     tableClassification = #2;    (* insert '#' + currentTable as keyword *)
  290.  
  291. function readKeyWd: word;
  292. (* Calls BIOS to read the keyboard, returns scan code in hi and char. in lo *)
  293.   inline($B4/$00/ {mov ah,0}  $CD/$16 {int $16});
  294.  
  295. procedure wl(s: string);
  296. (* a substitute for single-string "writeln" to screen (or "output") (saves
  297.    20 bytes of code per call).
  298. *)
  299.   begin writeln(s) end;
  300.  
  301. procedure errorExit(msg: string; err: byte);
  302. (* prints "msg" to screen and halts with errorlevel "err" *)
  303.   begin wl(msg); halt(err); end;
  304.  
  305. function exist(filename: pathStr): boolean;
  306. (* check the existance of "filename" *)
  307.   var b: boolean; t: text;
  308.   begin
  309. (*$I-*)
  310.     assign(t,filename);
  311.     reset(t);
  312.     b:=IOresult=0;
  313.     if b then close(t);
  314.     exist:=b;
  315. (*$I+*)
  316.   end; (* function exist *)
  317.  
  318. procedure defaultDir(var fileName: pathStr; var default: dirStr);
  319. (* if fileName has no drive, root, or current specification, then insert the
  320.    default directory.
  321. *)
  322.   begin
  323.     if (fileName[2]<>':') AND (fileName[1]<>'\') AND (fileName[1]<>'.') then
  324.       insert(default,filename,1);
  325.     fileName:=fExpand(fileName);
  326.   end; (* procedure defaultDir *)
  327.  
  328. (* Some of the following procedures are Windows getPrivateProfileXxx-like
  329.    routines to search the configuration file. If INT2WHLP.CFG is not found
  330.    in the current directory or in INT2WHLP.EXE's home directory, or if
  331.    the section or entry is not found in the file, the "value" parameter is
  332.    unchanged, otherwise the section/entry value is assigned to "value". A
  333.    boolean value is considered false if it is 0, and true otherwise.
  334. *)
  335.  
  336. function findProfile(var configFile: text; var section: dirStr): boolean;
  337. (* opens INT2WHLP.CFG on configFile and reads up to the specified section.
  338.    findProfile returns true if the configuration file was located, false
  339.    otherwise. If eof(configFile) returns true after a successful call
  340.    to findProfile this indicates that the section was not found, or it was
  341.    empty and last.
  342. *)
  343.   var i,l: integer; s: string;
  344.   begin
  345. (*$I-*)
  346.     findProfile:=false; (* suggest configuration file absent *)
  347.     if exist(progName+'.CFG') then assign(configFile,progName+'.CFG')
  348.     else assign(configFile,homeDir+progName+'.CFG');
  349.     reset(configFile);
  350.     if IOresult<>0 then exit;
  351.     findProfile:=true;
  352.     i:=1;
  353.     l:=length(section);
  354.     if l=0 then exit; (* we will interpret section='' as "open only" *)
  355.     while (i<=l) AND NOT eof(configFile) do begin
  356.       readln(configFile,s);
  357.       i:=1;
  358.       if (length(s)>=l+2) AND (s[1]='[') AND (s[l+2]=']') then
  359.     while (i<=l) AND (upcase(section[i])=upcase(s[succ(i)])) do inc(i);
  360.     end; (* while i<=l ... *)
  361. (*$I+*)
  362.   end; (* procedure findProfile *)
  363.  
  364. procedure profileList(section: dirStr; var listP: stringListPtr);
  365. (* reads all the entries in the specified section to a linked list and
  366.    assigns the beginning of the list to listP. Empty lines and lines
  367.    starting with a semicolon (;) are ignored.
  368. *)
  369.   label done,doneNC;
  370.   var listPP: ^stringListPtr; s: string; configFile: text;
  371.   begin
  372.     listPP:=@listP;
  373.     if NOT findProfile(configFile,section) then goto doneNC;
  374.       (* no configuration file *)
  375.     while NOT eof(configFile) do begin
  376.       readln(configFile,s);
  377.       if (s<>'') AND (s[1]<>';') then begin
  378.     if s[1]='[' then goto done;
  379.     getMem(listPP^,length(s)+1+sizeOf(pointer));
  380.     listPP^^.s:=s;
  381.     listPP:=@listPP^^.next;
  382.       end; (* if (s<>'')... *)
  383.     end; (* while NOT eof() *)
  384.   done:
  385.     close(configFile);
  386.   doneNC:
  387.     listPP^:=NIL;
  388.   end; (* procedure profileList *)
  389.  
  390. procedure freeStringRec(var p: stringListPtr);
  391. (* updates p to point to the next record, and frees the current one *)
  392.   var p1: stringListPtr;
  393.   begin
  394.     if p=NIL then exit;
  395.     p1:=p;
  396.     p:=p1^.next;
  397.     freeMem(p1,length(p1^.s)+1+sizeOf(pointer));
  398.   end; (* procedure freeStringRec *)
  399.  
  400. procedure profileString(section, entry: dirStr; var value: string;
  401.   bufferLen: integer);
  402.   label done;
  403.   var i,l: integer; s: string; configFile: text;
  404.   begin
  405. (*$I-*)
  406.     if (section='') OR (entry='') then exit;
  407.     if NOT findProfile(configFile,section) then exit;
  408.       (* no configuration file *)
  409.     i:=1;
  410.     l:=length(entry);
  411.     while (i<=l) AND NOT eof(configFile) do begin
  412.       readln(configFile,s);
  413.       if (s<>'') AND (s[1]='[') then goto done;
  414.       i:=1;
  415.       if (length(s)>l) AND (s[succ(l)]='=') then
  416.     while (i<=l) AND (upcase(entry[i])=upcase(s[i])) do inc(i);
  417.     end; (* while i<=l ... *)
  418.     if i>l then value:=copy(s,succ(i),bufferLen);
  419.   done:
  420.     close(configFile);
  421. (*$I+*)
  422.   end; (* procedure profileString *)
  423.  
  424. procedure profileInt(section, entry: dirStr; var value: integer);
  425.   var i,j: integer; s: string[19];
  426.   begin
  427.     s:='';
  428.     profileString(section,entry,s,pred(sizeOf(s)));
  429.     if s='' then exit;
  430.     val(s,i,j);
  431.     if j=0 then value:=i;
  432.   end; (* procedure profileInt *)
  433.  
  434. procedure profileBoolean(section, entry: dirStr; var value: boolean);
  435.   var i: integer;
  436.   begin
  437.     i:=ord(value);
  438.     profileInt(section,entry,i);
  439.     value:=i<>0;
  440.   end; (* procedure profileBoolean *)
  441.  
  442. procedure scan(line: string; var spa: categoryStringPtrArr);
  443. (* scans lines with format "xxx a - definition a, A - definition A" and
  444.    allocates memory and stores the definitions at appropriate index in spa.
  445. *)
  446.   var
  447.     p: integer;
  448.     c: char;
  449.     ok: boolean;
  450.   begin
  451.     repeat
  452.       p:=pos(' - ',line);
  453.       if p=0 then exit;
  454.       if p>1 then c:=line[p-1];
  455.       ok:=((p=2) OR ((p>2) AND (line[p-2]<=' '))) AND (c>' ') AND (c<#127);
  456.       delete(line,1,p+2);
  457.       if ok then begin
  458.     p:=pos(' - ',line);
  459.     if p=0 then p:=length(line)+1 else dec(p,2);
  460.     while line[p-1]<=' ' do dec(p);
  461.     if line[p-1]=',' then dec(p);
  462.     getmem(spa[c],p);
  463.     spa[c]^:=copy(line,1,p-1);
  464.     delete(line,1,p);
  465.       end; (* if ok *)
  466.     until false; (* terminated by exit *)
  467.   end; (* procedure scan *)
  468.  
  469. procedure check1st(var s: string);
  470. (* scans s for the occurence of 'INTERRUP.1ST' and inserts xref to id1st.
  471.    Letter case is ignored.
  472. *)
  473.   var p: byte; s1: string[119];
  474.   begin
  475.     s1[0]:=s[0];
  476.     for p:=1 to length(s) do s1[p]:=upcase(s[p]);
  477.     p:=pos('INTERRUP.1ST',s1);
  478.     if p<>0 then begin
  479.       insert('}{\v id1st}',s,p+12);
  480.       insert('{\uldb ',s,p);
  481.     end; (* if p<>0 *)
  482.   end; (* procedure check1st *)
  483.  
  484. procedure getINTtitle(var line: string; var titles: titleStringPtrArr);
  485. (* allocates memory and copies a line starting with "INT nn " to titles[nn]^ *)
  486.   type (* for type casts *)
  487.     lineRec = record l: byte; INT: longint; nn: word; spc: char; end;
  488.     hexRec = record l: byte; dollar: char; nn: word; end;
  489.   const
  490.     intC = ord('I')+ord('N')*$100+ord('T')*$10000+ord(' ')*$1000000;
  491.     intNumber: string[3] = '$nn'; (* preset length to 3 and [1] to '$' *)
  492.   var
  493.     lineR: lineRec absolute line; (* for typecast *)
  494.     intR: hexRec absolute intNumber; (* for typecast *)
  495.     n,j: integer;
  496.   begin
  497.     if (length(line)<8) OR (lineR.spc<>' ') OR (lineR.INT<>intC) then exit;
  498.     intR.nn:=lineR.nn; (* two characters typecasted to a word *)
  499.     val(intNumber,n,j);
  500.     if j<>0 then exit;
  501.     getmem(titles[n],succ(length(line)));
  502.     titles[n]^:=line;
  503.   end; (* procedure getINTtitle *)
  504.  
  505. procedure getNextAlias(var aliasP: stringListPtr;
  506.    var aliasId, aliasString: string);
  507. (* extract an alias string from the heap and free the heap memory *)
  508.   var n: integer;
  509.   begin
  510.     aliasString:='';
  511.     if aliasP=NIL then exit;
  512.     aliasString:=aliasP^.s;
  513.     freeStringRec(aliasP); (* free memory and update aliasP *)
  514.     n:=pos('=',aliasString);
  515.     if n<2 then errorExit('Missing alias Id in '+aliasString,aliasErr);
  516.     if n>pred(sizeOf(aliasId)) then errorExit('Alias Id too long in '
  517.       +aliasString,aliasErr);
  518.     aliasId:=copy(aliasString,1,n);
  519.     delete(aliasString,1,n);
  520.   end; (* procedure getNextAlias *)
  521.  
  522. procedure saveAlias(var aPP: stringListPtrPtr; s: dirStr);
  523. (* allocates memory on the heap, stores information, and updates aPP *)
  524.   begin
  525.     getmem(aPP^,length(s)+1+sizeOf(pointer));
  526.     aPP^^.next:=NIL;
  527.     aPP^^.s:=s;
  528.     aPP:=@aPP^^.next
  529.   end; (* procedure saveAlias *)
  530.  
  531. procedure processAliasList(aP: stringListPtr);
  532.   begin
  533.     while aP<>NIL do begin
  534.       writeln(HPJ,aP^.s);
  535.       aP:=aP^.next;
  536.     end; (* while aP<>NIL *)
  537.   end; (* procedure processAliasList *)
  538.  
  539. procedure setTabs(var f: text; spaces, deciPoints, tabs: word);
  540. (* writes tab settings to file f, tabspacing approximately "spaces" character
  541.    columns width New Courier font with size 1/10*"deciPoints". Number of tab
  542.    settings = "tabs".
  543.    The tabs are valid until the next "\pard".
  544. *)
  545.   var i: integer; s: string[11];
  546.   begin
  547.     for i:=1 to tabs do begin
  548.       str(longint(i*spaces*deciPoints)*1170 DIV 1000,s);
  549.       (* tab spacing = (point size)*(column width)*11.70 *)
  550.     (* at least, this seems to fit pretty well *)
  551.       write(f,'\tx',s);
  552.     end; (* for i:=1 *)
  553.     writeln(f);
  554.   end; (* procedure setTabs *)
  555.  
  556. procedure writeIndex(s: string);
  557.   begin writeln(indexFile, s); end;
  558.  
  559.   procedure CreateHPJ;
  560.     var i,n: integer; bP: stringListPtr; s: dirStr;
  561.     begin
  562.       assign(HPJ, OutPath + hfName+'.HPJ');
  563.       rewrite(HPJ);
  564.       n:=0;
  565.       profileList('BUILDTAGS',bP);
  566.       if bP<>NIL then begin (* write [BuildTags] section *)
  567.     writeln(HPJ,'[BUILDTAGS]');
  568.     while bP<>NIL do begin
  569.       writeln(HPJ,bP^.s);
  570.       freeStringRec(bP); (* free memory and update bP *)
  571.     end; (* while bP<>NIL *)
  572.     writeln(HPJ);
  573.       end; (* if i>0 *)
  574.       profileList('BAGGAGE',bP);
  575.       if bP<>NIL then begin (* write [Baggage] section *)
  576.     writeln(HPJ,'[BAGGAGE]');
  577.     while bP<>NIL do begin
  578.       writeln(HPJ,bP^.s);
  579.       freeStringRec(bP); (* free memory and update bP *)
  580.     end; (* while bP<>NIL *)
  581.     writeln(HPJ);
  582.       end; (* if i>0 *)
  583.       s:=fExpand(OutPath);
  584.       if length(s)>3 then dec(s[0]); (* delete terminating '\' if not root *)
  585.       writeln(HPJ, '[OPTIONS]'#13#10'CONTENTS=CONTENTS'#13#10'COMPRESS=',compression);
  586.       writeln(HPJ,'REPORT=ON'#13#10'WARNING=2'#13#10'ROOT=',s);
  587.     (* warning=2 avoids the "Using old *.ph file" warning *)
  588.       if errorLog then writeln(HPJ,'ERRORLOG='+hfName+'.ERR');
  589.       if buildExpr<>'' then writeln(HPJ,'BUILD=',buildExpr);
  590.       writeln(HPJ, 'CITATION=Copied from Ralf Brown''s Interrupt List');
  591.       writeln(HPJ, 'COPYRIGHT='+hfName+' Layout: Christian Müller-Planitz');
  592.       writeln(HPJ, #13#10'[CONFIG]'#13#10'CreateButton(`id_print'',`&Print'',`Print()'')');
  593.       writeln(HPJ, 'CreateButton(`id_copy'',`C&opy'',`CopyTopic()'')'#13#10'BrowseButtons()');
  594.       writeln(HPJ, 'CreateButton(`id_exit'',`E&xit'',`Exit()'')');
  595.       if twoindexes AND NOT expandedIndex then
  596.     writeln(HPJ, 'SaveMark(`Compressed_Index'')');
  597.       profileList('INTWINCONFIG',bP);
  598.       while bP<>NIL do begin (* copy [INTWINCONFIG] entries *)
  599.     writeln(HPJ,bP^.s);
  600.     freeStringRec(bP); (* free memory and update bP *)
  601.       end; (* while bP<>NIL *)
  602.       writeln(HPJ, #13#10'[WINDOWS]'#13#10'main='+windowsTitle+',',windowsPosSize,
  603.     ','+windowsMaximized+',',windowsBackgr,',',windowsHdrBackgr);
  604.       if tableWindow then writeln(HPJ, secWindow+'='+secWindowsTitle+',',
  605.     secWindowsPosSize,','+windowsMaximized+',',windowsBackgr,',',
  606.     windowsHdrBackgr);
  607.       writeln(HPJ, #13#10'[FILES]');
  608.     end;
  609.  
  610.   Procedure OpenRTF(VAR F: Text; Name: String);
  611.     begin
  612.      {$I-}
  613.       assign(F, OutPath + Name);
  614.       rewrite(F);
  615.      {$I+}
  616.       if IOResult <> 0 then errorExit('Error craeting '+OutPath+Name,rtfErr);
  617.  
  618.       writeln(HPJ, Name);
  619.  
  620.       writeln(F, '{\rtf1\pc \deff1{\fonttbl{\f0\f',headerFont,';}');
  621.       writeln(F, '{\f1\f',textFont,';}}');
  622.       writeln(F, '{\colortbl \red255\green0\blue0;\red0\green0\blue0;');
  623.       writeln(F, '\red0\green0\blue255;\red255\green255\blue255;}');
  624.       writeln(F, '\plain',fontSize,'\pard\keep');
  625.       TextRec(F).UserData[1]:=ord(false); (* mark as unused *)
  626.     end;
  627.  
  628.  
  629.   Procedure CloseRTF(VAR F: Text);
  630.     begin
  631.       writeln(F, '}');
  632.       close(F);
  633.     end;
  634.  
  635.   Procedure PageRTF(VAR F: Text);
  636.     begin
  637.       if boolean(TextRec(F).UserData[1]) then write(F, '\page')
  638.       else TextRec(F).UserData[1]:=ord(true);
  639.     end;
  640.  
  641.   Function HEX(b:byte):string;
  642.     Const h : array [0..15] of char = ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  643.     begin
  644.       Hex[0]:=#2; Hex[1]:=h[b shr 4]; Hex[2]:=h[b and 15];
  645.     end;
  646.  
  647.  
  648.   Procedure ReadLine(VAR F: Text; VAR S: String);
  649.     VAR q: Word;
  650.  
  651.     begin
  652.       readln(F, S);
  653.       q:= 1;
  654.       while q <= Length(s) do    { duplicate all '\' etc. }
  655.     begin
  656.       case s[q] of
  657.         '\', '{', '}': begin insert('\', s, q); inc(q); end;
  658.     (* v. 1.13: DOS framing characters are not transformed properly by
  659.        selecting the "pc" character set. We will transform single and double
  660.        horizontal frames to '-', vertical frames to '|', and all other
  661.        framing characters to '+'. Please note that some codepage 850 extended
  662.        characters are also transformed to '+'.
  663.     *)
  664.         #196, #205: s[q]:='-';
  665.         #179, #186: s[q]:='|';
  666.         #176..#223: s[q]:='+';
  667.         #128..#255: begin
  668.           insert(#39+HEX(ord(s[q])), s, q+1);
  669.           s[q] := '\';
  670.           Inc(q,3);
  671.         end; (* case #128..#255 *)
  672.       end; (* case s[q] of *)
  673.       if q>=255 then begin
  674.         writeln('Too many graphic characters in line ', lineCount);
  675.         ErrorExit('Please edit the file and try again', formatErr);
  676.       end; (* if q>255 *)
  677.       Inc(q);
  678.     end; (* while q>=length(s) *)
  679.  
  680.     end;
  681.  
  682.  
  683.  
  684.   Procedure OutLN(VAR F: Text; S : String);
  685.     begin
  686.       writeln(F, '\par ', S);
  687.     end;
  688.  
  689.  
  690.   Procedure Intro;
  691.     begin
  692.       wl(#10'Interrupt List-WinHelp preprocessor '+progname+' version '+progvers);
  693.       wl(copyright);
  694.       wl(e_mail+#13#10);
  695.       wl('Use "'+progname+' ?" for help.'#13#10);
  696.     end;
  697.  
  698.   Procedure Explain;
  699.     begin
  700.       wl('This program converts the Interrupt List written by Ralf Brown to a RTF-Format');
  701.       wl('that is used as an input format by the Microsoft WinHelp compiler.'#10);
  702.  
  703.       wl('In order to generate a Windows 3.1 helpfile you need the WinHelp compiler');
  704.       wl('"HC31.EXE", which is distributed with almost all Windows compilers and which');
  705.       wl('is also available on many Internet sites and FIDO BBS systems.'#10);
  706.  
  707.       wl('Please note that you also need a fast computer and a *lot* of free space on');
  708.       wl('your harddrive, see the file I2W-HINT.TXT. If you want to find out whether you');
  709.       wl('are able to compile a RTF file, I recommend that you experiment with the files');
  710.       wl('in the I2W-TEST.ZIP subpackage.'#10);
  711.  
  712.       wl('After this program finishes, you have to invoke the WinHelp compiler with');
  713.       writeln('the command "HC31 ',hfName,'.HPJ".'#10);
  714.  
  715.       wl('For more information about '+progName+' program options and configuration file,');
  716.       wl('read the I2W-OPT.TXT and I2W-CFG.TXT files.'#10);
  717.  
  718.       wl('Have fun ! --CMP'#10);
  719.  
  720.       wl('P.S. If you have problems building the helpfile or if you simply want to write');
  721.       wl('     an e-mail to me, please write to:');
  722.       wl('     '+e_mail);
  723.       halt(0);
  724.     end;
  725.  
  726. procedure initializeArrays;
  727.   var i: integer; ch: char;
  728.   begin
  729.     for ch:='!' to #126 do begin (* default to empty string *)
  730.       flagStrings[ch]:=@emptyString;
  731.       categoryStrings[ch]:=@emptyString;
  732.       categoryKeyStrings[ch]:=@emptyString;
  733.     end; (* for ch:='!' *)
  734.     categoryStrings['!']:=@noteString;
  735.     categoryStrings['-']:=@noneString;
  736.     for i:=$00 to $FF do begin INTcounts[i]:=0; INTtitles[i]:=@emptyString; end;
  737.   end; (* procedure initializeArrays *)
  738.  
  739. procedure findDateAndCopyright;
  740.   var a,b,c,d: word; s,ss: string[99]; t: text;
  741.   begin
  742.     getDate(a,b,c,d);
  743.     (*$ifdef m_dd_yy *)
  744.       str(b*1000000+(c*1000+a MOD 100),dateString);
  745.       dateString[length(dateString)-5]:=dateSep;
  746.       dateString[length(dateString)-2]:=dateSep;
  747.     (*$else*)
  748.       (*$ifdef d_mm_yy *)
  749.     str(c*1000000+(b*1000+a MOD 100),dateString);
  750.     dateString[length(dateString)-5]:=dateSep;
  751.     dateString[length(dateString)-2]:=dateSep;
  752.       (*$else*)
  753.     str(a*1000000+(b*1000+c),dateString);
  754.     dateString[5]:=dateSep;
  755.     dateString[8]:=dateSep;
  756.     (*$ifdef yy_mm_dd *) delete(dateString,1,2); (*$endif*)
  757.       (*$endif*)
  758.     (*$endif*)
  759.     getTime(a,b,c,d);
  760.     str((a*1000+b)+100000,s);
  761.     s[4]:=timeSep;
  762.     s[1]:=' ';
  763.     if a<10 then delete(s,2,1);
  764.     dateString:=dateString+' -'+s;
  765.   (*$I-*)
  766.     assign(t,InPath+'interrup.lst');
  767.     reset(t);
  768.     if IOresult<>0 then begin
  769.       assign(t,InPath+'interrup.a');
  770.       reset(t);
  771.       if IOresult<>0 then
  772.     errorExit('Unable to open INTERRUP file in directory '+InPath,fileErr);
  773.     end; (* if IOresult<>0 *)
  774.   (*$I+*)
  775.     ReadLine(t,s);
  776.     ReadLine(t,ss);
  777.     close(t);
  778.     for a:=1 to 2 do begin
  779.       b:=pos(#9,s); (* remove two wide areas of whitespace *)
  780.       if b<>0 then while s[b]=#9 do delete(s,b,1)
  781.       else begin
  782.     b:=pos('        ',s);
  783.     if b<>0 then while s[b]=' ' do delete(s,b,1)
  784.       end; (* else *)
  785.       if b<>0 then insert('      ',s,b); (* insert 6 spaces instead *)
  786.     end; (* for a:=1 *)
  787.     indexHeader:='{\keep '+s+#13#10'\par{'+header2ndSize+' '+ss+'}'#13#10'\par';
  788.     if scrollIndexTitle then indexHeader:=indexHeader+'\pard';
  789.     indexHeader:=indexHeader+#13#10'\par}';
  790.     compilationStr:=progName+' v. '+progVers+' compilation.'#13#10'\par '
  791.       +hfName+'.HLP compiled '+dateString+'.';
  792.     if filtered then compilationStr:=compilationStr
  793.       +' {\ul Partial compilation.}{\v idPartComp}';
  794.   end; (* procedure findDateAndCopyright *)
  795.  
  796. procedure interpretParameters;
  797. (* interprets program parameters and parts of the configuration file *)
  798.   var i,argVal: integer; s: string[79]; blanks: boolean;
  799.   procedure copyParam(var dest: string; len: byte);
  800.     begin dest:=copy(s,3+ord(s[3]=':'),len); end;
  801.   procedure getArgVal;
  802.     (* assigns value of argument, or $8000, to argVal *)
  803.     var i: integer; st: string[9];
  804.     begin
  805.       copyParam(st,9);
  806.       val(st,argVal,i);
  807.       if i<>0 then argVal:=integer($8000);
  808.     end; (* procedure getArgVal in interpretParameters *)
  809.   function getBool: boolean;
  810.     begin getBool:=(length(s)<3) OR (s[3]<>'-'); end;
  811.   procedure setSize(var fs: string; dp: word);
  812.     (* converts decipoints to an RTF halfpoint font size string *)
  813.     begin
  814.       str(dp DIV 5,fs);
  815.       insert('\fs',fs,1);
  816.     end; (* procedure setSize in interpretParameters *)
  817.  
  818.   begin
  819.     blanks:=true;
  820.     (* first, check configuration file *)
  821.     profileString('OPTIONS','build',buildExpr,pred(sizeOf(buildExpr)));
  822.     profileString('OPTIONS','compression',compression,pred(sizeOf(compression)));
  823.     profileString('OPTIONS','filterFile',filterFileName,pred(sizeOf(filterFileName)));
  824.     profileBoolean('OPTIONS','singlesInMain',singlesInMain);
  825.     profileBoolean('OPTIONS','twoIndexes',twoIndexes);
  826.     profileBoolean('OPTIONS','errorLog',errorLog);
  827.     profileBoolean('OPTIONS','indexHeaders',indexHeaders);
  828.     profileInt('OPTIONS','indexColumns',indexColumns);
  829.     profileBoolean('OPTIONS','markKeys',markKeys);
  830.     profileBoolean('OPTIONS','equalBlanks',blanks);
  831.     profileInt('OPTIONS','releaseNo',releaseNo);
  832.     profileBoolean('OPTIONS','scrollIndexTitle',scrollIndexTitle);
  833.     profileBoolean('OPTIONS','tableWindow',tableWindow);
  834.     profileBoolean('OPTIONS','expandedIndex',expandedIndex);
  835.     (* second, check parameters *)
  836.     for i:=1 to paramCount do begin
  837.       s:=paramStr(i);
  838.       case s[1] of
  839.     '/','-': begin
  840.       if length(s)=1 then errorExit(
  841.         'Missing option after "'+s+'"',paramErr);
  842.       case upcase(s[2]) of
  843.         'B': copyParam(buildExpr,pred(sizeOf(buildExpr)));
  844.         (* legal: any .HPJ [OPTIONS] build= expression *)
  845.         'C': begin
  846.           copyParam(compression,pred(sizeOf(compression)));
  847.         (* legal: 0, 1, no, yes, low, medium, high. Not checked *)
  848.           if compression='' then compression:='YES';
  849.         (* default if "-c" or "-c:" is specified *)
  850.         end; (* case 'C' *)
  851.         'F': begin
  852.           copyParam(filterFileName,pred(sizeOf(filterFileName)));
  853.           if filterFileName='' then errorExit(
  854.         'No filter file name specified after "'+s+'"',fileErr);
  855.           filtered:=true;
  856.         end; (* case 'F' *)
  857.         '1': singlesInMain:=getBool;
  858.         '2': twoIndexes:=getBool;
  859.         'E': errorLog:=getBool;
  860.         'H': indexHeaders:=getBool;
  861.         'I': begin getArgVal; indexColumns:=argVal; end;
  862.         'M': markKeys:=getBool;
  863.         'Q': blanks:=getBool;
  864.         'R': begin getArgVal; releaseNo:=argVal; end;
  865.         'S': scrollIndexTitle:=getBool;
  866.         'T': tableWindow:=getBool;
  867.         'X': expandedIndex:=getBool;
  868.         else errorExit('Unknown option: '+s,paramErr);
  869.       end; (* case upcase(s[2] of *)
  870.     end; (* case '/','-' *)
  871.     else begin
  872.       if InPath='' then InPath:=s
  873.       else if OutPath='' then OutPath:=s
  874.       else errorExit('Too many parameters: '+s,paramErr);
  875.     end; (* case else *)
  876.       end; (* case s[1] of *)
  877.     end; (* for i:=1 *)
  878.     (* if file paths were not program parameters, try configuration file *)
  879.     if InPath='' then profileString('FILES','InPath',InPath,pred(sizeOf(InPath)));
  880.     if OutPath='' then profileString('FILES','OutPath',OutPath,pred(sizeOf(OutPath)));
  881.     (* read windows settings from configuration file *)
  882.     profileString('CONFIG','pos and size',windowsPosSize,pred(sizeOf(windowsPosSize)));
  883.     profileString('CONFIG','secondary pos and size',
  884.       secWindowsPosSize,pred(sizeOf(secWindowsPosSize)));
  885.     profileString('CONFIG','background',windowsBackgr,pred(sizeOf(windowsBackgr)));
  886.     profileString('CONFIG','header background',windowsHdrBackgr,pred(sizeOf(windowsHdrBackgr)));
  887.     profileString('CONFIG','header font',headerFont,pred(sizeOf(headerFont)));
  888.     profileString('CONFIG','text font',textFont,pred(sizeOf(textFont)));
  889.     profileInt('CONFIG','deciPoints',integer(deciPoints));
  890.     profileInt('CONFIG','header deciPoints',integer(headerDeciPoints));
  891.     profileInt('CONFIG','header 2nd deciPoints',integer(header2ndDeciPoints));
  892.     (* update other values *)
  893.     indexRows:=16; (* in most cases *)
  894.     indexPages:=1; (* in two cases *)
  895.     case indexColumns of
  896.       1: indexRows:=256;
  897.       4: indexPages:=4;
  898.       8: indexPages:=2;
  899.       16: ; (* already ok *)
  900.       else errorExit('Illegal index columns, only 1, 4, 8, or 16 accepted',
  901.     paramErr);
  902.     end; (* case indexColumns of *)
  903.     if NOT blanks then begin
  904.       equStr[4]:='=';
  905.       equStr[0]:=#4; (* equStr = ' Ax=' *)
  906.       equStr2[1]:='=';
  907.       equStr2[0]:=#1; (* equStr2 = '=' *)
  908.       equBlanks:=0;
  909.     end; (* if NOT blanks *)
  910.     setSize(fontSize,deciPoints);
  911.     setSize(headerSize,headerDeciPoints);
  912.     setSize(header2ndSize,header2ndDeciPoints);
  913.     filtered:=filterFileName<>'';
  914.     if NOT indexHeaders then indentIndex:=nl;
  915.     if releaseNo<41 then begin tables:=false; tableWindow:=false; end;
  916.     if NOT tableWindow then begin mainW:=''; tableW:=''; end;
  917.   end; (* procedure interpretParameters *)
  918.  
  919.