home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / editors / epm / e_macros / retrieve.e < prev    next >
Encoding:
Text File  |  1991-06-10  |  11.1 KB  |  277 lines

  1. /*****************************************************************************/
  2. /*  Retrieve interface for E3      Ralph Yozzo                               */
  3. /*                                                                           */
  4. /*  Acknowledgements                                                         */
  5. /*  Bryan Lewis significantly improved the handling of the c_pgdn and        */
  6. /*  c_pgup key.                                                              */
  7. /*                                                                           */
  8. /*  retrieves commands from the hidden file "coms.e".                        */
  9. /*  this avoids the need for endless uparrows and/or downarrows.             */
  10. /*  this simulates the ? operator in RETRIEVE.COM by Jack Gersbach           */
  11. /*  Have you ever tried to recall a command in E and repeatedly              */
  12. /*  pressed the uparrow. Sometimes it would be just as fast and less         */
  13. /*  keystrokes to retype the command.                                        */
  14. /*  Well, Retrieve is for you.                                               */
  15. /*                                                                           */
  16. /*  Retrieve will search through your stacked commands and                   */
  17. /*  return a match to the command line.                                      */
  18. /*  You can also clear the command stack.                                    */
  19. /*                                                                           */
  20. /*  Defined keys:                                                            */
  21. /*  The following keys have been reprogrammed while commandstate is true.    */
  22. /*  (i.e., the cursor is on the commandline).  They retain their             */
  23. /*  orginal function otherwise.                                              */
  24. /*                                                                           */
  25. /*  ctrl-pgup - clears the command stack                                     */
  26. /*  ctrl-pgdn - deletes the current command from the command stack           */
  27. /*                                                                           */
  28. /*  examples                                                                 */
  29. /*  r myte                                                                   */
  30. /*  retrieves commands such as "mytecopy a:retrieve.e h:retrieve e a"        */
  31. /*  r /c                                                                     */
  32. /*  this will clear the command stack                                        */
  33. /*  note:                                                                    */
  34. /*  The locate commands below will use a ascii 1 as a delimiter.             */
  35. /*  So the smilely faces that you see in the file on the PC are not          */
  36. /*  a mistake, but an ingenious method to guard against the user             */
  37. /*  passing a parameter which contains a delimiter.  Credit goes to          */
  38. /*  Bryan Lewis.  (I know you're saying what if the user wants to search     */
  39. /*  for ascii one) hopefully, this occurs rarely :-)                        */
  40. /*****************************************************************************/
  41. /*  Modified by Larry Margolis to be simpler, by using COMSFILEID.  Also,    */
  42. /*  omitted the Ctrl-pgup - I hated accidentally deleting my past commands.  */
  43. /*  Deleted ryedit routine.  Now done by activating fileids.                 */
  44. /*****************************************************************************/
  45. /*  Modified by Larry Margolis to define two commands.  The first, R, does   */
  46. /*  what it always did.  The second, RF, does a Retrieve, but matching the   */
  47. /*  command only if found starting in the First column.                      */
  48. /*****************************************************************************/
  49. /*  Many thanks to Tom Rogers for some of the ideas in the latest modification*/
  50. /*****************************************************************************/
  51.  
  52. /****************************************************************************
  53.    Included is the implementation of RETRIEVE's CTRL-W function in E3
  54.      added by Dan Kardell.  Taken from Russ Williams old retrieve macro.
  55.      (Placed on Ctrl-Y, since Ctrl-W was already in use.)
  56.  *****************************************************************************/
  57. /*  Modified by Larry Margolis to remove screen flashing and greatly         */
  58. /*  optimize the retrieve window.                                            */
  59. /*****************************************************************************/
  60. -- Sat Jun 24 07:55:36 pm 1989
  61. --  Retrieve's Windowing function has been modified by Larry Margolis.
  62. --  The '?' operator has been added to E for all versions greater than
  63. --  4.11
  64.  
  65. /*
  66.  *   universal ANSICHARS
  67.  *   delimiter=chr(verify(ANSICHARS,LocateTarget)-1)
  68.  *   "L" delimiter||LocateTarget||delimiter
  69.  *
  70.  *   we will convert the unique delimiter to the algorithm
  71.  *   above.
  72.  *
  73.  *  Many thanks to Jim Hurley for pointing out the idea above.
  74.  */
  75. /*
  76.  * c_minus - will delete the current command
  77.  *      and will repeat the most recent 'r' command
  78.  *      This is used in the following scenario.
  79.  *      The command stack contains:
  80.  *         cl c:\short\path\filename.c
  81.  *         cl c:\very\long\path\and\filename.c
  82.  *      We wish to retrieve "cl c:\very\long\path\and\filename.c"
  83.  *      and 'r' returns "cl c:\short\path\filename.c"
  84.  *      Our solution is to press c_minus
  85.  *      This avoids the need to type 'r cl c:\'
  86.  *
  87.  *      This is effectively a "find next" match.
  88.  */
  89.  
  90. def c_minus
  91.  universal RETRIEVE_argument
  92.  call RETRIEVE_delete_entry()
  93.  call coms_retrieve( RETRIEVE_argument )
  94.  
  95. /*
  96.  * rr - will repeat the most recent 'r' command.
  97.  *      This is used in the following scenario.
  98.  *      The command stack contains:
  99.  *         cl c:\short\path\filename.c
  100.  *         cl c:\very\long\path\and\filename.c
  101.  *      We wish to retrieve "cl c:\very\long\path\and\filename.c"
  102.  *      and 'r' returns "cl c:\short\path\filename.c"
  103.  *      Our solution is to delete "cl c:\short\path\filename.c"
  104.  *      using Ctrl-PgDn and then issuing the 'rr' command.
  105.  *      This avoids the need to type 'r cl c:\'
  106.  */
  107. defc rr
  108.  universal RETRIEVE_argument
  109.  call coms_retrieve( RETRIEVE_argument , 'r' )
  110.  
  111. compile if EVERSION < '4.12'
  112. defc r =
  113. compile else
  114. defc r,? =                              -- the '?' command is now valid in e
  115. compile endif
  116.    call coms_retrieve(arg(1))
  117. defc rf = call coms_retrieve(arg(1),'f')
  118.  
  119. defproc coms_retrieve=
  120.    universal comsfileid
  121.    universal RETRIEVE_argument
  122.    if arg(1)='' then
  123.       call remove('r')
  124.       sayerror 'Retrieve commands [/c]=clear stack [string]=search '
  125.       return 1
  126.    endif
  127.    getfileid fileid
  128.    activatefile comsfileid
  129.    call psave_mark(savemark)    -- LAM:  save user's previous mark, if any
  130.    if arg(1)='/c' then
  131.       top
  132.       unmark
  133.       mark_line
  134.       bottom
  135.       mark_line
  136.       call pdelete_mark()
  137.       call prestore_mark(savemark)    -- LAM:  restore user's previous mark.
  138.       sayerror CMD_STACK_CLEAR__MSG  -- LAM:  Sayerror restores top level ring.
  139.       return 1
  140.    endif
  141.    RETRIEVE_argument = arg(1)
  142.  
  143.    call remove('r'arg(2) arg(1))  -- Delete the command just typed (that called us).
  144.  
  145.    top
  146.    if arg(2) then
  147.       call pset_mark(1,.last,1,length(arg(1)),'BLOCK',comsfileid)
  148.       m = 'm'
  149.    else
  150.       m = ''
  151.    endif
  152.    'xcom L 'arg(1)'c'm   /* unused character ascii 1 for search delimiter */
  153.    lrc = rc
  154.    call prestore_mark(savemark)    -- LAM:  restore user's previous mark.
  155.    activatefile fileid
  156.    if lrc<>0 then
  157.       sayerror -273  -- 'String not found'
  158.       return 1
  159.    endif
  160.    getline line,comsfileid.line,comsfileid
  161.    setcommand line,length(line)+1,1
  162.  
  163. ;delete Retrieve command
  164. ;remove the "r xxx" from the coms.e file
  165. ;where xxx is argument supplied by the user
  166. defproc remove(comm)       -- LAM:  coms.e need not be active file.
  167.    universal comsfileid
  168.    getline nline,comsfileid.last,comsfileid
  169.    if substr(nline,1,length(comm))=comm then
  170.       deleteline comsfileid.last,comsfileid
  171.    endif
  172.  
  173. /*   LAM:  I pressed ctrl-PgUp without realizing I was on the command line
  174.            too many times.  Very annoying.  Can still do "R /C" to delete.
  175. def c_pgup=
  176.    if command_state() then   /* if press c_pgup on the command line */
  177.       'r /c'
  178.    else
  179.       .cursory=1              /* in data area, do the old c_pgup key */
  180.    endif
  181. */
  182.  
  183. def c_pgdn=  -- LAM:  Changed so we never leave the active file.
  184.  call RETRIEVE_delete_entry()
  185.  
  186. defproc RETRIEVE_delete_entry
  187.    universal comsfileid
  188.    if command_state() then   /* if press c_pgdn on the command line */
  189.       getcommand cur_cmd_line
  190.       getline coms_cmd_line,comsfileid.line,comsfileid
  191.       if cur_cmd_line=coms_cmd_line then
  192.          deleteline comsfileid.line,comsfileid
  193.          if comsfileid.last=0 then   /* list is empty */
  194. ;;          'r /c'         -- LAM:  Why clear?  already empty.
  195.             sayerror CMD_STACK_EMPTY__MSG
  196.             setcommand ''  -- LAM: Clear the command line.
  197.             return
  198.          endif
  199.                  /* get next line after deletion, like Retrieve.Com */
  200. ;                   LAM:  Note:  deleteline leaves .line on previous line.
  201.          newline=min(comsfileid.line+1,comsfileid.last)
  202.          getline line,newline,comsfileid
  203.          comsfileid.line=newline
  204.          setcommand line,1,1
  205.       endif
  206.    else
  207.       .cursory=.windowheight  /* do the old c_pgdn key */
  208.    endif
  209.  
  210. /****************************************************************************
  211.    Included is the implementation of RETRIEVE's CTRL-W function in E3
  212.      added by Dan Kardell.  Taken from Russ Williams old retrieve macro
  213.  ***************************************************************************/
  214.  
  215. ;def c_w=  c_w is already used by EOS2
  216. def c_y=
  217.    call RETRIEVE_window()
  218.  
  219. defproc RETRIEVE_window
  220.    newwindow 'e /w /n coms.e'
  221.    call sizepopup(45,11,35,15,1)
  222.    bottom
  223.    line=select_a_command()
  224.    sayerror 0
  225.    line
  226.    cursorcommand
  227.  
  228. defproc select_a_command
  229.    call psave_mark(save_mark)
  230.    cursor_data
  231.    begin_line
  232.    return_str=''
  233.    sayerror '* RETRIEVE * ,=scroll  ENTER=execute  ESC=quit  F10=get cmd Ctrl-F10=Clear all'
  234.    loop
  235.       markline
  236.       k=getkey()
  237.       if k=esc then
  238.          leave
  239.       endif
  240.       if k=up & .line<>1 then
  241.          unmark; up
  242.       elseif k=down then
  243.          unmark; down
  244.       elseif k=pgup then
  245.          unmark; page_up
  246.       elseif k=pgdn then
  247.          unmark; page_down
  248.       elseif k=c_home or k=home then
  249.          unmark; top
  250.       elseif k=c_end or k=end then
  251.          unmark; bottom
  252.       elseif k=c_F10 then
  253.          top
  254.          unmark
  255.          mark_line
  256.          bottom
  257.          mark_line
  258.          call pdelete_mark()
  259.       elseif k=c_backspace then
  260.          delete_mark; down
  261.       elseif k=f10 then
  262.          getline line
  263.          cursor_command
  264.          begin_line; erase_end_line
  265.          keyin line
  266.          Leave
  267.       elseif k=enter then
  268.          getline return_str
  269.          leave
  270.       endif
  271.    endloop
  272.    call prestore_mark(save_mark)
  273.    .modify=0
  274.    'xcom q'
  275.    return return_str
  276.  
  277.