home *** CD-ROM | disk | FTP | other *** search
- /*
- Function: IsConfig()
- System: GRUMPFISH LIBRARY
- Author: Greg Lief - inspired by Eric Lewis
- Copyright (c) 1990 - All Rights Reserved
- Clipper 5.x version
- Compile instructions: clipper isconfig /n/w/a
-
- Checks either CONFIG.SYS or SHELL.CFG file for either
- FILES / FILE HANDLES and/or BUFFERS / CACHE BUFFERS statements
-
- Calls: GFReadLine() (function contained in READLINE.PRG)
- : Yes_No() (function contained in YESNO.PRG)
- : WaitOn() (function contained in WAITING.PRG)
- : ShadowBox() (function contained in SHADOWBO.PRG)
- : ByeByeBox() (function contained in BYEBYE.PRG)
- */
-
- //───── begin preprocessor directives
-
- #include "grump.ch"
- #include "fileio.ch"
-
- //───── end preprocessor directives
-
- function isconfig(cfile, nfiles, nbuffers)
- local drive, no_files := .t., no_buffers := .t., ret_val := .t., ;
- string := [ ], inhandle, outhandle, buffer, filestring, ;
- buffstring, oldexact
- GFSaveEnv()
- oldexact := set(_SET_EXACT, .f.) // turn off SET EXACT
- cfile := if(cfile == NIL, "CONFIG.SYS", ;
- if(! upper(cfile) $ "CONFIG.SYSSHELL.CFG", "CONFIG.SYS", upper(cfile)))
- default nfiles to 50
- default nbuffers to 10
- filestring := "FILE" + if(cfile = "CONFIG.SYS", "S", " HANDLES")
- buffstring := if(cfile = "SHELL.CFG", "CACHE ", "") + "BUFFERS"
-
- //───── determine which drive is the booting drive by looking at the comspec.
- drive := substr(gete("COMSPEC"), 1, at(":", gete("COMSPEC")) - 1)
- if file(drive + ":\" + cfile)
-
- //───── read in from the config.sys file out to the temp.sys file
- inhandle := fopen(drive + ":\" + cfile, FO_READWRITE)
- outhandle := fcreate(drive + ":\TEMP.CFG", FC_NORMAL)
-
- do while gfreadline(@string, inhandle)
-
- //───── check for the files and/or buffers lines and the correct number
- do case
- case filestring $ upper(string)
- //───── check not only for adequate # of files, but that this
- //───── line begins with the word FILES or FILE HANDLES
- if upper(string) != filestring .or. ;
- val(substr(string, at("=", string) + 1)) < nfiles
- //───── write a new "FILE HANDLES=" line
- fwrite(outhandle, filestring + "=" + ltrim(str(nfiles)) + CRLF)
- ret_val := .f.
- else
- fwrite(outhandle, string + CRLF)
- endif
- no_files := .f.
-
- case buffstring $ upper(string)
- //───── check not only for adequate # of buffers, but that this
- //───── line begins with the word BUFFERS or CACHE BUFFERS
- if upper(string) != buffstring .or. ;
- val(substr(string, at("=", string) + 1)) < nbuffers
- //───── check to see if using Expanded Memory switch ("/X")
- buffer := "/X" $ UPPER(string)
- //───── Write a new "BUFFERS=" line
- FWRITE(outhandle, buffstring + "=" + LTRIM(STR(nbuffers)) + ;
- IF(buffer, " /X", "") + CRLF)
- ret_val := .f.
- else
- fwrite(outhandle, string + CRLF)
- endif
- no_buffers := .f.
-
- otherwise
- //───── write the string out to the new file
- if string != chr(26)
- fwrite(outhandle, string + CRLF)
- endif
- endcase
- enddo
-
- if no_files .or. no_buffers
- //───── move to the end of the file less two bytes
- //───── if the file ends with a cr/lf, erase them
- fseek(outhandle, -2, FS_END)
- //───── if the file does not end with a cr/lf, skip to the very end
- string := freadstr(outhandle, 2)
- if string != CRLF
- fseek(outhandle, 2, FS_RELATIVE)
- endif
-
- //───── check to see if a file handles= line was found
- if no_files
- //───── write a new "file handles=" line
- fwrite(outhandle, filestring + "=" + ltrim(str(nfiles)) + CRLF)
- ret_val := .f.
- endif
-
- //───── check to see if a buffers= line was found
- if no_buffers
- //───── write a new cache buffers= line
- fwrite(outhandle, buffstring + "=" + ltrim(str(nbuffers)) + CRLF)
- ret_val := .f.
- endif
- endif
-
- //───── close the input file
- fclose(inhandle)
-
- //───── check to see if the file needs an eof
- fseek(outhandle, 0, 2)
- if freadstr(outhandle, 1) != chr(26)
- fwrite(outhandle, chr(26))
- endif
-
- //───── close the output file
- fclose(outhandle)
-
- //───── confirm copy
- if ! ret_val
- if yes_no2( { cfile + " requires changes in order to run this program", ;
- "Would you like me to make these changes now?" }, , ;
- " Change " + cfile, " Ignore ")
- frename(drive + ":\" + cfile, drive + ":\" + ;
- substr(cfile, 1, at(".", cfile) - 1) + ".bak")
- frename(drive + ":\temp.cfg", drive + ":\" + cfile)
- else
- ret_val := .t.
- waiton( { "The " + cfile + " file must contain the following lines:", ;
- "'" + filestring + "=" + ltrim(str(nfiles)) + "'", ;
- "'" + buffstring + "=" + ltrim(str(nbuffers)) + "'" } )
- inkey(5)
- waiton(.F.)
- endif
- ferase(drive + ":\temp.cfg")
- endif
- else
- //───── the file does not exist, so create one
- outhandle := fcreate(drive + ":\" + cfile, FC_NORMAL)
- fwrite(outhandle, filestring + "=" + ltrim(str(nfiles)) + CRLF + ;
- buffstring + "=" + ltrim(str(nbuffers)) + CRLF)
- ret_val := .f.
-
- //───── check to see if the file needs an eof
- fseek(outhandle, 0, 2)
- if freadstr(outhandle, 1) != chr(26)
- fwrite(outhandle, chr(26))
- endif
-
- //───── close the output file
- fclose(outhandle)
- endif
-
- if ! ret_val
- ColorSet(C_MESSAGE)
- buffer := ShadowBox(10, 0, 14, 79, 2)
- SCRNCENTER(11, "Changes have been to the " + cfile + " file." )
- SCRNCENTER(11, "Please restart the computer by turning it off")
- SCRNCENTER(12, "or pressing Ctrl-Alt-Del at the same time.")
- SCRNCENTER(13, "Then start this program again.")
- ginkey(0)
- ByeByeBox(buffer)
- endif
- GFRestEnv()
- set(_SET_EXACT, oldexact) // restore previous SET EXACT setting
- return ret_val
-
- * end function IsConfig()
- *--------------------------------------------------------------------*
-
- * eof isconfig.prg
-