home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / nicol / sti_help / sti_help.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1991-09-11  |  8.2 KB  |  343 lines

  1. unit STI_HELP;
  2.  
  3. interface
  4.  
  5. uses
  6.   CRT,
  7.   STI_SCRF;
  8.  
  9. procedure STI_HelpSys(FileName : string; Start : word);
  10.  
  11. implementation
  12.  
  13. Const
  14.   MAXREFS                 = 128;
  15.  
  16.   HIGHLIGHTSYM            = '$';
  17.   ESCAPECHAR              = '\';
  18.   NEWPAGEVAL              = 0;
  19.   HBEGIN                  = 1;
  20.   HEND                    = 2;
  21.  
  22. Type
  23.   BigBuffer = array[1..65535] of char;
  24.   HelpIdent = record
  25.                 Name  : string[32];
  26.                 Value : word;
  27.               end;
  28.   HeadType  = record
  29.                 Name      : string;
  30.                 VMin      : byte;
  31.                 VMax      : byte;
  32.                 X1,X2     : byte;
  33.                 Y1,Y2     : byte;
  34.                 TextCol   : byte;
  35.                 FrameCol  : byte;
  36.                 HighCol   : byte;
  37.                 TitleCol  : byte;
  38.                 CaseSense : byte;
  39.                 FrameType : byte;
  40.                 Encrypt   : byte;
  41.                 MaxRefI   : word;
  42.                 NoRefs    : word;
  43.               end;
  44.   HelpItemT = record
  45.                 HelpID    : word;
  46.                 TextLen   : word;
  47.                 Refs      : array[1..MAXREFS] of word;
  48.               end;
  49.  
  50.  
  51. Var
  52.   InFile       : file;
  53.  
  54.   Header       : HeadType;
  55.   HelpItemBuff : HelpItemT;
  56.   TextBuffer   : ^BigBuffer;
  57.   Page,Select  : word;
  58.  
  59. {---------------------------------------------------------------------------}
  60.  
  61. function Open_HelpFile(FileName : string) : boolean;
  62.  
  63. begin
  64.   assign(InFile,FileName);
  65.   {$I-}
  66.   reset(InFile,1);
  67.   if IOResult <> 0 then
  68.     Open_HelpFile := FALSE
  69.   else
  70.     Open_HelpFile := TRUE;
  71.   {$I+}
  72. end;
  73.  
  74. {---------------------------------------------------------------------------}
  75.  
  76. function MapBorder(InByte : byte) : string;
  77.  
  78. begin
  79.   case InByte of
  80.     34 : MapBorder := NOBORDER;
  81.     35 : MapBorder := SPACES;
  82.     36 : MapBorder := SINGLELINE;
  83.     37 : MapBorder := ROUNDCORNERSINGLE;
  84.     38 : MapBorder := BIGBLOCK;
  85.     39 : MapBorder := THICKTOPTHINSIDES;
  86.     40 : MapBorder := THICKDIAGONALCORNER;
  87.     else MapBorder := SINGLELINE;
  88.   end;{case}
  89. end;
  90.  
  91. {---------------------------------------------------------------------------}
  92.  
  93. function MapColor(Inbyte : byte) : byte;
  94.  
  95. begin
  96.   Case InByte of
  97.     18   : MapColor := Black;
  98.     19   : MapColor := Blue;
  99.     20   : MapColor := Red;
  100.     21   : MapColor := Green;
  101.     22   : MapColor := Cyan;
  102.     23   : MapColor := Yellow;
  103.     24   : MapColor := Magenta;
  104.     25   : MapColor := White;
  105.     26   : MapColor := Black+Reverse;
  106.     27   : MapColor := Blue+Reverse;
  107.     28   : MapColor := Red+Reverse;
  108.     29   : MapColor := Green+Reverse;
  109.     30   : MapColor := Cyan+Reverse;
  110.     31   : MapColor := Yellow+Reverse;
  111.     32   : MapColor := Magenta+Reverse;
  112.     33   : MapColor := White+Reverse;
  113.     else   MapColor := White;
  114.   end;{case}
  115. end;
  116.  
  117. {---------------------------------------------------------------------------}
  118.  
  119. procedure Read_Help(HelpNum : word);
  120.  
  121. Var
  122.   Pos1  : longint;
  123.   Bytes : word;
  124.  
  125. begin
  126.   {$I-}
  127.   Seek(InFile,0);
  128.   Seek(InFile,sizeof(Header)+((HelpNum-1)*sizeof(Pos1)));
  129.   blockread(InFile,Pos1,sizeof(Pos1),Bytes);
  130.   Seek(InFile,Pos1);
  131.   blockread(InFile,HelpItemBuff,sizeof(HelpItemBuff),Bytes);
  132.   getmem(TextBuffer,HelpItemBuff.TextLen+10);
  133.   FillChar(TextBuffer^,HelpItemBuff.TextLen+10,#0);
  134.   blockread(InFile,TextBuffer^,HelpItemBuff.TextLen,Bytes);
  135.   HelpItemBuff.TextLen := Bytes;
  136.   {$I-}
  137. end;
  138.  
  139. {---------------------------------------------------------------------------}
  140.  
  141. function CountRefsEP(Sel,Page : word) : word;
  142.  
  143. Var
  144.   Loop,PCnt,SCnt : word;
  145.  
  146. begin
  147.   PCnt := 1;
  148.   SCnt := 0;
  149.   Loop := 1;
  150.   while PCnt <= Page do
  151.     begin
  152.       if TextBuffer^[Loop] = char(NEWPAGEVAL) then
  153.         inc(PCnt);
  154.       if TextBuffer^[Loop] = char(HBEGIN) then
  155.         inc(SCnt);
  156.       inc(Loop);
  157.     end;
  158.   CountRefsEP := SCnt;
  159. end;
  160.  
  161. {---------------------------------------------------------------------------}
  162.  
  163. function PageCountEP : word;
  164.  
  165. Var
  166.   Loop, Pcnt : word;
  167.  
  168. begin
  169.   Loop := 1;
  170.   PCnt := 1;
  171.   while Loop < HelpItemBuff.TextLen do
  172.     begin
  173.       if TextBuffer^[Loop] = char(NEWPAGEVAL) then
  174.         inc(PCnt);
  175.       inc(Loop);
  176.     end;
  177.   PageCountEP := PCnt;
  178. end;
  179.  
  180. {---------------------------------------------------------------------------}
  181.  
  182. function CountRefsFP(Sel,Page : word) : word;
  183.  
  184. Var
  185.   Loop,PCnt,SCnt : word;
  186.  
  187. begin
  188.   PCnt := 1;
  189.   SCnt := 0;
  190.   Loop := 1;
  191.   while PCnt <= Page do
  192.     begin
  193.       if TextBuffer^[Loop] = char(NEWPAGEVAL) then
  194.         inc(PCnt);
  195.       if (TextBuffer^[Loop] = char(HBEGIN)) and (PCnt = Page) then
  196.         begin
  197.           inc(SCnt);
  198.           CountRefsFP := SCnt;
  199.           Exit;
  200.         end;
  201.       inc(Loop);
  202.     end;
  203.   CountRefsFP := SCnt;
  204. end;
  205.  
  206. {---------------------------------------------------------------------------}
  207.  
  208. procedure Display_Prompt(Sel,Page : word);
  209.  
  210. Var
  211.   Loop : word;
  212.   PCnt : word;
  213.   SCnt : word;
  214.   High : boolean;
  215.  
  216. begin
  217.   PCnt := 1;
  218.   SCnt := 0;
  219.   Loop := 1;
  220.   High := FALSE;
  221.   while PCnt < Page do
  222.     begin
  223.       if TextBuffer^[Loop] = char(NEWPAGEVAL) then
  224.         inc(PCnt);
  225.       if TextBuffer^[Loop] = char(HBEGIN) then
  226.         inc(SCnt);
  227.       inc(Loop);
  228.     end;
  229.   GotoXY(1,1);
  230.   while (TextBuffer^[Loop] <> char(NEWPAGEVAL)) and (Loop <= HelpItemBuff.TextLen) do
  231.     begin
  232.       if TextBuffer^[Loop] = char(HBEGIN) then
  233.         begin
  234.           High := TRUE;
  235.           inc(SCnt);
  236.           if (Scnt = Sel) then
  237.             TextColor(MapColor(Header.HighCol))
  238.           else
  239.             TextColor(MapColor(Header.TitleCol));
  240.         end;
  241.  
  242.       if TextBuffer^[Loop] = char(HEND) then
  243.         begin
  244.           TextColor(White);
  245.           TextReverse(NoReverse);
  246.           TextColor(MapColor(Header.TextCol));
  247.           High := FALSE;
  248.         end;
  249.  
  250.       if TextBuffer^[Loop] in [#10,#13,#32..#255] then
  251.         begin
  252.           if (Textbuffer^[Loop] >= #32) and not(HIGH) then
  253.             DosPutch(TextBuffer^[Loop])
  254.           else
  255.             write(TextBuffer^[Loop]);
  256.         end
  257.       else
  258.         write(' ');
  259.       inc(Loop);
  260.     end;
  261. end;
  262.  
  263. {---------------------------------------------------------------------------}
  264.  
  265. function Display_Help(HelpNum : word) : word;
  266.  
  267. Var
  268.   Inch : char;
  269.  
  270. begin
  271.   TextColor(MapColor(Header.TextCol));
  272.   ClrScr;
  273.   Read_Help(HelpNum);
  274.   Page     := 1;
  275.   Select   := 1;
  276.   Inch := #0;
  277.   while Inch <> #27 do
  278.     begin
  279.       Display_Prompt(Select,Page);
  280.       repeat until KeyPressed;
  281.       Inch := ReadKey;
  282.       case Inch of
  283.         #13   : begin
  284.                   Display_Help := HelpItemBuff.Refs[Select];
  285.                   Exit;
  286.                 end;
  287.         #12   : begin
  288.                   if Select < CountRefsEP(Select,Page) then
  289.                     inc(Select);
  290.                 end;
  291.         #8    : begin
  292.                   if Select > CountRefsFP(Select,Page) then
  293.                     dec(Select);
  294.                 end;
  295.         #11   : begin
  296.                   if Page > 1 then
  297.                     dec(Page);
  298.                   ClrScr;
  299.                 end;
  300.         #10   : begin
  301.                   if Page < PageCountEP then
  302.                     inc(Page);
  303.                   ClrScr;
  304.                 end;
  305.       end;{case}
  306.     end;
  307.   Display_Help := 0;
  308. end;
  309.  
  310. {---------------------------------------------------------------------------}
  311.  
  312. procedure STI_HelpSys(FileName : string; Start : word);
  313.  
  314. Var
  315.   SaveWin : WindowSave;
  316.   Dummy   : word;
  317.  
  318. begin
  319.   if Open_HelpFile(FileName) then
  320.     begin
  321.       HiddenCursor;
  322.       blockread(InFile,Header,sizeof(Header));
  323.       MakeWindow(SaveWin,
  324.                  Header.X1,Header.Y1,
  325.                  Header.X2,Header.Y2,
  326.                  MapColor(Header.TextCol),
  327.                  MapColor(Header.FrameCol),
  328.                  MapColor(Header.TitleCol),
  329.                  MapBorder(Header.FrameType),
  330.                  ' Help ');
  331.       Window(Header.X1+1,Header.Y1+1,Header.X2-1,Header.Y2-1);
  332.       while Start <> 0 do
  333.         Start := Display_Help(Start);
  334.       Window(1,1,80,25);
  335.       DisposeWindow(SaveWin);
  336.     end;
  337.   Close(InFile);
  338. end;
  339.  
  340. {---------------------------------------------------------------------------}
  341.  
  342. begin
  343. end.