bio-velvet_underground 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (286) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +19 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.md +53 -0
  8. data/Rakefile +51 -0
  9. data/VERSION +1 -0
  10. data/ext/bioruby.patch +60 -0
  11. data/ext/mkrf_conf.rb +50 -0
  12. data/ext/src/Makefile +125 -0
  13. data/ext/src/src/allocArray.c +305 -0
  14. data/ext/src/src/allocArray.h +86 -0
  15. data/ext/src/src/autoOpen.c +107 -0
  16. data/ext/src/src/autoOpen.h +18 -0
  17. data/ext/src/src/binarySequences.c +813 -0
  18. data/ext/src/src/binarySequences.h +125 -0
  19. data/ext/src/src/concatenatedGraph.c +233 -0
  20. data/ext/src/src/concatenatedGraph.h +30 -0
  21. data/ext/src/src/concatenatedPreGraph.c +262 -0
  22. data/ext/src/src/concatenatedPreGraph.h +29 -0
  23. data/ext/src/src/correctedGraph.c +2642 -0
  24. data/ext/src/src/correctedGraph.h +32 -0
  25. data/ext/src/src/dfib.c +509 -0
  26. data/ext/src/src/dfib.h +69 -0
  27. data/ext/src/src/dfibHeap.c +89 -0
  28. data/ext/src/src/dfibHeap.h +39 -0
  29. data/ext/src/src/dfibpriv.h +105 -0
  30. data/ext/src/src/fib.c +628 -0
  31. data/ext/src/src/fib.h +78 -0
  32. data/ext/src/src/fibHeap.c +79 -0
  33. data/ext/src/src/fibHeap.h +41 -0
  34. data/ext/src/src/fibpriv.h +110 -0
  35. data/ext/src/src/globals.h +153 -0
  36. data/ext/src/src/graph.c +3983 -0
  37. data/ext/src/src/graph.h +233 -0
  38. data/ext/src/src/graphReConstruction.c +1472 -0
  39. data/ext/src/src/graphReConstruction.h +30 -0
  40. data/ext/src/src/graphStats.c +2167 -0
  41. data/ext/src/src/graphStats.h +72 -0
  42. data/ext/src/src/kmer.c +652 -0
  43. data/ext/src/src/kmer.h +73 -0
  44. data/ext/src/src/kmerOccurenceTable.c +236 -0
  45. data/ext/src/src/kmerOccurenceTable.h +44 -0
  46. data/ext/src/src/kseq.h +223 -0
  47. data/ext/src/src/locallyCorrectedGraph.c +557 -0
  48. data/ext/src/src/locallyCorrectedGraph.h +40 -0
  49. data/ext/src/src/passageMarker.c +677 -0
  50. data/ext/src/src/passageMarker.h +137 -0
  51. data/ext/src/src/preGraph.c +1717 -0
  52. data/ext/src/src/preGraph.h +106 -0
  53. data/ext/src/src/preGraphConstruction.c +990 -0
  54. data/ext/src/src/preGraphConstruction.h +26 -0
  55. data/ext/src/src/readCoherentGraph.c +557 -0
  56. data/ext/src/src/readCoherentGraph.h +30 -0
  57. data/ext/src/src/readSet.c +1734 -0
  58. data/ext/src/src/readSet.h +67 -0
  59. data/ext/src/src/recycleBin.c +199 -0
  60. data/ext/src/src/recycleBin.h +58 -0
  61. data/ext/src/src/roadMap.c +342 -0
  62. data/ext/src/src/roadMap.h +65 -0
  63. data/ext/src/src/run.c +318 -0
  64. data/ext/src/src/run.h +52 -0
  65. data/ext/src/src/run2.c +712 -0
  66. data/ext/src/src/scaffold.c +1876 -0
  67. data/ext/src/src/scaffold.h +64 -0
  68. data/ext/src/src/shortReadPairs.c +1243 -0
  69. data/ext/src/src/shortReadPairs.h +32 -0
  70. data/ext/src/src/splay.c +259 -0
  71. data/ext/src/src/splay.h +43 -0
  72. data/ext/src/src/splayTable.c +1315 -0
  73. data/ext/src/src/splayTable.h +31 -0
  74. data/ext/src/src/tightString.c +362 -0
  75. data/ext/src/src/tightString.h +82 -0
  76. data/ext/src/src/utility.c +199 -0
  77. data/ext/src/src/utility.h +98 -0
  78. data/ext/src/third-party/zlib-1.2.3/ChangeLog +855 -0
  79. data/ext/src/third-party/zlib-1.2.3/FAQ +339 -0
  80. data/ext/src/third-party/zlib-1.2.3/INDEX +51 -0
  81. data/ext/src/third-party/zlib-1.2.3/Makefile +154 -0
  82. data/ext/src/third-party/zlib-1.2.3/Makefile.in +154 -0
  83. data/ext/src/third-party/zlib-1.2.3/README +125 -0
  84. data/ext/src/third-party/zlib-1.2.3/adler32.c +149 -0
  85. data/ext/src/third-party/zlib-1.2.3/algorithm.txt +209 -0
  86. data/ext/src/third-party/zlib-1.2.3/amiga/Makefile.pup +66 -0
  87. data/ext/src/third-party/zlib-1.2.3/amiga/Makefile.sas +65 -0
  88. data/ext/src/third-party/zlib-1.2.3/as400/bndsrc +132 -0
  89. data/ext/src/third-party/zlib-1.2.3/as400/compile.clp +123 -0
  90. data/ext/src/third-party/zlib-1.2.3/as400/readme.txt +111 -0
  91. data/ext/src/third-party/zlib-1.2.3/as400/zlib.inc +331 -0
  92. data/ext/src/third-party/zlib-1.2.3/compress.c +79 -0
  93. data/ext/src/third-party/zlib-1.2.3/configure +459 -0
  94. data/ext/src/third-party/zlib-1.2.3/contrib/README.contrib +71 -0
  95. data/ext/src/third-party/zlib-1.2.3/contrib/ada/buffer_demo.adb +106 -0
  96. data/ext/src/third-party/zlib-1.2.3/contrib/ada/mtest.adb +156 -0
  97. data/ext/src/third-party/zlib-1.2.3/contrib/ada/read.adb +156 -0
  98. data/ext/src/third-party/zlib-1.2.3/contrib/ada/readme.txt +65 -0
  99. data/ext/src/third-party/zlib-1.2.3/contrib/ada/test.adb +463 -0
  100. data/ext/src/third-party/zlib-1.2.3/contrib/ada/zlib-streams.adb +225 -0
  101. data/ext/src/third-party/zlib-1.2.3/contrib/ada/zlib-streams.ads +114 -0
  102. data/ext/src/third-party/zlib-1.2.3/contrib/ada/zlib-thin.adb +141 -0
  103. data/ext/src/third-party/zlib-1.2.3/contrib/ada/zlib-thin.ads +450 -0
  104. data/ext/src/third-party/zlib-1.2.3/contrib/ada/zlib.adb +701 -0
  105. data/ext/src/third-party/zlib-1.2.3/contrib/ada/zlib.ads +328 -0
  106. data/ext/src/third-party/zlib-1.2.3/contrib/ada/zlib.gpr +20 -0
  107. data/ext/src/third-party/zlib-1.2.3/contrib/asm586/README.586 +43 -0
  108. data/ext/src/third-party/zlib-1.2.3/contrib/asm586/match.S +364 -0
  109. data/ext/src/third-party/zlib-1.2.3/contrib/asm686/README.686 +34 -0
  110. data/ext/src/third-party/zlib-1.2.3/contrib/asm686/match.S +329 -0
  111. data/ext/src/third-party/zlib-1.2.3/contrib/blast/Makefile +8 -0
  112. data/ext/src/third-party/zlib-1.2.3/contrib/blast/README +4 -0
  113. data/ext/src/third-party/zlib-1.2.3/contrib/blast/blast.c +444 -0
  114. data/ext/src/third-party/zlib-1.2.3/contrib/blast/blast.h +71 -0
  115. data/ext/src/third-party/zlib-1.2.3/contrib/blast/test.pk +0 -0
  116. data/ext/src/third-party/zlib-1.2.3/contrib/blast/test.txt +1 -0
  117. data/ext/src/third-party/zlib-1.2.3/contrib/delphi/ZLib.pas +557 -0
  118. data/ext/src/third-party/zlib-1.2.3/contrib/delphi/ZLibConst.pas +11 -0
  119. data/ext/src/third-party/zlib-1.2.3/contrib/delphi/readme.txt +76 -0
  120. data/ext/src/third-party/zlib-1.2.3/contrib/delphi/zlibd32.mak +93 -0
  121. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib.build +33 -0
  122. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib.chm +0 -0
  123. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib.sln +21 -0
  124. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib/AssemblyInfo.cs +58 -0
  125. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib/ChecksumImpl.cs +202 -0
  126. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib/CircularBuffer.cs +83 -0
  127. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib/CodecBase.cs +198 -0
  128. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib/Deflater.cs +106 -0
  129. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib/DotZLib.cs +288 -0
  130. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib/DotZLib.csproj +141 -0
  131. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib/GZipStream.cs +301 -0
  132. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib/Inflater.cs +105 -0
  133. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/DotZLib/UnitTests.cs +274 -0
  134. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/LICENSE_1_0.txt +23 -0
  135. data/ext/src/third-party/zlib-1.2.3/contrib/dotzlib/readme.txt +58 -0
  136. data/ext/src/third-party/zlib-1.2.3/contrib/infback9/README +1 -0
  137. data/ext/src/third-party/zlib-1.2.3/contrib/infback9/infback9.c +608 -0
  138. data/ext/src/third-party/zlib-1.2.3/contrib/infback9/infback9.h +37 -0
  139. data/ext/src/third-party/zlib-1.2.3/contrib/infback9/inffix9.h +107 -0
  140. data/ext/src/third-party/zlib-1.2.3/contrib/infback9/inflate9.h +47 -0
  141. data/ext/src/third-party/zlib-1.2.3/contrib/infback9/inftree9.c +323 -0
  142. data/ext/src/third-party/zlib-1.2.3/contrib/infback9/inftree9.h +55 -0
  143. data/ext/src/third-party/zlib-1.2.3/contrib/inflate86/inffas86.c +1157 -0
  144. data/ext/src/third-party/zlib-1.2.3/contrib/inflate86/inffast.S +1368 -0
  145. data/ext/src/third-party/zlib-1.2.3/contrib/iostream/test.cpp +24 -0
  146. data/ext/src/third-party/zlib-1.2.3/contrib/iostream/zfstream.cpp +329 -0
  147. data/ext/src/third-party/zlib-1.2.3/contrib/iostream/zfstream.h +128 -0
  148. data/ext/src/third-party/zlib-1.2.3/contrib/iostream2/zstream.h +307 -0
  149. data/ext/src/third-party/zlib-1.2.3/contrib/iostream2/zstream_test.cpp +25 -0
  150. data/ext/src/third-party/zlib-1.2.3/contrib/iostream3/README +35 -0
  151. data/ext/src/third-party/zlib-1.2.3/contrib/iostream3/TODO +17 -0
  152. data/ext/src/third-party/zlib-1.2.3/contrib/iostream3/test.cc +50 -0
  153. data/ext/src/third-party/zlib-1.2.3/contrib/iostream3/zfstream.cc +479 -0
  154. data/ext/src/third-party/zlib-1.2.3/contrib/iostream3/zfstream.h +466 -0
  155. data/ext/src/third-party/zlib-1.2.3/contrib/masm686/match.asm +413 -0
  156. data/ext/src/third-party/zlib-1.2.3/contrib/masmx64/bld_ml64.bat +2 -0
  157. data/ext/src/third-party/zlib-1.2.3/contrib/masmx64/gvmat64.asm +513 -0
  158. data/ext/src/third-party/zlib-1.2.3/contrib/masmx64/gvmat64.obj +0 -0
  159. data/ext/src/third-party/zlib-1.2.3/contrib/masmx64/inffas8664.c +186 -0
  160. data/ext/src/third-party/zlib-1.2.3/contrib/masmx64/inffasx64.asm +392 -0
  161. data/ext/src/third-party/zlib-1.2.3/contrib/masmx64/inffasx64.obj +0 -0
  162. data/ext/src/third-party/zlib-1.2.3/contrib/masmx64/readme.txt +28 -0
  163. data/ext/src/third-party/zlib-1.2.3/contrib/masmx86/bld_ml32.bat +2 -0
  164. data/ext/src/third-party/zlib-1.2.3/contrib/masmx86/gvmat32.asm +972 -0
  165. data/ext/src/third-party/zlib-1.2.3/contrib/masmx86/gvmat32.obj +0 -0
  166. data/ext/src/third-party/zlib-1.2.3/contrib/masmx86/gvmat32c.c +62 -0
  167. data/ext/src/third-party/zlib-1.2.3/contrib/masmx86/inffas32.asm +1083 -0
  168. data/ext/src/third-party/zlib-1.2.3/contrib/masmx86/inffas32.obj +0 -0
  169. data/ext/src/third-party/zlib-1.2.3/contrib/masmx86/mkasm.bat +3 -0
  170. data/ext/src/third-party/zlib-1.2.3/contrib/masmx86/readme.txt +21 -0
  171. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/ChangeLogUnzip +67 -0
  172. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/Makefile +25 -0
  173. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/crypt.h +132 -0
  174. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/ioapi.c +177 -0
  175. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/ioapi.h +75 -0
  176. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/iowin32.c +270 -0
  177. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/iowin32.h +21 -0
  178. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/miniunz.c +585 -0
  179. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/minizip.c +420 -0
  180. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/mztools.c +281 -0
  181. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/mztools.h +31 -0
  182. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/unzip.c +1598 -0
  183. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/unzip.h +354 -0
  184. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/zip.c +1219 -0
  185. data/ext/src/third-party/zlib-1.2.3/contrib/minizip/zip.h +235 -0
  186. data/ext/src/third-party/zlib-1.2.3/contrib/pascal/example.pas +599 -0
  187. data/ext/src/third-party/zlib-1.2.3/contrib/pascal/readme.txt +76 -0
  188. data/ext/src/third-party/zlib-1.2.3/contrib/pascal/zlibd32.mak +93 -0
  189. data/ext/src/third-party/zlib-1.2.3/contrib/pascal/zlibpas.pas +236 -0
  190. data/ext/src/third-party/zlib-1.2.3/contrib/puff/Makefile +8 -0
  191. data/ext/src/third-party/zlib-1.2.3/contrib/puff/README +63 -0
  192. data/ext/src/third-party/zlib-1.2.3/contrib/puff/puff.c +837 -0
  193. data/ext/src/third-party/zlib-1.2.3/contrib/puff/puff.h +31 -0
  194. data/ext/src/third-party/zlib-1.2.3/contrib/puff/zeros.raw +0 -0
  195. data/ext/src/third-party/zlib-1.2.3/contrib/testzlib/testzlib.c +275 -0
  196. data/ext/src/third-party/zlib-1.2.3/contrib/testzlib/testzlib.txt +10 -0
  197. data/ext/src/third-party/zlib-1.2.3/contrib/untgz/Makefile +14 -0
  198. data/ext/src/third-party/zlib-1.2.3/contrib/untgz/Makefile.msc +17 -0
  199. data/ext/src/third-party/zlib-1.2.3/contrib/untgz/untgz.c +674 -0
  200. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/readme.txt +73 -0
  201. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc7/miniunz.vcproj +126 -0
  202. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc7/minizip.vcproj +126 -0
  203. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc7/testzlib.vcproj +126 -0
  204. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc7/zlib.rc +32 -0
  205. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc7/zlibstat.vcproj +246 -0
  206. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc7/zlibvc.def +92 -0
  207. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc7/zlibvc.sln +78 -0
  208. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc7/zlibvc.vcproj +445 -0
  209. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc8/miniunz.vcproj +566 -0
  210. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc8/minizip.vcproj +563 -0
  211. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc8/testzlib.vcproj +948 -0
  212. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc8/testzlibdll.vcproj +567 -0
  213. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc8/zlib.rc +32 -0
  214. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc8/zlibstat.vcproj +870 -0
  215. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc8/zlibvc.def +92 -0
  216. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc8/zlibvc.sln +144 -0
  217. data/ext/src/third-party/zlib-1.2.3/contrib/vstudio/vc8/zlibvc.vcproj +1219 -0
  218. data/ext/src/third-party/zlib-1.2.3/crc32.c +423 -0
  219. data/ext/src/third-party/zlib-1.2.3/crc32.h +441 -0
  220. data/ext/src/third-party/zlib-1.2.3/deflate.c +1736 -0
  221. data/ext/src/third-party/zlib-1.2.3/deflate.h +331 -0
  222. data/ext/src/third-party/zlib-1.2.3/example.c +565 -0
  223. data/ext/src/third-party/zlib-1.2.3/examples/README.examples +42 -0
  224. data/ext/src/third-party/zlib-1.2.3/examples/fitblk.c +233 -0
  225. data/ext/src/third-party/zlib-1.2.3/examples/gun.c +693 -0
  226. data/ext/src/third-party/zlib-1.2.3/examples/gzappend.c +500 -0
  227. data/ext/src/third-party/zlib-1.2.3/examples/gzjoin.c +448 -0
  228. data/ext/src/third-party/zlib-1.2.3/examples/gzlog.c +413 -0
  229. data/ext/src/third-party/zlib-1.2.3/examples/gzlog.h +58 -0
  230. data/ext/src/third-party/zlib-1.2.3/examples/zlib_how.html +523 -0
  231. data/ext/src/third-party/zlib-1.2.3/examples/zpipe.c +191 -0
  232. data/ext/src/third-party/zlib-1.2.3/examples/zran.c +404 -0
  233. data/ext/src/third-party/zlib-1.2.3/gzio.c +1026 -0
  234. data/ext/src/third-party/zlib-1.2.3/infback.c +623 -0
  235. data/ext/src/third-party/zlib-1.2.3/inffast.c +318 -0
  236. data/ext/src/third-party/zlib-1.2.3/inffast.h +11 -0
  237. data/ext/src/third-party/zlib-1.2.3/inffixed.h +94 -0
  238. data/ext/src/third-party/zlib-1.2.3/inflate.c +1368 -0
  239. data/ext/src/third-party/zlib-1.2.3/inflate.h +115 -0
  240. data/ext/src/third-party/zlib-1.2.3/inftrees.c +329 -0
  241. data/ext/src/third-party/zlib-1.2.3/inftrees.h +55 -0
  242. data/ext/src/third-party/zlib-1.2.3/make_vms.com +461 -0
  243. data/ext/src/third-party/zlib-1.2.3/minigzip.c +322 -0
  244. data/ext/src/third-party/zlib-1.2.3/msdos/Makefile.bor +109 -0
  245. data/ext/src/third-party/zlib-1.2.3/msdos/Makefile.dj2 +104 -0
  246. data/ext/src/third-party/zlib-1.2.3/msdos/Makefile.emx +69 -0
  247. data/ext/src/third-party/zlib-1.2.3/msdos/Makefile.msc +106 -0
  248. data/ext/src/third-party/zlib-1.2.3/msdos/Makefile.tc +94 -0
  249. data/ext/src/third-party/zlib-1.2.3/old/Makefile.riscos +151 -0
  250. data/ext/src/third-party/zlib-1.2.3/old/README +3 -0
  251. data/ext/src/third-party/zlib-1.2.3/old/descrip.mms +48 -0
  252. data/ext/src/third-party/zlib-1.2.3/old/os2/Makefile.os2 +136 -0
  253. data/ext/src/third-party/zlib-1.2.3/old/os2/zlib.def +51 -0
  254. data/ext/src/third-party/zlib-1.2.3/old/visual-basic.txt +160 -0
  255. data/ext/src/third-party/zlib-1.2.3/old/zlib.html +971 -0
  256. data/ext/src/third-party/zlib-1.2.3/projects/README.projects +41 -0
  257. data/ext/src/third-party/zlib-1.2.3/projects/visualc6/README.txt +73 -0
  258. data/ext/src/third-party/zlib-1.2.3/projects/visualc6/example.dsp +278 -0
  259. data/ext/src/third-party/zlib-1.2.3/projects/visualc6/minigzip.dsp +278 -0
  260. data/ext/src/third-party/zlib-1.2.3/projects/visualc6/zlib.dsp +609 -0
  261. data/ext/src/third-party/zlib-1.2.3/projects/visualc6/zlib.dsw +59 -0
  262. data/ext/src/third-party/zlib-1.2.3/qnx/package.qpg +141 -0
  263. data/ext/src/third-party/zlib-1.2.3/trees.c +1219 -0
  264. data/ext/src/third-party/zlib-1.2.3/trees.h +128 -0
  265. data/ext/src/third-party/zlib-1.2.3/uncompr.c +61 -0
  266. data/ext/src/third-party/zlib-1.2.3/win32/DLL_FAQ.txt +397 -0
  267. data/ext/src/third-party/zlib-1.2.3/win32/Makefile.bor +107 -0
  268. data/ext/src/third-party/zlib-1.2.3/win32/Makefile.emx +69 -0
  269. data/ext/src/third-party/zlib-1.2.3/win32/Makefile.gcc +141 -0
  270. data/ext/src/third-party/zlib-1.2.3/win32/Makefile.msc +126 -0
  271. data/ext/src/third-party/zlib-1.2.3/win32/VisualC.txt +3 -0
  272. data/ext/src/third-party/zlib-1.2.3/win32/zlib.def +60 -0
  273. data/ext/src/third-party/zlib-1.2.3/win32/zlib1.rc +39 -0
  274. data/ext/src/third-party/zlib-1.2.3/zconf.h +332 -0
  275. data/ext/src/third-party/zlib-1.2.3/zconf.in.h +332 -0
  276. data/ext/src/third-party/zlib-1.2.3/zlib.3 +159 -0
  277. data/ext/src/third-party/zlib-1.2.3/zlib.h +1357 -0
  278. data/ext/src/third-party/zlib-1.2.3/zutil.c +318 -0
  279. data/ext/src/third-party/zlib-1.2.3/zutil.h +269 -0
  280. data/lib/bio-velvet_underground.rb +12 -0
  281. data/lib/bio-velvet_underground/external/VERSION +1 -0
  282. data/lib/bio-velvet_underground/velvet_underground.rb +72 -0
  283. data/spec/binary_sequence_store_spec.rb +27 -0
  284. data/spec/data/1/CnyUnifiedSeq +0 -0
  285. data/spec/spec_helper.rb +31 -0
  286. metadata +456 -0
@@ -0,0 +1,42 @@
1
+ This directory contains examples of the use of zlib.
2
+
3
+ fitblk.c
4
+ compress just enough input to nearly fill a requested output size
5
+ - zlib isn't designed to do this, but fitblk does it anyway
6
+
7
+ gun.c
8
+ uncompress a gzip file
9
+ - illustrates the use of inflateBack() for high speed file-to-file
10
+ decompression using call-back functions
11
+ - is approximately twice as fast as gzip -d
12
+ - also provides Unix uncompress functionality, again twice as fast
13
+
14
+ gzappend.c
15
+ append to a gzip file
16
+ - illustrates the use of the Z_BLOCK flush parameter for inflate()
17
+ - illustrates the use of deflatePrime() to start at any bit
18
+
19
+ gzjoin.c
20
+ join gzip files without recalculating the crc or recompressing
21
+ - illustrates the use of the Z_BLOCK flush parameter for inflate()
22
+ - illustrates the use of crc32_combine()
23
+
24
+ gzlog.c
25
+ gzlog.h
26
+ efficiently maintain a message log file in gzip format
27
+ - illustrates use of raw deflate and Z_SYNC_FLUSH
28
+ - illustrates use of gzip header extra field
29
+
30
+ zlib_how.html
31
+ painfully comprehensive description of zpipe.c (see below)
32
+ - describes in excruciating detail the use of deflate() and inflate()
33
+
34
+ zpipe.c
35
+ reads and writes zlib streams from stdin to stdout
36
+ - illustrates the proper use of deflate() and inflate()
37
+ - deeply commented in zlib_how.html (see above)
38
+
39
+ zran.c
40
+ index a zlib or gzip stream and randomly access it
41
+ - illustrates the use of Z_BLOCK, inflatePrime(), and
42
+ inflateSetDictionary() to provide random access
@@ -0,0 +1,233 @@
1
+ /* fitblk.c: example of fitting compressed output to a specified size
2
+ Not copyrighted -- provided to the public domain
3
+ Version 1.1 25 November 2004 Mark Adler */
4
+
5
+ /* Version history:
6
+ 1.0 24 Nov 2004 First version
7
+ 1.1 25 Nov 2004 Change deflateInit2() to deflateInit()
8
+ Use fixed-size, stack-allocated raw buffers
9
+ Simplify code moving compression to subroutines
10
+ Use assert() for internal errors
11
+ Add detailed description of approach
12
+ */
13
+
14
+ /* Approach to just fitting a requested compressed size:
15
+
16
+ fitblk performs three compression passes on a portion of the input
17
+ data in order to determine how much of that input will compress to
18
+ nearly the requested output block size. The first pass generates
19
+ enough deflate blocks to produce output to fill the requested
20
+ output size plus a specfied excess amount (see the EXCESS define
21
+ below). The last deflate block may go quite a bit past that, but
22
+ is discarded. The second pass decompresses and recompresses just
23
+ the compressed data that fit in the requested plus excess sized
24
+ buffer. The deflate process is terminated after that amount of
25
+ input, which is less than the amount consumed on the first pass.
26
+ The last deflate block of the result will be of a comparable size
27
+ to the final product, so that the header for that deflate block and
28
+ the compression ratio for that block will be about the same as in
29
+ the final product. The third compression pass decompresses the
30
+ result of the second step, but only the compressed data up to the
31
+ requested size minus an amount to allow the compressed stream to
32
+ complete (see the MARGIN define below). That will result in a
33
+ final compressed stream whose length is less than or equal to the
34
+ requested size. Assuming sufficient input and a requested size
35
+ greater than a few hundred bytes, the shortfall will typically be
36
+ less than ten bytes.
37
+
38
+ If the input is short enough that the first compression completes
39
+ before filling the requested output size, then that compressed
40
+ stream is return with no recompression.
41
+
42
+ EXCESS is chosen to be just greater than the shortfall seen in a
43
+ two pass approach similar to the above. That shortfall is due to
44
+ the last deflate block compressing more efficiently with a smaller
45
+ header on the second pass. EXCESS is set to be large enough so
46
+ that there is enough uncompressed data for the second pass to fill
47
+ out the requested size, and small enough so that the final deflate
48
+ block of the second pass will be close in size to the final deflate
49
+ block of the third and final pass. MARGIN is chosen to be just
50
+ large enough to assure that the final compression has enough room
51
+ to complete in all cases.
52
+ */
53
+
54
+ #include <stdio.h>
55
+ #include <stdlib.h>
56
+ #include <assert.h>
57
+ #include "zlib.h"
58
+
59
+ #define local static
60
+
61
+ /* print nastygram and leave */
62
+ local void quit(char *why)
63
+ {
64
+ fprintf(stderr, "fitblk abort: %s\n", why);
65
+ exit(1);
66
+ }
67
+
68
+ #define RAWLEN 4096 /* intermediate uncompressed buffer size */
69
+
70
+ /* compress from file to def until provided buffer is full or end of
71
+ input reached; return last deflate() return value, or Z_ERRNO if
72
+ there was read error on the file */
73
+ local int partcompress(FILE *in, z_streamp def)
74
+ {
75
+ int ret, flush;
76
+ unsigned char raw[RAWLEN];
77
+
78
+ flush = Z_NO_FLUSH;
79
+ do {
80
+ def->avail_in = fread(raw, 1, RAWLEN, in);
81
+ if (ferror(in))
82
+ return Z_ERRNO;
83
+ def->next_in = raw;
84
+ if (feof(in))
85
+ flush = Z_FINISH;
86
+ ret = deflate(def, flush);
87
+ assert(ret != Z_STREAM_ERROR);
88
+ } while (def->avail_out != 0 && flush == Z_NO_FLUSH);
89
+ return ret;
90
+ }
91
+
92
+ /* recompress from inf's input to def's output; the input for inf and
93
+ the output for def are set in those structures before calling;
94
+ return last deflate() return value, or Z_MEM_ERROR if inflate()
95
+ was not able to allocate enough memory when it needed to */
96
+ local int recompress(z_streamp inf, z_streamp def)
97
+ {
98
+ int ret, flush;
99
+ unsigned char raw[RAWLEN];
100
+
101
+ flush = Z_NO_FLUSH;
102
+ do {
103
+ /* decompress */
104
+ inf->avail_out = RAWLEN;
105
+ inf->next_out = raw;
106
+ ret = inflate(inf, Z_NO_FLUSH);
107
+ assert(ret != Z_STREAM_ERROR && ret != Z_DATA_ERROR &&
108
+ ret != Z_NEED_DICT);
109
+ if (ret == Z_MEM_ERROR)
110
+ return ret;
111
+
112
+ /* compress what was decompresed until done or no room */
113
+ def->avail_in = RAWLEN - inf->avail_out;
114
+ def->next_in = raw;
115
+ if (inf->avail_out != 0)
116
+ flush = Z_FINISH;
117
+ ret = deflate(def, flush);
118
+ assert(ret != Z_STREAM_ERROR);
119
+ } while (ret != Z_STREAM_END && def->avail_out != 0);
120
+ return ret;
121
+ }
122
+
123
+ #define EXCESS 256 /* empirically determined stream overage */
124
+ #define MARGIN 8 /* amount to back off for completion */
125
+
126
+ /* compress from stdin to fixed-size block on stdout */
127
+ int main(int argc, char **argv)
128
+ {
129
+ int ret; /* return code */
130
+ unsigned size; /* requested fixed output block size */
131
+ unsigned have; /* bytes written by deflate() call */
132
+ unsigned char *blk; /* intermediate and final stream */
133
+ unsigned char *tmp; /* close to desired size stream */
134
+ z_stream def, inf; /* zlib deflate and inflate states */
135
+
136
+ /* get requested output size */
137
+ if (argc != 2)
138
+ quit("need one argument: size of output block");
139
+ ret = strtol(argv[1], argv + 1, 10);
140
+ if (argv[1][0] != 0)
141
+ quit("argument must be a number");
142
+ if (ret < 8) /* 8 is minimum zlib stream size */
143
+ quit("need positive size of 8 or greater");
144
+ size = (unsigned)ret;
145
+
146
+ /* allocate memory for buffers and compression engine */
147
+ blk = malloc(size + EXCESS);
148
+ def.zalloc = Z_NULL;
149
+ def.zfree = Z_NULL;
150
+ def.opaque = Z_NULL;
151
+ ret = deflateInit(&def, Z_DEFAULT_COMPRESSION);
152
+ if (ret != Z_OK || blk == NULL)
153
+ quit("out of memory");
154
+
155
+ /* compress from stdin until output full, or no more input */
156
+ def.avail_out = size + EXCESS;
157
+ def.next_out = blk;
158
+ ret = partcompress(stdin, &def);
159
+ if (ret == Z_ERRNO)
160
+ quit("error reading input");
161
+
162
+ /* if it all fit, then size was undersubscribed -- done! */
163
+ if (ret == Z_STREAM_END && def.avail_out >= EXCESS) {
164
+ /* write block to stdout */
165
+ have = size + EXCESS - def.avail_out;
166
+ if (fwrite(blk, 1, have, stdout) != have || ferror(stdout))
167
+ quit("error writing output");
168
+
169
+ /* clean up and print results to stderr */
170
+ ret = deflateEnd(&def);
171
+ assert(ret != Z_STREAM_ERROR);
172
+ free(blk);
173
+ fprintf(stderr,
174
+ "%u bytes unused out of %u requested (all input)\n",
175
+ size - have, size);
176
+ return 0;
177
+ }
178
+
179
+ /* it didn't all fit -- set up for recompression */
180
+ inf.zalloc = Z_NULL;
181
+ inf.zfree = Z_NULL;
182
+ inf.opaque = Z_NULL;
183
+ inf.avail_in = 0;
184
+ inf.next_in = Z_NULL;
185
+ ret = inflateInit(&inf);
186
+ tmp = malloc(size + EXCESS);
187
+ if (ret != Z_OK || tmp == NULL)
188
+ quit("out of memory");
189
+ ret = deflateReset(&def);
190
+ assert(ret != Z_STREAM_ERROR);
191
+
192
+ /* do first recompression close to the right amount */
193
+ inf.avail_in = size + EXCESS;
194
+ inf.next_in = blk;
195
+ def.avail_out = size + EXCESS;
196
+ def.next_out = tmp;
197
+ ret = recompress(&inf, &def);
198
+ if (ret == Z_MEM_ERROR)
199
+ quit("out of memory");
200
+
201
+ /* set up for next reocmpression */
202
+ ret = inflateReset(&inf);
203
+ assert(ret != Z_STREAM_ERROR);
204
+ ret = deflateReset(&def);
205
+ assert(ret != Z_STREAM_ERROR);
206
+
207
+ /* do second and final recompression (third compression) */
208
+ inf.avail_in = size - MARGIN; /* assure stream will complete */
209
+ inf.next_in = tmp;
210
+ def.avail_out = size;
211
+ def.next_out = blk;
212
+ ret = recompress(&inf, &def);
213
+ if (ret == Z_MEM_ERROR)
214
+ quit("out of memory");
215
+ assert(ret == Z_STREAM_END); /* otherwise MARGIN too small */
216
+
217
+ /* done -- write block to stdout */
218
+ have = size - def.avail_out;
219
+ if (fwrite(blk, 1, have, stdout) != have || ferror(stdout))
220
+ quit("error writing output");
221
+
222
+ /* clean up and print results to stderr */
223
+ free(tmp);
224
+ ret = inflateEnd(&inf);
225
+ assert(ret != Z_STREAM_ERROR);
226
+ ret = deflateEnd(&def);
227
+ assert(ret != Z_STREAM_ERROR);
228
+ free(blk);
229
+ fprintf(stderr,
230
+ "%u bytes unused out of %u requested (%lu input)\n",
231
+ size - have, size, def.total_in);
232
+ return 0;
233
+ }
@@ -0,0 +1,693 @@
1
+ /* gun.c -- simple gunzip to give an example of the use of inflateBack()
2
+ * Copyright (C) 2003, 2005 Mark Adler
3
+ * For conditions of distribution and use, see copyright notice in zlib.h
4
+ Version 1.3 12 June 2005 Mark Adler */
5
+
6
+ /* Version history:
7
+ 1.0 16 Feb 2003 First version for testing of inflateBack()
8
+ 1.1 21 Feb 2005 Decompress concatenated gzip streams
9
+ Remove use of "this" variable (C++ keyword)
10
+ Fix return value for in()
11
+ Improve allocation failure checking
12
+ Add typecasting for void * structures
13
+ Add -h option for command version and usage
14
+ Add a bunch of comments
15
+ 1.2 20 Mar 2005 Add Unix compress (LZW) decompression
16
+ Copy file attributes from input file to output file
17
+ 1.3 12 Jun 2005 Add casts for error messages [Oberhumer]
18
+ */
19
+
20
+ /*
21
+ gun [ -t ] [ name ... ]
22
+
23
+ decompresses the data in the named gzip files. If no arguments are given,
24
+ gun will decompress from stdin to stdout. The names must end in .gz, -gz,
25
+ .z, -z, _z, or .Z. The uncompressed data will be written to a file name
26
+ with the suffix stripped. On success, the original file is deleted. On
27
+ failure, the output file is deleted. For most failures, the command will
28
+ continue to process the remaining names on the command line. A memory
29
+ allocation failure will abort the command. If -t is specified, then the
30
+ listed files or stdin will be tested as gzip files for integrity (without
31
+ checking for a proper suffix), no output will be written, and no files
32
+ will be deleted.
33
+
34
+ Like gzip, gun allows concatenated gzip streams and will decompress them,
35
+ writing all of the uncompressed data to the output. Unlike gzip, gun allows
36
+ an empty file on input, and will produce no error writing an empty output
37
+ file.
38
+
39
+ gun will also decompress files made by Unix compress, which uses LZW
40
+ compression. These files are automatically detected by virtue of their
41
+ magic header bytes. Since the end of Unix compress stream is marked by the
42
+ end-of-file, they cannot be concantenated. If a Unix compress stream is
43
+ encountered in an input file, it is the last stream in that file.
44
+
45
+ Like gunzip and uncompress, the file attributes of the orignal compressed
46
+ file are maintained in the final uncompressed file, to the extent that the
47
+ user permissions allow it.
48
+
49
+ On my Mac OS X PowerPC G4, gun is almost twice as fast as gunzip (version
50
+ 1.2.4) is on the same file, when gun is linked with zlib 1.2.2. Also the
51
+ LZW decompression provided by gun is about twice as fast as the standard
52
+ Unix uncompress command.
53
+ */
54
+
55
+ /* external functions and related types and constants */
56
+ #include <stdio.h> /* fprintf() */
57
+ #include <stdlib.h> /* malloc(), free() */
58
+ #include <string.h> /* strerror(), strcmp(), strlen(), memcpy() */
59
+ #include <errno.h> /* errno */
60
+ #include <fcntl.h> /* open() */
61
+ #include <unistd.h> /* read(), write(), close(), chown(), unlink() */
62
+ #include <sys/types.h>
63
+ #include <sys/stat.h> /* stat(), chmod() */
64
+ #include <utime.h> /* utime() */
65
+ #include "zlib.h" /* inflateBackInit(), inflateBack(), */
66
+ /* inflateBackEnd(), crc32() */
67
+
68
+ /* function declaration */
69
+ #define local static
70
+
71
+ /* buffer constants */
72
+ #define SIZE 32768U /* input and output buffer sizes */
73
+ #define PIECE 16384 /* limits i/o chunks for 16-bit int case */
74
+
75
+ /* structure for infback() to pass to input function in() -- it maintains the
76
+ input file and a buffer of size SIZE */
77
+ struct ind {
78
+ int infile;
79
+ unsigned char *inbuf;
80
+ };
81
+
82
+ /* Load input buffer, assumed to be empty, and return bytes loaded and a
83
+ pointer to them. read() is called until the buffer is full, or until it
84
+ returns end-of-file or error. Return 0 on error. */
85
+ local unsigned in(void *in_desc, unsigned char **buf)
86
+ {
87
+ int ret;
88
+ unsigned len;
89
+ unsigned char *next;
90
+ struct ind *me = (struct ind *)in_desc;
91
+
92
+ next = me->inbuf;
93
+ *buf = next;
94
+ len = 0;
95
+ do {
96
+ ret = PIECE;
97
+ if ((unsigned)ret > SIZE - len)
98
+ ret = (int)(SIZE - len);
99
+ ret = (int)read(me->infile, next, ret);
100
+ if (ret == -1) {
101
+ len = 0;
102
+ break;
103
+ }
104
+ next += ret;
105
+ len += ret;
106
+ } while (ret != 0 && len < SIZE);
107
+ return len;
108
+ }
109
+
110
+ /* structure for infback() to pass to output function out() -- it maintains the
111
+ output file, a running CRC-32 check on the output and the total number of
112
+ bytes output, both for checking against the gzip trailer. (The length in
113
+ the gzip trailer is stored modulo 2^32, so it's ok if a long is 32 bits and
114
+ the output is greater than 4 GB.) */
115
+ struct outd {
116
+ int outfile;
117
+ int check; /* true if checking crc and total */
118
+ unsigned long crc;
119
+ unsigned long total;
120
+ };
121
+
122
+ /* Write output buffer and update the CRC-32 and total bytes written. write()
123
+ is called until all of the output is written or an error is encountered.
124
+ On success out() returns 0. For a write failure, out() returns 1. If the
125
+ output file descriptor is -1, then nothing is written.
126
+ */
127
+ local int out(void *out_desc, unsigned char *buf, unsigned len)
128
+ {
129
+ int ret;
130
+ struct outd *me = (struct outd *)out_desc;
131
+
132
+ if (me->check) {
133
+ me->crc = crc32(me->crc, buf, len);
134
+ me->total += len;
135
+ }
136
+ if (me->outfile != -1)
137
+ do {
138
+ ret = PIECE;
139
+ if ((unsigned)ret > len)
140
+ ret = (int)len;
141
+ ret = (int)write(me->outfile, buf, ret);
142
+ if (ret == -1)
143
+ return 1;
144
+ buf += ret;
145
+ len -= ret;
146
+ } while (len != 0);
147
+ return 0;
148
+ }
149
+
150
+ /* next input byte macro for use inside lunpipe() and gunpipe() */
151
+ #define NEXT() (have ? 0 : (have = in(indp, &next)), \
152
+ last = have ? (have--, (int)(*next++)) : -1)
153
+
154
+ /* memory for gunpipe() and lunpipe() --
155
+ the first 256 entries of prefix[] and suffix[] are never used, could
156
+ have offset the index, but it's faster to waste the memory */
157
+ unsigned char inbuf[SIZE]; /* input buffer */
158
+ unsigned char outbuf[SIZE]; /* output buffer */
159
+ unsigned short prefix[65536]; /* index to LZW prefix string */
160
+ unsigned char suffix[65536]; /* one-character LZW suffix */
161
+ unsigned char match[65280 + 2]; /* buffer for reversed match or gzip
162
+ 32K sliding window */
163
+
164
+ /* throw out what's left in the current bits byte buffer (this is a vestigial
165
+ aspect of the compressed data format derived from an implementation that
166
+ made use of a special VAX machine instruction!) */
167
+ #define FLUSHCODE() \
168
+ do { \
169
+ left = 0; \
170
+ rem = 0; \
171
+ if (chunk > have) { \
172
+ chunk -= have; \
173
+ have = 0; \
174
+ if (NEXT() == -1) \
175
+ break; \
176
+ chunk--; \
177
+ if (chunk > have) { \
178
+ chunk = have = 0; \
179
+ break; \
180
+ } \
181
+ } \
182
+ have -= chunk; \
183
+ next += chunk; \
184
+ chunk = 0; \
185
+ } while (0)
186
+
187
+ /* Decompress a compress (LZW) file from indp to outfile. The compress magic
188
+ header (two bytes) has already been read and verified. There are have bytes
189
+ of buffered input at next. strm is used for passing error information back
190
+ to gunpipe().
191
+
192
+ lunpipe() will return Z_OK on success, Z_BUF_ERROR for an unexpected end of
193
+ file, read error, or write error (a write error indicated by strm->next_in
194
+ not equal to Z_NULL), or Z_DATA_ERROR for invalid input.
195
+ */
196
+ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
197
+ int outfile, z_stream *strm)
198
+ {
199
+ int last; /* last byte read by NEXT(), or -1 if EOF */
200
+ int chunk; /* bytes left in current chunk */
201
+ int left; /* bits left in rem */
202
+ unsigned rem; /* unused bits from input */
203
+ int bits; /* current bits per code */
204
+ unsigned code; /* code, table traversal index */
205
+ unsigned mask; /* mask for current bits codes */
206
+ int max; /* maximum bits per code for this stream */
207
+ int flags; /* compress flags, then block compress flag */
208
+ unsigned end; /* last valid entry in prefix/suffix tables */
209
+ unsigned temp; /* current code */
210
+ unsigned prev; /* previous code */
211
+ unsigned final; /* last character written for previous code */
212
+ unsigned stack; /* next position for reversed string */
213
+ unsigned outcnt; /* bytes in output buffer */
214
+ struct outd outd; /* output structure */
215
+
216
+ /* set up output */
217
+ outd.outfile = outfile;
218
+ outd.check = 0;
219
+
220
+ /* process remainder of compress header -- a flags byte */
221
+ flags = NEXT();
222
+ if (last == -1)
223
+ return Z_BUF_ERROR;
224
+ if (flags & 0x60) {
225
+ strm->msg = (char *)"unknown lzw flags set";
226
+ return Z_DATA_ERROR;
227
+ }
228
+ max = flags & 0x1f;
229
+ if (max < 9 || max > 16) {
230
+ strm->msg = (char *)"lzw bits out of range";
231
+ return Z_DATA_ERROR;
232
+ }
233
+ if (max == 9) /* 9 doesn't really mean 9 */
234
+ max = 10;
235
+ flags &= 0x80; /* true if block compress */
236
+
237
+ /* clear table */
238
+ bits = 9;
239
+ mask = 0x1ff;
240
+ end = flags ? 256 : 255;
241
+
242
+ /* set up: get first 9-bit code, which is the first decompressed byte, but
243
+ don't create a table entry until the next code */
244
+ if (NEXT() == -1) /* no compressed data is ok */
245
+ return Z_OK;
246
+ final = prev = (unsigned)last; /* low 8 bits of code */
247
+ if (NEXT() == -1) /* missing a bit */
248
+ return Z_BUF_ERROR;
249
+ if (last & 1) { /* code must be < 256 */
250
+ strm->msg = (char *)"invalid lzw code";
251
+ return Z_DATA_ERROR;
252
+ }
253
+ rem = (unsigned)last >> 1; /* remaining 7 bits */
254
+ left = 7;
255
+ chunk = bits - 2; /* 7 bytes left in this chunk */
256
+ outbuf[0] = (unsigned char)final; /* write first decompressed byte */
257
+ outcnt = 1;
258
+
259
+ /* decode codes */
260
+ stack = 0;
261
+ for (;;) {
262
+ /* if the table will be full after this, increment the code size */
263
+ if (end >= mask && bits < max) {
264
+ FLUSHCODE();
265
+ bits++;
266
+ mask <<= 1;
267
+ mask++;
268
+ }
269
+
270
+ /* get a code of length bits */
271
+ if (chunk == 0) /* decrement chunk modulo bits */
272
+ chunk = bits;
273
+ code = rem; /* low bits of code */
274
+ if (NEXT() == -1) { /* EOF is end of compressed data */
275
+ /* write remaining buffered output */
276
+ if (outcnt && out(&outd, outbuf, outcnt)) {
277
+ strm->next_in = outbuf; /* signal write error */
278
+ return Z_BUF_ERROR;
279
+ }
280
+ return Z_OK;
281
+ }
282
+ code += (unsigned)last << left; /* middle (or high) bits of code */
283
+ left += 8;
284
+ chunk--;
285
+ if (bits > left) { /* need more bits */
286
+ if (NEXT() == -1) /* can't end in middle of code */
287
+ return Z_BUF_ERROR;
288
+ code += (unsigned)last << left; /* high bits of code */
289
+ left += 8;
290
+ chunk--;
291
+ }
292
+ code &= mask; /* mask to current code length */
293
+ left -= bits; /* number of unused bits */
294
+ rem = (unsigned)last >> (8 - left); /* unused bits from last byte */
295
+
296
+ /* process clear code (256) */
297
+ if (code == 256 && flags) {
298
+ FLUSHCODE();
299
+ bits = 9; /* initialize bits and mask */
300
+ mask = 0x1ff;
301
+ end = 255; /* empty table */
302
+ continue; /* get next code */
303
+ }
304
+
305
+ /* special code to reuse last match */
306
+ temp = code; /* save the current code */
307
+ if (code > end) {
308
+ /* Be picky on the allowed code here, and make sure that the code
309
+ we drop through (prev) will be a valid index so that random
310
+ input does not cause an exception. The code != end + 1 check is
311
+ empirically derived, and not checked in the original uncompress
312
+ code. If this ever causes a problem, that check could be safely
313
+ removed. Leaving this check in greatly improves gun's ability
314
+ to detect random or corrupted input after a compress header.
315
+ In any case, the prev > end check must be retained. */
316
+ if (code != end + 1 || prev > end) {
317
+ strm->msg = (char *)"invalid lzw code";
318
+ return Z_DATA_ERROR;
319
+ }
320
+ match[stack++] = (unsigned char)final;
321
+ code = prev;
322
+ }
323
+
324
+ /* walk through linked list to generate output in reverse order */
325
+ while (code >= 256) {
326
+ match[stack++] = suffix[code];
327
+ code = prefix[code];
328
+ }
329
+ match[stack++] = (unsigned char)code;
330
+ final = code;
331
+
332
+ /* link new table entry */
333
+ if (end < mask) {
334
+ end++;
335
+ prefix[end] = (unsigned short)prev;
336
+ suffix[end] = (unsigned char)final;
337
+ }
338
+
339
+ /* set previous code for next iteration */
340
+ prev = temp;
341
+
342
+ /* write output in forward order */
343
+ while (stack > SIZE - outcnt) {
344
+ while (outcnt < SIZE)
345
+ outbuf[outcnt++] = match[--stack];
346
+ if (out(&outd, outbuf, outcnt)) {
347
+ strm->next_in = outbuf; /* signal write error */
348
+ return Z_BUF_ERROR;
349
+ }
350
+ outcnt = 0;
351
+ }
352
+ do {
353
+ outbuf[outcnt++] = match[--stack];
354
+ } while (stack);
355
+
356
+ /* loop for next code with final and prev as the last match, rem and
357
+ left provide the first 0..7 bits of the next code, end is the last
358
+ valid table entry */
359
+ }
360
+ }
361
+
362
+ /* Decompress a gzip file from infile to outfile. strm is assumed to have been
363
+ successfully initialized with inflateBackInit(). The input file may consist
364
+ of a series of gzip streams, in which case all of them will be decompressed
365
+ to the output file. If outfile is -1, then the gzip stream(s) integrity is
366
+ checked and nothing is written.
367
+
368
+ The return value is a zlib error code: Z_MEM_ERROR if out of memory,
369
+ Z_DATA_ERROR if the header or the compressed data is invalid, or if the
370
+ trailer CRC-32 check or length doesn't match, Z_BUF_ERROR if the input ends
371
+ prematurely or a write error occurs, or Z_ERRNO if junk (not a another gzip
372
+ stream) follows a valid gzip stream.
373
+ */
374
+ local int gunpipe(z_stream *strm, int infile, int outfile)
375
+ {
376
+ int ret, first, last;
377
+ unsigned have, flags, len;
378
+ unsigned char *next;
379
+ struct ind ind, *indp;
380
+ struct outd outd;
381
+
382
+ /* setup input buffer */
383
+ ind.infile = infile;
384
+ ind.inbuf = inbuf;
385
+ indp = &ind;
386
+
387
+ /* decompress concatenated gzip streams */
388
+ have = 0; /* no input data read in yet */
389
+ first = 1; /* looking for first gzip header */
390
+ strm->next_in = Z_NULL; /* so Z_BUF_ERROR means EOF */
391
+ for (;;) {
392
+ /* look for the two magic header bytes for a gzip stream */
393
+ if (NEXT() == -1) {
394
+ ret = Z_OK;
395
+ break; /* empty gzip stream is ok */
396
+ }
397
+ if (last != 31 || (NEXT() != 139 && last != 157)) {
398
+ strm->msg = (char *)"incorrect header check";
399
+ ret = first ? Z_DATA_ERROR : Z_ERRNO;
400
+ break; /* not a gzip or compress header */
401
+ }
402
+ first = 0; /* next non-header is junk */
403
+
404
+ /* process a compress (LZW) file -- can't be concatenated after this */
405
+ if (last == 157) {
406
+ ret = lunpipe(have, next, indp, outfile, strm);
407
+ break;
408
+ }
409
+
410
+ /* process remainder of gzip header */
411
+ ret = Z_BUF_ERROR;
412
+ if (NEXT() != 8) { /* only deflate method allowed */
413
+ if (last == -1) break;
414
+ strm->msg = (char *)"unknown compression method";
415
+ ret = Z_DATA_ERROR;
416
+ break;
417
+ }
418
+ flags = NEXT(); /* header flags */
419
+ NEXT(); /* discard mod time, xflgs, os */
420
+ NEXT();
421
+ NEXT();
422
+ NEXT();
423
+ NEXT();
424
+ NEXT();
425
+ if (last == -1) break;
426
+ if (flags & 0xe0) {
427
+ strm->msg = (char *)"unknown header flags set";
428
+ ret = Z_DATA_ERROR;
429
+ break;
430
+ }
431
+ if (flags & 4) { /* extra field */
432
+ len = NEXT();
433
+ len += (unsigned)(NEXT()) << 8;
434
+ if (last == -1) break;
435
+ while (len > have) {
436
+ len -= have;
437
+ have = 0;
438
+ if (NEXT() == -1) break;
439
+ len--;
440
+ }
441
+ if (last == -1) break;
442
+ have -= len;
443
+ next += len;
444
+ }
445
+ if (flags & 8) /* file name */
446
+ while (NEXT() != 0 && last != -1)
447
+ ;
448
+ if (flags & 16) /* comment */
449
+ while (NEXT() != 0 && last != -1)
450
+ ;
451
+ if (flags & 2) { /* header crc */
452
+ NEXT();
453
+ NEXT();
454
+ }
455
+ if (last == -1) break;
456
+
457
+ /* set up output */
458
+ outd.outfile = outfile;
459
+ outd.check = 1;
460
+ outd.crc = crc32(0L, Z_NULL, 0);
461
+ outd.total = 0;
462
+
463
+ /* decompress data to output */
464
+ strm->next_in = next;
465
+ strm->avail_in = have;
466
+ ret = inflateBack(strm, in, indp, out, &outd);
467
+ if (ret != Z_STREAM_END) break;
468
+ next = strm->next_in;
469
+ have = strm->avail_in;
470
+ strm->next_in = Z_NULL; /* so Z_BUF_ERROR means EOF */
471
+
472
+ /* check trailer */
473
+ ret = Z_BUF_ERROR;
474
+ if (NEXT() != (outd.crc & 0xff) ||
475
+ NEXT() != ((outd.crc >> 8) & 0xff) ||
476
+ NEXT() != ((outd.crc >> 16) & 0xff) ||
477
+ NEXT() != ((outd.crc >> 24) & 0xff)) {
478
+ /* crc error */
479
+ if (last != -1) {
480
+ strm->msg = (char *)"incorrect data check";
481
+ ret = Z_DATA_ERROR;
482
+ }
483
+ break;
484
+ }
485
+ if (NEXT() != (outd.total & 0xff) ||
486
+ NEXT() != ((outd.total >> 8) & 0xff) ||
487
+ NEXT() != ((outd.total >> 16) & 0xff) ||
488
+ NEXT() != ((outd.total >> 24) & 0xff)) {
489
+ /* length error */
490
+ if (last != -1) {
491
+ strm->msg = (char *)"incorrect length check";
492
+ ret = Z_DATA_ERROR;
493
+ }
494
+ break;
495
+ }
496
+
497
+ /* go back and look for another gzip stream */
498
+ }
499
+
500
+ /* clean up and return */
501
+ return ret;
502
+ }
503
+
504
+ /* Copy file attributes, from -> to, as best we can. This is best effort, so
505
+ no errors are reported. The mode bits, including suid, sgid, and the sticky
506
+ bit are copied (if allowed), the owner's user id and group id are copied
507
+ (again if allowed), and the access and modify times are copied. */
508
+ local void copymeta(char *from, char *to)
509
+ {
510
+ struct stat was;
511
+ struct utimbuf when;
512
+
513
+ /* get all of from's Unix meta data, return if not a regular file */
514
+ if (stat(from, &was) != 0 || (was.st_mode & S_IFMT) != S_IFREG)
515
+ return;
516
+
517
+ /* set to's mode bits, ignore errors */
518
+ (void)chmod(to, was.st_mode & 07777);
519
+
520
+ /* copy owner's user and group, ignore errors */
521
+ (void)chown(to, was.st_uid, was.st_gid);
522
+
523
+ /* copy access and modify times, ignore errors */
524
+ when.actime = was.st_atime;
525
+ when.modtime = was.st_mtime;
526
+ (void)utime(to, &when);
527
+ }
528
+
529
+ /* Decompress the file inname to the file outnname, of if test is true, just
530
+ decompress without writing and check the gzip trailer for integrity. If
531
+ inname is NULL or an empty string, read from stdin. If outname is NULL or
532
+ an empty string, write to stdout. strm is a pre-initialized inflateBack
533
+ structure. When appropriate, copy the file attributes from inname to
534
+ outname.
535
+
536
+ gunzip() returns 1 if there is an out-of-memory error or an unexpected
537
+ return code from gunpipe(). Otherwise it returns 0.
538
+ */
539
+ local int gunzip(z_stream *strm, char *inname, char *outname, int test)
540
+ {
541
+ int ret;
542
+ int infile, outfile;
543
+
544
+ /* open files */
545
+ if (inname == NULL || *inname == 0) {
546
+ inname = "-";
547
+ infile = 0; /* stdin */
548
+ }
549
+ else {
550
+ infile = open(inname, O_RDONLY, 0);
551
+ if (infile == -1) {
552
+ fprintf(stderr, "gun cannot open %s\n", inname);
553
+ return 0;
554
+ }
555
+ }
556
+ if (test)
557
+ outfile = -1;
558
+ else if (outname == NULL || *outname == 0) {
559
+ outname = "-";
560
+ outfile = 1; /* stdout */
561
+ }
562
+ else {
563
+ outfile = open(outname, O_CREAT | O_TRUNC | O_WRONLY, 0666);
564
+ if (outfile == -1) {
565
+ close(infile);
566
+ fprintf(stderr, "gun cannot create %s\n", outname);
567
+ return 0;
568
+ }
569
+ }
570
+ errno = 0;
571
+
572
+ /* decompress */
573
+ ret = gunpipe(strm, infile, outfile);
574
+ if (outfile > 2) close(outfile);
575
+ if (infile > 2) close(infile);
576
+
577
+ /* interpret result */
578
+ switch (ret) {
579
+ case Z_OK:
580
+ case Z_ERRNO:
581
+ if (infile > 2 && outfile > 2) {
582
+ copymeta(inname, outname); /* copy attributes */
583
+ unlink(inname);
584
+ }
585
+ if (ret == Z_ERRNO)
586
+ fprintf(stderr, "gun warning: trailing garbage ignored in %s\n",
587
+ inname);
588
+ break;
589
+ case Z_DATA_ERROR:
590
+ if (outfile > 2) unlink(outname);
591
+ fprintf(stderr, "gun data error on %s: %s\n", inname, strm->msg);
592
+ break;
593
+ case Z_MEM_ERROR:
594
+ if (outfile > 2) unlink(outname);
595
+ fprintf(stderr, "gun out of memory error--aborting\n");
596
+ return 1;
597
+ case Z_BUF_ERROR:
598
+ if (outfile > 2) unlink(outname);
599
+ if (strm->next_in != Z_NULL) {
600
+ fprintf(stderr, "gun write error on %s: %s\n",
601
+ outname, strerror(errno));
602
+ }
603
+ else if (errno) {
604
+ fprintf(stderr, "gun read error on %s: %s\n",
605
+ inname, strerror(errno));
606
+ }
607
+ else {
608
+ fprintf(stderr, "gun unexpected end of file on %s\n",
609
+ inname);
610
+ }
611
+ break;
612
+ default:
613
+ if (outfile > 2) unlink(outname);
614
+ fprintf(stderr, "gun internal error--aborting\n");
615
+ return 1;
616
+ }
617
+ return 0;
618
+ }
619
+
620
+ /* Process the gun command line arguments. See the command syntax near the
621
+ beginning of this source file. */
622
+ int main(int argc, char **argv)
623
+ {
624
+ int ret, len, test;
625
+ char *outname;
626
+ unsigned char *window;
627
+ z_stream strm;
628
+
629
+ /* initialize inflateBack state for repeated use */
630
+ window = match; /* reuse LZW match buffer */
631
+ strm.zalloc = Z_NULL;
632
+ strm.zfree = Z_NULL;
633
+ strm.opaque = Z_NULL;
634
+ ret = inflateBackInit(&strm, 15, window);
635
+ if (ret != Z_OK) {
636
+ fprintf(stderr, "gun out of memory error--aborting\n");
637
+ return 1;
638
+ }
639
+
640
+ /* decompress each file to the same name with the suffix removed */
641
+ argc--;
642
+ argv++;
643
+ test = 0;
644
+ if (argc && strcmp(*argv, "-h") == 0) {
645
+ fprintf(stderr, "gun 1.3 (12 Jun 2005)\n");
646
+ fprintf(stderr, "Copyright (c) 2005 Mark Adler\n");
647
+ fprintf(stderr, "usage: gun [-t] [file1.gz [file2.Z ...]]\n");
648
+ return 0;
649
+ }
650
+ if (argc && strcmp(*argv, "-t") == 0) {
651
+ test = 1;
652
+ argc--;
653
+ argv++;
654
+ }
655
+ if (argc)
656
+ do {
657
+ if (test)
658
+ outname = NULL;
659
+ else {
660
+ len = (int)strlen(*argv);
661
+ if (strcmp(*argv + len - 3, ".gz") == 0 ||
662
+ strcmp(*argv + len - 3, "-gz") == 0)
663
+ len -= 3;
664
+ else if (strcmp(*argv + len - 2, ".z") == 0 ||
665
+ strcmp(*argv + len - 2, "-z") == 0 ||
666
+ strcmp(*argv + len - 2, "_z") == 0 ||
667
+ strcmp(*argv + len - 2, ".Z") == 0)
668
+ len -= 2;
669
+ else {
670
+ fprintf(stderr, "gun error: no gz type on %s--skipping\n",
671
+ *argv);
672
+ continue;
673
+ }
674
+ outname = malloc(len + 1);
675
+ if (outname == NULL) {
676
+ fprintf(stderr, "gun out of memory error--aborting\n");
677
+ ret = 1;
678
+ break;
679
+ }
680
+ memcpy(outname, *argv, len);
681
+ outname[len] = 0;
682
+ }
683
+ ret = gunzip(&strm, *argv, outname, test);
684
+ if (outname != NULL) free(outname);
685
+ if (ret) break;
686
+ } while (argv++, --argc);
687
+ else
688
+ ret = gunzip(&strm, NULL, NULL, test);
689
+
690
+ /* clean up */
691
+ inflateBackEnd(&strm);
692
+ return ret;
693
+ }