History

rewrite the API, support more object types and actual evaluation

Sigrid Haflínudóttir committed 6 years ago

Commit a080ae81 parent 34238e011 files · +494 −376Browse files

Showing the changes to array.c (1 of 11 files). Show all

Unified · Split

array.c+21−24
@@ -1,40 +1,34 @@
1#include <u.h>1#include <u.h>
2#include <libc.h>2#include <libc.h>
3#include <ctype.h>3#include <bio.h>
4#include "pdf.h"4#include "pdf.h"
5 5
6/* 7.3.6 Array Objects */
7
6Object *8Object *
7pdfarray(char *p, char **e, int len)9pdfarray(Biobuf *b)
8{10{
9 Object *o, *m;11 Object *o, *m;
10 Object **a;12 Object **a;
11 13 int c, noel;
12 o = nil;
13 if(len < 3 || p[0] != '['){
14 werrstr("invalid array");
15 goto err;
16 }
17 p++;
18 len--;
19 14
20 o = calloc(1, sizeof(*o));15 o = calloc(1, sizeof(*o));
21 o->type = Oarray;16 o->type = Oarray;
22 for(; len >= 1;){17 Bgetc(b); /* throw away '[' */
23 for(; len > 0 && isws(*p); p++, len--);
24 if(len < 1){
25 werrstr("too short");
26 goto err;
27 }
28 18
29 if(p[0] == ']'){19 for(noel = 0;;){
30 p++;20 if((c = Bgetc(b)) < 0 || c == ']')
31 break;21 break;
22 if(noel){
23 werrstr("no ']'");
24 goto err;
32 }25 }
33 26
34 if((m = pdfobject(p, e, len)) == nil)27 Bungetc(b);
35 goto err;28 if((m = pdfobject(b)) == nil){
36 len -= *e - p;29 noel = 1;
37 p = *e;30 continue;
31 }
38 32
39 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){
40 freeobject(m);34 freeobject(m);
@@ -45,11 +39,14 @@ pdfarray(char *p, char **e, int len) · 4 unmodified lines
45 a[o->array.ne++] = m;39 a[o->array.ne++] = m;
46 }40 }
47 41
48 *e = p;42 if(c != ']'){
43 werrstr("no ']'");
44 goto err;
45 }
49 46
50 return o;47 return o;
51err:48err:
49 werrstr("array: %r");
52 freeobject(o);50 freeobject(o);
53
54 return nil;51 return nil;
55}52}

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