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 @@
11 #include <u.h>
22 #include <libc.h>
3−#include <ctype.h>
3+#include <bio.h>
44 #include "pdf.h"
55
6+/* 7.3.6 Array Objects */
7+
68 Object *
7−pdfarray(char *p, char **e, int len)
9+pdfarray(Biobuf *b)
810 {
911 Object *o, *m;
1012 Object **a;
11−
12− o = nil;
13− if(len < 3 || p[0] != '['){
14− werrstr("invalid array");
15− goto err;
16− }
17− p++;
18− len--;
13+ int c, noel;
1914
2015 o = calloc(1, sizeof(*o));
2116 o->type = Oarray;
22− for(; len >= 1;){
23− for(; len > 0 && isws(*p); p++, len--);
24− if(len < 1){
25− werrstr("too short");
26− goto err;
27− }
17+ Bgetc(b); /* throw away '[' */
2818
29− if(p[0] == ']'){
30− p++;
19+ for(noel = 0;;){
20+ if((c = Bgetc(b)) < 0 || c == ']')
3121 break;
22+ if(noel){
23+ werrstr("no ']'");
24+ goto err;
3225 }
3326
34− if((m = pdfobject(p, e, len)) == nil)
35− goto err;
36− len -= *e - p;
37− p = *e;
27+ Bungetc(b);
28+ if((m = pdfobject(b)) == nil){
29+ noel = 1;
30+ continue;
31+ }
3832
3933 if((a = realloc(o->array.e, (o->array.ne+1)*sizeof(Object*))) == nil){
4034 freeobject(m);
@@ -45,11 +39,14 @@ pdfarray(char *p, char **e, int len) · 4 unmodified lines
4539 a[o->array.ne++] = m;
4640 }
4741
48− *e = p;
42+ if(c != ']'){
43+ werrstr("no ']'");
44+ goto err;
45+ }
4946
5047 return o;
5148 err:
49+ werrstr("array: %r");
5250 freeobject(o);
53−
5451 return nil;
5552 }

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