home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / editor / epmtools / epmmac / all.e next >
Text File  |  1993-03-31  |  6KB  |  186 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.  define INCLUDING_FILE = 'ALL.E'
  15. const
  16.    tryinclude 'MYCNF.E'
  17.  compile if not defined(SITE_CONFIG)
  18.     const SITE_CONFIG = 'SITECNF.E'
  19.  compile endif
  20.  compile if SITE_CONFIG
  21.     tryinclude SITE_CONFIG
  22.  compile endif
  23. const
  24.  compile if not defined(NLS_LANGUAGE)
  25.    NLS_LANGUAGE = 'ENGLISH'
  26.  compile endif
  27.  include NLS_LANGUAGE'.e'
  28.  
  29. defmain
  30.    'all' arg(1)
  31. compile endif
  32.  
  33. define
  34.  compile if defined(HIGHLIGHT_COLOR)
  35.    XCOM_L = 'L'            -- Do a DEFC L, so that the string gets highlighted.
  36.  compile else
  37.    XCOM_L = 'XCOM L'       -- Otherwise, use the faster internal locate command
  38.  compile endif
  39.  
  40. defc all=   /* ALL macro */
  41.    universal allorig,allsrch,default_search_options
  42.    call psave_pos(save_pos)
  43. compile if EVERSION < 5
  44.    cursor_data
  45. compile endif
  46.    if .filename = '.ALL' then
  47.       .filename = '.prev_ALL'
  48.    endif
  49.    getfileid allorig
  50.    'e /q /n .ALL'    /* Don't use XCOM so can handle either windowing style */
  51.    .filename = '.ALL'
  52.    getfileid allfile
  53.    allsrch=strip(arg(1),'L')
  54.    if allsrch='' then
  55.       .modify=0
  56.       'q'
  57.       if allorig<>allfile then activatefile allorig; endif
  58.       sayerror 1
  59.       return
  60.    endif
  61.    for i=1 to .last
  62.       deleteline 1
  63.    endfor
  64.    activatefile allorig
  65.  
  66.     /* Copied from DEFC L - we only will use E or C (case) and A or M (mark)  */
  67.     DSO=''   /* subset of default_search_options */
  68.     do i=1 to length(default_search_options)
  69.        ch=substr(default_search_options,i,1)
  70.        if pos(ch,'EeCcAaMm')>0 then DSO=DSO || ch endif
  71.     end
  72.     /* Insert default_search_options just before supplied options (if any)    */
  73.     /* so the supplied options will take precedence.                          */
  74.     if DSO then
  75.        ch=substr(allsrch,1,1)
  76.        p=pos(ch,allsrch,2)
  77.        user_options=''
  78.        if p>0 then
  79.           user_options=substr(allsrch,p+1)
  80.           allsrch=substr(allsrch,1,p-1)
  81.        endif
  82.        allsrch=allsrch||ch||DSO||user_options
  83.     endif
  84.  
  85.    0
  86. compile if EVERSION >= 5
  87.    display -3
  88. compile endif
  89.    do forever
  90.       .col=1
  91.       'xcom l' allsrch
  92.       if rc=-273 then leave; endif  -- sayerror("String not found")
  93.       getline line
  94. compile if EVERSION >= '5.17'
  95.       line=rightstr(.line,5) line
  96. compile else
  97.       line=substr('    '.line,length(.line)) line
  98. compile endif
  99.       insertline line,allfile.last+1,allfile
  100.       if .line=.last then leave; endif
  101.       '+1'
  102.    end
  103. compile if EVERSION >= 5
  104.    display 3
  105. compile endif
  106.    call prestore_pos(save_pos)
  107.    if allfile.last=0 then
  108.       activatefile allfile
  109.       .modify=0
  110.       'q'
  111.       activatefile allorig
  112.       return
  113.    endif
  114.    sayerror 0
  115.    activatefile allfile
  116. compile if EVERSION < 4
  117.    call select_edit_keys()
  118. compile endif
  119.    sayerror 0
  120.    .modify=0; top; .col=6
  121. compile if EVERSION < 5
  122.    cursor_data
  123. compile endif
  124.    XCOM_L allsrch  -- Position cursor under first hit.
  125.  
  126. def c_q =  /* Shows the .ALL file's current line in the original file */
  127.    universal allorig,allsrch
  128. compile if EVERSION < 5
  129.    universal messy
  130. compile endif
  131.    if .filename <> '.ALL' then
  132.       getfileid allfile,'.ALL'
  133.       if allfile='' then
  134.          sayerror NO_ALL_FILE__MSG
  135.       else
  136. compile if EVERSION < 5
  137.          if messy then .box = 1; endif
  138. compile endif
  139.          activatefile allfile
  140. compile if EVERSION < 5
  141.          if messy then .box = 2; endif
  142. compile if EVERSION < 4
  143.          call select_edit_keys()
  144. compile endif
  145. compile endif
  146.                 /* Scroll the .ALL file a la FILEMAN. */
  147.          if .line=.last then
  148.             top
  149.          elseif .last <= .windowheight-2 then     /* no need to scroll */
  150.             .cursory=.cursory+1
  151.          elseif .line < .windowheight%2 then      /* no need to scroll - yet */
  152.             .cursory=.cursory+1
  153.          elseif .last-.line < .windowheight%2 then  /* === Bot === on screen */
  154.             .cursory=.cursory+1
  155.          else                                     /* Scroll ! */
  156.             '+1'
  157.             oldline=.line
  158.             .cursory=(.windowheight+1)%2     /* Center vertically */
  159.             oldline
  160.          endif
  161.          .col=6  /* Skip line number for search */
  162.          XCOM_L allsrch
  163.       endif
  164.       return
  165.    endif  /* .filename <> '.ALL' */
  166.    getline line
  167.    parse value line with line .
  168.    if not isnum(line) then
  169.       sayerror BAD_ALL_LINE__MSG
  170.       return
  171.    endif
  172. compile if EVERSION < 5
  173.    if messy then .box = 1; endif
  174. compile endif
  175.    activatefile allorig
  176. compile if EVERSION < 5
  177.    if messy then .box = 2; endif
  178.  compile if EVERSION < 4
  179.    call select_edit_keys()
  180.  compile endif
  181. compile endif
  182.    .cursory=.windowheight%2     /* Center vertically */
  183.    line
  184.    .col=1
  185.    XCOM_L allsrch
  186.