home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 24.9 Fix_cfg()
- Author: Joe Booth
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- //───── NOTE: must compile with the /N option!
-
- #include "FILEIO.CH"
- #define CRLF chr(13)+chr(10)
-
- function Fix_cfg(nFiles,nBuffers)
- LOCAL fh,retval:=.T.,cfg_array:={},buf:="",x,k,x2
- LOCAL numfiles:=0,numBufs:=0
- if file("CONFIG.SYS")
- fh := fopen("CONFIG.SYS",FO_READWRITE)
- if fh > -1
- buf := upper(Freadln(fh,1,80))
- while !empty(buf)
- x := at("FILES",buf)
- if x > 0
- x2 := at("=",buf)
- numFiles := val(substr(buf,x2+1,25))
- endif
- x := at("BUFFERS",buf)
- if x > 0
- x2 := at("=",buf)
- numBufs := val(substr(buf,x2+1,25))
- endif
- Aadd(cfg_array,buf)
- buf := Freadln(fh,1,80)
- enddo
- if numFiles < nFiles .or. numBufs < nBuffers
- fclose(fh)
- frename('config.sys', 'config.old')
- fh := fcreate("CONFIG.SYS",FC_NORMAL)
- for k=1 to len(cfg_array)
- x := at("FILES=",cfg_array[k])
- if x > 0
- cfg_array[k] := trim("FILES="+str(nFiles,3))
- endif
- x := at("BUFFERS=",cfg_array[k])
- if x > 0
- cfg_array[k] := trim("BUFFERS="+str(nBuffers,3))
- endif
- Fwriteln(fh,cfg_array[k],len(cfg_array[k])+2)
- next
- retval :=.F.
- endif
- fclose(fh)
- endif
- else
- fh := fcreate( "CONFIG.SYS",FC_NORMAL )
- if fh > -1
- fwrite(fh,"FILES="+str(nFiles,3)+CRLF+;
- "BUFFERS="+str(nBuffers,3)+CRLF)
- fclose(fh)
- endif
- retval :=.F.
- endif
- return retval
-
- // end of file CHP2409.PRG
-