home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac.zip / ALL.E next >
Text File  |  1996-05-16  |  6KB  |  197 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' & arg(1) 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.    last_line = .last
  85.    if pos('M', upcase(DSO || user_options)) > pos('A', upcase(DSO || user_options)) then
  86.       getmark line, last_line  -- /x/m will move to start of mark if past end!
  87.    endif
  88.  
  89.    0
  90. compile if EVERSION >= 5
  91.    display -3
  92. compile endif
  93.    do forever
  94.       .col=1
  95.       'xcom l' allsrch
  96.       if rc=-273 then leave; endif  -- sayerror("String not found")
  97.       getline line
  98. compile if EVERSION >= '5.17'
  99.       line=rightstr(.line,5) line
  100. compile else
  101.       line=substr('    '.line,length(.line)) line
  102. compile endif
  103.       insertline line,allfile.last+1,allfile
  104.       if .line=last_line then leave; endif
  105.       '+1'
  106.    end
  107. compile if EVERSION >= 5
  108.    display 3
  109. compile endif
  110.    call prestore_pos(save_pos)
  111.    if allfile.last=0 then
  112.       activatefile allfile
  113.       .modify=0
  114.       'q'
  115.       activatefile allorig
  116.       sayerror -273 -- sayerror("String not found")
  117.       return
  118.    endif
  119.    sayerror 0
  120.    activatefile allfile
  121. compile if EVERSION < 4
  122.    call select_edit_keys()
  123. compile endif
  124.    sayerror 0
  125.    .modify=0; top; .col=7
  126. compile if EVERSION < 5
  127.    cursor_data
  128.    XCOM_L allsrch'A'  -- Position cursor under first hit.
  129. compile else  -- Use PostMe to delay execution until after DEFLOAD sets font
  130.    'postme' XCOM_L allsrch'A'  -- Position cursor under first hit.
  131. compile endif
  132.  
  133. compile if not defined(ALL_KEY)
  134. define ALL_KEY = 'c_Q'
  135. compile endif
  136.  
  137. def $ALL_KEY =      -- Shows the .ALL file's current line in the original file
  138.    universal allorig,allsrch
  139. compile if EVERSION < 5
  140.    universal messy
  141. compile endif
  142.    if .filename <> '.ALL' then
  143.       getfileid allfile,'.ALL'
  144.       if allfile='' then
  145.          sayerror NO_ALL_FILE__MSG
  146.       else
  147. compile if EVERSION < 5
  148.          if messy then .box = 1; endif
  149. compile endif
  150.          activatefile allfile
  151. compile if EVERSION < 5
  152.          if messy then .box = 2; endif
  153. compile if EVERSION < 4
  154.          call select_edit_keys()
  155. compile endif
  156. compile endif
  157.                 /* Scroll the .ALL file a la FILEMAN. */
  158.          if .line=.last then
  159.             top
  160.          elseif .last <= .windowheight-2 then     /* no need to scroll */
  161.             .cursory=.cursory+1
  162.          elseif .line < .windowheight%2 then      /* no need to scroll - yet */
  163.             .cursory=.cursory+1
  164.          elseif .last-.line < .windowheight%2 then  /* === Bot === on screen */
  165.             .cursory=.cursory+1
  166.          else                                     /* Scroll ! */
  167.             '+1'
  168.             oldline=.line
  169.             .cursory=(.windowheight+1)%2     /* Center vertically */
  170.             oldline
  171.          endif
  172.          .col=6  /* Skip line number for search */
  173.          XCOM_L allsrch'A'
  174.       endif
  175.       return
  176.    endif  /* .filename <> '.ALL' */
  177.    getline line
  178.    parse value line with line .
  179.    if not isnum(line) then
  180.       sayerror BAD_ALL_LINE__MSG
  181.       return
  182.    endif
  183. compile if EVERSION < 5
  184.    if messy then .box = 1; endif
  185. compile endif
  186.    activatefile allorig
  187. compile if EVERSION < 5
  188.    if messy then .box = 2; endif
  189.  compile if EVERSION < 4
  190.    call select_edit_keys()
  191.  compile endif
  192. compile endif
  193.    .cursory=.windowheight%2     /* Center vertically */
  194.    line
  195.    .col=1
  196.    XCOM_L allsrch'A'
  197.