home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP24.EXE / CHP2418.PRG < prev    next >
Encoding:
Text File  |  1991-04-30  |  2.0 KB  |  81 lines

  1. /*
  2.    Listing 24.18  Zipdir()
  3.    Author: Joe Booth
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11. //───── NOTE: must compile with the /N option!
  12.  
  13. #include "FILEIO.CH"
  14.  
  15. function zipdir(zip_file)
  16. LOCAL zip := fopen(zip_file,FO_READ), tmp :=space(4)
  17. LOCAL method,orig_date,fn_date,comp_size,uncomp
  18. LOCAL fn_size,extra,junk,_array:={},file_name
  19. while .t.
  20.    tmp = space(4)
  21.    if fread(zip,@tmp,4) <> 4    && End of file
  22.       exit
  23.    endif
  24.    if tmp = "PK"+chr(1)+chr(2)  && Central dir
  25.       exit
  26.    elseif tmp <> "PK"+chr(3)+chr(4)
  27.       exit
  28.    endif
  29.    tmp := space(26)
  30.    fread(zip,@tmp,26)
  31.    method    := bin2i(substr(tmp,5,2))
  32.    orig_date := bin2i(substr(tmp,9,2))
  33.    fn_date   := Dos_date(orig_date)
  34.    comp_size := bin2l(substr(tmp,15,4))
  35.    uncomp    := bin2l(substr(tmp,19,4))
  36.    fn_size   := bin2i(substr(tmp,23,2))
  37.    extra     := bin2i(substr(tmp,25,2))
  38.    file_name := freadstr(zip,fn_size)
  39.    tmp       := space(extra)
  40.    junk      := if(extra=0,"",fread(zip,@tmp,extra))
  41.    fseek(zip,comp_size,1)
  42.    aadd(_array,{file_name,comp_size,uncomp,fn_date})
  43. enddo
  44. fclose(zip)
  45. return _array
  46.  
  47.  
  48. function dos_date(_datestamp)
  49. local temp :=dec2bin(_datestamp),yy,mm,dd
  50. yy := bin2dec(substr(temp,1,7)) +1980
  51. mm := bin2dec(substr(temp,8,4))
  52. dd := bin2dec(substr(temp,12,5))
  53. return ctod(str(mm,2)+"/"+str(dd,2)+"/"+str(yy,4))
  54.  
  55.  
  56. function Bin2dec(_string)
  57. local retval :=0 ,k
  58. for k=1 to len(_string)
  59.     retval = If(Substr(_string,k,1)="0",0,1)+retval+retval
  60. next
  61. return retval
  62.  
  63.  
  64. function Dec2bin(_number)
  65. local tmp := _number,retval:="",remd,quot
  66. while .T.
  67.    quot  := int(tmp/2)
  68.    remd  := abs(tmp)-2*abs(quot)
  69.    retval:= Substr("01",remd+1,1)+retval
  70.    if quot= 0
  71.       exit
  72.    endif
  73.    tmp := quot
  74. enddo
  75. while len(retval)<16
  76.    retval="0"+retval
  77. enddo
  78. return retval
  79.  
  80. // end of file CHP2418.PRG
  81.