shithub: pdffs

Download patch

ref: 52ffbd2fcf4ca85fe9958b9aa977e53175234235
parent: a8650067946d600cbf7e6406bc85d248cf96607d
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Nov 21 15:24:52 EST 2020

stream: wrong filters order, fix it; add Sobjoffset

--- a/pdf.h
+++ b/pdf.h
@@ -111,6 +111,7 @@
 	Buffer buf;
 	void *bio;
 	int linelen;
+	int objoff;
 };
 
 extern Object null;
@@ -174,6 +175,7 @@
 int Sungetc(Stream *s);
 int Ssize(Stream *s);
 int Soffset(Stream *s);
+int Sobjoffset(Stream *s);
 int Sseek(Stream *s, int off, int whence);
 void Sclose(Stream *s);
 int Sgetd(Stream *s, double *d);
--- a/stream.c
+++ b/stream.c
@@ -49,7 +49,7 @@
 			goto err;
 		}
 
-		for(i = nflts-1; i >= 0; i--){
+		for(i = 0; i < nflts; i++){
 			if(flts[i]->type != Oname){
 				werrstr("filter type invalid (%T)", flts[i]);
 				goto err;
@@ -73,6 +73,7 @@
 		return nil;
 	}
 	s->buf = b;
+	s->objoff = o->stream.off;
 
 	return s;
 err:
@@ -94,9 +95,10 @@
 	int n;
 	uchar c;
 
+	n = 1;
 	if(s->bio != nil)
-		return Bgetc(s->bio);
-	if((n = bufget(&s->buf, &c, 1)) < 0)
+		c = Bgetc(s->bio);
+	else if((n = bufget(&s->buf, &c, 1)) < 0)
 		return -2;
 
 	return n == 0 ? -1 : (int)c;
@@ -115,9 +117,16 @@
 }
 
 int
+Sobjoffset(Stream *s)
+{
+	return s->objoff;
+}
+
+int
 Ssize(Stream *s)
 {
-	assert(s->bio == nil);
+	if(s->bio != nil)
+		return -1;
 	return bufleft(&s->buf);
 }