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