home *** CD-ROM | disk | FTP | other *** search
- { MSUSER.PAS
- MS 4.0
- Copyright (c) 1985, 87 by Borland International, Inc. }
-
- {$I msdirect.inc}
-
- unit MsUser;
- {-User keyboard, prompt and error interactions}
-
- interface
-
- uses
- Crt, {Basic video}
- Dos, {DOS interface - standard unit}
- Errors, {Runtime error handler}
- MsVars, {Global types and declarations}
- MsScrn1, {Fast screen writing routines}
- MsString, {String primitives}
- MsPtrOp, {Primitive pointer operations}
- EscSeq, {Returns text string for extended scan codes}
- MsCmds, {Maps keystrokes to commands}
- Int24, {DOS critical error handler}
- Message; {Message system}
-
- const
- DefTypeahead = 256; {Capacity of typeahead buffer}
-
- type
- ScreenBuffer = array[0..1999] of Word; {Buffer for holding a text screen (size arbitrary)}
- WindowPtr = ^ScreenBuffer; {Points to a buffer holding screen contents}
-
- {Elements for drawing box borders}
- BorderElements = (TopLeft, TopRight, BotLeft, BotRight, Horiz, Vert, LeftJoin, RightJoin);
- BorderChars = array[BorderElements] of Char; {Holds characters used for box borders}
-
- WindowRec =
- record
- XPosn : Byte;
- YPosn : Byte;
- XSize : Byte;
- YSize : Byte;
- Overlap : WindowPtr;
- end;
-
- const
- MaxMenuDepth = 3; {Maximum depth of menus}
- MaxSelections = 20; {Maximum number of selections in one menu}
-
- type
- {Definitions for pulldown menu system}
-
- MenuOrientation = (Horizontal, Vertical); {Horizontal or vertical scrolling menus}
-
- MenuDescriptor =
- record
- Border : BorderChars; {Characters used for window borders}
- Orientation : MenuOrientation; {Horizontal or vertical}
- Overlap : WindowPtr; {Points to buffer holding what it covers}
- end;
-
- Menulevels = array[1..MaxMenuDepth] of MenuDescriptor;
-
- Menuptr = ^Menurecord;
-
- SubMenuRecord = {12 bytes}
- record
- Command : CommandType; {Editor command returned via selection}
- Doffset : Byte; {Rows or cols offset for prompt within window}
- StatVal : Byte; {Indicates whether entry display also has status info}
- Soffset : Byte; {Offset into prompt of Select char (for highlight)}
-
- Prompt : String255Ptr; {Points to string displayed for menu item}
- SubMenu : Menuptr; {Points to submenu if any}
- end;
-
- SubArray = array[1..MaxSelections] of SubMenuRecord;
-
- Menurecord = {12 bytes}
- record
- MenuLev : Byte; {Depth of this menu, points into MenuDescriptor array}
- XPosn : Byte; {X upper left. not border, but text position}
- YPosn : Byte; {Y upper left. not border, but text position}
- XSize : Byte; {Number of characters of text}
- YSize : Byte; {Number of lines of text}
- SubMax : Byte; {Number of selections or submenus}
-
- SubCur : Byte; {Currently active submenu or selection}
- SubOn : Boolean; {True if submenu is simultaneously displayed}
- SubMenus : ^SubArray; {Points to array of selections}
- end;
-
- {Definitions for custom popup menus}
-
- MenuArray = array[0..MaxSelections] of String255Ptr;
- MenuArrayPtr = ^MenuArray;
- CustomMenuRec = {Describes a custom menu}
- record
- Xmin : Byte; {Upper left x screen position}
- Ymin : Byte; {Upper left y screen position}
- Xmax : Byte; {Lower right x screen position}
- Ymax : Byte; {Lower right y screen position}
- MinChoice : Integer; {Lowest choice}
- MaxChoice : Integer; {Highest choice}
- InitChoice : Integer; {Initial choice}
- MessageNum : Integer; {Message for message line}
- PromptNum : Integer; {Message for menu box}
- Messages : MenuArrayPtr; {Points to strings to be displayed}
- CmdSet : Charset; {Acceptable selection characters}
- UseLetters : Boolean; {True to accept first char of string as command}
- end;
-
- const
- Border : BorderChars = '┌┐└┘─│├┤';
-
- {Command characters which drive custom menus}
- DirCmdSet : Charset = {Characters to scroll through file menu}
- [^M, ^[ , ^E, ^X, ^R, ^C, ^T, ^B,
- 'A'..'Z', '0'..'9', '!', '#'..')', '-',
- '@', '^', '`', '{', '}', '~'];
-
- NumCmdSet : Charset = {Characters to choose from numbered menus}
- [^J, ^M, ^[ , ^E, ^X, '0'..'9'];
-
- {Commands which leave the menu system on screen after completion}
- StayCommands : CmdSet =
- [
- CmdShowMem, {Show available memory}
- CmdSysInfo, {Show system information}
- CmdInvokeDOS, {Run DOS command}
- CmdDirectory, {Show directory}
- CmdPrintFile, {Print a file}
- CmdLogDrive, {Log drive or path}
- CmdTogglePaginate, {Toggle Pagination display}
- CmdToggleAttribute, {Toggle on-screen attribute display}
- CmdToggleInsert, {Toggle insert mode}
- CmdToggleAutoindent, {Toggle autoindent mode}
- CmdSetRightMargin, {Set the right margin for word wrap and reformat}
- CmdToggleWordWrap, {Toggle word wrap on or off}
- CmdSetLeftMargin, {Set the left margin for word wrap}
- CmdToggleJustify, {Toggle right justification}
- CmdToggleTabLine, {Toggle tab line display}
- CmdSetTabSize, {Set default tab size}
- CmdSetTopMargin, {Set default top margin}
- CmdSetBotMargin, {Set default bottom margin}
- CmdSetPageLength, {Set default page length}
- CmdSetUndoLimit, {Set default undo limit}
- CmdToggleTabExpansion, {Toggle tab expansion on read-in}
- CmdToggleTabMode, {Toggle between fixed and "smart" tabs}
- CmdGetDefaultExtension, {Get a new default file extension}
- CmdSetSupportPath, {Set the path to all the support files}
- CmdToggleStripMode, {Toggle high bit stripping on read-in}
- CmdEditMacro, {Edit a macro}
- CmdToggleKeyHelp, {Toggle display of keyboard help in menu system}
- CmdSaveDefaults, {Save colors, toggles, etc for next time}
- CmdSetColors, {Set editor colors}
- CmdToggleRetraceMode, {Toggle snow checking}
- CmdToggleSolidCursor, {Toggle block cursor mode}
- CmdToggleEga43Line, {Toggle EGA 43 line mode}
- CmdToggleInitZoomState, {Toggle default zoom state}
- CmdEditTabLine, {Interactively edit the tabs}
- CmdPromptSetMarker, {Prompt for a marker number to set}
- CmdToggleWriteTabs, {Toggle tabs written to compress output}
- CmdToggleCompressWrap, {Toggle compression prior to wrap}
- CmdHelpMenu {Put up the help summary}
- ];
-
- {Commands accessible with no windows open}
- MainCommands : CmdSet =
- [
- CmdNullMain, {Lets us access certain submenus}
- CmdAddWindow, {Add second window with same or different file}
- CmdAbandonFile, {Abandon file, quit editor}
- CmdSysInfo, {Show system information}
- CmdShowMem, {Show available memory}
- CmdInvokeDOS, {Run DOS command}
- CmdPrintFile, {Print a file}
- CmdLogDrive, {Log drive or path}
- CmdDirectory, {Show directory}
- CmdSetUndoLimit, {Set default undo limit}
- CmdGetDefaultExtension, {Get a new default file extension}
- CmdSetTabSize, {Set default tab size}
- CmdToggleTabExpansion, {Toggle tab expansion on read-in}
- CmdToggleWriteTabs, {Toggle tabs written to compress output}
- CmdToggleStripMode, {Toggle high bit stripping on read-in}
- CmdSetColors, {Set editor colors}
- CmdSetSupportPath, {Set the path to all the support files}
- CmdToggleKeyHelp, {Toggle display of keyboard help in menu system}
- CmdSaveDefaults, {Save colors, toggles, etc for next time}
- CmdToggleRetraceMode, {Toggle snow checking}
- CmdToggleSolidCursor, {Toggle block cursor mode}
- CmdToggleEga43Line, {Toggle EGA 43 line mode}
- CmdToggleInitZoomState, {Toggle default zoom state}
- CmdHelpMenu {Help summary menu}
- ];
-
- var
- MenuDesc : Menulevels; {General specification of each menu level}
- RootMenu : Menuptr; {The menu that starts it all}
- CurrMenu : Menuptr; {Currently active menu}
- ExitMenu : Boolean; {False to loop within menu system}
-
- const
- HelpFileExt : ExtString = 'HLP'; {Extension for help file}
-
- var
- {Help system}
- HelpAvailable : Boolean; {Set if the help file is found}
- Helpf : file; {Indexed file of help information, always kept open}
-
- const
- PrintBufferSize = 512; {Bytes to read at a swoop from file being printed}
- PrintCommandSize = 32; {Maximum length of a printer formatting command}
- PrintStackSize = 1024; {Size of printer command/header stack}
- MaxHeaderChars = 256; {Maximum number of characters in a header or footer}
- CharsPerPrintBlock = 4; {Number of chars printed to printer in each time slice}
- CharsPerFileBlock = 32; {Number of chars printed to file per time slice}
-
- type
- {Printer command sequences}
- PrintCommand = string[PrintCommandSize];
- PrintCommandPair = array[False..True] of PrintCommand;
- PrintCommandStrings = array[PrintCommandtype] of PrintCommandPair;
- PrinterDefinition = {Describes characteristics of a particular printer}
- record
- Commands : PrintCommandStrings; {Strings for font control}
- FormfeedMode : Boolean; {True to eject page via formfeed}
- PaperPause : Boolean; {True to pause at end of page}
- end;
- PrintFontState = array[PrintCommandtype] of Boolean;
- PrintStack = array[0..PrintStackSize] of Char; {Holds about to be printed characters}
- PrintBuffer = array[1..PrintBufferSize] of Char; {Holds text waiting to be formatted for printing}
-
- PrintRecord = {Information regarding the current print job}
- record
- PrintFilename : Filepath; {File name being printed}
- PrintFile : file; {File being printed}
- OutFilename : Filepath; {Output file name if ToFile is true}
- OutFile : file of Char; {Output file if ToFile is true}
- StartPage : Integer; {First page to print}
- StopPage : Integer; {Last page to print}
- ToFile : Boolean; {True if printing to file}
- Printer : Byte; {0 for LPT1, 1 for LPT2}
- Format : Boolean; {True to interpret dot commands}
- FontState : PrintFontState; {What fonts are active}
- PendingFontState : PrintFontState; {What fonts are being sent to printer}
- PushStart : Boolean; {True if header not yet inserted on current page}
- PushEnd : Boolean; {True if footer not yet inserted on current page}
- NewLine : Boolean; {True at begin of a new line}
- PrinterInit : Boolean; {True until printer init codes are printed}
- LastPage : Boolean; {True when last page is being printed}
- ShowPageNum : Boolean; {True for page numbers to print in footer}
- Column : Integer; {Current position in line}
- Line : Integer; {Current line on page}
- PageNum : Integer; {Current page}
- Pagecol : Integer; {Column for default page numbers}
- PageLen : Integer; {Current page length}
- Tmargin : Integer; {Top of page to text}
- Bmargin : Integer; {Bottom of text to bottom of page}
- Loffset : Integer; {Current left offset}
- HTMargin : Integer; {Top of page to header}
- FBMargin : Integer; {Footer to bottom of page}
- Header : String255; {Current header string}
- Footer : String255; {Current footer string}
- Buffer : PrintBuffer; {Characters to be printed}
- BufferPtr : Integer; {Position in character buffer}
- BufferChars : Integer; {Number of characters in buffer}
- Stack : PrintStack; {Translated characters awaiting printout}
- StackIndex : Integer; {Number of translated chars currently stacked}
- Devicename : Filepath; {Printer type description file name}
- end;
-
- var
- Printing : Boolean; {True if print job in progress}
- PrintJob : PrintRecord; {Describes the current print job}
- PrintDef : PrinterDefinition; {Describes the currently selected printer}
- PrintChars : Integer; {Number of chars to print in a time slice}
-
- const
- MaxMacro = 9; {Maximum number of macros, 0..MaxMacro}
- MaxMacroLength = 255; {Maximum length of a macro sequence, <=255}
- MacroSignature : string[6] = 'MACROS'; {At the beginning of every macro file}
- MacroFileExt : ExtString = 'MAC';
-
- type
- MacroString = string[MaxMacroLength]; {String for recorded keystroke sequences}
- MacroName = string[255];
- MacroNamePtr = ^MacroName;
- MacroArray = array[0..MaxMacro] of MacroString;
-
- var
- Macrokeys : MacroArray; {Records macros for playback}
- Macronames : array[0..MaxMacro] of MacroNamePtr; {Points to name for each macro}
- Macronum : Integer; {Macro number used by EditFindAndMacro}
-
-
- procedure EdPrintExit;
- {-Quit printing}
-
- procedure EdPrintNext(PrintChars : Integer);
- {-Background process to print the next PrintChars characters of print job}
-
- procedure EdPushPrintString(S : PrintCommand);
- {-Push a command string onto print stack}
-
- function EdGetInput : Char;
- {-Read next character from typeahead buffer}
-
- function EdKeyPressed : Boolean;
- {-Determine if input is available}
-
- function EdKeyInterrupt : Boolean;
- {-Determine whether a keystroke should interrupt background processes}
-
- procedure EdBreathe;
- {-Stimulate typeahead routines without returning a character}
-
- procedure EdUserPush(S : String255);
- {-Push string onto typeahead buffer}
-
- procedure EdWaitforKey;
- {-Tight loop waiting for keystroke}
-
- function EdGetAnyChar : Char;
- {-Wait for and return a character from internal keyboard buffer}
-
- function EdGetCursorCommand(CmdSet : Charset) : Char;
- {-Return a legal cursor command, WordStar style}
-
- procedure EdClearBuffer;
- {-Clear keyboard buffer}
-
- procedure EdSetInsertMode(Inserting : Boolean);
- {-Keep the cursor appearance and BIOS keyboard flag up to date}
-
- procedure EdUpdateCursor;
- {-Move the cursor to the right spot}
-
- procedure EdUpdateCmdLine;
- {-Update the message line}
-
- procedure EdEraseMenuHelp;
- {-Remove menu help from the prompt line}
-
- procedure EdShowMenuHelp;
- {-Put the menu help into the prompt line}
-
- procedure EdAppPromptLine(S : VarString);
- {-Append command name to message line}
-
- procedure EdZapPromptLine;
- {-Zap message line, leaving it blank}
-
- procedure EdResetPromptLine;
- {-Clear partial command indicator from command line}
-
- procedure EdWritePromptLine(S : VarString);
- {-Write a new message line to the screen}
-
- procedure EdForceMessage(msg : VarString);
- {-Guarantee that a message is displayed}
-
- procedure EdDisplayCommandBuffer;
- {-Indicate that a partial command has been entered}
-
- procedure EdWait;
- {-Display a Wait signal}
-
- function EdYcenterWindow(Rows : Byte) : Byte;
- {-Return a legal row number centered in the current window}
-
- procedure EdDrawBox(Border : BorderChars;
- XPosn, YPosn, XSize, YSize : Byte;
- BoxAttr : BoxType);
- {-Draw a box frame on the screen}
-
- function EdSetupWindow(Border : BorderChars;
- XLow, YLow, XHigh, YHigh : Byte;
- BoxAttr : BoxType) : WindowPtr;
- {-Save current screen and set up a new window}
-
- procedure EdRestoreWindow(var W : WindowPtr;
- XPosn, YPosn, XSize, YSize : Byte);
- {-Given a pointer to a WindowRec, restore the contents of the window}
-
- procedure EdSaveTextWindow(Border : BorderChars;
- Title : VarString;
- XLow, YLow, XHigh, YHigh : Byte;
- var W : WindowRec);
- {-Save existing screen and set up a new text window}
-
- procedure EdRestoreTextWindow(W : WindowRec);
- {Given a pointer to a WindowRec, restore the contents of the window}
-
- procedure EdDisplayPromptWindow(msg : VarString; Yp : Integer;
- OKset : Charset; var Ch : Char;
- BoxAttr : BoxType);
- {-Display a one line message, and wait for char to clear it}
-
- procedure EdErrormsg(Msgno : Integer);
- {-Write error message and dump typeahead buffer}
-
- function EdFileerror : Boolean;
- {-Report error during file operation}
-
- procedure EdBlockWrite(var F : file; var Buf; Num : Word);
- {-Write a block and check for errors}
-
- procedure EdBlockRead(var F : file; var Buf; Num : Word; var BytesRead);
- {-Read a block and check for errors}
-
- procedure EdAskforEditor(Xp, Yp, XSize, Maxlen : Integer; HaveWindow : Boolean; var Rs : VarString);
- {-Perform line editing functions for string input}
-
- procedure EdAskfor(Prompt : VarString; Xp, Yp, Wid : Integer; var Rs : VarString);
- {-Edit and return a string}
-
- procedure EdArg2Integer(Arg : String255; Min, Max : Integer; var V);
- {-Convert string to integer. Clip at min and max}
-
- procedure EdString2integer(Src : VarString; var R);
- {-Convert string to integer. 0 returned may mean ERROR - check GotError}
-
- function EdYesNo(Prompt : VarString) : Boolean;
- {-Return True for Yes, False for No}
-
- function EdGetnumber(Prompt : VarString; Default : Integer) : Integer;
- {-Prompt for and return a number, 0 if invalid or empty}
- {-Plus or minus in input strings return results relative to default}
-
- procedure EdSetNumber(var Num; msg, Min, Max : Integer; var Empty : Boolean);
- {-Prompt for and set an integer value in range min..max}
-
- procedure EdHelpWindow(Cmd : CommandType);
- {-Display help for the specified command}
-
- {==========================================================================}
-
- implementation
-
- const
- {Following two must be matched with those in MSINST}
- HelpWidth = 60; {Max line length of help window}
- HelpHeight = 15; {Number of rows of help window}
-
- type
- HelpIndexRec = {File position and block length of help sections}
- record
- Start : LongInt;
- Len : Word;
- end;
-
- PrintErrorType = {Errors that may occur during printing}
- (PrtFileRead,
- PrtOutPaper,
- PrtOffLine,
- PrtNoResponse,
- PrtFileWrite,
- PrtCmdTooLong,
- PrtUnknown
- );
-
- {$I MSPRINT.INC}
- {$I MSKEYBRD.INC}
- {$I MSCURSOR.INC}
- {$I MSPROMPT.INC}
- {$I MSWINDOW.INC}
- {$I MSUSERIO.INC}
- {$I MSFILEIO.INC}
- {$I MSHELP.INC}
-
- begin
- {Assure break checking is off}
- CheckBreak := False;
- {No buffered keystrokes}
- Circin := 0;
- Circout := 0;
- {Command line editor starts in insert mode}
- AskforInsertflag := True;
- end.