home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / prodtool / epm / e_macros / all.e next >
Encoding:
Text File  |  1991-08-29  |  5.3 KB  |  173 lines

  1. /* This command will create a new file showing all occurrances of the */
  2. /* search string given.  Syntax:  ALL /find_string[/[c]]              */
  3. /* where / can be any delimiter, and c means ignore case.             */
  4. /*                                                                    */
  5. /* The key c_Q is set up so that if you press it while in the .ALL    */
  6. /* file, it will position you on the corresponding line in the        */
  7. /* original file.  If you are not in .ALL, you will be placed there   */
  8. /* and the cursor will be moved down one line.  This enables you to   */
  9. /* rapidly switch from .ALL to succeeding lines of the original.      */
  10. /*                                                                    */
  11. /* Author:  Larry Margolis, MARGOLI at YORKTOWN                       */
  12.  
  13. compile if not defined(SMALL)  -- If being externally compiled...
  14. const
  15.    tryinclude 'MYCNF.E'
  16. const
  17.  compile if not defined(NLS_LANGUAGE)
  18.    NLS_LANGUAGE = 'ENGLISH'
  19.  compile endif
  20.  include NLS_LANGUAGE'.e'
  21. compile endif
  22.  
  23. define
  24.  compile if defined(HIGHLIGHT_COLOR)
  25.    XCOM_L = 'L'            -- Do a DEFC L, so that the string gets highlighted.
  26.  compile else
  27.    XCOM_L = 'XCOM L'       -- Otherwise, use the faster internal locate command
  28.  compile endif
  29.  
  30. defc all=   /* ALL macro */
  31.    universal allorig,allsrch,default_search_options
  32.    call psave_pos(save_pos)
  33. compile if EVERSION < 5
  34.    cursor_data
  35. compile endif
  36.    getfileid allorig
  37.    'e /q /n .ALL'    /* Don't use XCOM so can handle either windowing style */
  38.    .filename = '.ALL'
  39.    getfileid allfile
  40.    allsrch=strip(arg(1),'L')
  41.    if allsrch='' then
  42.       .modify=0
  43.       'q'
  44.       if allorig<>allfile then activatefile allorig; endif
  45.       sayerror 1
  46.       return
  47.    endif
  48.    for i=1 to .last
  49.       deleteline 1
  50.    endfor
  51.    activatefile allorig
  52.  
  53.     /* Copied from DEFC L - we only will use E or C (case) and A or M (mark)  */
  54.     DSO=''   /* subset of default_search_options */
  55.     do i=1 to length(default_search_options)
  56.        ch=substr(default_search_options,i,1)
  57.        if pos(ch,'EeCcAaMm')>0 then DSO=DSO || ch endif
  58.     end
  59.     /* Insert default_search_options just before supplied options (if any)    */
  60.     /* so the supplied options will take precedence.                          */
  61.     if DSO then
  62.        ch=substr(allsrch,1,1)
  63.        p=pos(ch,allsrch,2)
  64.        user_options=''
  65.        if p>0 then
  66.           user_options=substr(allsrch,p+1)
  67.           allsrch=substr(allsrch,1,p-1)
  68.        endif
  69.        allsrch=allsrch||ch||DSO||user_options
  70.     endif
  71.  
  72.    0
  73. compile if EVERSION >= 5
  74.    display -2
  75. compile endif
  76.    do forever
  77.       .col=1
  78.       'xcom l' allsrch
  79.       if rc=-273 then leave; endif  -- sayerror("String not found")
  80.       getline line
  81. compile if EVERSION >= '5.17'
  82.       line=rightstr(.line,5) line
  83. compile else
  84.       line=substr('    '.line,length(.line)) line
  85. compile endif
  86.       insertline line,allfile.last+1,allfile
  87.       if .line=.last then leave; endif
  88.       '+1'
  89.    end
  90. compile if EVERSION >= 5
  91.    display 2
  92. compile endif
  93.    call prestore_pos(save_pos)
  94.    if allfile.last=0 then
  95.       activatefile allfile
  96.       .modify=0
  97.       'q'
  98.       activatefile allorig
  99.       return
  100.    endif
  101.    sayerror 0
  102.    activatefile allfile
  103. compile if EVERSION < 4
  104.    call select_edit_keys()
  105. compile endif
  106.    sayerror 0
  107.    .modify=0; top; .col=6
  108. compile if EVERSION < 5
  109.    cursor_data
  110. compile endif
  111.    XCOM_L allsrch  -- Position cursor under first hit.
  112.  
  113. def c_q =  /* Shows the .ALL file's current line in the original file */
  114.    universal allorig,allsrch
  115. compile if EVERSION < 5
  116.    universal messy
  117. compile endif
  118.    if .filename <> '.ALL' then
  119.       getfileid allfile,'.ALL'
  120.       if allfile='' then
  121.          sayerror NO_ALL_FILE__MSG
  122.       else
  123. compile if EVERSION < 5
  124.          if messy then .box = 1; endif
  125. compile endif
  126.          activatefile allfile
  127. compile if EVERSION < 5
  128.          if messy then .box = 2; endif
  129. compile if EVERSION < 4
  130.          call select_edit_keys()
  131. compile endif
  132. compile endif
  133.                 /* Scroll the .ALL file a la FILEMAN. */
  134.          if .line=.last then
  135.             top
  136.          elseif .last <= .windowheight-2 then     /* no need to scroll */
  137.             .cursory=.cursory+1
  138.          elseif .line < .windowheight%2 then      /* no need to scroll - yet */
  139.             .cursory=.cursory+1
  140.          elseif .last-.line < .windowheight%2 then  /* === Bot === on screen */
  141.             .cursory=.cursory+1
  142.          else                                     /* Scroll ! */
  143.             '+1'
  144.             oldline=.line
  145.             .cursory=(.windowheight+1)%2     /* Center vertically */
  146.             oldline
  147.          endif
  148.          .col=6  /* Skip line number for search */
  149.          XCOM_L allsrch
  150.       endif
  151.       return
  152.    endif  /* .filename <> '.ALL' */
  153.    getline line
  154.    parse value line with line .
  155.    if not isnum(line) then
  156.       sayerror BAD_ALL_LINE__MSG
  157.       return
  158.    endif
  159. compile if EVERSION < 5
  160.    if messy then .box = 1; endif
  161. compile endif
  162.    activatefile allorig
  163. compile if EVERSION < 5
  164.    if messy then .box = 2; endif
  165.  compile if EVERSION < 4
  166.    call select_edit_keys()
  167.  compile endif
  168. compile endif
  169.    .cursory=.windowheight%2     /* Center vertically */
  170.    line
  171.    .col=1
  172.    XCOM_L allsrch
  173.