common: Add support for backends to support aliases.

This also renames the reported names for mitsu9550, dnpds40, and
kodak6800 to mitsu9xxx, dnp_citizen, and kodak68x0.  Backwards
compatibility is maintained!
This commit is contained in:
Solomon Peachy 2018-03-16 13:35:17 -04:00
parent 44162d76b6
commit 320c84f770
5 changed files with 51 additions and 15 deletions

View file

@ -29,7 +29,7 @@
#include "backend_common.h"
#define BACKEND_VERSION "0.76"
#define BACKEND_VERSION "0.77"
#ifndef URI_PREFIX
#error "Must Define URI_PREFIX"
#endif
@ -729,10 +729,15 @@ static struct dyesub_backend *find_backend(char *uri_prefix)
for (i = 0; ; i++) {
struct dyesub_backend *backend = backends[i];
const char **alias;
if (!backend)
return NULL;
if (!strcmp(uri_prefix, backend->uri_prefix))
return backend;
for (alias = backend->altprefixes ; alias && *alias ; alias++) {
if (!strcmp(uri_prefix, *alias))
return backend;
}
}
return NULL;
}
@ -789,18 +794,30 @@ void print_help(char *argv0, struct dyesub_backend *backend)
DEBUG(" [ -d copies ] \n");
DEBUG(" [ - | infile ] \n");
for (i = 0; ; i++) {
const char **alias;
backend = backends[i];
if (!backend)
break;
DEBUG(" BACKEND=%s\t# %s version %s\n",
backend->uri_prefix, backend->name, backend->version);
DEBUG("\t# %s version %s\n",
backend->name, backend->version);
DEBUG(" BACKEND=%s", backend->uri_prefix);
for (alias = backend->altprefixes ; alias && *alias ; alias++)
DEBUG2(" %s", *alias);
DEBUG2("\n");
if (backend->cmdline_usage)
backend->cmdline_usage();
}
} else {
const char **alias;
DEBUG("Standalone %s backend version %s\n",
backend->name, backend->version);
DEBUG("\t%s\n", backend->uri_prefix);
DEBUG("\t%s", backend->uri_prefix);
for (alias = backend->altprefixes ; alias && *alias ; alias++)
DEBUG2(" %s", *alias);
DEBUG2("\n");
DEBUG("\t[ -D ] [ -G ] [ -f ]\n");
if (backend->cmdline_usage)
backend->cmdline_usage();

View file

@ -143,9 +143,10 @@ struct device_id {
/* Backend Functions */
struct dyesub_backend {
char *name;
char *version;
char *uri_prefix;
const char *name;
const char *version;
const char *uri_prefix;
const char **altprefixes;
void (*cmdline_usage)(void); /* Optional */
void *(*init)(void);
void (*attach)(void *ctx, struct libusb_device_handle *dev,
@ -155,7 +156,7 @@ struct dyesub_backend {
int (*read_parse)(void *ctx, int data_fd);
int (*main_loop)(void *ctx, int copies);
int (*query_serno)(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len); /* Optional */
struct device_id devices[];
const struct device_id devices[];
};
/* Exported functions */

View file

@ -2548,11 +2548,17 @@ static int dnpds40_cmdline_arg(void *vctx, int argc, char **argv)
return 0;
}
static const char *dnpds40_altprefixes[] = {
"dnpds40",
NULL
};
/* Exported */
struct dyesub_backend dnpds40_backend = {
.name = "DNP DS40/DS80/DSRX1/DS620/DS820",
.version = "0.97",
.uri_prefix = "dnpds40",
.version = "0.98",
.uri_prefix = "dnp_citizen",
.altprefixes = dnpds40_altprefixes,
.cmdline_usage = dnpds40_cmdline,
.cmdline_arg = dnpds40_cmdline_arg,
.init = dnpds40_init,

View file

@ -1256,11 +1256,17 @@ static int kodak6800_main_loop(void *vctx, int copies) {
return CUPS_BACKEND_OK;
}
static const char *kodak6800_altprefixes[] = {
"kodak6800",
NULL
};
/* Exported */
struct dyesub_backend kodak6800_backend = {
.name = "Kodak 6800/6850",
.version = "0.58",
.uri_prefix = "kodak6800",
.version = "0.59",
.uri_prefix = "kodak68x0",
.altprefixes = kodak6800_altprefixes,
.cmdline_usage = kodak6800_cmdline,
.cmdline_arg = kodak6800_cmdline_arg,
.init = kodak6800_init,

View file

@ -1268,11 +1268,17 @@ static int mitsu9550_cmdline_arg(void *vctx, int argc, char **argv)
return 0;
}
static const char *mitsu9550_altprefixes[] = {
"mitsu9550",
NULL
};
/* Exported */
struct dyesub_backend mitsu9550_backend = {
.name = "Mitsubishi CP-9xxx family",
.version = "0.30",
.uri_prefix = "mitsu9550",
.name = "Mitsubishi CP9xxx family",
.version = "0.31",
.uri_prefix = "mitsu9xxx",
.altprefixes = mitsu9550_altprefixes,
.cmdline_usage = mitsu9550_cmdline,
.cmdline_arg = mitsu9550_cmdline_arg,
.init = mitsu9550_init,