home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / editor / epmtools / epmsmp / alt_1.e next >
Text File  |  1992-08-26  |  20KB  |  470 lines

  1. -- Alt-One.E   Bells & whistles for the Alt-1 key.   Bryan Lewis  03/08/87
  2. --
  3. -- I use the Alt-1 key a lot, to edit the file named in the current text line.
  4. -- Very handy along with the commands LIST and SCAN, and with source code.
  5. -- I've jazzed it up so I can hit it when working with:
  6. --
  7. --   1. Lists output by SCAN.COM (see SCAN.E), in the form:
  8. --        --- c:\e3\mykeys.e    3/4/87 1:04p  21136 ---
  9. --   2. E3 source which contains lines like:
  10. --        include 'colors.e'
  11. --   3. C source which contains lines like:
  12. --        #include <dos.h>
  13. --   4. Any old list of filenames to which I've added comments.
  14. --      All text after the filename is ignored.
  15. --   5. Cross-reference lists output by C-USED.
  16. --   6. File lists from the host.
  17. --   7. Lists output by GREP with filenames like "File #0==> CKEYSEL.E <==".
  18. --
  19. --- History, latest change first ----------------------------------------------
  20. --
  21. -- Modified 11/10/88 by TJR:  ALT-ONE may be used to load a file
  22. -- specified by H:*PROCS INDEX (currently only E3PROCS INDEX).  The
  23. -- file will be loaded, and the cursor moved to the line containing
  24. -- the macro of interest.  This is lightning fast once the files
  25. -- are in the ring, and is the perfect tool for anyone who looks through
  26. -- E3PROCS.  When is EOS2PROCS INDEX coming out?  You guys in aisle
  27. -- 32 better keep the same format :-).
  28. --
  29. -- Modified 11/09/88 by TJR:  ALT-ONE will now work even better with
  30. -- the output of GREP.E by TJR.  If the current line of the .grep
  31. -- file is a file listing (see number 7 above), then pressing ALT-1
  32. -- will open the specfied file for editing.  If the current line is
  33. -- not a file specification, then it must be a line within the previous
  34. -- file specified.  If this is the case, then that file will be opened,
  35. -- and the cursor moved to the line specified in the file.  The current
  36. -- line of the new file will be highlighted for quick recognition.
  37. -- Many thanks to Bryan Lewis for all his help.
  38. --
  39. -- Modified 8/9/88 by jbl:  Alt-One will search along a user-specified path.
  40. -- You need this if you usually store your include files somewhere other than
  41. -- the current directory.  I borrowed code from the USE_APPEND feature of
  42. -- standard E (by Ken Kahn, Larry Margolis, and me).
  43. --
  44. -- This is good for editing C or E programs when the include files lie in a
  45. -- different directory, for example:
  46. --
  47. --    #include "foo.e"
  48. --
  49. -- Alt-One will look first in the current directory and then along the path
  50. -- specified by the ESEARCH environmewnt variable.  For instance, you might do:
  51. --
  52. --    C> set esearch=c:\current\et;d:\old\include
  53. --
  54. -- A special feature for C programmers:  If you turn on the constant C_INCLUDE,
  55. -- filenames enclosed in angle brackets will not be looked for in the current
  56. -- directory but along the path specified by the INCLUDE environment variable.
  57. --
  58. -- The ESEARCH feature works for any list of filenames, not just source code.
  59. --
  60. -------------------------------------------------------------------------------
  61. -- Modified 10/19/87 by Chris Codella to handle tryincludes and includes not
  62. -- starting in column 1, and includes with imbedded blanks.  10/19/87
  63. -------------------------------------------------------------------------------
  64. -- Modified by Bryan Lewis to handle lines in a cross-reference listing
  65. -- produced by C-USED, resembling:
  66. --
  67. --   statement                               36 STAT.C
  68. --     1 stat                                31 MAIN.C
  69. --
  70. -- If I press Alt-1 on the first line I want to edit STAT.C and search for the
  71. -- word "statement".  For the second line I want to edit MAIN.C and search for
  72. -- "stat" (the containing function) and then "statement".  I don't trust the
  73. -- line numbers to stay constant.
  74. -- I turn on this feature if the filetype is "USE" or "XRF".
  75. -------------------------------------------------------------------------------
  76.  
  77. -- For linking:  To make this separately compilable, we set the constants we
  78. -- need to check the same way they would be set if we were included in E.EX.
  79. compile if not defined(SMALL)        -- If compiling stand-alone,
  80.   tryinclude 'mycnf.e'                 -- Include user's configuration
  81.   CONST                 -- Need this to prevent compile error on USE_APPEND=0
  82.   compile if not defined(USE_APPEND)   -- because we need these variables
  83.   USE_APPEND = 0                       -- and this sets them properly.
  84.   compile endif
  85.   compile if not defined(HOST_SUPPORT)
  86.   HOST_SUPPORT = 'STD'
  87.   compile endif
  88.   compile if HOST_SUPPORT='STD' | HOST_SUPPORT=''
  89.    compile if not defined(HOSTDRIVE)
  90.       HOSTDRIVE= 'H:'
  91.    compile endif
  92.   compile endif
  93.   compile if not defined(WANT_SEARCH_PATH)
  94.   WANT_SEARCH_PATH = 0
  95.   compile endif
  96.   compile if not defined(WANT_GET_ENV)
  97.     compile if EVERSION < 4            -- Was IF E3, but this avoids STDCONST.
  98.   WANT_GET_ENV = 0
  99.     compile else
  100.   WANT_GET_ENV = 1
  101.     compile endif
  102.   compile endif
  103.   compile if not defined(DIRECTORYOF_STRING)
  104.   DIRECTORYOF_STRING = 'Directory of'
  105.   compile endif
  106. compile endif
  107.  
  108. const                             -- These are Alt-1.e -specific constants.
  109.   compile if not defined(AltOnePathVar)
  110.    AltOnePathVar= 'ESEARCH'    -- the name of the environment variable
  111.   compile endif
  112.   compile if not defined(C_INCLUDE)
  113.    C_INCLUDE    = 1            -- 1 means search <filename> along INCLUDE path
  114.   compile endif
  115.  
  116. def a_1=
  117.    universal host_LT                    -- Used with LAMPDQ.E
  118. compile if HOST_SUPPORT='EMUL' or HOST_SUPPORT='SRPI'
  119.    universal hostdrive
  120. compile endif
  121.    /* edit filename on current text line */
  122.    getline line
  123.  
  124.    -- jbl 2/14/89:  we now distribute a standard front end for the DIR
  125.    -- command, which redirects the output to a file named ".dos dir <dirname>".
  126.    -- lam 3/15/89:  added code to handle trailing blanks and wildcards.
  127.    -- Previously, after a 'DIR \path\*.E ', would do:  E \path\*.E \fname.ext
  128.    parse value .filename with word1 word2 word3 .
  129.    if upcase(word1 word2) = '.DOS DIR' then
  130.       call psave_pos(save_pos)
  131. compile if EVERSION >= '4.12'
  132.       getsearch oldsearch
  133. compile endif
  134.       'xcom l /'DIRECTORYOF_STRING'/c-'
  135.       if not rc then
  136.          getline word3
  137.          parse value word3 with . . word3 .
  138.       endif
  139. compile if EVERSION >= '4.12'
  140.       setsearch oldsearch
  141. compile endif
  142.       call prestore_pos(save_pos)
  143. compile if EVERSION >= 4  -- DOS (box) doesn't see new-format DIR listing
  144.       filename=substr(line,41)                 -- Support HPFS.  FAT dir's end at 40
  145.       if filename='' then                      -- Must be FAT.
  146. compile endif
  147.          filename=strip(substr(line,1,8))
  148.          word2=strip(substr(line,10,3))
  149.          if word2<>'' then filename=filename'.'word2; endif
  150. compile if EVERSION >= 4  -- DOS (box) doesn't see new-format DIR listing
  151.       endif
  152. compile endif
  153.       name=word3 ||                            -- Start with the path.
  154.            substr('\', 1,                      -- Append a '\', but only if path
  155.                   '\'<>substr(word3,length(word3),1)) ||  -- doesn't end with one.
  156.            filename                            -- Finally, the filename
  157.       if pos('<DIR>',line) then
  158.          'dir 'name
  159.       else
  160.          call a1load(name,AltOnePathVar,0)
  161.       endif
  162.       return
  163.    endif
  164.  
  165.    -- jbl 11/15/88:  replace any '/' with '\'.  C compiler error output
  166.    -- can have forward slashes.
  167.    p=pos('/',line)
  168.    while p>0 do
  169.       line=substr(line,1,p-1)'\'substr(line,p+1)
  170.       p=pos('/',line)
  171.    endwhile
  172.    -- jbl 11/15/88:  The C compiler error line can have a line number in
  173.    -- parentheses, like "/epm/i/iproto.h(196)".  Get the number.
  174.    linenum=''; col = ''
  175.    p=pos('(',line)
  176.    if p>0 then
  177.       parse value line with line '(' linenum ')' .
  178.       parse value linenum with linenum ':' col  -- LAM: CSet/2 includes column
  179.    endif
  180.  
  181. /******************************************************************************/
  182. /***       LAMPDQ support for LISTFILE output                               ***/
  183. /******************************************************************************/
  184.  
  185.    -- 5/11/88:  make Alt-1 work on lists of host files. */
  186.    -- This works best with Larry Margolis's PDQ support (SLPDQ), and only
  187.    -- when the name of the list file is "LIST OUTPUT", as is true when
  188.    -- I'm using LaMail.  I have to have some way of knowing it's a list
  189.    -- of host files.
  190. ;; if .filename ="LIST OUTPUT" then
  191.    -- 10/21/88 (LAM): Make work for any abbreviation of LISTFILE, not just
  192.    -- LIST, and ignore extra spaces on left and info on right [e.g., output
  193.    -- from LISTFILE (ALLOC ].
  194.    parse value .filename with file ext .
  195.    if ext='OUTPUT' & file=substr('LISTFILE',1,length(file)) then
  196.       parse value line with fn ft fm .
  197.       'e 'substr(hostdrive,1,1) || host_lt':'fn ft fm
  198.       return
  199.    endif
  200.  
  201. /******************************************************************************/
  202. /***       C-USED support                                                   ***/
  203. /******************************************************************************/
  204.  
  205.    -- If the filetype is USE or XRF, do C-USED feature.
  206.    ext=substr(upcase(.filename),lastpos('.',upcase(.filename))+1)
  207.    if ext='USE' or ext='XRF' then
  208.       if substr(line,1,1)=' ' then  -- child line
  209.          parse value line with . infunc linenum file
  210.          for i = .line-1 to 1 by -1   -- search upward for parent line
  211.             getline line,i
  212.             if substr(line,1,1) <> ' ' then
  213.                parse value line with func .
  214.                leave
  215.             endif
  216.          endfor
  217.          call a1load(file,AltOnePathVar,1)
  218.          top
  219.          'L /'infunc; if rc then return; endif
  220.          'L /'func;   if rc then return; endif
  221.          sayerror 'Found 'func' in 'infunc' in 'file'.'
  222.       else                          -- parent line
  223.          parse value line with func linenum file
  224.          if linenum='#' then        -- might have a '#' in 2nd column
  225.             parse value file with linenum file
  226.          endif
  227.          call a1load(file,AltOnePathVar,1)
  228.          top
  229.          'L /'func; if rc then return; endif
  230.          sayerror 'Found 'func' in 'file'.'
  231.       endif
  232.       return
  233.    endif    -- C-USED feature
  234.  
  235. /******************************************************************************/
  236. /***       E3PROCS index support                                            ***/
  237. /******************************************************************************/
  238.  
  239.    -- 11/10/88: Load Files Directly From The INDEX File.  By TJR
  240.    --           Now loads files from the E3PROCS INDEX hostfile.  It is
  241.    --           assumed that someday there will be an EOS2PROCS INDEX of
  242.    --           the same format, therefore this macro was written to
  243.    --           look for any H:*PROCS INDEX file.  A sincere attempt is
  244.    --           made to open the file and move to the macro of interest.
  245. compile if HOST_SUPPORT
  246.    fn = .filename
  247.    parse value .filename with filename filetype fmode .  -- Not as crude, TJR
  248.    if ('INDEX'=filetype & 'PROCS'=substr(filename, max(length(filename)-4,1), 5) &
  249.         vmfile(fn,ft)) then
  250.       parse value line with proc fn ft uid node date .
  251.       if ('PROCS'<>ft) then                   -- Is the current line an entry?
  252.          getline line, .line-1                -- Go back one line and try again.
  253.          parse value line with proc fn ft uid node date .
  254.          if ('PROCS'<>ft) then                -- One more time. . . .
  255.             sayerror'Sorry, cursor is not at a PROCS index entry!  No file loaded!'
  256.             return
  257.          endif
  258.       endif                                   -- If we're here, must be an entry!
  259.  compile if HOST_SUPPORT='EMUL' or HOST_SUPPORT='SRPI'
  260.       'e' hostdrive || host_lt':'fn ft fmode
  261.  compile else
  262.       'e' HOSTDRIVE || fn ft fmode
  263.  compile endif
  264.       TOP                                     -- Goto top of file.
  265.       do forever
  266.  compile if EVERSION >= '4.12'
  267.          getsearch oldsearch
  268.  compile endif
  269.          'xcom l ₧'date'₧'                    -- Try to get the procedure.
  270.  compile if EVERSION >= '4.12'
  271.          setsearch oldsearch
  272.  compile endif
  273.          if rc then
  274.             sayerror proc' macro added by 'uid' on 'date' was not found!'
  275.             TOP                               -- Go back to the top.
  276.             BEGINLINE                         -- Move to beginning.
  277.             return
  278.          else
  279.             getline line
  280.             if (uid = substr(line, lastpos('by ', line)+3, length(uid))) then
  281.                sayerror proc' macro added by 'uid' on 'date
  282.                BEGINLINE                      -- Move to beginning.
  283.                return
  284.             else
  285.                '+1'
  286.             endif
  287.          endif
  288.       enddo
  289.    endif
  290.    -- End of TJR's INDEX file modifications.
  291. compile endif
  292.  
  293. /******************************************************************************/
  294. /***       GREP support                                                     ***/
  295. /******************************************************************************/
  296.  
  297.    -- 8/10/88:  Handle GREP output like "File #0==> CKEYSEL.E <==".
  298.    parse value line with "==>" filename "<=="
  299.    if filename then
  300.       call a1load(filename,AltOnePathVar,1)
  301.       return
  302.    endif
  303.  
  304.    -- 11/03/88: Open file specified by GREP and move to current line!  TJR
  305.    -- Use the name ".grep" as the signature, so I can load multiple grep lists.
  306.    -- See GREP.E.  jbl.
  307.    if substr(.filename,1,5)=".grep" |                            -- TJR's GREP
  308.       substr(.filename,1,17)=".Output from grep" then            -- LAM's GREP
  309. compile if EVERSION >= '4.12'
  310.          getsearch oldsearch
  311. compile endif
  312.        call psave_pos(save_pos)
  313.        'xcom l .   File #. -'          /* Find previous file           */
  314. compile if EVERSION >= '4.12'
  315.          setsearch oldsearch
  316. compile endif
  317.        if rc then
  318.           sayerror 'No files found!'
  319.           return
  320.        else
  321.           getline newline
  322.           call prestore_pos(save_pos)
  323.           parse value newline with "==>" filename "<=="
  324.           call a1load(filename,AltOnePathVar,1)
  325. ;;compile if 1                                                -- LAM:  I use /L
  326. ;  Now supports both; if line starts with a number, assume /L; if not, do search.
  327.           parse value line with num ')'
  328.           if isnum(num) then
  329.              .cursory=.windowheight%2
  330.              num
  331.              return
  332.           endif
  333. ;;compile else                                                -- TJR doesn't
  334.           parse value line with "==>" tempstr
  335.           if  tempstr = ''  then
  336.              'xcom l ₧'line'₧'         /* ALT-158 is the search delim */
  337.              if rc then
  338.                  sayerror substr(line, 1, 60)'. . . Not Found!'
  339.              else
  340.                  refresh
  341.                  unmark
  342.                  mark_block            /* hilite the line with string  */
  343.                  end_line
  344.                  mark_block
  345.                  begin_line
  346.              endif
  347.           endif
  348.           return
  349. ;;compile endif
  350.        endif
  351.    endif
  352.    -- End of TJRs 11/03/88 Modifications!
  353.  
  354.  
  355.    /** If line starts with 'include' or '#include', read the filename. **/
  356.    pathvar = AltOnePathVar      -- default, if not #include <>
  357.    TryCurFirst=1
  358.    -- jbl 10/25/88:  don't accept "include" anywhere in the line, you'll be
  359.    -- fooled by path names like c:\c\include.  Accept it only as first word.
  360.    -- inclpos=pos('include',lowcase(line))
  361.    parse value lowcase(line) with word1 word2 .
  362.    if word1="include" or word1="#include" or word1="tryinclude" then
  363.       delim=substr(word2,1,1)
  364.       if delim="'" | delim='"' then
  365.          line =strip(word2,'B',delim)    /* For E files */
  366.       elseif delim='<' then
  367.          parse value word2 with '<'word2'>'
  368.          -- jbl 10/25/88:  Searching only along the INCLUDE path didn't always
  369.          -- work.  Rechecking the C compiler manual, I see that it first
  370.          -- searches the specified search path (i.e., what we call ESEARCH) and
  371.          -- then the "standard directories", the INCLUDE path.
  372.          call a1load(word2,PathVar,TryCurFirst)  -- So first search ESEARCH.
  373. compile if C_INCLUDE
  374.          -- If that fails, try INCLUDE path.
  375.          if rc=sayerror("New file") or rc=sayerror("Path not found") then
  376.             'q'
  377.             pathvar='INCLUDE'
  378.             TryCurFirst=0
  379.             call a1load(word2,PathVar,TryCurFirst)
  380.          endif
  381. compile endif
  382.       endif
  383.    else
  384.       /** If line starts with fillers (duplicate characters and a space) like: **/
  385.       /**   --- FOOBAR.TXT    (which is from SCAN), strip them off.  JBL       **/
  386.       c=substr(line,1,1)
  387.       temp = strip(line,'L',c)
  388.       /* Must be a space after the fillers, and more than one filler. */
  389.       if substr(temp,1,1)=' ' and length(temp)<length(line)-1 then
  390.          line=temp          --LAM: Leading blank will be stripped by Parse, below.
  391.       endif
  392.       /**  end of strip-leading-fillers modification  **/
  393.    endif
  394.  
  395.    /* also discard remainder of line after the first word, so I can comment */
  396.    parse value line with line .
  397.    call a1load(line,PathVar,TryCurFirst)
  398.    linenum  -- jbl 11/15/88, go to specified linenum if any.
  399.    if col <> '' then .col = col; endif
  400.  
  401. defproc a1load(filename,PathVar,TryCurFirst)
  402.    if TryCurFirst then
  403.       if exist(filename) then
  404.          'e' filename
  405.          return
  406.       endif
  407.    endif
  408.    'e' search_path(Get_Env(PathVar),filename)filename
  409.  
  410. compile if not (USE_APPEND | WANT_SEARCH_PATH)  -- This might already be included in user's E.
  411. defproc search_path(AppendPath, FileName)
  412.    do while AppendPath<>''
  413.       parse value AppendPath with TryDir ';' AppendPath
  414.       if trydir='' then iterate; endif
  415.       lastch=substr(TryDir,length(TryDir),1)
  416.       if lastch<>'\' & lastch<>':' then
  417.          TryDir = TryDir||'\'
  418.       endif
  419.       if exist(TryDir||FileName) then
  420.          return TryDir
  421.       endif
  422.    enddo
  423.    return ''
  424. compile endif
  425.  
  426. compile if not (USE_APPEND | WANT_GET_ENV)  -- This might already be included in user's E.
  427. defproc get_env(varname)=
  428.    varname = upcase(varname)
  429.    env_ofs = 0
  430. compile if EVERSION>=4
  431.  compile if EVERSION<'4.10'     -- If no more family mode, don't check machine()
  432.    if machine()='OS2PROTECT' then
  433.  compile endif
  434.       seg_ptr = 1234
  435.       cmd_ptr = 1234
  436.       call dynalink('DOSCALLS',
  437.                     '#91',
  438.                     selector(seg_ptr) ||
  439.                     offset(seg_ptr)   ||
  440.                     selector(cmd_ptr) ||
  441.                     offset(cmd_ptr)     )
  442.       env_seg=itoa(seg_ptr,10)
  443.  compile if EVERSION<'4.10'     -- If no more family mode, don't check machine()
  444.    else
  445.  compile endif
  446. compile endif
  447. compile if EVERSION<'4.10'
  448.       if dos_version() < 300 then
  449.          sayerror 'DOS version 3.0 or above required for Get_Env Address.'
  450.          return ''
  451.       endif
  452.       parse value int86x(33,25088,'') with . PSP_seg .  -- Int 21H, AH=62H
  453.       env_seg = asc(peek(PSP_seg,45,1)) * 256 + asc(peek(PSP_seg,44,1))
  454.  compile if EVERSION>='4.02'
  455.    endif
  456.  compile endif
  457. compile endif
  458.    do while peek(env_seg,env_ofs,1) /== \0  -- (backslash) 0 == ASCII null
  459.       start = env_ofs
  460.       do while peek(env_seg,env_ofs,1) /== \0
  461.          env_ofs = env_ofs + 1
  462.       end
  463.       setting = peek(env_seg,start,env_ofs-start)
  464.       parse value setting with name '=' parameter
  465.       if name=varname then return parameter; endif
  466.       env_ofs=env_ofs+1
  467.    end
  468.    return ''
  469. compile endif
  470.