commit - 5772a2bc0cde0d65bafcc61ae81f5d156fb8e217
commit + c0a508241b974e32485a86191d363ee29fe64cb1
blob - 7f54083301b8555c1ce140580b03944de320b6d8
blob + 7c59c8704db10ae825fbbacf4672e7a63a4304aa
--- pdf.1.mdoc
+++ pdf.1.mdoc
.Sh SYNOPSIS
.Nm pdf
.Op Fl qsv
-.Op Fl d Ar what
+.Op Fl d Ar type
.Op Fl x Ar txtfile
.Ar input.pdf
-.Op Ar oid
+.Op Ar oid ...
.Sh DESCRIPTION
The
.Nm
.Pp
The optional
.Ar oid
-argument selects a specific object to be printed instead of the whole document.
-It is expected to be of the form
+arguments select specific objects to be printed instead of the whole document.
+Each is expected to be of the form
.Dq Va n . Ns Va g
where
.Va n
blob - b461f20777868ac50849218b64b8aeabeb02e9e0
blob + 047745e413075672abecbc5108fe1f15345288b6
--- pdf.c
+++ pdf.c
const char *infile;
const char *xfile;
int qflag, vflag, dflag;
-int onum = -1, ogen = -1; /* -1 means unspecified */
+int *onum, *ogen;
/* helper: parse 's' as a natural number. returns -1 on error. */
int
void
usage(void)
{
- fprintf(stderr, "usage: %s [-qsv] [-d what] [-x out.txt] file [oid]\n",
+ fprintf(stderr,
+ "usage: %s [-qsv] [-d type] [-x out.txt] file [oid ...]\n",
progname);
exit(2);
}
{
struct Env aux;
HParseResult *res = NULL;
- const HParsedToken *obj = NULL;
+ const HParsedToken **obj = NULL;
const uint8_t *input;
off_t sz;
int fd;
- int ch, n;
+ int ch, i, n;
/* command line handling */
progname = argv[0];
switch(ch) {
case 'd': /* dump object */
if (strlen(optarg) != 1 ||
- strchr("s", optarg[0]) == NULL)
+ strchr("sc", optarg[0]) == NULL)
errx(2, "-d: invalid argument");
dflag = optarg[0];
break;
}
argc -= optind;
argv += optind;
- if (argc < 1 || argc > 2)
+ if (argc < 1)
usage();
infile = argv[0];
- if (dflag && argc < 2)
+ argc--;
+ argv++;
+ if (dflag && argc < 1)
errx(2, "-d requires an oid argument");
- if (argc > 1) {
+ if (argc > 0) {
+ onum = calloc(argc, sizeof *onum);
+ ogen = calloc(argc, sizeof *ogen);
+ obj = calloc(argc, sizeof *obj);
+ if (onum == NULL || ogen == NULL)
+ err(2, "object id arguments");
+ }
+ for (i = 0; i < argc; i++) {
char *a, *b;
- a = strtok(argv[1], ". ");
+ ogen[i] = -1; /* -1 = unspecified */
+ a = strtok(argv[i], ". ");
b = strtok(NULL, ". ");
- if ((onum = strtonat(a)) == -1 ||
- (b != NULL && (ogen = strtonat(b)) == -1))
+ if ((onum[i] = strtonat(a)) == -1 ||
+ (b != NULL && (ogen[i] = strtonat(b)) == -1))
errx(2, "invalid oid argument; expected num[.gen]");
- if (onum < 1)
- errx(2, "invalid object number %d", onum);
+ if (onum[i] < 1)
+ errx(2, "invalid object number %d", onum[i]);
}
/* configure output verbosity */
return 1;
}
- /* find the requested object */
- if (onum != -1) {
- obj = findobj(res->ast, onum, ogen);
- if (obj == NULL) {
- if (ogen == -1) {
- errx(2, "%s: object %d not found", infile,
- onum);
- } else {
- errx(2, "%s: object %d.%d not found", infile,
- onum, ogen);
+ /* find the requested objects */
+ if (obj != NULL) {
+ for (i = 0; i < argc; i++) {
+ obj[i] = findobj(res->ast, onum[i], ogen[i]);
+ if (obj[i] == NULL) {
+ if (ogen[i] == -1) {
+ errx(2, "%s: object %d not found",
+ infile, onum[i]);
+ } else {
+ errx(2, "%s: object %d.%d not found",
+ infile, onum[i], ogen[i]);
+ }
}
}
}
/* print desired output */
if (!qflag) {
if (dflag == 's')
- dumpstream(stdout, obj);
+ for (i = 0; i < argc; i++)
+ dumpstream(stdout, obj[i]);
else if (obj != NULL)
- h_pprintln(stdout, obj);
+ for (i = 0; i < argc; i++)
+ h_pprintln(stdout, obj[i]);
else
h_pprintln(stdout, res->ast);
}