home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / diskmanager / dbase_1 / !DiskBase / !StrongHlp / Utilities / CleanCopy (.txt) next >
RISC OS BBC BASIC V Source  |  1996-11-13  |  4KB  |  176 lines

  1.   >CleanCopy
  2.  We dummy-define these variables so that PROC_Error will know them
  3.  if we should crash before they are actually defined
  4.   del% = 
  5.   A$   = ""
  6.   B$   = ""
  7. _Error
  8.  wrk% 255, wrk2% 255
  9.  "Hourglass_On"
  10.  Find parameters
  11.  "OS_GetEnv" 
  12.  env$
  13.   A$ = 
  14. _GetArg(env$,2)
  15.   B$ = 
  16. _GetArg(env$,3)
  17.  PRINT "env = ";env$
  18.  PRINT "A = ";A$
  19.  PRINT "B = ";B$
  20.  A$ = "" 
  21.  -1,"Needs Manual name"
  22.  B$ = "" 
  23. .    
  24.  First test whether Wimp$Scrap exists
  25. 8    
  26.  "XOS_ReadVarVal","Wimp$Scrap",,-1,0,0 
  27.  ,,R2%
  28.  1    
  29.  R2%>=0 
  30.  0,"Wimp$Scrap isn't defined"
  31. "#    
  32.  Remove any old Wimp$Scrap
  33. #,    
  34.  "OS_File",17,"<Wimp$Scrap>" 
  35. $,    
  36.  R0% <> 0 
  37.  "Delete <Wimp$Scrap>"
  38.     B$ = A$
  39.     A$ = "<Wimp$Scrap>"
  40. (%    
  41.  "Copy "+B$+" "+A$ +" D~C~V"
  42.     del% = 
  43.     del% = 
  44.  We create the new "Manual"
  45.   A% = 
  46. _DirSize(A$)
  47.  "StrongCreate "+B$+" "+
  48.  Now recursively copy everything
  49. _CopyDir(A$,B$)
  50.  If we used Wimp$Scrap, we now delete it.
  51.  del% 
  52.  "Delete "+A$
  53.  Force Close of new version
  54.  (So that we don't have to quit !StrongHelp (which closes all) to be safe)
  55.  "Rename "+B$+" "+B$
  56.  "Hourglass_Off"
  57. _CopyDir(From$,To$)
  58.  offset%,read%,x%,A%,F$,T$,S%,strlen%
  59.   offset% = 0
  60. LG    
  61.  "OS_GBPB",10,From$,wrk%,1,offset%,255,"*" 
  62.  ,,,read%,offset%
  63.  read% > 0 
  64.       x% = wrk%
  65.       
  66.  A% = 1 
  67.  read%
  68. P%        strlen% = 
  69. _StrLen(x%+20)
  70. Q!        ?(x%+20+strlen%) = 13
  71. S'        F$ = From$ + "." + $(x%+20)
  72. T'        T$ = To$   + "." + $(x%+20)
  73.         
  74.  x%!16 
  75. V&          
  76.  1 : 
  77.  PRINT "Copy ";F$
  78. W3                   
  79.  "OS_FSControl",26,F$,T$,0
  80. X&          
  81.  2 : S% = 
  82. _DirSize(F$)
  83. Y.                   
  84.  PRINT "Create ";T$,S%
  85. Z,                   
  86.  "Cdir "+T$+" "+
  87. ['                   
  88. _CopyDir(F$,T$)
  89.         
  90. ^-        x%     += ((strlen%+4) 
  91.  3) + 20
  92.       
  93. `        
  94.  offset% = -1
  95. _DirSize(dir$)
  96.  tot%,offset%,strlen%,A%,x%
  97.  This routine calculates the size of all the entries in a directory,
  98.  and all heading info for the dir.
  99.  The size of heading info is
  100.     4 (offset into dir of 1st unused pos)
  101.  The size of one entry is
  102.    24 (offset in image, load, exec, size, flags, compressed size)
  103.  + word aligned length of name (incl \0)
  104.  (The 'compressed size' is there for possible future use)
  105.   tot% = 4
  106.   offset% = 0
  107. uI    
  108.  "OS_GBPB",10,dir$,wrk2%,255,offset%,255,"*" 
  109.  ,,,read%,offset%
  110.  read% > 0 
  111.       x% = wrk2%
  112.       
  113.  A% = 1 
  114.  read%
  115. y2        strlen% = ( 
  116. _StrLen(x%+20) + 4 ) 
  117. z"        tot%   += strlen% + 24
  118. {"        x%     += strlen% + 20
  119.       
  120. }        
  121.  offset% = -1
  122. = tot%
  123. _StrLen(A%)
  124.   L% = A%
  125.  ?A% >= 32
  126.     A% += 1
  127. = A% - L%
  128. _GetArg(arg$,no%)
  129.  a%,b%,x%
  130.  Find start of the given part
  131.   a% = 1
  132.   x% = 0
  133.     a% = 
  134. arg$," ",a%)
  135.  a% = 0 
  136.       = ""
  137.         
  138.     a% += 1
  139. arg$,a%,1) = " ")
  140.       a% += 1
  141.         
  142. 1    
  143. arg$,a%,1) = "-" 
  144. arg$,a%,1) = "@" 
  145.       no% +=1
  146.         
  147.     x% += 1
  148.  x% >= no%
  149.  Find end of the given part
  150.   b% = 
  151. arg$," ",a%)
  152.  b% = 0 
  153.     = 
  154. arg$,a%)
  155.     = 
  156. arg$,a%,b%-a%)
  157. _Error
  158.  "Hourglass_Off"
  159.  If we have renamed original file to Wimp$Scrap, then we should move
  160.  it back..
  161.  del% 
  162. .    
  163.  1st delete new file (if it exists..)
  164.      
  165.  "OS_File",17,B$ 
  166. #    
  167.  R0% <> 0 
  168.  "Delete "+B$
  169. !    
  170.  Move original file back
  171. #    
  172.  OSCLI "Rename "+A$+" "+B$
  173. $    
  174.  "Copy "+A$+" "+B$+" ~AD~V"
  175. $;" at ";
  176.