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

  1. {                          EDVARS.PAS
  2.                              ED 4.0
  3.              Copyright (c) 1985, 87 by Borland International, Inc.            }
  4.  
  5. {$I eddirect.inc}
  6.  
  7. unit EdVars;
  8.  
  9. interface
  10.  
  11. uses
  12.   Dos,
  13.   Errors;
  14.  
  15. const
  16.   Version = '4.00A';         {Version number of editor}
  17.  
  18.   {Constants you may wish to customize}
  19.   MaxLineLength = 999;       {Maximum number of chars/text line}
  20.   Bufsize = 4096;            {Size of file global read/write buffer}
  21.   MaxMarker = 9;             {Maximum number of text markers, 0..MaxMarker}
  22.   FreeListPerm = 4000;       {Minimum bytes to keep free for heap free list}
  23.   MaxWindows = 6;            {Maximum number of text windows}
  24.   MinWindowLines = 2;        {Minimum rows in a text window}
  25.   PositionFindAtStart = False; {False to position cursor at END of search string}
  26.   MakeBackups = True;        {True to create backup files when saving}
  27.   CleanupAtExit = False;     {True to make ED free up heap space at exit}
  28.  
  29.   {Basic identities}
  30.   Line1 = 1;                 {Logical line number 1}
  31.   Col1 = 1;                  {Logical column number 1}
  32.   Null = #0;                 {Null character}
  33.  
  34.   {Flags used in the Linedesc record}
  35.   InBlock = $4000;           {Set => display block in Blockcolor}
  36.   InMark = $8000;            {Set => line contains a marker}
  37.  
  38.   {Miscellaneous constant strings}
  39.   NoFile : string[6] = 'NONAME'; {Name of window with no file}
  40.   EolMark : string[2] = ^M^J; {Indicates end of line}
  41.   Period : Char = '.';
  42.   Blank : Char = ' ';
  43.  
  44. type
  45.   ExtString = string[3];     {File extensions}
  46.   Filename = string[14];     {DOS filename without path}
  47.   Filepath = string[64];     {DOS pathname}
  48.   VarString = string[80];    {String for screen messages}
  49.   String255 = string[255];   {Longest Turbo string}
  50.  
  51.   Charset = set of Char;     {General purpose for character sets}
  52.  
  53.   TextLine = array[0..MaxLineLength] of Char; {Can hold the text of one line}
  54.   WorkBuffer = array[0..Bufsize] of Char; {Buffer for file, block, search operations}
  55.  
  56.   PlineDesc = ^LineDesc;
  57.   PtextLine = ^TextLine;
  58.  
  59.   LineDesc =                 {A complete text line, with links}
  60.   record
  61.     FwdLink : PlineDesc;     {Ptr to previous line in stream - MUST BE FIRST FIELD}
  62.     Backlink : PlineDesc;    {Ptr to next line in stream - MUST BE SECOND FIELD}
  63.     Txt : PtextLine;         {Ptr to text buffer}
  64.     Flags : Word;            {Packed flags word - see bit masks above}
  65.     Bufflen : Integer;       {Holds current length of text buffer}
  66.   end;
  67.  
  68.   BlockMarker =              {Describes a unique position in text stream}
  69.   record
  70.     Line : PlineDesc;
  71.     Col : Integer;
  72.   end;
  73.   MarkArray = array[0..MaxMarker] of BlockMarker;
  74.  
  75.   PwinDesc = ^WinDesc;
  76.   WinDesc =                  {Describes each window on screen}
  77.   record
  78.     FwdLink : PwinDesc;      {Next window down - MUST BE FIRST FIELD}
  79.     Backlink : PwinDesc;     {Next window up - MUST BE SECOND FIELD}
  80.     FirstLineNo : Integer;   {Screen row number of window status line}
  81.     LastLineNo : Integer;    {Screen row number of last text line}
  82.     FirstTextNo : Integer;   {Screen row number of first text line}
  83.     Filename : Filepath;     {File being edited}
  84.     InsertFlag : Boolean;    {Insert mode}
  85.     AI : Boolean;            {Autoindent mode}
  86.     WW : Boolean;            {WordWrap mode - enables paragraph reformat}
  87.     TL : Boolean;            {Tab line display}
  88.     JU : Boolean;            {Right justification}
  89.     PA : Boolean;            {Paginated}
  90.     AT : Boolean;            {Attributes displayed}
  91.     FT : Boolean;            {Fixed tabs displayed}
  92.     Modified : Boolean;      {True when save is required}
  93.     PaginationDone : Boolean; {True when pagination has run through entire file}
  94.     Wmargin : Integer;       {Wrap margin column number}
  95.     Lmargin : Integer;       {Left margin column number}
  96.     Rmargin : Integer;       {Right margin column number}
  97.     PageLen : Integer;       {Default page length}
  98.     Tmargin : Integer;       {Default top margin}
  99.     Bmargin : Integer;       {Default bottom margin}
  100.     LineNo : Integer;        {Line number relative to screen, 1..25}
  101.     ColNo : Integer;         {Last cursor address}
  102.     Clineno : Word;          {Display only: line in file}
  103.     TlineNo : Word;          {Total lines in file}
  104.     TcharNo : LongInt;       {Total bytes in file}
  105.     TpageNo : Integer;       {Total pages in file}
  106.     TopLine : PlineDesc;     {Ptr to first line in view}
  107.     CurLine : PlineDesc;     {Ptr to current line}
  108.     PageLine : PlineDesc;    {Ptr to last line with accurate pagination}
  109.     WmarginLine : PlineDesc; {Ptr to line where wmargin was set}
  110.     Stream : Word;           {Unique text stream id}
  111.     LeftEdge : Integer;      {Leftmost displayed text column}
  112.     LeftCol : Integer;       {Screen column offset where text display starts}
  113.     Visible : Boolean;       {True if window shows on screen}
  114.   end;
  115.  
  116. const
  117.  
  118.   {Used by various word oriented commands}
  119.   {Punctuation symbols are for consistency with Turbo editor}
  120.   Alphas : Charset =         {Used in word oriented operations}
  121.   ['A'..'Z', 'a'..'z', '0'..'9', '%', '@', '_', '|', '"', '?', ';', #128..#254];
  122.  
  123.   WordDelimiters : string[34] = {Used by EditScanPat for whole word searches}
  124.   #32#9#13#10#39',./?;:"<>[]{}-=\+|()*%@&^$#!~';
  125.  
  126.   {Marks start of INSTALLATION AREA}
  127.   MainIDstring : string[22] = 'MAIN INSTALLATION AREA';
  128.  
  129.   {Common to all windows}
  130.   SaveUndoLimit : Integer = 20; {Default number of lines for undo stack}
  131.   DefExtension : string[3] = ''; {Default extension applied to filenames}
  132.  
  133.   {Set up by independent toggles for each window}
  134.   SaveInsertMode : Boolean = True; {Default to insert mode ON}
  135.   SaveIndentMode : Boolean = True; {Default to indent mode ON}
  136.  
  137.   {End of INSTALLATION AREA}
  138.  
  139. var
  140.   {Keyboard-related}
  141.   EditUsercommandInput : Integer; {Count of chars pushed by UserCommand}
  142.  
  143.   {Screen-related}
  144.   FullScroll : Integer;      {Number of lines to BIOS scroll at next screen update}
  145.   TempScroll : Integer;      {Intermediate number of lines of BIOS scroll}
  146.   UpdateScreen : Boolean;    {True when text screen must be redrawn}
  147.   PromptLine : String255;    {Command line image}
  148.   PromptCol : Integer;       {Column for next cmd printed on command line}
  149.  
  150.   {Markers and Macros}
  151.   Blockfrom : BlockMarker;   {Points to beginning of block}
  152.   Blockto : BlockMarker;     {Points to end of block}
  153.   CurLineTo : BlockMarker;   {Used in current line buffering wrt marked blocks}
  154.   CurLineFrom : BlockMarker; {Used in current line buffering wrt marked blocks}
  155.   LastPosition : BlockMarker; {Cursor position prior to current operation}
  156.   Marker : MarkArray;        {Text markers}
  157.   Blockop : Boolean;         {Set if a block operation just occurred}
  158.   Blockhide : Boolean;       {Set if block is not displayed}
  159.   MarkHide : Boolean;        {set if marks are not displayed}
  160.  
  161.   {Window-related}
  162.   WindowCount : Integer;     {Number of text windows on screen, 0..MaxWindows}
  163.   CurWin : PwinDesc;         {Pointer to window containing cursor}
  164.   Window1 : PwinDesc;        {Pointer to window at top of screen}
  165.   WinStack : PwinDesc;       {Pointer to free list of windows}
  166.  
  167.   {Basic flags}
  168.   Rundown : Boolean;         {Determines when scheduler is done}
  169.   UpdateCursor : Boolean;    {Set if we must reposition cursor}
  170.   GotError : Boolean;        {Set after any error, pollable by calling routine}
  171.   Abortcmd : Boolean;        {Set when AbortChar is pressed}
  172.   Aborting : Boolean;        {Stops recursion during abort}
  173.   AbortEnable : Boolean;     {Set when AbortChar is to be accepted as abort}
  174.   IntrFlag : (NoInterr, Interr); {Set to Interrupt when keystrokes can interrupt screen writes}
  175.  
  176.   {Find and Replace}
  177.   PromptForInput : Boolean;  {Set False for Find Next operations}
  178.   LastSearchOp : (Find, Replace, RunMacro, None); {Whatever was done after last search}
  179.  
  180.   {Undo-related}
  181.   UndoCount : Integer;       {Number of lines currently on undo stack}
  182.   UndoLimit : Integer;       {Maximum number of lines on undo stack}
  183.   UndoStack : PlineDesc;     {First line on undo stack}
  184.   UndoEnd : PlineDesc;       {Last line on undo stack}
  185.   CurLineBuf : PlineDesc;    {Pointer to current line buffer for line restore}
  186.   CurLineCol : Integer;      {Column number upon entry to line}
  187.  
  188.   {File support}
  189.   WorkBuf : WorkBuffer;      {Buffer used for read/write speed, also for searching}
  190.   LastBlockRead : Filepath;  {Last file used in blockread}
  191.   LastBlockWrite : Filepath; {Last file used in blockwrite}
  192.   LastFileEdit : Filepath;   {Last file used in edit}
  193.  
  194.   FreeListSpace : Word;      {Dynamic amount of free list space to retain}
  195.  
  196.   {==============================================================================}
  197.  
  198. implementation
  199.  
  200.   procedure EdInitGlobals;
  201.   var
  202.     P : PwinDesc;
  203.     I : Integer;
  204.  
  205.   begin                      {EdInitGlobals}
  206.  
  207.     UpdateScreen := True;    {Screen needs updating}
  208.     UpdateCursor := True;    {Cursor needs updating}
  209.     FullScroll := 0;         {BIOS scrolling not currently needed}
  210.     IntrFlag := Interr;      {Allow interrupts of screen updates}
  211.     Abortcmd := False;       {Set by EditAbort to stop EditAskfor}
  212.     Aborting := False;       {Set by EditAbort to stop recursion}
  213.     AbortEnable := False;    {Disable AbortCmd until needed}
  214.  
  215.     LastFileEdit := '';
  216.     LastBlockRead := '';
  217.     LastBlockWrite := '';
  218.  
  219.     UndoCount := 0;          {Used by EditUndo and EditDelline}
  220.     UndoLimit := SaveUndoLimit; {Default size of undo buffer}
  221.     UndoStack := nil;        {Front of undo queue}
  222.     UndoEnd := nil;          {Rear of undo queue}
  223.     PromptCol := 1;          {Next cursor position on command line}
  224.     Blockop := False;        {A block operation has not occurred yet}
  225.     Blockhide := True;       {No block is showing}
  226.     MarkHide := False;       {Show marks when set}
  227.     Rundown := False;        {Set true when editor is ready to exit}
  228.     LastSearchOp := None;    {Controls operation of ^L command}
  229.     EditUsercommandInput := 0; {Number of chars user has pushed so far}
  230.     GotError := False;       {Indicates when error has occurred}
  231.     FreeListSpace := FreeListPerm; {Amount of free list space to keep free}
  232.     PromptForInput := True;  {Prompt for find/replace parameters}
  233.     PromptCol := 1;          {Column for start of cmd printing}
  234.     WindowCount := 0;        {No windows open}
  235.  
  236.     {Allocate window structures for later use}
  237.     WinStack := nil;
  238.     for I := 0 to MaxWindows do begin
  239.       New(P);
  240.       P^.FwdLink := WinStack;
  241.       WinStack := P;
  242.     end;
  243.  
  244.     {Initialize markers}
  245.     for I := 0 to MaxMarker do
  246.       Marker[I].Line := nil;
  247.     Blockfrom.Line := nil;
  248.     Blockto.Line := nil;
  249.  
  250.   end;                       {EdInitGlobals}
  251.  
  252. begin
  253.   EdInitGlobals;
  254. end.
  255.