common: add an 'early_parse' backend hook

Also fix 'query_only' usage to properly bypass the open/read.
This commit is contained in:
Solomon Peachy 2013-07-19 10:13:35 -04:00
parent 4598c5cd6b
commit a7a75cb7c9
2 changed files with 21 additions and 11 deletions

View File

@ -27,7 +27,7 @@
#include "backend_common.h"
#define BACKEND_VERSION "0.12"
#define BACKEND_VERSION "0.13"
#ifndef URI_PREFIX
#define URI_PREFIX "gutenprint+usb"
#endif
@ -443,19 +443,19 @@ int main (int argc, char **argv)
exit(1);
}
if (backend->cmdline_arg && backend->cmdline_arg(NULL, 0, argv[1], argv[2])) {
query_only = 1;
}
srand(getpid());
jobid = rand();
/* Open Input File */
if (strcmp("-", argv[1])) {
data_fd = open(argv[1], O_RDONLY);
if (data_fd < 0) {
perror("ERROR:Can't open input file");
exit(1);
if (backend->cmdline_arg && backend->cmdline_arg(NULL, 0, argv[1], argv[2])) {
query_only = 1;
} else {
/* Open Input File */
if (strcmp("-", argv[1])) {
data_fd = open(argv[1], O_RDONLY);
if (data_fd < 0) {
perror("ERROR:Can't open input file");
exit(1);
}
}
}
}
@ -467,6 +467,15 @@ int main (int argc, char **argv)
/* Initialize backend */
backend_ctx = backend->init();
/* Parse printjob if necessary */
if (!query_only && backend->early_parse) {
printer_type = backend->early_parse(ctx, data_fd);
if (printer_type < 0) {
ret = 4;
goto done;
}
}
/* Libusb setup */
libusb_init(&ctx);
found = find_and_enumerate(ctx, &list, use_serno, printer_type, -1, 0);

View File

@ -112,6 +112,7 @@ struct dyesub_backend {
uint8_t endp_up, uint8_t endp_down, uint8_t jobid);
void (*teardown)(void *ctx);
int (*cmdline_arg)(void *ctx, int run, char *arg1, char *arg2);
int (*early_parse)(void *ctx, int data_fd);
int (*read_parse)(void *ctx, int data_fd);
int (*main_loop)(void *ctx, int copies);