home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / e / epmmac2.zip / ALL.E next >
Text File  |  1992-12-18  |  6KB  |  183 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.    getfileid allorig
  47.    'e /q /n .ALL'    /* Don't use XCOM so can handle either windowing style */
  48.    .filename = '.ALL'
  49.    getfileid allfile
  50.    allsrch=strip(arg(1),'L')
  51.    if allsrch='' then
  52.       .modify=0
  53.       'q'
  54.       if allorig<>allfile then activatefile allorig; endif
  55.       sayerror 1
  56.       return
  57.    endif
  58.    for i=1 to .last
  59.       deleteline 1
  60.    endfor
  61.    activatefile allorig
  62.  
  63.     /* Copied from DEFC L - we only will use E or C (case) and A or M (mark)  */
  64.     DSO=''   /* subset of default_search_options */
  65.     do i=1 to length(default_search_options)
  66.        ch=substr(default_search_options,i,1)
  67.        if pos(ch,'EeCcAaMm')>0 then DSO=DSO || ch endif
  68.     end
  69.     /* Insert default_search_options just before supplied options (if any)    */
  70.     /* so the supplied options will take precedence.                          */
  71.     if DSO then
  72.        ch=substr(allsrch,1,1)
  73.        p=pos(ch,allsrch,2)
  74.        user_options=''
  75.        if p>0 then
  76.           user_options=substr(allsrch,p+1)
  77.           allsrch=substr(allsrch,1,p-1)
  78.        endif
  79.        allsrch=allsrch||ch||DSO||user_options
  80.     endif
  81.  
  82.    0
  83. compile if EVERSION >= 5
  84.    display -2
  85. compile endif
  86.    do forever
  87.       .col=1
  88.       'xcom l' allsrch
  89.       if rc=-273 then leave; endif  -- sayerror("String not found")
  90.       getline line
  91. compile if EVERSION >= '5.17'
  92.       line=rightstr(.line,5) line
  93. compile else
  94.       line=substr('    '.line,length(.line)) line
  95. compile endif
  96.       insertline line,allfile.last+1,allfile
  97.       if .line=.last then leave; endif
  98.       '+1'
  99.    end
  100. compile if EVERSION >= 5
  101.    display 2
  102. compile endif
  103.    call prestore_pos(save_pos)
  104.    if allfile.last=0 then
  105.       activatefile allfile
  106.       .modify=0
  107.       'q'
  108.       activatefile allorig
  109.       return
  110.    endif
  111.    sayerror 0
  112.    activatefile allfile
  113. compile if EVERSION < 4
  114.    call select_edit_keys()
  115. compile endif
  116.    sayerror 0
  117.    .modify=0; top; .col=6
  118. compile if EVERSION < 5
  119.    cursor_data
  120. compile endif
  121.    XCOM_L allsrch  -- Position cursor under first hit.
  122.  
  123. def c_q =  /* Shows the .ALL file's current line in the original file */
  124.    universal allorig,allsrch
  125. compile if EVERSION < 5
  126.    universal messy
  127. compile endif
  128.    if .filename <> '.ALL' then
  129.       getfileid allfile,'.ALL'
  130.       if allfile='' then
  131.          sayerror NO_ALL_FILE__MSG
  132.       else
  133. compile if EVERSION < 5
  134.          if messy then .box = 1; endif
  135. compile endif
  136.          activatefile allfile
  137. compile if EVERSION < 5
  138.          if messy then .box = 2; endif
  139. compile if EVERSION < 4
  140.          call select_edit_keys()
  141. compile endif
  142. compile endif
  143.                 /* Scroll the .ALL file a la FILEMAN. */
  144.          if .line=.last then
  145.             top
  146.          elseif .last <= .windowheight-2 then     /* no need to scroll */
  147.             .cursory=.cursory+1
  148.          elseif .line < .windowheight%2 then      /* no need to scroll - yet */
  149.             .cursory=.cursory+1
  150.          elseif .last-.line < .windowheight%2 then  /* === Bot === on screen */
  151.             .cursory=.cursory+1
  152.          else                                     /* Scroll ! */
  153.             '+1'
  154.             oldline=.line
  155.             .cursory=(.windowheight+1)%2     /* Center vertically */
  156.             oldline
  157.          endif
  158.          .col=6  /* Skip line number for search */
  159.          XCOM_L allsrch
  160.       endif
  161.       return
  162.    endif  /* .filename <> '.ALL' */
  163.    getline line
  164.    parse value line with line .
  165.    if not isnum(line) then
  166.       sayerror BAD_ALL_LINE__MSG
  167.       return
  168.    endif
  169. compile if EVERSION < 5
  170.    if messy then .box = 1; endif
  171. compile endif
  172.    activatefile allorig
  173. compile if EVERSION < 5
  174.    if messy then .box = 2; endif
  175.  compile if EVERSION < 4
  176.    call select_edit_keys()
  177.  compile endif
  178. compile endif
  179.    .cursory=.windowheight%2     /* Center vertically */
  180.    line
  181.    .col=1
  182.    XCOM_L allsrch
  183.