home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w048 / 2.ddi / MSSRC.ARC / MSVARS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-12-21  |  16.3 KB  |  364 lines

  1. {                            MSVARS.PAS
  2.                                MS 4.0
  3.                 Copyright (c) 1985, 87 by Borland International, Inc.         }
  4.  
  5. {$I msdirect.inc}
  6.  
  7. unit MsVars;
  8.  
  9. interface
  10.  
  11. const
  12.   ProgName : string[8] = 'MS'; {Root name for support files}
  13.   Version = '4.0';           {Version number of editor}
  14.  
  15.   {Constants you may wish to customize}
  16.   Maxlinelength = 999;       {Maximum number of chars/text line}
  17.   Bufsize = 4096;            {Size of file global work buffer}
  18.   MaxMarker = 9;             {Maximum number of text markers, 0..MaxMarker}
  19.   MaxWindows = 6;            {Maximum number of text windows}
  20.   MinWindowLines = 2;        {Minimum rows in a text window}
  21.   FreeListTemp = 2000;       {Freelist bytes to keep free even for temporary requests}
  22.   FreeListPerm = 8000;       {Freelist bytes to keep free during permanent allocation requests}
  23.   MaxNumTabs = 20;           {Maximum number of tab stops per window}
  24.   PositionFindAtStart = False; {False to position cursor at END of search string}
  25.   MakeBackups = True;        {True to create backup files when saving}
  26.   OpeningMenu = False;       {True to bring up menus when no command line parameter is entered from DOS}
  27.   ShowMenuHelp = True;       {True to display continuous prompt about how to activate menu system}
  28.   CleanupAtExit = False;     {True to make MS clean up the heap upon exit}
  29.  
  30.   {Basic identities}
  31.   Line1 = 1;                 {Logical line number 1}
  32.   Col1 = 1;                  {Logical column number 1}
  33.   Null = #0;                 {Null character}
  34.  
  35.   {Masks used in the Linedesc record}
  36.   MaxPage = $0FFF;           {Low 12 bits of flag word are page number}
  37.   NewAttr = $1000;           {Set => attribute changes within line}
  38.   NewPage = $2000;           {Set => display page marker on screen}
  39.   InBlock = $4000;           {Set => display block in Blockcolor}
  40.   InMark = $8000;            {Set => line contains a marker}
  41.  
  42.   {Miscellaneous constant strings}
  43.   NoFile : string[6] = 'NONAME'; {Name of window with no file}
  44.   EolMark : string[2] = ^M^J; {Indicates end of line}
  45.   EopMark : string[1] = ^L;  {String used to terminate pages}
  46.   Period : Char = '.';
  47.   Blank : Char = ' ';
  48.  
  49.   Months : string[36] =      {Names of months}
  50.   'JanFebMarAprMayJunJulAugSepOctNovDec';
  51.  
  52.   FormatCommands : string[41] = {Names of print formatting commands}
  53.   {0        1         2         3         4         5         6}
  54.   {123456789012345678901234567890123456789012345678901234567890}
  55.   'PA CP PN PL MT MB PO HM FM OP PG HE FO PC';
  56.  
  57.   FormatChar : Char = '@';   {Character used to indicate print format command}
  58.  
  59.   OnOff : array[False..True] of string[3] = {Used for toggle status}
  60.   ('OFF', ' ON');
  61.  
  62.   ExeExt : string[3] = 'EXE';
  63.  
  64. type
  65.   ExtString = string[3];     {File extensions}
  66.   Filename = string[14];     {DOS filename without path, with room for padding}
  67.   Filepath = string[64];     {DOS pathname}
  68.   VarString = string[80];    {String for screen messages}
  69.  
  70.   Charset = set of Char;     {General purpose for character sets}
  71.   WorkBuffer = array[0..Bufsize] of Char; {Buffer for file, block, search operations}
  72.   CaseChange = (ToUpper, ToLower, Toggle); {Used in case changing operations}
  73.  
  74.   TextLine = array[0..Maxlinelength] of Char; {Can hold the text of one line}
  75.   PtextLine = ^TextLine;
  76.   PlineDesc = ^Linedesc;
  77.   TabArray = array[1..MaxNumTabs] of Integer; {Holds tab columns}
  78.  
  79.   Linedesc =                 {A complete text line, with links}
  80.   record
  81.     Fwdlink : PlineDesc;     {Ptr to previous line in stream - MUST BE FIRST FIELD}
  82.     Backlink : PlineDesc;    {Ptr to next line in stream - MUST BE SECOND FIELD}
  83.     Txt : PtextLine;         {Ptr to text buffer}
  84.     Flags : Word;            {Packed flags word - see bit masks above}
  85.     Bufflen : Integer;       {Holds current length of text buffer}
  86.     Font : Byte;             {Font the line starts with}
  87.   end;
  88.  
  89.   BlockMarker =              {Describes a unique position in text stream}
  90.   record
  91.     Line : PlineDesc;
  92.     Col : Integer;
  93.   end;
  94.   MarkArray = array[0..MaxMarker] of BlockMarker;
  95.  
  96.   Pwindesc = ^WinDesc;
  97.   WinDesc =                  {Describes each window on screen}
  98.   record
  99.     Fwdlink : Pwindesc;      {Next window down - MUST BE FIRST FIELD}
  100.     Backlink : Pwindesc;     {Next window up - MUST BE SECOND FIELD}
  101.     Firstlineno : Integer;   {Screen row number of window status line}
  102.     Lastlineno : Integer;    {Screen row number of last text line}
  103.     Firsttextno : Integer;   {Screen row number of first text line}
  104.     Filename : Filepath;     {File being edited}
  105.     Insertflag : Boolean;    {Insert mode}
  106.     AI : Boolean;            {Autoindent mode}
  107.     WW : Boolean;            {WordWrap mode - enables paragraph reformat}
  108.     TL : Boolean;            {Tab line display}
  109.     JU : Boolean;            {Right justification}
  110.     PA : Boolean;            {Paginated}
  111.     AT : Boolean;            {Attributes displayed}
  112.     FT : Boolean;            {Fixed tabs displayed}
  113.     CW : Boolean;            {Compress line when wrapping}
  114.     Modified : Boolean;      {True when save is required}
  115.     PaginationDone : Boolean; {True when pagination has run through entire file}
  116.     Wmargin : Integer;       {Wrap margin column number}
  117.     Lmargin : Integer;       {Left margin column number}
  118.     Rmargin : Integer;       {Right margin column number}
  119.     PageLen : Integer;       {Default page length}
  120.     Tmargin : Integer;       {Default top margin}
  121.     Bmargin : Integer;       {Default bottom margin}
  122.     CPagelen : Integer;      {Current page length for on-screen pagination}
  123.     CTmargin : Integer;      {Current top margin for on-screen pagination}
  124.     CBmargin : Integer;      {Current bottom margin for on-screen pagination}
  125.     Clnum : Integer;         {Line number in page at point of pagination interruption}
  126.     Lineno : Integer;        {Line number relative to screen, 1..25}
  127.     Colno : Integer;         {Last cursor address}
  128.     Clineno : Word;          {Display only: line in file}
  129.     Crelpos : LongInt;       {Display only: relative position in file}
  130.     TlineNo : Word;          {Total lines in file}
  131.     TcharNo : LongInt;       {Total bytes in file}
  132.     Tpageno : Integer;       {Total pages in file}
  133.     TopLine : PlineDesc;     {Ptr to first line in view}
  134.     Curline : PlineDesc;     {Ptr to current line}
  135.     PageLine : PlineDesc;    {Ptr to last line with accurate pagination}
  136.     WmarginLine : PlineDesc; {Ptr to line where wmargin was set}
  137.     Stream : Word;           {Unique text stream id}
  138.     Leftedge : Integer;      {Leftmost displayed text column}
  139.     Leftcol : Integer;       {Screen column offset where text display starts}
  140.     Visible : Boolean;       {True if window shows on screen}
  141.     Tabs : TabArray;         {Tab stop settings}
  142.   end;
  143.  
  144.   ZoomDesc =                 {Former size of currently zoomed window}
  145.   record
  146.     Firstlineno : Integer;   {Physical top line number}
  147.     Lastlineno : Integer;    {Physical bottom line number}
  148.   end;
  149.  
  150. type
  151.   PrintCommandtype =
  152.   (PrtInit,                  {Initialization/reset}
  153.    PrtBold,                  {Bolding on/off - keep second}
  154.    PrtDbl,                   {Doublestrike on/off}
  155.    PrtUnd,                   {Underline on/off}
  156.    PrtSup,                   {Superscript on/off}
  157.    PrtSub,                   {Subscript on/off}
  158.    PrtAlt1,                  {Alternate font 1 on/off}
  159.    PrtAlt2,                  {Alternate font 2 on/off - keep next to last}
  160.    PrtNone                   {Used only as terminator}
  161.    );
  162.   PrintCommandMap = array[#0..#255] of PrintCommandtype; {Print command associated with each ASCII character}
  163.  
  164.  
  165. const
  166.  
  167.   {Used by various word oriented commands}
  168.   {Punctuation symbols are for consistency with Turbo editor}
  169.   Alphas : Charset =         {Used in word oriented operations}
  170.   ['A'..'Z', 'a'..'z', '0'..'9', '%', '@', '_', '|', '"', '?', ';', #128..#254];
  171.  
  172.   SentenceEnd : Charset =    {Used in sentence oriented operations}
  173.   ['.', '?', '!', ';'];
  174.  
  175.   WordDelimiters : string[34] = {Used by EditScanPat for whole word searches}
  176.   #32#9#13#10#39',./?;:"<>[]{}-=\+|()*%@&^$#!~';
  177.  
  178.   PrtCmdSet : Charset =      {Characters to scroll around print setup menu}
  179.   [^J, ^M, ^[ , ^E, ^X];
  180.  
  181.   {Marks start of INSTALLATION AREA}
  182.   MainIDstring : string[22] = 'MAIN INSTALLATION AREA';
  183.  
  184.   {Common to all windows}
  185.   SaveUndoLimit : Integer = 20; {Default number of lines for undo queue}
  186.   DefExtension : string[3] = ''; {Default extension applied to filenames}
  187.   SaveTabSize : Integer = 8; {Spacing of default tabs}
  188.   ReadExpandTabs : Boolean = True; {True if tabs are expanded to spaces on read-in}
  189.   WriteCompressTabs : Boolean = False; {True if spaces are compressed to tabs on file writes}
  190.   SaveDeviceName : Filepath = 'PLAIN.PDF'; {Default printer configuration}
  191.   SaveOutputName : Filepath = ''; {Default printer output file}
  192.   SavePrinterPort : Byte = 0; {Default printer port - 0 for LPT1, 1 for LPT2}
  193.   SaveToFile : Boolean = False; {True if printing is done to file}
  194.   SaveFormatState : Boolean = True; {True to format printed documents}
  195.   SaveStripMode : Boolean = False; {True to convert WordStar DOC files on read-in}
  196.   SaveSupportPath : Filepath = ''; {Drive:Path to support files - MS.HLP, MS.DCT, MS.MAC}
  197.   SaveKeyHelpMode : Boolean = True; {Keystroke help displayed in menus}
  198.   SaveInitZoomState : Boolean = False; {Initial zoom state}
  199.  
  200.   {Set up by independent toggles for each window}
  201.   SaveInsertMode : Boolean = True; {Default to insert mode ON}
  202.   SaveIndentMode : Boolean = True; {Default to indent mode ON}
  203.   SaveWWmode : Boolean = True; {Default to word wrap mode ON}
  204.   SaveJustMode : Boolean = False; {Default to right justification OFF}
  205.   SavePageMode : Boolean = False; {Default to pagination OFF}
  206.   SaveAttrMode : Boolean = True; {Default to attribute display ON}
  207.   SaveFTmode : Boolean = True; {Default to using fixed tabs}
  208.   SaveTabMode : Boolean = True; {Default to tab line displayed}
  209.   SaveLeftMargin : Integer = 1; {Default left margin for word wrap}
  210.   SaveRightMargin : Integer = 65; {Default right margin for word wrap}
  211.   SaveTopMargin : Integer = 3; {Length of top margin}
  212.   SaveBottomMargin : Integer = 8; {Length of bottom margin}
  213.   SavePageLen : Integer = 66; {Length of default page}
  214.   SaveCompressWrap : Boolean = True; {True to compress lines before wrapping}
  215.  
  216.   {End of INSTALLATION AREA}
  217.   LastMainDefault : Byte = 0;
  218.  
  219. var
  220.   {Keyboard-related}
  221.   EditUsercommandInput : Integer; {Count of chars pushed by UserCommand}
  222.  
  223.   {Markers}
  224.   Blockfrom : BlockMarker;   {Points to beginning of block}
  225.   Blockto : BlockMarker;     {Points to end of block}
  226.   Curlineto : BlockMarker;   {Used in current line buffering wrt marked blocks}
  227.   Curlinefrom : BlockMarker; {Used in current line buffering wrt marked blocks}
  228.   LastPosition : BlockMarker; {Cursor position prior to current operation}
  229.   Marker : MarkArray;        {Text markers}
  230.   Blockop : Boolean;         {Set if a block operation just occurred}
  231.   Blockhide : Boolean;       {Set if block is not displayed}
  232.   Markhide : Boolean;        {set if marks are not displayed}
  233.  
  234.   {Macros}
  235.   UseExtendedSequence : Boolean; {False to interpret nulls individually}
  236.   Recording : Boolean;       {Set true to activate macro recording}
  237.  
  238.   {Window-related}
  239.   WindowCount : Integer;     {Number of text windows on screen, 0..MaxWindows}
  240.   Curwin : Pwindesc;         {Pointer to window containing cursor}
  241.   Window1 : Pwindesc;        {Pointer to window at top of screen}
  242.   WinStack : Pwindesc;       {Pointer to free list of windows}
  243.   ZoomWin : ZoomDesc;        {Holds Window zoom info}
  244.   Zoomed : Boolean;          {True when one window has zoomed to fill the screen}
  245.  
  246.   {Basic flags}
  247.   Rundown : Boolean;         {Determines when scheduler is done}
  248.   UpdateCursor : Boolean;    {Set if we must reposition cursor}
  249.   Goterror : Boolean;        {Set after any error, pollable by calling routine}
  250.   Abortcmd : Boolean;        {Set when AbortChar is pressed}
  251.   Aborting : Boolean;        {Stops recursion during abort}
  252.   AbortEnable : Boolean;     {Set when AbortChar is to be accepted as abort}
  253.   Intrflag : (NoInterr, Interr); {Set to Interrupt when keystrokes can interrupt screen writes}
  254.   Recurring : Boolean;       {Used to control Recursion during macro playback}
  255.   MarginRelease : Boolean;   {Set when word wrap not to be active}
  256.  
  257.   {Find and Replace}
  258.   PromptForInput : Boolean;  {Set False for Find Next operations}
  259.   LastSearchOp : (Find, Replace, RunMacro, None); {Whatever was done after last search}
  260.  
  261.   {Undo-related}
  262.   UndoCount : Integer;       {Number of lines currently on undo stack}
  263.   UndoLimit : Integer;       {Maximum number of lines on undo stack}
  264.   UndoStack : PlineDesc;     {First line on undo stack}
  265.   UndoEnd : PlineDesc;       {Last line on undo stack}
  266.   CurlineBuf : PlineDesc;    {Pointer to current line buffer for line restore}
  267.   Curlinecol : Integer;      {Column number upon entry to line}
  268.  
  269.   {File support}
  270.   WorkBuf : WorkBuffer;      {Buffer used for read/write speed, also for searching}
  271.   LastBlockRead : Filepath;  {Last file used in blockread}
  272.   LastBlockWrite : Filepath; {Last file used in blockwrite}
  273.   LastFileEdit : Filepath;   {Last file used in edit}
  274.   LastPrintFile : Filepath;  {Last file printed}
  275.   LastPrintOutput : Filepath; {Last printer output file}
  276.   LastDosCommand : VarString; {Last DOS command entered}
  277.   LastDirectory : VarString; {Last file directory mask}
  278.   SupportPath : Filepath;    {Path to the support files for this editor run}
  279.  
  280.   PrintMap : PrintCommandMap; {Maps control chars to printer toggle commands}
  281.  
  282.   FreeListSpace : Word;      {Dynamic amount of free list space to retain}
  283.  
  284.   {==========================================================================}
  285.  
  286. implementation
  287.  
  288.   procedure EdInitGlobals;
  289.   var
  290.     P : Pwindesc;
  291.     I : Integer;
  292.  
  293.   begin                      {EdInitGlobals}
  294.  
  295.     Intrflag := Interr;      {Allow interrupts of screen updates}
  296.     Abortcmd := False;       {Set by EditAbort to stop EditAskfor}
  297.     Aborting := False;       {Set by EditAbort to stop recursion}
  298.     AbortEnable := False;    {Disable AbortCmd until needed}
  299.  
  300.     if DefExtension = '' then
  301.       LastFileEdit := '*.*'
  302.     else
  303.       LastFileEdit := '*.'+DefExtension;
  304.     LastPrintFile := '';
  305.     LastBlockRead := '';
  306.     LastBlockWrite := '';
  307.     LastDosCommand := '';
  308.     LastDirectory := '';
  309.     LastPrintOutput := SaveOutputName;
  310.  
  311.     UndoCount := 0;          {Used by EditUndo and EditDelline}
  312.     UndoLimit := SaveUndoLimit; {Default size of undo buffer}
  313.     UndoStack := nil;        {Front of undo queue}
  314.     UndoEnd := nil;          {Rear of undo queue}
  315.     Blockop := False;        {A block operation has not occurred yet}
  316.     Blockhide := True;       {No block is showing}
  317.     Markhide := False;       {Show marks when set}
  318.     Rundown := False;        {Set true when editor is ready to exit}
  319.     LastSearchOp := None;    {Controls operation of ^L command}
  320.     Recording := False;      {Set true to activate macro recording}
  321.     Recurring := False;      {Set true when Find and Macro is playing macro}
  322.     EditUsercommandInput := 0; {Number of chars user has pushed so far}
  323.     Goterror := False;       {Indicates when error has occurred}
  324.     FreeListSpace := FreeListPerm; {Amount of free list to keep free}
  325.     PromptForInput := True;  {Prompt for find/replace parameters}
  326.     WindowCount := 0;        {No windows open}
  327.     MarginRelease := False;  {Margins are not released}
  328.     UseExtendedSequence := True; {Interpret Nulls by reading following character}
  329.  
  330.     {Allocate window structures for later use}
  331.     WinStack := nil;
  332.     for I := 0 to MaxWindows do begin
  333.       New(P);
  334.       P^.Fwdlink := WinStack;
  335.       WinStack := P;
  336.     end;
  337.  
  338.     {Initialize markers}
  339.     for I := 0 to MaxMarker do
  340.       Marker[I].Line := nil;
  341.     Blockfrom.Line := nil;
  342.     Blockto.Line := nil;
  343.  
  344.   end;                       {EdInitGlobals}
  345.  
  346.   procedure EdInitPrintMap;
  347.     {-Initialize the mapping between control chars and printer toggle commands}
  348.  
  349.   begin                      {EdInitPrintMap}
  350.     FillChar(PrintMap, SizeOf(PrintMap), PrtNone);
  351.     PrintMap[^B] := PrtBold;
  352.     PrintMap[^D] := PrtDbl;
  353.     PrintMap[^S] := PrtUnd;
  354.     PrintMap[^T] := PrtSup;
  355.     PrintMap[^V] := PrtSub;
  356.     PrintMap[^A] := PrtAlt1;
  357.     PrintMap[^N] := PrtAlt2;
  358.   end;                       {EdInitPrintMap}
  359.  
  360. begin
  361.   EdInitGlobals;
  362.   EdInitPrintMap;
  363. end.
  364.