home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / cfgsort.zip / CfgSort.CMD
OS/2 REXX Batch file  |  1998-08-23  |  4KB  |  202 lines

  1. /* Rexx */
  2. /* Sortiert die Datei CONFIG.SYS
  3.    Copyright (c) 1997 by Stefan Milcke
  4.                          Fresenbergstraße 75
  5.            28779 Bremen
  6.  
  7.    Dieses Rexx-Script ist Freeware
  8.    Datum der Erstellung: 03.07.1997
  9.    Letzte Aenderung am:  23.08.1998
  10. */
  11.  
  12. /* Vorgeplänkel */
  13.  
  14. CfgFile="\CONFIG.SYS"
  15. TempCfg="\CONFIG.NEW"
  16.  
  17. Call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  18. Call RxFuncAdd 'SysFileDelete','RexxUtil','SysFileDelete'
  19. Call RxFuncAdd 'SysTempFileName','RexxUtil','SysTempFileName'
  20.  
  21. /* CONFIG.SYS einlesen */
  22. i=1
  23. IFile=Stream(CfgFile,"C","OPEN READ")
  24. Do Forever
  25.  If Lines(CfgFile)=0 Then Leave
  26.  CfgLine.i=Linein(CfgFile)
  27.  If (Left(CfgLine.i,20)="REM ****************") | (Left(CfgLine.i,6)="REM : ") Then
  28.   Nop
  29.  Else
  30.   i=i+1
  31.  CfgLine.0=i
  32. End
  33. IFile=Stream(CfgFile,"C","CLOSE")
  34.  
  35. /* ggf. Temporäre Datei löschen */
  36. FileThere=Stream(TempCfg,"C","QUERY EXISTS")
  37. If Length(FileThere)>0 Then
  38.  Call SysFileDelete TempCfg
  39.  
  40. /* Temporäre Datei öffnen */
  41. OFile=Stream(TempCfg,"C","OPEN WRITE")
  42.  
  43. /* IFS einsortieren */
  44. /* Zuerst einen Remark einfügen */
  45. Call AddRemark "Installable File Systems (IFS)"
  46. Call GetUnsorted "IFS"
  47. Call WriteFoundArray
  48. rc=LineOut(TempCfg,"")
  49.  
  50. /* Base Devices einsortieren */
  51. Call AddRemark "Base Devices"
  52. Call GetUnsorted "BASEDEV"
  53. Call WriteFoundArray
  54. rc=LineOut(TempCfg,"")
  55.  
  56. /* SET statements einsortieren */
  57. Call AddRemark "Environment variables"
  58. Call GetUnsorted "SET "
  59. Call SortFoundArray
  60. Call WriteFoundArray
  61. rc=LineOut(TempCfg,"")
  62.  
  63. /* Devices einsortieren */
  64. Call AddRemark "Devices"
  65. Call GetUnsorted "DEVICE"
  66. Call WriteFoundArray
  67. rc=LineOut(TempCfg,"")
  68.  
  69. /* Alle bekannten OS/2 statements einsortieren */
  70. Call AddRemark "OS2 Statements"
  71. Call GetUnsorted "AUTOFAIL"
  72. Call WriteFoundArray
  73. Call GetUnsorted "PROTSHELL"
  74. Call WriteFoundArray
  75. Call GetUnsorted "LIBPATH"
  76. Call WriteFoundArray
  77. Call GetUnsorted "PRIORITY_DISK_IO"
  78. Call WriteFoundArray
  79. Call GetUnsorted "IOPL"
  80. Call WriteFoundArray
  81. Call GetUnsorted "DISKCACHE"
  82. Call WriteFoundArray
  83. Call GetUnsorted "MAXWAIT"
  84. Call WriteFoundArray
  85. Call GetUnsorted "MEMMAN"
  86. Call WriteFoundArray
  87. Call GetUnsorted "SWAPPATH"
  88. Call WriteFoundArray
  89. Call GetUnsorted "THREADS"
  90. Call WriteFoundArray
  91. Call GetUnsorted "PRINTMONBUFSIZE"
  92. Call WriteFoundArray
  93. Call GetUnsorted "PROTECTONLY"
  94. Call WriteFoundArray
  95. Call GetUnsorted "DEVINFO"
  96. Call WriteFoundArray
  97. rc=LineOut(TempCfg,"")
  98.  
  99. /* RUN und CALL anweisungen einsortieren */
  100. Call AddRemark "Run And Call"
  101. Call GetUnsortedRunAndCall
  102. Call WriteFoundArray
  103. rc=LineOut(TempCfg,"")
  104.  
  105. /* Rest unter unbekannt einsortieren */
  106. Call AddRemark "Unknown"
  107. Call WriteUnmatched
  108.  
  109. /* Datei schließen */
  110. OFile=Stream(TempCfg,"C","CLOSE")
  111. Exit
  112.  
  113. SortFoundArray:
  114.  Do i=1 To Found.0
  115.   L1=Found.i
  116.   If Left(L1,4)="REM " Then
  117.   Do
  118.    L1=Right(L1,Length(L1)-4)
  119.   End
  120.   Do j=i To Found.0
  121.    L2=Found.j
  122.    If Left(L2,4)="REM " Then
  123.    Do
  124.     L2=Right(L2,Length(L2)-4)
  125.    End
  126.    If L1>L2 Then
  127.    Do
  128.     T=Found.i
  129.     Found.i=Found.j
  130.     Found.j=T
  131.     L1=Found.i
  132.     If Left(L1,4)="REM " Then
  133.     Do
  134.      L1=Right(L1,Length(L1)-4)
  135.     End
  136.    End
  137.   End
  138.  End
  139. Return
  140.  
  141. WriteFoundArray:
  142.  Do i=1 To Found.0
  143.   rc=LineOut(TempCfg,Found.i)
  144.  End
  145. Return
  146.  
  147. GetUnsorted:
  148.  Sea1=Arg(1)
  149.  Sea2="REM "Arg(1)
  150.  Found.0=0
  151.  j=0
  152.  Do i=1 To CfgLine.0
  153.   Line=CfgLine.i
  154.   If (Translate(Left(Line,Length(Sea1)))=Translate(Sea1)) | (Translate(Left(Line,Length(Sea2)))=Translate(Sea2)) Then
  155.   Do
  156.    j=j+1
  157.    Found.j=Line
  158.    CfgLine.i=""
  159.   End
  160.  End
  161.  Found.0=j
  162. Return
  163.  
  164. GetUnsortedRunAndCall:
  165.  Sea1="RUN"
  166.  Sea2="REM RUN"
  167.  Sea3="CALL"
  168.  Sea4="REM CALL"
  169.  Found.0=0
  170.  j=0
  171.  Do i=1 To CfgLine.0
  172.   Line=CfgLine.i
  173.   If (Left(Line,Length(Sea1))=Sea1) | (Left(Line,Length(Sea2))=Sea2) | (Left(Line,Length(Sea3))=Sea3) | (Left(Line,Length(Sea4))=Sea4) Then
  174.   Do
  175.    j=j+1
  176.    Found.j=Line
  177.    CfgLine.i=""
  178.   End
  179.  End
  180.  Found.0=j
  181. Return
  182.  
  183. WriteUnmatched:
  184.  Do i=1 To CfgLine.0-1
  185.   If CfgLine.i="" Then
  186.    Nop
  187.   Else
  188.    rc=LineOut(TempCfg,CfgLine.i)
  189.  End
  190. Return
  191.  
  192.  
  193. AddRemark:
  194. Call AddRemarkLine
  195. rc=LineOut(TempCfg,"REM : "Arg(1)":")
  196. Call AddRemarkLine
  197. Return
  198.  
  199. AddRemarkLine:
  200. rc=LineOut(TempCfg,"REM ***************************************************************************")
  201. Return
  202.