dnpds40: Properly trim trailing spaces on strings that come from the printer.

This commit is contained in:
Solomon Peachy 2014-02-11 20:49:08 -05:00
parent 12358843c7
commit a7eff10ed6
1 changed files with 11 additions and 4 deletions

View File

@ -103,10 +103,17 @@ static void dnpds40_cleanup_string(char *start, int len)
{ {
char *ptr = strchr(start, 0x0d); char *ptr = strchr(start, 0x0d);
if (ptr && (ptr - start < len)) if (ptr && (ptr - start < len)) {
*ptr = 0x00; /* If there is a <CR>, terminate there */ *ptr = 0x00; /* If there is a <CR>, terminate there */
else len = ptr - start;
*(start + len - 1) = 0x00; /* force null-termination */ } else {
start[--len] = 0x00; /* force null-termination */
}
/* Trim trailing spaces */
while (len && start[len-1] == ' ') {
start[--len] = 0;
}
} }
static char *dnpds40_media_types(char *str) static char *dnpds40_media_types(char *str)
@ -980,7 +987,7 @@ static int dnpds40_cmdline_arg(void *vctx, int argc, char **argv)
/* Exported */ /* Exported */
struct dyesub_backend dnpds40_backend = { struct dyesub_backend dnpds40_backend = {
.name = "DNP DS40/DS80/DSRX1", .name = "DNP DS40/DS80/DSRX1",
.version = "0.27", .version = "0.28",
.uri_prefix = "dnpds40", .uri_prefix = "dnpds40",
.cmdline_usage = dnpds40_cmdline, .cmdline_usage = dnpds40_cmdline,
.cmdline_arg = dnpds40_cmdline_arg, .cmdline_arg = dnpds40_cmdline_arg,