home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epm603a.zip / EPMMAC.ZIP / STDPROCS.E < prev    next >
Text File  |  1995-11-10  |  65KB  |  1,890 lines

  1. compile if EVERSION >= 4 & EVERSION < '5.51'  -- 5.51 & above define this internally.
  2. defproc address(var varname) =
  3.    return selector(varname) || offset(varname)
  4. compile endif
  5.  
  6. ; A useful subroutine:  asks "Are you sure (Y/N)?" (same as DOS's prompt
  7. ; after "erase *.*") and returns uppercase keystroke.
  8. ; If called with a string parameter, displays it at start of prompt, e.g.
  9. ;   usersays = askyesno("About to erase.")
  10. ;   ==>   "About to erase. Are you sure (Y/N)? "
  11. ; EPM 5.12B:  Now enabled for EPM, using entrybox().  Optional second argument
  12. ; is a flag to prevent the "Are you sure" from being appended.
  13. ; EPM 5.15:  Now uses WinMessageBox to get Yes, No buttons.  [\toolktxx\c\include\pmwin.h]
  14. ; 93/12/15:  Added optional 3rd arg for messagebox title.
  15. defproc askyesno
  16.    prompt=arg(1)
  17. compile if EVERSION < 5
  18.    if not arg(2) then
  19.       prompt=prompt || ARE_YOU_SURE_YN__MSG
  20.    endif
  21.    return upcase(mgetkey(prompt))     /* Accept key from macro. */
  22. compile else
  23.    if not arg(2) then
  24.       prompt=prompt\13 || ARE_YOU_SURE__MSG
  25.    endif
  26.    return substr(YES_CHAR || NO_CHAR, winmessagebox(arg(3), prompt, 16388) - 5, 1)  -- YESNO + MOVEABLE
  27. compile endif
  28.  
  29.  
  30. compile if EVERSION >= 4
  31. ; Does an atol of its argument, then a word reversal and returns the result.
  32. defproc atol_swap(num)
  33.    hwnd=atol(num)
  34.  compile if EVERSION >= '5.17'
  35.    return rightstr(hwnd,2) || leftstr(hwnd,2)
  36.  compile else
  37.    return substr(hwnd,3,2) || substr(hwnd,1,2)
  38.  compile endif
  39. compile endif
  40.  
  41.  
  42. defproc checkmark()        /* Common routine, save space.  from Jim Hurley.*/
  43.   if marktype()='' then
  44. compile if EPM
  45.     sayerror NO_MARK_HERE__MSG
  46. compile else
  47.     sayerror NO_MARK__MSG
  48. compile endif
  49.     stop
  50.   endif
  51.  
  52. ; Routine to tell if a mark is visible on the screen.  (Actually, only on the
  53. ; current window; if the window is less than full size, a mark could be visible
  54. ; in an inactive window without our being able to tell.)  Also, if a character
  55. ; mark begins above the top of the window and ends below the bottom, and the
  56. ; window contains only blank lines, then this routine will return 1 (since the
  57. ; mark spans the window) even though no sign of the mark will be visible.
  58. defproc check_mark_on_screen =
  59.    if marktype() = '' then return 0; endif  -- If no mark, then not on screen.
  60.    getmark first_mark_line, last_mark_line, first_mark_col, last_mark_col
  61.    first_screen_line = .line - .cursory + 1
  62.    last_screen_line = .line - .cursory + .windowheight
  63.    if last_mark_line < first_screen_line then return 0; endif
  64.    if first_mark_line > last_screen_line then return 0; endif
  65.    no_char_overlap = marktype()<>'CHAR' or first_mark_line=last_mark_line
  66.    if last_mark_col < .col - .cursorx + 1 and
  67.       (no_char_overlap or last_mark_line=first_screen_line)
  68.    then return 0; endif
  69.    if first_mark_col > .col - .cursorx + .windowwidth and
  70.       (no_char_overlap or first_mark_line=last_screen_line)
  71.    then return 0; endif
  72.    return 1
  73.  
  74. ; Tests whether the "filename" is actually a printer
  75. ; device, so we'll know whether to test printer readiness first.
  76. ; Called by savefile() in SAVELOAD.E.  Returns 0 if not, else printer number.
  77. defproc check_for_printer(name)
  78.    if not name then return 0; endif
  79. compile if EVERSION >= '5.50'
  80.    if leftstr(name,1)='"' & rightstr(name,1)='"' then
  81.       name=substr(name,2,length(name)-2)
  82.    endif
  83. compile endif
  84. compile if EVERSION >= '5.17'
  85.    if rightstr(name,1) = ':' then  -- a device
  86.       name = leftstr(name,length(name)-1)
  87. compile else
  88.    if substr(name,length(name),1) = ':' then  -- a device
  89.       name = substr(name,1,length(name)-1)
  90. compile endif
  91.    else       -- Might be a full pathspec, C:\EDIT\PRN, and still go to a device!
  92.       indx = lastpos('\',name)
  93.       if not indx then indx = lastpos(':',name) endif
  94.       if indx then name=substr(name,indx+1) endif
  95.       indx = pos('.',name)
  96.       if indx then name=substr(name,1,indx-1) endif
  97.    endif
  98.    if upcase(name)='PRN' then return 1; endif
  99. compile if EVERSION >= 4  -- Check_for_printer always returns true, so we don't need to distinguish COMn.
  100.    return (4+pos('.'upcase(name)'.','.LPT1.LPT2.LPT3.LPT4.LPT5.LPT6.LPT7.LPT8.LPT9.COM1.COM2.COM3.COM4.')) % 5
  101. compile else
  102.    return (4+pos('.'upcase(name)'.','.LPT1.LPT2.LPT3.')) % 5
  103. compile endif
  104.  
  105. compile if WANT_WINDOWS
  106. ; This proc is called only by DEFC EDIT in messy-desk mode.
  107. defproc create_window_for_each_file(emptyfileid)
  108.    fileidlist=''
  109.    activatefile emptyfileid /* Start list at beginning so we get 'em all.    */
  110.    nextfile                 /* Except first one, can leave one in each ring. */
  111.    loop
  112.       nextfile
  113.       .box=1
  114.       getfileid fileid
  115.       if fileid=emptyfileid then
  116.          leave
  117.       endif
  118.       fileidlist=fileidlist fileid
  119.    endloop
  120.    rest=fileidlist
  121.    loop
  122.       parse value rest with fileid rest
  123.       if fileid='' then
  124.          leave
  125.       endif
  126.       rc=0
  127.       newwindow fileid
  128.       if rc then leave endif
  129.       getfileid cur_fileid
  130.       activatefile fileid
  131.       quitview
  132.       activatefile cur_fileid
  133.    endloop
  134. compile endif
  135.  
  136.  
  137. COMPILE IF EVERSION >= 4
  138. defproc dec_to_string(string)    -- for dynalink usage
  139.    line = ''
  140.    for i = 1 to length(string)
  141.      line= line || asc(substr(string,i,1)) || ' '
  142.    endfor
  143.    return line
  144. COMPILE ENDIF
  145.  
  146. defproc default_printer
  147. compile if defined(my_printer)
  148.    return MY_PRINTER
  149. compile elseif EPM
  150.    parse value queryprofile(HINI_PROFILE, 'PM_SPOOLER', 'PRINTER') with printername ';'
  151.    if printername<>'' then
  152.       parse value queryprofile(HINI_PROFILE, 'PM_SPOOLER_PRINTER', printername) with dev ';'
  153.       if dev<>'' then return dev; endif
  154.    endif
  155. compile endif
  156.    return 'LPT1'
  157.  
  158. ;  Returns DOS version number, multiplied by 100 so we can treat
  159. ;  it as an integer string.  That is, DOS 3.2 is reported as "320".
  160. ;  Needed by DEFPROC SUBDIR.
  161.  
  162. defproc dos_version()
  163. compile if E3
  164.    parse value int86x(DOS_INT,DOS_GET_VERSION,'') with ax .
  165.    major = ax // 256                  /* AL = major version number */
  166. ;  minor = (ax - major) % 256
  167.    return 100*major + (ax - major) % 256
  168. compile elseif EPM32
  169.       verbuf = copies(\0,8)
  170.       res= dynalink32('DOSCALLS',          /* dynamic link library name */
  171.                      '#348',              /* ordinal for DOS32QuerySysInfo */
  172.                      atol(11)         ||  -- Start index (Major version number)
  173.                      atol(12)         ||  -- End index (Minor version number)
  174.                      address(verbuf)  ||  -- buffer
  175.                      atol(8),2)           -- Buffer length
  176. ;     major = ltoa(leftstr(verbuf,4),10)
  177. ;     minor = ltoa(rightstr(verbuf,4),10)
  178.       return 100*ltoa(leftstr(verbuf,4),10) + ltoa(rightstr(verbuf,4),10)
  179. compile else
  180.       verbuf = 'nn'
  181.       res= dynalink('DOSCALLS',          /* dynamic link library name */
  182.                     '#92',               /* ordinal for DOSGETVERSION */
  183.                     address(verbuf))
  184. ;     major = asc(substr(verbuf,2,1))
  185. ;     minor = asc(substr(verbuf,1,1))
  186.       return 100*asc(substr(verbuf,2,1)) + asc(substr(verbuf,1,1))
  187. compile endif
  188.  
  189.  
  190. compile if WANT_ET_COMMAND     -- Let user omit ET command.
  191. defproc ec_position_on_error(tempfile)   /* load file containing error */
  192.    'xcom e 'tempfile
  193.    if rc then    -- Unexpected error.
  194.       sayerror ERROR_LOADING__MSG tempfile
  195.       if rc=-282 then 'xcom q'; endif  -- sayerror('New file')
  196.       return
  197.    endif
  198.    if .last<=4 then
  199.       getline msg,.last
  200.       'xcom q'
  201.    else
  202.       getline msg,2
  203. compile if EPM
  204.       if leftstr(msg,3)='(C)' then  -- 5.20 changed output
  205.          getline msg,4
  206.       endif
  207. compile endif
  208.       getline temp,.last
  209.       parse value temp with 'col= ' col
  210.       getline temp,.last-1
  211.       parse value temp with 'line= ' line
  212.       getline temp,.last-2
  213.       parse value temp with 'filename=' filename
  214.       'xcom q'
  215.       'e 'filename               -- not xcom here, respect user's window style
  216.       if line<>'' and col<>'' then
  217. compile if EPM
  218.          .cursory=min(.windowheight%2,.last)
  219. compile else
  220.          .cursory=15
  221. compile endif
  222.          if col>0 then
  223.             .col=col
  224.             line
  225.          else
  226.             .line=line-1   /* sometimes the compiler is off by 1 */
  227.             getline s
  228.             .col=length(s) /* position cursor at end of previous line */
  229.          endif
  230.       endif
  231.    endif
  232.    sayerror msg
  233. compile endif
  234.  
  235. defproc einsert_line
  236.    insert
  237.    up
  238.    getline line
  239.    parse value pmargins() with leftcol . paracol .
  240.    if line='' or not .line then
  241.       .col=paracol
  242.    else
  243.       call pfirst_nonblank()
  244.       if .col=paracol then .col=leftcol; endif
  245.    endif
  246.    down
  247.  
  248. compile if ENHANCED_ENTER_KEYS
  249. defproc enter_common(action)
  250.  compile if WANT_CUA_MARKING = 'SWITCH'
  251.    universal CUA_marking_switch
  252.  compile endif
  253.  compile if WANT_STREAM_MODE = 'SWITCH'
  254.    universal stream_mode
  255.    if stream_mode then
  256.  compile endif
  257.  compile if WANT_STREAM_MODE
  258.       if .line then
  259.   compile if WANT_CUA_MARKING
  260.    compile if WANT_CUA_MARKING = 'SWITCH'
  261.          if CUA_marking_switch then
  262.    compile endif
  263.             if not process_mark_like_cua() and   -- There was no mark
  264.                not insert_state() then           -- & we're in replace mode
  265.                delete_char    -- Delete the character, to emulate replacing the
  266.             endif             -- marked character with a newline.
  267.    compile if WANT_CUA_MARKING = 'SWITCH'
  268.          endif
  269.    compile endif
  270.   compile endif  -- WANT_CUA_MARKING
  271.   compile if WANT_STREAM_INDENTED
  272.          call splitlines()
  273.          call pfirst_nonblank()
  274.          down
  275.   compile else
  276.          split
  277.          .col=1
  278.          down
  279.   compile endif -- WANT_STREAM_INDENTED
  280.       else
  281.          insert
  282.          .col=1
  283.       endif
  284.       return
  285.  compile endif  -- WANT_STREAM_MODE
  286.  compile if WANT_STREAM_MODE = 'SWITCH'
  287.    endif
  288.  compile endif
  289.  compile if WANT_STREAM_MODE <> 1
  290.    is_lastline = .line=.last
  291.    if is_lastline  & (action=3 | action=5) then  -- 'ADDATEND' | 'DEPENDS+'
  292.       call einsert_line()
  293.       down                       -- This keeps the === Bottom === line visible.
  294.       return
  295.    endif
  296. ;     'NEXTLINE' 'ADDATEND'                        'DEPENDS'  'DEPENDS+'
  297.    if action=2 | action=3 | (not insert_state() & (action=4 | action=5)) then
  298.       down                          -- go to next line
  299.       begin_line
  300.       return
  301.    endif
  302.    if action=6 then
  303.       call splitlines()
  304.       call pfirst_nonblank()
  305.       down
  306. ;;    refresh
  307.       return
  308.    endif
  309.    if action=7 | action=8 then
  310.       insert
  311.       parse value pmargins() with leftcol . paracol .
  312.       if textline(.line-1)='' or .line=1 or action=8 then
  313.          .col=paracol
  314.       else
  315.          .col=leftcol
  316.       endif
  317.       if is_lastline then down; endif  -- This keeps the === Bottom === line visible.
  318.       return
  319.    endif
  320.    if action=9 then
  321.       insert
  322.       begin_line
  323.       if is_lastline then down; endif  -- This keeps the === Bottom === line visible.
  324.       return
  325.    endif
  326.    call einsert_line()           -- insert a line
  327.    if is_lastline then down; endif  -- This keeps the === Bottom === line visible.
  328.  compile endif  -- WANT_STREAM_MODE <> 1
  329. compile endif
  330.  
  331. ;  Erasetemp erases a file quietly (no "File not found" message) on both DOS
  332. ;  and OS/2.  Thanks to Larry Margolis.  Returns 0 if successful erase, or
  333. ;  the error code (if on DOS) which will usually be 2 for 'file not found'.
  334. defproc erasetemp(filename)
  335.    asciiz = filename\0
  336. compile if E3
  337.    call free()    -- Keep variables from moving around before int86x.
  338.    parse value int86x(DOS_INT,DOS_UNLINK 0 0 ofs(asciiz), seg(asciiz)) with ax . . . . . cf ',' .
  339.    -- Most callers will ignore error code, don't care file doesn't exist.
  340.    -- if cf then sayerror 'DOS error code' ax endif
  341.    if cf then return ax; endif
  342. compile elseif EPM32
  343.    return dynalink32('DOSCALLS',          /* dynamic link library name */
  344.                     '#259',               /* ordinal value for DOSDELETE */
  345.                     address(asciiz) )
  346. compile else
  347.    return dynalink('DOSCALLS',          /* dynamic link library name */
  348.                    '#60',               /* ordinal value for DOSDELETE */
  349.                    address(asciiz) ||
  350.                    atoi(0)         ||   /* reserved                  */
  351.                    atoi(0))             /* reserved                  */
  352. compile endif
  353.  
  354. compile if EPM
  355. defproc find_token(var startcol, var endcol)  -- find a token around the cursor.
  356.    if arg(3)='' then
  357.       token_separators = ' ~`!%^&*()-+=][{}|\:;?/><,''"'\t
  358.    else
  359.       token_separators = arg(3)
  360.    endif
  361.    if arg(4)='' then
  362.       diads = '-> ++ -- << >> <= >= && || += -= *= /= %= ¬= &= |= :: /* */'
  363.    else
  364.       diads = arg(4)
  365.    endif
  366.    getline line
  367.    len = length(line)
  368.    if .col>len | pos(substr(line, .col, 1), ' '\t) then
  369.       return  -- Past end of line, or over whitespace
  370.    endif
  371.    endcol = verify(line, token_separators, 'M', .col)
  372.    if endcol = .col then  -- On an operator.
  373.       startcol = endcol
  374.       if wordpos(substr(line, startcol, 2), diads) then
  375.          endcol = endcol + 1  -- On first character
  376.       elseif .col > 1 then
  377.          if wordpos(substr(line, endcol-1, 2), diads) then
  378.             startcol = startcol - 1  -- -- On last character
  379.          endif
  380.       endif
  381.       return 2
  382.    endif
  383.    if endcol then
  384.       endcol = endcol - 1
  385.    else
  386.       endcol = len
  387.    endif
  388.    startcol = verify(reverse(line), token_separators, 'M', len - .col + 1)
  389.    if startcol then
  390.       startcol = len - startcol + 2
  391.    else
  392.       startcol = 1
  393.    endif
  394.    return 1
  395. compile endif
  396.  
  397. ; Note on a speed trick:  The following routine is used to both verify that
  398. ; an external program exists, and to get its path.  After that first search,
  399. ; the exact path location of the routine is known; it can be remembered so that
  400. ; all future calls can supply the exact location to avoid the path search.
  401. ; See SUBDIR for an example of its use.
  402.  
  403. defproc find_routine(utility)  -- Split from SUBDIR
  404.    parse arg util opts         -- take first word, so can pass options too.
  405.    findfile fully_qualified,util,'PATH','P'
  406.    if rc then return -1 endif
  407. compile if E3
  408.    if dos_version() < 300 then
  409.       return utility             --DOS 2 can't handle the path
  410.    endif                         --in front of the command.
  411. compile endif
  412.    return fully_qualified opts
  413.  
  414. compile if EVERSION >='5.50'    -- For GPI version, we must manage the cursor ourself
  415. defproc fixup_cursor()
  416.  compile if DYNAMIC_CURSOR_STYLE
  417.    universal cursordimensions
  418.    parse value word(cursordimensions, insert_state()+1) with cursorw '.' cursorh
  419.  compile else
  420.   compile if UNDERLINE_CURSOR
  421.    cursorh = 3 - 67*insert_state()         -- 0 -> 3; 1 -> -64
  422.    cursorw = '-128'
  423.   compile else
  424.    cursorw = 2 - 130*(not insert_state())  -- 0 -> -128; 1 -> 2
  425.    cursorh = '-128'
  426.   compile endif
  427.  compile endif
  428.    cursor_dimensions cursorw, cursorh
  429. compile endif
  430.  
  431. ; Highlight a "hit" after a Locate command or Repeat_find operation
  432. compile if defined(HIGHLIGHT_COLOR)
  433. defproc highlight_match(search_len)
  434.    if not rc then
  435.  compile if EVERSION < '5.50'
  436.       refresh
  437.       sayat '', .cursory, .cursorx, HIGHLIGHT_COLOR, min(search_len, .windowwidth - .cursorx + 1)
  438.  compile elseif EVERSION >= '6.02'
  439.       col = getpminfo(EPMINFO_SEARCHPOS)
  440.       circleit LOCATE_CIRCLE_STYLE, .line, col, col+getpminfo(EPMINFO_LSLENGTH)-1, LOCATE_CIRCLE_COLOR1, LOCATE_CIRCLE_COLOR2
  441.  compile elseif EVERSION >= '5.60'
  442.       circleit LOCATE_CIRCLE_STYLE, .line, .col, .col+getpminfo(EPMINFO_LSLENGTH)-1, LOCATE_CIRCLE_COLOR1, LOCATE_CIRCLE_COLOR2
  443.  compile elseif EVERSION >= '5.51'
  444.       circleit LOCATE_CIRCLE_STYLE, .line, .col, .col+getpminfo(EPMINFO_LSLENGTH)-1, HIGHLIGHT_COLOR
  445.  compile else
  446.       circleit LOCATE_CIRCLE_STYLE, .line, .col, .col+search_len-1, HIGHLIGHT_COLOR
  447. ;     refresh
  448.  compile endif
  449.    endif
  450. compile endif
  451.  
  452. compile if EVERSION < 5
  453. defproc init_operation_on_commandline
  454.    universal comsfileid,oldline
  455.    if command_state() then
  456.       activatefile comsfileid
  457.       oldline=.line
  458.       getcommand line,col,scrollpos
  459.       insertline line,.last+1
  460.       .cursorx=col-scrollpos+1
  461.       .col=col
  462.       bottom
  463.    endif
  464. compile endif
  465.  
  466. ; Returns true if parameter given is a number.
  467. ; Leading and trailing spaces are ignored.
  468. defproc isnum
  469.    zzi=pos('-',arg(1))           -- Optional minus sign?
  470.    if zzi then                   -- If there is one,
  471.       parse arg zz1 '-' zz zz2   --   zz1 <- before it, zz <- number, zz2 <- after
  472.    else
  473.       parse arg zz zz1 zz2       --   zz <- number; zz1, zz2 <- after it
  474.    endif
  475.    zz=strip(zz)                  -- Delete leading & trailing spaces.
  476.    if zz1||zz2 <> '' or          -- If there were more tokens on the line
  477.       zz==''                     -- or if the result is null
  478.    then return 0 endif           -- then not a number.
  479. compile if EVERSION >= 4         -- OS/2 version - real numbers
  480.    if pos(DECIMAL,zz) <> lastpos(DECIMAL,zz) then return 0 endif
  481.                                  -- Max. of one decimal point.
  482.    return not verify(zz,'0123456789'DECIMAL)
  483. compile else                        -- DOS version - integers only
  484.    return not verify(zz,'0123456789')
  485. compile endif
  486.  
  487. defproc isoption(var cmdline,optionletter)
  488.    i=pos(argsep||upcase(optionletter),upcase(cmdline))
  489.    if i then
  490. compile if EPM
  491.       cmdline=delstr(cmdline,i,2)
  492. compile else
  493.       cmdline=substr(cmdline,1,i-1)||substr(cmdline,i+2)
  494. compile endif
  495.       return 1
  496.    endif
  497.  
  498. defproc joinlines()
  499.    if .line<.last and .line then
  500. compile if EPM           -- Can't use REPLACELINE because it wipes out attributes.
  501.       oldcol = .col
  502.       down                   -- ensure one space at start of second line
  503.       call pfirst_nonblank()
  504.       col2 = .col
  505.       .col = 1
  506.       getsearch savesearch
  507.       if col2 > 2 then       -- Shift line left
  508.          'xcom c/'copies(' ',col2-2)'//'  -- Change first n-1 blanks to null
  509.       elseif col2=1 then     -- Shift line right
  510. ;        'xcom c/^/ /g'         -- insert a space at beginning of line
  511.          i=insert_state()
  512.          if not i then insert_toggle endif
  513.          keyin ' '
  514.          if not i then insert_toggle endif
  515.       endif
  516.       setsearch savesearch
  517.       up                     -- ensure no spaces at end of first line
  518.       .col = length(strip(textline(.line),'T')) + 1
  519.       erase_end_line
  520.       .col = oldcol
  521. compile else           -- E3 and EOS2 can still use the old, simple way.
  522.       /* remove all but one trailing space of current line */
  523.       getline line
  524.       replaceline strip(line,'T')' '
  525.       /* remove all leading spaces of next line */
  526.       getline line,.line+1
  527.       replaceline strip(line),.line+1
  528. compile endif
  529.       join
  530.    endif
  531.  
  532. compile if EVERSION < 5
  533. defproc leave_last_command
  534.    if (not arg() or arg(2)) and arg(1) then
  535.       cursor_command
  536.       up
  537.       for i = 1 to arg(1)-1
  538.          right
  539.       endfor
  540.    endif
  541. compile endif
  542.  
  543. compile if EVERSION < '5.17'  -- Provide leftstr() macro for easier back-porting of EPM macros
  544. defproc leftstr(argstring, len)
  545.    return substr(argstring, 1, len, substr(arg(3),1,1))
  546. compile endif
  547.  
  548. compile if WANT_LAN_SUPPORT
  549. defproc lock
  550.    file=.filename\0
  551.  compile if EPM32
  552.    newhandle='????'
  553.    actiontaken=atol(1)   -- File exists
  554.    result = dynalink32('DOSCALLS',
  555.                       '#273',                     /* dos32open          */
  556.                       address(file)         ||
  557.                       address(newhandle)    ||
  558.                       address(actiontaken)  ||
  559.                       atol(0)    ||       -- file size
  560.                       atol(0)    ||       -- file attribute
  561.                       atol(17)   ||       -- open flag; open if exists, else create
  562.                       atol(146)  ||       -- openmode; deny Read/Write
  563.                       atol(0),2)
  564.  compile else
  565.    newhandle='??'
  566.    actiontaken=atoi(1)   -- File exists
  567.    result = dynalink('DOSCALLS',
  568.                      '#70',                     /* dosopen          */
  569.                      address(file)        ||
  570.                      address(newhandle)   ||
  571.                      address(actiontaken) ||
  572.                      atol(0)              || -- file size
  573.                      atoi(0)              || -- file attribute
  574.                      atoi(17)             || -- open flag; open if exists, else create
  575.                      atoi(146)            || -- openmode; deny Read/Write
  576.                      atol(0))
  577.  compile endif
  578.    if result then
  579. ;     'quit'  /* quit since the file could not be locked */
  580.       messageNwait('DOSOPEN' ERROR__MSG result NOT_LOCKED__MSG)
  581.       return result
  582.    endif
  583.  compile if EPM32
  584.    if newhandle = \0\0\0\0 then  -- Handle of 0 - bad news
  585.       newhandle2=\255\255\255\255
  586.       result = dynalink32('DOSCALLS',
  587.                          '#260',                     /* Dos32DupHandle     */
  588.                          newhandle ||
  589.                          address( newhandle2 ), 2)
  590.       call dynalink32('DOSCALLS',    -- Free the original handle
  591.                      '#257',                    -- dos32close
  592.                      newhandle, 2)
  593.       if result then
  594.          messageNwait('DosDupHandle' ERROR__MSG result NOT_LOCKED__MSG)
  595.          return result
  596.       endif
  597.       newhandle = newhandle2
  598.    endif
  599.    .lockhandle=ltoa(newhandle,10)
  600.  compile else
  601.    if newhandle = \0\0 then  -- Handle of 0 - bad news
  602.       newhandle2=atoi(65535)
  603.       result = dynalink('DOSCALLS',
  604.                         '#61',                     /* DosDupHandle     */
  605.                         newhandle ||
  606.                         address( newhandle2 ))
  607.       call dynalink('DOSCALLS',    -- Free the original handle
  608.                     '#59',                    -- dosclose
  609.                     newhandle)
  610.       if result then
  611.          messageNwait('DosDupHandle' ERROR__MSG result NOT_LOCKED__MSG)
  612.          return result
  613.       endif
  614.       newhandle = newhandle2
  615.    endif
  616.    .lockhandle=itoa(newhandle,10)
  617.  compile endif
  618. compile endif
  619.  
  620. defproc max(a,b)  -- Support as many arguments as E3 will allow.
  621.    maximum=a
  622.    do i=2 to arg()
  623.       if maximum<arg(i) then maximum=arg(i); endif
  624.    end
  625.    return maximum
  626.  
  627. compile if E3
  628. definit  /* Keep this definit close to the proc it serves. */
  629.    universal lines_entered
  630.    lines_entered=0
  631.  
  632. defproc maybe_autosave    -- For E3 users, this routine increments the autosave
  633.    universal autosave,lines_entered  -- counter, and does an autosave if necessary.
  634.    if autosave then
  635.       lines_entered = lines_entered +1
  636.       if lines_entered >= autosave then
  637.          'xcom save' MakeTempName()  -- Don't worry about HPFS files in E3.
  638.          if rc=-2  then  -- sayerror('File not found') -> Invalid filename
  639.             'xcom save' MakeTempName('BAD-NAME')
  640.          endif
  641.          .modify=1                  /* Reraise the modify flag. */
  642.          lines_entered =0
  643.       endif
  644.    endif
  645. compile endif
  646.  
  647.  
  648. compile if BACKUP_PATH <> ''
  649. ;  Procedure to pick a filename for backup purposes, like STDPROCS.E$.
  650. defproc MakeBakName
  651.    name = arg(1)
  652.    if name = '' then   /* if no arg given, default to current filename */
  653.       name = .filename
  654.    endif
  655.    -- Change name as little as possible, but enough to identify it as
  656.    -- a noncritical file.  Replace the last character with '$'.
  657.    ext = filetype(name)
  658.    if length(ext)=3 then
  659.       ext = substr(ext,1,2)'$'
  660.    else
  661.       ext = ext'$'
  662.    endif
  663.    -- We still use MakeTempName() for its handling of host names.
  664.    bakname = MakeTempName(name)
  665.    i=lastpos('\',bakname)       -- but with a different directory
  666.    if i then
  667.       bakname = substr(bakname,i+1)
  668.    endif
  669.    parse value bakname with fname'.'.
  670.  compile if BACKUP_PATH = '='
  671.    bakname = fname'.'ext
  672.    i=lastpos('\',name)       -- Use original file's directory
  673.    if i then
  674.       bakname = substr(name,1,i) || bakname
  675.    endif
  676.  compile else
  677.    bakname = BACKUP_PATH || fname'.'ext
  678.  compile endif
  679.    return bakname
  680. compile endif
  681.  
  682.  
  683. ;  Procedure to pick a temporary filename like ORIGNAME.$$1.
  684. ;  First argument is the filename, 2nd is the fileid.  Both are optional,
  685. ;  default to the current filename and fileid if absent.
  686. ;  Revised by BTTUCKER to catch all cases and work with E3EMUL.
  687. defproc MakeTempName
  688.    universal vAUTOSAVE_PATH
  689.    TempName  = arg(1)
  690.    extension = arg(2)
  691.    if TempName = '' then   /* if no arg given, default to current filename */
  692.       TempName = .filename
  693.    endif
  694.    if TempName = '' then
  695.       TempName = '$'       /* new file? o.k. then $  */
  696.    else /* We want only PC file name, VM filename, or MVS firstname          */
  697.         /* These next statements will strip everything else off...           */
  698.      p = lastpos('\',TempName)                      /* PC filename with path */
  699.      if p then TempName=substr(TempName,p+1) endif
  700.      p = pos('.',TempName)                          /* PC or MVS filename    */
  701.      if p then TempName=substr(TempName,1,p-1) endif
  702.      p = pos(' ',TempName)                          /* VM filename (or HPFS) */
  703.      if p then TempName=substr(TempName,1,p-1) endif
  704.      p = pos(':',TempName)                          /* VM or MVS filename    */
  705.      if p then TempName=substr(TempName,p+1) endif
  706.      p = pos("'",TempName)                          /* MVS filename          */
  707.      if p then TempName=substr(TempName,p+1) endif
  708.      if length(tempname)>8 then tempname=substr(tempname,1,8); endif  /* HPFS names */
  709.    endif
  710.  
  711.    -- TempName might still be blank, as for '.Unnamed file'.
  712.    if TempName='' then TempName='$'; endif
  713.  
  714.    TempName = vAUTOSAVE_PATH || TempName
  715.    if extension='' then            /* default is current fileid              */
  716.       getfileid extension
  717.    endif
  718. compile if EVERSION < 5
  719.    extension = '$$' || extension
  720. compile else
  721.    /* In EPM we can have the same filename in multiple edit windows without
  722.     * knowing it, because different edit windows are actually separate
  723.     * instances of the editor.  So try to make the tempname unique by
  724.     * combining the window handle with the fileid.  Combine two middle
  725.     * digits of the window handle with the last digit of the fileid.
  726.     */
  727.    extension = substr(getpminfo(EPMINFO_EDITCLIENT),2,2) || extension
  728. compile endif
  729.    if length(extension)>3 then     /* could be >one digit, or something else */
  730.       extension=substr(extension,2,3)
  731.    endif
  732.    return TempName'.'extension
  733.  
  734. defproc message
  735.    getfileid fileid
  736.    sayerror arg(1)
  737.    activatefile fileid
  738.  
  739. ; Print message and wait for a key press.
  740. ; Preserve active file and activate ring.
  741. ; Note:  There is no need to use "call" to invoke this procedure,  since it
  742. ; returns the null string.  Execution of a null string does nothing
  743. defproc messageNwait
  744.    getfileid zzfileid
  745. compile if EPM
  746.    display -4                    -- Force a messagebox popup from the SAYERROR
  747.  compile if EVERSION >= '5.60b'
  748.    display 32                    -- Force a messagebox popup from the SAYERROR
  749.  compile endif
  750. compile endif
  751.    sayerror arg(1)
  752. compile if EVERSION < 5
  753.    call getkey()
  754. compile else
  755.  compile if EVERSION >= '5.60b'
  756.    display -32
  757.  compile endif
  758.    display 4
  759. compile endif
  760.    activatefile zzfileid
  761.  
  762. compile if EVERSION < 5
  763. ; Mgetkey() acts the same as a call to getkey(), but first checks
  764. ; whether we're in mid-execution of a key-string (Ctrl-R/Ctrl-T).
  765. ; If so it gets the next key from the string.  Call this in place of
  766. ; getkey() if you want the user to be able to record the response.
  767. ; Don't call this for unusual inputs, such as messageNwait after errors.
  768.  
  769. ; Optional argument is prompt string, will be displayed on status line.
  770.  
  771. defproc mgetkey()
  772.    universal Kstring,inKstring          /* See c_r in STDKEYS.E. */
  773.    prompt=arg(1)
  774.    if prompt<>'' and inKstring<=0 then
  775.       sayerror prompt
  776.    endif
  777.    if inKstring=0 then     /* If not recording or replaying, normal input. */
  778.       k=getkey()
  779.    elseif inKstring=-1 then /* If recording, stash key in string.          */
  780.       k=getkey()
  781.       Kstring=Kstring||k   /* Trust that it doesn't get longer than 255.   */
  782.    else           /* inKstring>0 ==> replaying; get next key from Kstring. */
  783.       k=substr(Kstring,inKstring,1)
  784.       ksize=1
  785.       if k==substr(esc,1,1) then       /* extended key ? */
  786.          k=substr(Kstring,inKstring,2) /* Yes, 2 bytes for extended key.   */
  787.          ksize=2
  788.       endif
  789.       inKstring=inKstring+ksize        /* bump index AFTER execution */
  790.    endif
  791.    if prompt<>'' and inKstring<=0 then
  792.       sayerror 0
  793.    endif
  794.    return k
  795. compile endif
  796.  
  797. defproc min(a,b)  -- Support as many arguments as E3 will allow.
  798.    minimum=a
  799.    do i=2 to arg()
  800.       if minimum>arg(i) then minimum=arg(i); endif
  801.    end
  802.    return minimum
  803.  
  804. compile if EVERSION < 5
  805. defproc move_results_to_commandline
  806.    universal oldline
  807.    if command_state() then
  808.       getline line
  809.       deleteline
  810.       setcommand line,.col,.col-.cursorx+1
  811.       oldline
  812.    endif
  813. compile endif
  814.  
  815. ; The following two routines (from Larry Margolis) let the
  816. ; user decide what action should be taken when the Enter and Ctrl-Enter
  817. ; keys are pressed.  The possible values for the action constants are
  818. ; defined in STDCNF.
  819.  
  820. compile if C_ENTER_ACTION & not ENHANCED_ENTER_KEYS  -- If null, don't define - user will supply.
  821. defproc my_c_enter
  822.    compile if C_ENTER_ACTION = 'ADDATEND' | C_ENTER_ACTION = 'DEPENDS+'
  823.    if .line = .last then         -- If we're on the last line, then add a line.
  824. compile if EVERSION < '4.12'
  825.       call maybe_autosave()
  826. compile endif
  827.       call einsert_line()
  828.       down                       -- This keeps the === Bottom === line visible.
  829.    else
  830.    compile endif
  831.  
  832.    compile if C_ENTER_ACTION = 'DEPENDS' | C_ENTER_ACTION = 'DEPENDS+'
  833.    if insert_state() then        -- DEPENDS means if insertstate() then ...
  834.    compile endif
  835.  
  836.    compile if C_ENTER_ACTION = 'NEXTLINE' | C_ENTER_ACTION = 'DEPENDS' |
  837.               C_ENTER_ACTION = 'ADDATEND' | C_ENTER_ACTION = 'DEPENDS+'
  838.    down                          -- go to next line
  839.    begin_line
  840.    compile endif
  841.  
  842.    compile if C_ENTER_ACTION = 'DEPENDS' | C_ENTER_ACTION = 'DEPENDS+'
  843.    else                          -- otherwise ...
  844.    compile endif
  845.  
  846.    compile if C_ENTER_ACTION = 'ADDLINE' | C_ENTER_ACTION = 'DEPENDS' | C_ENTER_ACTION = 'DEPENDS+'
  847. compile if EVERSION < '4.12'
  848.    call maybe_autosave()
  849. compile endif
  850.    call einsert_line()           -- insert a line
  851.    compile endif
  852.  
  853.    compile if C_ENTER_ACTION = 'DEPENDS' | C_ENTER_ACTION='ADDATEND' | C_ENTER_ACTION = 'DEPENDS+'
  854.    endif
  855.    compile endif
  856.  
  857.    compile if C_ENTER_ACTION = 'DEPENDS+'
  858.    endif
  859.    compile endif
  860.  
  861.    compile if C_ENTER_ACTION = 'STREAM'
  862.    call splitlines()
  863.    call pfirst_nonblank()
  864.    down
  865.     compile if EPM
  866.    refresh
  867.     compile endif
  868.    compile endif
  869. compile endif
  870.  
  871. compile if not ENHANCED_ENTER_KEYS & ENTER_ACTION   -- If null, don't define - user will supply.
  872. defproc my_enter
  873.  compile if WANT_STREAM_MODE = 'SWITCH'
  874.    universal stream_mode
  875.  compile endif
  876.  compile if EVERSION < 5
  877.    if command_state() then
  878.       execute
  879.  compile else
  880.    if 0 then   -- EPM has no command_state()
  881.  compile endif
  882.  compile if WANT_STREAM_MODE = 'SWITCH'
  883.    elseif stream_mode then
  884.  compile endif
  885.  compile if WANT_STREAM_MODE
  886.       if .line then
  887.   compile if WANT_STREAM_INDENTED
  888.          call splitlines()
  889.          call pfirst_nonblank()
  890.          down
  891.   compile else
  892.          split
  893.          .col=1
  894.          down
  895.   compile endif -- WANT_STREAM_INDENTED
  896.       else
  897.          insert
  898.          .col=1
  899.       endif
  900.       return
  901.  compile endif
  902.  compile if WANT_STREAM_MODE <> 1
  903.  compile if ENTER_ACTION = 'ADDATEND' | ENTER_ACTION = 'DEPENDS+'
  904.    elseif .line = .last then     -- If we're on the last line, then add a line.
  905. compile if EVERSION <= '4.12'
  906.       call maybe_autosave()
  907. compile endif
  908.       call einsert_line()
  909.       down                       -- This keeps the === Bottom === line visible.
  910.  compile endif
  911.    else
  912.       compile if ENTER_ACTION = 'DEPENDS' | ENTER_ACTION = 'DEPENDS+'
  913.       if insert_state() then     -- DEPENDS means if insertstate() then ...
  914.       compile endif
  915.  
  916.       compile if ENTER_ACTION = 'ADDLINE' | ENTER_ACTION = 'DEPENDS' | ENTER_ACTION = 'DEPENDS+'
  917. compile if EVERSION < '4.12'
  918.       call maybe_autosave()
  919. compile endif
  920.       call einsert_line()        -- insert a line
  921.       compile endif
  922.  
  923.       compile if ENTER_ACTION = 'DEPENDS' | ENTER_ACTION = 'DEPENDS+'
  924.       else                       -- otherwise ...
  925.       compile endif
  926.  
  927.       compile if ENTER_ACTION = 'NEXTLINE' | ENTER_ACTION = 'DEPENDS' |
  928.                  ENTER_ACTION = 'ADDATEND' | ENTER_ACTION = 'DEPENDS+'
  929.       down                       -- go to next line
  930.       begin_line
  931.       compile endif
  932.  
  933.       compile if ENTER_ACTION = 'DEPENDS' | ENTER_ACTION = 'DEPENDS+'
  934.       endif
  935.       compile endif
  936.  
  937.       compile if ENTER_ACTION = 'STREAM'
  938.       if .line then
  939.          if .col<=length(textline(.line)) then
  940.             split
  941.             .col=1
  942.          else
  943.             split
  944.             call pfirst_nonblank()
  945.          endif
  946.          down
  947.       else
  948.          insert
  949.          .col=1
  950.       endif
  951.        compile if EPM
  952.       refresh
  953.        compile endif
  954.       compile endif
  955.  compile endif  -- WANT_STREAM_MODE <> 1
  956.    endif
  957. compile endif
  958.  
  959.  
  960. ;  A common routine to parse an argument string containing a mix of
  961. ;  options and DOS file specs.  The DOS file specs can contain an "=" for the
  962. ;  path or the fileid, which will be replaced by the corresponding part of the
  963. ;  previous file (initially, the current filename).
  964. defproc parse_file_n_opts(argstr)
  965.    prev_filename = .filename
  966.    output = ''
  967.    do while argstr<>''
  968. compile if EVERSION >= '5.50'
  969.       parse value argstr with filename rest
  970.       if leftstr(filename,1)='"' then
  971.          parse value argstr with '"' filename '"' argstr
  972.          filename = '"'filename'"'
  973.       else
  974.          argstr = rest
  975.       endif
  976. compile else
  977.       parse value argstr with filename argstr
  978. compile endif
  979.       if substr(filename,1,1)<>'/' then
  980.          call parse_filename(filename,prev_filename)
  981.          prev_filename = filename
  982.       endif
  983.       output = output filename
  984.    end
  985.    return substr(output,2)
  986.  
  987. ;  A common routine to parse a DOS file name.  Optional second argument
  988. ;  gives source for = when used for path or fileid.  RC is 0 if successful, or
  989. ;  position of "=" in first arg if no second arg given but was needed.
  990. defproc parse_filename(var filename)
  991. compile if EVERSION >= '5.50'
  992.    if leftstr(filename,1)='"' & rightstr(filename,1)='"' then
  993.       return 0
  994.    endif
  995. compile endif
  996.    sourcefile = strip(arg(2))
  997.    if sourcefile='' then return pos('=',filename) endif
  998.  
  999.    if filename='=' then filename=sourcefile; return 0; endif
  1000.  
  1001.    lastsep = lastpos('\',sourcefile)
  1002.    if not lastsep & substr(sourcefile,2,1) = ':' then lastsep=2; endif
  1003.  
  1004.    /* E doesn't handle the = prefix if it's on the first file given on      */
  1005.    /* the E command line.  This replaces = with path of current file.  LAM  */
  1006.    if substr(filename,1,1) = '=' & lastsep then
  1007.       if substr(filename,2,1) = '.' & not pos('\', filename) then filename='='filename endif
  1008.       filename=substr(sourcefile,1,lastsep) || substr(filename,2)
  1009.    endif
  1010.  
  1011.    /* Also accept '=' after the pathspec, like 'c:\bat\=', */
  1012.    /* or c:\bat\=.bat or c:\doc\new.=                      */
  1013.    p = pos('=',filename)
  1014.    if p > 1 then
  1015.       sourcefileid=substr(sourcefile,max(lastsep+1,1))
  1016.       parse value sourcefileid with sourcefilename '.' sourcefileext
  1017.       lastsep2 = lastpos('\',filename)
  1018.       if not lastsep2 & substr(filename,2,1) = ':' then lastsep2=2; endif
  1019.       dot1=pos('.',filename,max(lastsep2,1))
  1020.       firstpart=substr(filename,1,p-1)
  1021.       if dot1 then
  1022.          if dot1<p then  -- filename.=
  1023.             filename= firstpart || sourcefileext
  1024.          else            -- =.ext
  1025.             filename= firstpart || sourcefilename || substr(filename,dot1)
  1026.          endif
  1027.       else            -- d:\path\         ||        filename.ext
  1028.          filename= firstpart || sourcefileid
  1029.       endif -- dot1
  1030.    endif -- p > 1
  1031.    return 0
  1032.  
  1033. ;  This proc is called by DEFC EDIT.
  1034. ;  Does *not* assume all options are specified before filenames.
  1035. defproc parse_leading_options(var rest,var options)
  1036.    options=''
  1037.    loop
  1038.       parse value rest with wrd more
  1039.       if substr(wrd,1,1)='/' then
  1040.          options = options wrd
  1041.          rest = more
  1042.       else
  1043.          leave
  1044.       endif
  1045.    endloop
  1046.  
  1047.  
  1048. ; PBEGIN_MARK: this procedure moves the cursor to the first character of the
  1049. ; mark area.  If the mark area is not in the active file, the marked file is
  1050. ; activated.
  1051. defproc pbegin_mark
  1052.    call checkmark()
  1053.    getmark  firstline,lastline,firstcol,lastcol,fileid
  1054.    activatefile fileid
  1055. compile if EVERSION < 5
  1056.    cursor_data
  1057. compile endif
  1058.    firstline
  1059.    if marktype()<>'LINE' then
  1060.       .col=firstcol
  1061.    endif
  1062.  
  1063.  
  1064. ; PBEGIN_WORD: moves the cursor to the beginning of the word if the cursor is on
  1065. ; this word.  If it's not on a word, it's moved to the beginning of the first
  1066. ; word on the left.  If there is no word on the left it's moved to the beginning
  1067. ; of the word on the right.  If the line is empty the cursor doesn't move.
  1068. defproc pbegin_word
  1069.    getline line,.line
  1070.    if  substr(line,.col,1)=' ' then
  1071.       p=verify(line,' ')       /* 1st case: the cursor on a space */
  1072.       if p>=.col then
  1073.          .col=p
  1074.       else
  1075.          if p then
  1076.             q=p
  1077.             loop
  1078.                p=verify(line,' ','M',p)
  1079.                if not p or p>.col then leave endif
  1080.                p=verify(line,' ','',p)
  1081.                if not p or p>.col then leave endif
  1082.                q=p
  1083.             endloop
  1084.             .col=q
  1085.          endif
  1086.       endif
  1087.    else
  1088.       if .col<>1 then          /* 2nd case: not on a space */
  1089.          .col=lastpos(' ',line,.col)+1
  1090.       endif
  1091.    endif
  1092.  
  1093.  
  1094. ; PBLOCK_REFLOW: reflow the text in the marked area.  Then the destination block
  1095. ; area must be selected and a second call to this procedure reflow the source
  1096. ; block in the destination block.  The source block is fill with spaces.
  1097. ;   option=0 saves the marked block in temp file
  1098. ;   option=1 reflow temp file text and copies it to marked area
  1099. defproc pblock_reflow(option,var spc,var tempofid)
  1100.    call checkmark()
  1101.    if not option then
  1102.       usedmk=marktype()
  1103.       getmark  firstline1,lastline1,firstcol1,lastcol1,fileid1
  1104.       /* move the source mark to a temporary file */
  1105. compile if EPM
  1106.       'xcom e /c .tempo'
  1107.       if rc<>sayerror('New file') then
  1108.          sayerror ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext(rc)
  1109.          return rc
  1110.       endif
  1111.       .visible = 0                                  -- Make hidden
  1112. compile else
  1113.       'xcom e 'argsep'q 'argsep'n 'argsep'h .tempo'
  1114.       if rc & rc<>sayerror('New file') then
  1115.          sayerror ERROR__MSG rc BAD_TMP_FILE__MSG
  1116.          return rc
  1117.       endif
  1118.       sayerror 1
  1119. compile endif
  1120.       getfileid tempofid
  1121.       activatefile tempofid
  1122.       call pcopy_mark()
  1123.       activatefile fileid1
  1124. compile if EVERSION < 5
  1125.       cursor_data
  1126. compile endif
  1127.       call pset_mark(firstline1,lastline1,firstcol1,lastcol1,usedmk,fileid1)
  1128.       if usedmk='LINE' then
  1129.          begin_line
  1130.       endif
  1131.       spc=usedmk firstline1 lastline1 firstcol1 lastcol1 fileid1
  1132.       return 0
  1133.    else
  1134.       getfileid startfid
  1135.       if marktype() <> 'BLOCK' then
  1136.          sayerror NEED_BLOCK_MARK__MSG
  1137.          /* release tempo */
  1138.          rc=0
  1139.          activatefile tempofid
  1140.          if rc then return rc; endif
  1141.          .modify=0
  1142.          'xcom q'
  1143.          activatefile startfid
  1144.          return 1
  1145.       endif
  1146. compile if EPM  -- Make sure temp file is good before deleting current file's text.
  1147.       rc=0
  1148.       activatefile tempofid
  1149.       if rc then return rc; endif
  1150.       activatefile startfid
  1151. compile endif
  1152.       parse value spc with usedmk firstline1 lastline1 firstcol1 lastcol1 fileid1
  1153.       getmark  firstline2,lastline2,firstcol2,lastcol2,fileid2
  1154.       /* fill source with space */
  1155.       if usedmk='LINE' then
  1156.          for i = firstline1 to lastline1
  1157.             replaceline '',i,fileid2
  1158.          endfor
  1159.       else
  1160.          call pset_mark(firstline1,lastline1,firstcol1,lastcol1,usedmk,fileid1)
  1161.          call pfill_mark(' ')
  1162.       endif
  1163.       call pset_mark(firstline2,lastline2,firstcol2,lastcol2,'BLOCK',fileid2)
  1164.       delete_mark
  1165.       /* let's reflow in the hidden file */
  1166.       activatefile tempofid
  1167.       width = lastcol2+1-firstcol2
  1168.       height = lastline2+1-firstline2
  1169. compile if EVERSION < '4.12'
  1170.       savemargins= pmargins()
  1171. compile endif
  1172.       'xcom ma 1 'width
  1173.       unmark; mark_line; bottom; mark_line
  1174.       reflow
  1175. compile if EVERSION < '4.12'
  1176.       'xcom ma 'savemargins
  1177. compile endif
  1178.       nbl = .last
  1179.       /* go back to the destination */
  1180.       activatefile fileid2
  1181.       if nbl > height then
  1182.          fix = nbl-height
  1183.          getline line,lastline2
  1184.          for i = 1 to fix
  1185.             insertline line,lastline2+1
  1186.          endfor
  1187.       elseif nbl < height then
  1188.          fix=0
  1189.          for i = nbl+1 to height
  1190.             insertline '',tempofid.last+1,tempofid
  1191.          endfor
  1192.          nbl=height
  1193.       else
  1194.          fix=0
  1195.       endif
  1196.       call pset_mark(1,nbl,1,width,'BLOCK',tempofid)
  1197.       firstline2; .col=firstcol2; copy_mark; unmark
  1198.       call pset_mark(firstline2,lastline2+fix,firstcol2,lastcol2,'BLOCK',fileid2)
  1199.       /* release tempo */
  1200.       activatefile tempofid
  1201.       .modify=0
  1202.       'xcom q'
  1203.       activatefile fileid2
  1204.       sayerror 1
  1205.     endif
  1206.  
  1207.  
  1208. ; PCENTER_MARK: center the strings between the block marks
  1209. defproc pcenter_mark
  1210.    if  marktype() = 'BLOCK' then
  1211.       getmark  firstline,lastline,firstcol,lastcol,fileid
  1212.    elseif marktype() = 'LINE' then
  1213.       getmark  firstline,lastline,firstcol,lastcol,fileid
  1214.       parse value pmargins() with  firstcol lastcol .
  1215.    elseif marktype() = '' then
  1216.       getfileid fileid
  1217.       parse value pmargins() with  firstcol lastcol .
  1218.       firstline=.line;lastline=.line
  1219.    else
  1220.       sayerror CHAR_INVALID__MSG
  1221.       stop
  1222.    endif
  1223.    sz = lastcol+1-firstcol
  1224.    for i=firstline to lastline
  1225.       getline line,i,fileid
  1226.       inblock=strip(substr(line,firstcol,sz))
  1227.       if inblock='' then iterate endif
  1228. compile if EPM
  1229.       replaceline strip(overlay(center(inblock, sz), line, firstcol),'T'), i, fileid
  1230. compile else
  1231.       replaceline substr(line,1,firstcol-1) ||
  1232.          substr(substr('',1,(sz-length(inblock))%2)||inblock,1,sz) ||
  1233.          substr(line,lastcol+1) ,i,fileid
  1234. compile endif
  1235.    endfor
  1236.  
  1237.  
  1238. compile if EVERSION < 5
  1239. ;  A built-in function command_state() is now provided for better
  1240. ;  efficiency.  This defproc is kept only for compatibility with older macros.
  1241. ;  Please use command_state() instead.
  1242. defproc pcommand_state
  1243.    return command_state()
  1244.  
  1245.  
  1246. ; PCOMMON_TAB_MARGIN: subroutine common to ptabs and pmargins
  1247.  
  1248. defproc pcommon_tab_margin(TabOrMargins)
  1249. ;    the tricky stuff:  execute ma (or tabs) and get the result from coms.e file
  1250.    getcommand oldcmd,oldcol,oldscroll    -- Save old cmdline status
  1251.    TabOrMargins                          -- Execute the command
  1252.    getcommand setting                    -- Get current setting from cmdline
  1253.    setcommand oldcmd,oldcol,oldscroll    -- Restore old cmdline status
  1254.    parse value setting with . val        -- Get the stuff we want
  1255.    return val
  1256. compile endif
  1257.  
  1258. compile if 0    -- The following two routines are unused; why waste space??  LAM
  1259. ; PDISPLAY_MARGINS: put the margins mark on the current line
  1260.  
  1261. defproc pdisplay_margins()
  1262.    i=insert_state()
  1263.    if i then insert_toggle endif
  1264.    call psave_pos(save_pos)
  1265.    insert
  1266.    parse value pmargins() with lm rm pm .
  1267.    .col=lm;keyin'L';.col=pm;keyin'P';.col=rm;keyin'R'
  1268.    begin_line
  1269.    call prestore_pos(save_pos)
  1270.    if i then insert_toggle endif
  1271.    return 0
  1272.  
  1273.  
  1274. ; PDISPLAY_TABS: put the tab stops on the current line
  1275.  
  1276. defproc pdisplay_tabs()
  1277.    i=insert_state()
  1278.    if i then insert_toggle endif
  1279.    call psave_pos(save_pos)
  1280.    insert
  1281.    tabstops = ptabs()
  1282.    do forever
  1283.       parse value tabstops with tabx tabstops
  1284.       if tabx = '' then leave endif
  1285.       .col=tabx
  1286.       keyin'T'
  1287.    end
  1288.    begin_line
  1289.    call prestore_pos(save_pos)
  1290.    if i then insert_toggle endif
  1291.    return 0
  1292. compile endif
  1293.  
  1294. ; PEND_MARK: moves the cursor to the end of the marked area
  1295. defproc pend_mark
  1296. compile if WANT_DBCS_SUPPORT
  1297.    universal ondbcs
  1298. compile endif
  1299.    call checkmark()
  1300.    getmark  firstline,lastline,firstcol,lastcol,fileid
  1301.    activatefile fileid
  1302. compile if EVERSION < 5
  1303.    cursor_data
  1304. compile endif
  1305.    if marktype()<>'LINE' then
  1306.       .col=lastcol
  1307. compile if WANT_DBCS_SUPPORT
  1308.       if ondbcs then
  1309.          if .col > lastcol then -- Must have been in the middle of a DBC.
  1310.              .col = lastcol - 1
  1311.          endif
  1312.       endif
  1313. compile endif
  1314.    endif
  1315.    lastline
  1316.  
  1317. ; PEND_WORD: moves the cursor to the end of the word if the cursor is on this
  1318. ; word.  If it's not on a word, it's moved to the end of the first word on the
  1319. ; right.  If there is no word on the right it's moved to the end of the word on
  1320. ; the left.  If the line is empty the cursor doesn't move.
  1321. defproc pend_word
  1322.    getline line,.line
  1323.    if  substr(line,.col,1)=' '  then
  1324.       if substr(line,.col)=' ' then
  1325.          if  line<> ' ' then
  1326.             for i=.col to 2 by -1
  1327.                if substr(line,i-1,1)<>' ' then leave endif
  1328.             endfor
  1329.            .col=i-1
  1330.          endif
  1331.       else
  1332.          p=verify(line,' ','',.col)
  1333.          p=verify(line' ',' ','M',p)
  1334.          .col=p-1
  1335.       endif
  1336.    else
  1337.       if .col<>MAXCOL then
  1338.          i=pos(' ',line,.col)
  1339.          if i then
  1340.             .col=i-1
  1341.          else
  1342.             .col=length(line)
  1343.          endif
  1344.       endif
  1345.    endif
  1346.  
  1347.  
  1348. defproc pfile_exists /* Check if file already exists in ring */
  1349.    if substr(arg(1),2,1)=':'  then
  1350.       /* parse off drive specifier and try again */
  1351.       getfileid zzfileid,substr(arg(1),3)
  1352.    else
  1353.       getfileid zzfileid,arg(1)
  1354.    endif
  1355.    return zzfileid<>''
  1356.  
  1357. defproc pfind_blank_line
  1358.    -- Find first blank line after the current one.  Make that the new current
  1359.    -- line.  If no such line is found before the end of file, don't change the
  1360.    -- current line.
  1361.    for i = .line+1 to .last
  1362.       getline line,i
  1363.       -- Ver 3.11:  Modified to respect GML tags:  stop at first blank line
  1364.       -- or first line with a period or a colon (".:") in column 1.
  1365.       if line='' or not verify(substr(line,1,1), ".:" ) then
  1366.          i
  1367.          leave
  1368.       endif
  1369.    endfor
  1370.  
  1371. defproc pfirst_nonblank
  1372.    /* different from PE */
  1373.    if not .line then .col=1
  1374.    else
  1375.       getline line
  1376.       .col=max(1,verify(line,' '))
  1377.    endif
  1378.  
  1379.  
  1380. ; PLOWERCASE: force to lowercase the marked area
  1381.  
  1382. defproc plowercase
  1383.    call checkmark()
  1384.    /* invoke pinit_extract, pextract_string, pput_string_back to do the job */
  1385.    call psave_pos(save_pos)
  1386.    call pinit_extract()
  1387.    do forever
  1388.       code = pextract_string(string)
  1389.       if code = 1 then leave; endif
  1390.       if code = 0 then
  1391.          string = lowcase(string)
  1392.          call pput_string_back(string)
  1393.       endif
  1394.    end
  1395.    call prestore_pos(save_pos)
  1396.  
  1397.  
  1398. ; PMARGINS: return the current margins setting. (Uses pcommon_tab_margin)
  1399.  
  1400. defproc pmargins
  1401. compile if EVERSION < 5
  1402.    return pcommon_tab_margin('ma')
  1403. compile else
  1404.    return .margins
  1405. compile endif
  1406.  
  1407.  
  1408. ; PMARK: mark at the cursor position (mark type received as argument).  Used by
  1409. ; pset_mark
  1410. defproc pmark(mt)
  1411.    if mt= 'LINE' then
  1412.       mark_line
  1413.    elseif mt = 'CHAR' then
  1414.       mark_char
  1415.    else
  1416.       mark_block
  1417.    endif
  1418.  
  1419.  
  1420. ; PMARK_WORD: mark the word pointed at by the cursor.  If the cursor is on a
  1421. ; space, the word at the right is marked.  If there is no word on the right, the
  1422. ; word on the left is marked.
  1423. defproc pmark_word
  1424.    if marktype()<>'' then
  1425.       sayerror -279  -- 'Text already marked'
  1426.       stop
  1427.    endif
  1428.    call pend_word()
  1429. compile if WANT_CHAR_OPS
  1430.    mark_char
  1431. compile else
  1432.    mark_block
  1433. compile endif
  1434.    call pbegin_word()
  1435. compile if WANT_CHAR_OPS
  1436.    mark_char
  1437. compile else
  1438.    mark_block
  1439. compile endif
  1440. compile if EVERSION > 5
  1441.   'Copy2SharBuff'       /* Copy mark to shared text buffer */
  1442. compile endif
  1443.  
  1444.  
  1445. ; PRESTORE_MARK: restore the current marks (cannot be used as a stack) See also
  1446. ; psave_mark
  1447. defproc prestore_mark(savemark)
  1448.    unmark
  1449.    parse value savemark with savefirstline savelastline savefirstcol savelastcol savemkfileid savemt
  1450.    if savemt<>'' then
  1451.       call pset_mark(savefirstline,savelastline,savefirstcol,savelastcol,savemt,savemkfileid)
  1452.    endif
  1453.  
  1454.  
  1455. ; PRESTORE_POS: restore the cursor position (cannot be used as a stack) See
  1456. ; also psave_pos()
  1457. defproc prestore_pos(save_pos)
  1458.    parse value save_pos with svline svcol svcx svcy
  1459.    .cursory = svcy                          -- set .cursory
  1460.    min(svline, .last)                       -- set .line
  1461.    .col = MAXCOL; .col = svcol - svcx + 1   -- set left edge of window
  1462.    .col = svcol                             -- set .col
  1463.  
  1464.  
  1465. ;  Printer_ready( printer_number ) tests whether printer is ready.
  1466. ;
  1467. ;  Enter with printer_number = 1 for the first printer (LPT1), 2 for LPT2.
  1468. ;  No argument at all defaults to LPT1.
  1469. ;
  1470. ;  Returns 1 (true)  for printer attached and ready.
  1471. ;  Returns 0 (false) for printer not attached or not ready.
  1472. ;
  1473. ;  Note:  Assumes the standard BIOS responses for an IBM PC.
  1474. ;  The BIOS responds with AH=90 hex for printer ready.
  1475. ;  Might not work on clones and other strange machines.
  1476. ;
  1477. ;  If we're on OS/2 we don't check because the spooler protects us from
  1478. ;  a hang if the printer's off-line.  We always return "ready" on OS/2.
  1479. ;
  1480. defproc printer_ready
  1481. compile if EVERSION >= 4
  1482.    return 1
  1483. compile else
  1484.    if arg(1)='' then
  1485.       printer_number=1
  1486.    elseif not isnum(arg(1)) then
  1487.       sayerror 'Printer_ready:  'INVALID_NUMBER__MSG
  1488.       return 0
  1489.    else
  1490.       printer_number = arg(1)
  1491.    endif
  1492.    /* Call BIOS interrupt 17 hex with AH=2, printer status query. */
  1493.    parse value int86x(23,512 0 0 printer_number-1,'') with printer_status .
  1494. ;    IBM PC family returns '90' for printer ready (not busy + selected).
  1495. ;    Some clones return 'D0' (not busy + acknowledge + selected).
  1496. ;    Here, we'll accept either value.
  1497. ;                    hex2dec('9000'):              hex2dec('D000'):
  1498.    return (printer_status == -28672) or (printer_status == -12288)
  1499. compile endif
  1500.  
  1501.  
  1502. ; PSAVE_MARK: save the current marks (cannot be used as a stack) See also
  1503. ; prestore_pos()
  1504. defproc psave_mark(var savemark)
  1505.    savemt=marktype()
  1506.    if savemt then
  1507.       getmark  savefirstline,savelastline,savefirstcol,savelastcol,savemkfileid
  1508.       unmark
  1509.       savemark=savefirstline savelastline savefirstcol savelastcol savemkfileid savemt
  1510.    else
  1511.       savemark=''
  1512.    endif
  1513.  
  1514.  
  1515. ; PSAVE_POS: save the cursor position (cannot be used as a stack) See also
  1516. ; prestore_pos()
  1517. defproc psave_pos(var save_pos)
  1518.    save_pos=.line .col .cursorx .cursory
  1519.  
  1520.  
  1521. defproc pset_mark(firstline,lastline,firstcol,lastcol,mt,fileid)
  1522. compile if EVERSION >= '5.50'
  1523.    setmark firstline,lastline,firstcol,lastcol,wordpos(mt,'LINE CHAR BLOCK CHARG BLOCKG')-1,fileid
  1524. compile else
  1525.    getfileid actfileid    /* preserve current active fileid */
  1526.    rc = 0
  1527.    activatefile fileid
  1528.  compile if not E3
  1529.    if rc=sayerror('Invalid fileid') then stop; endif
  1530.  compile endif
  1531.    call psave_pos(save_pos)
  1532.    unmark
  1533.    if lastcol then
  1534.       .col=lastcol; lastline
  1535.    else
  1536.       lastline-1; .col=MAXCOL
  1537.    endif
  1538.    call  pmark(mt)
  1539.    .col=firstcol; firstline
  1540.    call pmark(mt)
  1541.    call prestore_pos(save_pos)
  1542.    activatefile actfileid         /* restore the initial active file */
  1543. compile endif
  1544.  
  1545. ; PTABS: return the current tabs setting. (Uses pcommon_tab_margin)
  1546.  
  1547. defproc ptabs
  1548. compile if EVERSION < 5
  1549.    return pcommon_tab_margin('tabs')
  1550. compile else
  1551.    return .tabs
  1552. compile endif
  1553.  
  1554.  
  1555. ; PUPPERCASE: force to uppercase the marked area
  1556.  
  1557. defproc puppercase
  1558.    call checkmark()
  1559.    /* invoke pinit_extract, pextract_string, pput_string_back to do the job */
  1560.    call psave_pos(save_pos)
  1561.    call pinit_extract()
  1562.    do forever
  1563.       code = pextract_string(string)
  1564.       if code = 1 then leave endif
  1565.       if code = 0 then
  1566.          string = upcase(string)
  1567.          call pput_string_back(string)
  1568.       endif
  1569.    end
  1570.    call prestore_pos(save_pos)
  1571.  
  1572. ;defproc remove_trailing_spaces
  1573. ;   /* This is no longer used by any file in standard E.  Use strip()  */
  1574. ;   /* instead.  But left here for compatibility with older procs.     */
  1575. ;   return strip(arg(1),'T')
  1576.  
  1577. compile if EPM
  1578. ; In E3 and EOS2, we can use a_X to enter the value of any key.  In EPM,
  1579. ; we can't, so the following routine is used by KEY and LOOPKEY to convert
  1580. ; from an ASCII key name to the internal value.  It handles shift or alt +
  1581. ; any letter, or a function key (optionally, with any shift prefix).  LAM
  1582. defproc resolve_key(k)
  1583.    kl=lowcase(k)
  1584.    suffix=\2                           -- For unshifted function keys
  1585.    if length(k)>=3 & pos(substr(k,2,1),'_-+') then
  1586.       if length(k)>3 then
  1587.          if substr(kl,3,1)='f' then     -- Shifted function key
  1588.             suffix=substr(\10\34\18,pos(leftstr(kl,1),'sac'),1)  -- Set suffix,
  1589.             kl=substr(kl,3)             -- strip shift prefix, and more later...
  1590.          elseif wordpos(substr(kl, 3), 'left up right down') then
  1591.             suffix=substr(\10\34\18,pos(leftstr(kl,1),'sac'),1)  -- Set suffix,
  1592.             kl=substr(kl,3)             -- strip shift prefix, and more later...
  1593.          else                        -- Something we don't handle...
  1594.             sayerror 'Resolve_key:' sayerrortext(-328)
  1595.             rc = -328
  1596.          endif
  1597.       else                        -- alt+letter or ctrl+letter
  1598.          k=substr(kl,3,1) || substr(' ',pos(leftstr(kl,1),'ac'),1)
  1599.       endif
  1600.    endif
  1601.    if leftstr(kl,1)='f' & isnum(substr(kl,2)) then
  1602.       k=chr(substr(kl,2)+31) || suffix
  1603.    elseif wordpos(kl, 'left up right down') then
  1604.       k=chr(wordpos(kl, 'left up right down')+20) || suffix
  1605.    endif
  1606.    return k
  1607. compile endif
  1608.  
  1609. compile if EVERSION < 5
  1610. defproc restore_command_state(cstate)
  1611.    if command_state()<>cstate then
  1612.       command_toggle
  1613.    endif
  1614.  
  1615. defproc save_command_state(var cstate)
  1616.    cstate=command_state()
  1617.    cursor_data
  1618.    refresh            /* Force E to update the cursor position */
  1619. compile endif
  1620.  
  1621.  
  1622. compile if EVERSION < '5.17'  -- Provide rightstr() macro for easier back-porting of EPM macros
  1623. defproc rightstr(argstring, len)
  1624.    l = length(argstring)
  1625.    if l=len then
  1626.       return argstring
  1627.    endif
  1628.    if l>len then
  1629.       return substr(argstring, l-len+1)
  1630.    endif
  1631.    return substr('', 1, len-l, substr(arg(3),1,1)) || argstring
  1632. compile endif
  1633.  
  1634.  
  1635. -- 4.10:  Saving with tab compression is built in now.  No need for
  1636. -- the make-do proc savefilewithtabs().  DOS version still needs it for
  1637. -- people editing MAKE files, but we make it optional via WANT_TABS.
  1638.  
  1639. compile if E3 & WANT_TABS
  1640. ; Note:  This does not tabify the entire file; it just replaces 8 blanks
  1641. ; in the first column with a tab character.
  1642. defproc savefilewithtabs(filename)
  1643.    options=arg(2)
  1644.    call psave_pos(save_pos)
  1645.    getfileid fileid
  1646.    unmark;bottom;markline;top;markline
  1647.    call prestore_pos(save_pos)
  1648.    'xcom e 'argsep'n .';deleteline
  1649.    if rc and rc<>-282 then  -- sayerror("new file")
  1650.       return rc
  1651.    endif
  1652.    rc=0
  1653.    copymark
  1654.    if rc then return rc endif
  1655.    unmark
  1656.    top;.col=1;markblock;bottom;.col=8;markblock
  1657.    .col=1;top
  1658.    'c/        /'\t'/m*'     /* replace first column 8 spaces with tab */
  1659.    sayerror 1  /* Turn off pending messages */
  1660.    unmark
  1661.    savestatus=savefile(filename,options)
  1662.    .modify=0
  1663.    'xcom q'
  1664.    if savestatus then return savestatus endif
  1665.    activatefile fileid
  1666.    if filename=.filename then
  1667.       .modify=0
  1668.    endif
  1669.    return 0
  1670. compile endif
  1671.  
  1672. define
  1673. compile if EVERSION < '5.21'
  1674.    MSGC = '.messagecolor'
  1675. compile elseif EVERSION < '5.50'
  1676.    MSGC = 'vMESSAGECOLOR'
  1677. compile else            -- GPI version
  1678.    MSGC = 'color'
  1679. compile endif
  1680.  
  1681. ; Paste up a message in a box, using SAYAT's.  Useful for "Processing..." msgs.
  1682. defproc sayatbox
  1683. compile if EVERSION >= '5.21'
  1684.    universal vMESSAGECOLOR
  1685. compile endif
  1686. compile if WANT_DBCS_SUPPORT
  1687.    universal ondbcs
  1688. compile endif
  1689.  
  1690. compile if EVERSION >= '5.50'  -- GPI version; doesn't use background color in SAYATs.
  1691.    color = sayat_color()
  1692. compile endif
  1693. compile if WANT_DBCS_SUPPORT
  1694.    if ondbcs then
  1695.       middle = substr('',1,length(arg(1)),\x06)
  1696.       sayat '  '\x01\x06||middle||\x06\x02'  ',1,2, $MSGC
  1697.       sayat '  '\x05' 'arg(1)' '\x05'  ',2,2, $MSGC
  1698.       sayat '  '\x03\x06||middle\x06\x04'  ',3,2, $MSGC
  1699.    else
  1700. compile endif
  1701.       middle = substr('',1,length(arg(1)),'═')
  1702.       sayat '  ╔═'middle'═╗  ',1,2, $MSGC
  1703.       sayat '  ║ 'arg(1)' ║  ',2,2, $MSGC
  1704.       sayat '  ╚═'middle'═╝  ',3,2, $MSGC
  1705. compile if WANT_DBCS_SUPPORT
  1706.    endif
  1707. compile endif
  1708.  
  1709. compile if EVERSION >= '5.50'
  1710. defproc sayat_color =          -- Pick a color for SAYAT that doesn't conflict w/ foreground or background color.
  1711.    universal vMESSAGECOLOR
  1712.    if vMESSAGECOLOR // 16 <> .textcolor // 16 & vMESSAGECOLOR // 16 <> .textcolor % 16 then
  1713.       return vMESSAGECOLOR       -- Preference is the message color.
  1714.    endif
  1715.    if vMESSAGECOLOR // 16 <> LIGHT_RED then
  1716.       return LIGHT_RED           -- Second choice is light red.
  1717.    endif
  1718.    if .textcolor // 16 <> LIGHT_BLUE & .textcolor % 16 <> LIGHT_BLUE then
  1719.       return LIGHT_BLUE          -- If that's used, then how about light blue
  1720.    endif
  1721.    return GREEN                  -- Final fallback is green.
  1722. compile endif
  1723.  
  1724. defproc splitlines()
  1725.    if .line then
  1726.       split
  1727.       oldcol=.col
  1728.       call pfirst_nonblank()
  1729. compile if EPM           -- Can't use REPLACELINE because it wipes out attributes.
  1730.       col1 = .col
  1731.       down
  1732.       if textline(.line)<>'' then
  1733.          call pfirst_nonblank()
  1734.          col2 = .col
  1735.          getsearch savesearch
  1736.          .col = 1
  1737.          if col1 < col2 then       -- Shift new line left
  1738.             'xcom c/'copies(' ',col2-col1)'//'  -- Change first n blanks to null
  1739.          elseif col1 > col2 then   -- Shift new line right
  1740. ;;            c = substr(textline(.line),1,1)  -- LAM: simpler to use GREP
  1741. ;;            if c='/' then d='?'; else d='/'; endif  -- Choose delimiter
  1742. ;;            'xcom c 'd||c||d||substr('',1,col1-col2)||c||d  -- Add blanks before 1st char.
  1743.             'xcom c /^/'copies(' ',col1-col2)'/g'  -- Add blanks before 1st char.
  1744.          endif
  1745.          setsearch savesearch
  1746.       endif
  1747.       up
  1748. compile else           -- E3 and EOS2 can still use the old, simple way.
  1749.       getline line,.line+1
  1750.       replaceline substr('',1,.col-1) ||    -- indent like previous line
  1751.          strip(line,'L'),                   -- (remove leading spaces)
  1752.          .line+1
  1753. compile endif
  1754.       .col=oldcol
  1755.    endif
  1756.  
  1757.  
  1758. ; Note on a speed trick:  subdir_present is initialized to null at start-up.
  1759. ; This causes defproc subdir(), the first time it's called, to execute a
  1760. ; FINDFILE (by way of find_routine) to search the path for the subdir program.
  1761. ; (See DEFC HELP for another example of findfile.)
  1762. ; After that first search the exact path location of subdir is known; it's
  1763. ; remembered in the universal variable subdir_present.  All future calls supply
  1764. ; the exact location (as in "C:\UTIL\SUBDIR.COM") to avoid the path search.
  1765.  
  1766. compile if EPM32  -- Only runs on OS/2 2.0 or above, so no question as to what to use...
  1767. defproc subdir
  1768.    quietshell 'dir /b /s /a:-D' arg(1)
  1769.  
  1770. compile else
  1771. definit  /* Keep this definit close to the proc it serves. */
  1772.    universal subdir_present
  1773.    subdir_present=''
  1774.  
  1775. defproc subdir
  1776.    universal subdir_present
  1777.    if subdir_present='' then  -- First time; look for the program
  1778.  compile if E3
  1779.       subdir_present=find_routine('SUBDIR /Q')
  1780.       if subdir_present == -1 then      -- Not found
  1781.          if Dos_Version() >= 500 then   -- If DOS version is 5, can use DIR
  1782.             subdir_present='dir /b /s'  -- (SUBDIR preferable for leading wildcards)
  1783.          endif
  1784.       endif
  1785.  compile else
  1786.       if Dos_Version() >= 2000 then   -- If OS/2 2.0 or above, use DIR
  1787.          subdir_present='dir /b /s'   -- (OS/2 DIR supports leading wildcards)
  1788.       else
  1789.          subdir_present=find_routine('FILEFIND')
  1790.       endif
  1791.  compile endif
  1792.       if subdir_present == -1 then     -- Not found, try ATTRIB
  1793.          subdir_present=find_routine('ATTRIB /S')
  1794.       endif
  1795.    endif
  1796.    if subdir_present == -1 then
  1797.       sayerror CANT_FIND_PROG__MSG 'ATTRIB'
  1798.       stop
  1799.    endif
  1800.    quietshell subdir_present arg(1)
  1801. compile endif -- EPM32
  1802.  
  1803. compile if EVERSION >= 4
  1804. defproc swapwords(num)
  1805.    return substr(num,3,2) || substr(num,1,2)
  1806. compile endif
  1807.  
  1808.  
  1809. compile if E3 or (EPM & not (EVERSION >= '5.17'))
  1810. ;  EOS2 & EPM have a TEXTLINE() function built in.  This is added here so that
  1811. ;  E3 macro programmers can use TEXTLINE also, if they like.
  1812. defproc textline(linenum)
  1813.    getline line,linenum; return line
  1814. compile endif
  1815.  
  1816. -- Standard text reflow, moved from Alt+P definition in STDKEYS.E.
  1817. -- Only called from Alt+P if no mark exists; users wishing to call
  1818. -- this from their own code must save & restore the mark themselves
  1819. -- if that's desired.
  1820. defproc text_reflow
  1821.    if .line then
  1822.       getline line
  1823.       if line<>'' then  -- If currently on a blank line, don't reflow.
  1824.          oldcursory=.cursory;oldcursorx=.cursorx; oldline=.line;oldcol=.col;
  1825.          unmark;mark_line
  1826.          call pfind_blank_line()
  1827.          -- Ver 3.11:  slightly revised test works better with GML sensitivity.
  1828.          if .line<>oldline then
  1829.             up
  1830.          else
  1831.             bottom
  1832.          endif
  1833.          mark_line
  1834.          reflow
  1835.  
  1836. compile if REFLOW_LIKE_PE   /* position on next paragraph (like PE) */
  1837.          down                       /* Thanks to Doug Short. */
  1838.          for i=.line+1 to .last
  1839.             getline line,i
  1840.             if line<>'' then i; leave; endif
  1841.          endfor
  1842. compile else
  1843.          /* or like old E */
  1844.          getmark firstline,lastline
  1845.          firstline
  1846.          .cursory=oldcursory;.cursorx=oldcursorx; oldline;.col=oldcol
  1847. compile endif
  1848.          unmark
  1849.       endif
  1850.    endif
  1851.  
  1852. ;  A truncate function to maintain compatibility of macros between this
  1853. ;  version and the OS/2 version which will have floating point.  Two
  1854. ;  functions in DOSUTIL.E need this.
  1855. ;
  1856. ;  If we're passed a floating point number with a decimal point in it,
  1857. ;  like "4.0", drop the decimal part.
  1858. ;  If we're passed an exponential-format number like "6E3", fatal error.
  1859. defproc trunc(num)
  1860.    if not verify('E',upcase(num)) then
  1861.       sayerror NO_FLOAT__MSG num
  1862.       stop
  1863.    endif
  1864.    parse value num with whole'.'.
  1865.    return whole
  1866.  
  1867. compile if WANT_LAN_SUPPORT
  1868. defproc unlock(fileid)
  1869.    if fileid.lockhandle = 0 then
  1870.       sayerror fileid.filename NOT_LOCKED__MSG
  1871.       return 1
  1872.    endif
  1873.  compile if EPM32
  1874.    result = dynalink32('DOSCALLS',    -- Free the original handle
  1875.                        '#257',                    -- dos32close
  1876.                        atol(fileid.lockhandle), 2)
  1877.  compile else
  1878.    result = dynalink('DOSCALLS',
  1879.                      '#59',                    /* dosclose */
  1880.                      atoi(fileid.lockhandle))
  1881.  compile endif
  1882.    if result then
  1883.       sayerror 'DOSCLOSE' ERROR_NUMBER__MSG result
  1884.    else
  1885.       fileid.lockhandle = 0
  1886.    endif
  1887.    return result
  1888. compile endif
  1889.  
  1890.