home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a075 / 1.img / TOOLKIT1.EXE / SST91.PRG < prev    next >
Encoding:
Text File  |  1989-08-08  |  1.6 KB  |  57 lines

  1. ********************
  2.  
  3. FUNCTION Modi_auto
  4.  
  5.    PARAMETERS _a, _b
  6.  
  7.    * _a is the string to search for in the AUTOEXEC.BAT
  8.    *    is the string to replace that entire line that is found
  9.    *    if !FOUND(), then add the line to the file
  10.    * _b is the drive to look for AUTOEXEC.BAT
  11.  
  12.    IF PCOUNT() = 1
  13.       _b = "C:"
  14.    ENDIF
  15.  
  16.    IF TYPE("_a") + TYPE("_b") != "CC"
  17.       RETURN(.F.)
  18.    ELSEIF LEN(_b) != 2
  19.       RETURN(.F.)
  20.    ELSEIF !FILE(_b + "\AUTOEXEC.BAT")
  21.       RETURN(.F.)
  22.    ENDIF
  23.  
  24.    PRIVATE _temp, _search, _c, _passback
  25.  
  26.    _temp = MEMOREAD(_b + "\AUTOEXEC.BAT")
  27.  
  28.    MEMOWRIT(_b + "\AUTOEXEC.SST", _temp)
  29.  
  30.    _search = UPPER(Parsing(@_a))
  31.    IF EMPTY(Occurence(_search, _temp))
  32.       * Just append the line to the end of the file
  33.       MEMOWRIT(_b + "\AUTOEXEC.BAT", STRTRAN(TRIM(_temp) + _a, ;
  34.                CHR(13)+CHR(10)+CHR(13)+CHR(10), CHR(13)+CHR(10)))
  35.       _passback = .T.
  36.    ELSE
  37.       * first, check to see if the line contents are the same with the
  38.       * contents of _a and if so, just return (.T.) without writing back
  39.       * the file.  Otherwise, write out a new file by replacing the line
  40.       * with the contents of _a
  41.       _c = TRIM(Parsing(STRTRAN(Occur_at(_search, UPPER(_temp) ), ;
  42.                 CHR(13)+CHR(10), "|"), "|"))
  43.       IF _c != TRIM(_a)
  44.          _temp = STRTRAN(UPPER(_temp), UPPER(_c), UPPER(_a))
  45.          MEMOWRIT(_b + "\AUTOEXEC.BAT", STRTRAN(TRIM(_temp), ;
  46.                   CHR(13)+CHR(10)+CHR(13)+CHR(10), CHR(13)+CHR(10)) )
  47.          _passback = .T.
  48.       ELSE
  49.          _passback = .F.
  50.       ENDIF
  51.    ENDIF
  52.    RETURN(_passback)
  53.  
  54. * End of File
  55.  
  56.  
  57.