home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / fixfile.zip / fixfile.cmd
OS/2 REXX Batch file  |  1997-03-12  |  2KB  |  73 lines

  1. /* Rexx Diskete File Fixer                     */
  2. /*      12/03/1997        v 1.0                */
  3. /* Tries to read all good sectors from file    */
  4. /*  bad sectors are replaced by ???????        */
  5. /* I use it to fix rar archives with data      */
  6. /*  recovery record, becouse rar 2.0 have some */
  7. /*  troubles with repair files on bad disks.   */
  8. /* Public domain donated by                    */
  9. /* Radim Kolar, Team OS/2, Czech Republic      */
  10. /* Progress indicator is borowed from          */
  11. /* Rexx Tips & Ticks,                          */
  12. /* Copyright (c) 1994 - 1996 by Bernd Schemmer.*/
  13. /*                                             */
  14. /* email:                                      */
  15. /*  hsn@cybermail.net                          */
  16.  
  17. parse arg infile outfile
  18. if infile='' then do
  19.                  say "fixfile.cmd infile outfile"
  20.                     return 1
  21.                   end
  22. if outfile='' then do
  23.                  say "fixfile.cmd infile outfile"
  24.                     return 2
  25.                   end
  26. fsize=stream(infile,'C','QUERY SIZE')                    
  27. if fsize='' then do 
  28.                   say "Cannot open input file!"
  29.                   return 3
  30.                  end
  31.  
  32. blocksize=512                                    
  33. say "File name: "infile
  34. say "Write to : "outfile
  35. say "File size: "trunc(fsize/blocksize)"x"blocksize"+"fsize-trunc(fsize/blocksize)*blocksize
  36. say
  37.  
  38. remain=fsize-trunc(fsize/blocksize)*blocksize;
  39. if remain=0 then bonus=0 
  40.             else bonus=1;
  41.  
  42.    p1.0 = "\"
  43.    p1.1 = "-"
  44.    p1.2 = "/"
  45.    p1.3 = "-"
  46.    p2 = 0
  47.  
  48.  
  49. "@del 2>nul "outfile
  50.  
  51. blocks=trunc(fsize/blocksize)
  52. /* soubor zacina na 1 */
  53.  call stream infile,'C','OPEN READ'
  54. do i=1 to blocks+bonus
  55.  if i>blocks then blocksize=remain
  56.  buffer = charin(infile,,blocksize)
  57.  if length(buffer)\=blocksize then do 
  58.                               say 'Error reading block 'i
  59.                               buffer=copies('?',blocksize);
  60.                               call stream infile,'C','CLOSE'
  61.                               call stream infile,'C','OPEN READ'
  62.                               pos1=((i)*blocksize)+1
  63.                               call stream infile,'C','SEEK 'pos1
  64.                              end 
  65.  call charout outfile, buffer
  66.  call charOut , "1B"x || "[sReading block "i"/"blocks+bonus " " || p1.p2 || "1B"x || "[u"
  67.  p2 = (p2+1) // 4
  68. end
  69. call stream infile,'C','CLOSE'
  70. call stream outfile,'C','CLOSE'
  71. say
  72. say 'Done.'
  73.