Unified · Split
| @@ -25,13 +25,13 @@ pdfarray(Pdf *pdf, Biobuf *b) · 24 unmodified lines | |||
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | Bungetc(b); | 27 | Bungetc(b); |
| 28 | if((m = pdfobject(pdf, b)) == nil){ | 28 | if((m = pdfobj(pdf, b)) == nil){ |
| 29 | noel = 1; | 29 | noel = 1; |
| 30 | continue; | 30 | continue; |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | if((a = realloc(o->array.e, (o->array.ne+1)*sizeof(Object*))) == nil){ | 33 | if((a = realloc(o->array.e, (o->array.ne+1)*sizeof(Object*))) == nil){ |
| 34 | freeobject(m); | 34 | pdfobjfree(m); |
| 35 | goto err; | 35 | goto err; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| @@ -47,6 +47,6 @@ pdfarray(Pdf *pdf, Biobuf *b) · 9 unmodified lines | |||
| 47 | return o; | 47 | return o; |
| 48 | err: | 48 | err: |
| 49 | werrstr("array: %r"); | 49 | werrstr("array: %r"); |
| 50 | freeobject(o); | 50 | pdfobjfree(o); |
| 51 | return nil; | 51 | return nil; |
| 52 | } | 52 | } |
| @@ -33,11 +33,11 @@ pdfdict(Pdf *pdf, Biobuf *b) · 32 unmodified lines | |||
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | Bungetc(b); | 35 | Bungetc(b); |
| 36 | if((k = pdfobject(pdf, b)) == nil){ | 36 | if((k = pdfobj(pdf, b)) == nil){ |
| 37 | nokey = 1; | 37 | nokey = 1; |
| 38 | continue; | 38 | continue; |
| 39 | } | 39 | } |
| 40 | if((v = pdfobject(pdf, b)) == nil) | 40 | if((v = pdfobj(pdf, b)) == nil) |
| 41 | goto err; | 41 | goto err; |
| 42 | if(k->type != Oname){ | 42 | if(k->type != Oname){ |
| 43 | werrstr("expected name as a key"); | 43 | werrstr("expected name as a key"); |
| @@ -49,16 +49,16 @@ pdfdict(Pdf *pdf, Biobuf *b) · 5 unmodified lines | |||
| 49 | 49 | ||
| 50 | o->dict.kv = kv; | 50 | o->dict.kv = kv; |
| 51 | kv[o->dict.nkv].key = strdup(k->name); | 51 | kv[o->dict.nkv].key = strdup(k->name); |
| 52 | freeobject(k); | 52 | pdfobjfree(k); |
| 53 | kv[o->dict.nkv++].value = v; | 53 | kv[o->dict.nkv++].value = v; |
| 54 | k = v = nil; | 54 | k = v = nil; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | return o; | 57 | return o; |
| 58 | err: | 58 | err: |
| 59 | freeobject(o); | 59 | pdfobjfree(o); |
| 60 | freeobject(k); | 60 | pdfobjfree(k); |
| 61 | freeobject(v); | 61 | pdfobjfree(v); |
| 62 | werrstr("dict: %r"); | 62 | werrstr("dict: %r"); |
| 63 | 63 | ||
| 64 | return nil; | 64 | return nil; |
| @@ -24,11 +24,11 @@ pdfeval(Pdf *pdf, Object *o) · 23 unmodified lines | |||
| 24 | werrstr("xref seek failed"); | 24 | werrstr("xref seek failed"); |
| 25 | return -1; | 25 | return -1; |
| 26 | } | 26 | } |
| 27 | if((d = pdfobject(pdf, pdf->bio)) == nil) | 27 | if((d = pdfobj(pdf, pdf->bio)) == nil) |
| 28 | return -1; | 28 | return -1; |
| 29 | *o = *d; | 29 | *o = *d; |
| 30 | memset(d, 0, sizeof(*d)); | 30 | memset(d, 0, sizeof(*d)); |
| 31 | freeobject(d); | 31 | pdfobjfree(d); |
| 32 | 32 | ||
| 33 | return 0; | 33 | return 0; |
| 34 | } | 34 | } |
| @@ -125,7 +125,7 @@ test_pdfname(void) · 124 unmodified lines | |||
| 125 | fprint(2, "ERROR: expected %q, got %q\n", t[i].out, o->name); | 125 | fprint(2, "ERROR: expected %q, got %q\n", t[i].out, o->name); |
| 126 | else | 126 | else |
| 127 | fprint(2, "OK\n"); | 127 | fprint(2, "OK\n"); |
| 128 | freeobject(o); | 128 | pdfobjfree(o); |
| 129 | Bterm(&b); | 129 | Bterm(&b); |
| 130 | } | 130 | } |
| 131 | } | 131 | } |
| @@ -15,7 +15,7 @@ static Object null = { · 14 unmodified lines | |||
| 15 | 15 | ||
| 16 | /* General function to parse an object of any type. */ | 16 | /* General function to parse an object of any type. */ |
| 17 | Object * | 17 | Object * |
| 18 | pdfobject(Pdf *pdf, void *b) | 18 | pdfobj(Pdf *pdf, void *b) |
| 19 | { | 19 | { |
| 20 | Object *o, *o2, *m; | 20 | Object *o, *o2, *m; |
| 21 | vlong off; | 21 | vlong off; |
| @@ -121,7 +121,7 @@ unexpected: · 99 unmodified lines | |||
| 121 | Bgetd(b, &o->num); /* get the first number */ | 121 | Bgetd(b, &o->num); /* get the first number */ |
| 122 | off = Boffset(b); /* seek here if not an indirect object later */ | 122 | off = Boffset(b); /* seek here if not an indirect object later */ |
| 123 | 123 | ||
| 124 | if((o2 = pdfobject(pdf, b)) != nil && o2->type == Onum){ /* second object is number too */ | 124 | if((o2 = pdfobj(pdf, b)) != nil && o2->type == Onum){ /* second object is number too */ |
| 125 | do; while(isws(c = Bgetc(b))); | 125 | do; while(isws(c = Bgetc(b))); |
| 126 | if(c < 0) | 126 | if(c < 0) |
| 127 | goto err; | 127 | goto err; |
| @@ -129,16 +129,16 @@ unexpected: · 1 unmodified line | |||
| 129 | o->type = Oindir; | 129 | o->type = Oindir; |
| 130 | o->indir.id = o->num; | 130 | o->indir.id = o->num; |
| 131 | o->indir.gen = o2->num; | 131 | o->indir.gen = o2->num; |
| 132 | freeobject(o2); | 132 | pdfobjfree(o2); |
| 133 | return o; | 133 | return o; |
| 134 | } | 134 | } |
| 135 | if(c == 'o' && Bgetc(b) == 'b' && Bgetc(b) == 'j'){ /* object */ | 135 | if(c == 'o' && Bgetc(b) == 'b' && Bgetc(b) == 'j'){ /* object */ |
| 136 | xref.id = o->num; | 136 | xref.id = o->num; |
| 137 | xref.gen = o2->num; | 137 | xref.gen = o2->num; |
| 138 | /* FIXME put into a map */ | 138 | /* FIXME put into a map */ |
| 139 | freeobject(o); | 139 | pdfobjfree(o); |
| 140 | freeobject(o2); | 140 | pdfobjfree(o2); |
| 141 | if((o = pdfobject(pdf, b)) != nil) | 141 | if((o = pdfobj(pdf, b)) != nil) |
| 142 | return o; | 142 | return o; |
| 143 | o2 = nil; | 143 | o2 = nil; |
| 144 | } | 144 | } |
| @@ -155,13 +155,13 @@ unexpected: · 10 unmodified lines | |||
| 155 | 155 | ||
| 156 | err: | 156 | err: |
| 157 | werrstr("object: %r"); | 157 | werrstr("object: %r"); |
| 158 | freeobject(o); | 158 | pdfobjfree(o); |
| 159 | freeobject(o2); | 159 | pdfobjfree(o2); |
| 160 | return nil; | 160 | return nil; |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | void | 163 | void |
| 164 | freeobject(Object *o) | 164 | pdfobjfree(Object *o) |
| 165 | { | 165 | { |
| 166 | int i; | 166 | int i; |
| 167 | 167 | ||
| @@ -180,7 +180,7 @@ freeobject(Object *o) · 12 unmodified lines | |||
| 180 | 180 | ||
| 181 | case Oarray: | 181 | case Oarray: |
| 182 | for(i = 0; i < o->array.ne; i++) | 182 | for(i = 0; i < o->array.ne; i++) |
| 183 | freeobject(o->array.e[i]); | 183 | pdfobjfree(o->array.e[i]); |
| 184 | free(o->array.e); | 184 | free(o->array.e); |
| 185 | break; | 185 | break; |
| 186 | 186 | ||
| @@ -188,7 +188,7 @@ freeobject(Object *o) · 1 unmodified line | |||
| 188 | case Ostream: | 188 | case Ostream: |
| 189 | for(i = 0; i < o->dict.nkv; i++){ | 189 | for(i = 0; i < o->dict.nkv; i++){ |
| 190 | free(o->dict.kv[i].key); | 190 | free(o->dict.kv[i].key); |
| 191 | freeobject(o->dict.kv[i].value); | 191 | pdfobjfree(o->dict.kv[i].value); |
| 192 | } | 192 | } |
| 193 | free(o->dict.kv); | 193 | free(o->dict.kv); |
| 194 | break; | 194 | break; |
| @@ -79,7 +79,7 @@ trailerread(Pdf *pdf) · 78 unmodified lines | |||
| 79 | Object *o; | 79 | Object *o; |
| 80 | KeyValue *kv; | 80 | KeyValue *kv; |
| 81 | 81 | ||
| 82 | if((o = pdfobject(pdf, pdf->bio)) == nil) | 82 | if((o = pdfobj(pdf, pdf->bio)) == nil) |
| 83 | goto err; | 83 | goto err; |
| 84 | 84 | ||
| 85 | if(o->type != Odict){ | 85 | if(o->type != Odict){ |
| @@ -93,7 +93,7 @@ trailerread(Pdf *pdf) · 7 unmodified lines | |||
| 93 | else if(strcmp(kv->key, "Info") == 0) | 93 | else if(strcmp(kv->key, "Info") == 0) |
| 94 | pdf->info = kv->value; | 94 | pdf->info = kv->value; |
| 95 | } | 95 | } |
| 96 | freeobject(o); | 96 | pdfobjfree(o); |
| 97 | o = nil; | 97 | o = nil; |
| 98 | 98 | ||
| 99 | /* root is required, info is optional */ | 99 | /* root is required, info is optional */ |
| @@ -106,7 +106,7 @@ trailerread(Pdf *pdf) · 6 unmodified lines | |||
| 106 | 106 | ||
| 107 | return 0; | 107 | return 0; |
| 108 | err: | 108 | err: |
| 109 | freeobject(o); | 109 | pdfobjfree(o); |
| 110 | return -1; | 110 | return -1; |
| 111 | } | 111 | } |
| 112 | 112 | ||
| @@ -196,7 +196,7 @@ badxref: · 83 unmodified lines | |||
| 196 | } | 196 | } |
| 197 | }else if(isdigit(tmp[0])){ /* could be 7.5.8 xref stream (since PDF 1.5) */ | 197 | }else if(isdigit(tmp[0])){ /* could be 7.5.8 xref stream (since PDF 1.5) */ |
| 198 | Bseek(b, xreftb, 0); | 198 | Bseek(b, xreftb, 0); |
| 199 | if((o = pdfobject(pdf, b)) == nil || pdfeval(pdf, o) != 0) | 199 | if((o = pdfobj(pdf, b)) == nil || pdfeval(pdf, o) != 0) |
| 200 | goto err; | 200 | goto err; |
| 201 | 201 | ||
| 202 | } | 202 | } |
| @@ -205,7 +205,7 @@ badxref: · 2 unmodified lines | |||
| 205 | err: | 205 | err: |
| 206 | werrstr("pdfopen: %r [at %p]", (void*)Boffset(b)); | 206 | werrstr("pdfopen: %r [at %p]", (void*)Boffset(b)); |
| 207 | pdfclose(pdf); | 207 | pdfclose(pdf); |
| 208 | freeobject(o); | 208 | pdfobjfree(o); |
| 209 | return nil; | 209 | return nil; |
| 210 | } | 210 | } |
| 211 | 211 | ||
| @@ -14,6 +14,7 @@ typedef struct KeyValue KeyValue; · 13 unmodified lines | |||
| 14 | typedef struct Object Object; | 14 | typedef struct Object Object; |
| 15 | typedef struct Pdf Pdf; | 15 | typedef struct Pdf Pdf; |
| 16 | typedef struct Xref Xref; | 16 | typedef struct Xref Xref; |
| 17 | typedef struct Stream Stream; | ||
| 17 | 18 | ||
| 18 | struct Object { | 19 | struct Object { |
| 19 | int type; | 20 | int type; |
| @@ -70,11 +71,17 @@ struct Xref { · 50 unmodified lines | |||
| 70 | u16int gen; | 71 | u16int gen; |
| 71 | }; | 72 | }; |
| 72 | 73 | ||
| 74 | struct Stream { | ||
| 75 | Biobuf; | ||
| 76 | Object *o; | ||
| 77 | u32int offset; | ||
| 78 | }; | ||
| 79 | |||
| 73 | Pdf *pdfopen(int fd); | 80 | Pdf *pdfopen(int fd); |
| 74 | void pdfclose(Pdf *pdf); | 81 | void pdfclose(Pdf *pdf); |
| 75 | 82 | ||
| 76 | Object *pdfobject(Pdf *pdf, void *b); | 83 | Object *pdfobj(Pdf *pdf, void *b); |
| 77 | void freeobject(Object *o); | 84 | void pdfobjfree(Object *o); |
| 78 | 85 | ||
| 79 | /* | 86 | /* |
| 80 | * If the object is indirect, resolve it. Operation is not recursive, ie | 87 | * If the object is indirect, resolve it. Operation is not recursive, ie |
| @@ -86,3 +93,6 @@ int isws(int c); · 5 unmodified lines | |||
| 86 | int isdelim(int c); | 93 | int isdelim(int c); |
| 87 | 94 | ||
| 88 | Object *pdfdictget(Object *o, char *name); | 95 | Object *pdfdictget(Object *o, char *name); |
| 96 | |||
| 97 | Stream *streamopen(Pdf *pdf, Object *o); | ||
| 98 | void streamclose(Stream *s); | ||
| @@ -216,7 +216,7 @@ test_pdfstring(void) · 215 unmodified lines | |||
| 216 | fprint(2, "ERROR: expected %q, got %q\n", t[i].out, o->str); | 216 | fprint(2, "ERROR: expected %q, got %q\n", t[i].out, o->str); |
| 217 | else | 217 | else |
| 218 | fprint(2, "OK\n"); | 218 | fprint(2, "OK\n"); |
| 219 | freeobject(o); | 219 | pdfobjfree(o); |
| 220 | Bterm(&b); | 220 | Bterm(&b); |
| 221 | } | 221 | } |
| 222 | } | 222 | } |