home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / tptools.zip / BINED.ZIP / DEMO.INC < prev    next >
Text File  |  1987-12-21  |  6KB  |  209 lines

  1. {                             DEMO.INC
  2.              Copyright (c) 1985, 87 by Borland International, Inc.            }
  3.  
  4.   procedure DrawBox(Border : BorderChars; x1, y1, x2, y2 : byte);
  5.     {-Draw a box around an editor window}
  6.   var
  7.     i : Word;
  8.     bar : String;
  9.     barlen : Byte absolute bar;
  10.  
  11.   begin                       {DrawBox}
  12.  
  13.     {Build horizontal bar}
  14.     barlen := 3+X2-X1;
  15.     FillChar(bar[1], barlen, Border[horiz]);
  16.  
  17.     {Draw top bar}
  18.     bar[1] := Border[topleft];
  19.     bar[barlen] := Border[topright];
  20.     CRTputFast(X1, Y1, bar);
  21.  
  22.     {Draw bottom bar}
  23.     bar[1] := Border[botleft];
  24.     bar[barlen] := Border[botright];
  25.     CRTputFast(X1, Y2+2, bar);
  26.  
  27.     {Vertical bars}
  28.     for i := Succ(Y1) to Succ(Y2) do begin
  29.       CRTputFast(X1, i, Border[vert]);
  30.       CRTputFast(X2+2, i, Border[vert]);
  31.     end;
  32.   end;                        {DrawBox}
  33.  
  34.   procedure WriteStatus(msg : String);
  35.     {-Write a status message to the bottom line of the screen}
  36.   var
  37.     msglen : Byte absolute msg;
  38.  
  39.   begin                       {WriteStatus}
  40.     FillChar(msg[Succ(msglen)], 80-msglen, #32);
  41.     msglen := 80;
  42.     CRTputFast(1, 25, CAerr+msg);
  43.   end;                        {WriteStatus}
  44.  
  45.   procedure CheckInitBinary(ExitCode : Word);
  46.     {-Check the results of the editor load operation}
  47.  
  48.   begin                       {CheckInitBinary}
  49.     if ExitCode <> 0 then begin
  50.       {Couldn't initialize editor}
  51.       GoToXY(1, 25);
  52.       case ExitCode of
  53.         1 : WriteLn('Insufficient heap space for text buffer');
  54.       else
  55.         WriteLn('Unknown load error');
  56.       end;
  57.       Halt(1);
  58.     end;
  59.   end;                        {CheckInitBinary}
  60.  
  61.   procedure CheckReadFile(ExitCode : Word; Fname : String);
  62.     {-Check the results of the file read}
  63.   var
  64.     f : file;
  65.  
  66.   begin                       {CheckReadFile}
  67.     if ExitCode <> 0 then begin
  68.       {Couldn't read file}
  69.       case ExitCode of
  70.         1 : begin
  71.               {New file, assure valid file name}
  72.               {$I-}
  73.               Assign(f, Fname);
  74.               Rewrite(f);
  75.               if IOResult <> 0 then begin
  76.                 Close(f);
  77.                 WriteStatus('Illegal file name '+Fname);
  78.               end else begin
  79.                 Close(f);
  80.                 Erase(f);
  81.                 Write('New File');
  82.                 Delay(2000);
  83.                 Write(^M);
  84.                 ClrEol;
  85.                 GoToXY(1, 1);
  86.                 ClrEol;
  87.                 Exit;
  88.               end;
  89.               {$I+}
  90.             end;
  91.         2 : WriteStatus('Insufficient text buffer size');
  92.       else
  93.         WriteStatus('Unknown read error');
  94.       end;
  95.       GoToXY(1, 25);
  96.       Halt(1);
  97.     end;
  98.     GoToXY(1, 1);
  99.     ClrEol;
  100.   end;                        {CheckReadFile}
  101.  
  102.   procedure CheckSaveFile(ExitCode : Word; Fname : String);
  103.     {-Check the results of a file save}
  104.  
  105.   begin                       {CheckSaveFile}
  106.     if ExitCode <> 0 then begin
  107.       {Couldn't save file}
  108.       case ExitCode of
  109.         1 : WriteStatus('Unable to create output file '+Fname);
  110.         2 : WriteStatus('Error while writing output to '+Fname);
  111.         3 : WriteStatus('Unable to close output file '+Fname);
  112.       else
  113.         WriteStatus('Unknown write error');
  114.       end;
  115.       GoToXY(1, 25);
  116.       Halt(1);
  117.     end;
  118.   end;                        {CheckSaveFile}
  119.  
  120.   procedure WriteKeyboardToggles(info : Word);
  121.     {-Write the status of the keyboard toggles}
  122.   var
  123.     s : String;
  124.  
  125.   begin                       {WriteKeyboardToggles}
  126.     s := CAerr;
  127.     if (info and $40) <> 0 then
  128.       s := s+'CL'
  129.     else
  130.       s := s+'  ';
  131.     if (info and $20) <> 0 then
  132.       s := s+' NL'
  133.     else
  134.       s := s+'   ';
  135.     if (info and $10) <> 0 then
  136.       s := s+' SL'
  137.     else
  138.       s := s+'   ';
  139.     CRTputFast(72, 25, s);
  140.   end;                        {WriteKeyboardToggles}
  141.  
  142. type
  143.   string20 = string[20];
  144. var
  145.   TickCount : Word;        {Counter used to support on-screen clock}
  146.   TickMax : Word;          {Count when on-screen clock is updated}
  147.   LastTime : String20;     {Current time showing on screen}
  148.  
  149. {Note the user event handler must have a FAR attribute}
  150. {$F+}
  151.  
  152.   procedure UserEventCheck(EventNo, KbdFlagInfo : Word);
  153.     {-User hook for a background process called at every keypressed check}
  154.   var
  155.     NewTime : String20;
  156.  
  157.     function Time : String20;
  158.       {-Return a string holding the current time}
  159.     type
  160.       string2 = string[2];
  161.     var
  162.       hours, mins : string2;
  163.       hiclock, loclock : Word;
  164.       regs : registers;
  165.  
  166.       function ZeroPad(s : string2) : string2;
  167.         {-Left pad a numeral with a zero}
  168.  
  169.       begin                   {ZeroPad}
  170.         if s[0] = #1 then
  171.           s := '0'+s;
  172.         ZeroPad := s;
  173.       end;                    {ZeroPad}
  174.  
  175.     begin                     {Time}
  176.  
  177.       {Get the time from DOS}
  178.       regs.ah := $2C;
  179.       intr($21, regs);
  180.       hiclock := regs.cx;
  181.       loclock := regs.dx;
  182.  
  183.       {Convert to string}
  184.       Str(Hi(hiclock), hours);
  185.       Str(Lo(hiclock), mins);
  186.       Time := ' '+ZeroPad(hours)+':'+ZeroPad(mins)+' ';
  187.     end;                      {Time}
  188.  
  189.   begin                       {UserEventCheck}
  190.  
  191.     {Update on-screen clock once a minute}
  192.     if TickCount > TickMax then begin
  193.       TickCount := 0;
  194.       NewTime := Time;
  195.       if NewTime <> LastTime then begin
  196.         CRTputFast(65, 25, CAerr+NewTime);
  197.         LastTime := NewTime;
  198.       end;
  199.     end else
  200.       TickCount := Succ(TickCount);
  201.  
  202.     if eventno = EventKBflag then
  203.       {Update keyboard toggles whenever changed}
  204.       WriteKeyboardToggles(kbdflaginfo);
  205.  
  206.   end;                        {UserEventCheck}
  207.  
  208. {$F-}
  209.