all: Fix command like parsing when the argument has an option.

This was a longstanding bug.  Oops.
master
Solomon Peachy 8 years ago
parent 14af6acbb9
commit 992e551a02

@ -450,7 +450,8 @@
-N [ A | B | M ] Reset Counter A/B/M [2]
-p num Set 'P' counter to 'num'
-s Query printer status
-S num Specify standby delay (1-99 minutes, 0 disables) [1]
-k num Specify standby delay (1-99 minutes, 0 disables) [1]
-K num Keep Media Status Across Power Cycles (1 yes, 0 no) [1]
Notes:

@ -847,7 +847,7 @@ static int cw01_cmdline_arg(void *vctx, int argc, char **argv)
j = cw01_clear_counter(ctx, optarg[0]);
break;
}
return 1;
return 2;
case 's':
if (ctx) {
j = cw01_get_status(ctx);

@ -27,7 +27,7 @@
#include "backend_common.h"
#define BACKEND_VERSION "0.54"
#define BACKEND_VERSION "0.55"
#ifndef URI_PREFIX
#error "Must Define URI_PREFIX"
#endif
@ -799,7 +799,14 @@ int main (int argc, char **argv)
/* Check to see if it is claimed by the backend */
if (backend && backend->cmdline_arg) {
int keep = optind;
backend_cmd += backend->cmdline_arg(NULL, argc, argv);
int boo;
boo = backend->cmdline_arg(NULL, argc, argv);
backend_cmd += boo;
if (boo > 1)
keep++;
optind = keep;
}
break;

@ -1507,6 +1507,23 @@ static int dnpds620_standby_mode(struct dnpds40_ctx *ctx, int delay)
return 0;
}
static int dnpds620_media_keep_mode(struct dnpds40_ctx *ctx, int delay)
{
struct dnpds40_cmd cmd;
char msg[9];
int ret;
/* Generate command */
dnpds40_build_cmd(&cmd, "MNT_WT", "END_KEEP_MODE", 4);
snprintf(msg, sizeof(msg), "%02d\r", delay);
if ((ret = dnpds40_do_cmd(ctx, &cmd, (uint8_t*)msg, 4)))
return ret;
return 0;
}
static int dnpds40_set_counter_p(struct dnpds40_ctx *ctx, char *arg)
{
struct dnpds40_cmd cmd;
@ -1531,8 +1548,8 @@ static void dnpds40_cmdline(void)
DEBUG("\t\t[ -n ] # Query counters\n");
DEBUG("\t\t[ -N A|B|M ] # Clear counter A/B/M\n");
DEBUG("\t\t[ -p num ] # Set counter P\n");
DEBUG("\t\t[ -S num ] # Set standby time (1-99 minutes, 0 disables)\n");
DEBUG("\t\t[ -S num ] # Set standby time (1-99 minutes, 0 disables)\n");
DEBUG("\t\t[ -K num ] # Keep Media Status Across Power Cycles (1 on, 0 off)\n");
}
static int dnpds40_cmdline_arg(void *vctx, int argc, char **argv)
@ -1543,7 +1560,7 @@ static int dnpds40_cmdline_arg(void *vctx, int argc, char **argv)
/* Reset arg parsing */
optind = 1;
opterr = 0;
while ((i = getopt(argc, argv, "iInN:p:sS:")) >= 0) {
while ((i = getopt(argc, argv, "iInN:p:sK:k:")) >= 0) {
switch(i) {
case 'i':
if (ctx) {
@ -1556,6 +1573,7 @@ static int dnpds40_cmdline_arg(void *vctx, int argc, char **argv)
j = dnpds40_get_sensors(ctx);
break;
}
return 1;
case 'n':
if (ctx) {
j = dnpds40_get_counters(ctx);
@ -1575,20 +1593,20 @@ static int dnpds40_cmdline_arg(void *vctx, int argc, char **argv)
j = dnpds40_clear_counter(ctx, optarg[0]);
break;
}
return 1;
return 2;
case 'p':
if (ctx) {
j = dnpds40_set_counter_p(ctx, optarg);
break;
}
return 1;
return 2;
case 's':
if (ctx) {
j = dnpds40_get_status(ctx);
break;
}
return 1;
case 'S':
case 'k':
if (ctx) {
int time = atoi(optarg);
if (!ctx->supports_standby) {
@ -1603,6 +1621,23 @@ static int dnpds40_cmdline_arg(void *vctx, int argc, char **argv)
}
j = dnpds620_standby_mode(ctx, time);
}
return 2;
case 'K':
if (ctx) {
int keep = atoi(optarg);
if (!ctx->supports_standby) {
ERROR("Printer does not support media keep mode\n");
j = -1;
break;
}
if (keep < 0 || keep > 1) {
ERROR("Value out of range (0-1)");
j = -1;
break;
}
j = dnpds620_media_keep_mode(ctx, keep);
}
return 2;
default:
break; /* Ignore completely */
}

@ -268,7 +268,7 @@ int kodak1400_cmdline_arg(void *vctx, int argc, char **argv)
j = kodak1400_set_tonecurve(ctx, optarg);
break;
}
return 1;
return 2;
default:
break; /* Ignore completely */
}

@ -517,7 +517,7 @@ static int kodak605_cmdline_arg(void *vctx, int argc, char **argv)
j = kodak605_set_tonecurve(ctx, optarg);
break;
}
return 1;
return 2;
case 'm':
if (ctx) {
j = kodak605_get_media(ctx);

@ -592,13 +592,13 @@ static int kodak6800_cmdline_arg(void *vctx, int argc, char **argv)
j = kodak6800_get_tonecurve(ctx, optarg);
break;
}
return 1;
return 2;
case 'C':
if (ctx) {
j = kodak6800_set_tonecurve(ctx, optarg);
break;
}
return 1;
return 2;
case 'm':
if (ctx) {
uint8_t mediabuf[MAX_MEDIA_LEN];

@ -1148,75 +1148,83 @@ int shinkos1245_cmdline_arg(void *vctx, int argc, char **argv)
while ((i = getopt(argc, argv, "c:C:l:L:FfmsuU:X:")) >= 0) {
switch(i) {
case 'F':
if (!ctx)
return 1;
ctx->tonecurve = PARAM_TABLE_FINE;
break;
if (ctx) {
ctx->tonecurve = PARAM_TABLE_FINE;
break;
}
return 1;
case 'c':
if (!ctx)
return 1;
j = get_tonecurve(ctx, TONE_TABLE_USER, ctx->tonecurve, optarg);
break;
if (ctx) {
j = get_tonecurve(ctx, TONE_TABLE_USER, ctx->tonecurve, optarg);
break;
}
return 2;
case 'C':
if (!ctx)
return 1;
j = set_tonecurve(ctx, TONE_TABLE_USER, ctx->tonecurve, optarg);
break;
if (ctx) {
j = set_tonecurve(ctx, TONE_TABLE_USER, ctx->tonecurve, optarg);
break;
}
return 2;
case 'l':
if (!ctx)
return 1;
j = get_tonecurve(ctx, TONE_TABLE_CURRENT, ctx->tonecurve, optarg);
break;
if (ctx) {
j = get_tonecurve(ctx, TONE_TABLE_CURRENT, ctx->tonecurve, optarg);
break;
}
return 2;
case 'L':
if (!ctx)
return 1;
j = set_tonecurve(ctx, TONE_TABLE_CURRENT, ctx->tonecurve, optarg);
break;
if (ctx) {
j = set_tonecurve(ctx, TONE_TABLE_CURRENT, ctx->tonecurve, optarg);
break;
}
return 2;
case 'f':
if (!ctx)
return 1;
ctx->fast_return = 1;
break;
if (!ctx) {
ctx->fast_return = 1;
break;
}
return 1;
case 'm':
if (!ctx)
return 1;
j = shinkos1245_get_media(ctx);
if (!j)
shinkos1245_dump_media(ctx->medias, ctx->num_medias);
break;
case 's': {
if (!ctx)
return 1;
struct shinkos1245_resp_status sts;
j = shinkos1245_get_status(ctx, &sts);
if (!j)
shinkos1245_dump_status(&sts);
break;
}
case 'u': {
if (!ctx)
return 1;
struct shinkos1245_resp_getid resp;
j = shinkos1245_get_printerid(ctx, &resp);
if (!j) {
char buffer[sizeof(resp.data)+1];
memcpy(buffer, resp.data, sizeof(resp.data));
buffer[sizeof(resp.data)] = 0;
INFO("Printer ID: %02x '%s'\n", resp.id, buffer);
if (ctx) {
j = shinkos1245_get_media(ctx);
if (!j)
shinkos1245_dump_media(ctx->medias, ctx->num_medias);
break;
}
break;
}
return 1;
case 's':
if (ctx) {
struct shinkos1245_resp_status sts;
j = shinkos1245_get_status(ctx, &sts);
if (!j)
shinkos1245_dump_status(&sts);
break;
}
return 1;
case 'u':
if (ctx) {
struct shinkos1245_resp_getid resp;
j = shinkos1245_get_printerid(ctx, &resp);
if (!j) {
char buffer[sizeof(resp.data)+1];
memcpy(buffer, resp.data, sizeof(resp.data));
buffer[sizeof(resp.data)] = 0;
INFO("Printer ID: %02x '%s'\n", resp.id, buffer);
break;
}
}
return 1;
case 'U':
if (!ctx)
return 1;
j = shinkos1245_set_printerid(ctx, optarg);
break;
if (ctx) {
j = shinkos1245_set_printerid(ctx, optarg);
break;
}
return 1;
case 'X':
if (!ctx)
return 1;
j = shinkos1245_canceljob(ctx, atoi(optarg));
break;
if (ctx) {
j = shinkos1245_canceljob(ctx, atoi(optarg));
break;
}
return 1;
default:
break; /* Ignore completely */
}
@ -1607,7 +1615,7 @@ static int shinkos1245_query_serno(struct libusb_device_handle *dev, uint8_t end
struct dyesub_backend shinkos1245_backend = {
.name = "Shinko/Sinfonia CHC-S1245",
.version = "0.02WIP",
.version = "0.03WIP",
.uri_prefix = "shinkos1245",
.cmdline_usage = shinkos1245_cmdline,
.cmdline_arg = shinkos1245_cmdline_arg,

@ -1306,19 +1306,19 @@ int shinkos2145_cmdline_arg(void *vctx, int argc, char **argv)
return -1;
break;
}
return 1;
return 2;
case 'c':
if (ctx) {
j = get_tonecurve(ctx, TONECURVE_USER, optarg);
break;
}
return 1;
return 2;
case 'C':
if (ctx) {
j = set_tonecurve(ctx, TONECURVE_USER, optarg);
break;
}
return 1;
return 2;
case 'e':
if (ctx) {
j = get_errorlog(ctx);
@ -1348,13 +1348,13 @@ int shinkos2145_cmdline_arg(void *vctx, int argc, char **argv)
j = get_tonecurve(ctx, TONECURVE_CURRENT, optarg);
break;
}
return 1;
return 2;
case 'L':
if (ctx) {
j = set_tonecurve(ctx, TONECURVE_CURRENT, optarg);
break;
}
return 1;
return 2;
case 'm':
if (ctx) {
j = get_mediainfo(ctx);
@ -1390,13 +1390,13 @@ int shinkos2145_cmdline_arg(void *vctx, int argc, char **argv)
j = set_user_string(ctx, optarg);
break;
}
return 1;
return 2;
case 'X':
if (ctx) {
j = cancel_job(ctx, optarg);
break;
}
return 1;
return 2;
default:
break; /* Ignore completely */
}

Loading…
Cancel
Save