home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a067 / 1.img / GRUMP501.EXE / ISCONFIG.PRG < prev    next >
Encoding:
Text File  |  1991-04-24  |  6.4 KB  |  178 lines

  1. /*
  2.     Function: IsConfig()
  3.     System: GRUMPFISH LIBRARY
  4.     Author: Greg Lief - inspired by Eric Lewis
  5.     Copyright (c) 1990 - All Rights Reserved
  6.     Clipper 5.x version
  7.     Compile instructions: clipper isconfig /n/w/a
  8.  
  9.     Checks either CONFIG.SYS or SHELL.CFG file for either
  10.     FILES / FILE HANDLES and/or BUFFERS / CACHE BUFFERS statements
  11.  
  12.     Calls: GFReadLine()   (function contained in READLINE.PRG)
  13.          : Yes_No()       (function contained in YESNO.PRG)
  14.          : WaitOn()       (function contained in WAITING.PRG)
  15.          : ShadowBox()    (function contained in SHADOWBO.PRG)
  16.          : ByeByeBox()    (function contained in BYEBYE.PRG)
  17. */
  18.  
  19. //───── begin preprocessor directives
  20.  
  21. #include "grump.ch"
  22. #include "fileio.ch"
  23.  
  24. //───── end preprocessor directives
  25.  
  26. function isconfig(cfile, nfiles, nbuffers)
  27. local drive, no_files := .t., no_buffers := .t., ret_val := .t., ;
  28.       string := [ ], inhandle, outhandle, buffer, filestring, ;
  29.       buffstring, oldexact
  30. GFSaveEnv()
  31. oldexact := set(_SET_EXACT, .f.)    // turn off SET EXACT
  32. cfile := if(cfile == NIL, "CONFIG.SYS", ;
  33.          if(! upper(cfile) $ "CONFIG.SYSSHELL.CFG", "CONFIG.SYS", upper(cfile)))
  34. default nfiles to 50
  35. default nbuffers to 10
  36. filestring := "FILE" + if(cfile = "CONFIG.SYS", "S", " HANDLES")
  37. buffstring := if(cfile = "SHELL.CFG", "CACHE ", "") + "BUFFERS"
  38.  
  39. //───── determine which drive is the booting drive by looking at the comspec.
  40. drive := substr(gete("COMSPEC"), 1, at(":", gete("COMSPEC")) - 1)
  41. if file(drive + ":\" + cfile)
  42.  
  43.    //───── read in from the config.sys file out to the temp.sys file
  44.    inhandle := fopen(drive + ":\" + cfile, FO_READWRITE)
  45.    outhandle := fcreate(drive + ":\TEMP.CFG", FC_NORMAL)
  46.  
  47.    do while gfreadline(@string, inhandle)
  48.  
  49.       //───── check for the files and/or buffers lines and the correct number
  50.       do case
  51.          case filestring $ upper(string)
  52.             //───── check not only for adequate # of files, but that this
  53.             //───── line begins with the word FILES or FILE HANDLES
  54.             if upper(string) != filestring .or. ;
  55.                     val(substr(string, at("=", string) + 1)) < nfiles
  56.                //───── write a new "FILE HANDLES=" line
  57.                fwrite(outhandle, filestring + "=" + ltrim(str(nfiles)) + CRLF)
  58.                ret_val := .f.
  59.             else
  60.                fwrite(outhandle, string + CRLF)
  61.             endif
  62.             no_files := .f.
  63.  
  64.          case buffstring $ upper(string)
  65.             //───── check not only for adequate # of buffers, but that this
  66.             //───── line begins with the word BUFFERS or CACHE BUFFERS
  67.             if upper(string) != buffstring .or. ;
  68.                      val(substr(string, at("=", string) + 1)) < nbuffers
  69.                //───── check to see if using Expanded Memory switch ("/X")
  70.                buffer := "/X" $ UPPER(string)
  71.                //───── Write a new "BUFFERS=" line
  72.                FWRITE(outhandle, buffstring + "=" + LTRIM(STR(nbuffers)) + ;
  73.                       IF(buffer, " /X", "") + CRLF)
  74.                ret_val := .f.
  75.             else
  76.                fwrite(outhandle, string + CRLF)
  77.             endif
  78.             no_buffers := .f.
  79.  
  80.          otherwise
  81.             //───── write the string out to the new file
  82.             if string != chr(26)
  83.                fwrite(outhandle, string + CRLF)
  84.             endif
  85.       endcase
  86.    enddo
  87.  
  88.    if no_files .or. no_buffers
  89.       //───── move to the end of the file less two bytes
  90.       //───── if the file ends with a cr/lf, erase them
  91.       fseek(outhandle, -2, FS_END)
  92.       //───── if the file does not end with a cr/lf, skip to the very end
  93.       string := freadstr(outhandle, 2)
  94.       if string != CRLF
  95.          fseek(outhandle, 2, FS_RELATIVE)
  96.       endif
  97.  
  98.       //───── check to see if a file handles= line was found
  99.       if no_files
  100.          //───── write a new "file handles=" line
  101.          fwrite(outhandle, filestring + "=" + ltrim(str(nfiles)) + CRLF)
  102.          ret_val := .f.
  103.       endif
  104.  
  105.       //───── check to see if a buffers= line was found
  106.       if no_buffers
  107.          //───── write a new cache buffers= line
  108.          fwrite(outhandle, buffstring + "=" + ltrim(str(nbuffers)) + CRLF)
  109.          ret_val := .f.
  110.       endif
  111.    endif
  112.  
  113.    //───── close the input file
  114.    fclose(inhandle)
  115.  
  116.    //───── check to see if the file needs an eof
  117.    fseek(outhandle, 0, 2)
  118.    if freadstr(outhandle, 1) != chr(26)
  119.       fwrite(outhandle, chr(26))
  120.    endif
  121.  
  122.    //───── close the output file
  123.    fclose(outhandle)
  124.  
  125.    //───── confirm copy
  126.    if ! ret_val
  127.       if yes_no2( { cfile + " requires changes in order to run this program", ;
  128.                     "Would you like me to make these changes now?" }, , ;
  129.                     " Change " + cfile, " Ignore ")
  130.          frename(drive + ":\" + cfile, drive + ":\" + ;
  131.                    substr(cfile, 1, at(".", cfile) - 1) + ".bak")
  132.          frename(drive + ":\temp.cfg", drive + ":\" + cfile)
  133.       else
  134.          ret_val := .t.
  135.          waiton( { "The " + cfile + " file must contain the following lines:", ;
  136.                    "'" + filestring + "=" + ltrim(str(nfiles)) + "'", ;
  137.                    "'" + buffstring + "=" + ltrim(str(nbuffers)) + "'" } )
  138.          inkey(5)
  139.          waiton(.F.)
  140.       endif
  141.       ferase(drive + ":\temp.cfg")
  142.    endif
  143. else
  144.    //───── the file does not exist, so create one
  145.    outhandle := fcreate(drive + ":\" + cfile, FC_NORMAL)
  146.    fwrite(outhandle, filestring + "=" + ltrim(str(nfiles)) + CRLF + ;
  147.                      buffstring + "=" + ltrim(str(nbuffers)) + CRLF)
  148.    ret_val := .f.
  149.  
  150.    //───── check to see if the file needs an eof
  151.    fseek(outhandle, 0, 2)
  152.    if freadstr(outhandle, 1) != chr(26)
  153.       fwrite(outhandle, chr(26))
  154.    endif
  155.  
  156.    //───── close the output file
  157.    fclose(outhandle)
  158. endif
  159.  
  160. if ! ret_val
  161.    ColorSet(C_MESSAGE)
  162.    buffer := ShadowBox(10, 0, 14, 79, 2)
  163.    SCRNCENTER(11, "Changes have been to the " + cfile + " file." )
  164.    SCRNCENTER(11, "Please restart the computer by turning it off")
  165.    SCRNCENTER(12, "or pressing Ctrl-Alt-Del at the same time.")
  166.    SCRNCENTER(13, "Then start this program again.")
  167.    ginkey(0)
  168.    ByeByeBox(buffer)
  169. endif
  170. GFRestEnv()
  171. set(_SET_EXACT, oldexact)    // restore previous SET EXACT setting
  172. return ret_val
  173.  
  174. * end function IsConfig()
  175. *--------------------------------------------------------------------*
  176.  
  177. * eof isconfig.prg
  178.