home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / bcklib2.zip / FINDREPL.PRG < prev    next >
Text File  |  1993-01-16  |  3KB  |  124 lines

  1. /*
  2.     The source code contained within this file is protected under the
  3.     laws of the United States of America and by International Treaty.
  4.     Unless otherwise noted, the source contained herein is:
  5.  
  6.     Copyright (c)1990, 1991, 1992 BecknerVision Inc - All Rights Reserved
  7.  
  8.     Written by John Wm Beckner        THIS NOTICE MUST NOT BE REMOVED
  9.     BecknerVision Inc
  10.     PO Box 11945                      DISTRIBUTE ONLY WITH SHAREWARE
  11.     Winston-Salem NC 27116            VERSION OF THIS PRODUCT.
  12.     Fax: 919/760-1003
  13.  
  14. */
  15.  
  16. #include "beckner.inc"
  17.  
  18. * Find & Replace Global File Fixer
  19. #define False .n.
  20. #define True .y.
  21.  
  22. Static lIgnoreCase := False, cFind, cReplace, cFile := '*.PRG'
  23.  
  24. FUNCTION fFindRepl(cOpt1, cOpt2, cOpt3, cOpt4)
  25.    LOCAL lUseFile := False, aFile, SysVersion := '1.1', BakFile, cCheck, nCounter
  26.    LOCAL cTemp, cTemp2, nCtr, hnewfile
  27.    FIELD cText
  28.    ? 'Find & Replace Global File Fixer v'+SysVersion
  29.    ? 'Copyright (c)1990 John Wm Beckner - All Rights Reserved'
  30.    IF PCount()>=1
  31.       SetOption(cOpt1)
  32.    ENDIF
  33.    IF PCount()>=2
  34.       SetOption(cOpt2)
  35.    ENDIF
  36.    IF PCount()>=3
  37.       SetOption(cOpt3)
  38.    ENDIF
  39.    IF PCount()>=4
  40.       SetOption(cOpt4)
  41.    ENDIF
  42.    IF Empty(cFind) .or. Empty(cReplace)
  43.       IF !File('FINDREPL.TXT')
  44.          ? 'Invalid Parameters'
  45.          Quit
  46.       ENDIF
  47.       lUseFile := True
  48.       fCreateDBF('TempIn/cLook/C/254/cChange/C/254')
  49.       USE TempIn New
  50.       APPEND FROM FindRepl.Txt delimited
  51.    ENDIF
  52.    aFile := Directory(cFile)
  53.    fCreateDBF('Temp/cText/C/254')
  54.    USE Temp new
  55.    CLS
  56.    @ 1,0 say 'Find & Replace Global File Fixer v'+SysVersion
  57.    @ 2,0 say 'Copyright (c)1990 John Wm Beckner - All Rights Reserved'
  58.    @ 4,0 say 'Current file:'
  59.    @ 5,0 say '     Change #'
  60.    cFind    := Trim(lTrim(cFind))
  61.    cReplace := Trim(lTrim(cReplace))
  62.    FOR nCtr := 1 to len(aFile)
  63.       @ 4,14 say aFile[nCtr,1]
  64.       nCounter := 0
  65.       SET COLOR to i*
  66.       @ 24,0 say '*READING*'
  67.       APPEND FROM (aFile[nCtr,1]) sdf
  68.       SET COLOR to
  69.       @ 24,0 say space(9)
  70.       IF lUseFile
  71.          SELECT TempIn
  72.          GO TOP
  73.          WHILE !eof()
  74.             @ 5,14 say ++nCounter pict '9,999,999'
  75.             SELECT Temp
  76.             REPLACE all cText with strtran(trim(cText), alltrim(TempIn->cLook),;
  77.             alltrim(TempIn->cChange))
  78.             SELECT TempIn
  79.             SKIP
  80.          ENDWHILE
  81.       ELSE
  82.          REPLACE all cText with strtran(trim(cText), cFind, cReplace)
  83.       ENDIF
  84.       SELECT Temp
  85.       BakFile := fExtNew(aFile[nCtr,1], "BAK")
  86.       IF file(BakFile)
  87.          ERASE (BakFile)
  88.       ENDIF
  89.       RENAME (aFile[nCtr,1]) to (BakFile)
  90.       hNewFile := fcreate(aFile[nCtr,1])
  91.       GO TOP
  92.       WHILE !eof()
  93.          fwrite(hNewFile,trim(cText)+CRLF)
  94.          SKIP
  95.       ENDWHILE
  96.       fclose(hNewFile)
  97.       ZAP
  98.    NEXT
  99.    CLOSE ALL
  100.    ERASE Temp.dbf
  101.    IF lUseFile
  102.       ERASE TempIn.dbf
  103.    ENDIF
  104.    QUIT
  105. ENDFUNCTION
  106.  
  107. STATIC FUNCTION SetOption(cOption)
  108.    LOCAL cChoice
  109.    IF left(cOption,1)='/'
  110.       cOption := substr(cOption,2)
  111.    ENDIF
  112.    cChoice := upper(left(cOption,1))
  113.    cOption := substr(cOption,2)
  114.    IF cChoice="I"
  115.       lIgnoreCase := True
  116.    ELSEIF cChoice="F"
  117.       cFind       := cOption
  118.    ELSEIF cChoice="R"
  119.       cReplace    := cOption
  120.    ELSEIF cChoice="N"
  121.       cFile       := cOption
  122.    ENDIF
  123. ENDFUNCTION
  124.