diff --git a/backend_common.c b/backend_common.c index 8ca02ac..f03100c 100644 --- a/backend_common.c +++ b/backend_common.c @@ -119,20 +119,54 @@ static int send_data(struct libusb_device_handle *dev, uint8_t endp, { int num; - int ret = libusb_bulk_transfer(dev, endp, - buf, len, - &num, 10000); - - if (ret < 0 || len != num) { - ERROR("Failure to send data to printer (libusb error %d: (%d/%d to 0x%02x))\n", ret, num, len, endp); - return ret; + while (len) { + int ret = libusb_bulk_transfer(dev, endp, + buf, len, + &num, 10000); + if (ret < 0) { + ERROR("Failure to send data to printer (libusb error %d: (%d/%d to 0x%02x))\n", ret, num, len, endp); + return ret; + } + len -= num; + buf += num; } + return 0; } static int terminate = 0; -void sigterm_handler(int signum) { +static void sigterm_handler(int signum) { terminate = 1; INFO("Job Cancelled"); } + +static void print_scan_output(struct libusb_device_handle *dev, + unsigned char *product, unsigned char *serial, + char *manuf, char *prefix) +{ + /* URL-ify model. */ + char buf[128]; // XXX ugly.. + int j = 0, k = 0; + char *ieee_id; + while (*(product + j + strlen(manuf))) { + buf[k] = *(product + j + strlen(manuf) + 1); + if(buf[k] == ' ') { + buf[k++] = '%'; + buf[k++] = '2'; + buf[k] = '0'; + } + k++; + j++; + } + ieee_id = get_device_id(dev); + + fprintf(stdout, "direct %s%s/%s?serial=%s \"%s\" \"%s\" \"%s\" \"\"\n", + prefix, manuf, + buf, serial, product, product, + ieee_id); + + if (ieee_id) + free(ieee_id); + +} diff --git a/kodak1400_print.c b/kodak1400_print.c index d11371a..c16dc0e 100644 --- a/kodak1400_print.c +++ b/kodak1400_print.c @@ -140,28 +140,8 @@ static int find_and_enumerate(struct libusb_context *ctx, desc.idProduct, product, serial); if (scan_only) { - /* URL-ify model. */ - char buf[128]; // XXX ugly.. - int j = 0, k = 0; - char *ieee_id; - while (*(product + j + strlen("Kodak"))) { - buf[k] = *(product + j + strlen("Kodak ")); - if(buf[k] == ' ') { - buf[k++] = '%'; - buf[k++] = '2'; - buf[k] = '0'; - } - k++; - j++; - } - ieee_id = get_device_id(dev); - - fprintf(stdout, "direct %sKodak/%s?serial=%s \"%s\" \"%s\" \"%s\" \"\"\n", URI_PREFIX, - buf, serial, product, product, - ieee_id); - - if (ieee_id) - free(ieee_id); + print_scan_output(dev, product, serial, + "Kodak", URI_PREFIX); } /* If a serial number was passed down, use it. */ diff --git a/kodak6800_print.c b/kodak6800_print.c index e59d8c7..e9fd026 100644 --- a/kodak6800_print.c +++ b/kodak6800_print.c @@ -122,28 +122,8 @@ static int find_and_enumerate(struct libusb_context *ctx, desc.idProduct, product, serial); if (scan_only) { - /* URL-ify model. */ - char buf[128]; // XXX ugly.. - int j = 0, k = 0; - char *ieee_id; - while (*(product + j + strlen("Kodak"))) { - buf[k] = *(product + j + strlen("Kodak ")); - if(buf[k] == ' ') { - buf[k++] = '%'; - buf[k++] = '2'; - buf[k] = '0'; - } - k++; - j++; - } - ieee_id = get_device_id(dev); - - fprintf(stdout, "direct %sKodak/%s?serial=%s \"%s\" \"%s\" \"%s\" \"\"\n", URI_PREFIX, - buf, serial, product, product, - ieee_id); - - if (ieee_id) - free(ieee_id); + print_scan_output(dev, product, serial, + "Kodak", URI_PREFIX); } /* If a serial number was passed down, use it. */ diff --git a/selphy_print.c b/selphy_print.c index 4bbe61f..861e922 100644 --- a/selphy_print.c +++ b/selphy_print.c @@ -475,28 +475,8 @@ static int find_and_enumerate(struct libusb_context *ctx, desc.idProduct, product, serial); if (valid && scan_only) { - /* URL-ify model. */ - char buf[128]; // XXX ugly.. - int j = 0, k = 0; - char *ieee_id; - while (*(product + j + strlen("Canon"))) { - buf[k] = *(product + j + strlen("Canon ")); - if(buf[k] == ' ') { - buf[k++] = '%'; - buf[k++] = '2'; - buf[k] = '0'; - } - k++; - j++; - } - ieee_id = get_device_id(dev); - - fprintf(stdout, "direct %sCanon/%s?serial=%s \"%s\" \"%s\" \"%s\" \"\"\n", URI_PREFIX, - buf, serial, product, product, - ieee_id); - - if (ieee_id) - free(ieee_id); + print_scan_output(dev, product, serial, + "Canon", URI_PREFIX); } /* If a serial number was passed down, use it. */