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