static fz_error parsearray(fz_obj **obj, pdf_xref *xref, char **sp, struct vap *v) { fz_error error; fz_obj *a; fz_obj *o; char *s = *sp; error = fz_newarray(&a, 8); if (error) return fz_rethrow(error, "cannot create array"); s ++; /* skip '[' */ while (*s) { skipwhite(&s); if (*s == ']') { s ++; break; } error = parseobj(&o, xref, &s, v); if (error) { fz_dropobj(a); return fz_rethrow(error, "cannot parse item"); } error = fz_arraypush(a, o); if (error) { fz_dropobj(o); fz_dropobj(a); return fz_rethrow(error, "cannot add item to array"); } fz_dropobj(o); } *obj = a; *sp = s; return fz_okay; }
int main (int argc, char **argv) { char str[102400]; Index S; int k; Tdist r; struct stat sdata; struct tms t1,t2; int numQueries = 0; if (argc != 2) { fprintf (stderr,"Usage: %s index-file\n",argv[0]); exit(1); } fprintf (stderr,"reading index...\n"); S = loadIndex (argv[1]); stat (argv[1],&sdata); fprintf (stderr,"read %lli bytes\n",(long long)sdata.st_size); numDistances = 0; while (true) { Obj qry; int siz; bool fixed; if (scanf ("%[0123456789-.]s",str) == 0) break; if (!strcmp(str,"-0")) break; // -0 -> terminate if (str[0] == '-') // negative => kNN { fixed = false; if (sscanf (str+1,"%d",&k) == 0) break; // syntax error } else // range query { fixed = true; #ifdef CONT if (sscanf (str,"%f",&r) == 0) break; // syntax error #else if (sscanf (str,"%d",&r) == 0) break; // syntax error #endif } if (getchar() != ',') break; // syntax error if (scanf ("%[^\n]s",str) == 0) break; // syntax error if (getchar() != '\n') break; // syntax error qry = parseobj (str); numQueries++; if (fixed) { times(&t1); siz = search(S,qry,r,true); times(&t2); fprintf (stderr,"%i objects found\n",siz); } else { times(&t1); r = searchNN (S,qry,k,true); siz = k; times(&t2); #ifdef CONT fprintf (stderr,"kNNs at distance %f\n",r); #else fprintf (stderr,"kNNs at distance %i\n",r); #endif } } fprintf(stderr,"Total distances per query: %f\n", numDistances/(float)numQueries); fprintf (stderr,"freeing...\n"); freeIndex (S,true); fprintf (stderr,"done\n"); return 0; }
static fz_error parsedict(fz_obj **obj, pdf_xref *xref, char **sp, struct vap *v) { fz_error error = fz_okay; fz_obj *dict = nil; fz_obj *key = nil; fz_obj *val = nil; char *s = *sp; error = fz_newdict(&dict, 8); if (error) return fz_rethrow(error, "cannot create dict"); s += 2; /* skip "<<" */ while (*s) { skipwhite(&s); /* end-of-dict marker >> */ if (*s == '>') { s ++; if (*s == '>') { s ++; break; } error = fz_throw("malformed >> marker"); goto cleanup; } /* non-name as key, bail */ if (*s != '/') { error = fz_throw("key is not a name"); goto cleanup; } error = parsename(&key, &s); if (error) { error = fz_rethrow(error, "cannot parse key"); goto cleanup; } skipwhite(&s); error = parseobj(&val, xref, &s, v); if (error) { error = fz_rethrow(error, "cannot parse value"); goto cleanup; } error = fz_dictput(dict, key, val); if (error) { error = fz_rethrow(error, "cannot insert dict entry"); goto cleanup; } fz_dropobj(val); val = nil; fz_dropobj(key); key = nil; } *obj = dict; *sp = s; return fz_okay; cleanup: if (val) fz_dropobj(val); if (key) fz_dropobj(key); if (dict) fz_dropobj(dict); *obj = nil; *sp = s; return error; /* already rethrown */ }