home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / editors / epm / sampmacs / stdcmds.e < prev    next >
Encoding:
Text File  |  1993-12-02  |  66.2 KB  |  2,028 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 defined(WANT_TRUNCATED_WARNING)
  561. const WANT_TRUNCATED_WARNING = 0
  562. compile endif
  563.  
  564. compile if not EPM
  565. defc e,ed,edit=
  566. compile else
  567. defc e,ed,edit,epm=
  568. compile endif
  569. universal default_edit_options
  570. compile if not EPM
  571.    universal messy
  572. compile endif
  573.   compile if (HOST_SUPPORT='EMUL' | HOST_SUPPORT='E3EMUL') & not SMALL
  574.    universal fto                -- Need this passed to loadfile...
  575.   compile endif
  576.  
  577.    rest=strip(arg(1))
  578.  
  579.    if rest='' then   /* 'edit' by itself goes to next file */
  580. compile if EVERSION < 5
  581.       call pnextfile()
  582.       call select_edit_keys()
  583. compile else
  584.       nextfile
  585. compile endif
  586.       return 0
  587.    endif
  588.  
  589.    options=default_edit_options
  590.    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
  591. --  bad_paths     --> Non-existing path specified.
  592. --  truncated     --> File contained lines longer than 255 characters.
  593. --  access_denied --> If user tried to edit a subdirectory.
  594. --  invalid_drive --> No such drive letter
  595. --  error_reading --> Bad disk(ette).
  596. --  error_opening --> Path contained invalid name.
  597.  
  598.    do while rest<>''
  599.       rest=strip(rest,'L')
  600.       if substr(rest,1,1)=',' then rest=strip(substr(rest,2),'L'); endif
  601.       ch=substr(rest,1,1)
  602. compile if (HOST_SUPPORT='EMUL' | HOST_SUPPORT='E3EMUL') & not SMALL
  603.  compile if (MVS or E3MVS) and not HOST_LT_REQUIRED  -- (MVS filespecs can start with '.)
  604.   compile if EVERSION >= '5.50'      -- Now use "" to support spaces in filenames
  605.       if 0 then                         -- No-op
  606.   compile else
  607.       if ch='"' then                    -- Command
  608.   compile endif
  609.  compile else
  610.   compile if EVERSION >= '5.50'     -- Now use "" to support spaces in filenames
  611.       if ch="'" then                    -- Command
  612.   compile else
  613.       if ch='"' | ch="'" then           -- Command
  614.   compile endif
  615.  compile endif
  616. compile else
  617.  compile if EVERSION >= '5.50'     -- Now use "" to support spaces in filenames
  618.       if ch="'" then                    -- Command
  619.  compile else
  620.       if ch='"' | ch="'" then           -- Command
  621.  compile endif
  622. compile endif
  623.          parse value rest with (ch) cmd (ch) rest
  624.          do while substr(rest,1,1)=ch & pos(ch,rest,2)
  625.             parse value rest with (ch) p (ch) rest
  626.             cmd = cmd || ch || p
  627.          enddo
  628.          cmd
  629.       elseif ch='/' then       -- Option
  630.          parse value rest with opt rest
  631.          options=options upcase(opt)
  632.       else
  633.          files_loaded=files_loaded+1  -- Number of files we tried to load
  634. compile if EVERSION >= '5.50'     -- Now use "" to support spaces in filenames
  635.       if ch='"' then
  636.          p=pos('"',rest,2)
  637.          if p then
  638.             file = substr(rest, 1, p)
  639.             rest = substr(rest, p+1)
  640.          else
  641.             sayerror INVALID_FILENAME__MSG
  642.             return
  643.          endif
  644.       else
  645. compile endif
  646. compile if HOST_SUPPORT & not SMALL
  647.          p=length(rest)+1  -- If no delimiters, take to the end.
  648.          p1=pos(',',rest); if not p1 then p1=p; endif
  649.          p2=pos('/',rest); if not p2 then p2=p; endif
  650.          p3=pos('"',rest); if not p3 then p3=p; endif
  651.          p4=pos("'",rest); if not p4 then p4=p; endif
  652.   compile if HOST_SUPPORT='EMUL' | HOST_SUPPORT='E3EMUL'
  653.     compile if MVS or E3MVS
  654.          p4=p     -- Can't use single quote for commands if allowing MVS files
  655.     compile endif
  656.          p5=pos('[',rest); if not p5 then p5=p; endif  -- Allow for [FTO]
  657.          p=min(p1,p2,p3,p4,p5)
  658.   compile else
  659.          p=min(p1,p2,p3,p4)
  660.   compile endif
  661.          file=substr(rest,1,p-1)
  662.          if VMfile(file,more) then        -- tricky - VMfile modifies file
  663.             if p=p1 then p=p+1; endif     -- Keep any except comma in string
  664.             rest=more substr(rest,p)
  665.          else
  666. compile endif
  667.             parse value rest with file rest2
  668.             if pos(',',file) then parse value rest with file ',' rest
  669.             else rest=rest2; endif
  670. compile if HOST_SUPPORT & not SMALL
  671.          endif
  672.   compile if HOST_SUPPORT='EMUL' | HOST_SUPPORT='E3EMUL'
  673.          if substr(strip(rest,'L'),1,1)='[' then
  674.             parse value rest with '[' fto ']' rest
  675.          else
  676.             fto = ''                           --  reset for each file!
  677.          endif
  678.   compile endif
  679. compile endif
  680. compile if EVERSION >= '5.50'     -- Now use "" to support spaces in filenames
  681.       endif
  682. compile endif
  683.  
  684.          call parse_filename(file,.filename)
  685.  
  686. compile if USE_APPEND  -- Support for DOS 3.3's APPEND, thanks to Ken Kahn.
  687.          If not(verify(file,'\:','M')) then
  688.             if not exist(file) then
  689.                File = Append_Path(File)||File  -- LAM todo: fixup
  690.             Endif
  691.          Endif
  692. compile endif
  693.  
  694. compile if WANT_WINDOWS         -- Always 0 for EPM
  695.          if messy then                            -- messy-desk style?
  696.             .windowoverlap=1
  697.             if pos('H',options) then      -- hidden option used?
  698.                call loadfile(file,options)
  699.             else
  700.                if not verify(file,'?*','M') and   -- If no wildcards
  701.                   not pos('D',options)    -- and not /D,
  702.                then
  703.                   if verify(file,':\','M') then   -- get fully qualified file
  704.                      getfileid newfileid,file
  705.                   else
  706.                      getfileid newfileid,directory()'\'file -- (add path if necessary).
  707.                      if newfileid='' & pos('N', options) then  -- Only match different path if /n
  708.                         getfileid newfileid,file
  709.                      endif
  710.                   endif
  711.                   if newfileid<>'' then           -- If it's already loaded,
  712.                      .box=1
  713.                      if newfileid.windowid=0 then   -- (in the hidden ring?)
  714.                         newwindow 'e /w' options file -- (Yes, have to edit it.)
  715.                      else
  716.                         activatefile newfileid       -- then just activate it.
  717.                      endif
  718.                      iterate
  719.                   endif
  720.                endif
  721.                newwindow 'e /w /n'  /* start a new file */
  722.                /* Newwindow 'e' creates an empty file just like E startup. */
  723.                getfileid emptyfileid
  724.                if not (rc and rc<>-282) then  -- sayerror('New file')
  725.                   if pos('Q',options) then sayerror 1; endif
  726.                   call loadfile(file,options argsep||'w')
  727.                   loadrc=rc
  728.                   getfileid newfileid
  729.                   if loadrc=-270 & newfileid=emptyfileid then  -- sayerror('Not enough memory')
  730.                      deletewindow
  731.                      stop
  732.                   endif           -- Otherwise, wildcard & some were loaded.
  733.                   call create_window_for_each_file(emptyfileid)
  734.                   .windowoverlap=1
  735.                   if not loadrc or loadrc=-282 or    -- sayerror('New file')
  736.                                    loadrc=-270 or    -- sayerror('Not enough memory')
  737.                                    loadrc=-278 then  -- sayerror('Lines truncated')
  738.                      /* Normal results, normal cleanup:  discard empty file. */
  739.                      activatefile emptyfileid
  740.                      quitview
  741.                      activatefile newfileid
  742.                   else     /* Unexpected error! */
  743.                      deletewindow
  744.                   endif
  745.                endif
  746.                prevwindow; .box=1; nextwindow
  747.             endif
  748.          else      -- not messy
  749. compile endif
  750.             call loadfile(file,options)
  751. compile if WANT_WINDOWS
  752.             prevfile;.box=1;nextfile
  753.          endif -- if messy
  754. compile endif
  755.  
  756.          if rc=-3 then        -- sayerror('Path not found')
  757.             bad_paths=bad_paths', 'file
  758.          elseif rc=-2 then    -- sayerror('File not found')
  759.             not_found=not_found', 'file
  760.          elseif rc=-282 then  -- sayerror('New file')
  761.             new_files=new_files', 'file
  762.             new_files_loaded=new_files_loaded+1
  763.          elseif rc=-278 then  --sayerror('Lines truncated')
  764.             truncated=truncated', 'file
  765.             .modify = 0
  766. compile if WANT_TRUNCATED_WARNING
  767.  compile if EPM
  768.             refresh
  769.             call winmessagebox(sayerrortext(-278), .filename\10'One or more lines were split at column 255; file may be damaged if saved.', 16416)  -- MB_OK + MB_WARNING + MB_MOVEABLE
  770.  compile else
  771.             messageNwait('Lines truncated; file may be damaged if saved.')
  772.  compile endif
  773. compile endif  -- WANT_TRUNCATED_WARNING
  774.          elseif rc=-5 then  -- sayerror('Access denied')
  775.             access_denied=access_denied', 'file
  776.          elseif rc=-15 then  -- sayerror('Invalid drive')
  777.             invalid_drive=invalid_drive', 'file
  778.          elseif rc=-286 then  -- sayerror('Error reading file')
  779.             error_reading=error_reading', 'file
  780.          elseif rc=-284 then  -- sayerror('Error opening file')
  781.             error_opening=error_opening', 'file
  782.          endif
  783.          if first_file_loaded='' then
  784.             if rc<>-3   &  -- sayerror('Path not found')
  785.                rc<>-2   &  -- sayerror('File not found')
  786.                rc<>-5   &  -- sayerror('Access denied')
  787.                rc<>-15     -- sayerror('Invalid drive')
  788.             then
  789.                getfileid first_file_loaded
  790.             endif
  791.          endif
  792.       endif  -- not "cmd"
  793.    enddo  -- while rest<>''
  794.    if files_loaded>1 then  -- If only one file, leave E3's message
  795.       if new_files_loaded>1 then p='New files:'; else p='New file:'; endif
  796. compile if EVERSION < 5  -- EPM doesn't give messages; have to supply in all cases.
  797.       if new_files || bad_paths || not_found || truncated || access_denied || error_reading || error_opening || invalid_drive <>
  798.          invalid_drive || error_opening || error_reading || access_denied || truncated || not_found || bad_paths || new_files
  799.       then                                        -- More than one.
  800. compile else
  801.       multiple_errors = (new_files || bad_paths || not_found || truncated || access_denied || error_reading || error_opening || invalid_drive <>
  802.                         invalid_drive || error_opening || error_reading || access_denied || truncated || not_found || bad_paths || new_files ) &
  803.                   '' <> new_files || bad_paths || not_found || truncated || access_denied || error_reading || error_opening || invalid_drive
  804.  
  805. compile endif
  806.          if new_files then $SAYERR NEW_FILE__MSG substr(new_files,2); endif
  807.          if not_found then $SAYERR FILE_NOT_FOUND__MSG':' substr(not_found,2); endif
  808. compile if EPM  -- If only one file, don't need "New file" msg in EPM.
  809.    else
  810.       multiple_errors = 0
  811.    endif
  812. compile endif
  813.          if bad_paths then $SAYERR BAD_PATH__MSG':' substr(bad_paths,2); endif
  814.          if truncated then $SAYERR LINES_TRUNCATED__MSG':' substr(truncated,2); endif
  815.          if access_denied then $SAYERR ACCESS_DENIED__MSG':' substr(access_denied,2); endif
  816.          if invalid_drive then $SAYERR INVALID_DRIVE__MSG':' substr(invalid_drive,2); endif
  817.          if error_reading then $SAYERR ERROR_OPENING__MSG':' substr(error_reading,2); endif
  818.          if error_opening then $SAYERR ERROR_READING__MSG':' substr(error_opening,2); endif
  819. compile if EVERSION < 5
  820.          pause
  821.       elseif new_files then sayerror NEW_FILE__MSG':' substr(new_files,2)
  822.       elseif bad_paths then sayerror BAD_PATH__MSG':' substr(bad_paths,2)
  823.       elseif not_found then sayerror FILE_NOT_FOUND__MSG':' substr(not_found,2)
  824.       elseif truncated then sayerror LINES_TRUNCATED__MSG':' substr(truncated,2)
  825.       elseif access_denied then sayerror ACCESS_DENIED__MSG':' substr(access_denied,2)
  826.       elseif invalid_drive then sayerror INVALID_DRIVE__MSG':' substr(invalid_drive,2)
  827.       elseif error_reading then sayerror ERROR_OPENING__MSG':' substr(error_reading,2)
  828.       elseif error_opening then sayerror ERROR_READING__MSG':' substr(error_opening,2)
  829.       endif
  830. compile else
  831.       if multiple_errors then
  832.          messageNwait(MULTIPLE_ERRORS__MSG)
  833.       endif
  834. compile endif
  835.       if first_file_loaded<>'' then activatefile first_file_loaded; endif
  836. compile if EVERSION < 5
  837.    endif
  838. compile endif
  839.  
  840. compile if not EPM
  841.    /* Save the edit RC through select_edit_keys, since it might get reset  */
  842.    /* by some command like 'tabs' or 'margins'.  This used to be in        */
  843.    /* select_edit_keys, but that made configurability hard.                */
  844.    saverc=rc
  845.    call select_edit_keys()
  846.    rc=saverc
  847.    .box=2
  848. compile elseif MENU_LIMIT
  849. ;compile if SHOW_MODIFY_METHOD = 'TITLE'
  850. ;  call settitletext(.filename) /* done internally */
  851. ;compile endif
  852.    if .visible & files_loaded then
  853.       call updateringmenu()
  854.    endif
  855. compile endif
  856.  
  857.  
  858. ; LAM - Edit a file along the EPATH.  This command will be included if
  859. ; the user is including the required routines.  If you've done a
  860. ;   SET EPMPATH=d:\EPM;d:\my_emacs;d:\E_macros
  861. ; and then do
  862. ;   ep stdcmds.e
  863. ; that will load this file, just as if you had entered
  864. ;   e d:\e_macros\stdcmds.e
  865. compile if USE_APPEND or (WANT_SEARCH_PATH and WANT_GET_ENV and not SMALL)
  866. defc ep, epath=
  867.    parse arg filename pathname .
  868.    if pathname='' then
  869. compile if E3
  870.       if filetype(filename)='BAT' then
  871. compile else
  872.       if filetype(filename)='CMD' then
  873. compile endif
  874.          pathname='PATH'
  875.       else
  876.          pathname=EPATH
  877.       endif
  878.    endif
  879.    if not exist(filename) then
  880.       filename = search_path_ptr(Get_Env(pathname,1),filename)filename
  881.    endif
  882.    'e 'filename
  883.  
  884.  compile if EPM
  885. defc op, opath, openpath=
  886.    "open 'ep "arg(1)"'"
  887.  compile endif
  888. compile endif
  889.  
  890.  
  891. ; jbl 1/12/89:  The syntax of ECHO is revised to be like browse().  It's
  892. ; a function so a macro can test its current value.
  893. defc echo =
  894. compile if EVERSION >= '4.12'
  895.    uparg=upcase(arg(1))
  896.    if uparg=ON__MSG or uparg=1 then
  897.       call echo(1)
  898.    elseif uparg=OFF__MSG or uparg='0' then
  899.       call echo(0)
  900.  compile if EVERSION >= '5.60'
  901.    elseif uparg='2' then
  902.       call echo(2)
  903.  compile endif
  904.    else
  905.  compile if EVERSION < 5
  906.       if echo() then onoff = ON__MSG; else onoff = OFF__MSG; endif
  907.       cursor_command
  908.       setcommand 'echo' onoff,8,1
  909.  compile else
  910.       sayerror ECHO_IS__MSG word(OFF__MSG ON__MSG 2, echo()+1)
  911.  compile endif
  912.    endif
  913. compile else                         -- The old way, for E3 & EOS2FAM.
  914.    if arg(1) = '' then
  915.       echo 'ON'
  916.    else
  917.       echo arg(1)
  918.    endif
  919. compile endif
  920.  
  921. compile if TOGGLE_ESCAPE
  922. defc ESCAPEKEY
  923.    universal ESCAPE_KEY
  924.    uparg=upcase(arg(1))
  925.    if uparg=ON__MSG or uparg=1 then
  926.       ESCAPE_KEY = 1
  927.    elseif uparg=OFF__MSG or uparg=0 then
  928.       ESCAPE_KEY = 0
  929.    else
  930.       sayerror 'EscapeKey' word(OFF__MSG ON__MSG, ESCAPE_KEY+1)
  931.    endif
  932. compile endif
  933.  
  934.  
  935. define TEMPFILENAME = 'vTEMP_FILENAME'
  936. compile if WANT_ET_COMMAND     -- Ver. 3.09 - Let user omit ET command.
  937.  compile if EVERSION < 5
  938. defc et=
  939.  compile else
  940.  define TEMPFILENAME = 'tempfile'
  941. defc et,etpm=
  942.  compile endif
  943.    universal vTEMP_PATH,vTEMP_FILENAME
  944.    infile=arg(1); if infile='' then infile=MAINFILE endif
  945.    sayerror COMPILING__MSG infile
  946.  compile if EVERSION < 5
  947.    quietshell 'xcom et /e' vTEMP_FILENAME infile
  948.    if rc=-2 then sayerror CANT_FIND_PROG__MSG 'ET.Exe';stop endif
  949.  compile else
  950.    tempfile=vTEMP_PATH'ETPM'substr(ltoa(gethwnd(EPMINFO_EDITCLIENT),16),1,4)'.TMP'
  951.    -- quietshell 'xcom etpm /e 'tempfile infile
  952.   compile if defined(ETPM_CMD)  -- let user specify fully-qualified name
  953.    quietshell 'xcom' ETPM_CMD infile ' /e 'tempfile ' /p'upcase(EPATH)
  954.   compile else
  955.    quietshell 'xcom etpm 'infile ' /e 'tempfile ' /p'upcase(EPATH)
  956.   compile endif
  957.    if rc=-2 then sayerror CANT_FIND_PROG__MSG 'ETPM.EXE'; stop; endif
  958.    if rc=41 then sayerror 'ETPM.EXE' CANT_OPEN_TEMP__MSG '"'tempfile'"'; stop; endif
  959.  compile endif
  960.    if rc then
  961.       saverc = rc
  962.       call ec_position_on_error($TEMPFILENAME)
  963.       rc = saverc
  964.    else
  965.  compile if EPM
  966.       refresh
  967.  compile endif
  968.       sayerror COMP_COMPLETED__MSG
  969.    endif
  970.    call erasetemp($TEMPFILENAME) -- 4.11:  added to erase the temp file.
  971. compile endif
  972.  
  973.                -- No EXIT command in EPM.  Do it from the system pull-downs.
  974. compile if EVERSION < 5
  975. ;  Ver. 3.11D  Optional return code as argument.  Added by Davis Foulger
  976. defc exit=
  977.    if askyesno(EXIT_PROMPT__MSG) = YES_CHAR then
  978.       exit arg(1)
  979.    endif
  980.    sayerror 0
  981. compile endif
  982.  
  983.  
  984. defc expand=
  985.    universal expand_on
  986.    uparg=upcase(arg(1))
  987.    if uparg=ON__MSG then
  988.       expand_on = 1
  989.       call select_edit_keys()
  990.    elseif uparg=OFF__MSG then
  991.       expand_on = 0
  992.       call select_edit_keys()
  993.    elseif uparg='' then
  994. compile if EVERSION < 5
  995.       if expand_on then onoff = ON__MSG; else onoff = OFF__MSG; endif
  996.       cursor_command
  997.       setcommand 'expand' onoff,8,1
  998. compile else
  999.       sayerror 'EXPAND:' word(OFF__MSG ON__MSG, expand_on+1)
  1000. compile endif
  1001.    else
  1002.       sayerror INVALID_ARG__MSG ON_OFF__MSG')'
  1003.       stop
  1004.    endif
  1005.  
  1006. defc f,file=
  1007.    's 'arg(1)
  1008.    if not rc then
  1009.       .modify=0            -- If saved to a different file, turn modify off
  1010.       'q'
  1011.       call select_edit_keys()
  1012.    endif
  1013.  
  1014.  
  1015. ;  EPM's replacement for Alt-F.  "FILL <character>".
  1016. defc fill=
  1017.    call checkmark()
  1018.    call pfill_mark(arg(1))
  1019.  
  1020.  
  1021. compile if EVERSION < 4       -- With linking, GET can be an external module.
  1022. defc get=
  1023.    universal default_edit_options
  1024.    get_file = strip(arg(1))
  1025.    if get_file='' then sayerror NO_FILENAME__MSG 'GET'; stop endif
  1026.    if pos(argsep,get_file) then
  1027.       sayerror INVALID_OPTION__MSG
  1028.       stop
  1029.    endif
  1030.    call parse_filename(get_file,.filename)
  1031.    getfileid fileid
  1032.    s_last=.last
  1033.    'e /q /h /d' default_edit_options get_file
  1034.    editrc=rc
  1035.    getfileid gfileid
  1036.    if editrc= -2 | .last=0 then  -- -2 = sayerror('New file')
  1037.       'q'
  1038.       if editrc=-2 then
  1039.          sayerror FILE_NOT_FOUND__MSG':  'get_file
  1040.       else
  1041.          sayerror FILE_IS_EMPTY__MSG':  'get_file
  1042.       endif
  1043.       stop
  1044.    endif
  1045.    if editrc & editrc<> -278 then  -- -278 = sayerror('Lines truncated')
  1046.       sayerror editrc
  1047.       stop
  1048.    endif
  1049.    call psave_mark(save_mark)
  1050.    top
  1051.    mark_line
  1052.    bottom
  1053.    mark_line
  1054.    activatefile fileid
  1055.    rc=0
  1056.    copy_mark
  1057.    copy_rc=rc           -- Test for memory too full for copy_mark.
  1058.    activatefile gfileid
  1059.    'q'
  1060.    parse value save_mark with s_firstline s_lastline s_firstcol s_lastcol s_mkfileid s_mt
  1061.    if fileid=s_mkfileid then           -- May have to move the mark.
  1062.       diff=fileid.last-s_last          -- (Adjustment for difference in size)
  1063.       if fileid.line<s_firstline then s_firstline=s_firstline+diff; endif
  1064.       if fileid.line<s_lastline then s_lastline=s_lastline+diff; endif
  1065.    endif
  1066.    call prestore_mark(s_firstline s_lastline s_firstcol s_lastcol s_mkfileid s_mt)
  1067.    if copy_rc then
  1068.       sayerror NOT_2_COPIES__MSG get_file
  1069.    else
  1070.       call message(1)
  1071.    endif
  1072.    activatefile fileid
  1073.    call select_edit_keys()
  1074. compile endif
  1075.  
  1076. defc goto =
  1077.    parse arg line col .
  1078.    line
  1079.    if col<>'' then .col = col; endif
  1080.  
  1081. /* Uses findfile statement to search EPATH for the helpfile.              */
  1082. /* Its syntax: findfile destfilename,searchfilename[,envpathvar][,['P']]  */
  1083. defc help=
  1084. compile if EVERSION < 5
  1085.    universal messy
  1086. compile endif
  1087.    helpfile = HELPFILENAME
  1088.  
  1089. compile if EVERSION > 4
  1090.    -- 4.02:  search EPATH/DPATH for the help file.  New 'D' option on findfile.
  1091.    findfile destfilename, helpfile, '','D'
  1092.    if rc then    /* If not there, search the HELP path. */
  1093.       findfile destfilename, helpfile, 'HELP'
  1094.    endif
  1095. compile else
  1096.    findfile destfilename, helpfile,EPATH
  1097. compile endif
  1098.    if rc then
  1099.       /* If all that fails, try the standard path. */
  1100.       findfile destfilename, helpfile, 'PATH'
  1101.       if rc then
  1102.          sayerror FILE_NOT_FOUND__MSG':' helpfile
  1103.          return ''
  1104.       endif
  1105.    endif
  1106. compile if EVERSION < 5
  1107.  compile if WANT_WINDOWS
  1108.    if messy then
  1109.       newwindow 'e /w 'destfilename  /* load one view only */
  1110.       call setzoomwindow(1,1,1,25,screenwidth())
  1111.       .windowoverlap=1
  1112.    else
  1113.  compile endif
  1114.       'e /w 'destfilename  /* load one view of help only */
  1115.  compile if WANT_WINDOWS
  1116.    endif
  1117.  compile endif
  1118. compile else
  1119.    'openhelp' destfilename
  1120. compile endif
  1121.  
  1122. ; In EPM we don't do a getkey() to ask you for the key.  You must supply it
  1123. ; as part of the command, as in "key 80 =".
  1124. defc key=
  1125.    parse value arg(1) with number k .
  1126.    if not isnum(number) then sayerror INVALID_NUMBER__MSG;stop endif
  1127.    -- jbl:  Allow the user to specify the key in the command, so he can
  1128.    -- say "key 80 =" and avoid the prompt.
  1129.    if k == '' then
  1130. compile if EVERSION < 5
  1131.       k=mgetkey(KEY_PROMPT1__MSG)  -- Accept key from macro.
  1132.    endif
  1133.    if k<>esc then
  1134.       cursor_data
  1135. compile else
  1136.       sayerror KEY_PROMPT2__MSG '"key 'number' =", "key 'number' S+F3".'
  1137.       return
  1138.    else
  1139.       k=resolve_key(k)
  1140. compile endif
  1141.       for i=1 to number
  1142.          executekey k
  1143.       endfor
  1144. compile if EVERSION < 5
  1145.       cursor_command
  1146. compile endif
  1147.    endif
  1148.    sayerror 0
  1149.  
  1150.  
  1151. defc l, locate =  /* Note:  this DEFC also gets executed by the slash ('/') command. */
  1152.    universal default_search_options
  1153. compile if defined(HIGHLIGHT_COLOR)
  1154.    universal search_len
  1155. compile endif
  1156. compile if EVERSION < 5
  1157.    r=rc /* This little trick tells us whether we're in a macro or on command */
  1158.         /* line, so we'll know where to leave the cursor at end.             */
  1159. compile endif
  1160.    /* Insert default_search_options just before supplied options (if any)    */
  1161.    /* so the supplied options will take precedence.                          */
  1162.    args=strip(arg(1),'L')
  1163. compile if not defined(HIGHLIGHT_COLOR)
  1164.    if default_search_options<>'' then
  1165. compile endif
  1166.       delim=substr(args,1,1)
  1167.       p=pos(delim,args,2)
  1168.       user_options=''
  1169.       if p then
  1170.          user_options=substr(args,p+1)
  1171.          args=substr(args,1,p-1)
  1172.       endif
  1173.       if marktype() then
  1174.          all=''
  1175.       else           -- No mark, so override if default is M.
  1176.          all='A'
  1177.       endif
  1178. compile if defined(HIGHLIGHT_COLOR)
  1179.       search_len=length(args)-1   /***** added for hilite *****/
  1180. compile endif
  1181.       args=args|| delim || default_search_options || all || user_options
  1182. compile if not defined(HIGHLIGHT_COLOR)
  1183.    endif
  1184. compile endif
  1185.    'xcom l 'args
  1186. compile if EVERSION < 5
  1187.    if not rc and r then
  1188.       cursor_data
  1189.  compile if defined(HIGHLIGHT_COLOR)
  1190.       refresh
  1191.       sayat '', .windowy+.cursory-1,.windowx+.cursorx-1,
  1192.             HIGHLIGHT_COLOR, min(search_len, .windowwidth - .cursorx + 1)
  1193.       k = mgetkey(); executekey k
  1194.  compile endif
  1195.    else
  1196.       call leave_last_command(r,rc)
  1197.    endif
  1198. compile elseif defined(HIGHLIGHT_COLOR)
  1199.    if not rc then
  1200.  compile if EVERSION < '5.50'
  1201.       refresh
  1202.       sayat '', .cursory, .cursorx, HIGHLIGHT_COLOR, min(search_len, .windowwidth - .cursorx + 1)
  1203.  compile elseif EVERSION >= '5.60'
  1204.       circleit LOCATE_CIRCLE_STYLE, .line, .col, .col+getpminfo(EPMINFO_LSLENGTH)-1, LOCATE_CIRCLE_COLOR1, LOCATE_CIRCLE_COLOR2
  1205.  compile elseif EVERSION >= '5.51'
  1206.       circleit LOCATE_CIRCLE_STYLE, .line, .col, .col+getpminfo(EPMINFO_LSLENGTH)-1, HIGHLIGHT_COLOR
  1207.  compile else
  1208.       circleit LOCATE_CIRCLE_STYLE, .line, .col, .col+search_len-1, HIGHLIGHT_COLOR
  1209. ;     refresh
  1210.  compile endif
  1211.    endif
  1212. compile endif
  1213.  
  1214. ; As of EPM 5.18, this command supports use of the DOS or OS/2 ATTRIB command,
  1215. ; so non-IBM users can also use the LIST command.  Note that installing SUBDIR
  1216. ; (DOS) or FILEFIND (OS/2) is still preferred, since it's not necessary to
  1217. ; "clean up" their output.  Also, ATTRIB before DOS 3.? doesn't support the /S
  1218. ; option we need to search subdirectories.
  1219. defc list, findfile, filefind=
  1220.    universal vTEMP_FILENAME
  1221.    universal subdir_present
  1222.  compile if EVERSION < 5
  1223.    call save_command_state(cstate)
  1224.  compile endif
  1225.    /* If I say "list c:\util" I mean the whole util directory.  But we */
  1226.    /* have to tell SubDir that explicitly by appending "\*.*".         */
  1227.    spec = arg(1)
  1228.    call parse_filename(spec,.filename)
  1229.    if spec='' then    /* If no argument at all, assume current directory. */
  1230.       spec="*.*"
  1231.    elseif not verify(spec,'*?','M') then      /* If no wildcards... */
  1232. compile if EPM                                   /* assume directory.  */
  1233.       if pos(rightstr(spec,1),'\:') then         /* If ends in ':' or '\' */
  1234. compile else
  1235.       if pos(substr(spec,length(spec),1),'\:') then
  1236. compile endif
  1237.          spec=spec'*.*'                             /* just add '*.*'         */
  1238.       else
  1239.          spec=spec'\*.*'                            /* Otherwise, add '\*.*'  */
  1240.       endif
  1241.    endif
  1242.    src = subdir(spec' >'vTEMP_FILENAME)  -- Moved /Q option to defproc subdir
  1243.  
  1244.    'e' argsep'd' argsep'q' vTEMP_FILENAME
  1245.    call erasetemp(vTEMP_FILENAME)
  1246.    if .last then
  1247.       .filename='.DIR 'spec
  1248.       if pos('ATTRIB.EXE',subdir_present) then  /* Handle differently          */
  1249.          getline line,1
  1250.          if src then                  /* Extract error message.      */
  1251.             'xcom q'
  1252. compile if EVERSION < 5
  1253.             call restore_command_state(cstate)
  1254. compile endif
  1255.             sayerror FILE_NOT_FOUND__MSG':  'line
  1256.          else                         /* Must delete the attributes.      */
  1257.             c=pos(':',line)           /* Delete through last space before */
  1258.             s=lastpos(' ',line,c+1)   /* the colon.  Can't use absolute   */
  1259.             if s then                 /* column position; changes with OS */
  1260.                call psave_mark(savemark)
  1261.                getfileid fid
  1262.                call pset_mark(1,.last,1,s,'BLOCK',fid)
  1263.                deletemark
  1264.                call prestore_mark(savemark)
  1265.                .modify=0
  1266.             endif
  1267.          endif
  1268. compile if not E3
  1269.       elseif substr(subdir_present,1,4)='dir ' then
  1270.          if .last<=2 & substr(textline(.last),1,8)='SYS0002:' then
  1271.             'xcom q'
  1272.             sayerror FILE_NOT_FOUND__MSG
  1273.          endif
  1274. compile endif
  1275.       endif
  1276.    else
  1277.       'xcom q'
  1278. compile if EVERSION < 5
  1279.       call restore_command_state(cstate)
  1280. compile endif
  1281.       sayerror FILE_NOT_FOUND__MSG
  1282.    endif
  1283.    call select_edit_keys()
  1284.  
  1285. compile if WANT_LAN_SUPPORT
  1286. defc lock
  1287.    if arg(1)<>'' then
  1288.       'e 'arg(1)
  1289.       if rc & rc<>-282 then  --sayerror('New file')
  1290.          return 1
  1291.       endif
  1292.    endif
  1293.    call lock()
  1294. compile endif
  1295.  
  1296. compile if WANT_LONGNAMES='SWITCH'
  1297. defc longnames
  1298.    universal SHOW_LONGNAMES
  1299.    uparg=upcase(arg(1))
  1300.    if uparg=ON__MSG or uparg=1 then
  1301.       SHOW_LONGNAMES = 1
  1302.    elseif uparg=OFF__MSG or uparg=0 then
  1303.       SHOW_LONGNAMES = 0
  1304.    else
  1305.       sayerror LONGNAMES_IS__MSG word(OFF__MSG ON__MSG, SHOW_LONGNAMES+1)
  1306.    endif
  1307. compile endif
  1308.  
  1309. defc loopkey=
  1310.    parse value arg(1) with finish k .
  1311.    if upcase(finish)='ALL' then
  1312.       finish= .last-.line+1
  1313.    endif
  1314.    if not isnum(finish) then sayerror INVALID_NUMBER__MSG;stop endif
  1315.    if k == '' then
  1316. compile if EVERSION < 5
  1317.       k=mgetkey(KEY_PROMPT1__MSG)  -- Accept key from macro.
  1318.    endif
  1319.    if k<>esc then
  1320.       cursor_data
  1321. compile else
  1322.       sayerror KEY_PROMPT2__MSG '"loopkey 'finish' =", "loopkey 'finish' S+F3".'
  1323.    else
  1324.       k=resolve_key(k)
  1325. compile endif
  1326.       oldcol=.col
  1327.       for i=1 to finish
  1328.          executekey k;down;.col=oldcol
  1329.       endfor
  1330. compile if EVERSION < 5
  1331.       cursor_command
  1332. compile endif
  1333.    endif
  1334.    sayerror 0
  1335.  
  1336. defc lowercase=
  1337.    call plowercase()
  1338.  
  1339. compile if EPM
  1340. ;  In EOS2 you could query the margins by typing "margins" with no argument.
  1341. ;  It typed them into the command line.  In EPM we can't write to the command
  1342. ;  line (yet).  So the query uses a sayerror.
  1343. ;
  1344. defc margins,ma=
  1345.    if arg(1)<>'' then         -- if user gives an argument he's setting,
  1346.       'xcom margins' arg(1)   -- pass it to the old internal margins command.
  1347.    else
  1348.       'commandline margins' .margins   -- Note the new .margins field
  1349.    endif
  1350. compile endif
  1351.  
  1352. defc matchtab=
  1353.    universal matchtab_on
  1354.    uparg=upcase(arg(1))
  1355.    if uparg=ON__MSG then
  1356.       matchtab_on = 1
  1357.    elseif uparg=OFF__MSG then
  1358.       matchtab_on = 0
  1359.    elseif uparg='' then
  1360. compile if EVERSION < 5
  1361.       if matchtab_on then onoff = ON__MSG; else onoff = OFF__MSG; endif
  1362.       cursor_command
  1363.       setcommand 'matchtab' onoff, 10, 1
  1364. compile else
  1365.       sayerror 'MATCHTAB:' word(OFF__MSG ON__MSG, matchtab_on+1)
  1366. compile endif
  1367.    else
  1368.       sayerror INVALID_ARG__MSG ON_OFF__MSG')'
  1369.       stop
  1370.    endif
  1371.  
  1372. ; MultiCommand, or Many Commands - lets you enter many commands on a line,
  1373. ; like XEDIT's SET LINEND, but you specify the delimiter as part of the
  1374. ; command so there's never a conflict.  Example, using ';' as delimiter:
  1375. ;   mc ; top; c /begin/{/ *; top; c/end/}/ *; top
  1376. defc mc =
  1377.    parse value strip(arg(1),'L') with delim 2 rest
  1378.    do while rest <> ''
  1379.       parse value rest with cmd (delim) rest
  1380.       cmd
  1381.    enddo
  1382.  
  1383. defc n,name
  1384. compile if WANT_LONGNAMES='SWITCH'
  1385.    universal SHOW_LONGNAMES
  1386. compile endif
  1387.    -- Name with no args supplies current name.
  1388.    if arg(1)='' then
  1389. compile if EVERSION < 5
  1390.       setcommand 'Name '.filename,6
  1391. compile else
  1392.       'commandline Name '.filename
  1393. compile endif
  1394.    else
  1395. compile if WANT_LAN_SUPPORT | EVERSION >= '5.51'
  1396.       if .lockhandle then
  1397.          sayerror LOCKED__MSG
  1398.          return
  1399.       endif
  1400. compile endif
  1401. compile if SMARTFILE or EVERSION >= '5.50'
  1402.       oldname = .filename
  1403. compile endif
  1404.       autosave_name = MakeTempName()
  1405.       call namefile(arg(1))
  1406. compile if SMARTFILE or EVERSION >= '5.50'
  1407.       if oldname <> .filename then .modify = .modify+1 endif
  1408. compile endif
  1409. compile if EVERSION > 5
  1410.       if get_EAT_ASCII_value('.LONGNAME')<>'' then
  1411.          call delete_ea('.LONGNAME')
  1412.  compile if WANT_LONGNAMES
  1413.   compile if WANT_LONGNAMES='SWITCH'
  1414.          if SHOW_LONGNAMES then
  1415.   compile endif
  1416.             .titletext = ''
  1417.   compile if WANT_LONGNAMES='SWITCH'
  1418.          endif
  1419.   compile endif
  1420.  compile endif  -- WANT_LONGNAMES
  1421.       endif  -- .LONGNAME EA exists
  1422.  compile if SHOW_MODIFY_METHOD = 'TITLE' | EVERSION < '5.50'
  1423.       call settitletext(.filename)
  1424.  compile endif
  1425.  compile if MENU_LIMIT
  1426.       call updateringmenu()
  1427.  compile endif
  1428. compile endif  -- EVERSION > 5
  1429. compile if E3
  1430.       if exist(autosave_name) then
  1431.          quietshell 'rename' autosave_name MakeTempName()
  1432.       endif
  1433. compile else
  1434.       call dosmove(autosave_name, MakeTempName())  -- Rename the autosave file
  1435. compile endif
  1436.       call select_edit_keys()
  1437. compile if SUPPORT_USER_EXITS
  1438.       if isadefproc('rename_exit') then
  1439.          call rename_exit(oldname, .filename)
  1440.       endif
  1441. compile endif
  1442. compile if INCLUDE_BMS_SUPPORT
  1443.       if isadefproc('BMS_rename_exit') then
  1444.          call BMS_rename_exit(oldname, .filename)
  1445.       endif
  1446. compile endif
  1447.    endif
  1448.  
  1449. defc newwindow=
  1450. compile if EVERSION < 5
  1451.    universal messy
  1452.    if messy then opt=' /w'; else opt=''; endif
  1453.    rest=parse_file_n_opts(arg(1))
  1454.    newwindow 'e'opt rest
  1455.    call select_edit_keys()
  1456. compile else
  1457.    if .modify then
  1458.       'save'
  1459.       if rc then
  1460.          sayerror ERROR_SAVING_HALT__MSG
  1461.          return
  1462.       endif
  1463.    endif
  1464.    'open' .filename
  1465.    'quit'
  1466. compile endif
  1467.  
  1468. compile if EPM
  1469. ;  New in EPM.  Edits a file in a different PM window.  This means invoking
  1470. ;  a completely new instance of E.DLL, with its own window and data.  We do it
  1471. ;  by posting a message to the executive, the top-level E application.
  1472. defc o,open=
  1473.    fname=strip(arg(1))                    -- Remove excess spaces
  1474.    call parse_filename(fname,.filename)   -- Resolve '=', if any
  1475.  
  1476.    call windowmessage(0,  getpminfo(APP_HANDLE),
  1477.                       5386,                   -- EPM_EDIT_NEWFILE
  1478.                       put_in_buffer(fname),
  1479.                       1)                      -- Tell EPM to free the buffer.
  1480. compile endif
  1481.  
  1482. compile if EVERSION > 5
  1483. defc openhelp
  1484.  compile if 0
  1485.    rectangle = atol(4) || atol(75)  || atol(632) || atol(351)
  1486.  
  1487.    filename  = arg(1) \0
  1488.    exfile    = 'help.ex' \0
  1489.    topoffile = HELP_TOP__MSG\0
  1490.    botoffile = HELP_BOT__MSG\0
  1491.    rethwnd   = '1234'
  1492.    params =   atol(getpminfo(EPMINFO_HAB))          ||  /* application anchor block              */
  1493.               atol(getpminfo(EPMINFO_PARENTCLIENT)) ||  /* handle to parent of edit window       */
  1494.               atol(getpminfo(EPMINFO_OWNERCLIENT))  ||  /* handle to owner of edit window        */
  1495.               address(rectangle)   ||  /* positioning of edit window            */
  1496.               address(filename)    ||  /* file to be edited                     */
  1497.               atol(0)              ||  /* handle to editor pointer icon.        */
  1498.               atol(0)              ||  /* handle to mark pointer icon.          */
  1499.               atol(0)              ||  /* editor ICON.                          */
  1500.               atol(12)             ||  /* internal editor options               */
  1501.               atol(203)            ||  /* PM standard window styles (FCF_xxxx)  */
  1502.               atoi(1)              ||  /* TRUE = LARGE FONT,  FALSE = SMALL FONT*/
  1503.               address(exfile)      ||  /* pre-compiled macro code file (EPM.EX) */
  1504.               address(topoffile)   ||  /* top and bottom of file markers        */
  1505.               address(botoffile)   ||
  1506.               atoi(0)              ||  /* unique window id specified for edit window */
  1507.               atol(0)              ||  /* environment variable to search for .ex */
  1508.               atoi(0)                  /* reserved for future use.              */
  1509.  
  1510.    call dynalinkc( E_DLL,
  1511.              '_EPM_EDITWINDOWCREATE',
  1512.               address(params)    ||
  1513.               address(rethwnd))
  1514.  compile else
  1515.  
  1516.    -- send EPM icon window a help message.  It will take care of
  1517.    -- the correct setting up of the help window.
  1518.    --
  1519.    call windowmessage(0,  getpminfo(APP_HANDLE),
  1520.                       5132,                   -- EPM_POPHELPBROWSER
  1521.                       put_in_buffer(arg(1)),
  1522.                       1)                      -- Tell EPM to free the buffer.
  1523.  compile endif
  1524. compile endif
  1525.  
  1526. ;  Print just the marked area, if there is one.  Defaults to printing on LPT1.
  1527. ;  Optional argument specifies printer.
  1528. defc print=  /* Save the users current file to the printer */
  1529.    parse arg prt ':'                             -- Optional printer name
  1530.    if not prt then prt=default_printer(); endif  -- Default
  1531.    prtnum = check_for_printer(prt)
  1532.    if prtnum then
  1533.       if not printer_ready(prtnum) then
  1534.          sayerror PRINTER_NOT_READY__MSG
  1535.          stop
  1536.       endif
  1537.    elseif substr(prt,1,2)<>'\\' then      -- Assume \\hostname\prt is correct.
  1538.       sayerror BAD_PRINT_ARG__MSG
  1539.       stop
  1540.    endif
  1541.    if marktype() then
  1542.       getmark firstline,lastline,firstcol,lastcol,markfileid
  1543.       getfileid fileid
  1544.       if fileid<>markfileid then
  1545.          sayerror OTHER_FILE_MARKED__MSG UNMARK_OR_EDIT__MSG markfileid.filename
  1546.          stop
  1547.       endif
  1548.       mt=marktype()
  1549.       'xcom e /n'             /*  Create a temporary no-name file. */
  1550.       if rc=-282 then  -- sayerror("New file")
  1551.          if marktype()='LINE' then deleteline endif
  1552.       elseif rc then
  1553.          stop
  1554.       endif
  1555.       getfileid tempofid
  1556.       call pcopy_mark()
  1557.       if rc then stop endif
  1558.       call pset_mark(firstline,lastline,firstcol,lastcol,mt,markfileid)
  1559.       activatefile tempofid
  1560.       sayerror PRINTING_MARK__MSG
  1561.    else
  1562.       sayerror PRINTING__MSG .filename
  1563.    endif
  1564. compile if EVERSION < '5.50'
  1565.    'xcom save /q' prt     /* This will not set .modify to 0 */
  1566. compile else
  1567.    'xcom save /ne /q' prt  /* /NE means No EOF (for Laserjet driver) */
  1568. compile endif
  1569.    if marktype() then .modify=0; 'xcom q' endif
  1570.    sayerror 0    /* clear 'printing' message */
  1571.  
  1572. compile if EVERSION > 5
  1573. defc processbreak
  1574.    universal Dictionary_loaded
  1575.    call showwindow('ON')             -- Make sure that the window is displayed.
  1576.    if dictionary_loaded then
  1577.       call drop_dictionary()
  1578.    endif
  1579.    sayerror MACRO_HALTED__MSG
  1580. compile endif
  1581.  
  1582. compile if WANT_PROFILE='SWITCH'
  1583. defc PROFILE
  1584.    universal REXX_PROFILE
  1585.    uparg=upcase(arg(1))
  1586.    if uparg=ON__MSG or uparg=1 then
  1587.       REXX_PROFILE = 1
  1588.    elseif uparg=OFF__MSG or uparg=0 then
  1589.       REXX_PROFILE = 0
  1590.    else
  1591.       sayerror 'Profile' word(OFF__MSG ON__MSG, REXX_PROFILE+1)
  1592.    endif
  1593. compile endif
  1594.  
  1595. compile if WANT_STACK_CMDS
  1596. definit
  1597.    universal mark_stack, position_stack
  1598.    mark_stack = ''
  1599.    position_stack = ''
  1600.  
  1601. defc popmark
  1602.    universal mark_stack
  1603.    parse value mark_stack with savemark '/' mark_stack
  1604.    call prestore_mark(savemark)
  1605.  
  1606. defc poppos
  1607.    universal position_stack
  1608.    parse value position_stack with fid saveposition '/' position_stack
  1609.    if fid='' then
  1610.       sayerror STACK_EMPTY__MSG
  1611.       return
  1612.    endif
  1613. compile if EPM  -- EPM has error checking; EOS2 & E3 just stop.
  1614.    display -2
  1615.    rc = 0
  1616. compile endif
  1617.    activatefile fid
  1618. compile if EPM
  1619.    display 2
  1620.    if rc then
  1621.       sayerror FILE_GONE__MSG
  1622.       return
  1623.    endif
  1624. compile endif
  1625.    call prestore_pos(saveposition)
  1626.  
  1627. defc pushmark
  1628.    universal mark_stack
  1629.    call checkmark()
  1630.    call psave_mark(savemark)  -- Note - this does an UNMARK
  1631.    call prestore_mark(savemark)
  1632.    if length(mark_stack) + length(savemark) >= MAXCOL then
  1633.       sayerror STACK_FULL__MSG
  1634.       return
  1635.    endif
  1636.    mark_stack = savemark'/'mark_stack
  1637.  
  1638. defc swapmark
  1639.    universal mark_stack
  1640.    call checkmark()
  1641.    call psave_mark(savemark)
  1642.    'popmark'
  1643.    if length(mark_stack) + length(savemark) >= MAXCOL then
  1644.       sayerror STACK_FULL__MSG
  1645.       return
  1646.    endif
  1647.    mark_stack = savemark'/'mark_stack
  1648.  
  1649. defc pushpos
  1650.    universal position_stack
  1651.    call psave_pos(saveposition)
  1652.    getfileid fid
  1653.    if length(position_stack) + length(saveposition fid) >= MAXCOL then
  1654.       sayerror STACK_FULL__MSG
  1655.       return
  1656.    endif
  1657.    position_stack = fid saveposition'/'position_stack
  1658.  
  1659. defc swappos
  1660.    universal position_stack
  1661.    call psave_pos(saveposition)
  1662.    getfileid fid
  1663.    'poppos'
  1664.    if length(position_stack) + length(saveposition fid) >= MAXCOL then
  1665.       sayerror STACK_FULL__MSG
  1666.       return
  1667.    endif
  1668.    position_stack = fid saveposition'/'position_stack
  1669. compile endif
  1670.  
  1671. defc qs,quietshell,quiet_shell=
  1672.    quietshell arg(1)
  1673.  
  1674. defc q,quit=
  1675.    -- Ver. 4.11c: If we're trying to quit the shell window, kill the process.
  1676. compile if EVERSION >= '4.11'
  1677.  compile if SHELL_USAGE
  1678.    if .filename = ".SHELL" then
  1679. ;     It's important to kill the process before we quit the window, else the
  1680. ;     process will churn merrily along without output.  If we're MAKEing a
  1681. ;     large C program and quit the editor, it can tie up the session.
  1682. ;     Simpler tasks like DIR and FILEFIND don't tie up the session.
  1683. ;
  1684. ;     Doesn't hurt anything if the process has already been killed.  The
  1685. ;     internal shell_kill function will merely beep at you.
  1686.       call shell_kill()
  1687.    endif
  1688.  compile endif
  1689. compile endif
  1690.  
  1691. compile if EVERSION > '5.19' & WANT_EPM_SHELL
  1692.    if leftstr(.filename, 15) = ".command_shell_" then
  1693.       'shell_kill'
  1694.       return
  1695.    endif
  1696. compile endif
  1697.  
  1698. compile if SUPPORT_USER_EXITS
  1699.       if isadefproc('quit_exit') then
  1700.          call quit_exit(.filename)
  1701.       endif
  1702. compile endif
  1703. compile if INCLUDE_BMS_SUPPORT
  1704.       if isadefproc('BMS_quit_exit') then
  1705.          call BMS_quit_exit(.filename)
  1706.       endif
  1707. compile endif
  1708.  
  1709. compile if TRASH_TEMP_FILES
  1710.    if substr(.filename,1,1) = "." then      -- a temporary file
  1711.       .modify=0                             -- so no "Are you sure?"
  1712.    endif
  1713. compile endif
  1714.  
  1715.    getfileid quitfileid      -- Temp workaround
  1716. ;compile if EVERSION > 5
  1717. ;   if marktype() then
  1718. ;      getmark firstline,lastline,firstcol,lastcol,markfileid
  1719. ;      if markfileid = quitfileid then
  1720. ;         'ClearSharBuff'       -- Remove content of EPM shared text buffer
  1721. ;      endif
  1722. ;   endif
  1723. ;compile endif
  1724. compile if WANT_LAN_SUPPORT & EVERSION < '5.51'
  1725.    if .lockhandle then call unlock(quitfileid); endif
  1726. compile endif
  1727.    call quitfile()
  1728. compile if EVERSION < 5
  1729.    call select_edit_keys()
  1730.    .box=2
  1731. compile elseif MENU_LIMIT
  1732.    getfileid fileid
  1733.    if fileid <> quitfileid then    -- temp workaround - fileid not null if no more files;
  1734.                                    -- breaks updateringmenu.
  1735.    call updateringmenu()
  1736.    endif
  1737. compile endif
  1738.  
  1739. defc rc=
  1740.    arg(1)
  1741.    sayerror 'RC='rc''
  1742.  
  1743. defc reflow_all
  1744.    call psave_mark(savemark)
  1745.    call psave_pos(savepos)
  1746. compile if not EPM
  1747.    cursor_data
  1748. compile endif
  1749.    stopit = 0
  1750.    top
  1751.    do forever
  1752.       getline line
  1753.       do while line='' |                              -- Skip over blank lines or
  1754.                (lastpos(':',line)=1 & pos('.',line)=length(line)) |  -- lines containing only a GML tag or
  1755.                substr(line,1,1)='.'                                  -- SCRIPT commands
  1756.          if .line=.last then stopit=1; leave; endif
  1757.          down
  1758.          getline line
  1759.       enddo
  1760.       if stopit then leave; endif
  1761.       startline = .line
  1762.       unmark; mark_line
  1763.       call pfind_blank_line()
  1764.       if .line<>startline then
  1765.          up
  1766.       else
  1767.          bottom
  1768.       endif
  1769.       mark_line
  1770.       reflow
  1771.       getmark firstline,lastline
  1772.       if lastline=.last then leave; endif
  1773.       lastline+1
  1774.    enddo
  1775.    call prestore_mark(savemark)
  1776.    call prestore_pos(savepos)
  1777.  
  1778. defc s,save=
  1779.    universal save_with_tabs, default_save_options
  1780.    name=arg(1)
  1781.    call parse_leading_options(name,options)
  1782.    options = default_save_options options
  1783. compile if EVERSION >= '5.21'
  1784.    save_as = 0
  1785.    if name='' | name=UNNAMED_FILE_NAME then
  1786. compile else
  1787.    if name='' then
  1788. compile endif
  1789.       name=.filename
  1790. compile if EVERSION >= '5.21'
  1791.       if .filename=UNNAMED_FILE_NAME then
  1792.          result = saveas_dlg(name, type)
  1793.          if result then return result; endif
  1794.          'name' name
  1795.          if not rc then
  1796.             name=.filename
  1797.             save_as = 1
  1798.          endif
  1799.       endif
  1800. compile endif
  1801.    else
  1802.       call parse_filename(name,.filename)
  1803.    endif
  1804. compile if SUPPORT_USER_EXITS
  1805.       if isadefproc('presave_exit') then
  1806.          call presave_exit(name, options, save_as)
  1807.       endif
  1808. compile endif
  1809. compile if INCLUDE_BMS_SUPPORT
  1810.       if isadefproc('BMS_presave_exit') then
  1811.          call BMS_presave_exit(name, options, save_as)
  1812.       endif
  1813. compile endif
  1814. compile if WANT_LAN_SUPPORT & EVERSION < '5.51'
  1815.    locked = .lockhandle
  1816.    if locked & not arg(1) then 'unlock'; endif
  1817. compile endif
  1818. compile if WANT_BOOKMARKS
  1819.    if .levelofattributesupport%8 - 2*(.levelofattributesupport%16) then
  1820.       'saveattributes'
  1821.    endif
  1822. compile endif
  1823. compile if not E3
  1824.    -- 4.10:  Saving with tab compression is built in now.  No need for
  1825.    -- the make-do proc savefilewithtabs().
  1826.    -- 4.10 new feature:  if save_with_tabs is true, always specify /t.
  1827.    if save_with_tabs then
  1828.       options = '/t' options
  1829.    endif
  1830. compile elseif WANT_TABS
  1831.    if isoption(options,'t') or save_with_tabs then
  1832.       src=savefilewithtabs(name,options)
  1833.    else
  1834. compile endif
  1835.       src=savefile(name,options)
  1836. compile if (EVERSION < '4.10') & WANT_TABS
  1837.    endif
  1838. compile endif
  1839. compile if SUPPORT_USER_EXITS
  1840.       if isadefproc('postsave_exit') then
  1841.          call postsave_exit(name, options, save_as, src)
  1842.       endif
  1843. compile endif
  1844. compile if INCLUDE_BMS_SUPPORT
  1845.       if isadefproc('BMS_postsave_exit') then
  1846.          call BMS_postsave_exit(name, options, save_as, src)
  1847.       endif
  1848. compile endif
  1849.    if not src & not isoption(options,'q') then
  1850.       call message(SAVED_TO__MSG name)
  1851. compile if not E3
  1852.    elseif src=-5 then  -- call message('Access denied')
  1853.       if qfilemode(name, attrib) then      -- Error from DosQFileMode
  1854.          call message(src)    -- ? Don't know why got Access denied.
  1855.       else                    -- File exists:
  1856.          if attrib % 16 - 2 * (attrib % 32) then    -- x'10' is on
  1857.             call message(ACCESS_DENIED__MSG '-' IS_A_SUBDIR__MSG)  -- It's a subdirectory
  1858.          elseif attrib // 2 then                    -- x'01' is on
  1859.             call message(ACCESS_DENIED__MSG '-' READ_ONLY__MSG)    -- It's read/only
  1860.          elseif attrib % 4 - 2 * (attrib % 8) then  -- x'04' is on
  1861.             call message(ACCESS_DENIED__MSG '-' IS_SYSTEM__MSG)    -- It's a system file
  1862.          elseif attrib % 2 - 2 * (attrib % 4) then  -- x'02' is on
  1863.             call message(ACCESS_DENIED__MSG '-' IS_HIDDEN__MSG)    -- It's a hidden file
  1864.          else                                -- None of the above?
  1865.             call message(ACCESS_DENIED__MSG '-' MAYBE_LOCKED__MSG) -- Maybe someone locked it.
  1866.          endif
  1867.       endif
  1868.       rc = src  -- reset, since qfilemode() changed the RC.
  1869. compile endif
  1870. compile if EPM32
  1871.    elseif src=-345 then
  1872.       call winmessagebox('Demo Version', sayerrortext(-345)\10\10'File too large to be saved.' , MB_CANCEL + MB_CRITICAL + MB_MOVEABLE)
  1873. compile endif
  1874.    elseif src<0 then          -- If RC > 0 assume from host save; and
  1875.       call message(src)       -- assume host routine gave error msg.
  1876.    endif
  1877. compile if EVERSION >= '5.21'
  1878.    if src & save_as then
  1879.       .filename=UNNAMED_FILE_NAME
  1880.  compile if SHOW_MODIFY_METHOD = 'TITLE'
  1881.       call settitletext(.filename)
  1882.  compile endif
  1883.  compile if MENU_LIMIT
  1884.       call updateringmenu()
  1885.  compile endif
  1886.    endif
  1887. compile endif
  1888. compile if E3 and SHOW_MODIFY_METHOD
  1889.    call show_modify()
  1890. compile endif
  1891. compile if WANT_LAN_SUPPORT & EVERSION < '5.51'
  1892.    if locked & not arg(1) then call lock(); endif
  1893. compile endif
  1894.    return src
  1895.  
  1896. defc select_all =
  1897.    getfileid fid
  1898.    call pset_mark(1, .last, 1, length(textline(.last)), 'CHAR' , fid)
  1899. compile if EVERSION >= 5
  1900.    'Copy2SharBuff'       /* Copy mark to shared text buffer */
  1901. compile endif
  1902.  
  1903. compile if SETSTAY='?'
  1904. defc stay=
  1905.    universal stay
  1906.    parse arg arg1; arg1=upcase(arg1)
  1907.  compile if EPM
  1908.    if arg1='' then sayerror 'Stay =' word(OFF__MSG ON__MSG, stay+1)
  1909.  compile else
  1910.    if arg1='' then sayerror 'Stay =' stay
  1911.  compile endif
  1912.    elseif arg1='1' | arg1=ON__MSG then stay=1
  1913.    elseif arg1='0' | arg1=OFF__MSG then stay=0
  1914.    else sayerror INVALID_ARG__MSG ON_OFF__MSG')'
  1915.    endif
  1916. compile endif
  1917.  
  1918. compile if EVERSION >= '4.11'
  1919. ; read a file from stdin
  1920. defc stdfile_read
  1921.  while  read_stdin() > 0 do
  1922.     join
  1923.     bottom
  1924.  endwhile
  1925.  
  1926. ; write a file to stdout
  1927. defc stdfile_write
  1928.  if .filename=='' then
  1929.     .filename='UNNAMED'
  1930.  endif
  1931.  's'
  1932.  'type '.filename
  1933.  'q'
  1934. compile endif
  1935.  
  1936. compile if EVERSION >= '5.50'  -- Earlier versions didn't retain trailing blanks anyway.
  1937. defc strip =
  1938.    parse arg firstline lastline .
  1939.    if firstline='' then firstline=1; endif
  1940.    if lastline='' then lastline=.last; endif
  1941.    do i=firstline to lastline
  1942.       getline line, i
  1943.       if length(line) & rightstr(line,1) == ' ' then
  1944.          replaceline strip(line, 'T'), i
  1945.       endif
  1946.    enddo
  1947. compile endif
  1948.  
  1949. compile if TOGGLE_TAB
  1950. defc TABKEY
  1951.    universal TAB_KEY
  1952.    uparg=upcase(arg(1))
  1953.    if uparg=ON__MSG or uparg=1 then
  1954.       TAB_KEY = 1
  1955.    elseif uparg=OFF__MSG or uparg=0 then
  1956.       TAB_KEY = 0
  1957.    else
  1958.       sayerror 'TabKey' word(OFF__MSG ON__MSG, TAB_KEY+1)
  1959.    endif
  1960. compile endif
  1961.  
  1962. compile if (EVERSION >= '5.60c' & EVERSION < 6) | EVERSION >= '6.00c'
  1963. defc tabglyph =
  1964.    uparg=upcase(arg(1))
  1965.    if uparg=ON__MSG or uparg=1 then
  1966.       call tabglyph(1)
  1967.    elseif uparg=OFF__MSG or uparg='0' then
  1968.       call tabglyph(0)
  1969.    elseif uparg='' or uparg='?' then
  1970.       cb = tabglyph()     -- query current state
  1971.       sayerror TABGLYPH_IS__MSG word(OFF__MSG ON__MSG, cb+1)
  1972.    else
  1973.       sayerror INVALID_ARG__MSG ON_OFF__MSG'/?)'
  1974.    endif
  1975. compile endif
  1976.  
  1977. compile if EVERSION >= 5
  1978. ;  In EOS2 you could query the tabs by typing "tabs" with no argument.
  1979. ;  It typed them into the command line.
  1980. ;
  1981. defc tabs=
  1982.    if arg(1)<>'' then         -- if user gives an argument to be set,
  1983.       'xcom tabs 'arg(1)      -- pass it to the old internal tabs command.
  1984.    else
  1985.       -- Note the new .tabs field; each file has its own tabs.
  1986.       'commandline Tabs' .tabs
  1987.    endif
  1988. compile endif
  1989.  
  1990.  
  1991. defc top=
  1992.    top
  1993.  
  1994. compile if WANT_LAN_SUPPORT
  1995. defc unlock
  1996.    parse arg file
  1997.    if file='' then
  1998.       getfileid fileid
  1999.    else
  2000.       getfileid fileid,file
  2001.       if fileid=='' then
  2002.          sayerror '"'file'"' DOES_NOT_EXIST__MSG
  2003.          return 1
  2004.       endif
  2005.    endif
  2006.    call unlock(fileid)
  2007. compile endif
  2008.  
  2009. defc uppercase=
  2010.    call puppercase()
  2011.  
  2012. compile if EPM
  2013. defc ver =
  2014.    sayerror EDITOR_VER__MSG ver(0)
  2015. compile endif
  2016.  
  2017. defc xcom_quit
  2018. compile if EVERSION < 5
  2019.    if .windowoverlap then
  2020.       quitview
  2021.    else
  2022.       'xcom q'
  2023.    endif
  2024. compile else
  2025.    'xcom q'
  2026. compile endif
  2027.  
  2028.