home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / CLNINI.ZIP / CLEANINI.CMD next >
OS/2 REXX Batch file  |  1992-11-10  |  5KB  |  145 lines

  1. /* CLEANINI.CMD - Version 1.1 - November 10, 1992
  2.  
  3.    Copyright (C) 1992 by James D. Stuyck
  4.  
  5.    This is "shareware" and, if you find it useful, please send a
  6.    contribution of $10.00 to:
  7.  
  8.                           J. D. Stuyck and Associates
  9.                           6 Lincolnshire Circle
  10.                           Bedford, TX  76021-4618
  11.  
  12.    Tested and "seems to work just fine" with the ServicePak (XR06055)
  13.    installed.  However, though the risk seems to be negligible, the
  14.    author specifically disclaims any responsibility for bad effects
  15.    arising from the use of this program.
  16.  
  17.    PLEASE!  -- Test this in your own environment before doing things
  18.    like arbitrarily discarding working OS2.INI and OS2SYS.INI files.
  19. */
  20.  
  21. If arg(1) = '?' | arg(1) = "help" then Signal Help    /* Display some help */
  22.  
  23. Call RxFuncAdd SysLoadFuncs, RexxUtil, SysLoadFuncs
  24.  
  25. If RxFuncQuery('SysLoadFuncs') then
  26.    Do
  27.       Say 'Error!  The RexxUtil "SysLoadFuncs" problem.'
  28.       Say 'CLEANINI cannot continue!'
  29.       Exit
  30.    End
  31.  
  32. Call SysLoadFuncs
  33.  
  34. Parse upper arg Oldfile Newfile .         /* Separate input values from arg*/
  35. If Oldfile == '' then                     /* For no arg(s) assume OS2*.INI */
  36.    Do
  37.       Call CopyIni 'USER',   'OS2.NEW'    /* Clean up OS2.INI              */
  38.       Call CopyIni 'SYSTEM', 'OS2SYS.NEW' /* Clean up OS2SYS.INI           */
  39.       Exit                                /* End the program               */
  40.    End
  41.  
  42. If Oldfile == Newfile then                /* Careful not to copy over self */
  43.    Do
  44.       Say 'Error!  You cannot copy a file over itself.'
  45.       Say 'CLEANINI cannot continue!'
  46.       Exit                                /* End the program               */
  47.    End
  48.  
  49. '@ECHO OFF'
  50. 'DIR' Oldfile '>NUL'                      /* Make sure file exists         */
  51. If rc \= 0 then
  52.    Do
  53.       Say Oldfile 'does not seem to exist.'
  54.       Say 'Please check your spelling.'
  55.       Say 'CLEANINI cannot continue!'
  56.       Exit                                /* End the program               */
  57.    End
  58.  
  59. If Newfile == '' then                     /* Named file; test for new name */
  60.    Do
  61.       Parse value Oldfile with Newfile '.' junk
  62.       Newfile = Newfile||'.NEW'
  63.    End
  64.  
  65. Call CopyIni Oldfile, Newfile             /* Clean up named INI file       */
  66. Exit                                      /* End the program               */
  67.  
  68. CopyIni: PROCEDURE                        /* Routine to do the real work   */
  69.  
  70. Parse arg Oldfile, Newfile 
  71.  
  72. Say 'Processing' Oldfile '---->' Newfile
  73.  
  74. Call SysFileDelete Newfile                /* Erase copy of new file, if any*/
  75.  
  76. /* Much of the following was "cut" from the "OS/2 Procedures Language 2/REXX"
  77.    (REXX Information) on-line documentation found in the OS/2 2.0 Information
  78.    folder.  The reader can expand "REXX Utiltiy Functions (RexxUtil)" then 
  79.    read the part about "SysIni" for complete details.
  80. */
  81.  
  82. Call SysIni Oldfile, 'All:', 'Apps.'
  83. If Result == 'ERROR:' then
  84.    Do
  85.       Say 'Error! ' Oldfile 'does not seem to be a valid .INI file.'
  86.       Say 'CLEANINI cannot continue!'
  87.       Exit
  88.    End
  89. Else
  90.    Do i = 1 to Apps.0
  91.       Call SysIni Oldfile, Apps.i, 'All:', 'Keys.'
  92.       If Result == 'ERROR:' then
  93.          Do
  94.             Say 'Error!  REXX SysIni function cannot process' Apps.i 'in' OldFile
  95.             Say "You may have a corrupted .INI file (which ain't too good)."
  96.             Say 'CLEANINI cannot continue!'
  97.             Exit
  98.          End
  99.       Else
  100.          Say 'Processing entry' i 'of' Apps.0 '('Apps.i').  It has' Keys.0 'keys.'
  101.          Do j=1 to Keys.0
  102.             val = SysIni(Oldfile, Apps.i, Keys.j)
  103.             Call  SysIni Newfile, Apps.i, Keys.j, val
  104.             If Result == "ERROR:" then
  105.                Do
  106.                   Say 'Error!  REXX SysIni function cannot create' Apps.i Keys.j 'in' NewFile
  107.                   Say 'Check to see if the disk is full.'
  108.                   Say 'CLEANINI cannot continue!'
  109.                   Exit
  110.                End
  111.          End
  112.    End
  113. Say Newfile 'created successfully from' Oldfile
  114. Return
  115.  
  116. Help:
  117. Call SysCls
  118. Say 'Usage:    cleanini [OldFileName [NewFileName]]'
  119. Say ' '
  120. Say 'By default, with no optional parameters specified, the two critical OS/2 2.0'
  121. Say '".INI" files are located (they are in the "\OS2" directory of your boot disk),'
  122. Say 'cleaned (compressed), copied to the "current directory" and renamed:'
  123. Say ' '
  124. Say '   OS2.INI becomes OS2.NEW and OS2SYS.INI becomes OS2SYS.NEW.'
  125. Say ' '
  126. Say 'Often, you will find that the cleaned (NEW) files are somewhat smaller than the'
  127. Say 'old files. You could then boot from the OS/2 installation diskettes and copy'
  128. Say 'the NEW files to the \OS2 directory, renaming them with the INI extension.'
  129. Say ' '
  130. Say 'The old (input) file is NEVER modified.'
  131. Say ' '
  132. Say 'Other applications that use OS/2-style INI files can have their INI files'
  133. Say 'cleaned. If an OldFileName is specified, it must be fully qualified. Examples:'
  134. Say ' '
  135. Say '   C:\OS2\EPM.INI or C:\OS2\APPS\KLONDIKE.INI or D:\OS2\APPS\OS2CHESS.INI'
  136. Say ' '
  137. Say 'NewFileName is optional. If it is not specified, then a new file is placed in'
  138. Say 'the same directory with the same file name as the old file, with the file'
  139. Say 'extension ".NEW." Example:'
  140. Say ' '
  141. Say '   D:\OS2\APPS\OS2CHESS.INI is cleaned into D:\OS2\APPS\OS2CHESS.NEW'
  142. Exit
  143.  
  144. /* End of file */
  145.