Commit Diff


commit - 91473d5f1fa4f5e83430127f82ec336551db3f28
commit + 81dc4dbad250ff8e9433eea76c1cc15649a2f927
blob - 3b282184f21c92d3d3c6b73983f07c53cb54b3bf
blob + 1761f1414ca65700c8f8cea42ddf9ed29f4e7fe2
--- pdf.c
+++ pdf.c
@@ -4416,11 +4416,6 @@ process_page_content(struct Env *aux)
 
 
 /*
- * ********************************************************************
- * Start xref parsing
- * ********************************************************************
- */
-/*
  * decode the bytes in 'b' according to metadata in the stream dictionary 'd'
  * and parse the result with 'p'.
  */
@@ -4875,8 +4870,75 @@ kxstream(HAllocator *mm__, const HParsedToken *x, void
 	return h_sequence__m(mm__, dict_p, value_p, NULL);
 }
 
+
+/*
+ * main program
+ */
 
+#include <stdio.h>
+#include <string.h>	/* strtok() */
+#include <inttypes.h>
+#include <fcntl.h>	/* open() */
+#include <unistd.h>	/* lseek(), getopt() */
+#include <sys/mman.h>	/* mmap() */
+#include <errno.h>
 
+/* used with getopt() */
+extern char *optarg;
+extern int optind;
+
+/* command line arguments */
+const char *progname;
+const char *infile;
+const char *xfile, *Xfile;
+int qflag, vflag, dflag;
+int onum = -1, ogen = -1;	/* -1 means unspecified */
+
+/* helper: parse 's' as a natural number. returns -1 on error. */
+int
+strtonat(const char *s)
+{
+	char *p;
+	long l;
+
+	errno = 0;
+	l = strtol(s, &p, 10);
+	if (errno != 0)
+		return -1;
+	if (p == s || *p != '\0')	/* no parse */
+		return -1;
+	if (l < 0 || l > INT_MAX)	/* out of range */
+		return -1;
+	return l;
+}
+
+void
+usage(void)
+{
+	fprintf(stderr, "usage: %s [-qsv] [-d what] [-x out.txt] file [oid]\n",
+	    progname);
+	exit(2);
+}
+
+void
+dumpstream(FILE *f, const HParsedToken *obj)
+{
+	HParseResult *res;
+	HBytes data;
+
+	// XXX properly verify that obj is a stream (needs custom token type)
+	if (obj->token_type != TT_SEQUENCE || obj->seq->used != 2 ||
+	    obj->seq->elements[1]->token_type != TT_HParseResult)
+		errx(2, "%s: requested object is not a stream", infile);
+
+	res = H_INDEX(HParseResult, obj, 1);
+	assert(res != NULL);
+	assert(res->ast != NULL);
+	data = H_CAST_BYTES(res->ast);
+
+	fwrite(data.token, 1, data.len, f);
+}
+
 /*
  * This helper implements the standard backwards parsing strategy to read all
  * cross-reference sections and trailer dictionaries, starting from the
@@ -4887,8 +4949,6 @@ kxstream(HAllocator *mm__, const HParsedToken *x, void
  * number of elements.
  */
 // XXX review changes to this function. see git -L /^parse_xrefs/,/^}/:pdf.c'
-const char *infile = NULL;
-
 void
 parse_xrefs(struct Env *aux)
 {
@@ -4979,84 +5039,8 @@ parse_xrefs(struct Env *aux)
 end:
 	aux->xrefs = xrefs;
 	aux->nxrefs = n;
-}
-
-/*
- * ********************************************************************
- * End xref parsing
- * ********************************************************************
- */
-
-
-
-
-/*
- * main program
- */
-
-#include <stdio.h>
-#include <string.h>	/* strtok() */
-#include <inttypes.h>
-#include <fcntl.h>	/* open() */
-#include <unistd.h>	/* lseek(), getopt() */
-#include <sys/mman.h>	/* mmap() */
-#include <errno.h>
-
-/* used with getopt() */
-extern char *optarg;
-extern int optind;
-
-/* command line arguments */
-const char *progname;
-const char *xfile, *Xfile;
-int qflag, vflag, dflag;
-int onum = -1, ogen = -1;	/* -1 means unspecified */
-
-/* helper: parse 's' as a natural number. returns -1 on error. */
-int
-strtonat(const char *s)
-{
-	char *p;
-	long l;
-
-	errno = 0;
-	l = strtol(s, &p, 10);
-	if (errno != 0)
-		return -1;
-	if (p == s || *p != '\0')	/* no parse */
-		return -1;
-	if (l < 0 || l > INT_MAX)	/* out of range */
-		return -1;
-	return l;
 }
 
-void
-usage(void)
-{
-	fprintf(stderr, "usage: %s [-qsv] [-d what] [-x out.txt] file [oid]\n",
-	    progname);
-	exit(2);
-}
-
-void
-dumpstream(FILE *f, const HParsedToken *obj)
-{
-	HParseResult *res;
-	HBytes data;
-
-	// XXX properly verify that obj is a stream (needs custom token type)
-	if (obj->token_type != TT_SEQUENCE || obj->seq->used != 2 ||
-	    obj->seq->elements[1]->token_type != TT_HParseResult)
-		errx(2, "%s: requested object is not a stream", infile);
-
-	res = H_INDEX(HParseResult, obj, 1);
-	assert(res != NULL);
-	assert(res->ast != NULL);
-	data = H_CAST_BYTES(res->ast);
-
-	fwrite(data.token, 1, data.len, f);
-}
-
 int
 main(int argc, char *argv[])
 {