home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / PROGRAMM / BUILDER.ZIP / CHCON2.BLD < prev    next >
Text File  |  1992-11-17  |  4KB  |  120 lines

  1. '==================================================================
  2. ' CHCON2.BLD
  3. '
  4. ' What it does:
  5. '   Like CHCON1.BLD but shows everything and lets user decide.
  6. '   Demonstrates the ability of a Builder program to alter the
  7. '   contents of CONFIG.SYS (doesn't actually change CONFIG.SYS;
  8. '   it copies CONFIG.SYS to a file called TEST.TMP and makes the
  9. '   changes to that file).  Cruises through CONFIG.SYS and looks
  10. '   for a "FILES=" line.  Displays the contents of CONFIG.SYS in a
  11. '   box as it goes.  When the "FILES=" line is found, the program
  12. '   creates a second box below the first, showing the new proposed
  13. '   line (which contains "FILES=50"), and asks if the new line
  14. '   should be written out.  Writes that line to the new file if
  15. '   user inputs {Y}.  Creates a new TEST.TMP file, which you
  16. '   would in practice copy to CONFIG.SYS.
  17. '
  18. ' Tested using:
  19. '   Builder 1.21
  20. '
  21. ' By:
  22. '   Tom Campbell
  23. '
  24. '==================================================================
  25.  
  26.  
  27. ' CHCONFIG.BLD
  28. ' Reads CONFIG.SYS and copies is output to TEST.TMP.
  29. ' When it finds a line with "FILES=", it changes the line to FILES=50.
  30.  
  31.  
  32. ' Descriptors for the input file (CONFIG.SYS)
  33. ' and the output file (TEST.TMP)
  34. File InFile, OutFile
  35.  
  36. ' Original holds each line as it's read from the file; Upper is
  37. ' its uppercase version.
  38. ' RevisedLine is the text the line will be changed to.
  39. String Original, RevisedLine, Upper
  40.  
  41. ' DoChange is set to 1 if user decided to change file, and cleared
  42. ' to 0 if not.  Its value is relevant only if CONFIG.SYS was
  43. ' found.
  44. ' FoundIt is 0 until the "FILES=" line is found. When it is,
  45. ' FoundIt is set to 1.
  46. Integer DoChange, FoundIt
  47.  
  48. cls
  49.  
  50. ' Draw the top box, which shows the original file.
  51. Single box 5, 10, 60, 5 white on black
  52.  
  53. ' Assume the line with "FILES=" isn't in the file.
  54. Put 0 into FoundIt
  55. Put 0 into DoChange
  56. Put "FILES=50" into RevisedLine
  57.  
  58. ' Quit if CONFIG.SYS isn't available.  Set ERRORLEVEL to 1, which
  59. ' traditionally means an error has occurred, on exit.
  60. if not exist "C:\CONFIG.SYS" exit 1
  61.  
  62. ' Make CONFIG.SYS available for file operations.
  63. Open "C:\CONFIG.SYS" for reading as InFile
  64. ' It will be copied to TEST.TMP, except for the "FILES=" line, which
  65. ' will be replaced with RevisedLine.
  66. Open "TEST.TMP" for writing as OutFile
  67.  
  68. ' This loop continues as long as there are lines in CONFIG.SYS.
  69. While not eof InFile
  70.   ' Get the next line from "CONFIG.SYS".
  71.   ReadLine Original from InFile
  72.   ' Clear a line in the box.
  73.   say @ 7, 11 "                                                       "
  74.   ' Display the line to be changed.
  75.   say @ 7, 11 Original;
  76.   ' Copy it to the string var Upper, forcing it to uppercase.
  77.   Put UpperCase Original into Upper
  78.   ' See if it's the line in question.
  79.   If Upper contains "FILES="
  80.     ' Note that the line was found.
  81.     Put 1 into FoundIt
  82.     ' Title over the box.
  83.     say @ 4, 11 "Line to be changed:";
  84.     ' Draw the bottom box, which shows the new line.
  85.     Double box 15, 10, 60, 5 white on black
  86.     ' Display box title.
  87.     say @ 14, 11 "Proposed change:"
  88.     ' Display text to replace the old text.
  89.     say @ 17, 11 RevisedLine
  90.     ' Ask user if it should be changed.
  91.     Say @ 22, 10 "Would you like to change it? ";
  92.     GetYN
  93.     ' ERRORLEVEL is set to 1 if user types {Y}, 0 if user types {N}.
  94.     if DOSErrorLevel is 1
  95.       ' User typed {Y}.
  96.       DoChange := 1
  97.       ' Write the new line to the file.
  98.       WriteLine RevisedLine to OutFile
  99.     end else
  100.       ' User typed {N}.  Don't continue.
  101.       DoChange := 0
  102.     end
  103.   end else
  104.     ' Not the right line.  Copy it to "TEST.TMP" unchanged.
  105.     ' This occurs every time a line that does *not* contain "FILES=" is
  106.     ' read from the original CONFIG.SYS.
  107.     WriteLine Original to OutFile
  108.   End ' If
  109. End ' While
  110. ' Return file resources to DOS.
  111. Close InFile
  112. Close OutFile
  113.   ' Explain whether the mission was successful.pressed
  114.   if DoChange is 1
  115.     say @ 22, 10 "Successful--was able to alter CONFIG.SYS.";
  116.   end else
  117.     say @ 22, 10 "CONFIG.SYS was not changed."
  118.   end
  119.  
  120.