History

rename some of the functions

Sigrid Haflínudóttir committed 6 years ago

Commit ef6cdd01 parent 51cd3bf8 files · +41 −31Browse files

Unified · Split

8 files
  1. array.c +3 −3
  2. dict.c +6 −6
  3. eval.c +2 −2
  4. name.c +1 −1
  5. object.c +11 −11
  6. pdf.c +5 −5
  7. pdf.h +12 −2
  8. string.c +1 −1
array.c+3−3
@@ -25,13 +25,13 @@ pdfarray(Pdf *pdf, Biobuf *b) · 24 unmodified lines
2525 }
2626
2727 Bungetc(b);
28− if((m = pdfobject(pdf, b)) == nil){
28+ if((m = pdfobj(pdf, b)) == nil){
2929 noel = 1;
3030 continue;
3131 }
3232
3333 if((a = realloc(o->array.e, (o->array.ne+1)*sizeof(Object*))) == nil){
34− freeobject(m);
34+ pdfobjfree(m);
3535 goto err;
3636 }
3737
@@ -47,6 +47,6 @@ pdfarray(Pdf *pdf, Biobuf *b) · 9 unmodified lines
4747 return o;
4848 err:
4949 werrstr("array: %r");
50− freeobject(o);
50+ pdfobjfree(o);
5151 return nil;
5252 }
dict.c+6−6
@@ -33,11 +33,11 @@ pdfdict(Pdf *pdf, Biobuf *b) · 32 unmodified lines
3333 }
3434
3535 Bungetc(b);
36− if((k = pdfobject(pdf, b)) == nil){
36+ if((k = pdfobj(pdf, b)) == nil){
3737 nokey = 1;
3838 continue;
3939 }
40− if((v = pdfobject(pdf, b)) == nil)
40+ if((v = pdfobj(pdf, b)) == nil)
4141 goto err;
4242 if(k->type != Oname){
4343 werrstr("expected name as a key");
@@ -49,16 +49,16 @@ pdfdict(Pdf *pdf, Biobuf *b) · 5 unmodified lines
4949
5050 o->dict.kv = kv;
5151 kv[o->dict.nkv].key = strdup(k->name);
52− freeobject(k);
52+ pdfobjfree(k);
5353 kv[o->dict.nkv++].value = v;
5454 k = v = nil;
5555 }
5656
5757 return o;
5858 err:
59− freeobject(o);
60− freeobject(k);
61− freeobject(v);
59+ pdfobjfree(o);
60+ pdfobjfree(k);
61+ pdfobjfree(v);
6262 werrstr("dict: %r");
6363
6464 return nil;
eval.c+2−2
@@ -24,11 +24,11 @@ pdfeval(Pdf *pdf, Object *o) · 23 unmodified lines
2424 werrstr("xref seek failed");
2525 return -1;
2626 }
27− if((d = pdfobject(pdf, pdf->bio)) == nil)
27+ if((d = pdfobj(pdf, pdf->bio)) == nil)
2828 return -1;
2929 *o = *d;
3030 memset(d, 0, sizeof(*d));
31− freeobject(d);
31+ pdfobjfree(d);
3232
3333 return 0;
3434 }
name.c+1−1
@@ -125,7 +125,7 @@ test_pdfname(void) · 124 unmodified lines
125125 fprint(2, "ERROR: expected %q, got %q\n", t[i].out, o->name);
126126 else
127127 fprint(2, "OK\n");
128− freeobject(o);
128+ pdfobjfree(o);
129129 Bterm(&b);
130130 }
131131 }
object.c+11−11
@@ -15,7 +15,7 @@ static Object null = { · 14 unmodified lines
1515
1616 /* General function to parse an object of any type. */
1717 Object *
18−pdfobject(Pdf *pdf, void *b)
18+pdfobj(Pdf *pdf, void *b)
1919 {
2020 Object *o, *o2, *m;
2121 vlong off;
@@ -121,7 +121,7 @@ unexpected: · 99 unmodified lines
121121 Bgetd(b, &o->num); /* get the first number */
122122 off = Boffset(b); /* seek here if not an indirect object later */
123123
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 */
125125 do; while(isws(c = Bgetc(b)));
126126 if(c < 0)
127127 goto err;
@@ -129,16 +129,16 @@ unexpected: · 1 unmodified line
129129 o->type = Oindir;
130130 o->indir.id = o->num;
131131 o->indir.gen = o2->num;
132− freeobject(o2);
132+ pdfobjfree(o2);
133133 return o;
134134 }
135135 if(c == 'o' && Bgetc(b) == 'b' && Bgetc(b) == 'j'){ /* object */
136136 xref.id = o->num;
137137 xref.gen = o2->num;
138138 /* FIXME put into a map */
139− freeobject(o);
140− freeobject(o2);
141− if((o = pdfobject(pdf, b)) != nil)
139+ pdfobjfree(o);
140+ pdfobjfree(o2);
141+ if((o = pdfobj(pdf, b)) != nil)
142142 return o;
143143 o2 = nil;
144144 }
@@ -155,13 +155,13 @@ unexpected: · 10 unmodified lines
155155
156156 err:
157157 werrstr("object: %r");
158− freeobject(o);
159− freeobject(o2);
158+ pdfobjfree(o);
159+ pdfobjfree(o2);
160160 return nil;
161161 }
162162
163163 void
164−freeobject(Object *o)
164+pdfobjfree(Object *o)
165165 {
166166 int i;
167167
@@ -180,7 +180,7 @@ freeobject(Object *o) · 12 unmodified lines
180180
181181 case Oarray:
182182 for(i = 0; i < o->array.ne; i++)
183− freeobject(o->array.e[i]);
183+ pdfobjfree(o->array.e[i]);
184184 free(o->array.e);
185185 break;
186186
@@ -188,7 +188,7 @@ freeobject(Object *o) · 1 unmodified line
188188 case Ostream:
189189 for(i = 0; i < o->dict.nkv; i++){
190190 free(o->dict.kv[i].key);
191− freeobject(o->dict.kv[i].value);
191+ pdfobjfree(o->dict.kv[i].value);
192192 }
193193 free(o->dict.kv);
194194 break;
pdf.c+5−5
@@ -79,7 +79,7 @@ trailerread(Pdf *pdf) · 78 unmodified lines
7979 Object *o;
8080 KeyValue *kv;
8181
82− if((o = pdfobject(pdf, pdf->bio)) == nil)
82+ if((o = pdfobj(pdf, pdf->bio)) == nil)
8383 goto err;
8484
8585 if(o->type != Odict){
@@ -93,7 +93,7 @@ trailerread(Pdf *pdf) · 7 unmodified lines
9393 else if(strcmp(kv->key, "Info") == 0)
9494 pdf->info = kv->value;
9595 }
96− freeobject(o);
96+ pdfobjfree(o);
9797 o = nil;
9898
9999 /* root is required, info is optional */
@@ -106,7 +106,7 @@ trailerread(Pdf *pdf) · 6 unmodified lines
106106
107107 return 0;
108108 err:
109− freeobject(o);
109+ pdfobjfree(o);
110110 return -1;
111111 }
112112
@@ -196,7 +196,7 @@ badxref: · 83 unmodified lines
196196 }
197197 }else if(isdigit(tmp[0])){ /* could be 7.5.8 xref stream (since PDF 1.5) */
198198 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)
200200 goto err;
201201
202202 }
@@ -205,7 +205,7 @@ badxref: · 2 unmodified lines
205205 err:
206206 werrstr("pdfopen: %r [at %p]", (void*)Boffset(b));
207207 pdfclose(pdf);
208− freeobject(o);
208+ pdfobjfree(o);
209209 return nil;
210210 }
211211
pdf.h+12−2
@@ -14,6 +14,7 @@ typedef struct KeyValue KeyValue; · 13 unmodified lines
1414 typedef struct Object Object;
1515 typedef struct Pdf Pdf;
1616 typedef struct Xref Xref;
17+typedef struct Stream Stream;
1718
1819 struct Object {
1920 int type;
@@ -70,11 +71,17 @@ struct Xref { · 50 unmodified lines
7071 u16int gen;
7172 };
7273
74+struct Stream {
75+ Biobuf;
76+ Object *o;
77+ u32int offset;
78+};
79+
7380 Pdf *pdfopen(int fd);
7481 void pdfclose(Pdf *pdf);
7582
76−Object *pdfobject(Pdf *pdf, void *b);
77−void freeobject(Object *o);
83+Object *pdfobj(Pdf *pdf, void *b);
84+void pdfobjfree(Object *o);
7885
7986 /*
8087 * If the object is indirect, resolve it. Operation is not recursive, ie
@@ -86,3 +93,6 @@ int isws(int c); · 5 unmodified lines
8693 int isdelim(int c);
8794
8895 Object *pdfdictget(Object *o, char *name);
96+
97+Stream *streamopen(Pdf *pdf, Object *o);
98+void streamclose(Stream *s);
string.c+1−1
@@ -216,7 +216,7 @@ test_pdfstring(void) · 215 unmodified lines
216216 fprint(2, "ERROR: expected %q, got %q\n", t[i].out, o->str);
217217 else
218218 fprint(2, "OK\n");
219− freeobject(o);
219+ pdfobjfree(o);
220220 Bterm(&b);
221221 }
222222 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t