home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / nicol / sti_help / makehelp.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-07-28  |  19.6 KB  |  596 lines

  1. program makehelp;
  2. {$I-}
  3. uses
  4.   STI_STRN;
  5.  
  6. Const
  7.   DEBUG_GETSYM            = FALSE;
  8.  
  9.   MAXHELPITEMS            = 1024;
  10.   MAXREFS                 = 128;
  11.  
  12.   HIGHLIGHTSYM            = '$';
  13.   ESCAPECHAR              = '\';
  14.   NEWPAGEVAL              = 0;
  15.   HBEGIN                  = 1;
  16.   HEND                    = 2;
  17.  
  18.  
  19.   EOFSYM                  = 0;
  20.   TITLE                   = 1;
  21.   VERSION                 = 2;
  22.   SIZE                    = 3;
  23.   TEXTCOLOR               = 4;
  24.   FRAMECOLOR              = 5;
  25.   HIGHLIGHTCOLOR          = 6;
  26.   TITLECOLOR              = 7;
  27.   CASESENSE               = 8;
  28.   ENCRYPT                 = 9;
  29.   FRAMETYPE               = 10;
  30.   HELPITEM                = 11;
  31.   TEXT                    = 12;
  32.   NEWPAGE                 = 13;
  33.   ENDTEXT                 = 14;
  34.   REFER                   = 15;
  35.   ENDHELPITEM             = 16;
  36.   ENDSYM                  = 17;
  37.   BLACK                   = 18;
  38.   BLUE                    = 19;
  39.   RED                     = 20;
  40.   GREEN                   = 21;
  41.   CYAN                    = 22;
  42.   YELLOW                  = 23;
  43.   MAGENTA                 = 24;
  44.   WHITE                   = 25;
  45.   BLACKREVERSE            = 26;
  46.   BLUEREVERSE             = 27;
  47.   REDREVERSE              = 28;
  48.   GREENREVERSE            = 29;
  49.   CYANREVERSE             = 30;
  50.   YELLOWREVERSE           = 31;
  51.   MAGENTAREVERSE          = 32;
  52.   WHITEREVERSE            = 33;
  53.   NOBORDER                = 34;
  54.   SPACES                  = 35;
  55.   SINGLELINE              = 36;
  56.   ROUNDCORNERSINGLE       = 37;
  57.   BIGBLOCK                = 38;
  58.   THICKTOPTHINSIDES       = 39;
  59.   THICKDIAGONALCORNER     = 40;
  60.  
  61. Type
  62.   HelpIdent = record
  63.                 Name  : string[32];
  64.                 Value : word;
  65.               end;
  66.   HeadType  = record
  67.                 Name      : string;
  68.                 VMin      : byte;
  69.                 VMax      : byte;
  70.                 X1,X2     : byte;
  71.                 Y1,Y2     : byte;
  72.                 TextCol   : byte;
  73.                 FrameCol  : byte;
  74.                 HighCol   : byte;
  75.                 TitleCol  : byte;
  76.                 CaseSense : byte;
  77.                 FrameType : byte;
  78.                 Encrypt   : byte;
  79.                 MaxRefI   : word;
  80.                 NoRefs    : word;
  81.               end;
  82.   HelpItemT = record
  83.                 HelpID    : word;
  84.                 TextLen   : word;
  85.                 Refs      : array[1..MAXREFS] of word;
  86.               end;
  87.  
  88.  
  89. Var
  90.   InFile       : file of char;
  91.   Inch         : char;
  92.   OutFile      : file;
  93.  
  94.   HelpIDTable  : array[1..MAXHELPITEMS] of ^HelpIdent;
  95.   NumHelpItems : word;
  96.   Header       : HeadType;
  97.   HelpItemBuff : HelpItemT;
  98.  
  99. {---------------------------------------------------------------------------}
  100.  
  101. procedure Abort(S : string);                {mama I'm dying....             }
  102.  
  103. begin
  104.   writeln;                                  {whack in a return              }
  105.   writeln;                                  {and another                    }
  106.   writeln(S);                               {write the message              }
  107.   close(Infile);                            {close the input                }
  108.   Halt;                                     {then die gracefully            }
  109. end;
  110.  
  111. {---------------------------------------------------------------------------}
  112.  
  113. function GetToken : string;                 {return a token to the caller   }
  114.  
  115. label
  116.   jump;
  117.  
  118. var
  119.   temp : string;                            {temporary string buffer        }
  120.  
  121. begin
  122.   Inch := #0;                               {null input character           }
  123.   temp := '';                               {null temp                      }
  124.  
  125. jump:
  126.   while (Inch < #33) and not(eof(Infile))do {skip white spaces              }
  127.     begin
  128.       read(Infile,Inch);                    {continue reading characters    }
  129.     end;
  130.  
  131.   if Inch = ';' then
  132.     begin
  133.       while(Inch <> #10) do
  134.         read(InFile,Inch);
  135.       goto jump;
  136.     end;
  137.   temp := temp+Inch;                        {build up buffer                }
  138.   if eof(InFile) then temp := 'EOF ';       {end of file command            }
  139.   while (Inch > #33) and not(eof(Infile)) and (Inch <> '"') do
  140.     begin
  141.       read(Infile,Inch);                    {get next character             }
  142.       if Inch = '"' then                    {this is a text area            }
  143.     begin
  144.       while Inch <> '"' do              {loop until the next match      }
  145.         begin
  146.           read(Infile,Inch );           {get a character                }
  147.           temp := temp+Inch;            {add it to temp verbatim        }
  148.         end;
  149.         Seek(InFile,FilePos(InFile)-1); {skip back one char             }
  150.     end else
  151.       if Inch <> '$' then               {this is a highlught character  }
  152.           temp := temp+Inch;            {this is temp                   }
  153.   end;
  154.   if DEBUG_GETSYM then
  155.     writeln('Symbol = ',temp);
  156.   gettoken := copy(temp,1,length(temp)-1);  {return the token               }
  157. end;
  158.  
  159. {---------------------------------------------------------------------------}
  160.  
  161. function GetKeyword : byte;                 {return the command type        }
  162.  
  163. var
  164.    temp  : byte;                            {temporary storage for type     }
  165.    token : string;                          {this is the token to match     }
  166.  
  167. begin
  168.   temp  := 255;                             {this is the error code         }
  169.   token := GetToken;                        {get a token                    }
  170.   if token = 'EOF'                 then temp := 0   else
  171.   if token = '%TITLE'              then temp := 1   else
  172.   if token = '%VERSION'            then temp := 2   else
  173.   if token = '%SIZE'               then temp := 3   else
  174.   if token = '%TEXTCOLOR'          then temp := 4   else
  175.   if token = '%FRAMECOLOR'         then temp := 5   else
  176.   if token = '%HIGHLIGHTCOLOR'     then temp := 6   else
  177.   if token = '%TITLECOLOR'         then temp := 7   else
  178.   if token = '%CASESENSE'          then temp := 8   else
  179.   if token = '%ENCRYPT'            then temp := 9   else
  180.   if token = '%FRAMETYPE'          then temp := 10  else
  181.   if token = '%HELPITEM'           then temp := 11  else
  182.   if token = '%TEXT'               then temp := 12  else
  183.   if token = '%NEWPAGE'            then temp := 13  else
  184.   if token = '%ENDTEXT'            then temp := 14  else
  185.   if token = '%REFER'              then temp := 15  else
  186.   if token = '%ENDHELPITEM'        then temp := 16  else
  187.   if token = '%END'                then temp := 17  else
  188.   if token = 'BLACK'               then temp := 18  else
  189.   if token = 'BLUE'                then temp := 19  else
  190.   if token = 'RED'                 then temp := 20  else
  191.   if token = 'GREEN'               then temp := 21  else
  192.   if token = 'CYAN'                then temp := 22  else
  193.   if token = 'YELLOW'              then temp := 23  else
  194.   if token = 'MAGENTA'             then temp := 24  else
  195.   if token = 'WHITE'               then temp := 25  else
  196.   if token = 'BLACKREVERSE'        then temp := 26  else
  197.   if token = 'BLUEREVERSE'         then temp := 27  else
  198.   if token = 'REDREVERSE'          then temp := 28  else
  199.   if token = 'GREENREVERSE'        then temp := 29  else
  200.   if token = 'CYANREVERSE'         then temp := 30  else
  201.   if token = 'YELLOWREVERSE'       then temp := 31  else
  202.   if token = 'MAGENTAREVERSE'      then temp := 32  else
  203.   if token = 'WHITEREVERSE'        then temp := 33  else
  204.   if token = 'NOBORDER'            then temp := 34  else
  205.   if token = 'SPACES'              then temp := 35  else
  206.   if token = 'SINGLELINE'          then temp := 36  else
  207.   if token = 'ROUNDCORNERSINGLE'   then temp := 37  else
  208.   if token = 'BIGBLOCK'            then temp := 38  else
  209.   if token = 'THICKTOPTHINSIDES'   then temp := 39  else
  210.   if token = 'THICKDIAGONALCORNER' then temp := 40;
  211.   GetKeyword := temp;                       {return the token type 255 = err}
  212. end;
  213.  
  214. {---------------------------------------------------------------------------}
  215.  
  216. procedure Usage;
  217.  
  218. begin
  219.   writeln('USAGE : makehelp infile outfile');
  220.   halt;
  221. end;
  222.  
  223. {---------------------------------------------------------------------------}
  224.  
  225. procedure SetFiles;
  226.  
  227. begin
  228.   if paramcount < 2 then
  229.     Usage;
  230.   assign(InFile,ParamStr(1));
  231.   reset(InFile);
  232.   if IOResult <> 0 then
  233.     begin
  234.       writeln('Could not find '+ParamStr(1));
  235.       halt;
  236.     end;
  237.   assign(OutFile,ParamStr(2));
  238.   rewrite(OutFile,1);
  239.   if IOResult <> 0 then
  240.     begin
  241.       writeln('Could not create '+ParamStr(2));
  242.       halt;
  243.     end;
  244. end;
  245.  
  246. {---------------------------------------------------------------------------}
  247.  
  248. procedure Message;
  249.  
  250. begin
  251.   writeln('                       STI_HELP Version 2.0');
  252.   writeln('    Copyright (C) 1991,1992 By Software Technology International');
  253.   writeln;
  254. end;
  255.  
  256. {---------------------------------------------------------------------------}
  257.  
  258. procedure AddHelpID(HID : HelpIdent);
  259.  
  260. Var
  261.   Loop : word;
  262.  
  263. begin
  264.   for Loop := 1 to NumHelpItems do
  265.     begin
  266.       if HelpIDTable[Loop]^.Name = HID.Name then
  267.         Exit;
  268.     end;
  269.   inc(NumHelpItems);
  270.   if NumHelpItems > MAXHELPITEMS then
  271.     begin
  272.       writeln('Help Identifier Table Overflow.');
  273.       halt;
  274.     end;
  275.   new(HelpIDTable[NumHelpItems]);
  276.   HelpIDTable[NumHelpItems]^ := HID;
  277. end;
  278.  
  279. {---------------------------------------------------------------------------}
  280.  
  281. procedure Init;
  282.  
  283. Var
  284.   Loop : word;
  285.  
  286. begin
  287.   NumHelpItems := 0;
  288.   for Loop := 1 to MAXHELPITEMS do
  289.     HelpIDTable[Loop] := NIL;
  290.   FillChar(Header,sizeof(Header),#0);
  291.   Header.MaxRefI := MAXREFS;
  292. end;
  293.  
  294. {---------------------------------------------------------------------------}
  295.  
  296. procedure GetVal(S1,S2 : string; Var Variable; dtype : byte);
  297.  
  298. var
  299.   check : integer;
  300.   wval  : word absolute Variable;
  301.   bval  : byte absolute Variable;
  302.  
  303. begin
  304.   case dtype of
  305.      1 : Val(S2,wval,check);
  306.      2 : Val(S2,bval,check);
  307.   end;
  308.   if Check <> 0 then
  309.     begin
  310.       writeln;
  311.       writeln('Illegal format for ',S1);
  312.     end;
  313. end;
  314.  
  315. {---------------------------------------------------------------------------}
  316.  
  317. procedure AssignColor(S1 : string; Var Dest : byte; From : Byte);
  318.  
  319. begin
  320.   Dest := From;
  321.   if not(From in[18..33]) then
  322.     begin
  323.       writeln;
  324.       writeln('Illegal color for ',S1);
  325.     end;
  326. end;
  327.  
  328. {---------------------------------------------------------------------------}
  329.  
  330. procedure AssignFrame(S1 : string; Var Dest : byte; From : Byte);
  331.  
  332. begin
  333.   Dest := From;
  334.   if not(From in[34..40]) then
  335.     begin
  336.       writeln;
  337.       writeln('Illegal frame type for ',S1);
  338.     end;
  339. end;
  340.  
  341. {---------------------------------------------------------------------------}
  342.  
  343. function GetOnOff : byte;
  344.  
  345. Var
  346.   Dummy : string;
  347.   Temp  : byte;
  348.  
  349. begin
  350.   Dummy := GetToken;
  351.   Temp  := 1;
  352.   if Dummy = 'OFF' then
  353.     Temp := 0
  354.   else
  355.     if Dummy <> 'ON' then
  356.       begin
  357.         writeln;
  358.         writeln('Illegal switch in CASESENSE or ENCRYPT.');
  359.       end;
  360.   GetOnOff := Temp;
  361. end;
  362.  
  363. {---------------------------------------------------------------------------}
  364.  
  365. procedure Pass1;
  366.  
  367. Var
  368.   Keyword : byte;
  369.   Sense   : boolean;
  370.   HelpIDC : word;
  371.   HelpID  : HelpIdent;
  372.  
  373. begin
  374.   HelpIDC := 0;
  375.   Sense   := FALSE;
  376.   while not(eof(InFile)) do
  377.     begin
  378.       KeyWord := GetKeyWord;
  379.       if Keyword = CASESENSE then
  380.         begin
  381.           if GetToken = 'TRUE' then
  382.             Sense := TRUE
  383.           else
  384.             Sense := FALSE;
  385.         end;
  386.       if Keyword = HELPITEM then
  387.         begin
  388.           inc(HelpIDC);
  389.           HelpID.Name  := GetToken;
  390.           HelpID.Value := HelpIDC;
  391.           if not(Sense) then
  392.             HelpID.Name := UpCaseStr(HelpID.Name);
  393.           write(#13);
  394.           write(MakeStr(79,32));
  395.           write(#13);
  396.           write('Pass #1 : Processing ',HelpID.Name,#13);
  397.           AddHelpID(HelpID);
  398.         end;
  399.     end;
  400.   writeln;
  401. end;
  402.  
  403. {---------------------------------------------------------------------------}
  404.  
  405. function FindRef(Tok : string) : word;
  406.  
  407. Var
  408.   Loop : word;
  409.  
  410. begin
  411.   for Loop := 1 to NumHelpItems do
  412.     begin
  413.       if HelpIDTable[Loop]^.Name = Tok then
  414.         begin
  415.           FindRef := HelpIDTable[Loop]^.Value;
  416.           Exit;
  417.         end;
  418.     end;
  419.   writeln('Reference ',Tok,' not found.');
  420.   FindRef := 1;
  421. end;
  422.  
  423. {---------------------------------------------------------------------------}
  424.  
  425. procedure Pass2;
  426.  
  427. var
  428.   HeaderOut : boolean;
  429.   Command   : byte;
  430.   Inch2     : char;
  431.   Check     : integer;
  432.   Loop      : word;
  433.   DummyJMP  : longint;
  434.   PSave1,
  435.   PSave2    : longint;
  436.   RefNum    : word;
  437.   toggle    : boolean;
  438.   CharCount : word;
  439.  
  440. begin
  441.   toggle        := FALSE;
  442.   DummyJMP      := 0;
  443.   HeaderOut     := TRUE;
  444.   Header.NoRefs := NumHelpItems;
  445.   Command       := 255;
  446.   Seek(Infile,0);
  447.   while Command <> EOFSYM do
  448.     begin
  449.       Command := GetKeyword;
  450.       write('Pass #2 : Command = ',Command:4,#13);
  451.       case Command of
  452.         TITLE       : begin
  453.                         Inch2 := #0;
  454.                         while (Inch2 <> '"') do
  455.                           Read(InFile,Inch2);
  456.                         Read(InFile,Inch2);
  457.                         repeat
  458.                           begin
  459.                             Header.Name := Header.Name + Inch2;
  460.                             Read(InFile,Inch2);
  461.                           end;
  462.                         until Inch2 = '"';
  463.                       end;
  464.         VERSION     : begin
  465.                         GetVal('Version MAX',GetToken,Header.VMax,2);
  466.                         GetVal('Version MIN',GetToken,Header.VMin,2);
  467.                       end;
  468.         SIZE        : begin
  469.                         GetVal('Size X1',GetToken,Header.X1,2);
  470.                         GetVal('Size Y1',GetToken,Header.Y1,2);
  471.                         GetVal('Size X2',GetToken,Header.X2,2);
  472.                         GetVal('Size Y2',GetToken,Header.Y2,2);
  473.                       end;
  474.         TEXTCOLOR   : begin
  475.                         Command := GetKeyword;
  476.                         AssignColor('TEXTCOLOR',Header.TextCol,Command);
  477.                       end;
  478.         FRAMECOLOR  : begin
  479.                         Command := GetKeyword;
  480.                         AssignColor('FRAMECOLOR',Header.FrameCol,Command);
  481.                       end;
  482.         HIGHLIGHTCOLOR : begin
  483.                         Command := GetKeyword;
  484.                         AssignColor('HIGHLIGHTCOLOR',Header.HighCol,Command);
  485.                       end;
  486.         TITLECOLOR  : begin
  487.                         Command := GetKeyword;
  488.                         AssignColor('TITLECOLOR',Header.TitleCol,Command);
  489.                       end;
  490.         FRAMETYPE   : begin
  491.                         Command := GetKeyword;
  492.                         AssignFrame('FRAMETYPE',Header.FrameType,Command);
  493.                       end;
  494.         CASESENSE   : begin
  495.                         Header.CaseSense := GetOnOff;
  496.                       end;
  497.         ENCRYPT     : begin
  498.                         Header.Encrypt   := GetOnOff;
  499.                       end;
  500.         HELPITEM    : begin
  501.                         if HeaderOut then
  502.                           begin
  503.                             Seek(OutFile,0);
  504.                             blockwrite(OutFile,Header,sizeof(Header));
  505.                             for Loop := 1 to Header.NoRefs do
  506.                               begin
  507.                                 blockwrite(OutFile,DummyJMP,sizeof(DummyJMP));
  508.                               end;
  509.                             HeaderOut := False;
  510.                           end;
  511.                         CharCount := 0;
  512.                         RefNum := 0;
  513.                         FillChar(HelpItemBuff,sizeof(HelpItemBuff),#0);
  514.                         PSave1 := FilePos(OutFile);
  515.                         HelpItemBuff.HelpID := FindRef(GetToken);
  516.                         blockwrite(outFile,HelpItemBuff,sizeof(HelpItemBuff));
  517.                         Command := GetKeyWord;
  518.                         while Command <> ENDHELPITEM do
  519.                           begin
  520.                             case Command of
  521.                                REFER   : begin
  522.                                            inc(RefNum);
  523.                                            HelpItemBuff.Refs[RefNum] := FindRef(GetToken);
  524.                                          end;
  525.                                NEWPAGE : begin
  526.                                            Inch2 := char(NEWPAGEVAL);
  527.                                            blockwrite(OutFile,Inch2,sizeof(Inch2));
  528.                                            inc(CharCount);
  529.                                          end;
  530.                                ENDTEXT : begin
  531.                                          end;
  532.                                TEXT    : begin
  533.                                            Inch2 := #0;
  534.                                            while (Inch2 <> '"') do
  535.                                              Read(InFile,Inch2);
  536.                                            Read(InFile,Inch2);
  537.                                            inc(CharCount);
  538.                                            repeat
  539.                                              begin
  540.                                                if Inch2 = HIGHLIGHTSYM then
  541.                                                  begin
  542.                                                    case toggle of
  543.                                                      FALSE : begin
  544.                                                                toggle := TRUE;
  545.                                                                Inch2  := char(HBEGIN);
  546.                                                              end;
  547.                                                      TRUE  : begin
  548.                                                                toggle := FALSE;
  549.                                                                Inch2  := char(HEND);
  550.                                                              end;
  551.                                                    end;{case}
  552.                                                  end;
  553.                                                if Inch2 = ESCAPECHAR then
  554.                                                  begin
  555.                                                    Read(InFile,Inch2);
  556.                                                  end;
  557.                                                if Header.Encrypt = 1 then
  558.                                                  Inch2 := char(ord(Inch2) xor 20);
  559.                                                blockwrite(OutFile,Inch2,sizeof(Inch2));
  560.                                                inc(CharCount);
  561.                                                Read(InFile,Inch2);
  562.                                              end;
  563.                                            until Inch2 = '"';
  564.  
  565.                                          end;
  566.                             end;{case}
  567.                             Command := GetKeyword;
  568.                           end;
  569.                         PSave2 := FilePos(OutFile);
  570.                         HelpItemBuff.TextLen := CharCount;
  571.                         Seek(OutFile,sizeof(Header)+((HelpItemBuff.HelpID-1)*sizeof(DummyJMP)));
  572.                         blockwrite(OutFile,PSave1,Sizeof(PSave1));
  573.                         Seek(OutFile,PSave1);
  574.                         blockwrite(OutFile,HelpItemBuff,sizeof(HelpItemBuff));
  575.                         Seek(OutFile,PSave2);
  576.                         PSave2 := FilePos(OutFile);
  577.                      end;
  578.       end;{case}
  579.     end;
  580.   writeln;
  581. end;
  582.  
  583. {---------------------------------------------------------------------------}
  584.  
  585. Var
  586.   Dummy : string;
  587.  
  588. begin
  589.   Init;
  590.   SetFiles;
  591.   Message;
  592.   Pass1;
  593.   Pass2;
  594.   Close(OutFile);
  595.   Close(InFile);
  596. end.