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