home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / GLOBCHNG.E < prev    next >
Text File  |  1994-11-15  |  3KB  |  120 lines

  1. compile if not defined(SMALL)  -- If SMALL not defined, then being separately compiled.
  2.  define INCLUDING_FILE = 'GLOBCHNG.E'
  3. const
  4.    tryinclude 'MYCNF.E'        -- the user's configuration customizations.
  5.  
  6.  compile if not defined(SITE_CONFIG)
  7.     const SITE_CONFIG = 'SITECNF.E'
  8.  compile endif
  9.  compile if SITE_CONFIG
  10.     tryinclude SITE_CONFIG
  11.  compile endif
  12.  
  13. const
  14.  compile if not defined(SETSTAY)
  15.    SETSTAY = 0
  16.  compile endif
  17.  compile if not defined(NLS_LANGUAGE)
  18.    NLS_LANGUAGE = 'ENGLISH'
  19.  compile endif
  20. include NLS_LANGUAGE'.e'
  21.  
  22. defmain     -- External modules always start execution at DEFMAIN.
  23.    'globchng' arg(1)
  24.  
  25.  compile if EVERSION >= 6
  26.    EA_comment 'This defines the GLOBCHNG command; it can be linked, or executed directly.'
  27.  compile endif
  28. compile endif  -- not defined(SMALL)
  29.  
  30. defc globchng, globalchange
  31.    universal lastchangeargs, default_search_options
  32. compile if SETSTAY='?'
  33.    universal stay
  34. compile endif
  35.  
  36.    /* Insert default_search_options just before supplied options (if any)    */
  37.    /* so the supplied options will take precedence.                          */
  38.    user_options=''
  39.    change_args=strip(arg(1),'L')  /* Delimiter = 1st char, ignoring leading spaces. */
  40.    delim=substr(change_args,1,1)
  41.    p=pos(delim, change_args, 2)   /* find last delimiter of 2 or 3 */
  42.    if p then
  43.       p=pos(delim, change_args, p+1)   /* find last delimiter of 2 or 3 */
  44.       if p>0 then
  45.          user_options=substr(change_args, p+1)
  46.          change_args=substr(change_args,1,p-1)
  47.       endif
  48.    else
  49.       sayerror NO_REP__MSG
  50.       return
  51.    endif
  52.    if verify(upcase(default_search_options),'M','M') then
  53.       user_options = 'A'user_options
  54.    endif
  55.    change_args=change_args || delim || default_search_options || user_options
  56.    backwards = 0
  57.    p1 = lastpos('-', default_search_options || user_options)
  58.    if p1 then
  59.       if p1 > lastpos('+', default_search_options || user_options) then
  60.          backwards = 1
  61.       endif
  62.    endif
  63.    reverse = 0
  64.    p1 = lastpos('R', upcase(default_search_options || user_options))
  65.    if p1 then
  66.       if p1 > lastpos('F', upcase(default_search_options || user_options)) then
  67.          reverse = 1
  68.       endif
  69.    endif
  70.  
  71.    /* Remember our current file so we don't search forever.  */
  72.    getfileid StartFileID
  73.    change_count = 0
  74.  
  75.    loop
  76.       /* Include this refresh if you like to see each file as it's */
  77.       /* searched.  Causes too much screen flashing for my taste,  */
  78. ;;       refresh
  79.  
  80.       /* Start from top of file, save current posn in case no match. */
  81.       call psave_pos(save_pos)
  82.       if backwards then
  83.          bottom
  84.          if reverse then
  85.             end_line
  86.          else
  87.             begin_line
  88.          endif
  89.       else
  90.          0
  91.       endif
  92.       'xcom c' change_args
  93.       if rc=0 then
  94.          change_count = change_count + 1
  95. compile if SETSTAY='?'
  96.          if stay then
  97. compile endif
  98. compile if SETSTAY
  99.             call prestore_pos(save_pos)
  100. compile endif
  101. compile if SETSTAY='?'
  102.          endif
  103. compile endif
  104.       else
  105.          /* no match in file - restore file location */
  106.          call prestore_pos(save_pos)
  107.       endif
  108.       nextfile
  109.       getfileid fileid
  110.       if fileid=StartFileID then
  111.          leave
  112.       endif
  113.    endloop
  114.    if change_count = 1 then
  115.       files = 'file.'
  116.    else
  117.       files = 'files.'
  118.    endif
  119.    sayerror 'String changed in' change_count files
  120.