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

  1. {                            MSUSER.PAS
  2.                                MS 4.0
  3.                 Copyright (c) 1985, 87 by Borland International, Inc.         }
  4.  
  5. {$I msdirect.inc}
  6.  
  7. unit MsUser;
  8.   {-User keyboard, prompt and error interactions}
  9.  
  10. interface
  11.  
  12. uses
  13.   Crt,                       {Basic video}
  14.   Dos,                       {DOS interface - standard unit}
  15.   Errors,                    {Runtime error handler}
  16.   MsVars,                    {Global types and declarations}
  17.   MsScrn1,                   {Fast screen writing routines}
  18.   MsString,                  {String primitives}
  19.   MsPtrOp,                   {Primitive pointer operations}
  20.   EscSeq,                    {Returns text string for extended scan codes}
  21.   MsCmds,                    {Maps keystrokes to commands}
  22.   Int24,                     {DOS critical error handler}
  23.   Message;                   {Message system}
  24.  
  25. const
  26.   DefTypeahead = 256;        {Capacity of typeahead buffer}
  27.  
  28. type
  29.   ScreenBuffer = array[0..1999] of Word; {Buffer for holding a text screen (size arbitrary)}
  30.   WindowPtr = ^ScreenBuffer; {Points to a buffer holding screen contents}
  31.  
  32.   {Elements for drawing box borders}
  33.   BorderElements = (TopLeft, TopRight, BotLeft, BotRight, Horiz, Vert, LeftJoin, RightJoin);
  34.   BorderChars = array[BorderElements] of Char; {Holds characters used for box borders}
  35.  
  36.   WindowRec =
  37.   record
  38.     XPosn : Byte;
  39.     YPosn : Byte;
  40.     XSize : Byte;
  41.     YSize : Byte;
  42.     Overlap : WindowPtr;
  43.   end;
  44.  
  45. const
  46.   MaxMenuDepth = 3;          {Maximum depth of menus}
  47.   MaxSelections = 20;        {Maximum number of selections in one menu}
  48.  
  49. type
  50.   {Definitions for pulldown menu system}
  51.  
  52.   MenuOrientation = (Horizontal, Vertical); {Horizontal or vertical scrolling menus}
  53.  
  54.   MenuDescriptor =
  55.   record
  56.     Border : BorderChars;    {Characters used for window borders}
  57.     Orientation : MenuOrientation; {Horizontal or vertical}
  58.     Overlap : WindowPtr;     {Points to buffer holding what it covers}
  59.   end;
  60.  
  61.   Menulevels = array[1..MaxMenuDepth] of MenuDescriptor;
  62.  
  63.   Menuptr = ^Menurecord;
  64.  
  65.   SubMenuRecord =            {12 bytes}
  66.   record
  67.     Command : CommandType;   {Editor command returned via selection}
  68.     Doffset : Byte;          {Rows or cols offset for prompt within window}
  69.     StatVal : Byte;          {Indicates whether entry display also has status info}
  70.     Soffset : Byte;          {Offset into prompt of Select char (for highlight)}
  71.  
  72.     Prompt : String255Ptr;   {Points to string displayed for menu item}
  73.     SubMenu : Menuptr;       {Points to submenu if any}
  74.   end;
  75.  
  76.   SubArray = array[1..MaxSelections] of SubMenuRecord;
  77.  
  78.   Menurecord =               {12 bytes}
  79.   record
  80.     MenuLev : Byte;          {Depth of this menu, points into MenuDescriptor array}
  81.     XPosn : Byte;            {X upper left. not border, but text position}
  82.     YPosn : Byte;            {Y upper left. not border, but text position}
  83.     XSize : Byte;            {Number of characters of text}
  84.     YSize : Byte;            {Number of lines of text}
  85.     SubMax : Byte;           {Number of selections or submenus}
  86.  
  87.     SubCur : Byte;           {Currently active submenu or selection}
  88.     SubOn : Boolean;         {True if submenu is simultaneously displayed}
  89.     SubMenus : ^SubArray;    {Points to array of selections}
  90.   end;
  91.  
  92.   {Definitions for custom popup menus}
  93.  
  94.   MenuArray = array[0..MaxSelections] of String255Ptr;
  95.   MenuArrayPtr = ^MenuArray;
  96.   CustomMenuRec =            {Describes a custom menu}
  97.   record
  98.     Xmin : Byte;             {Upper left x screen position}
  99.     Ymin : Byte;             {Upper left y screen position}
  100.     Xmax : Byte;             {Lower right x screen position}
  101.     Ymax : Byte;             {Lower right y screen position}
  102.     MinChoice : Integer;     {Lowest choice}
  103.     MaxChoice : Integer;     {Highest choice}
  104.     InitChoice : Integer;    {Initial choice}
  105.     MessageNum : Integer;    {Message for message line}
  106.     PromptNum : Integer;     {Message for menu box}
  107.     Messages : MenuArrayPtr; {Points to strings to be displayed}
  108.     CmdSet : Charset;        {Acceptable selection characters}
  109.     UseLetters : Boolean;    {True to accept first char of string as command}
  110.   end;
  111.  
  112. const
  113.   Border : BorderChars = '┌┐└┘─│├┤';
  114.  
  115.   {Command characters which drive custom menus}
  116.   DirCmdSet : Charset =      {Characters to scroll through file menu}
  117.   [^M, ^[ , ^E, ^X, ^R, ^C, ^T, ^B,
  118.    'A'..'Z', '0'..'9', '!', '#'..')', '-',
  119.    '@', '^', '`', '{', '}', '~'];
  120.  
  121.   NumCmdSet : Charset =      {Characters to choose from numbered menus}
  122.   [^J, ^M, ^[ , ^E, ^X, '0'..'9'];
  123.  
  124.   {Commands which leave the menu system on screen after completion}
  125.   StayCommands : CmdSet =
  126.   [
  127.   CmdShowMem,                {Show available memory}
  128.   CmdSysInfo,                {Show system information}
  129.   CmdInvokeDOS,              {Run DOS command}
  130.   CmdDirectory,              {Show directory}
  131.   CmdPrintFile,              {Print a file}
  132.   CmdLogDrive,               {Log drive or path}
  133.   CmdTogglePaginate,         {Toggle Pagination display}
  134.   CmdToggleAttribute,        {Toggle on-screen attribute display}
  135.   CmdToggleInsert,           {Toggle insert mode}
  136.   CmdToggleAutoindent,       {Toggle autoindent mode}
  137.   CmdSetRightMargin,         {Set the right margin for word wrap and reformat}
  138.   CmdToggleWordWrap,         {Toggle word wrap on or off}
  139.   CmdSetLeftMargin,          {Set the left margin for word wrap}
  140.   CmdToggleJustify,          {Toggle right justification}
  141.   CmdToggleTabLine,          {Toggle tab line display}
  142.   CmdSetTabSize,             {Set default tab size}
  143.   CmdSetTopMargin,           {Set default top margin}
  144.   CmdSetBotMargin,           {Set default bottom margin}
  145.   CmdSetPageLength,          {Set default page length}
  146.   CmdSetUndoLimit,           {Set default undo limit}
  147.   CmdToggleTabExpansion,     {Toggle tab expansion on read-in}
  148.   CmdToggleTabMode,          {Toggle between fixed and "smart" tabs}
  149.   CmdGetDefaultExtension,    {Get a new default file extension}
  150.   CmdSetSupportPath,         {Set the path to all the support files}
  151.   CmdToggleStripMode,        {Toggle high bit stripping on read-in}
  152.   CmdEditMacro,              {Edit a macro}
  153.   CmdToggleKeyHelp,          {Toggle display of keyboard help in menu system}
  154.   CmdSaveDefaults,           {Save colors, toggles, etc for next time}
  155.   CmdSetColors,              {Set editor colors}
  156.   CmdToggleRetraceMode,      {Toggle snow checking}
  157.   CmdToggleSolidCursor,      {Toggle block cursor mode}
  158.   CmdToggleEga43Line,        {Toggle EGA 43 line mode}
  159.   CmdToggleInitZoomState,    {Toggle default zoom state}
  160.   CmdEditTabLine,            {Interactively edit the tabs}
  161.   CmdPromptSetMarker,        {Prompt for a marker number to set}
  162.   CmdToggleWriteTabs,        {Toggle tabs written to compress output}
  163.   CmdToggleCompressWrap,     {Toggle compression prior to wrap}
  164.   CmdHelpMenu                {Put up the help summary}
  165.   ];
  166.  
  167.   {Commands accessible with no windows open}
  168.   MainCommands : CmdSet =
  169.   [
  170.   CmdNullMain,               {Lets us access certain submenus}
  171.   CmdAddWindow,              {Add second window with same or different file}
  172.   CmdAbandonFile,            {Abandon file, quit editor}
  173.   CmdSysInfo,                {Show system information}
  174.   CmdShowMem,                {Show available memory}
  175.   CmdInvokeDOS,              {Run DOS command}
  176.   CmdPrintFile,              {Print a file}
  177.   CmdLogDrive,               {Log drive or path}
  178.   CmdDirectory,              {Show directory}
  179.   CmdSetUndoLimit,           {Set default undo limit}
  180.   CmdGetDefaultExtension,    {Get a new default file extension}
  181.   CmdSetTabSize,             {Set default tab size}
  182.   CmdToggleTabExpansion,     {Toggle tab expansion on read-in}
  183.   CmdToggleWriteTabs,        {Toggle tabs written to compress output}
  184.   CmdToggleStripMode,        {Toggle high bit stripping on read-in}
  185.   CmdSetColors,              {Set editor colors}
  186.   CmdSetSupportPath,         {Set the path to all the support files}
  187.   CmdToggleKeyHelp,          {Toggle display of keyboard help in menu system}
  188.   CmdSaveDefaults,           {Save colors, toggles, etc for next time}
  189.   CmdToggleRetraceMode,      {Toggle snow checking}
  190.   CmdToggleSolidCursor,      {Toggle block cursor mode}
  191.   CmdToggleEga43Line,        {Toggle EGA 43 line mode}
  192.   CmdToggleInitZoomState,    {Toggle default zoom state}
  193.   CmdHelpMenu                {Help summary menu}
  194.   ];
  195.  
  196. var
  197.   MenuDesc : Menulevels;     {General specification of each menu level}
  198.   RootMenu : Menuptr;        {The menu that starts it all}
  199.   CurrMenu : Menuptr;        {Currently active menu}
  200.   ExitMenu : Boolean;        {False to loop within menu system}
  201.  
  202. const
  203.   HelpFileExt : ExtString = 'HLP'; {Extension for help file}
  204.  
  205. var
  206.   {Help system}
  207.   HelpAvailable : Boolean;   {Set if the help file is found}
  208.   Helpf : file;              {Indexed file of help information, always kept open}
  209.  
  210. const
  211.   PrintBufferSize = 512;     {Bytes to read at a swoop from file being printed}
  212.   PrintCommandSize = 32;     {Maximum length of a printer formatting command}
  213.   PrintStackSize = 1024;     {Size of printer command/header stack}
  214.   MaxHeaderChars = 256;      {Maximum number of characters in a header or footer}
  215.   CharsPerPrintBlock = 4;    {Number of chars printed to printer in each time slice}
  216.   CharsPerFileBlock = 32;    {Number of chars printed to file per time slice}
  217.  
  218. type
  219.   {Printer command sequences}
  220.   PrintCommand = string[PrintCommandSize];
  221.   PrintCommandPair = array[False..True] of PrintCommand;
  222.   PrintCommandStrings = array[PrintCommandtype] of PrintCommandPair;
  223.   PrinterDefinition =        {Describes characteristics of a particular printer}
  224.   record
  225.     Commands : PrintCommandStrings; {Strings for font control}
  226.     FormfeedMode : Boolean;  {True to eject page via formfeed}
  227.     PaperPause : Boolean;    {True to pause at end of page}
  228.   end;
  229.   PrintFontState = array[PrintCommandtype] of Boolean;
  230.   PrintStack = array[0..PrintStackSize] of Char; {Holds about to be printed characters}
  231.   PrintBuffer = array[1..PrintBufferSize] of Char; {Holds text waiting to be formatted for printing}
  232.  
  233.   PrintRecord =              {Information regarding the current print job}
  234.   record
  235.     PrintFilename : Filepath; {File name being printed}
  236.     PrintFile : file;        {File being printed}
  237.     OutFilename : Filepath;  {Output file name if ToFile is true}
  238.     OutFile : file of Char;  {Output file if ToFile is true}
  239.     StartPage : Integer;     {First page to print}
  240.     StopPage : Integer;      {Last page to print}
  241.     ToFile : Boolean;        {True if printing to file}
  242.     Printer : Byte;          {0 for LPT1, 1 for LPT2}
  243.     Format : Boolean;        {True to interpret dot commands}
  244.     FontState : PrintFontState; {What fonts are active}
  245.     PendingFontState : PrintFontState; {What fonts are being sent to printer}
  246.     PushStart : Boolean;     {True if header not yet inserted on current page}
  247.     PushEnd : Boolean;       {True if footer not yet inserted on current page}
  248.     NewLine : Boolean;       {True at begin of a new line}
  249.     PrinterInit : Boolean;   {True until printer init codes are printed}
  250.     LastPage : Boolean;      {True when last page is being printed}
  251.     ShowPageNum : Boolean;   {True for page numbers to print in footer}
  252.     Column : Integer;        {Current position in line}
  253.     Line : Integer;          {Current line on page}
  254.     PageNum : Integer;       {Current page}
  255.     Pagecol : Integer;       {Column for default page numbers}
  256.     PageLen : Integer;       {Current page length}
  257.     Tmargin : Integer;       {Top of page to text}
  258.     Bmargin : Integer;       {Bottom of text to bottom of page}
  259.     Loffset : Integer;       {Current left offset}
  260.     HTMargin : Integer;      {Top of page to header}
  261.     FBMargin : Integer;      {Footer to bottom of page}
  262.     Header : String255;      {Current header string}
  263.     Footer : String255;      {Current footer string}
  264.     Buffer : PrintBuffer;    {Characters to be printed}
  265.     BufferPtr : Integer;     {Position in character buffer}
  266.     BufferChars : Integer;   {Number of characters in buffer}
  267.     Stack : PrintStack;      {Translated characters awaiting printout}
  268.     StackIndex : Integer;    {Number of translated chars currently stacked}
  269.     Devicename : Filepath;   {Printer type description file name}
  270.   end;
  271.  
  272. var
  273.   Printing : Boolean;        {True if print job in progress}
  274.   PrintJob : PrintRecord;    {Describes the current print job}
  275.   PrintDef : PrinterDefinition; {Describes the currently selected printer}
  276.   PrintChars : Integer;      {Number of chars to print in a time slice}
  277.  
  278. const
  279.   MaxMacro = 9;              {Maximum number of macros, 0..MaxMacro}
  280.   MaxMacroLength = 255;      {Maximum length of a macro sequence, <=255}
  281.   MacroSignature : string[6] = 'MACROS'; {At the beginning of every macro file}
  282.   MacroFileExt : ExtString = 'MAC';
  283.  
  284. type
  285.   MacroString = string[MaxMacroLength]; {String for recorded keystroke sequences}
  286.   MacroName = string[255];
  287.   MacroNamePtr = ^MacroName;
  288.   MacroArray = array[0..MaxMacro] of MacroString;
  289.  
  290. var
  291.   Macrokeys : MacroArray;    {Records macros for playback}
  292.   Macronames : array[0..MaxMacro] of MacroNamePtr; {Points to name for each macro}
  293.   Macronum : Integer;        {Macro number used by EditFindAndMacro}
  294.  
  295.  
  296. procedure EdPrintExit;
  297.   {-Quit printing}
  298.  
  299. procedure EdPrintNext(PrintChars : Integer);
  300.   {-Background process to print the next PrintChars characters of print job}
  301.  
  302. procedure EdPushPrintString(S : PrintCommand);
  303.   {-Push a command string onto print stack}
  304.  
  305. function EdGetInput : Char;
  306.   {-Read next character from typeahead buffer}
  307.  
  308. function EdKeyPressed : Boolean;
  309.   {-Determine if input is available}
  310.  
  311. function EdKeyInterrupt : Boolean;
  312.   {-Determine whether a keystroke should interrupt background processes}
  313.  
  314. procedure EdBreathe;
  315.   {-Stimulate typeahead routines without returning a character}
  316.  
  317. procedure EdUserPush(S : String255);
  318.   {-Push string onto typeahead buffer}
  319.  
  320. procedure EdWaitforKey;
  321.   {-Tight loop waiting for keystroke}
  322.  
  323. function EdGetAnyChar : Char;
  324.   {-Wait for and return a character from internal keyboard buffer}
  325.  
  326. function EdGetCursorCommand(CmdSet : Charset) : Char;
  327.   {-Return a legal cursor command, WordStar style}
  328.  
  329. procedure EdClearBuffer;
  330.   {-Clear keyboard buffer}
  331.  
  332. procedure EdSetInsertMode(Inserting : Boolean);
  333.   {-Keep the cursor appearance and BIOS keyboard flag up to date}
  334.  
  335. procedure EdUpdateCursor;
  336.   {-Move the cursor to the right spot}
  337.  
  338. procedure EdUpdateCmdLine;
  339.   {-Update the message line}
  340.  
  341. procedure EdEraseMenuHelp;
  342.   {-Remove menu help from the prompt line}
  343.  
  344. procedure EdShowMenuHelp;
  345.   {-Put the menu help into the prompt line}
  346.  
  347. procedure EdAppPromptLine(S : VarString);
  348.   {-Append command name to message line}
  349.  
  350. procedure EdZapPromptLine;
  351.   {-Zap message line, leaving it blank}
  352.  
  353. procedure EdResetPromptLine;
  354.   {-Clear partial command indicator from command line}
  355.  
  356. procedure EdWritePromptLine(S : VarString);
  357.   {-Write a new message line to the screen}
  358.  
  359. procedure EdForceMessage(msg : VarString);
  360.   {-Guarantee that a message is displayed}
  361.  
  362. procedure EdDisplayCommandBuffer;
  363.   {-Indicate that a partial command has been entered}
  364.  
  365. procedure EdWait;
  366.   {-Display a Wait signal}
  367.  
  368. function EdYcenterWindow(Rows : Byte) : Byte;
  369.   {-Return a legal row number centered in the current window}
  370.  
  371. procedure EdDrawBox(Border : BorderChars;
  372.                     XPosn, YPosn, XSize, YSize : Byte;
  373.                     BoxAttr : BoxType);
  374.   {-Draw a box frame on the screen}
  375.  
  376. function EdSetupWindow(Border : BorderChars;
  377.                        XLow, YLow, XHigh, YHigh : Byte;
  378.                        BoxAttr : BoxType) : WindowPtr;
  379.   {-Save current screen and set up a new window}
  380.  
  381. procedure EdRestoreWindow(var W : WindowPtr;
  382.                           XPosn, YPosn, XSize, YSize : Byte);
  383.   {-Given a pointer to a WindowRec, restore the contents of the window}
  384.  
  385. procedure EdSaveTextWindow(Border : BorderChars;
  386.                            Title : VarString;
  387.                            XLow, YLow, XHigh, YHigh : Byte;
  388.                            var W : WindowRec);
  389.   {-Save existing screen and set up a new text window}
  390.  
  391. procedure EdRestoreTextWindow(W : WindowRec);
  392.   {Given a pointer to a WindowRec, restore the contents of the window}
  393.  
  394. procedure EdDisplayPromptWindow(msg : VarString; Yp : Integer;
  395.                                 OKset : Charset; var Ch : Char;
  396.                                 BoxAttr : BoxType);
  397.   {-Display a one line message, and wait for char to clear it}
  398.  
  399. procedure EdErrormsg(Msgno : Integer);
  400.   {-Write error message and dump typeahead buffer}
  401.  
  402. function EdFileerror : Boolean;
  403.   {-Report error during file operation}
  404.  
  405. procedure EdBlockWrite(var F : file; var Buf; Num : Word);
  406.   {-Write a block and check for errors}
  407.  
  408. procedure EdBlockRead(var F : file; var Buf; Num : Word; var BytesRead);
  409.   {-Read a block and check for errors}
  410.  
  411. procedure EdAskforEditor(Xp, Yp, XSize, Maxlen : Integer; HaveWindow : Boolean; var Rs : VarString);
  412.   {-Perform line editing functions for string input}
  413.  
  414. procedure EdAskfor(Prompt : VarString; Xp, Yp, Wid : Integer; var Rs : VarString);
  415.   {-Edit and return a string}
  416.  
  417. procedure EdArg2Integer(Arg : String255; Min, Max : Integer; var V);
  418.   {-Convert string to integer. Clip at min and max}
  419.  
  420. procedure EdString2integer(Src : VarString; var R);
  421.   {-Convert string to integer. 0 returned may mean ERROR - check GotError}
  422.  
  423. function EdYesNo(Prompt : VarString) : Boolean;
  424.   {-Return True for Yes, False for No}
  425.  
  426. function EdGetnumber(Prompt : VarString; Default : Integer) : Integer;
  427.   {-Prompt for and return a number, 0 if invalid or empty}
  428.   {-Plus or minus in input strings return results relative to default}
  429.  
  430. procedure EdSetNumber(var Num; msg, Min, Max : Integer; var Empty : Boolean);
  431.   {-Prompt for and set an integer value in range min..max}
  432.  
  433. procedure EdHelpWindow(Cmd : CommandType);
  434.   {-Display help for the specified command}
  435.  
  436.   {==========================================================================}
  437.  
  438. implementation
  439.  
  440. const
  441.   {Following two must be matched with those in MSINST}
  442.   HelpWidth = 60;            {Max line length of help window}
  443.   HelpHeight = 15;           {Number of rows of help window}
  444.  
  445. type
  446.   HelpIndexRec =             {File position and block length of help sections}
  447.   record
  448.     Start : LongInt;
  449.     Len : Word;
  450.   end;
  451.  
  452.   PrintErrorType =           {Errors that may occur during printing}
  453.   (PrtFileRead,
  454.    PrtOutPaper,
  455.    PrtOffLine,
  456.    PrtNoResponse,
  457.    PrtFileWrite,
  458.    PrtCmdTooLong,
  459.    PrtUnknown
  460.    );
  461.  
  462.   {$I MSPRINT.INC}
  463.   {$I MSKEYBRD.INC}
  464.   {$I MSCURSOR.INC}
  465.   {$I MSPROMPT.INC}
  466.   {$I MSWINDOW.INC}
  467.   {$I MSUSERIO.INC}
  468.   {$I MSFILEIO.INC}
  469.   {$I MSHELP.INC}
  470.  
  471. begin
  472.   {Assure break checking is off}
  473.   CheckBreak := False;
  474.   {No buffered keystrokes}
  475.   Circin := 0;
  476.   Circout := 0;
  477.   {Command line editor starts in insert mode}
  478.   AskforInsertflag := True;
  479. end.
  480.