home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / cleandups < prev    next >
Text File  |  2020-01-01  |  5KB  |  138 lines

  1. #!/usr/local/bin/kermit +
  2. ;
  3. ; c l e a n d u p s
  4. ;
  5. ; Script to clean out duplicate C-Kermit 6.1/7.0 test binaries at the
  6. ; Kermit website.  Illustrates some of C-Kermit 7.0's new features.
  7. ;
  8. ; F. da Cruz, the Kermit Project, Columbia University, March 1999
  9. ;
  10. ; Change the first line to have the path of C-Kermit 7.0 on your computer
  11. ; and give this file execute permission.  Then run this script exactly as if
  12. ; it were a shell script.
  13. ;
  14. ; Parameters:
  15. ;  \%1 = Beta number (one or two digits, required)
  16. ;  \%2 = Function: LIST-ONLY or DELETE (default = DELETE, abbreviations OK)
  17. ;  \%3 = Directory (default = current directory)
  18. ;
  19. ; Examples:
  20. ;  cleandups                     ; Missing Beta number gives usage message.
  21. ;  cleandups 5                   ; Beta.05, DELETE, default directory.
  22. ;  cleandups 5 d                 ; Beta.05, DELETE, default directory.
  23. ;  cleandups 5 delete            ; DELETE or LIST-ONLY can be spelled out
  24. ;  cleandups 5 del               ; or abbreviated.
  25. ;  cleandups 5 l /some/other/directory ; List dups in /some/other/directory.
  26. ;
  27. ; The files have names like ck<x><vvv>[ab]<nn><text>, where:
  28. ; <x>    Is a single letter or digit denoting the platform
  29. ; <vvv>  Is the C-Kermit edit number (e.g. 193, 194, 195, ...)
  30. ; [ab]   Is "a" for an Alpha test and "b" for a Beta test
  31. ; <nn>   The two-digit Alpha or Beta test number.
  32. ; <text> Is arbitrary text specific to the platform.
  33. ;
  34. ; For example, if we have just installed a new file cku195b05.aix41, this
  35. ; script will delete (or list) cku195b04.aix41, cku195b03.aix41, and so on,
  36. ; as well as any cku*.aix41 files earlier than version 195, in the target
  37. ; directory.  Similarly for all other old versions superseded by newer ones.
  38. ;
  39. ; When listing, the new file is shown first followed by the old files to
  40. ; be deleted in reverse order; each such set of files is set off by a
  41. ; dashed line.
  42. ;
  43. local \%b \%e \%f \%j \%k \%l \%m \%n \%x \%y ; Local scalars
  44. local  \&a[] \&b[]                            ; Local arrays
  45. local usage found freed lowest deleting       ; Local macros
  46.  
  47. .\%m := \fbasename(\%0)                       ; Script name for usage message
  48.  
  49. if LLT \v(version) 700000 exit 1 C-Kermit 7.0 required
  50.  
  51. define usage {
  52.     exit 1 Usage: \%m betanumber [ { DELETE, LIST-ONLY } [ directory ] ] }
  53. }
  54. ; Check parameters...
  55. ;
  56. if not def \%1 usage
  57. if not numeric \%1 exit 1 Beta number not numeric
  58. if < \%1 1 exit 1 Beta number not positive
  59. if > \%1 99 exit 1 Beta number more than two digits -- Too many Betas!
  60.  
  61. .deleting = 1                   ; Assume LIST-ONLY - no deleting.
  62. if not def \%2 .\%2 = DELETE
  63. if match LIST-ONLY \%2* .deleting = 0
  64. else if not match DELETE \%2* usage
  65. if not def \%3 .\%3 = .
  66. cd \%3
  67. if fail exit 1 Can't cd to "\%3"
  68.  
  69. ; Define constants (note new assignment operators)...
  70.  
  71. .\%e = 196                      ; C-Kermit edit number
  72. .lowest = 2                     ; C-Kermit 7.0.19x Betas started off at 2.
  73. .found = 0
  74. .freed = 0
  75.  
  76. .\%x ::= \%1 - 1                ; Beta number before this one.
  77. .\%b := \flpad(\%1,2,0)         ; Current beta number left-padded with zero.
  78.  
  79. ; Say what will happen...
  80.  
  81. echo Checking duplicates for Beta.\%b; lowest = \m(lowest); previous = \%x
  82. if \m(deleting) echo \fpathname(\%3): DELETING old versions...
  83. else echo \fpathname(\%3): LISTING old versions but not deleting them...
  84.  
  85. ; The following command assigns the list of files that matches the pattern
  86. ; for this Beta version to the array \&a[] and the number of files to \%n.
  87.  
  88. .\%n := \ffiles(ck*\%eb\%b*,&a)
  89. if < \%n 1 exit 1 No files match "ck*\%eb\%b*"
  90.  
  91. sort a                          ; Sort the file-list array.
  92.  
  93. for \%i 1 \%n 1 {               ; Loop through file list for this beta.
  94.     set flag off                ; Assume no old files matching this one.
  95.     for \%j \%x \m(lowest) -1 { ; Search for previous versions of same binary.
  96.         .\%l := \flpad(\%j,2,0)
  97.         .\%f := \freplace(\&a[\%i],b\%b,b\%l)
  98.         if exist \%f {                ; Found one.
  99.             increment found           ; Count it.
  100.             if \m(deleting) {         ; If deleting
  101.                 .\%9 := \fsize(\%f)   ; get this one's size for stats 
  102.                 delete /verbose \%f   ; and delete it verbosely.
  103.                 if fail exit 1        ; But stop if deletion fails.
  104.                 increment freed \%9   ; Accumulate bytes freed.
  105.             } else {                  ; Otherwise only listing.
  106.                 if not flag dir /message:(KEEP) \&a[\%i] ; List first one once
  107.                 dir /message:(DELETE) \%f ; List this one
  108.             }
  109.             set flag on               ; Found one - remember.
  110.         }
  111.     }
  112.     for \%j \%e-1 193 -1 {            ; Same deal for previous edits
  113.         .\%f := \freplace(\&a[\%i],\%eb\%b,\%j*)
  114.         .\%y := \ffiles(\%f,&b)
  115.         if = \%y 0 continue
  116.         sort /rev b
  117.     if not flag dir /message:(KEEP) \&a[\%i]
  118.         set flag on
  119.         for \%k 1 \%y 1 {
  120.             increment found
  121.             if \m(deleting) {
  122.                 .\%9 := \fsize(\&b[\%k])
  123.                 delete /verbose \&b[\%k]
  124.                 if fail exit 1
  125.                 increment freed \%9
  126.             } else {
  127.                 dir /message:(DELETE) \&b[\%k]
  128.             }            
  129.         }
  130.     }
  131.     if flag echo {---------}
  132. }
  133.  
  134. echo Files: \m(found) 
  135. echo Freed: \m(freed)
  136.  
  137. exit 0
  138.