Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/Stream.cc') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/Stream.cc | 215 |
1 files changed, 187 insertions, 28 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/Stream.cc b/noncore/unsupported/qpdf/xpdf/Stream.cc index 18490d4..c558478 100644 --- a/noncore/unsupported/qpdf/xpdf/Stream.cc +++ b/noncore/unsupported/qpdf/xpdf/Stream.cc | |||
@@ -2,7 +2,7 @@ | |||
2 | // | 2 | // |
3 | // Stream.cc | 3 | // Stream.cc |
4 | // | 4 | // |
5 | // Copyright 1996 Derek B. Noonburg | 5 | // Copyright 1996-2002 Glyph & Cog, LLC |
6 | // | 6 | // |
7 | //======================================================================== | 7 | //======================================================================== |
8 | 8 | ||
@@ -303,7 +303,7 @@ void FilterStream::close() { | |||
303 | str->close(); | 303 | str->close(); |
304 | } | 304 | } |
305 | 305 | ||
306 | void FilterStream::setPos(int pos) { | 306 | void FilterStream::setPos(Guint pos, int dir) { |
307 | error(-1, "Internal: called setPos() on FilterStream"); | 307 | error(-1, "Internal: called setPos() on FilterStream"); |
308 | } | 308 | } |
309 | 309 | ||
@@ -554,27 +554,37 @@ GBool StreamPredictor::getNextLine() { | |||
554 | // FileStream | 554 | // FileStream |
555 | //------------------------------------------------------------------------ | 555 | //------------------------------------------------------------------------ |
556 | 556 | ||
557 | FileStream::FileStream(FILE *fA, int startA, int lengthA, Object *dictA): | 557 | FileStream::FileStream(FILE *fA, Guint startA, GBool limitedA, |
558 | Guint lengthA, Object *dictA): | ||
558 | BaseStream(dictA) { | 559 | BaseStream(dictA) { |
559 | f = fA; | 560 | f = fA; |
560 | start = startA; | 561 | start = startA; |
562 | limited = limitedA; | ||
561 | length = lengthA; | 563 | length = lengthA; |
562 | bufPtr = bufEnd = buf; | 564 | bufPtr = bufEnd = buf; |
563 | bufPos = start; | 565 | bufPos = start; |
564 | savePos = -1; | 566 | savePos = 0; |
567 | saved = gFalse; | ||
565 | } | 568 | } |
566 | 569 | ||
567 | FileStream::~FileStream() { | 570 | FileStream::~FileStream() { |
568 | close(); | 571 | close(); |
569 | } | 572 | } |
570 | 573 | ||
571 | Stream *FileStream::makeSubStream(int startA, int lengthA, Object *dictA) { | 574 | Stream *FileStream::makeSubStream(Guint startA, GBool limitedA, |
572 | return new FileStream(f, startA, lengthA, dictA); | 575 | Guint lengthA, Object *dictA) { |
576 | return new FileStream(f, startA, limitedA, lengthA, dictA); | ||
573 | } | 577 | } |
574 | 578 | ||
575 | void FileStream::reset() { | 579 | void FileStream::reset() { |
576 | savePos = (int)ftell(f); | 580 | #if HAVE_FSEEK64 |
581 | savePos = (Guint)ftell64(f); | ||
582 | fseek64(f, start, SEEK_SET); | ||
583 | #else | ||
584 | savePos = (Guint)ftell(f); | ||
577 | fseek(f, start, SEEK_SET); | 585 | fseek(f, start, SEEK_SET); |
586 | #endif | ||
587 | saved = gTrue; | ||
578 | bufPtr = bufEnd = buf; | 588 | bufPtr = bufEnd = buf; |
579 | bufPos = start; | 589 | bufPos = start; |
580 | #ifndef NO_DECRYPTION | 590 | #ifndef NO_DECRYPTION |
@@ -584,9 +594,13 @@ void FileStream::reset() { | |||
584 | } | 594 | } |
585 | 595 | ||
586 | void FileStream::close() { | 596 | void FileStream::close() { |
587 | if (savePos >= 0) { | 597 | if (saved) { |
598 | #if HAVE_FSEEK64 | ||
599 | fseek64(f, savePos, SEEK_SET); | ||
600 | #else | ||
588 | fseek(f, savePos, SEEK_SET); | 601 | fseek(f, savePos, SEEK_SET); |
589 | savePos = -1; | 602 | #endif |
603 | saved = gFalse; | ||
590 | } | 604 | } |
591 | } | 605 | } |
592 | 606 | ||
@@ -598,10 +612,10 @@ GBool FileStream::fillBuf() { | |||
598 | 612 | ||
599 | bufPos += bufEnd - buf; | 613 | bufPos += bufEnd - buf; |
600 | bufPtr = bufEnd = buf; | 614 | bufPtr = bufEnd = buf; |
601 | if (length >= 0 && bufPos >= start + length) { | 615 | if (limited && bufPos >= start + length) { |
602 | return gFalse; | 616 | return gFalse; |
603 | } | 617 | } |
604 | if (length >= 0 && bufPos + fileStreamBufSize > start + length) { | 618 | if (limited && bufPos + fileStreamBufSize > start + length) { |
605 | n = start + length - bufPos; | 619 | n = start + length - bufPos; |
606 | } else { | 620 | } else { |
607 | n = fileStreamBufSize; | 621 | n = fileStreamBufSize; |
@@ -621,23 +635,37 @@ GBool FileStream::fillBuf() { | |||
621 | return gTrue; | 635 | return gTrue; |
622 | } | 636 | } |
623 | 637 | ||
624 | void FileStream::setPos(int pos) { | 638 | void FileStream::setPos(Guint pos, int dir) { |
625 | long size; | 639 | Guint size; |
626 | 640 | ||
627 | if (pos >= 0) { | 641 | if (dir >= 0) { |
642 | #if HAVE_FSEEK64 | ||
643 | fseek64(f, pos, SEEK_SET); | ||
644 | #else | ||
628 | fseek(f, pos, SEEK_SET); | 645 | fseek(f, pos, SEEK_SET); |
646 | #endif | ||
629 | bufPos = pos; | 647 | bufPos = pos; |
630 | } else { | 648 | } else { |
649 | #if HAVE_FSEEK64 | ||
650 | fseek64(f, 0, SEEK_END); | ||
651 | size = (Guint)ftell64(f); | ||
652 | #else | ||
631 | fseek(f, 0, SEEK_END); | 653 | fseek(f, 0, SEEK_END); |
632 | size = ftell(f); | 654 | size = (Guint)ftell(f); |
633 | if (pos < -size) | 655 | #endif |
634 | pos = (int)(-size); | 656 | if (pos > size) |
657 | pos = (Guint)size; | ||
635 | #ifdef __CYGWIN32__ | 658 | #ifdef __CYGWIN32__ |
636 | //~ work around a bug in cygwin's implementation of fseek | 659 | //~ work around a bug in cygwin's implementation of fseek |
637 | rewind(f); | 660 | rewind(f); |
638 | #endif | 661 | #endif |
639 | fseek(f, pos, SEEK_END); | 662 | #if HAVE_FSEEK64 |
640 | bufPos = (int)ftell(f); | 663 | fseek64(f, -(int)pos, SEEK_END); |
664 | bufPos = (Guint)ftell64(f); | ||
665 | #else | ||
666 | fseek(f, -(int)pos, SEEK_END); | ||
667 | bufPos = (Guint)ftell(f); | ||
668 | #endif | ||
641 | } | 669 | } |
642 | bufPtr = bufEnd = buf; | 670 | bufPtr = bufEnd = buf; |
643 | } | 671 | } |
@@ -649,6 +677,90 @@ void FileStream::moveStart(int delta) { | |||
649 | } | 677 | } |
650 | 678 | ||
651 | //------------------------------------------------------------------------ | 679 | //------------------------------------------------------------------------ |
680 | // MemStream | ||
681 | //------------------------------------------------------------------------ | ||
682 | |||
683 | MemStream::MemStream(char *bufA, Guint lengthA, Object *dictA): | ||
684 | BaseStream(dictA) { | ||
685 | buf = bufA; | ||
686 | needFree = gFalse; | ||
687 | length = lengthA; | ||
688 | bufEnd = buf + length; | ||
689 | bufPtr = buf; | ||
690 | } | ||
691 | |||
692 | MemStream::~MemStream() { | ||
693 | if (needFree) { | ||
694 | gfree(buf); | ||
695 | } | ||
696 | } | ||
697 | |||
698 | Stream *MemStream::makeSubStream(Guint start, GBool limited, | ||
699 | Guint lengthA, Object *dictA) { | ||
700 | Guint newLength; | ||
701 | |||
702 | if (!limited || start + lengthA > length) { | ||
703 | newLength = length - start; | ||
704 | } else { | ||
705 | newLength = lengthA; | ||
706 | } | ||
707 | return new MemStream(buf + start, newLength, dictA); | ||
708 | } | ||
709 | |||
710 | void MemStream::reset() { | ||
711 | bufPtr = buf; | ||
712 | #ifndef NO_DECRYPTION | ||
713 | if (decrypt) { | ||
714 | decrypt->reset(); | ||
715 | } | ||
716 | #endif | ||
717 | } | ||
718 | |||
719 | void MemStream::close() { | ||
720 | } | ||
721 | |||
722 | void MemStream::setPos(Guint pos, int dir) { | ||
723 | if (dir >= 0) { | ||
724 | if (pos > length) { | ||
725 | bufPtr = bufEnd; | ||
726 | } else { | ||
727 | bufPtr = buf + pos; | ||
728 | } | ||
729 | } else { | ||
730 | if (pos > length) { | ||
731 | bufPtr = buf; | ||
732 | } else { | ||
733 | bufPtr = bufEnd - pos; | ||
734 | } | ||
735 | } | ||
736 | } | ||
737 | |||
738 | void MemStream::moveStart(int delta) { | ||
739 | buf += delta; | ||
740 | bufPtr = buf; | ||
741 | } | ||
742 | |||
743 | #ifndef NO_DECRYPTION | ||
744 | void MemStream::doDecryption(Guchar *fileKey, int keyLength, | ||
745 | int objNum, int objGen) { | ||
746 | char *newBuf; | ||
747 | char *p, *q; | ||
748 | |||
749 | this->BaseStream::doDecryption(fileKey, keyLength, objNum, objGen); | ||
750 | if (decrypt) { | ||
751 | newBuf = (char *)gmalloc(bufEnd - buf); | ||
752 | for (p = buf, q = newBuf; p < bufEnd; ++p, ++q) { | ||
753 | *q = (char)decrypt->decryptByte((Guchar)*p); | ||
754 | } | ||
755 | bufEnd = newBuf + (bufEnd - buf); | ||
756 | bufPtr = newBuf + (bufPtr - buf); | ||
757 | buf = newBuf; | ||
758 | needFree = gTrue; | ||
759 | } | ||
760 | } | ||
761 | #endif | ||
762 | |||
763 | //------------------------------------------------------------------------ | ||
652 | // EmbedStream | 764 | // EmbedStream |
653 | //------------------------------------------------------------------------ | 765 | //------------------------------------------------------------------------ |
654 | 766 | ||
@@ -660,21 +772,22 @@ EmbedStream::EmbedStream(Stream *strA, Object *dictA): | |||
660 | EmbedStream::~EmbedStream() { | 772 | EmbedStream::~EmbedStream() { |
661 | } | 773 | } |
662 | 774 | ||
663 | Stream *EmbedStream::makeSubStream(int start, int length, Object *dictA) { | 775 | Stream *EmbedStream::makeSubStream(Guint start, GBool limited, |
776 | Guint length, Object *dictA) { | ||
664 | error(-1, "Internal: called makeSubStream() on EmbedStream"); | 777 | error(-1, "Internal: called makeSubStream() on EmbedStream"); |
665 | return NULL; | 778 | return NULL; |
666 | } | 779 | } |
667 | 780 | ||
668 | void EmbedStream::setPos(int pos) { | 781 | void EmbedStream::setPos(Guint pos, int dir) { |
669 | error(-1, "Internal: called setPos() on EmbedStream"); | 782 | error(-1, "Internal: called setPos() on EmbedStream"); |
670 | } | 783 | } |
671 | 784 | ||
672 | int EmbedStream::getStart() { | 785 | Guint EmbedStream::getStart() { |
673 | error(-1, "Internal: called getStart() on EmbedStream"); | 786 | error(-1, "Internal: called getStart() on EmbedStream"); |
674 | return 0; | 787 | return 0; |
675 | } | 788 | } |
676 | 789 | ||
677 | void EmbedStream::moveStart(int start) { | 790 | void EmbedStream::moveStart(int delta) { |
678 | error(-1, "Internal: called moveStart() on EmbedStream"); | 791 | error(-1, "Internal: called moveStart() on EmbedStream"); |
679 | } | 792 | } |
680 | 793 | ||
@@ -959,11 +1072,7 @@ void LZWStream::reset() { | |||
959 | return; | 1072 | return; |
960 | } | 1073 | } |
961 | #else // HAVE_POPEN | 1074 | #else // HAVE_POPEN |
962 | #ifdef VMS | 1075 | if (!executeCommand(zCmd->getCString())) { |
963 | if (!system(zCmd->getCString())) { | ||
964 | #else | ||
965 | if (system(zCmd->getCString())) { | ||
966 | #endif | ||
967 | error(getPos(), "Couldn't execute '%s'", zCmd->getCString()); | 1076 | error(getPos(), "Couldn't execute '%s'", zCmd->getCString()); |
968 | unlink(zName->getCString()); | 1077 | unlink(zName->getCString()); |
969 | delete zName; | 1078 | delete zName; |
@@ -3287,6 +3396,56 @@ int FixedLengthEncoder::lookChar() { | |||
3287 | } | 3396 | } |
3288 | 3397 | ||
3289 | //------------------------------------------------------------------------ | 3398 | //------------------------------------------------------------------------ |
3399 | // ASCIIHexEncoder | ||
3400 | //------------------------------------------------------------------------ | ||
3401 | |||
3402 | ASCIIHexEncoder::ASCIIHexEncoder(Stream *strA): | ||
3403 | FilterStream(strA) { | ||
3404 | bufPtr = bufEnd = buf; | ||
3405 | lineLen = 0; | ||
3406 | eof = gFalse; | ||
3407 | } | ||
3408 | |||
3409 | ASCIIHexEncoder::~ASCIIHexEncoder() { | ||
3410 | if (str->isEncoder()) { | ||
3411 | delete str; | ||
3412 | } | ||
3413 | } | ||
3414 | |||
3415 | void ASCIIHexEncoder::reset() { | ||
3416 | str->reset(); | ||
3417 | bufPtr = bufEnd = buf; | ||
3418 | lineLen = 0; | ||
3419 | eof = gFalse; | ||
3420 | } | ||
3421 | |||
3422 | void ASCIIHexEncoder::close() { | ||
3423 | } | ||
3424 | |||
3425 | GBool ASCIIHexEncoder::fillBuf() { | ||
3426 | static char *hex = "0123456789abcdef"; | ||
3427 | int c; | ||
3428 | |||
3429 | if (eof) { | ||
3430 | return gFalse; | ||
3431 | } | ||
3432 | bufPtr = bufEnd = buf; | ||
3433 | if ((c = str->getChar()) == EOF) { | ||
3434 | *bufEnd++ = '>'; | ||
3435 | eof = gTrue; | ||
3436 | } else { | ||
3437 | if (lineLen >= 64) { | ||
3438 | *bufEnd++ = '\n'; | ||
3439 | lineLen = 0; | ||
3440 | } | ||
3441 | *bufEnd++ = hex[(c >> 4) & 0x0f]; | ||
3442 | *bufEnd++ = hex[c & 0x0f]; | ||
3443 | lineLen += 2; | ||
3444 | } | ||
3445 | return gTrue; | ||
3446 | } | ||
3447 | |||
3448 | //------------------------------------------------------------------------ | ||
3290 | // ASCII85Encoder | 3449 | // ASCII85Encoder |
3291 | //------------------------------------------------------------------------ | 3450 | //------------------------------------------------------------------------ |
3292 | 3451 | ||