home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / editor / epmtools / epmmac / stdcmds.e < prev    next >
Text File  |  1993-07-29  |  65KB  |  1,952 lines

  1. ;
  2. ; STDCMDS.E            Alphabetized by command name.
  3. ;
  4.  
  5. compile if EVERSION >=4
  6.  
  7. defc app, append =            -- With linking, PUT can be an external module.
  8.    'put' arg(1)               -- Collect the names; the module is named PUT.EX.
  9. compile else
  10. ;  Put and append work the same, and the same as XEdit's PUT.
  11. ;  If the file already exists, append to it.
  12. ;  If no file is specified, use same file as last specified.
  13. ;  If no mark, use append the entire file.
  14. defc app, append, put =
  15.    universal last_append_file
  16.  
  17.    if arg(1) = '' then
  18.       app_file=last_append_file
  19.    else
  20.       app_file=parse_file_n_opts(arg(1))
  21.       last_append_file=app_file
  22.    endif
  23.    if app_file='' then
  24.       sayerror NO_FILENAME__MSG 'PUT'
  25.       stop
  26.    endif
  27.    getfileid fileid
  28.    if marktype() then
  29.       had_mark = 1
  30.       call psave_mark(save_mark)
  31.       call prestore_mark(save_mark)
  32.    elseif .last = 0 then sayerror FILE_IS_EMPTY__MSG; stop
  33.    else
  34.       had_mark = 0
  35.       call pset_mark(1,.last,1,1,'LINE',fileid)
  36.    endif
  37.    /* If file is already in memory, we'll leave it there for speed. */
  38.    parse value 1 check_for_printer(app_file) with already_in_ring is_printer .
  39.    is_console = upcase(app_file)='CON' | upcase(app_file)='CON:'
  40.    if is_printer | is_console then
  41.       'e /q /n 'app_file
  42.    else
  43.       'e /q /n' app_file   /* look for file already in ring */
  44.       if rc=-282 then  -- -282 = sayerror("New file")
  45.          already_in_ring = 0
  46.          'q'
  47.          'e /q' app_file  /* not 'xcom e', so we can append to host files */
  48.       endif
  49.    endif
  50.    if is_printer or is_console or not already_in_ring then
  51.       if rc=-282 then
  52.          deleteline
  53.       elseif rc then
  54.          stop
  55.       endif
  56.    endif
  57.    getfileid tempofid
  58.    if marktype()<>'LINE' then
  59.       insertline '',tempofid.last+1
  60.    endif
  61.    bottom
  62.    copyrc=pcopy_mark()
  63.    if copyrc then /* Check memory full, invalid path, etc. */
  64.       .modify=0; 'q'
  65.       sayerror copyrc
  66.       stop
  67.    endif
  68.    aborted=0
  69.    /* If the app_file was already in memory, don't file it. */
  70.    if is_printer or is_console or not already_in_ring then
  71.       if is_console then say ''; endif
  72.       'save'
  73.       if is_console then pause; endif
  74.       aborted=rc
  75.       activatefile tempofid; tempofid.modify=0; 'q'
  76.    endif
  77.    activatefile fileid
  78.    if had_mark then
  79.       call prestore_mark(save_mark)
  80.    else
  81.       unmark
  82.    endif
  83.    if not aborted then
  84.       sayerror MARK_APPENDED__MSG app_file
  85.    endif
  86. compile endif
  87.  
  88. defc asc=
  89.    parse arg i '=' .
  90.    if i='' then
  91.       getline line
  92.       i=substr(line,.col,1)
  93.    endif
  94. compile if EVERSION < 5
  95.    setcommand 'asc 'i'='asc(i)'',5,1
  96.    cursorcommand
  97. compile else
  98.    sayerror 'asc 'i'='asc(i)''
  99. compile endif
  100.  
  101.  
  102. defc autosave=
  103.    universal vAUTOSAVE_PATH
  104. compile if RING_OPTIONAL
  105.    universal ring_enabled
  106. compile endif
  107. compile if E3
  108.    universal autosave
  109. compile endif
  110.    uparg=upcase(arg(1))
  111.    if uparg=ON__MSG then                  /* If only says AUTOSAVE ON,  */
  112. compile if E3
  113.    compile if DEFAULT_AUTOSAVE > 0
  114.       autosave = DEFAULT_AUTOSAVE
  115.    compile else
  116.       autosave = 10                    /* default is every 10 lines. */
  117.    compile endif
  118. compile else
  119.    compile if DEFAULT_AUTOSAVE > 0
  120.       .autosave = DEFAULT_AUTOSAVE
  121.    compile else
  122.       .autosave=10                     /* default is every 10 mods. */
  123.    compile endif
  124. compile endif
  125.    elseif uparg=OFF__MSG then
  126. compile if E3
  127.       autosave = 0
  128. compile else
  129.       .autosave = 0
  130. compile endif
  131.    elseif isnum(uparg) then            /* Check whether numeric argument. */
  132. compile if EVERSION < '4.12'
  133.       autosave = uparg
  134. compile else
  135.       .autosave = uparg
  136. compile endif
  137.    elseif uparg='DIR' then
  138.       'dir' vAUTOSAVE_PATH
  139.    elseif uparg='' then
  140. compile if EPM
  141.       'commandline autosave' .autosave
  142.    elseif uparg='?' then
  143.  compile if RING_OPTIONAL
  144.      if ring_enabled then
  145.  compile endif
  146.  compile if 0
  147.       do forever
  148.          retvalue=winmessagebox(AUTOSAVE__MSG, CURRENT_AUTOSAVE__MSG||.autosave\10||NAME_IS__MSG||MakeTempName()\10\10LIST_DIR__MSG, 24628)  -- YESNO + MB_INFORMATION + MOVEABLE + HELP
  149.          if retvalue<>8 then leave; endif    -- MBID_HELP = 8
  150.          'helpmenu 2045'
  151.       enddo
  152.       if 6=retvalue then  -- MBID_YES
  153.  compile else
  154.       if 6=winmessagebox(AUTOSAVE__MSG, CURRENT_AUTOSAVE__MSG||.autosave\10||NAME_IS__MSG||MakeTempName()\10\10LIST_DIR__MSG, 16436)  -- YESNO + MB_INFORMATION + MOVEABLE
  155.       then
  156.  compile endif
  157.          'dir' vAUTOSAVE_PATH
  158.       endif
  159.  compile if RING_OPTIONAL
  160.      else
  161.         call winmessagebox(AUTOSAVE__MSG, CURRENT_AUTOSAVE__MSG||.autosave\10||NAME_IS__MSG||MakeTempName()\10\10NO_LIST_DIR__MSG, 16432)  -- OK + MB_INFORMATION + MOVEABLE
  162.      endif
  163.  compile endif
  164.       return
  165. compile else  -- not EPM; uparg=''
  166.       cursor_command; begin_line; eraseendline
  167.  compile if E3
  168.       keyin 'autosave' autosave
  169.  compile else
  170.       keyin 'autosave' .autosave
  171.  compile endif
  172. compile endif
  173.    else
  174.       sayerror AUTOSAVE_PROMPT__MSG
  175.       return
  176.    endif
  177. compile if E3
  178.    sayerror CURRENT_AUTOSAVE__MSG||autosave', 'NAME_IS__MSG||MakeTempName()
  179. compile else
  180.    sayerror CURRENT_AUTOSAVE__MSG||.autosave', 'NAME_IS__MSG||MakeTempName()
  181. compile endif
  182.  
  183. ;   autoshell off/on/0/1
  184. ;
  185. ; specifies whether E should automatically pass internally-unresolved commands
  186. ; to DOS.  Autoshell is an internal command; this DEFC is a simple front end
  187. ; to allow the user to type off/on/0/1.  It calls the internal command via
  188. ; 'xcom autoshell'.
  189. ;
  190. ; Users who have very long path-search times might prefer to execute
  191. ; "autoshell 0" somewhere in their start-up sequence.
  192.  
  193. compile if EVERSION < 5
  194. defc autoshell=
  195.    uparg=upcase(arg(1))
  196.    if uparg='ON' or uparg=1 then
  197.       'xcom autoshell 1'
  198.    elseif uparg='OFF' or uparg='0' then
  199.       'xcom autoshell 0'
  200.    else
  201.       sayerror INVALID_ARG__MSG ON_OFF__MSG')'
  202.       stop
  203.    endif
  204. compile elseif EVERSION >= '5.50'
  205. defc autoshell=
  206.    uparg=upcase(arg(1))
  207.    if uparg=ON__MSG or uparg=1 then
  208.       .autoshell = 1
  209.    elseif uparg=OFF__MSG or uparg='0' then
  210.       .autoshell = 0
  211.    else
  212.       sayerror 'AUTOSHELL =' .AUTOSHELL
  213.    endif
  214. compile endif
  215.  
  216. defc bottom,bot=
  217.    bottom
  218.  
  219. compile if EVERSION >='4.11'
  220. ;  BROWSE -- A simple front end to Ralph Yozzo's browse() function.
  221. ;            It allows the user to type off/on/0/1/?.
  222. ;
  223. ;     BROWSE off/on/0/1
  224. ;
  225. ; specifies whether E should allow text to be altered (normal editing mode)
  226. ; or whether all text is read-only.
  227. ;
  228. ; Issuing BROWSE with '?' or no argument returns the current setting.
  229. ;
  230. ; The function browse() takes an optional argument 0/1.  It always returns
  231. ; the current setting.  So you can query the current setting without changing
  232. ; it by giving no argument.
  233. ;
  234. defc browse =
  235.    uparg=upcase(arg(1))
  236.    if uparg=ON__MSG or uparg=1 then
  237.       cb = browse(1)
  238.    elseif uparg=OFF__MSG or uparg='0' then
  239.       cb = browse(0)
  240.    elseif uparg='' or uparg='?' then
  241.       cb = browse()     -- query current state
  242.  compile if EVERSION >= 5
  243.       /* jbl 12/30/88:  move msg to this case only, avoid trivial sayerror's.*/
  244.       sayerror BROWSE_IS__MSG word(OFF__MSG ON__MSG, cb+1)
  245.  compile endif
  246.    else
  247.       sayerror INVALID_ARG__MSG ON_OFF__MSG'/?)'
  248.       stop
  249.    endif
  250.  compile if EVERSION < 5
  251.    if cb then cb=ON__MSG; else cb=OFF__MSG; endif
  252.    sayerror BROWSE_IS__MSG cb
  253.  compile endif
  254. compile endif
  255.  
  256. compile if EVERSION < 4       -- With linking, BOX can be an external module.
  257. ; Ver.3.11:  Don't move cursor for BOX R.
  258. ;  Script style suggested by Larry Salomon, Jr.
  259. defc box=  /* give height width style */
  260.    universal tempofid
  261.  
  262.    uparg=upcase(arg(1))
  263.    msg =  BOX_ARGS__MSG
  264.    if not length(uparg) then
  265.       sayerror msg
  266.       cursor_command;begin_line;erase_end_line;keyin 'Box '
  267.       stop
  268.    endif
  269.    if marktype()<>'BLOCK' then
  270.       sayerror -288  -- 'Block mark required'
  271.       stop
  272.    endif
  273.    flg=0
  274.    for ptr = 1 to length(uparg)
  275.       if flg then
  276.          style=substr(arg(1),ptr,1)
  277.       else
  278.          style=substr(uparg,ptr,1)
  279.       endif
  280.       if style='/' then
  281.          flg=1; iterate
  282.       endif
  283.       if not flg and verify(uparg,"123456BCPAERS") then
  284.          sayerror msg
  285.          cursor_command;begin_line;erase_end_line;keyin 'Box '
  286.          stop
  287.       endif
  288.       call psave_pos(save_pos)
  289.       getmark firstline,lastline,firstcol,lastcol,fileid
  290.       if style='E' then
  291.          getline tline,firstline,fileid
  292.          getline bline,lastline,fileid
  293.          msg=BOX_MARK_BAD__MSG
  294.          if firstcol=1 or firstline=1 or lastline=fileid.last then
  295.             sayerror msg
  296.             stop
  297.          endif
  298.  
  299.          brc=substr(bline,lastcol+1,1)
  300.          lside=substr(tline,firstcol-1,1)
  301.          if lside='║' or lside='│' or lside=';' or lside='|' or lside='█'  then
  302.             sl=1
  303.          elseif lside='*' and firstcol>2 and  -- MAX prevents error if firstcol <= 2
  304.                               pos(substr(tline,max(firstcol-2,1),1),'{/.') then
  305.                sl=2
  306.          elseif brc=lside then
  307.             sl=1
  308.          else
  309.             sayerror msg
  310.             stop
  311.          endif
  312.          for i=firstline to lastline
  313.             getline line,i,fileid
  314.             replaceline substr(line,1,firstcol-sl-1)||substr(line,firstcol,lastcol+1-firstcol)||substr(line,lastcol+sl+1),i,fileid
  315.          endfor
  316.          deleteline lastline+1,fileid
  317.          deleteline firstline-1,fileid
  318.          call prestore_pos(save_pos)
  319.          call pset_mark( firstline-1,lastline-1,firstcol-sl,lastcol-sl,marktype(),fileid)
  320.       elseif style='R' then
  321.          if not pblock_reflow(0,spc,tempofid) then
  322.             call pblock_reflow(1,spc,tempofid)
  323.          endif
  324.          call prestore_pos(save_pos)
  325.       else
  326.          if flg then
  327.             lside=style;rside=style;tside=style;tlc=style;trc=style;blc=style;brc=style
  328.          else
  329.             if style='P' then lside='{*';rside='*}';tside='*';tlc='{*';trc='*}';blc='{*';brc='*}'
  330.             elseif style='A' then lside=';';rside=' ';tside='*';tlc=';';trc=' ';blc=';';brc=' '
  331.             elseif style='C' then lside='/*';rside='*/';tside='*';tlc='/*';trc='*/';blc='/*';brc='*/'
  332.             elseif style=1 then lside='│';rside='│';tside='─';tlc='┌';trc='┐';blc='└';brc='┘'
  333.             elseif style=2 then lside='║';rside='║';tside='═';tlc='╔';trc='╗';blc='╚';brc='╝'
  334.             elseif style=3 then lside='|';rside='|';tside='-';tlc='+';trc='+';blc='+';brc='+'
  335.             elseif style=4 then lside='█';rside='█';tside='▀';tlc='█';trc='█';blc='▀';brc='▀'
  336.             elseif style=5 then lside='│';rside='│';tside='═';tlc='╒';trc='╕';blc='╘';brc='╛'
  337.             elseif style=6 then lside='║';rside='║';tside='─';tlc='╓';trc='╖';blc='╙';brc='╜'
  338.             elseif style='S' then lside='.*';rside='**';tside='*';tlc='.*';trc='**';blc='.*';brc='**'
  339.             else   style='B';lside=' ';rside=' ';tside=' ';tlc=' ';trc=' ';blc=' ';brc=' '
  340.             endif
  341.          endif
  342.          sl=length(lside)
  343.          width=1+lastcol-firstcol   /* width of inside of box */
  344.          side=substr('',1,width,tside)
  345.          line = substr('',1,firstcol-1)||blc||side||brc
  346.          insertline line,lastline+1,fileid
  347.          insertline substr('',1,firstcol-1)||tlc||side||trc,firstline,fileid
  348.          for i=firstline+1 to lastline+1
  349.             getline line,i,fileid
  350.             replaceline substr(line,1,firstcol-1)||lside||substr(line,firstcol,width)||rside||substr(line,lastcol+1),i,fileid
  351.          endfor
  352.          call prestore_pos(save_pos)
  353.          call pset_mark(firstline+1,lastline+1,firstcol+sl,lastcol+sl,marktype(),fileid)
  354.       endif
  355.       flg=0
  356.    endfor
  357. compile endif
  358.  
  359. defc c,change=
  360.    universal lastchangeargs, default_search_options
  361. compile if SETSTAY='?'
  362.    universal stay
  363. compile endif
  364. compile if defined(HIGHLIGHT_COLOR)
  365.    universal search_len
  366. compile endif
  367.  
  368. compile if SETSTAY
  369.    call psave_pos(savepos)
  370. compile endif
  371.    /* Insert default_search_options just before supplied options (if any)    */
  372.    /* so the supplied options will take precedence.                          */
  373.    args=strip(arg(1),'L')  /* Delimiter = 1st char, ignoring leading spaces. */
  374.    user_options=''
  375.    if args<>'' then        /* If args blank, use lastchangeargs. */
  376.       if default_search_options='' then
  377.          lastchangeargs=args
  378.       else
  379.          delim=substr(args,1,1)
  380.          p=pos(delim,args,2)   /* find last delimiter of 2 or 3 */
  381.          if p then
  382. compile if defined(HIGHLIGHT_COLOR)
  383.             search_len=p-2
  384. compile endif
  385.             p=pos(delim,args,p+1)   /* find last delimiter of 2 or 3 */
  386.             if p>0 then
  387.                user_options=substr(args,p+1)
  388.                args=substr(args,1,p-1)
  389.             endif
  390.          else
  391.             sayerror NO_REP__MSG
  392.          endif
  393.          if marktype() then
  394.             all=''
  395.          else           -- No mark, so override if default is M.
  396.             all='A'
  397.          endif
  398.          lastchangeargs=args || delim || default_search_options || all || user_options
  399.       endif
  400.    endif
  401.    if verify(upcase(user_options),'M','M') then
  402.       call checkmark()
  403.       /* Put this line back in if you want the M choice to force */
  404.       /* the cursor to the start of the mark.                    */
  405. ;;;   call pbegin_mark()  /* mark specified - make sure at top of mark */
  406.    endif
  407.    'xcom c 'lastchangeargs
  408.  
  409. compile if SETSTAY='?'
  410.    if stay then
  411. compile endif
  412. compile if SETSTAY
  413.       call prestore_pos(savepos)
  414. compile endif
  415. compile if SETSTAY='?'
  416.    endif
  417. compile endif
  418.  
  419. defc cd=
  420.    rc=0
  421.    if arg(1)='' then
  422.       dir= directory()
  423.    else
  424.       dir= directory(arg(1))
  425.    endif
  426.    if not rc then
  427.       sayerror CUR_DIR_IS__MSG dir
  428.    endif
  429.  
  430. defc center=
  431.    call pcenter_mark()
  432.  
  433. defc chr=
  434.    parse arg i '=' .
  435. compile if EVERSION < 5
  436.    setcommand 'chr 'i'='chr(i)'',5,1
  437.    cursorcommand
  438. compile else
  439.    sayerror 'chr 'i'='chr(i)''
  440. compile endif
  441.  
  442. compile if EPM
  443. defc close=
  444.    call windowmessage(0,  getpminfo(EPMINFO_EDITCLIENT),
  445.                       41,                 -- WM_CLOSE
  446.                       0,
  447.                       0)
  448. compile endif
  449.  
  450. defc deleteautosavefile
  451. compile if EVERSION < '4.12'
  452.    universal autosave
  453.    if autosave then               -- Erase the tempfile if autosave is on.
  454. compile else
  455.    if .autosave then               -- Erase the tempfile if autosave is on.
  456. compile endif
  457.       TempName = MakeTempName()
  458.       getfileid tempid, TempName  -- (provided it's not in the ring.)
  459.       if tempid='' then call erasetemp(TempName); endif
  460.    endif
  461.  
  462. ;  This command is the same function that has been attached to
  463. ;  the key Alt-equal.  Moved here as a separate command to make key
  464. ;  binding more flexible.  And to allow execution without a key binding.
  465. ;  In EPM, no getkey() prompt.  Cancel at first error.
  466. defc dolines=
  467.    if marktype()='LINE' then
  468. compile if EVERSION < 5
  469.       sayerror EX_ALL_YN__MSG
  470.       loop
  471.          k=upcase(getkey())
  472.          if k=esc then return ''; endif
  473.          if k=NO_CHAR or k=YES_CHAR then leave endif
  474.       endloop
  475. compile else
  476.       k=substr('0000'YES_CHAR || NO_CHAR, winmessagebox('Dolines', EX_ALL__MSG, 16389) - 1, 1)  -- YESNOCANCEL + MOVEABLE
  477.       if not k then return ''; endif  -- 'Y'=Yes; 'N'=No; '0'=Cancel
  478. compile endif
  479.       if k='Y' then
  480.          getmark firstline,lastline,i,i,fileid
  481.          for i=firstline to lastline
  482.             getline line,i,fileid
  483.             line
  484.          endfor
  485.          sayerror 0
  486.          return ''
  487.       endif
  488. compile if EVERSION < 5
  489.       sayerror 0
  490. compile endif
  491.    endif
  492.    if .line then
  493.       getline line
  494.       line
  495.    endif
  496.  
  497. /* This DEFC EDIT eventually calls the built-in edit command, by calling      */
  498. /* loadfile(), but does additional processing for messy-desk windowing (moves */
  499. /* each file to its own window), and ends by calling select_edit_keys().      */
  500. ; Parse off each file individually.  Files can optionally be followed by one
  501. ; or more commands, each in quotes.  The first file that follows a host file
  502. ; must be separated by a comma, an option, or a (possibly null) command.
  503. ;
  504. ; EPM doesn't give error messages from XCOM EDIT, so we have to handle that for
  505. ; it.
  506. compile if EVERSION < 5   -- E3 & EOS2:  display multiple messages on a cleared
  507.   define SAYERR = 'say'   -- screen, since only most recent SAYERROR can be seen.
  508. compile else
  509.   define SAYERR = 'sayerror'  -- EPM:  Message box shows all SAYERRORs
  510. compile endif
  511.  
  512. compile if LINK_HOST_SUPPORT & (HOST_SUPPORT='EMUL' | HOST_SUPPORT='E3EMUL')
  513.  compile if not defined(MVS)
  514.     MVS = 0
  515.  compile endif
  516.  compile if not defined(E3MVS)
  517.     E3MVS = 0
  518.  compile endif
  519.  compile if not defined(HOST_LT_REQUIRED)
  520.     HOST_LT_REQUIRED = 0
  521.  compile endif
  522. compile endif
  523.  
  524. compile if not EPM
  525. defc e,ed,edit=
  526. compile else
  527. defc e,ed,edit,epm=
  528. compile endif
  529. universal default_edit_options
  530. compile if not EPM
  531.    universal messy
  532. compile endif
  533.   compile if (HOST_SUPPORT='EMUL' | HOST_SUPPORT='E3EMUL') & not SMALL
  534.    universal fto                -- Need this passed to loadfile...
  535.   compile endif
  536.  
  537.    rest=strip(arg(1))
  538.  
  539.    if rest='' then   /* 'edit' by itself goes to next file */
  540. compile if EVERSION < 5
  541.       call pnextfile()
  542.       call select_edit_keys()
  543. compile else
  544.       nextfile
  545. compile endif
  546.       return 0
  547.    endif
  548.  
  549.    options=default_edit_options
  550.    parse value '0 0' with files_loaded new_files_loaded new_files not_found bad_paths truncated access_denied invalid_drive error_reading error_opening first_file_loaded
  551. --  bad_paths     --> Non-existing path specified.
  552. --  truncated     --> File contained lines longer than 255 characters.
  553. --  access_denied --> If user tried to edit a subdirectory.
  554. --  invalid_drive --> No such drive letter
  555. --  error_reading --> Bad disk(ette).
  556. --  error_opening --> Path contained invalid name.
  557.  
  558.    do while rest<>''
  559.       rest=strip(rest,'L')
  560.       if substr(rest,1,1)=',' then rest=strip(substr(rest,2),'L'); endif
  561.       ch=substr(rest,1,1)
  562. compile if (HOST_SUPPORT='EMUL' | HOST_SUPPORT='E3EMUL') & not SMALL
  563.  compile if (MVS or E3MVS) and not HOST_LT_REQUIRED  -- (MVS filespecs can start with '.)
  564.   compile if EVERSION >= '5.50'      -- Now use "" to support spaces in filenames
  565.       if 0 then                         -- No-op
  566.   compile else
  567.       if ch='"' then                    -- Command
  568.   compile endif
  569.  compile else
  570.   compile if EVERSION >= '5.50'     -- Now use "" to support spaces in filenames
  571.       if ch="'" then                    -- Command
  572.   compile else
  573.       if ch='"' | ch="'" then           -- Command
  574.   compile endif
  575.  compile endif
  576. compile else
  577.  compile if EVERSION >= '5.50'     -- Now use "" to support spaces in filenames
  578.       if ch="'" then                    -- Command
  579.  compile else
  580.       if ch='"' | ch="'" then           -- Command
  581.  compile endif
  582. compile endif
  583.          parse value rest with (ch) cmd (ch) rest
  584.          do while substr(rest,1,1)=ch & pos(ch,rest,2)
  585.             parse value rest with (ch) p (ch) rest
  586.             cmd = cmd || ch || p
  587.          enddo
  588.          cmd
  589.       elseif ch='/' then       -- Option
  590.          parse value rest with opt rest
  591.          options=options upcase(opt)
  592.       else
  593.          files_loaded=files_loaded+1  -- Number of files we tried to load
  594. compile if EVERSION >= '5.50'     -- Now use "" to support spaces in filenames
  595.       if ch='"' then
  596.          p=pos('"',rest,2)
  597.          if p then
  598.             file = substr(rest, 1, p)
  599.             rest = substr(rest, p+1)
  600.          else
  601.             sayerror INVALID_FILENAME__MSG
  602.             return
  603.          endif
  604.       else
  605. compile endif
  606. compile if HOST_SUPPORT & not SMALL
  607.          p=length(rest)+1  -- If no delimiters, take to the end.
  608.          p1=pos(',',rest); if not p1 then p1=p; endif
  609.          p2=pos('/',rest); if not p2 then p2=p; endif
  610.          p3=pos('"',rest); if not p3 then p3=p; endif
  611.          p4=pos("'",rest); if not p4 then p4=p; endif
  612.   compile if HOST_SUPPORT='EMUL' | HOST_SUPPORT='E3EMUL'
  613.     compile if MVS or E3MVS
  614.          p4=p     -- Can't use single quote for commands if allowing MVS files
  615.     compile endif
  616.          p5=pos('[',rest); if not p5 then p5=p; endif  -- Allow for [FTO]
  617.          p=min(p1,p2,p3,p4,p5)
  618.   compile else
  619.          p=min(p1,p2,p3,p4)
  620.   compile endif
  621.          file=substr(rest,1,p-1)
  622.          if VMfile(file,more) then        -- tricky - VMfile modifies file
  623.             if p=p1 then p=p+1; endif     -- Keep any except comma in string
  624.             rest=more substr(rest,p)
  625.          else
  626. compile endif
  627.             parse value rest with file rest2
  628.             if pos(',',file) then parse value rest with file ',' rest
  629.             else rest=rest2; endif
  630. compile if HOST_SUPPORT & not SMALL
  631.          endif
  632.   compile if HOST_SUPPORT='EMUL' | HOST_SUPPORT='E3EMUL'
  633.          if substr(strip(rest,'L'),1,1)='[' then
  634.             parse value rest with '[' fto ']' rest
  635.          else
  636.             fto = ''                           --  reset for each file!
  637.          endif
  638.   compile endif
  639. compile endif
  640. compile if EVERSION >= '5.50'     -- Now use "" to support spaces in filenames
  641.       endif
  642. compile endif
  643.  
  644.          call parse_filename(file,.filename)
  645.  
  646. compile if USE_APPEND  -- Support for DOS 3.3's APPEND, thanks to Ken Kahn.
  647.          If not(verify(file,'\:','M')) then
  648.             if not exist(file) then
  649.                File = Append_Path(File)||File  -- LAM todo: fixup
  650.             Endif
  651.          Endif
  652. compile endif
  653.  
  654. compile if WANT_WINDOWS         -- Always 0 for EPM
  655.          if messy then                            -- messy-desk style?
  656.             .windowoverlap=1
  657.             if pos('H',options) then      -- hidden option used?
  658.                call loadfile(file,options)
  659.             else
  660.                if not verify(file,'?*','M') and   -- If no wildcards
  661.                   not pos('D',options)    -- and not /D,
  662.                then
  663.                   if verify(file,':\','M') then   -- get fully qualified file
  664.                      getfileid newfileid,file
  665.                   else
  666.                      getfileid newfileid,directory()'\'file -- (add path if necessary).
  667.                      if newfileid='' then getfileid newfileid,file; endif
  668.                   endif
  669.                   if newfileid<>'' then           -- If it's already loaded,
  670.                      .box=1
  671.                      if newfileid.windowid=0 then   -- (in the hidden ring?)
  672.                         newwindow 'e /w' options file -- (Yes, have to edit it.)
  673.                      else
  674.                         activatefile newfileid       -- then just activate it.
  675.                      endif
  676.                      iterate
  677.                   endif
  678.                endif
  679.                newwindow 'e /w /n'  /* start a new file */
  680.                /* Newwindow 'e' creates an empty file just like E startup. */
  681.                getfileid emptyfileid
  682.                if not (rc and rc<>-282) then  -- sayerror('New file')
  683.                   if pos('Q',options) then sayerror 1; endif
  684.                   call loadfile(file,options argsep||'w')
  685.                   loadrc=rc
  686.                   getfileid newfileid
  687.                   if loadrc=-270 & newfileid=emptyfileid then  -- sayerror('Not enough memory')
  688.                      deletewindow
  689.                      stop
  690.                   endif           -- Otherwise, wildcard & some were loaded.
  691.                   call create_window_for_each_file(emptyfileid)
  692.                   .windowoverlap=1
  693.                   if not loadrc or loadrc=-282 or    -- sayerror('New file')
  694.                                    loadrc=-270 or    -- sayerror('Not enough memory')
  695.                                    loadrc=-278 then  -- sayerror('Lines truncated')
  696.                      /* Normal results, normal cleanup:  discard empty file. */
  697.                      activatefile emptyfileid
  698.                      quitview
  699.                      activatefile newfileid
  700.                   else     /* Unexpected error! */
  701.                      deletewindow
  702.                   endif
  703.                endif
  704.                prevwindow; .box=1; nextwindow
  705.             endif
  706.          else      -- not messy
  707. compile endif
  708.             call loadfile(file,options)
  709. compile if WANT_WINDOWS
  710.             prevfile;.box=1;nextfile
  711.          endif -- if messy
  712. compile endif
  713.  
  714.          if rc=-3 then        -- sayerror('Path not found')
  715.             bad_paths=bad_paths', 'file
  716.          elseif rc=-2 then    -- sayerror('File not found')
  717.             not_found=not_found', 'file
  718.          elseif rc=-282 then  -- sayerror('New file')
  719.             new_files=new_files', 'file
  720.             new_files_loaded=new_files_loaded+1
  721.          elseif rc=-278 then  --sayerror('Lines truncated')
  722.             truncated=truncated', 'file
  723.             .modify = 0
  724.          elseif rc=-5 then  -- sayerror('Access denied')
  725.             access_denied=access_denied', 'file
  726.          elseif rc=-15 then  -- sayerror('Invalid drive')
  727.             invalid_drive=invalid_drive', 'file
  728.          elseif rc=-286 then  -- sayerror('Error reading file')
  729.             error_reading=error_reading', 'file
  730.          elseif rc=-284 then  -- sayerror('Error opening file')
  731.             error_opening=error_opening', 'file
  732.          endif
  733.          if first_file_loaded='' then
  734.             if rc<>-3   &  -- sayerror('Path not found')
  735.                rc<>-2   &  -- sayerror('File not found')
  736.                rc<>-5   &  -- sayerror('Access denied')
  737.                rc<>-15     -- sayerror('Invalid drive')
  738.             then
  739.                getfileid first_file_loaded
  740.             endif
  741.          endif
  742.       endif  -- not "cmd"
  743.    enddo  -- while rest<>''
  744.    if files_loaded>1 then  -- If only one file, leave E3's message
  745.       if new_files_loaded>1 then p='New files:'; else p='New file:'; endif
  746. compile if EVERSION < 5  -- EPM doesn't give messages; have to supply in all cases.
  747.       if new_files || bad_paths || not_found || truncated || access_denied || error_reading || error_opening || invalid_drive <>
  748.          invalid_drive || error_opening || error_reading || access_denied || truncated || not_found || bad_paths || new_files
  749.       then                                        -- More than one.
  750. compile else
  751.       multiple_errors = (new_files || bad_paths || not_found || truncated || access_denied || error_reading || error_opening || invalid_drive <>
  752.                         invalid_drive || error_opening || error_reading || access_denied || truncated || not_found || bad_paths || new_files ) &
  753.                   '' <> new_files || bad_paths || not_found || truncated || access_denied || error_reading || error_opening || invalid_drive
  754.  
  755. compile endif
  756.          if new_files then $SAYERR NEW_FILE__MSG substr(new_files,2); endif
  757.          if not_found then $SAYERR FILE_NOT_FOUND__MSG':' substr(not_found,2); endif
  758. compile if EPM  -- If only one file, don't need "New file" msg in EPM.
  759.    else
  760.       multiple_errors = 0
  761.    endif
  762. compile endif
  763.          if bad_paths then $SAYERR BAD_PATH__MSG':' substr(bad_paths,2); endif
  764.          if truncated then $SAYERR LINES_TRUNCATED__MSG':' substr(truncated,2); endif
  765.          if access_denied then $SAYERR ACCESS_DENIED__MSG':' substr(access_denied,2); endif
  766.          if invalid_drive then $SAYERR INVALID_DRIVE__MSG':' substr(invalid_drive,2); endif
  767.          if error_reading then $SAYERR ERROR_OPENING__MSG':' substr(error_reading,2); endif
  768.          if error_opening then $SAYERR ERROR_READING__MSG':' substr(error_opening,2); endif
  769. compile if EVERSION < 5
  770.          pause
  771.       elseif new_files then sayerror NEW_FILE__MSG':' substr(new_files,2)
  772.       elseif bad_paths then sayerror BAD_PATH__MSG':' substr(bad_paths,2)
  773.       elseif not_found then sayerror FILE_NOT_FOUND__MSG':' substr(not_found,2)
  774.       elseif truncated then sayerror LINES_TRUNCATED__MSG':' substr(truncated,2)
  775.       elseif access_denied then sayerror ACCESS_DENIED__MSG':' substr(access_denied,2)
  776.       elseif invalid_drive then sayerror INVALID_DRIVE__MSG':' substr(invalid_drive,2)
  777.       elseif error_reading then sayerror ERROR_OPENING__MSG':' substr(error_reading,2)
  778.       elseif error_opening then sayerror ERROR_READING__MSG':' substr(error_opening,2)
  779.       endif
  780. compile else
  781.       if multiple_errors then
  782.          messageNwait(MULTIPLE_ERRORS__MSG)
  783.       endif
  784. compile endif
  785.       if first_file_loaded<>'' then activatefile first_file_loaded; endif
  786. compile if EVERSION < 5
  787.    endif
  788. compile endif
  789.  
  790. compile if not EPM
  791.    /* Save the edit RC through select_edit_keys, since it might get reset  */
  792.    /* by some command like 'tabs' or 'margins'.  This used to be in        */
  793.    /* select_edit_keys, but that made configurability hard.                */
  794.    saverc=rc
  795.    call select_edit_keys()
  796.    rc=saverc
  797.    .box=2
  798. compile elseif MENU_LIMIT
  799. ;compile if SHOW_MODIFY_METHOD = 'TITLE'
  800. ;  call settitletext(.filename) /* done internally */
  801. ;compile endif
  802.    if .visible & files_loaded then
  803.       call updateringmenu()
  804.    endif
  805. compile endif
  806.  
  807.  
  808. ; LAM - Edit a file along the EPATH.  This command will be included if
  809. ; the user is including the required routines.  If you've done a
  810. ;   SET EPMPATH=d:\EPM;d:\my_emacs;d:\E_macros
  811. ; and then do
  812. ;   ep stdcmds.e
  813. ; that will load this file, just as if you had entered
  814. ;   e d:\e_macros\stdcmds.e
  815. compile if USE_APPEND or (WANT_SEARCH_PATH and WANT_GET_ENV and not SMALL)
  816. defc ep, epath=
  817.    parse arg filename pathname .
  818.    if pathname='' then
  819. compile if E3
  820.       if filetype(filename)='BAT' then
  821. compile else
  822.       if filetype(filename)='CMD' then
  823. compile endif
  824.          pathname='PATH'
  825.       else
  826.          pathname=EPATH
  827.       endif
  828.    endif
  829.    if not exist(filename) then
  830.       filename = search_path_ptr(Get_Env(pathname,1),filename)filename
  831.    endif
  832.    'e 'filename
  833.  
  834.  compile if EPM
  835. defc op, opath, openpath=
  836.    "open 'ep "arg(1)"'"
  837.  compile endif
  838. compile endif
  839.  
  840.  
  841. ; jbl 1/12/89:  The syntax of ECHO is revised to be like browse().  It's
  842. ; a function so a macro can test its current value.
  843. defc echo =
  844. compile if EVERSION >= '4.12'
  845.    uparg=upcase(arg(1))
  846.    if uparg=ON__MSG or uparg=1 then
  847.       call echo(1)
  848.    elseif uparg=OFF__MSG or uparg='0' then
  849.       call echo(0)
  850.    else
  851.  compile if EVERSION < 5
  852.       if echo() then onoff = ON__MSG; else onoff = OFF__MSG; endif
  853.       cursor_command
  854.       setcommand 'echo' onoff,8,1
  855.  compile else
  856.       sayerror ECHO_IS__MSG word(OFF__MSG ON__MSG, echo()+1)
  857.  compile endif
  858.    endif
  859. compile else                         -- The old way, for E3 & EOS2FAM.
  860.    if arg(1) = '' then
  861.       echo 'ON'
  862.    else
  863.       echo arg(1)
  864.    endif
  865. compile endif
  866.  
  867. compile if TOGGLE_ESCAPE
  868. defc ESCAPEKEY
  869.    universal ESCAPE_KEY
  870.    uparg=upcase(arg(1))
  871.    if uparg=ON__MSG or uparg=1 then
  872.       ESCAPE_KEY = 1
  873.    elseif uparg=OFF__MSG or uparg=0 then
  874.       ESCAPE_KEY = 0
  875.    else
  876.       sayerror 'EscapeKey' word(OFF__MSG ON__MSG, ESCAPE_KEY+1)
  877.    endif
  878. compile endif
  879.  
  880.  
  881. define TEMPFILENAME = 'vTEMP_FILENAME'
  882. compile if WANT_ET_COMMAND     -- Ver. 3.09 - Let user omit ET command.
  883.  compile if EVERSION < 5
  884. defc et=
  885.  compile else
  886.  define TEMPFILENAME = 'tempfile'
  887. defc et,etpm=
  888.  compile endif
  889.    universal vTEMP_PATH,vTEMP_FILENAME
  890.    infile=arg(1); if infile='' then infile=MAINFILE endif
  891.    sayerror COMPILING__MSG infile
  892.  compile if EVERSION < 5
  893.    quietshell 'xcom et /e' vTEMP_FILENAME infile
  894.    if rc=-2 then sayerror CANT_FIND_PROG__MSG 'ET.Exe';stop endif
  895.  compile else
  896.    tempfile=vTEMP_PATH'ETPM'substr(ltoa(gethwnd(EPMINFO_EDITCLIENT),16),1,4)'.TMP'
  897.    -- quietshell 'xcom etpm /e 'tempfile infile
  898.    quietshell 'xcom etpm 'infile ' /e 'tempfile ' /p'upcase(EPATH)
  899.    if rc=-2 then sayerror CANT_FIND_PROG__MSG 'ETPM.EXE'; stop; endif
  900.    if rc=41 then sayerror 'ETPM.EXE' CANT_OPEN_TEMP__MSG '"'tempfile'"'; stop; endif
  901.  compile endif
  902.    if rc then
  903.       saverc = rc
  904.       call ec_position_on_error($TEMPFILENAME)
  905.       rc = saverc
  906.    else
  907.  compile if EPM
  908.       refresh
  909.  compile endif
  910.       sayerror COMP_COMPLETED__MSG
  911.    endif
  912.    call erasetemp($TEMPFILENAME) -- 4.11:  added to erase the temp file.
  913. compile endif
  914.  
  915.                -- No EXIT command in EPM.  Do it from the system pull-downs.
  916. compile if EVERSION < 5
  917. ;  Ver. 3.11D  Optional return code as argument.  Added by Davis Foulger
  918. defc exit=
  919.    if askyesno(EXIT_PROMPT__MSG) = YES_CHAR then
  920.       exit arg(1)
  921.    endif
  922.    sayerror 0
  923. compile endif
  924.  
  925.  
  926. defc expand=
  927.    universal expand_on
  928.    uparg=upcase(arg(1))
  929.    if uparg=ON__MSG then
  930.       expand_on = 1
  931.       call select_edit_keys()
  932.    elseif uparg=OFF__MSG then
  933.       expand_on = 0
  934.       call select_edit_keys()
  935.    elseif uparg='' then
  936. compile if EVERSION < 5
  937.       if expand_on then onoff = ON__MSG; else onoff = OFF__MSG; endif
  938.       cursor_command
  939.       setcommand 'expand' onoff,8,1
  940. compile else
  941.       sayerror 'EXPAND:' word(OFF__MSG ON__MSG, expand_on+1)
  942. compile endif
  943.    else
  944.       sayerror INVALID_ARG__MSG ON_OFF__MSG')'
  945.       stop
  946.    endif
  947.  
  948. defc f,file=
  949.    's 'arg(1)
  950.    if not rc then
  951.       .modify=0            -- If saved to a different file, turn modify off
  952.       'q'
  953.       call select_edit_keys()
  954.    endif
  955.  
  956.  
  957. ;  EPM's replacement for Alt-F.  "FILL <character>".
  958. defc fill=
  959.    call checkmark()
  960.    call pfill_mark(arg(1))
  961.  
  962.  
  963. compile if EVERSION < 4       -- With linking, GET can be an external module.
  964. defc get=
  965.    universal default_edit_options
  966.    get_file = strip(arg(1))
  967.    if get_file='' then sayerror NO_FILENAME__MSG 'GET'; stop endif
  968.    if pos(argsep,get_file) then
  969.       sayerror INVALID_OPTION__MSG
  970.       stop
  971.    endif
  972.    call parse_filename(get_file,.filename)
  973.    getfileid fileid
  974.    s_last=.last
  975.    'e /q /h /d' default_edit_options get_file
  976.    editrc=rc
  977.    getfileid gfileid
  978.    if editrc= -2 | .last=0 then  -- -2 = sayerror('New file')
  979.       'q'
  980.       if editrc=-2 then
  981.          sayerror FILE_NOT_FOUND__MSG':  'get_file
  982.       else
  983.          sayerror FILE_IS_EMPTY__MSG':  'get_file
  984.       endif
  985.       stop
  986.    endif
  987.    if editrc & editrc<> -278 then  -- -278 = sayerror('Lines truncated')
  988.       sayerror editrc
  989.       stop
  990.    endif
  991.    call psave_mark(save_mark)
  992.    top
  993.    mark_line
  994.    bottom
  995.    mark_line
  996.    activatefile fileid
  997.    rc=0
  998.    copy_mark
  999.    copy_rc=rc           -- Test for memory too full for copy_mark.
  1000.    activatefile gfileid
  1001.    'q'
  1002.    parse value save_mark with s_firstline s_lastline s_firstcol s_lastcol s_mkfileid s_mt
  1003.    if fileid=s_mkfileid then           -- May have to move the mark.
  1004.       diff=fileid.last-s_last          -- (Adjustment for difference in size)
  1005.       if fileid.line<s_firstline then s_firstline=s_firstline+diff; endif
  1006.       if fileid.line<s_lastline then s_lastline=s_lastline+diff; endif
  1007.    endif
  1008.    call prestore_mark(s_firstline s_lastline s_firstcol s_lastcol s_mkfileid s_mt)
  1009.    if copy_rc then
  1010.       sayerror NOT_2_COPIES__MSG get_file
  1011.    else
  1012.       call message(1)
  1013.    endif
  1014.    activatefile fileid
  1015.    call select_edit_keys()
  1016. compile endif
  1017.  
  1018. defc goto =
  1019.    parse arg line col .
  1020.    line
  1021.    if col<>'' then .col = col; endif
  1022.  
  1023. /* Uses findfile statement to search EPATH for the helpfile.              */
  1024. /* Its syntax: findfile destfilename,searchfilename[,envpathvar][,['P']]  */
  1025. defc help=
  1026. compile if EVERSION < 5
  1027.    universal messy
  1028. compile endif
  1029.    helpfile = HELPFILENAME
  1030.  
  1031. compile if EVERSION > 4
  1032.    -- 4.02:  search EPATH/DPATH for the help file.  New 'D' option on findfile.
  1033.    findfile destfilename, helpfile, '','D'
  1034.    if rc then    /* If not there, search the HELP path. */
  1035.       findfile destfilename, helpfile, 'HELP'
  1036.    endif
  1037. compile else
  1038.    findfile destfilename, helpfile,EPATH
  1039. compile endif
  1040.    if rc then
  1041.       /* If all that fails, try the standard path. */
  1042.       findfile destfilename, helpfile, 'PATH'
  1043.       if rc then
  1044.          sayerror FILE_NOT_FOUND__MSG':' helpfile
  1045.          return ''
  1046.       endif
  1047.    endif
  1048. compile if EVERSION < 5
  1049.  compile if WANT_WINDOWS
  1050.    if messy then
  1051.       newwindow 'e /w 'destfilename  /* load one view only */
  1052.       call setzoomwindow(1,1,1,25,screenwidth())
  1053.       .windowoverlap=1
  1054.    else
  1055.  compile endif
  1056.       'e /w 'destfilename  /* load one view of help only */
  1057.  compile if WANT_WINDOWS
  1058.    endif
  1059.  compile endif
  1060. compile else
  1061.    'openhelp' destfilename
  1062. compile endif
  1063.  
  1064. ; In EPM we don't do a getkey() to ask you for the key.  You must supply it
  1065. ; as part of the command, as in "key 80 =".
  1066. defc key=
  1067.    parse value arg(1) with number k .
  1068.    if not isnum(number) then sayerror INVALID_NUMBER__MSG;stop endif
  1069.    -- jbl:  Allow the user to specify the key in the command, so he can
  1070.    -- say "key 80 =" and avoid the prompt.
  1071.    if k == '' then
  1072. compile if EVERSION < 5
  1073.       k=mgetkey(KEY_PROMPT1__MSG)  -- Accept key from macro.
  1074.    endif
  1075.    if k<>esc then
  1076.       cursor_data
  1077. compile else
  1078.       sayerror KEY_PROMPT2__MSG '"key 'number' =", "key 'number' S+F3".'
  1079.       return
  1080.    else
  1081.       k=resolve_key(k)
  1082. compile endif
  1083.       for i=1 to number
  1084.          executekey k
  1085.       endfor
  1086. compile if EVERSION < 5
  1087.       cursor_command
  1088. compile endif
  1089.    endif
  1090.    sayerror 0
  1091.  
  1092.  
  1093. defc l, locate =  /* Note:  this DEFC also gets executed by the slash ('/') command. */
  1094.    universal default_search_options
  1095. compile if defined(HIGHLIGHT_COLOR)
  1096.    universal search_len
  1097. compile endif
  1098. compile if EVERSION < 5
  1099.    r=rc /* This little trick tells us whether we're in a macro or on command */
  1100.         /* line, so we'll know where to leave the cursor at end.             */
  1101. compile endif
  1102.    /* Insert default_search_options just before supplied options (if any)    */
  1103.    /* so the supplied options will take precedence.                          */
  1104.    args=strip(arg(1),'L')
  1105. compile if not defined(HIGHLIGHT_COLOR)
  1106.    if default_search_options<>'' then
  1107. compile endif
  1108.       delim=substr(args,1,1)
  1109.       p=pos(delim,args,2)
  1110.       user_options=''
  1111.       if p then
  1112.          user_options=substr(args,p+1)
  1113.          args=substr(args,1,p-1)
  1114.       endif
  1115.       if marktype() then
  1116.          all=''
  1117.       else           -- No mark, so override if default is M.
  1118.          all='A'
  1119.       endif
  1120. compile if defined(HIGHLIGHT_COLOR)
  1121.       search_len=length(args)-1   /***** added for hilite *****/
  1122. compile endif
  1123.       args=args|| delim || default_search_options || all || user_options
  1124. compile if not defined(HIGHLIGHT_COLOR)
  1125.    endif
  1126. compile endif
  1127.    'xcom l 'args
  1128. compile if EVERSION < 5
  1129.    if not rc and r then
  1130.       cursor_data
  1131.  compile if defined(HIGHLIGHT_COLOR)
  1132.       refresh
  1133.       sayat '', .windowy+.cursory-1,.windowx+.cursorx-1,
  1134.             HIGHLIGHT_COLOR, min(search_len, .windowwidth - .cursorx + 1)
  1135.       k = mgetkey(); executekey k
  1136.  compile endif
  1137.    else
  1138.       call leave_last_command(r,rc)
  1139.    endif
  1140. compile elseif defined(HIGHLIGHT_COLOR)
  1141.    if not rc then
  1142.  compile if EVERSION < '5.50'
  1143.       refresh
  1144.       sayat '', .cursory, .cursorx, HIGHLIGHT_COLOR, min(search_len, .windowwidth - .cursorx + 1)
  1145.  compile elseif EVERSION >= '5.60'
  1146.       circleit LOCATE_CIRCLE_STYLE, .line, .col, .col+getpminfo(EPMINFO_LSLENGTH)-1, LOCATE_CIRCLE_COLOR1, LOCATE_CIRCLE_COLOR2
  1147.  compile elseif EVERSION >= '5.51'
  1148.       circleit LOCATE_CIRCLE_STYLE, .line, .col, .col+getpminfo(EPMINFO_LSLENGTH)-1, HIGHLIGHT_COLOR
  1149.  compile else
  1150.       circleit LOCATE_CIRCLE_STYLE, .line, .col, .col+search_len-1, HIGHLIGHT_COLOR
  1151. ;     refresh
  1152.  compile endif
  1153.    endif
  1154. compile endif
  1155.  
  1156. ; As of EPM 5.18, this command supports use of the DOS or OS/2 ATTRIB command,
  1157. ; so non-IBM users can also use the LIST command.  Note that installing SUBDIR
  1158. ; (DOS) or FILEFIND (OS/2) is still preferred, since it's not necessary to
  1159. ; "clean up" their output.  Also, ATTRIB before DOS 3.? doesn't support the /S
  1160. ; option we need to search subdirectories.
  1161. defc list, findfile, filefind=
  1162.    universal vTEMP_FILENAME
  1163.    universal subdir_present
  1164.  compile if EVERSION < 5
  1165.    call save_command_state(cstate)
  1166.  compile endif
  1167.    /* If I say "list c:\util" I mean the whole util directory.  But we */
  1168.    /* have to tell SubDir that explicitly by appending "\*.*".         */
  1169.    spec = arg(1)
  1170.    call parse_filename(spec,.filename)
  1171.    if spec='' then    /* If no argument at all, assume current directory. */
  1172.       spec="*.*"
  1173.    elseif not verify(spec,'*?','M') then      /* If no wildcards... */
  1174. compile if EPM                                   /* assume directory.  */
  1175.       if pos(rightstr(spec,1),'\:') then         /* If ends in ':' or '\' */
  1176. compile else
  1177.       if pos(substr(spec,length(spec),1),'\:') then
  1178. compile endif
  1179.          spec=spec'*.*'                             /* just add '*.*'         */
  1180.       else
  1181.          spec=spec'\*.*'                            /* Otherwise, add '\*.*'  */
  1182.       endif
  1183.    endif
  1184.    src = subdir(spec' >'vTEMP_FILENAME)  -- Moved /Q option to defproc subdir
  1185.  
  1186.    'e' argsep'd' argsep'q' vTEMP_FILENAME
  1187.    call erasetemp(vTEMP_FILENAME)
  1188.    if .last then
  1189.       .filename='.DIR 'spec
  1190.       if pos('ATTRIB.EXE',subdir_present) then  /* Handle differently          */
  1191.          getline line,1
  1192.          if src then                  /* Extract error message.      */
  1193.             'xcom q'
  1194. compile if EVERSION < 5
  1195.             call restore_command_state(cstate)
  1196. compile endif
  1197.             sayerror FILE_NOT_FOUND__MSG':  'line
  1198.          else                         /* Must delete the attributes.      */
  1199.             c=pos(':',line)           /* Delete through last space before */
  1200.             s=lastpos(' ',line,c+1)   /* the colon.  Can't use absolute   */
  1201.             if s then                 /* column position; changes with OS */
  1202.                call psave_mark(savemark)
  1203.                getfileid fid
  1204.                call pset_mark(1,.last,1,s,'BLOCK',fid)
  1205.                deletemark
  1206.                call prestore_mark(savemark)
  1207.                .modify=0
  1208.             endif
  1209.          endif
  1210. compile if not E3
  1211.       elseif substr(subdir_present,1,4)='dir ' then
  1212.          if .last<=2 & substr(textline(.last),1,8)='SYS0002:' then
  1213.             'xcom q'
  1214.             sayerror FILE_NOT_FOUND__MSG
  1215.          endif
  1216. compile endif
  1217.       endif
  1218.    else
  1219.       'xcom q'
  1220. compile if EVERSION < 5
  1221.       call restore_command_state(cstate)
  1222. compile endif
  1223.       sayerror FILE_NOT_FOUND__MSG
  1224.    endif
  1225.    call select_edit_keys()
  1226.  
  1227. compile if WANT_LAN_SUPPORT
  1228. defc lock
  1229.    if arg(1)<>'' then
  1230.       'e 'arg(1)
  1231.       if rc & rc<>-282 then  --sayerror('New file')
  1232.          return 1
  1233.       endif
  1234.    endif
  1235.    call lock()
  1236. compile endif
  1237.  
  1238. compile if WANT_LONGNAMES='SWITCH'
  1239. defc longnames
  1240.    universal SHOW_LONGNAMES
  1241.    uparg=upcase(arg(1))
  1242.    if uparg=ON__MSG or uparg=1 then
  1243.       SHOW_LONGNAMES = 1
  1244.    elseif uparg=OFF__MSG or uparg=0 then
  1245.       SHOW_LONGNAMES = 0
  1246.    else
  1247.       sayerror LONGNAMES_IS__MSG word(OFF__MSG ON__MSG, SHOW_LONGNAMES+1)
  1248.    endif
  1249. compile endif
  1250.  
  1251. defc loopkey=
  1252.    parse value arg(1) with finish k .
  1253.    if upcase(finish)='ALL' then
  1254.       finish= .last-.line+1
  1255.    endif
  1256.    if not isnum(finish) then sayerror INVALID_NUMBER__MSG;stop endif
  1257.    if k == '' then
  1258. compile if EVERSION < 5
  1259.       k=mgetkey(KEY_PROMPT1__MSG)  -- Accept key from macro.
  1260.    endif
  1261.    if k<>esc then
  1262.       cursor_data
  1263. compile else
  1264.       sayerror KEY_PROMPT2__MSG '"loopkey 'finish' =", "loopkey 'finish' S+F3".'
  1265.    else
  1266.       k=resolve_key(k)
  1267. compile endif
  1268.       oldcol=.col
  1269.       for i=1 to finish
  1270.          executekey k;down;.col=oldcol
  1271.       endfor
  1272. compile if EVERSION < 5
  1273.       cursor_command
  1274. compile endif
  1275.    endif
  1276.    sayerror 0
  1277.  
  1278. defc lowercase=
  1279.    call plowercase()
  1280.  
  1281. compile if EPM
  1282. ;  In EOS2 you could query the margins by typing "margins" with no argument.
  1283. ;  It typed them into the command line.  In EPM we can't write to the command
  1284. ;  line (yet).  So the query uses a sayerror.
  1285. ;
  1286. defc margins,ma=
  1287.    if arg(1)<>'' then         -- if user gives an argument he's setting,
  1288.       'xcom margins' arg(1)   -- pass it to the old internal margins command.
  1289.    else
  1290.       'commandline margins' .margins   -- Note the new .margins field
  1291.    endif
  1292. compile endif
  1293.  
  1294. defc matchtab=
  1295.    universal matchtab_on
  1296.    uparg=upcase(arg(1))
  1297.    if uparg=ON__MSG then
  1298.       matchtab_on = 1
  1299.    elseif uparg=OFF__MSG then
  1300.       matchtab_on = 0
  1301.    elseif uparg='' then
  1302. compile if EVERSION < 5
  1303.       if matchtab_on then onoff = ON__MSG; else onoff = OFF__MSG; endif
  1304.       cursor_command
  1305.       setcommand 'matchtab' onoff, 10, 1
  1306. compile else
  1307.       sayerror 'MATCHTAB:' word(OFF__MSG ON__MSG, matchtab_on+1)
  1308. compile endif
  1309.    else
  1310.       sayerror INVALID_ARG__MSG ON_OFF__MSG')'
  1311.       stop
  1312.    endif
  1313.  
  1314. ; MultiCommand, or Many Commands - lets you enter many commands on a line,
  1315. ; like XEDIT's SET LINEND, but you specify the delimiter as part of the
  1316. ; command so there's never a conflict.  Example, using ';' as delimiter:
  1317. ;   mc ; top; c /begin/{/ *; top; c/end/}/ *; top
  1318. defc mc =
  1319.    parse value strip(arg(1),'L') with delim 2 rest
  1320.    do while rest <> ''
  1321.       parse value rest with cmd (delim) rest
  1322.       cmd
  1323.    enddo
  1324.  
  1325. defc n,name
  1326. compile if WANT_LONGNAMES='SWITCH'
  1327.    universal SHOW_LONGNAMES
  1328. compile endif
  1329.    -- Name with no args supplies current name.
  1330.    if arg(1)='' then
  1331. compile if EVERSION < 5
  1332.       setcommand 'Name '.filename,6
  1333. compile else
  1334.       'commandline Name '.filename
  1335. compile endif
  1336.    else
  1337. compile if WANT_LAN_SUPPORT | EVERSION >= '5.51'
  1338.       if .lockhandle then
  1339.          sayerror LOCKED__MSG
  1340.          return
  1341.       endif
  1342. compile endif
  1343. compile if SMARTFILE or EVERSION >= '5.50'
  1344.       oldname = .filename
  1345. compile endif
  1346.       autosave_name = MakeTempName()
  1347.       call namefile(arg(1))
  1348. compile if SMARTFILE or EVERSION >= '5.50'
  1349.       if oldname <> .filename then .modify = .modify+1 endif
  1350. compile endif
  1351. compile if EVERSION > 5
  1352.       if get_EAT_ASCII_value('.LONGNAME')<>'' then
  1353.          call delete_ea('.LONGNAME')
  1354.  compile if WANT_LONGNAMES
  1355.   compile if WANT_LONGNAMES='SWITCH'
  1356.          if SHOW_LONGNAMES then
  1357.   compile endif
  1358.             .titletext = ''
  1359.   compile if WANT_LONGNAMES='SWITCH'
  1360.          endif
  1361.   compile endif
  1362.  compile endif  -- WANT_LONGNAMES
  1363.       endif  -- .LONGNAME EA exists
  1364.  compile if SHOW_MODIFY_METHOD = 'TITLE' | EVERSION < '5.50'
  1365.       call settitletext(.filename)
  1366.  compile endif
  1367.  compile if MENU_LIMIT
  1368.       call updateringmenu()
  1369.  compile endif
  1370. compile endif  -- EVERSION > 5
  1371. compile if E3
  1372.       if exist(autosave_name) then
  1373.          quietshell 'rename' autosave_name MakeTempName()
  1374.       endif
  1375. compile else
  1376.       call dosmove(autosave_name, MakeTempName())  -- Rename the autosave file
  1377. compile endif
  1378.       call select_edit_keys()
  1379. compile if SUPPORT_USER_EXITS
  1380.       if isadefproc('rename_exit') then
  1381.          call rename_exit(oldname, .filename)
  1382.       endif
  1383. compile endif
  1384. compile if INCLUDE_BMS_SUPPORT
  1385.       if isadefproc('BMS_rename_exit') then
  1386.          call BMS_rename_exit(oldname, .filename)
  1387.       endif
  1388. compile endif
  1389.    endif
  1390.  
  1391. defc newwindow=
  1392. compile if EVERSION < 5
  1393.    universal messy
  1394.    if messy then opt=' /w'; else opt=''; endif
  1395.    rest=parse_file_n_opts(arg(1))
  1396.    newwindow 'e'opt rest
  1397.    call select_edit_keys()
  1398. compile else
  1399.    if .modify then
  1400.       'save'
  1401.       if rc then
  1402.          sayerror ERROR_SAVING_HALT__MSG
  1403.          return
  1404.       endif
  1405.    endif
  1406.    'open' .filename
  1407.    'quit'
  1408. compile endif
  1409.  
  1410. compile if EPM
  1411. ;  New in EPM.  Edits a file in a different PM window.  This means invoking
  1412. ;  a completely new instance of E.DLL, with its own window and data.  We do it
  1413. ;  by posting a message to the executive, the top-level E application.
  1414. defc o,open=
  1415.    fname=strip(arg(1))                    -- Remove excess spaces
  1416.    call parse_filename(fname,.filename)   -- Resolve '=', if any
  1417.  
  1418.    call windowmessage(0,  getpminfo(APP_HANDLE),
  1419.                       5386,                   -- EPM_EDIT_NEWFILE
  1420.                       put_in_buffer(fname),
  1421.                       1)                      -- Tell EPM to free the buffer.
  1422. compile endif
  1423.  
  1424. compile if EVERSION > 5
  1425. defc openhelp
  1426.  compile if 0
  1427.    rectangle = atol(4) || atol(75)  || atol(632) || atol(351)
  1428.  
  1429.    filename  = arg(1) \0
  1430.    exfile    = 'help.ex' \0
  1431.    topoffile = HELP_TOP__MSG\0
  1432.    botoffile = HELP_BOT__MSG\0
  1433.    rethwnd   = '1234'
  1434.    params =   atol(getpminfo(EPMINFO_HAB))          ||  /* application anchor block              */
  1435.               atol(getpminfo(EPMINFO_PARENTCLIENT)) ||  /* handle to parent of edit window       */
  1436.               atol(getpminfo(EPMINFO_OWNERCLIENT))  ||  /* handle to owner of edit window        */
  1437.               address(rectangle)   ||  /* positioning of edit window            */
  1438.               address(filename)    ||  /* file to be edited                     */
  1439.               atol(0)              ||  /* handle to editor pointer icon.        */
  1440.               atol(0)              ||  /* handle to mark pointer icon.          */
  1441.               atol(0)              ||  /* editor ICON.                          */
  1442.               atol(12)             ||  /* internal editor options               */
  1443.               atol(203)            ||  /* PM standard window styles (FCF_xxxx)  */
  1444.               atoi(1)              ||  /* TRUE = LARGE FONT,  FALSE = SMALL FONT*/
  1445.               address(exfile)      ||  /* pre-compiled macro code file (EPM.EX) */
  1446.               address(topoffile)   ||  /* top and bottom of file markers        */
  1447.               address(botoffile)   ||
  1448.               atoi(0)              ||  /* unique window id specified for edit window */
  1449.               atol(0)              ||  /* environment variable to search for .ex */
  1450.               atoi(0)                  /* reserved for future use.              */
  1451.  
  1452.    call dynalinkc( E_DLL,
  1453.              '_EPM_EDITWINDOWCREATE',
  1454.               address(params)    ||
  1455.               address(rethwnd))
  1456.  compile else
  1457.  
  1458.    -- send EPM icon window a help message.  It will take care of
  1459.    -- the correct setting up of the help window.
  1460.    --
  1461.    call windowmessage(0,  getpminfo(APP_HANDLE),
  1462.                       5132,                   -- EPM_POPHELPBROWSER
  1463.                       put_in_buffer(arg(1)),
  1464.                       1)                      -- Tell EPM to free the buffer.
  1465.  compile endif
  1466. compile endif
  1467.  
  1468. ;  Print just the marked area, if there is one.  Defaults to printing on LPT1.
  1469. ;  Optional argument specifies printer.
  1470. defc print=  /* Save the users current file to the printer */
  1471.    parse arg prt ':'                             -- Optional printer name
  1472.    if not prt then prt=default_printer(); endif  -- Default
  1473.    prtnum = check_for_printer(prt)
  1474.    if prtnum then
  1475.       if not printer_ready(prtnum) then
  1476.          sayerror PRINTER_NOT_READY__MSG
  1477.          stop
  1478.       endif
  1479.    elseif substr(prt,1,2)<>'\\' then      -- Assume \\hostname\prt is correct.
  1480.       sayerror BAD_PRINT_ARG__MSG
  1481.       stop
  1482.    endif
  1483.    if marktype() then
  1484.       getmark firstline,lastline,firstcol,lastcol,markfileid
  1485.       getfileid fileid
  1486.       if fileid<>markfileid then
  1487.          sayerror OTHER_FILE_MARKED__MSG UNMARK_OR_EDIT__MSG markfileid.filename
  1488.          stop
  1489.       endif
  1490.       mt=marktype()
  1491.       'xcom e /n'             /*  Create a temporary no-name file. */
  1492.       if rc=-282 then  -- sayerror("New file")
  1493.          if marktype()='LINE' then deleteline endif
  1494.       elseif rc then
  1495.          stop
  1496.       endif
  1497.       getfileid tempofid
  1498.       call pcopy_mark()
  1499.       if rc then stop endif
  1500.       call pset_mark(firstline,lastline,firstcol,lastcol,mt,markfileid)
  1501.       activatefile tempofid
  1502.       sayerror PRINTING_MARK__MSG
  1503.    else
  1504.       sayerror PRINTING__MSG .filename
  1505.    endif
  1506. compile if EVERSION < '5.50'
  1507.    'xcom save /q' prt     /* This will not set .modify to 0 */
  1508. compile else
  1509.    'xcom save /ne /q' prt  /* /NE means No EOF (for Laserjet driver) */
  1510. compile endif
  1511.    if marktype() then .modify=0; 'xcom q' endif
  1512.    sayerror 0    /* clear 'printing' message */
  1513.  
  1514. compile if EVERSION > 5
  1515. defc processbreak
  1516.    universal Dictionary_loaded
  1517.    call showwindow('ON')             -- Make sure that the window is displayed.
  1518.    if dictionary_loaded then
  1519.       call drop_dictionary()
  1520.    endif
  1521.    sayerror MACRO_HALTED__MSG
  1522. compile endif
  1523.  
  1524. compile if WANT_PROFILE='SWITCH'
  1525. defc PROFILE
  1526.    universal REXX_PROFILE
  1527.    uparg=upcase(arg(1))
  1528.    if uparg=ON__MSG or uparg=1 then
  1529.       REXX_PROFILE = 1
  1530.    elseif uparg=OFF__MSG or uparg=0 then
  1531.       REXX_PROFILE = 0
  1532.    else
  1533.       sayerror 'Profile' word(OFF__MSG ON__MSG, REXX_PROFILE+1)
  1534.    endif
  1535. compile endif
  1536.  
  1537. compile if WANT_STACK_CMDS
  1538. definit
  1539.    universal mark_stack, position_stack
  1540.    mark_stack = ''
  1541.    position_stack = ''
  1542.  
  1543. defc popmark
  1544.    universal mark_stack
  1545.    parse value mark_stack with savemark '/' mark_stack
  1546.    call prestore_mark(savemark)
  1547.  
  1548. defc poppos
  1549.    universal position_stack
  1550.    parse value position_stack with fid saveposition '/' position_stack
  1551.    if fid='' then
  1552.       sayerror STACK_EMPTY__MSG
  1553.       return
  1554.    endif
  1555. compile if EPM  -- EPM has error checking; EOS2 & E3 just stop.
  1556.    display -2
  1557.    rc = 0
  1558. compile endif
  1559.    activatefile fid
  1560. compile if EPM
  1561.    display 2
  1562.    if rc then
  1563.       sayerror FILE_GONE__MSG
  1564.       return
  1565.    endif
  1566. compile endif
  1567.    call prestore_pos(saveposition)
  1568.  
  1569. defc pushmark
  1570.    universal mark_stack
  1571.    call checkmark()
  1572.    call psave_mark(savemark)  -- Note - this does an UNMARK
  1573.    call prestore_mark(savemark)
  1574.    if length(mark_stack) + length(savemark) >= MAXCOL then
  1575.       sayerror STACK_FULL__MSG
  1576.       return
  1577.    endif
  1578.    mark_stack = savemark'/'mark_stack
  1579.  
  1580. defc swapmark
  1581.    universal mark_stack
  1582.    call checkmark()
  1583.    call psave_mark(savemark)
  1584.    'popmark'
  1585.    if length(mark_stack) + length(savemark) >= MAXCOL then
  1586.       sayerror STACK_FULL__MSG
  1587.       return
  1588.    endif
  1589.    mark_stack = savemark'/'mark_stack
  1590.  
  1591. defc pushpos
  1592.    universal position_stack
  1593.    call psave_pos(saveposition)
  1594.    getfileid fid
  1595.    if length(position_stack) + length(saveposition fid) >= MAXCOL then
  1596.       sayerror STACK_FULL__MSG
  1597.       return
  1598.    endif
  1599.    position_stack = fid saveposition'/'position_stack
  1600.  
  1601. defc swappos
  1602.    universal position_stack
  1603.    call psave_pos(saveposition)
  1604.    getfileid fid
  1605.    'poppos'
  1606.    if length(position_stack) + length(saveposition fid) >= MAXCOL then
  1607.       sayerror STACK_FULL__MSG
  1608.       return
  1609.    endif
  1610.    position_stack = fid saveposition'/'position_stack
  1611. compile endif
  1612.  
  1613. defc qs,quietshell,quiet_shell=
  1614.    quietshell arg(1)
  1615.  
  1616. defc q,quit=
  1617.    -- Ver. 4.11c: If we're trying to quit the shell window, kill the process.
  1618. compile if EVERSION >= '4.11'
  1619.  compile if SHELL_USAGE
  1620.    if .filename = ".SHELL" then
  1621. ;     It's important to kill the process before we quit the window, else the
  1622. ;     process will churn merrily along without output.  If we're MAKEing a
  1623. ;     large C program and quit the editor, it can tie up the session.
  1624. ;     Simpler tasks like DIR and FILEFIND don't tie up the session.
  1625. ;
  1626. ;     Doesn't hurt anything if the process has already been killed.  The
  1627. ;     internal shell_kill function will merely beep at you.
  1628.       call shell_kill()
  1629.    endif
  1630.  compile endif
  1631. compile endif
  1632.  
  1633. compile if EVERSION > '5.19' & WANT_EPM_SHELL
  1634.    if leftstr(.filename, 15) = ".command_shell_" then
  1635.       'shell_kill'
  1636.       return
  1637.    endif
  1638. compile endif
  1639.  
  1640. compile if SUPPORT_USER_EXITS
  1641.       if isadefproc('quit_exit') then
  1642.          call quit_exit(.filename)
  1643.       endif
  1644. compile endif
  1645. compile if INCLUDE_BMS_SUPPORT
  1646.       if isadefproc('BMS_quit_exit') then
  1647.          call BMS_quit_exit(.filename)
  1648.       endif
  1649. compile endif
  1650.  
  1651. compile if TRASH_TEMP_FILES
  1652.    if substr(.filename,1,1) = "." then      -- a temporary file
  1653.       .modify=0                             -- so no "Are you sure?"
  1654.    endif
  1655. compile endif
  1656.  
  1657.    getfileid quitfileid      -- Temp workaround
  1658. ;compile if EVERSION > 5
  1659. ;   if marktype() then
  1660. ;      getmark firstline,lastline,firstcol,lastcol,markfileid
  1661. ;      if markfileid = quitfileid then
  1662. ;         'ClearSharBuff'       -- Remove content of EPM shared text buffer
  1663. ;      endif
  1664. ;   endif
  1665. ;compile endif
  1666. compile if WANT_LAN_SUPPORT & EVERSION < '5.51'
  1667.    if .lockhandle then call unlock(quitfileid); endif
  1668. compile endif
  1669.    call quitfile()
  1670. compile if EVERSION < 5
  1671.    call select_edit_keys()
  1672.    .box=2
  1673. compile elseif MENU_LIMIT
  1674.    getfileid fileid
  1675.    if fileid <> quitfileid then    -- temp workaround - fileid not null if no more files;
  1676.                                    -- breaks updateringmenu.
  1677.    call updateringmenu()
  1678.    endif
  1679. compile endif
  1680.  
  1681. defc rc=
  1682.    arg(1)
  1683.    sayerror 'RC='rc''
  1684.  
  1685. defc reflow_all
  1686.    call psave_mark(savemark)
  1687.    call psave_pos(savepos)
  1688. compile if not EPM
  1689.    cursor_data
  1690. compile endif
  1691.    stopit = 0
  1692.    top
  1693.    do forever
  1694.       getline line
  1695.       do while line='' |                              -- Skip over blank lines or
  1696.                (lastpos(':',line)=1 & pos('.',line)=length(line)) |  -- lines containing only a GML tag or
  1697.                substr(line,1,1)='.'                                  -- SCRIPT commands
  1698.          if .line=.last then stopit=1; leave; endif
  1699.          down
  1700.          getline line
  1701.       enddo
  1702.       if stopit then leave; endif
  1703.       startline = .line
  1704.       unmark; mark_line
  1705.       call pfind_blank_line()
  1706.       if .line<>startline then
  1707.          up
  1708.       else
  1709.          bottom
  1710.       endif
  1711.       mark_line
  1712.       reflow
  1713.       getmark firstline,lastline
  1714.       if lastline=.last then leave; endif
  1715.       lastline+1
  1716.    enddo
  1717.    call prestore_mark(savemark)
  1718.    call prestore_pos(savepos)
  1719.  
  1720. defc s,save=
  1721.    universal save_with_tabs, default_save_options
  1722.    name=arg(1)
  1723.    call parse_leading_options(name,options)
  1724.    options = default_save_options options
  1725. compile if EVERSION >= '5.21'
  1726.    save_as = 0
  1727.    if name='' | name=UNNAMED_FILE_NAME then
  1728. compile else
  1729.    if name='' then
  1730. compile endif
  1731.       name=.filename
  1732. compile if EVERSION >= '5.21'
  1733.       if .filename=UNNAMED_FILE_NAME then
  1734.          result = saveas_dlg(name, type)
  1735.          if result then return result; endif
  1736.          'name' name
  1737.          if not rc then
  1738.             name=.filename
  1739.             save_as = 1
  1740.          endif
  1741.       endif
  1742. compile endif
  1743.    else
  1744.       call parse_filename(name,.filename)
  1745.    endif
  1746. compile if SUPPORT_USER_EXITS
  1747.       if isadefproc('presave_exit') then
  1748.          call presave_exit(name, options, save_as)
  1749.       endif
  1750. compile endif
  1751. compile if INCLUDE_BMS_SUPPORT
  1752.       if isadefproc('BMS_presave_exit') then
  1753.          call BMS_presave_exit(name, options, save_as)
  1754.       endif
  1755. compile endif
  1756. compile if WANT_LAN_SUPPORT & EVERSION < '5.51'
  1757.    locked = .lockhandle
  1758.    if locked & not arg(1) then 'unlock'; endif
  1759. compile endif
  1760. compile if WANT_BOOKMARKS
  1761.    if .levelofattributesupport%8 - 2*(.levelofattributesupport%16) then
  1762.       'saveattributes'
  1763.    endif
  1764. compile endif
  1765. compile if not E3
  1766.    -- 4.10:  Saving with tab compression is built in now.  No need for
  1767.    -- the make-do proc savefilewithtabs().
  1768.    -- 4.10 new feature:  if save_with_tabs is true, always specify /t.
  1769.    if save_with_tabs then
  1770.       options = '/t' options
  1771.    endif
  1772. compile elseif WANT_TABS
  1773.    if isoption(options,'t') or save_with_tabs then
  1774.       src=savefilewithtabs(name,options)
  1775.    else
  1776. compile endif
  1777.       src=savefile(name,options)
  1778. compile if (EVERSION < '4.10') & WANT_TABS
  1779.    endif
  1780. compile endif
  1781. compile if SUPPORT_USER_EXITS
  1782.       if isadefproc('postsave_exit') then
  1783.          call postsave_exit(name, options, save_as, src)
  1784.       endif
  1785. compile endif
  1786. compile if INCLUDE_BMS_SUPPORT
  1787.       if isadefproc('BMS_postsave_exit') then
  1788.          call BMS_postsave_exit(name, options, save_as, src)
  1789.       endif
  1790. compile endif
  1791.    if not src & not isoption(options,'q') then
  1792.       call message(SAVED_TO__MSG name)
  1793. compile if not E3
  1794.    elseif src=-5 then  -- call message('Access denied')
  1795.       if qfilemode(name, attrib) then      -- Error from DosQFileMode
  1796.          call message(src)    -- ? Don't know why got Access denied.
  1797.       else                    -- File exists:
  1798.          if attrib % 16 - 2 * (attrib % 32) then    -- x'10' is on
  1799.             call message(ACCESS_DENIED__MSG '-' IS_A_SUBDIR__MSG)  -- It's a subdirectory
  1800.          elseif attrib // 2 then                    -- x'01' is on
  1801.             call message(ACCESS_DENIED__MSG '-' READ_ONLY__MSG)    -- It's read/only
  1802.          elseif attrib % 4 - 2 * (attrib % 8) then  -- x'04' is on
  1803.             call message(ACCESS_DENIED__MSG '-' IS_SYSTEM__MSG)    -- It's a system file
  1804.          elseif attrib % 2 - 2 * (attrib % 4) then  -- x'02' is on
  1805.             call message(ACCESS_DENIED__MSG '-' IS_HIDDEN__MSG)    -- It's a hidden file
  1806.          else                                -- None of the above?
  1807.             call message(ACCESS_DENIED__MSG '-' MAYBE_LOCKED__MSG) -- Maybe someone locked it.
  1808.          endif
  1809.       endif
  1810.       rc = src  -- reset, since qfilemode() changed the RC.
  1811. compile endif
  1812.    elseif src<0 then          -- If RC > 0 assume from host save; and
  1813.       call message(src)       -- assume host routine gave error msg.
  1814.    endif
  1815. compile if EVERSION >= '5.21'
  1816.    if src & save_as then
  1817.       .filename=UNNAMED_FILE_NAME
  1818.  compile if SHOW_MODIFY_METHOD = 'TITLE'
  1819.       call settitletext(.filename)
  1820.  compile endif
  1821.  compile if MENU_LIMIT
  1822.       call updateringmenu()
  1823.  compile endif
  1824.    endif
  1825. compile endif
  1826. compile if E3 and SHOW_MODIFY_METHOD
  1827.    call show_modify()
  1828. compile endif
  1829. compile if WANT_LAN_SUPPORT & EVERSION < '5.51'
  1830.    if locked & not arg(1) then call lock(); endif
  1831. compile endif
  1832.    return src
  1833.  
  1834. defc select_all =
  1835.    getfileid fid
  1836.    call pset_mark(1, .last, 1, length(textline(.last)), 'CHAR' , fid)
  1837. compile if EVERSION >= 5
  1838.    'Copy2SharBuff'       /* Copy mark to shared text buffer */
  1839. compile endif
  1840.  
  1841. compile if SETSTAY='?'
  1842. defc stay=
  1843.    universal stay
  1844.    parse arg arg1; arg1=upcase(arg1)
  1845.  compile if EPM
  1846.    if arg1='' then sayerror 'Stay =' word(OFF__MSG ON__MSG, stay+1)
  1847.  compile else
  1848.    if arg1='' then sayerror 'Stay =' stay
  1849.  compile endif
  1850.    elseif arg1='1' | arg1=ON__MSG then stay=1
  1851.    elseif arg1='0' | arg1=OFF__MSG then stay=0
  1852.    else sayerror INVALID_ARG__MSG ON_OFF__MSG')'
  1853.    endif
  1854. compile endif
  1855.  
  1856. compile if EVERSION >= '4.11'
  1857. ; read a file from stdin
  1858. defc stdfile_read
  1859.  while  read_stdin() > 0 do
  1860.     join
  1861.     bottom
  1862.  endwhile
  1863.  
  1864. ; write a file to stdout
  1865. defc stdfile_write
  1866.  if .filename=='' then
  1867.     .filename='UNNAMED'
  1868.  endif
  1869.  's'
  1870.  'type '.filename
  1871.  'q'
  1872. compile endif
  1873.  
  1874. compile if EVERSION >= '5.50'  -- Earlier versions didn't retain trailing blanks anyway.
  1875. defc strip =
  1876.    parse arg firstline lastline .
  1877.    if firstline='' then firstline=1; endif
  1878.    if lastline='' then lastline=.last; endif
  1879.    do i=firstline to lastline
  1880.       getline line, i
  1881.       if length(line) & rightstr(line,1) == ' ' then
  1882.          replaceline strip(line, 'T'), i
  1883.       endif
  1884.    enddo
  1885. compile endif
  1886.  
  1887. compile if TOGGLE_TAB
  1888. defc TABKEY
  1889.    universal TAB_KEY
  1890.    uparg=upcase(arg(1))
  1891.    if uparg=ON__MSG or uparg=1 then
  1892.       TAB_KEY = 1
  1893.    elseif uparg=OFF__MSG or uparg=0 then
  1894.       TAB_KEY = 0
  1895.    else
  1896.       sayerror 'TabKey' word(OFF__MSG ON__MSG, TAB_KEY+1)
  1897.    endif
  1898. compile endif
  1899.  
  1900.  
  1901. compile if EVERSION >= 5
  1902. ;  In EOS2 you could query the tabs by typing "tabs" with no argument.
  1903. ;  It typed them into the command line.
  1904. ;
  1905. defc tabs=
  1906.    if arg(1)<>'' then         -- if user gives an argument to be set,
  1907.       'xcom tabs 'arg(1)      -- pass it to the old internal tabs command.
  1908.    else
  1909.       -- Note the new .tabs field; each file has its own tabs.
  1910.       'commandline Tabs' .tabs
  1911.    endif
  1912. compile endif
  1913.  
  1914.  
  1915. defc top=
  1916.    top
  1917.  
  1918. compile if WANT_LAN_SUPPORT
  1919. defc unlock
  1920.    parse arg file
  1921.    if file='' then
  1922.       getfileid fileid
  1923.    else
  1924.       getfileid fileid,file
  1925.       if fileid=='' then
  1926.          sayerror '"'file'"' DOES_NOT_EXIST__MSG
  1927.          return 1
  1928.       endif
  1929.    endif
  1930.    call unlock(fileid)
  1931. compile endif
  1932.  
  1933. defc uppercase=
  1934.    call puppercase()
  1935.  
  1936. compile if EPM
  1937. defc ver =
  1938.    sayerror EDITOR_VER__MSG ver(0)
  1939. compile endif
  1940.  
  1941. defc xcom_quit
  1942. compile if EVERSION < 5
  1943.    if .windowoverlap then
  1944.       quitview
  1945.    else
  1946.       'xcom q'
  1947.    endif
  1948. compile else
  1949.    'xcom q'
  1950. compile endif
  1951.  
  1952.