home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 110 / EnigmaAmiga110CD.iso / indispensabili / utility / apdf / xpdf-0.80 / gzip.diff < prev    next >
Text File  |  1999-07-08  |  24KB  |  764 lines

  1. diff -u -b -B -r -N -w xpdf-0.80-decrypt/build020/xpdf/Makefile xpdf-0.80-decrypt-gzip/build020/xpdf/Makefile
  2. --- xpdf-0.80-decrypt/build020/xpdf/Makefile    Fri Jun 25 19:49:24 1999
  3. +++ xpdf-0.80-decrypt-gzip/build020/xpdf/Makefile       Fri Jun 25 19:25:56 1999
  4. @@ -52,6 +52,7 @@
  5.     $(srcdir)/PDFDoc.cc \
  6.     $(srcdir)/PSOutputDev.cc \
  7.     $(srcdir)/Stream.cc \
  8. +       $(srcdir)/unlzw.cc \
  9.     $(srcdir)/TextOutputDev.cc \
  10.     $(srcdir)/XRef.cc \
  11.     $(srcdir)/Apdf.c \
  12. @@ -72,7 +73,7 @@
  13.  #------------------------------------------------------------------------
  14.  
  15.  APDF_OBJS = Array.o Catalog.o Dict.o Error.o Gfx.o GfxFont.o \
  16. -       TextOutputDev.o AOutputDev.o XRef.o AGfx.o \
  17. +       TextOutputDev.o AOutputDev.o XRef.o AGfx.o unlzw.o \
  18.     GfxState.o Lexer.o Link.o Object.o OutputDev.o mystdio.o \
  19.     Page.o Parser.o PDFDoc.o PSOutputDev.o Stream.o \
  20.     Apdfcommon.o Apdf.o ImageOutputDev.o poly.o FontOutputDev.o \
  21. @@ -199,6 +200,11 @@
  22.   ../../xpdf/mystdio.h ../../xpdf/../goo/gtypes.h \
  23.   ../../xpdf/../goo/GString.h ../../xpdf/Array.h ../../xpdf/Dict.h \
  24.   ../../xpdf/Stream.h ../../xpdf/rc4.h ../../xpdf/Stream-CCITT.h
  25. +unlzw.o: ../../xpdf/unlzw.cc ../../xpdf/Object.h ../../xpdf/mystdio.h \
  26. + ../../xpdf/../goo/gtypes.h ../../xpdf/../goo/gmem.h \
  27. + ../../xpdf/../goo/GString.h ../../xpdf/Array.h ../../xpdf/Dict.h \
  28. + ../../xpdf/Stream.h ../../xpdf/Error.h ../../xpdf/config.h \
  29. + ../../xpdf/rc4.h
  30.  TextOutputDev.o: ../../xpdf/TextOutputDev.cc \
  31.   ../../xpdf/../goo/GString.h ../../xpdf/../goo/gmem.h \
  32.   ../../xpdf/config.h ../../xpdf/Error.h ../../xpdf/GfxState.h \
  33. diff -u -b -B -r -N -w xpdf-0.80-decrypt/build040/goo/Makefile xpdf-0.80-decrypt-gzip/build040/goo/Makefile
  34. --- xpdf-0.80-decrypt/build040/goo/Makefile     Fri Jun 25 19:41:17 1999
  35. +++ xpdf-0.80-decrypt-gzip/build040/goo/Makefile        Fri Jun 25 19:22:32 1999
  36. @@ -64,10 +64,3 @@
  37.     $(CC) $(CFLAGS) -MM $(C_SRC) >>Makefile
  38.  
  39.  #----- dependences -----
  40. -gmem.o: ../../goo/gmem.cc ../../goo/gmem.h
  41. -GString.o: ../../goo/GString.cc ../../goo/GString.h
  42. -gmempp.o: ../../goo/gmempp.cc ../../goo/gmem.h
  43. -gfile.o: ../../goo/gfile.cc ../../goo/GString.h ../../goo/gfile.h \
  44. - ../../goo/gtypes.h
  45. -parseargs.o: ../../goo/parseargs.c ../../goo/parseargs.h \
  46. - ../../goo/gtypes.h
  47. diff -u -b -B -r -N -w xpdf-0.80-decrypt/build040/xpdf/Makefile xpdf-0.80-decrypt-gzip/build040/xpdf/Makefile
  48. --- xpdf-0.80-decrypt/build040/xpdf/Makefile    Fri Jun 25 19:47:55 1999
  49. +++ xpdf-0.80-decrypt-gzip/build040/xpdf/Makefile       Fri Jun 25 19:25:29 1999
  50. @@ -52,6 +52,7 @@
  51.     $(srcdir)/PDFDoc.cc \
  52.     $(srcdir)/PSOutputDev.cc \
  53.     $(srcdir)/Stream.cc \
  54. +       $(srcdir)/unlzw.cc \
  55.     $(srcdir)/TextOutputDev.cc \
  56.     $(srcdir)/XRef.cc \
  57.     $(srcdir)/Apdf.c \
  58. @@ -72,7 +73,7 @@
  59.  #------------------------------------------------------------------------
  60.  
  61.  APDF_OBJS = Array.o Catalog.o Dict.o Error.o Gfx.o GfxFont.o \
  62. -       TextOutputDev.o AOutputDev.o XRef.o AGfx.o \
  63. +       TextOutputDev.o AOutputDev.o XRef.o AGfx.o unlzw.o \
  64.     GfxState.o Lexer.o Link.o Object.o OutputDev.o mystdio.o \
  65.     Page.o Parser.o PDFDoc.o PSOutputDev.o Stream.o \
  66.     Apdfcommon.o Apdf.o ImageOutputDev.o poly.o FontOutputDev.o \
  67. @@ -199,6 +200,11 @@
  68.   ../../xpdf/mystdio.h ../../xpdf/../goo/gtypes.h \
  69.   ../../xpdf/../goo/GString.h ../../xpdf/Array.h ../../xpdf/Dict.h \
  70.   ../../xpdf/Stream.h ../../xpdf/rc4.h ../../xpdf/Stream-CCITT.h
  71. +unlzw.o: ../../xpdf/unlzw.cc ../../xpdf/Object.h ../../xpdf/mystdio.h \
  72. + ../../xpdf/../goo/gtypes.h ../../xpdf/../goo/gmem.h \
  73. + ../../xpdf/../goo/GString.h ../../xpdf/Array.h ../../xpdf/Dict.h \
  74. + ../../xpdf/Stream.h ../../xpdf/Error.h ../../xpdf/config.h \
  75. + ../../xpdf/rc4.h
  76.  TextOutputDev.o: ../../xpdf/TextOutputDev.cc \
  77.   ../../xpdf/../goo/GString.h ../../xpdf/../goo/gmem.h \
  78.   ../../xpdf/config.h ../../xpdf/Error.h ../../xpdf/GfxState.h \
  79. diff -u -b -B -r -N -w xpdf-0.80-decrypt/build060/xpdf/Makefile xpdf-0.80-decrypt-gzip/build060/xpdf/Makefile
  80. --- xpdf-0.80-decrypt/build060/xpdf/Makefile    Fri Jun 25 19:49:06 1999
  81. +++ xpdf-0.80-decrypt-gzip/build060/xpdf/Makefile       Fri Jun 25 19:22:27 1999
  82. @@ -52,6 +52,7 @@
  83.     $(srcdir)/PDFDoc.cc \
  84.     $(srcdir)/PSOutputDev.cc \
  85.     $(srcdir)/Stream.cc \
  86. +       $(srcdir)/unlzw.cc \
  87.     $(srcdir)/TextOutputDev.cc \
  88.     $(srcdir)/XRef.cc \
  89.     $(srcdir)/Apdf.c \
  90. @@ -73,7 +74,7 @@
  91.  #------------------------------------------------------------------------
  92.  
  93.  APDF_OBJS = Array.o Catalog.o Dict.o Error.o Gfx.o GfxFont.o \
  94. -       TextOutputDev.o AOutputDev.o XRef.o AGfx.o \
  95. +       TextOutputDev.o AOutputDev.o XRef.o AGfx.o unlzw.o \
  96.     GfxState.o Lexer.o Link.o Object.o OutputDev.o mystdio.o \
  97.     Page.o Parser.o PDFDoc.o PSOutputDev.o Stream.o \
  98.     Apdfcommon.o Apdf.o ImageOutputDev.o poly.o FontOutputDev.o \
  99. @@ -200,6 +201,11 @@
  100.   ../../xpdf/mystdio.h ../../xpdf/../goo/gtypes.h \
  101.   ../../xpdf/../goo/GString.h ../../xpdf/Array.h ../../xpdf/Dict.h \
  102.   ../../xpdf/Stream.h ../../xpdf/rc4.h ../../xpdf/Stream-CCITT.h
  103. +unlzw.o: ../../xpdf/unlzw.cc ../../xpdf/Object.h ../../xpdf/mystdio.h \
  104. + ../../xpdf/../goo/gtypes.h ../../xpdf/../goo/gmem.h \
  105. + ../../xpdf/../goo/GString.h ../../xpdf/Array.h ../../xpdf/Dict.h \
  106. + ../../xpdf/Stream.h ../../xpdf/Error.h ../../xpdf/config.h \
  107. + ../../xpdf/rc4.h
  108.  TextOutputDev.o: ../../xpdf/TextOutputDev.cc \
  109.   ../../xpdf/../goo/GString.h ../../xpdf/../goo/gmem.h \
  110.   ../../xpdf/config.h ../../xpdf/Error.h ../../xpdf/GfxState.h \
  111. diff -u -b -B -r -N -w xpdf-0.80-decrypt/buildnofpu/xpdf/Makefile xpdf-0.80-decrypt-gzip/buildnofpu/xpdf/Makefile
  112. --- xpdf-0.80-decrypt/buildnofpu/xpdf/Makefile  Fri Jun 25 19:49:41 1999
  113. +++ xpdf-0.80-decrypt-gzip/buildnofpu/xpdf/Makefile     Fri Jun 25 19:26:20 1999
  114. @@ -52,6 +52,7 @@
  115.     $(srcdir)/PDFDoc.cc \
  116.     $(srcdir)/PSOutputDev.cc \
  117.     $(srcdir)/Stream.cc \
  118. +       $(srcdir)/unlzw.cc \
  119.     $(srcdir)/TextOutputDev.cc \
  120.     $(srcdir)/XRef.cc \
  121.     $(srcdir)/Apdf.c \
  122. @@ -73,7 +74,7 @@
  123.  #------------------------------------------------------------------------
  124.  
  125.  APDF_OBJS = Array.o Catalog.o Dict.o Error.o Gfx.o GfxFont.o \
  126. -       TextOutputDev.o AOutputDev.o XRef.o AGfx.o \
  127. +       TextOutputDev.o AOutputDev.o XRef.o AGfx.o unlzw.o \
  128.     GfxState.o Lexer.o Link.o Object.o OutputDev.o mystdio.o \
  129.     Page.o Parser.o PDFDoc.o PSOutputDev.o Stream.o \
  130.     Apdfcommon.o Apdf.o ImageOutputDev.o poly.o FontOutputDev.o \
  131. @@ -200,6 +201,11 @@
  132.   ../../xpdf/mystdio.h ../../xpdf/../goo/gtypes.h \
  133.   ../../xpdf/../goo/GString.h ../../xpdf/Array.h ../../xpdf/Dict.h \
  134.   ../../xpdf/Stream.h ../../xpdf/rc4.h ../../xpdf/Stream-CCITT.h
  135. +unlzw.o: ../../xpdf/unlzw.cc ../../xpdf/Object.h ../../xpdf/mystdio.h \
  136. + ../../xpdf/../goo/gtypes.h ../../xpdf/../goo/gmem.h \
  137. + ../../xpdf/../goo/GString.h ../../xpdf/Array.h ../../xpdf/Dict.h \
  138. + ../../xpdf/Stream.h ../../xpdf/Error.h ../../xpdf/config.h \
  139. + ../../xpdf/rc4.h
  140.  TextOutputDev.o: ../../xpdf/TextOutputDev.cc \
  141.   ../../xpdf/../goo/GString.h ../../xpdf/../goo/gmem.h \
  142.   ../../xpdf/config.h ../../xpdf/Error.h ../../xpdf/GfxState.h \
  143. diff -u -b -B -r -N -w xpdf-0.80-decrypt/buildppc/xpdf/Makefile xpdf-0.80-decrypt-gzip/buildppc/xpdf/Makefile
  144. --- xpdf-0.80-decrypt/buildppc/xpdf/Makefile    Fri Jun 25 19:39:49 1999
  145. +++ xpdf-0.80-decrypt-gzip/buildppc/xpdf/Makefile       Fri Jun 25 19:15:26 1999
  146. @@ -59,6 +59,7 @@
  147.     $(srcdir)/PDFDoc.cc \
  148.     $(srcdir)/PSOutputDev.cc \
  149.     $(srcdir)/Stream.cc \
  150. +       $(srcdir)/unlzw.cc \
  151.     $(srcdir)/TextOutputDev.cc \
  152.     $(srcdir)/XRef.cc \
  153.     $(srcdir)/Apdf.c \
  154. @@ -87,7 +88,7 @@
  155.  #        /sc/c/sc link define POWERUP define USE_GFX_PIPE addsym debug=full to apdf //xpdf/Apdf.c
  156.  
  157.  APDF_OBJS = stub.o Array.o Catalog.o Dict.o Error.o Gfx.o GfxFont.o \
  158. -       TextOutputDev.o AOutputDev.o XRef.o apdfppcserv.o AGfx.o \
  159. +       TextOutputDev.o AOutputDev.o XRef.o apdfppcserv.o AGfx.o unlzw.o \
  160.     GfxState.o Lexer.o Link.o Object.o OutputDev.o mystdio.o \
  161.     Page.o Parser.o PDFDoc.o PSOutputDev.o Stream.o \
  162.     apdfcommon.o ImageOutputDev.o poly.o FontOutputDev.o \
  163. @@ -218,6 +219,11 @@
  164.   ../../xpdf/mystdio.h ../../xpdf/../goo/gtypes.h \
  165.   ../../xpdf/../goo/GString.h ../../xpdf/Array.h ../../xpdf/Dict.h \
  166.   ../../xpdf/Stream.h ../../xpdf/rc4.h ../../xpdf/Stream-CCITT.h
  167. +unlzw.o: ../../xpdf/unlzw.cc ../../xpdf/Object.h ../../xpdf/mystdio.h \
  168. + ../../xpdf/../goo/gtypes.h ../../xpdf/../goo/gmem.h \
  169. + ../../xpdf/../goo/GString.h ../../xpdf/Array.h ../../xpdf/Dict.h \
  170. + ../../xpdf/Stream.h ../../xpdf/Error.h ../../xpdf/config.h \
  171. + ../../xpdf/rc4.h
  172.  TextOutputDev.o: ../../xpdf/TextOutputDev.cc \
  173.   ../../xpdf/../goo/GString.h ../../xpdf/../goo/gmem.h \
  174.   ../../xpdf/config.h ../../xpdf/Error.h ../../xpdf/GfxState.h \
  175. diff -u -b -B -r -N -w xpdf-0.80-decrypt/buildsas/xpdf/SMakefile xpdf-0.80-decrypt-gzip/buildsas/xpdf/SMakefile
  176. --- xpdf-0.80-decrypt/buildsas/xpdf/SMakefile   Fri Jun 25 19:50:21 1999
  177. +++ xpdf-0.80-decrypt-gzip/buildsas/xpdf/SMakefile      Fri Jun 25 19:33:02 1999
  178. @@ -59,6 +59,7 @@
  179.     $(srcdir)/PDFDoc.cc \
  180.     $(srcdir)/PSOutputDev.cc \
  181.     $(srcdir)/Stream.cc \
  182. +       $(srcdir)/unlzw.cc \
  183.     $(srcdir)/TextOutputDev.cc \
  184.     $(srcdir)/XRef.cc \
  185.     $(srcdir)/Apdf.c \
  186. @@ -81,7 +82,7 @@
  187.  #------------------------------------------------------------------------
  188.  
  189.  APDF_OBJS = Array.o Catalog.o Dict.o Error.o Gfx.o GfxFont.o \
  190. -       TextOutputDev.o AOutputDev.o XRef.o AGfx.o \
  191. +       TextOutputDev.o AOutputDev.o XRef.o AGfx.o unlzw.o \
  192.     GfxState.o Lexer.o Link.o Object.o OutputDev.o mystdio.o \
  193.     Page.o Parser.o PDFDoc.o PSOutputDev.o Stream.o \
  194.     Apdfcommon.o Apdf.o ImageOutputDev.o poly.o stub.o \
  195. @@ -215,6 +216,11 @@
  196.   //xpdf/mystdio.h //goo/gtypes.h \
  197.   //goo/GString.h //xpdf/Array.h //xpdf/Dict.h \
  198.   //xpdf/Stream.h //xpdf/rc4.h //xpdf/Stream-CCITT.h
  199. +unlzw.o: //xpdf/unlzw.cc //xpdf/Object.h //xpdf/mystdio.h \
  200. + //goo/gtypes.h //goo/gmem.h \
  201. + //goo/GString.h //xpdf/Array.h //xpdf/Dict.h \
  202. + //xpdf/Stream.h //xpdf/Error.h //xpdf/config.h \
  203. + //xpdf/rc4.h
  204.  TextOutputDev.o: //xpdf/TextOutputDev.cc \
  205.   //goo/GString.h //goo/gmem.h \
  206.   //xpdf/config.h //xpdf/Error.h //xpdf/GfxState.h \
  207. diff -u -b -B -r -N -w xpdf-0.80-decrypt/xpdf/Stream.cc xpdf-0.80-decrypt-gzip/xpdf/Stream.cc
  208. --- xpdf-0.80-decrypt/xpdf/Stream.cc    Fri Jun 25 18:43:44 1999
  209. +++ xpdf-0.80-decrypt-gzip/xpdf/Stream.cc       Fri Jun 25 19:07:41 1999
  210. @@ -682,6 +682,113 @@
  211.  // LZWStream
  212.  //------------------------------------------------------------------------
  213.  
  214. +static const int pipebufsize=100000;
  215. +
  216. +LZWStream::Pipe::Pipe() : wsize(pipebufsize),rsize(0) {
  217. +    unsigned char* p=new unsigned char [sizeof(chunk)+pipebufsize];
  218. +    chunks=wchunk=(chunk*)p;
  219. +    wp=rp=p+sizeof(chunk);
  220. +    chunks->next=NULL;
  221. +}
  222. +
  223. +LZWStream::Pipe::~Pipe() {
  224. +    chunk* p=chunks;
  225. +    while(p) {
  226. +       chunk* q=p->next;
  227. +       delete [] (unsigned char*)p;
  228. +       p=q;
  229. +    }
  230. +}
  231. +
  232. +void LZWStream::Pipe::enlarge() {
  233. +    if(chunks==wchunk)
  234. +       rsize=wp-rp;
  235. +    unsigned char* q=new unsigned char [sizeof(chunk)+pipebufsize];
  236. +    wchunk->next=(chunk*)q;
  237. +    wchunk=wchunk->next;
  238. +    wp=q+sizeof(chunk);
  239. +    wchunk->next=NULL;
  240. +    wsize=pipebufsize;
  241. +}
  242. +
  243. +void LZWStream::Pipe::write(const void* p,size_t sz) {
  244. +    while(sz>=wsize) {
  245. +       if(wsize) memcpy(wp,p,wsize);
  246. +       sz-=wsize;
  247. +       wp+=wsize;
  248. +       p=(const void*)((const char*)p+wsize);
  249. +       enlarge();
  250. +    }
  251. +    if(sz) {
  252. +       memcpy(wp,p,sz);
  253. +       wsize-=sz;
  254. +       wp+=sz;
  255. +    }
  256. +}
  257. +
  258. +bool LZWStream::Pipe::next_chunk() {
  259. +    if(chunks==wchunk) {
  260. +       if(rp<wp) {
  261. +          rsize=wp-rp;
  262. +          return true;
  263. +       } else
  264. +          return false;
  265. +    }
  266. +    if(chunks) {
  267. +       chunk* q=chunks->next;
  268. +       delete [] (unsigned char*)chunks;
  269. +       chunks=q;
  270. +       if(q) {
  271. +          rp=(unsigned char*)(q+1);
  272. +          rsize=pipebufsize;
  273. +          if(q==wchunk)
  274. +              rsize-=wsize;
  275. +          return rsize>0;
  276. +       } else {
  277. +          rsize=0;
  278. +          rp=NULL;
  279. +          return false;
  280. +       }
  281. +    } else
  282. +       return false;
  283. +}
  284. +
  285. +int LZWStream::Pipe::read(void* p,size_t sz) {
  286. +    int sz2=0;
  287. +    while(sz>rsize) {
  288. +       if(rsize==0 && !next_chunk()) return sz2;
  289. +       if(sz<=rsize) break;
  290. +       if(rsize) memcpy(p,rp,rsize);
  291. +       sz-=rsize;
  292. +       sz2+=rsize;
  293. +       rp+=rsize;
  294. +       rsize=0;
  295. +       p=(void*)((char*)p+rsize);
  296. +    }
  297. +    if(sz) {
  298. +       memcpy(p,rp,sz);
  299. +       rsize-=sz;
  300. +       sz2+=sz;
  301. +       rp+=sz;
  302. +    }
  303. +    return sz2;
  304. +}
  305. +
  306. +void LZWStream::Pipe::reset() {
  307. +    chunk* p=chunks->next;
  308. +    while(p) {
  309. +       chunk* q=p->next;
  310. +       delete [] (unsigned char*)p;
  311. +       p=q;
  312. +    }
  313. +    chunks->next=NULL;
  314. +    wchunk=chunks;
  315. +    rp=wp=(unsigned char*)(chunks+1);
  316. +    rsize=0;
  317. +    wsize=pipebufsize;
  318. +}
  319. +
  320. +
  321.  LZWStream::LZWStream(Stream *str1, int predictor1, int columns1, int colors1,
  322.              int bits1, int early1) {
  323.    str = str1;
  324. @@ -692,82 +799,46 @@
  325.      nBits = bits1;
  326.    }
  327.    early = early1;
  328. -  zPipe = NULL;
  329.    bufPtr = bufEnd = buf;
  330.  }
  331.  
  332.  LZWStream::~LZWStream() {
  333. -  if (zPipe) {
  334. -#ifdef HAVE_POPEN
  335. -    pclose(zPipe);
  336. -#else
  337. -    myfclose(zPipe);
  338. -#endif
  339. -    zPipe = NULL;
  340. -    unlink(zName);
  341. -  }
  342.    delete str;
  343.  }
  344.  
  345.  int LZWStream::getChar() {
  346. -  return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff);
  347. +  return pipe.get();
  348.  }
  349.  
  350.  int LZWStream::lookChar() {
  351. -  return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff);
  352. +  return pipe.lookc();
  353.  }
  354.  
  355. -void LZWStream::reset() {
  356. -  FILE *f;
  357. +inline int LZWStream::getCode() {
  358. +  int c;
  359. +  int code;
  360.  
  361. -  str->reset();
  362. -  bufPtr = bufEnd = buf;
  363. -  if (zPipe) {
  364. -#ifdef HAVE_POPEN
  365. -    pclose(zPipe);
  366. -#else
  367. -    myfclose(zPipe);
  368. -#endif
  369. -    zPipe = NULL;
  370. -    unlink(zName);
  371. -  }
  372. -  strcpy(zCmd, uncompressCmd);
  373. -  strcat(zCmd, " ");
  374. -  zName = zCmd + strlen(zCmd);
  375. -  tmpnam(zName);
  376. -  strcat(zName, ".Z");
  377. -  if (!(f = fopen(zName, "wb"))) {
  378. -    error(getPos(), "Couldn't open temporary file '%s'", zName);
  379. -    return;
  380. -  }
  381. -  dumpFile(f);
  382. -  fclose(f);
  383. -#ifdef HAVE_POPEN
  384. -  if (!(zPipe = popen(zCmd, "r"))) {
  385. -    error(getPos(), "Couldn't popen '%s'", zCmd);
  386. -    unlink(zName);
  387. -    return;
  388. -  }
  389. -#else
  390. -#ifdef VMS
  391. -  if (!system(zCmd)) {
  392. -#else
  393. -  if (system(zCmd)) {
  394. -#endif
  395. -    error(getPos(), "Couldn't execute '%s'", zCmd);
  396. -    unlink(zName);
  397. -    return;
  398. -  }
  399. -  zName[strlen(zName) - 2] = '\0';
  400. -  if (!(zPipe = myfopen(zName, "rb"))) {
  401. -    error(getPos(), "Couldn't open uncompress file '%s'", zName);
  402. -    unlink(zName);
  403. -    return;
  404. +  while (inputBits < inCodeBits) {
  405. +    if ((c = str->getChar()) == EOF)
  406. +      return EOF;
  407. +    inputBuf = (inputBuf << 8) | (c & 0xff);
  408. +    inputBits += 8;
  409.    }
  410. -#endif
  411. +  code = (inputBuf >> (inputBits - inCodeBits)) & ((1 << inCodeBits) - 1);
  412. +  inputBits -= inCodeBits;
  413. +  return code;
  414.  }
  415.  
  416. -void LZWStream::dumpFile(FILE *f) {
  417. +void LZWStream::reset() {
  418. +
  419. +  str->reset();
  420. +  pipe.reset();
  421. +
  422. +  Pipe tmppipe;
  423. +
  424. +  // fill tmppipe with the contents of the stream converted to
  425. +  // 'compress' format (without header).
  426. +
  427.    int outCodeBits;              // size of output code
  428.    int outBits;                  // max output code
  429.    int outBuf[8];                // output buffer
  430. @@ -779,13 +850,6 @@
  431.    GBool first;                  // indicates first code word after clear
  432.    int i, j;
  433.  
  434. -  // magic number
  435. -  fputc(0x1f, f);
  436. -  fputc(0x9d, f);
  437. -
  438. -  // max code length, block mode flag
  439. -  fputc(0x8c, f);
  440. -
  441.    // init input side
  442.    inCodeBits = 9;
  443.    inputBuf = 0;
  444. @@ -864,7 +928,7 @@
  445.     outData = outData | (outBuf[j++] << outBits);
  446.     outBits += outCodeBits;
  447.        }
  448. -      fputc(outData & 0xff, f);
  449. +      tmppipe.put(char(outData));
  450.        outData >>= 8;
  451.        outBits -= 8;
  452.      }
  453. @@ -886,40 +950,10 @@
  454.        clear = gFalse;
  455.      }
  456.    } while (!eof);
  457. -}
  458. -
  459. -int LZWStream::getCode() {
  460. -  int c;
  461. -  int code;
  462. -
  463. -  while (inputBits < inCodeBits) {
  464. -    if ((c = str->getChar()) == EOF)
  465. -      return EOF;
  466. -    inputBuf = (inputBuf << 8) | (c & 0xff);
  467. -    inputBits += 8;
  468. -  }
  469. -  code = (inputBuf >> (inputBits - inCodeBits)) & ((1 << inCodeBits) - 1);
  470. -  inputBits -= inCodeBits;
  471. -  return code;
  472. -}
  473.  
  474. -GBool LZWStream::fillBuf() {
  475. -  int n;
  476. +  // uncompress tmppipe to pipe
  477.  
  478. -  if (!zPipe)
  479. -    return gFalse;
  480. -  if ((n = myfread(buf, 1, 256, zPipe)) < 256) {
  481. -#ifdef HAVE_POPEN
  482. -    pclose(zPipe);
  483. -#else
  484. -    myfclose(zPipe);
  485. -#endif
  486. -    zPipe = NULL;
  487. -    unlink(zName);
  488. -  }
  489. -  bufPtr = buf;
  490. -  bufEnd = buf + n;
  491. -  return n > 0;
  492. +  unlzw(tmppipe, pipe);
  493.  }
  494.  
  495.  GString *LZWStream::getPSFilter(char *indent) {
  496. diff -u -b -B -r -N -w xpdf-0.80-decrypt/xpdf/Stream.h xpdf-0.80-decrypt-gzip/xpdf/Stream.h
  497. --- xpdf-0.80-decrypt/xpdf/Stream.h     Fri Jun 25 18:46:28 1999
  498. +++ xpdf-0.80-decrypt-gzip/xpdf/Stream.h        Fri Jun 25 19:08:58 1999
  499. @@ -266,6 +266,32 @@
  500.  //------------------------------------------------------------------------
  501.  
  502.  class LZWStream: public Stream {
  503. +  class Pipe {
  504. +    struct chunk {
  505. +      chunk* next;
  506. +    };
  507. +  public:
  508. +    Pipe();
  509. +    ~Pipe();
  510. +    void write(const void*,size_t);
  511. +    void put(char c) { if(wsize==0) enlarge(); *wp++=c; --wsize; }
  512. +    int read(void*,size_t);
  513. +    int get() { return rsize==0 && !next_chunk()?EOF:(--rsize,*rp++); }
  514. +    int lookc() { return rsize==0 && !next_chunk()?EOF:*rp; }
  515. +    void reset();
  516. +  private:
  517. +    Pipe(const Pipe&);
  518. +    Pipe& operator = (const Pipe&);
  519. +    void enlarge();
  520. +    bool next_chunk();
  521. +    chunk* chunks;
  522. +    chunk* wchunk;
  523. +    unsigned char* wp;
  524. +    int wsize;
  525. +    unsigned char* rp;
  526. +    int rsize;
  527. +  };
  528. +
  529.  public:
  530.  
  531.    LZWStream(Stream *str1, int predictor1, int columns1, int colors1,
  532. @@ -286,9 +312,7 @@
  533.  
  534.    Stream *str;                  // stream
  535.    int early;                    // early parameter
  536. -  char zCmd[256];               // uncompress command
  537. -  myFILE *zPipe;                // uncompress pipe
  538. -  char *zName;                  // .Z file name (in zCmd)
  539. +  Pipe pipe;
  540.    int inputBuf;                 // input buffer
  541.    int inputBits;                // number of bits in input buffer
  542.    int inCodeBits;               // size of input code
  543. @@ -296,9 +320,8 @@
  544.    char *bufPtr;                 // next char to read
  545.    char *bufEnd;                 // end of buffer
  546.  
  547. -  void dumpFile(FILE *f);
  548.    int getCode();
  549. -  GBool fillBuf();
  550. +  void unlzw(Pipe&,Pipe&);
  551.  };
  552.  
  553.  //------------------------------------------------------------------------
  554. diff -u -b -B -r -N -w xpdf-0.80-decrypt/xpdf/unlzw.cc xpdf-0.80-decrypt-gzip/xpdf/unlzw.cc
  555. --- xpdf-0.80-decrypt/xpdf/unlzw.cc     Thu May 20 20:56:27 1999
  556. +++ xpdf-0.80-decrypt-gzip/xpdf/unlzw.cc        Fri Jun 25 18:58:10 1999
  557. @@ -7,23 +7,18 @@
  558.   * to accommodate in-memory decompression.
  559.   */
  560.  
  561. -#ifdef RCSID
  562. -static char rcsid[] = "$Id: unlzw.c,v 0.15 1993/06/10 13:28:35 jloup Exp $";
  563. -#endif
  564. -
  565. -#include <sys/types.h>
  566. +/*
  567. + * Modified for integration into Xpdf by E. Lesueur.
  568. + */
  569.  
  570. -#include "tailor.h"
  571. +#include <stdio.h>
  572. +#include <stdlib.h>
  573. +#include "Object.h"
  574. +#include "Stream.h"
  575. +#include "Error.h"
  576.  
  577. -#ifdef HAVE_UNISTD_H
  578. -#  include <unistd.h>
  579. -#endif
  580. -#ifndef NO_FCNTL_H
  581. -#  include <fcntl.h>
  582. -#endif
  583. -
  584. -#include "gzip.h"
  585. -#include "lzw.h"
  586. +#define memzero(s, n)     memset((s), 0, (n))
  587. +#define Tracev(x)
  588.  
  589.  typedef        unsigned char   char_type;
  590.  typedef          long   code_int;
  591. @@ -31,6 +26,48 @@
  592.  typedef unsigned short count_short;
  593.  typedef unsigned long  cmp_code_int;
  594.  
  595. +static const int INIT_BITS = 9;
  596. +static const code_int CLEAR = 256;
  597. +static const code_int FIRST = 257;
  598. +static const int INBUFSIZ = 0x8000;
  599. +static const int INBUF_EXTRA = 64;
  600. +static const int OUTBUFSIZ = 16384;
  601. +static const int OUTBUF_EXTRA = 2048;
  602. +static const int DIST_BUFSIZE = 0x8000;
  603. +static const int test = 0;
  604. +static const int maxbits = 0x0c;
  605. +static const int block_mode = 1;
  606. +
  607. +static unsigned short* tab_prefix;
  608. +static unsigned char* tab_suffix;
  609. +static unsigned char* inbuf;
  610. +static unsigned char* outbuf;
  611. +static unsigned short* d_buf;
  612. +
  613. +class Init {
  614. +  public:
  615. +    Init() {
  616. +       tab_prefix = new unsigned short [1<<16];
  617. +       tab_suffix = new unsigned char [1<<16];
  618. +       inbuf = new unsigned char [INBUFSIZ+INBUF_EXTRA];
  619. +       outbuf = new unsigned char [OUTBUFSIZ+OUTBUF_EXTRA];
  620. +       d_buf = new unsigned short [DIST_BUFSIZE];
  621. +    }
  622. +
  623. +    ~Init() {
  624. +       delete [] tab_suffix;
  625. +       delete [] tab_prefix;
  626. +       delete [] inbuf;
  627. +       delete [] outbuf;
  628. +       delete [] d_buf;
  629. +    }
  630. +
  631. +    static Init init;
  632. +};
  633. +
  634. +Init Init::init;
  635. +
  636. +
  637.  #define MAXCODE(n)     (1L << (n))
  638.      
  639.  #ifndef        REGISTERS
  640. @@ -178,7 +215,6 @@
  641.  #define de_stack        ((char_type *)(&d_buf[DIST_BUFSIZE-1]))
  642.  #define tab_suffixof(i) tab_suffix[i]
  643.  
  644. -int block_mode = BLOCK_MODE; /* block compress mode -C compatible with 2.0 */
  645.  
  646.  /* ============================================================================
  647.   * Decompress in to out.  This routine adapts to the codes in the
  648. @@ -189,8 +225,7 @@
  649.   *   The magic header has already been checked and skipped.
  650.   *   bytes_in and bytes_out have been initialized.
  651.   */
  652. -int unlzw(in, out) 
  653. -    int in, out;    /* input and output file descriptors */
  654. +void LZWStream::unlzw(Pipe& in,Pipe& out)
  655.  {
  656.      REG2   char_type  *stackp;
  657.      REG3   code_int   code;
  658. @@ -200,7 +235,7 @@
  659.      REG7   long       inbits;
  660.      REG8   long       posbits;
  661.      REG9   int        outpos;
  662. -/*  REG10  int        insize; (global) */
  663. +    REG10  int        insize;
  664.      REG11  unsigned   bitmask;
  665.      REG12  code_int   free_ent;
  666.      REG13  code_int   maxcode;
  667. @@ -212,29 +247,19 @@
  668.      tab_prefix[0] = tab_prefix0;
  669.      tab_prefix[1] = tab_prefix1;
  670.  #endif
  671. -    maxbits = get_byte();
  672. -    block_mode = maxbits & BLOCK_MODE;
  673. -    if ((maxbits & LZW_RESERVED) != 0) {
  674. -       WARN((stderr, "\n%s: %s: warning, unknown flags 0x%x\n",
  675. -             progname, ifname, maxbits & LZW_RESERVED));
  676. -    }
  677. -    maxbits &= BIT_MASK;
  678.      maxmaxcode = MAXCODE(maxbits);
  679.      
  680. -    if (maxbits > BITS) {
  681. -       fprintf(stderr,
  682. -               "\n%s: %s: compressed with %d bits, can only handle %d bits\n",
  683. -               progname, ifname, maxbits, BITS);
  684. -       exit_code = ERROR;
  685. -       return ERROR;
  686. +    if ((rsize = insize = in.read(inbuf, INBUFSIZ)) == EOF) {
  687. +       error(getPos(), "unexpected end od file.");
  688. +       return;
  689.      }
  690. -    rsize = insize;
  691. +
  692.      maxcode = MAXCODE(n_bits = INIT_BITS)-1;
  693.      bitmask = (1<<n_bits)-1;
  694.      oldcode = -1;
  695.      finchar = 0;
  696.      outpos = 0;
  697. -    posbits = inptr<<3;
  698. +    posbits = 0;
  699.  
  700.      free_ent = ((block_mode) ? FIRST : 256);
  701.      
  702. @@ -258,11 +283,11 @@
  703.     posbits = 0;
  704.     
  705.     if (insize < INBUF_EXTRA) {
  706. -           if ((rsize = read(in, (char*)inbuf+insize, INBUFSIZ)) == EOF) {
  707. -               read_error();
  708. +           if ((rsize = in.read((char*)inbuf+insize, INBUFSIZ)) == EOF) {
  709. +               error(getPos(), "unexpected end of file.");
  710. +               return;
  711.         }
  712.         insize += rsize;
  713. -           bytes_in += (ulg)rsize;
  714.     }
  715.     inbits = ((rsize != 0) ? ((long)insize - insize%n_bits)<<3 : 
  716.           ((long)insize<<3)-(n_bits-1));
  717. @@ -284,7 +309,10 @@
  718.         Tracev((stderr, "%d ", code));
  719.  
  720.         if (oldcode == -1) {
  721. -               if (code >= 256) error("corrupt input.");
  722. +               if (code >= 256) {
  723. +                   error(getPos(),"corrupt input.");
  724. +                   return;
  725. +               }
  726.         outbuf[outpos++] = (char_type)(finchar = (int)(oldcode=code));
  727.         continue;
  728.         }
  729. @@ -315,11 +343,9 @@
  730.                 posbits, p[-1],p[0],p[1],p[2],p[3]);
  731.  #endif
  732.             if (!test && outpos > 0) {
  733. -                       write_buf(out, (char*)outbuf, outpos);
  734. -                       bytes_out += (ulg)outpos;
  735. +                       out.write(outbuf, outpos);
  736.             }
  737. -                   error(to_stdout ? "corrupt input." :
  738. -                         "corrupt input. Use zcat to recover some data.");
  739. +                   error(getPos(),"corrupt input." );
  740.         }
  741.         *--stackp = (char_type)finchar;
  742.         code = oldcode;
  743. @@ -346,8 +372,7 @@
  744.             }
  745.             if (outpos >= OUTBUFSIZ) {
  746.                 if (!test) {
  747. -                               write_buf(out, (char*)outbuf, outpos);
  748. -                               bytes_out += (ulg)outpos;
  749. +                               out.write(outbuf, outpos);
  750.                 }
  751.                 outpos = 0;
  752.             }
  753. @@ -370,8 +395,7 @@
  754.      } while (rsize != 0);
  755.      
  756.      if (!test && outpos > 0) {
  757. -       write_buf(out, (char*)outbuf, outpos);
  758. -       bytes_out += (ulg)outpos;
  759. +       out.write(outbuf, outpos);
  760.      }
  761. -    return OK;
  762.  }
  763. +
  764.