home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / editors / epm / e_macros / stdcmds.e < prev    next >
Encoding:
Text File  |  1993-08-11  |  64.8 KB  |  1,992 lines

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