home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / GCINI.ZIP / GCINI.CMD next >
OS/2 REXX Batch file  |  1992-11-30  |  4KB  |  101 lines

  1. /***  gcIni.Cmd:  garbage collection on an .INI file  ***/
  2. /***  Written by John S. Givler, givler@watson.ibm.com ***/
  3. /***  Version 1.0a ***/
  4. if arg(1) = '?' | arg(1) = '/?' | arg(1) = '-?' then
  5.    do
  6.       /* NB. [] are square brackets, denoting optional parameters */
  7.       say "      Syntax:  gcIni [InputFileName [OutputFileName]]"
  8.       say " "
  9.       say "The active Group/Name/Value triples in the input file will be copied"
  10.       say "to the output file.  The input file is NOT modified by this program."
  11.       say " "
  12.       say "The optional InputFileName must be fully qualified, e.g. 'C:\OS2\EPM.INI'."
  13.       say "The optional OutputFileName need not be fully qualified."
  14.       say "Wildcards are NOT supported in the FileNames."
  15.       say " "
  16.       say "With no parameters, we default to doing a matched pair of copies:"
  17.       say "'Os2Sys.Ini' to 'gcOs2Sys.Ini' and 'Os2.Ini' to 'gcOs2.Ini'."
  18.       say " "
  19.       say "Note 1:  This procedure will hog your CPU for a while."
  20.       say "Note 2:  It is HIGHLY RECOMMENDED that the output file be on a RAM disk!"
  21.       say "         (We do a vast amount of extremely inefficient file I/O.)"
  22.       exit
  23.    end
  24.  
  25. call RxFuncAdd SysLoadFuncs, RexxUtil, SysLoadFuncs
  26. if RxFuncQuery('SysLoadFuncs') then
  27.    do
  28.       say "Error:  RexxUtil's SysLoadFuncs procedure could not be loaded."
  29.       say "Perhaps RexxUtil.DLL is not on your LibPath?"
  30.       say "gcIni gives up."
  31.       exit
  32.    end
  33. call SysLoadFuncs
  34. if RxFuncQuery('SysIni') then
  35.    do
  36.       /*
  37.       ** I have no idea how a system could have passed the previous test
  38.       ** and yet fail this one!
  39.       */
  40.       say "Error:  RexxUtil's SysIni procedure could not be loaded,"
  41.       say "and gcIni cannot run without it."
  42.       exit
  43.    end
  44.  
  45. parse arg OldIni NewIni       /* Note: OldIni name must not contain spaces! */
  46. if OldIni == '' then
  47.    do
  48.       call gc "USER",   'gcOs2.Ini'
  49.       call gc "SYSTEM", 'gcOs2Sys.Ini'
  50.       exit
  51.    end
  52. if NewIni == '' then NewIni = "gc.Ini"
  53.  
  54. call gc OldIni, NewIni
  55. exit
  56.  
  57. gc: procedure
  58. parse arg OldIni, NewIni
  59. OldIni = strip(OldIni)
  60. NewIni = strip(NewIni)
  61.  
  62. say "Reading '"OldIni"', writing '"NewIni"'."
  63. call SysFileDelete NewIni     /* zap any old copies of output file */
  64.  
  65. /* This next part is based on a 'SysIni' RexxUtil code sample in REXX.INF */
  66. call SysIni OldIni, 'All:', 'Apps.'
  67. if Result == 'ERROR:'
  68.    then  do
  69.             say "Error:  '"OldIni"' does not seem to be a valid .Ini file."
  70.             if substr(OldIni,2,1) <> ':' then
  71.                do
  72.                   say "  Apparently you did not give me a fully-qualified input filename."
  73.                   say "  (This requirement is mentioned in the help text, 'gcini /?')."
  74.                   say "  I will prepend the current drive & directory, and try that..."
  75.                   if left(OldIni,1) == '\'
  76.                      then OldIni = left(directory(),2) || OldIni  /* prepend device */
  77.                      else OldIni = directory() || '\' || OldIni   /* prepend path */
  78.                end
  79.             call gc OldIni, NewIni
  80.             exit
  81.          end
  82.    else  do i = 1 to Apps.0
  83.             call SysIni OldIni, Apps.i, 'All:', 'Keys.'
  84.             if Result == 'ERROR:'
  85.                then  do
  86.                         say "Error querying group '"Apps.i"';"
  87.                         exit
  88.                      end
  89.                else  do j=1 to Keys.0
  90.                         Val = SysIni(OldIni, Apps.i, Keys.j)
  91.                         call  SysIni NewIni, Apps.i, Keys.j, Val
  92.                         if Result == "ERROR:" then
  93.                            do
  94.                               say 'Failure setting 'Apps.i":"Keys.j
  95.                               say "Possibly your disk is full?"
  96.                               exit
  97.                            end
  98.                      end
  99.          end
  100. return
  101.