ref: ef6cdd0d40612067504d1587aa4e64206fe1ea8a
parent: 51cd3bfceeb001872d4ff298180875c4229a3d68
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Aug 29 07:17:22 EDT 2020
rename some of the functions
--- a/array.c
+++ b/array.c
@@ -25,13 +25,13 @@
}
Bungetc(b);
- if((m = pdfobject(pdf, b)) == nil){
+ if((m = pdfobj(pdf, b)) == nil){
noel = 1;
continue;
}
if((a = realloc(o->array.e, (o->array.ne+1)*sizeof(Object*))) == nil){
- freeobject(m);
+ pdfobjfree(m);
goto err;
}
@@ -47,6 +47,6 @@
return o;
err:
werrstr("array: %r");
- freeobject(o);
+ pdfobjfree(o);
return nil;
}
--- a/dict.c
+++ b/dict.c
@@ -33,11 +33,11 @@
}
Bungetc(b);
- if((k = pdfobject(pdf, b)) == nil){
+ if((k = pdfobj(pdf, b)) == nil){
nokey = 1;
continue;
}
- if((v = pdfobject(pdf, b)) == nil)
+ if((v = pdfobj(pdf, b)) == nil)
goto err;
if(k->type != Oname){
werrstr("expected name as a key");
@@ -49,7 +49,7 @@
o->dict.kv = kv;
kv[o->dict.nkv].key = strdup(k->name);
- freeobject(k);
+ pdfobjfree(k);
kv[o->dict.nkv++].value = v;
k = v = nil;
}
@@ -56,9 +56,9 @@
return o;
err:
- freeobject(o);
- freeobject(k);
- freeobject(v);
+ pdfobjfree(o);
+ pdfobjfree(k);
+ pdfobjfree(v);
werrstr("dict: %r");
return nil;
--- a/eval.c
+++ b/eval.c
@@ -24,11 +24,11 @@
werrstr("xref seek failed");
return -1;
}
- if((d = pdfobject(pdf, pdf->bio)) == nil)
+ if((d = pdfobj(pdf, pdf->bio)) == nil)
return -1;
*o = *d;
memset(d, 0, sizeof(*d));
- freeobject(d);
+ pdfobjfree(d);
return 0;
}
--- a/name.c
+++ b/name.c
@@ -125,7 +125,7 @@
fprint(2, "ERROR: expected %q, got %q\n", t[i].out, o->name);
else
fprint(2, "OK\n");
- freeobject(o);
+ pdfobjfree(o);
Bterm(&b);
}
}
--- a/object.c
+++ b/object.c
@@ -15,7 +15,7 @@
/* General function to parse an object of any type. */
Object *
-pdfobject(Pdf *pdf, void *b)
+pdfobj(Pdf *pdf, void *b)
{
Object *o, *o2, *m;
vlong off;
@@ -121,7 +121,7 @@
Bgetd(b, &o->num); /* get the first number */
off = Boffset(b); /* seek here if not an indirect object later */
- if((o2 = pdfobject(pdf, b)) != nil && o2->type == Onum){ /* second object is number too */
+ if((o2 = pdfobj(pdf, b)) != nil && o2->type == Onum){ /* second object is number too */
do; while(isws(c = Bgetc(b)));
if(c < 0)
goto err;
@@ -129,7 +129,7 @@
o->type = Oindir;
o->indir.id = o->num;
o->indir.gen = o2->num;
- freeobject(o2);
+ pdfobjfree(o2);
return o;
}
if(c == 'o' && Bgetc(b) == 'b' && Bgetc(b) == 'j'){ /* object */
@@ -136,9 +136,9 @@
xref.id = o->num;
xref.gen = o2->num;
/* FIXME put into a map */
- freeobject(o);
- freeobject(o2);
- if((o = pdfobject(pdf, b)) != nil)
+ pdfobjfree(o);
+ pdfobjfree(o2);
+ if((o = pdfobj(pdf, b)) != nil)
return o;
o2 = nil;
}
@@ -155,13 +155,13 @@
err:
werrstr("object: %r");
- freeobject(o);
- freeobject(o2);
+ pdfobjfree(o);
+ pdfobjfree(o2);
return nil;
}
void
-freeobject(Object *o)
+pdfobjfree(Object *o)
{
int i;
@@ -180,7 +180,7 @@
case Oarray:
for(i = 0; i < o->array.ne; i++)
- freeobject(o->array.e[i]);
+ pdfobjfree(o->array.e[i]);
free(o->array.e);
break;
@@ -188,7 +188,7 @@
case Ostream:
for(i = 0; i < o->dict.nkv; i++){
free(o->dict.kv[i].key);
- freeobject(o->dict.kv[i].value);
+ pdfobjfree(o->dict.kv[i].value);
}
free(o->dict.kv);
break;
--- a/pdf.c
+++ b/pdf.c
@@ -79,7 +79,7 @@
Object *o;
KeyValue *kv;
- if((o = pdfobject(pdf, pdf->bio)) == nil)
+ if((o = pdfobj(pdf, pdf->bio)) == nil)
goto err;
if(o->type != Odict){
@@ -93,7 +93,7 @@
else if(strcmp(kv->key, "Info") == 0)
pdf->info = kv->value;
}
- freeobject(o);
+ pdfobjfree(o);
o = nil;
/* root is required, info is optional */
@@ -106,7 +106,7 @@
return 0;
err:
- freeobject(o);
+ pdfobjfree(o);
return -1;
}
@@ -196,7 +196,7 @@
}
}else if(isdigit(tmp[0])){ /* could be 7.5.8 xref stream (since PDF 1.5) */
Bseek(b, xreftb, 0);
- if((o = pdfobject(pdf, b)) == nil || pdfeval(pdf, o) != 0)
+ if((o = pdfobj(pdf, b)) == nil || pdfeval(pdf, o) != 0)
goto err;
}
@@ -205,7 +205,7 @@
err:
werrstr("pdfopen: %r [at %p]", (void*)Boffset(b));
pdfclose(pdf);
- freeobject(o);
+ pdfobjfree(o);
return nil;
}
--- a/pdf.h
+++ b/pdf.h
@@ -14,6 +14,7 @@
typedef struct Object Object;
typedef struct Pdf Pdf;
typedef struct Xref Xref;
+typedef struct Stream Stream;
struct Object {
int type;
@@ -70,11 +71,17 @@
u16int gen;
};
+struct Stream {
+ Biobuf;
+ Object *o;
+ u32int offset;
+};
+
Pdf *pdfopen(int fd);
void pdfclose(Pdf *pdf);
-Object *pdfobject(Pdf *pdf, void *b);
-void freeobject(Object *o);
+Object *pdfobj(Pdf *pdf, void *b);
+void pdfobjfree(Object *o);
/*
* If the object is indirect, resolve it. Operation is not recursive, ie
@@ -86,3 +93,6 @@
int isdelim(int c);
Object *pdfdictget(Object *o, char *name);
+
+Stream *streamopen(Pdf *pdf, Object *o);
+void streamclose(Stream *s);
--- a/string.c
+++ b/string.c
@@ -216,7 +216,7 @@
fprint(2, "ERROR: expected %q, got %q\n", t[i].out, o->str);
else
fprint(2, "OK\n");
- freeobject(o);
+ pdfobjfree(o);
Bterm(&b);
}
}