home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP24.EXE / CHP2409.PRG < prev    next >
Encoding:
Text File  |  1991-04-30  |  1.9 KB  |  68 lines

  1. /*
  2.    Listing 24.9  Fix_cfg()
  3.    Author: Joe Booth
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11. //───── NOTE: must compile with the /N option!
  12.  
  13. #include "FILEIO.CH"
  14. #define  CRLF chr(13)+chr(10)
  15.  
  16. function Fix_cfg(nFiles,nBuffers)
  17. LOCAL fh,retval:=.T.,cfg_array:={},buf:="",x,k,x2
  18. LOCAL numfiles:=0,numBufs:=0
  19. if file("CONFIG.SYS")
  20.    fh := fopen("CONFIG.SYS",FO_READWRITE)
  21.    if fh > -1
  22.       buf := upper(Freadln(fh,1,80))
  23.       while !empty(buf)
  24.          x := at("FILES",buf)
  25.          if x > 0
  26.             x2       := at("=",buf)
  27.             numFiles := val(substr(buf,x2+1,25))
  28.          endif
  29.          x := at("BUFFERS",buf)
  30.          if x > 0
  31.             x2      := at("=",buf)
  32.             numBufs := val(substr(buf,x2+1,25))
  33.          endif
  34.          Aadd(cfg_array,buf)
  35.          buf := Freadln(fh,1,80)
  36.       enddo
  37.       if numFiles < nFiles .or. numBufs < nBuffers
  38.          fclose(fh)
  39.          frename('config.sys', 'config.old')
  40.          fh := fcreate("CONFIG.SYS",FC_NORMAL)
  41.          for k=1 to len(cfg_array)
  42.              x := at("FILES=",cfg_array[k])
  43.              if x > 0
  44.                 cfg_array[k] := trim("FILES="+str(nFiles,3))
  45.              endif
  46.              x := at("BUFFERS=",cfg_array[k])
  47.              if x > 0
  48.                 cfg_array[k] := trim("BUFFERS="+str(nBuffers,3))
  49.              endif
  50.              Fwriteln(fh,cfg_array[k],len(cfg_array[k])+2)
  51.          next
  52.          retval :=.F.
  53.       endif
  54.       fclose(fh)
  55.    endif
  56. else
  57.    fh := fcreate( "CONFIG.SYS",FC_NORMAL )
  58.    if fh > -1
  59.       fwrite(fh,"FILES="+str(nFiles,3)+CRLF+;
  60.                 "BUFFERS="+str(nBuffers,3)+CRLF)
  61.       fclose(fh)
  62.    endif
  63.    retval :=.F.
  64. endif
  65. return retval
  66.  
  67. // end of file CHP2409.PRG
  68.