home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / tptools.zip / FIRSTED.ZIP / EDBACK.PAS < prev    next >
Pascal/Delphi Source File  |  1987-12-21  |  5KB  |  188 lines

  1. {                          EDBACK.PAS
  2.                              ED 4.0
  3.              Copyright (c) 1985, 87 by Borland International, Inc.            }
  4.  
  5. {$I eddirect.inc}
  6.  
  7. unit EdBack;
  8.   {-Background processes for FirstEd}
  9.  
  10. interface
  11.  
  12. uses
  13.   crt,                       {Basic video operations - standard unit}
  14.   Dos,                       {DOS calls - standard unit}
  15.   Errors,                    {Runtime error handler}
  16.   EdVars,                    {Global types and declarations}
  17.   EdScrn1,                   {Fast screen writing routines}
  18.   EdString,                  {String primitives}
  19.   EdPtrOp,                   {Primitive pointer operations}
  20.   EdCmds,                    {Maps keystrokes to commands}
  21.   int24,                     {DOS critical error handler}
  22.   Message,                   {Message system}
  23.   EdUser;                    {User keyboard input and error reporting}
  24.  
  25. procedure EdHscrollOne(W : PwinDesc);
  26.   {-Horizontal scroll one window}
  27.  
  28. procedure EdHscroll;
  29.   {-Scroll windows horizontally}
  30.  
  31. procedure EdMarkblock;
  32.   {-Mark lines in current block}
  33.  
  34. procedure EdGenLineNo;
  35.   {-Generate line numbers for window status lines}
  36.  
  37. procedure EdCloneModifiedFlags;
  38.   {-Update linked window modified flags}
  39.  
  40.   {==========================================================================}
  41.  
  42. implementation
  43.  
  44.   {***}
  45.   procedure EdHscrollOne(W : PwinDesc);
  46.     {-Horizontal scroll one window}
  47.  
  48.   begin                      {EdHscrollOne}
  49.     with W^ do begin
  50.       if ColNo < LeftEdge then
  51.         LeftEdge := ColNo
  52.       else if ColNo > (LeftEdge+PhyScrCols-2-LeftCol) then
  53.         LeftEdge := Succ(ColNo-PhyScrCols+LeftCol);
  54.     end;
  55.   end;                       {EdHscrollOne}
  56.  
  57.   procedure EdHscroll;
  58.     {-Scroll windows horizontally}
  59.   var
  60.     W : PwinDesc;
  61.  
  62.   begin                      {EdHscroll}
  63.     W := CurWin;
  64.     repeat
  65.       EdHscrollOne(W);
  66.       EdFwdPtr(W);
  67.     until (W = CurWin);
  68.   end;                       {EdHscroll}
  69.  
  70.   procedure EdMarkblock;
  71.     {-Mark lines in current block}
  72.   var
  73.     P, Q : PlineDesc;
  74.     I : Integer;
  75.     Done : Boolean;
  76.  
  77.   begin                      {EdMarkblock}
  78.  
  79.     if EdNoBlock then
  80.       Exit;
  81.  
  82.     {We have a block defined, so start marking}
  83.     P := Blockfrom.Line;
  84.     Q := Blockto.Line;
  85.     I := 0;
  86.     repeat
  87.       EdChangeFlag(P, True, InBlock);
  88.       Done := (P = Q);
  89.       if not(Done) then begin
  90.         Inc(I);
  91.         if (I and 3) = 0 then
  92.           if EdKeyInterrupt then
  93.             Exit;
  94.         EdFwdPtr(P);
  95.       end;
  96.     until Done;
  97.  
  98.   end;                       {EdMarkblock}
  99.  
  100.   {***}
  101.   procedure EdGenLineOne(W : PwinDesc);
  102.     {-Generate line and byte counts for one window}
  103.   var
  104.     P : PlineDesc;
  105.     TotalLine : Word;
  106.     Len : Integer;
  107.     TotalChar : LongInt;
  108.  
  109.   begin                      {EdGenLineOne}
  110.     with W^ do begin
  111.  
  112.       TotalLine := 0;
  113.       TotalChar := 00;
  114.  
  115.       {Count back to beginning of file}
  116.       P := CurLine;
  117.       while EdPtrNotNil(P) do begin
  118.         {Byte count - add 2 per line for CR/LF}
  119.         TotalChar := TotalChar+EdTextLength(P)+2;
  120.         {Line count}
  121.         Inc(TotalLine);
  122.         {Check the keyboard every four lines}
  123.         if (TotalLine and 3) = 0 then
  124.           if EdKeyInterrupt then
  125.             Exit;
  126.         EdBackPtr(P);
  127.       end;
  128.  
  129.       {Update line count}
  130.       if TotalLine <> Clineno then
  131.         UpdateScreen := True;
  132.       Clineno := TotalLine;
  133.  
  134.       {Update byte count, here Tcharno holds bytes to cursor, NOT total}
  135.       Len := EdTextLength(CurLine);
  136.       if ColNo > Len then
  137.         {Subtract the CR/LF added for the current line}
  138.         TotalChar := TotalChar-2
  139.       else
  140.         TotalChar := TotalChar-Len-2+ColNo;
  141.       if TotalChar <> TcharNo then
  142.         UpdateScreen := True;
  143.       TcharNo := TotalChar;
  144.  
  145.     end;
  146.   end;                       {EdGenLineOne}
  147.  
  148.   {***}
  149.   procedure EdGenLineNo;
  150.     {-Generate line numbers for window status lines}
  151.   var
  152.     W : PwinDesc;
  153.  
  154.   begin                      {EdGenlineno}
  155.     W := CurWin;
  156.     repeat
  157.       EdGenLineOne(W);
  158.       if EdKeyInterrupt then
  159.         Exit;
  160.       EdFwdPtr(W);
  161.     until W = CurWin;
  162.   end;                       {EdGenlineno}
  163.  
  164.   procedure EdCloneModifiedFlags;
  165.     {-Update linked window modified flags}
  166.   var
  167.     W : PwinDesc;
  168.     S : Word;
  169.  
  170.   begin                      {EdCloneModifiedFlags}
  171.     with CurWin^ do begin
  172.       if not(Modified) then
  173.         Exit;
  174.       S := Stream;
  175.     end;
  176.     W := CurWin;
  177.     repeat
  178.       with W^ do
  179.         if (S = Stream) and not(Modified) then begin
  180.           Modified := True;
  181.           UpdateScreen := True;
  182.         end;
  183.       EdFwdPtr(W);
  184.     until W = CurWin;
  185.   end;                       {EdCloneModifiedFlags}
  186.  
  187. end.
  188.