home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / HELPUN.ZIP / HELPUNIT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-02-17  |  3.8 KB  |  156 lines

  1. unit helpunit;
  2.  
  3. { This TP Ver 4 unit will allow the user to construct a standard ASCII
  4.   text file of help information which is displayed 23 lines at a time on
  5.   the screen.  The procedure HELP is called with any valid DOS filename
  6.   which contains the help information. If the file does not exist an error
  7.   message is displayed asking for operator acknowledgement and the procedure
  8.   issues an exit command.
  9.  
  10.   Navigation on the various help screens is controlled with the PgUp, PgDn,
  11.   Home and End keys.  A single line appears at (1,25) describing the keys
  12.   to the user.  The Esc key is used to end the help procedure and return to
  13.   the calling procedure.
  14.  
  15.   The constraints on the text file which contains the help information are:
  16.  
  17.       1.  No more than 23 lines.
  18.           (An "error in row length" message will appear at each attempt
  19.           to exceed this limit)
  20.  
  21.       2.  Pages are delimited with a ".pa" (a la WordStar but only lowercase
  22.           accepted )
  23.  
  24.       3.  Only standard ASCII text as created with the Turbo Editor.
  25.  
  26. }
  27.  
  28.  
  29.  
  30. interface
  31. uses crt;
  32.  
  33. procedure help(filename:string);
  34.  
  35. implementation
  36.  
  37.  
  38.  
  39. {-------------------------------------------------------------}
  40.  
  41. procedure help(filename:string);
  42.  
  43. type
  44. help_ptr=^help;
  45. help=record
  46.        lines:array[1..23] of string[80];
  47.        next,previous:help_ptr;
  48.      end;
  49.  
  50.  
  51. var
  52. x:integer;
  53. help_file:text;
  54. ans:char;
  55. data:string[80];
  56. head,help_data,temp,old:help_ptr;
  57. heaptop:^integer;
  58.  
  59. begin
  60.   ans:=' ';
  61.   clrscr;
  62.   gotoxy(1,10);
  63.   writeln('  Reading in help file -- Please standby  ');
  64.   textcolor(white);
  65.   assign(help_file,filename);
  66.   {$I-}
  67.   reset(help_file);
  68.   {$I+}
  69.   if ioresult<>0 then
  70.     begin
  71.       textcolor(lightred);
  72.       gotoxy(1,25);clreol;
  73.       write(^G,'ERROR --  The help file does not exist.  Push any key to return');
  74.       textcolor(white);
  75.       ans:=readkey;
  76.       exit;
  77.     end;
  78.  
  79.  
  80.   textcolor(yellow);
  81.   textbackground(blue);
  82.   gotoxy(1,25);clreol;
  83.   write('PgUp -next pg  PgDn -previous pg  Home -first pg  End -last pg  Esc -Exit');
  84.   textcolor(white);
  85.   textbackground(black);
  86.   window(1,1,80,24);
  87.  
  88.   mark(heaptop);
  89.   new(head);
  90.   new(help_data);
  91.   fillchar(help_data^,sizeof(help_data^),0);
  92.   head^.next:=help_data;
  93.   help_data^.next:=nil;
  94.   help_data^.previous:=nil;
  95.   x:=1;
  96.  
  97.   while (not eof(help_file)) do
  98.     begin
  99.       readln(help_file,data);
  100.       if (data<>'.pa') then
  101.         begin
  102.           help_data^.lines[x]:=data;
  103.           x:=x+1;
  104.           if x>23 then
  105.             begin
  106.               x:=23;
  107.               writeln('Error in row length');
  108.             end;
  109.         end
  110.         else
  111.         begin
  112.           new(temp);
  113.           old:=help_data;
  114.           help_data^.next:=temp;
  115.           help_data:=temp;
  116.           help_data^.next:=nil;
  117.           help_data^.previous:=old;
  118.           fillchar(help_data^.lines,sizeof(help_data^.lines),0);
  119.           x:=1;
  120.         end;
  121.  
  122.     end; {end while not eof and 27}
  123.  
  124.  
  125.  
  126. {now that we've got all the info, write it out }
  127.     head^.previous:=help_data;
  128.     help_data:=head^.next;
  129.     repeat
  130.       clrscr;
  131.       gotoxy(1,1);
  132.       for x:=1 to 23 do writeln(help_data^.lines[x]);
  133.       ans:=readkey;
  134.       if ans=#0 then
  135.         begin
  136.           ans:=readkey;
  137.           case ans of
  138.             #73:if help_data^.next<>nil then help_data:=help_data^.next else write(^G);
  139.             #81:if help_data^.previous<>nil then help_data:=help_data^.previous else write(^G);
  140.             #71:help_data:=head^.next;
  141.             #79:help_data:=head^.previous;
  142.           end; {end case}
  143.         end; {end if ans=#0}
  144.     until (ans=#27);
  145.  
  146.     close(help_file);
  147.     release(heaptop);
  148.     window(1,1,80,25);
  149.     clrscr;
  150.  
  151. end;
  152.  
  153. {-------------------------------------------------------------}
  154.  
  155.  
  156. end.