home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / BININT.ZIP / TEST1.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-10-22  |  2.8 KB  |  111 lines

  1. {$R-,S-}
  2.  
  3. program Test1;
  4.   {-Display BinEd internals information}
  5.  
  6. uses
  7.   Crt,                            {Just for convenience of demo}
  8.   BinEd,
  9.   BinInt;                         {Makes BinEd internals available to event handlers}
  10.  
  11. const
  12.   ExitCommands : Char = #0;       {No special exit characters}
  13.  
  14. var
  15.   EdData : EdCB;                  {Editor control block}
  16.   EdInt : EdIntRec;               {Internals record}
  17.  
  18.   procedure Abort(Msg : string);
  19.   begin
  20.     WriteLn(Msg);
  21.     Halt(1);
  22.   end;
  23.  
  24.   {$F+}
  25.   procedure EventHandler(EventNo, KbdFlagInfo : Word);
  26.     {-Event handler reports on internals}
  27.   const
  28.     {Used to avoid rewriting screen too much}
  29.     LOfsS : Word = $FFFF;
  30.     CharS : Char = #$FF;
  31.     LPosS : Byte = $FF;
  32.     LLenS : Byte = $FF;
  33.     OptnS : Byte = $FF;
  34.   var
  35.     LOfsC : Word;
  36.     CharC : Char;
  37.     LPosC : Byte;
  38.     LLenC : Byte;
  39.     OptnC : Byte;
  40.   begin
  41.     {Get current values}
  42.     LOfsC := CurrLineOfs(EdInt);
  43.     CharC := CurrChar(EdInt);
  44.     LPosC := LinePos(EdInt);
  45.     LLenC := LineLen(EdInt);
  46.     OptnC := EditOptions(EdInt);
  47.  
  48.     {See if they're different than last time we updated screen}
  49.     if (LOfsC <> LOfsS) or (CharC <> CharS) or
  50.        (LPosC <> LPosS) or (LLenC <> LLenS) or
  51.        (OptnC <> OptnS) then begin
  52.       {Write the buffer offset of the current line}
  53.       GoToXy(27, 20);
  54.       Write(LOfsC, '     ');
  55.       {Write the character at the cursor}
  56.       GoToXy(27, 21);
  57.       Write(CharC);
  58.       {Write the position within current line}
  59.       GoToXy(27, 22);
  60.       Write(LPosC, '   ');
  61.       {Write the length of the current line}
  62.       GoToXy(27, 23);
  63.       Write(LLenC, '   ');
  64.       GotoXy(27, 24);
  65.       Write(OptnC, '   ');
  66.       {Save values for next time}
  67.       LOfsS := LOfsC;
  68.       CharS := CharC;
  69.       LPosS := LPosC;
  70.       LLenS := LLenC;
  71.       OptnS := OptnC;
  72.     end;
  73.   end;
  74.   {$F-}
  75.  
  76. begin
  77.   if ParamCount = 0 then
  78.     Abort('Usage: TEST1 filename.ext');
  79.  
  80.   {Initialize binary editor for a partial screen window}
  81.   if InitBinaryEditor(EdData, MaxFileSize, 1, 1, 80, 18,
  82.                       True, EdOptInsert, '', ExitCommands,
  83.                       @EventHandler) <> 0 then
  84.     Abort('Unable to load binary editor.');
  85.  
  86.   {Store internals for event handler}
  87.   FindInternals(EdData, EdInt);
  88.  
  89.   {Read file to edit}
  90.   if ReadFileBinaryEditor(EdData, ParamStr(1)) > 1 then
  91.     Abort('Unable to read '+ParamStr(1));
  92.  
  93.   {Write titles for the event handler}
  94.   ClrScr;
  95.   GoToXy(1, 20);
  96.   WriteLn('Offset of current line  :');
  97.   WriteLn('Character at cursor     :');
  98.   WriteLn('Position in current line:');
  99.   WriteLn('Length of current line  :');
  100.   WriteLn('Editor options byte     :');
  101.  
  102.   {Reset for this file}
  103.   ResetBinaryEditor(EdData);
  104.  
  105.   {Edit it, no save supported}
  106.   if UseBinaryEditor(EdData, '') = -1 then
  107.     ;
  108.  
  109.   GoToXy(1, 25);
  110. end.
  111.