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

  1. {                            MSSET.PAS
  2.                                MS 4.0
  3.                 Copyright (c) 1985, 87 by Borland International, Inc.         }
  4.  
  5. {$I msdirect.inc}
  6.  
  7. unit MsSet;
  8.   {-Get and save default settings}
  9.  
  10. interface
  11.  
  12. uses
  13.   Crt,                       {Basic video operations - standard unit}
  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,                   {Pointer primitives}
  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.   MsUser,                    {User keyboard input, line edit, error report, help}
  25.   MsMemOp,                   {Text buffer allocation and deallocation}
  26.   MsBack,                    {Background processes}
  27.   MsScrn2,                   {Editor screen updating}
  28.   MsMenu,                    {Pulldown and custom menu system}
  29.   MsDir,                     {Popup directory picker}
  30.   MsEdit,                    {Basic editing commands}
  31.   MsFile;                    {File I/O routines}
  32.  
  33.  
  34. procedure EdToggleWordWrap;
  35.   {-Change state of word wrap}
  36.  
  37. procedure EdToggleFixedTabs;
  38.   {-Process fixed tab toggle command}
  39.  
  40. procedure EdToggleJustify;
  41.   {-Process justification toggle command}
  42.  
  43. procedure EdToggleCompressWrap;
  44.   {-Process CompressWrap toggle command}
  45.  
  46. procedure EdTogglePaginate;
  47.   {-Toggle display/computation of page numbers}
  48.  
  49. procedure EdSetUndoLimit;
  50.   {-Prompt for and set the global undo limit}
  51.  
  52. procedure EdGetDefaultExtension;
  53.   {-Get a new default file extension}
  54.  
  55. procedure EdSetColors;
  56.   {-Customize editor colors}
  57.  
  58. procedure EdToggleInitZoomState;
  59.   {-Toggle default zoom state}
  60.  
  61. procedure EdToggleRetraceMode;
  62.   {-Toggle snow control}
  63.  
  64. procedure EdToggleSolidCursor;
  65.   {-Toggle block cursor}
  66.  
  67. procedure EdToggleEga43Line;
  68.   {-Toggle 43 line display mode}
  69.  
  70. procedure EdToggleTabLine;
  71.   {-Toggle display of tab lines}
  72.  
  73. procedure EdSetLeftMargin;
  74.   {-Set up a new left margin}
  75.  
  76. procedure EdSetRightMargin;
  77.   {-Set up a new right margin}
  78.  
  79. procedure EdSetTabSize;
  80.   {-Prompt for and set a new default tab size}
  81.  
  82. procedure EdSetSupportPath;
  83.   {-Define the path or drive for all the editor support files}
  84.  
  85. procedure EdSetTopMargin;
  86.   {-Prompt for and set the top margin of the current window}
  87.  
  88. procedure EdSetBotMargin;
  89.   {-Prompt for and set the bottom margin of the current window}
  90.  
  91. procedure EdSetPageLength;
  92.   {-Prompt for and save the page length of the current window}
  93.  
  94. procedure EdSaveDefaults;
  95.   {-Write the current default settings to disk}
  96.  
  97.   {==========================================================================}
  98.  
  99. implementation
  100.  
  101. var
  102.   WhichColorItem : Integer;  {Last selection on color installation menu}
  103.  
  104.   procedure EdToggleWordWrap;
  105.     {-Change state of word wrap}
  106.  
  107.   begin                      {EdToggleWordWrap}
  108.     with Curwin^ do begin
  109.       WW := not WW;
  110.       {Turning wrap off turns justify off}
  111.       if not(WW) then
  112.         JU := False;
  113.     end;
  114.   end;                       {EdToggleWordWrap}
  115.  
  116.   procedure EdToggleFixedTabs;
  117.     {-Process fixed tab toggle command}
  118.  
  119.   begin                      {EdToggleFixedTabs}
  120.     with Curwin^ do begin
  121.       FT := not(FT);
  122.       {Turning fixed tabs off turns tab display off}
  123.       if not(FT) then begin
  124.         TL := False;
  125.         EdSetTextNo(Curwin);
  126.       end;
  127.     end;
  128.   end;                       {EdToggleFixedTabs}
  129.  
  130.   procedure EdToggleJustify;
  131.     {-Process justification toggle command}
  132.  
  133.   begin                      {EdToggleJustify}
  134.     with Curwin^ do begin
  135.       JU := not(JU);
  136.       {Turning justify on forces word wrap and compresswrap on}
  137.       if JU then begin
  138.         WW := True;
  139.         CW := True;
  140.       end;
  141.     end;
  142.   end;                       {EdToggleJustify}
  143.  
  144.   procedure EdToggleCompressWrap;
  145.     {-Process CompressWrap toggle command}
  146.  
  147.   begin                      {EdToggleCompressWrap}
  148.     with Curwin^ do begin
  149.       CW := not(CW);
  150.       {Turning compresswrap off forces justify off}
  151.       if not(CW) then
  152.         JU := False;
  153.     end;
  154.   end;                       {EdToggleCompressWrap}
  155.  
  156.   procedure EdTogglePaginate;
  157.     {-Toggle display/computation of page numbers}
  158.  
  159.   begin                      {EdTogglePaginate}
  160.     with Curwin^ do begin
  161.       PA := not(PA);
  162.       {Set screen display offsets to show page markers}
  163.       if PA then begin
  164.         Leftcol := 2;
  165.         PaginationDone := False;
  166.         EdSetPtrNil(PageLine);
  167.       end else
  168.         Leftcol := 0;
  169.     end;
  170.   end;                       {EdTogglePaginate}
  171.  
  172.   procedure EdSetUndoLimit;
  173.     {-Prompt for and set the global undo limit}
  174.   var
  175.     Empty : Boolean;
  176.  
  177.   begin                      {EdSetUndoLimit}
  178.     EdSetNumber(UndoLimit, 361, 0, MaxInt, Empty);
  179.     if Abortcmd or Goterror or Empty then
  180.       Exit;
  181.     SaveUndoLimit := UndoLimit;
  182.   end;                       {EdSetUndoLimit}
  183.  
  184.   procedure EdGetDefaultExtension;
  185.     {-Get a new default file extension}
  186.   var
  187.     DefExt : string[4];
  188.     Done : Boolean;
  189.  
  190.   begin                      {EdGetDefaultExtension}
  191.     repeat
  192.       Done := True;
  193.       DefExt := DefExtension;
  194.       EdAskfor(EdGetMessage(377), 10, 20, 6, DefExt);
  195.       if not(Abortcmd) then
  196.         {Do some error checking}
  197.         if EdHasWildCards(DefExt) then begin
  198.           EdErrormsg(49);
  199.           Done := False;
  200.         end else begin
  201.           {Remove leading period, if any}
  202.           if (Length(DefExt) > 0) and (DefExt[1] = Period) then
  203.             Delete(DefExt, 1, 1);
  204.           {Remove blanks, and characters trailing blanks}
  205.           EdDeleteLeadingBlanks(DefExt);
  206.           EdDeleteTrailers(DefExt);
  207.           {Uppercase}
  208.           EdUpcase(DefExt);
  209.           DefExtension := DefExt;
  210.         end;
  211.     until Done;
  212.   end;                       {EdGetDefaultExtension}
  213.  
  214.   procedure EdSetColors;
  215.     {-Customize editor colors}
  216.   const
  217.     MaxChoices = 16;
  218.     Xmin = 5;
  219.     Ymin = 7;
  220.     Xmax = 26;
  221.     ColorCmdSet : Charset =  {Characters to choose from color setup menus}
  222.     [^J, ^M, ^[ , ^S, ^D, ^E, ^X];
  223.  
  224.   type
  225.     ColorArray = array[1..16] of Byte;
  226.  
  227.   var
  228.     Wmenu : WindowRec;
  229.     Quitting, Changed : Boolean;
  230.     Colors : ^ColorArray;
  231.     SaveColor, Ncolor : Byte;
  232.  
  233.     procedure EdWriteEntry(W : WindowRec; I : Integer; Selected : Boolean);
  234.       {-Write one color entry}
  235.     var
  236.       S : VarString;
  237.  
  238.       function EdPadEntry(F : VarString; Width : Byte; Selected : Boolean) : VarString;
  239.         {-custom pad the string with blanks}
  240.       const
  241.         SelectChar : string[1] = #16;
  242.       var
  243.         S : VarString;
  244.  
  245.       begin                  {EdPadEntry}
  246.         FillChar(S[1], Width, Blank);
  247.         S[0] := Chr(Width);
  248.         Move(F[2], S[3], Pred(Length(F)));
  249.         if Selected then
  250.           Move(SelectChar[1], S[1], 1);
  251.         EdPadEntry := S;
  252.       end;                   {EdPadEntry}
  253.  
  254.     begin                    {EdWriteEntry}
  255.       with W do begin
  256.         S := EdPadEntry(EdGetMessage(405+I), XSize-2, Selected);
  257.         EdFastWrite(S[1], YPosn+I, Succ(XPosn), Ncolor);
  258.         EdFastWrite(Copy(S, 2, DefNoCols), YPosn+I, XPosn+2, Colors^[I]);
  259.       end;
  260.     end;                     {EdWriteEntry}
  261.  
  262.     procedure EdDrawAllChoices(W : WindowRec; SelectNum : Integer);
  263.       {-Draw all of the color choices}
  264.     var
  265.       I : Integer;
  266.  
  267.     begin                    {EdDrawAllChoices}
  268.       for I := 1 to MaxChoices do
  269.         EdWriteEntry(W, I, (I = SelectNum));
  270.     end;                     {EdDrawAllChoices}
  271.  
  272.     procedure EdChooseColor(Wmenu : WindowRec; I : Integer; var Color : Byte);
  273.       {-Interactively choose from menu of colors}
  274.     const
  275.       Xmin = 31;
  276.       Ymin = 10;
  277.       SelectStr = #15;
  278.       ShowStr = #7;
  279.       DefStr = #254;
  280.     var
  281.       F, B, Fdef, Bdef : Byte;
  282.       Wcolor : WindowRec;
  283.       Ch : Char;
  284.  
  285.       procedure EdWriteColored(W : WindowRec; F, B : Byte; S : VarString);
  286.         {-write a string in color}
  287.  
  288.       begin                  {EdWriteColored}
  289.         with W do
  290.           EdFastWrite(S, Succ(YPosn+B), Succ(XPosn+F), (F and $F) or (B shl 4));
  291.       end;                   {EdWriteColored}
  292.  
  293.       procedure EdDrawColorMap(Wcolor : WindowRec);
  294.         {-Draw the matrix of available colors}
  295.       var
  296.         F, B : Byte;
  297.  
  298.       begin                  {EdDrawColorMap}
  299.         for F := 0 to 15 do
  300.           for B := 0 to 7 do
  301.             EdWriteColored(Wcolor, F, B, ShowStr);
  302.       end;                   {EdDrawColorMap}
  303.  
  304.     begin                    {EdChooseColor}
  305.  
  306.       {Save screen and put up window}
  307.       EdSaveTextWindow(Border, EdGetMessage(374), Xmin, Ymin, Xmin+17, Ymin+9, Wcolor);
  308.  
  309.       {Save the default position}
  310.       Fdef := Color and $F;
  311.       Bdef := Color shr 4;
  312.       F := Fdef;
  313.       B := Bdef;
  314.  
  315.       {Draw the default color map}
  316.       EdDrawColorMap(Wcolor);
  317.  
  318.       EdWritePromptLine(EdGetMessage(376));
  319.  
  320.       {Allow moving around}
  321.       repeat
  322.  
  323.         {Pass back the new color}
  324.         Color := F or (B shl 4);
  325.         {Update the other menu}
  326.         EdWriteEntry(Wmenu, I, True);
  327.         {Update the color matrix}
  328.         EdWriteColored(Wcolor, F, B, SelectStr);
  329.  
  330.         {Get a cursor command}
  331.         Ch := EdGetCursorCommand(ColorCmdSet);
  332.  
  333.         {Rewrite the old cursor position}
  334.         if (F = Fdef) and (B = Bdef) then
  335.           EdWriteColored(Wcolor, F, B, DefStr)
  336.         else
  337.           EdWriteColored(Wcolor, F, B, ShowStr);
  338.  
  339.         case Ch of
  340.           ^J :               {Help}
  341.             EdHelpWindow(CmdSetColors);
  342.  
  343.           ^E :               {Cursor up}
  344.             if B > 0 then
  345.               Dec(B)
  346.             else
  347.               B := 7;
  348.  
  349.           ^X :               {Cursor down}
  350.             if B < 7 then
  351.               Inc(B)
  352.             else
  353.               B := 0;
  354.  
  355.           ^S :               {Cursor left}
  356.             if F > 0 then
  357.               Dec(F)
  358.             else
  359.               F := 15;
  360.  
  361.           ^D :               {Cursor right}
  362.             if F < 15 then
  363.               Inc(F)
  364.             else
  365.               F := 0;
  366.  
  367.           ^[ :               {Return to default and escape}
  368.             begin
  369.               Color := Fdef or (Bdef shl 4);
  370.               {Update the other menu}
  371.               EdWriteEntry(Wmenu, I, True);
  372.               Ch := ^M;
  373.             end;
  374.  
  375.         end;
  376.  
  377.       until Abortcmd or (Ch = ^M);
  378.  
  379.       EdRestoreTextWindow(Wcolor);
  380.     end;                     {EdChooseColor}
  381.  
  382.  
  383.   begin                      {EdSetColors}
  384.  
  385.     {Put up a menu of selections}
  386.     EdSaveTextWindow(Border, EdGetMessage(362), Xmin, Ymin, Xmax, Succ(Ymin+MaxChoices), Wmenu);
  387.     EdSetCursor(CursorOff);
  388.     EdEraseMenuHelp;
  389.     EdWritePromptLine(EdGetMessage(375));
  390.  
  391.     Colors := Addr(ScreenAttr);
  392.     Ncolor := ScreenAttr[MnColor];
  393.     EdDrawAllChoices(Wmenu, WhichColorItem);
  394.  
  395.     {Select until done}
  396.     Quitting := False;
  397.     Changed := False;
  398.  
  399.     repeat
  400.  
  401.       EdWriteEntry(Wmenu, WhichColorItem, True);
  402.  
  403.       case EdGetCursorCommand(ColorCmdSet) of
  404.  
  405.         ^J :                 {Help}
  406.           EdHelpWindow(CmdSetColors);
  407.  
  408.         ^M :                 {Select}
  409.           begin
  410.             SaveColor := Colors^[WhichColorItem];
  411.             EdChooseColor(Wmenu, WhichColorItem, Colors^[WhichColorItem]);
  412.             if Colors^[WhichColorItem] <> SaveColor then
  413.               Changed := True;
  414.             EdWritePromptLine(EdGetMessage(375));
  415.           end;
  416.  
  417.         ^[ :                 {Escape}
  418.           Quitting := True;
  419.  
  420.         ^E :                 {Scroll up}
  421.           begin
  422.             EdWriteEntry(Wmenu, WhichColorItem, False);
  423.             if WhichColorItem > 1 then
  424.               Dec(WhichColorItem)
  425.             else
  426.               WhichColorItem := MaxChoices;
  427.           end;
  428.  
  429.         ^X :                 {Scroll down}
  430.           begin
  431.             EdWriteEntry(Wmenu, WhichColorItem, False);
  432.             if WhichColorItem < MaxChoices then
  433.               Inc(WhichColorItem)
  434.             else
  435.               WhichColorItem := 1;
  436.           end;
  437.  
  438.       end;
  439.     until Abortcmd or Quitting;
  440.  
  441.     {Rebuild the attribute table for combined fonts}
  442.     EdBuildFontAttribute(FontAttribute);
  443.  
  444.     {Store the attribute used for control characters}
  445.     CtrlAttr := ScreenAttr[BlockColor];
  446.  
  447.     {Attributes used to draw boxes}
  448.     TextAttr[NormalBox] := ScreenAttr[MnColor];
  449.     TextAttr[ErrorBox] := ScreenAttr[CursorColor];
  450.     FrameAttr[NormalBox] := ScreenAttr[MfColor];
  451.     FrameAttr[ErrorBox] := ScreenAttr[CursorColor];
  452.  
  453.     {Restore the screen}
  454.     EdShowMenuHelp;
  455.     EdRestoreTextWindow(Wmenu);
  456.  
  457.     {Update all of the screen colors if any changed}
  458.     if Changed and EdPtrNotNil(CurrMenu) then begin
  459.       EdEraseMenus;
  460.       if WindowCount > 0 then begin
  461.         Intrflag := NoInterr;
  462.         EdUpdateScreen;
  463.       end;
  464.       {Back into menu system}
  465.       ExitMenu := True;
  466.       EdUserPush(MenuPrime+'O');
  467.     end;
  468.   end;                       {EdSetColors}
  469.  
  470.   procedure EdToggleInitZoomState;
  471.     {-Toggle default zoom state}
  472.  
  473.   begin                      {EdToggleInitZoomState}
  474.     SaveInitZoomState := not(SaveInitZoomState);
  475.     if SaveInitZoomState then begin
  476.       {Make sure zoom is currently active}
  477.       if not(Zoomed) then
  478.         EdZoomWindow(False);
  479.     end else if WindowCount <= 1 then
  480.       {Turn off zoom}
  481.       Zoomed := False;
  482.   end;                       {EdToggleInitZoomState}
  483.  
  484.   procedure EdToggleRetraceMode;
  485.     {-Toggle snow control}
  486.  
  487.   begin                      {EdToggleRetraceMode}
  488.     GoodColorCard := not(GoodColorCard);
  489.     RetraceMode := InitRetracemode and not(GoodColorCard);
  490.   end;                       {EdToggleRetraceMode}
  491.  
  492.   procedure EdToggleSolidCursor;
  493.     {-Toggle block cursor}
  494.  
  495.   begin                      {EdToggleSolidCursor}
  496.     SolidCursor := not(SolidCursor);
  497.     if SolidCursor then
  498.       {Avoid display of phantom solid cursor upon exit}
  499.       CurScrRow := 2;
  500.   end;                       {EdToggleSolidCursor}
  501.  
  502.   procedure EdToggleEga43Line;
  503.     {-Toggle 43 line display mode}
  504.   var
  505.     W : Pwindesc;
  506.     LastTop : Integer;
  507.     Rezoom : Boolean;
  508.  
  509.   begin                      {EdToggleEga43Line}
  510.     if EgaPresent then begin
  511.       Ega43lineMode := not(Ega43lineMode);
  512.       if Ega43lineMode then begin
  513.         EdSetEga43LineMode;
  514.         if Zoomed then begin
  515.           {Give the screen space to the visible window}
  516.           Curwin^.Lastlineno := PhyScrRows;
  517.           if Curwin = Window1^.Backlink then
  518.             {Correct the stored info regarding the zoom}
  519.             ZoomWin.Lastlineno := PhyScrRows;
  520.         end;
  521.         {Give the extra screen space to the bottom window}
  522.         Window1^.Backlink^.Lastlineno := PhyScrRows;
  523.       end else begin
  524.         EdSetEga25lineMode;
  525.         {Move up any windows that are off bottom of screen}
  526.         Rezoom := Zoomed;
  527.         if Rezoom then
  528.           {Toggle zoom off}
  529.           EdZoomWindow(False);
  530.         W := Window1;
  531.         LastTop := Succ(PhyscrRows);
  532.         repeat
  533.           {Work backwards from bottom window}
  534.           EdBackPtr(W);
  535.           with W^ do begin
  536.             Lastlineno := Pred(LastTop);
  537.             if Firstlineno+MinWindowLines > Lastlineno then begin
  538.               Firstlineno := Lastlineno-MinWindowLines;
  539.               EdSetTextNo(W);
  540.             end;
  541.             LastTop := Firstlineno;
  542.             EdBackupCurline(W);
  543.           end;
  544.         until W = Window1;
  545.         if Rezoom then
  546.           {toggle zoom back on}
  547.           EdZoomWindow(False);
  548.       end;
  549.  
  550.       {Redraw screen and menus if on}
  551.       if WindowCount > 0 then
  552.         EdUpdateScreen
  553.       else
  554.         ClrScr;
  555.       if EdPtrNotNil(CurrMenu) then
  556.         EdDrawMenu(RootMenu);
  557.  
  558.     end else
  559.       EdErrormsg(71);
  560.   end;                       {EdToggleEga43Line}
  561.  
  562.   procedure EdToggleTabLine;
  563.     {-Toggle display of tab lines}
  564.  
  565.   begin                      {EdToggleTabLine}
  566.     with Curwin^ do begin
  567.       TL := not(TL);
  568.       {Force fixed tabs on}
  569.       if TL then
  570.         FT := True;
  571.     end;
  572.     EdSetTextNo(Curwin);
  573.     EdRealignOne(Curwin);
  574.   end;                       {EdToggleTabLine}
  575.  
  576.   procedure EdSetLeftMargin;
  577.     {-Set up a new left margin}
  578.   var
  579.     Empty : Boolean;
  580.  
  581.   begin                      {EdSetLeftMargin}
  582.     with Curwin^ do begin
  583.       EdEraseMenuHelp;
  584.       EdWritePromptLine(EdGetMessage(256));
  585.       EdSetNumber(Lmargin, 344, 1, Pred(Rmargin), Empty);
  586.       if Abortcmd or Goterror then
  587.         Exit;
  588.       if Empty and (Colno < Rmargin) then
  589.         Lmargin := Colno;
  590.       EdResetTempMargin(Curwin, True);
  591.     end;
  592.   end;                       {EdSetLeftMargin}
  593.  
  594.   procedure EdSetRightMargin;
  595.     {-Set up a new right margin}
  596.   var
  597.     Empty : Boolean;
  598.  
  599.   begin                      {EdSetRightMargin}
  600.     with Curwin^ do begin
  601.       EdEraseMenuHelp;
  602.       EdWritePromptLine(EdGetMessage(256));
  603.       EdSetNumber(Rmargin, 340, Succ(Lmargin), Maxlinelength, Empty);
  604.       if Abortcmd or Goterror then
  605.         Exit;
  606.       if Empty and (Colno > Lmargin) then
  607.         Rmargin := Colno;
  608.       {Reset temp margin if invalidated by the change in right margin}
  609.       if Wmargin >= Pred(Rmargin) then
  610.         EdResetTempMargin(Curwin, True);
  611.     end;
  612.   end;                       {EdSetRightMargin}
  613.  
  614.   procedure EdSetTabSize;
  615.     {-Prompt for and set a new default tab size}
  616.   var
  617.     Empty : Boolean;
  618.  
  619.   begin                      {EdSetTabSize}
  620.     EdSetNumber(SaveTabSize, 356, 1, 100, Empty);
  621.   end;                       {EdSetTabSize}
  622.  
  623.   procedure EdSetSupportPath;
  624.     {-Define the path or drive for all the editor support files}
  625.   var
  626.     NewPath : Filepath;
  627.  
  628.   begin                      {EdSetSupportPath}
  629.     EdEraseMenuHelp;
  630.     EdWritePromptLine('');
  631.     NewPath := SupportPath;
  632.     EdAskfor(EdGetMessage(317), 5, 20, 66, NewPath);
  633.     if Abortcmd then
  634.       Exit;
  635.     if not(EdStringEmpty(NewPath)) then begin
  636.       EdCleanFileName(NewPath);
  637.       {Use popup window when appropriate to allow browsing directory}
  638.       NewPath := EdPickdir(NewPath, 304, Directory, True);
  639.       if Abortcmd then
  640.         Exit;
  641.     end;
  642.     {Update the path that we use to find files}
  643.     SupportPath := NewPath;
  644.     if not(EdStringEmpty(SupportPath)) then
  645.       SupportPath := EdAddTrailingBackslash(SupportPath);
  646.     {SaveSupportPath is stored in the installation area and displayed on the menu}
  647.     SaveSupportPath := SupportPath;
  648.   end;                       {EdSetSupportPath}
  649.  
  650.   procedure EdSetTopMargin;
  651.     {-Prompt for and set the top margin of the current window}
  652.   var
  653.     Empty : Boolean;
  654.  
  655.   begin                      {EdSetTopMargin}
  656.     with Curwin^ do
  657.       EdSetNumber(Tmargin, 358, 0, Pred(PageLen-Bmargin), Empty);
  658.     if Abortcmd or Goterror or Empty then
  659.       Exit;
  660.     EdResetPageLine(Curwin);
  661.   end;                       {EdSetTopMargin}
  662.  
  663.   procedure EdSetBotMargin;
  664.     {-Prompt for and set the bottom margin of the current window}
  665.   var
  666.     Empty : Boolean;
  667.  
  668.   begin                      {EdSetBotMargin}
  669.     with Curwin^ do
  670.       EdSetNumber(Bmargin, 359, 0, Pred(PageLen-Tmargin), Empty);
  671.     if Abortcmd or Goterror or Empty then
  672.       Exit;
  673.     EdResetPageLine(Curwin);
  674.   end;                       {EdSetBotMargin}
  675.  
  676.   procedure EdSetPageLength;
  677.     {-Prompt for and save the page length of the current window}
  678.   var
  679.     Empty : Boolean;
  680.  
  681.   begin                      {EdSetPageLength}
  682.     with Curwin^ do
  683.       EdSetNumber(PageLen, 360, Succ(Tmargin+Bmargin), (PrintStackSize-MaxHeaderChars) shr 1, Empty);
  684.     if Abortcmd or Goterror or Empty then
  685.       Exit;
  686.     EdResetPageLine(Curwin);
  687.   end;                       {EdSetPageLength}
  688.  
  689.   procedure EdSaveDefaults;
  690.     {-Write the current default settings to disk}
  691.   var
  692.     Found : Boolean;
  693.     Fname : Filepath;
  694.     Ch : Char;
  695.  
  696.     function EdClone(Fname : Filepath; var Head, Tail) : Boolean;
  697.       {-Clone installation area into the executable file, returning true if successful}
  698.     label
  699.       ExitPoint;
  700.     const
  701.       MaxBufSize = 32256;    {63 sectors * 512 bytes}
  702.     type
  703.       BufferType = array[0..MaxBufSize] of Byte;
  704.     var
  705.       Buflen : Word;
  706.       Buffer : ^BufferType;  {Read buffer}
  707.       Data : array[0..256] of Byte absolute Head; {Mask for start of installation area}
  708.       Source : string[255] absolute Head; {Mask for Installation ID string}
  709.       SearchLen : Byte;
  710.       I, Actual, Amount : Word;
  711.       Fpos : LongInt;
  712.       F : file;
  713.  
  714.     begin                    {EdClone}
  715.  
  716.       {Get the largest available buffer to work in}
  717.       if EdMemAvail(513, FreeListTemp) then begin
  718.         Fpos := MaxAvail;
  719.         if Fpos > MaxBufSize then
  720.           Buflen := MaxBufSize
  721.         else
  722.           {Choose a multiple of 512 within the available space}
  723.           Buflen := (Word(Fpos) shr 9) shl 9;
  724.         GetMem(Buffer, Succ(Buflen));
  725.         EdClone := True;
  726.       end else
  727.         EdClone := False;
  728.  
  729.       {Open the program file, previously determined to exist}
  730.       Assign(F, Fname);
  731.       Reset(F, 1);
  732.  
  733.       {Seek to the approximate start of the data segment}
  734.       Fpos := 16*(DSeg-PrefixSeg-$10);
  735.       Seek(F, Fpos);
  736.       if EdINT24Result <> 0 then begin
  737.         EdClone := False;
  738.         goto ExitPoint;
  739.       end;
  740.  
  741.       {Read the first buffer}
  742.       EdBlockRead(F, Buffer^[1], Buflen, Actual);
  743.       if Goterror then begin
  744.         EdClone := False;
  745.         goto ExitPoint;
  746.       end;
  747.       Inc(Fpos, Actual);
  748.       SearchLen := Pred(Length(Source));
  749.  
  750.       {Search for ID string in the buffer, returning position or zero}
  751.       I := EdLongPosFwd(Buffer^, 1, Actual, Source);
  752.  
  753.       {Keep searching throughout the file}
  754.       while (I = 0) and (Actual >= Length(Source)) do begin
  755.         {Save the tail end of the buffer into the next buffer}
  756.         Move(Buffer^[Succ(Actual-SearchLen)], Buffer^[1], SearchLen);
  757.         {Read the next part of the file}
  758.         EdBlockRead(F, Buffer^[Length(Source)], Buflen-SearchLen, Actual);
  759.         if Goterror then begin
  760.           {File read error}
  761.           EdClone := False;
  762.           goto ExitPoint;
  763.         end;
  764.         Inc(Fpos, Actual);
  765.         Actual := Actual+SearchLen;
  766.         {Search for ID string in the buffer, returning position or zero}
  767.         I := EdLongPosFwd(Buffer^, 1, Actual, Source);
  768.       end;
  769.  
  770.       if I <> 0 then begin
  771.         {Position file pointer to start of default area}
  772.         Seek(F, Fpos+I+SearchLen-Actual);
  773.         {Write the RAM default area to disk}
  774.         Amount := Ofs(Tail)-Ofs(Data[Succ(Length(Source))]);
  775.         EdBlockWrite(F, Data[Succ(Length(Source))], Amount);
  776.         if Goterror then
  777.           {Write error}
  778.           EdClone := False;
  779.       end else begin
  780.         {ID string not found}
  781.         EdErrormsg(240);
  782.         EdClone := False;
  783.       end;
  784.  
  785. ExitPoint:
  786.       Close(F);
  787.       FreeMem(Buffer, Succ(Buflen));
  788.  
  789.     end;                     {EdClone}
  790.  
  791.   begin                      {EdSaveDefaults}
  792.  
  793.     {Find the program file}
  794.     Fname := ProgName+Period+ExeExt;
  795.  
  796.     {Check the current directory first}
  797.     Found := EdExistFile(Fname);
  798.     if not(Found) then begin
  799.       {Try the installed directory next}
  800.       Fname := SupportPath+Fname;
  801.       Found := EdExistFile(Fname);
  802.     end;
  803.  
  804.     if Found then begin
  805.  
  806.       {Update the RAM defaults area from the current window}
  807.       with Curwin^ do begin
  808.         SaveInsertMode := Insertflag;
  809.         SaveIndentMode := AI;
  810.         SaveWWmode := WW;
  811.         SaveTabMode := TL;
  812.         SaveJustMode := JU;
  813.         SavePageMode := PA;
  814.         SaveAttrMode := AT;
  815.         SaveFTmode := FT;
  816.         SaveCompressWrap := CW;
  817.         SaveLeftMargin := Lmargin;
  818.         SaveRightMargin := Rmargin;
  819.         SaveTopMargin := Tmargin;
  820.         SaveBottomMargin := Bmargin;
  821.         SavePageLen := PageLen;
  822.       end;
  823.       SaveUndoLimit := UndoLimit;
  824.  
  825.       with PrintJob do begin
  826.         SaveDeviceName := Devicename;
  827.         SavePrinterPort := Printer;
  828.         SaveOutputName := OutFilename;
  829.         SaveToFile := ToFile;
  830.       end;
  831.  
  832.       if InitRetracemode then
  833.         ColorAttr := ScreenAttr
  834.       else
  835.         MonoAttr := ScreenAttr;
  836.  
  837.       {Write the RAM defaults to the program file}
  838.       EdWait;
  839.       if EdClone(Fname, MainIDstring, LastMainDefault) then
  840.         if EdClone(Fname, ScreenIDstring, LastScreenDefault) then
  841.           {Success message}
  842.           EdDisplayPromptWindow(EdGetMessage(401)+Fname+' -'+EdGetMessage(305),
  843.                                 EdYcenterWindow(2), [#27], Ch, NormalBox);
  844.  
  845.     end else
  846.       EdErrormsg(39);
  847.   end;                       {EdSaveDefaults}
  848.  
  849. begin
  850.   WhichColorItem := 1;
  851. end.
  852.