cups/cups-parallel-id.patch
2007-10-10 11:24:50 +00:00

136 lines
3.6 KiB
Diff

diff -up cups-1.3.3/backend/ieee1284.c.parallel-id cups-1.3.3/backend/ieee1284.c
--- cups-1.3.3/backend/ieee1284.c.parallel-id 2007-07-11 22:46:42.000000000 +0100
+++ cups-1.3.3/backend/ieee1284.c 2007-10-10 12:15:21.000000000 +0100
@@ -32,6 +32,10 @@
# include <linux/lp.h>
# define IOCNR_GET_DEVICE_ID 1
# define LPIOC_GET_DEVICE_ID(len) _IOC(_IOC_READ, 'P', IOCNR_GET_DEVICE_ID, len)
+# include <linux/parport.h>
+# include <linux/ppdev.h>
+# include <unistd.h>
+# include <fcntl.h>
#endif /* __linux */
#ifdef __sun
@@ -68,6 +72,7 @@ backendGetDeviceID(
int manulen; /* Length of manufacturer string */
#ifdef __linux
int length; /* Length of device ID info */
+ int got_id = 0;
#endif /* __linux */
#if defined(__sun) && defined(ECPPIOC_GETDEVID)
struct ecpp_device_id did; /* Device ID buffer */
@@ -93,9 +98,6 @@ backendGetDeviceID(
if (make_model)
*make_model = '\0';
- if (uri)
- *uri = '\0';
-
if (fd >= 0)
{
/*
@@ -105,7 +107,74 @@ backendGetDeviceID(
*device_id = '\0';
#ifdef __linux
- if (!ioctl(fd, LPIOC_GET_DEVICE_ID(device_id_size), device_id))
+ if (ioctl(fd, LPIOC_GET_DEVICE_ID(device_id_size), device_id))
+ {
+# ifdef DEBUG
+ printf("backendGetDeviceID: ioctl failed - %s\n", strerror(errno));
+# endif /* DEBUG */
+
+ if (!strcmp (scheme, "parallel") &&
+ uri && !strncmp (uri, "parallel:/dev/", 14))
+ {
+ const char *n;
+ char devparport[16];
+ int devparportfd;
+ n = uri + strcspn (uri, "0123456789");
+ strcpy (devparport, "/dev/parport");
+ strncpy (devparport + 12, n, 3);
+ devparport[15] = '\0';
+ devparportfd = open (devparport, O_RDWR | O_NOCTTY);
+ if (devparportfd != -1)
+ {
+ /* Put the device into Device ID mode */
+ int err = ioctl (devparportfd, PPCLAIM);
+ int m = IEEE1284_MODE_COMPAT;
+
+ if (err)
+ {
+ close (devparportfd);
+ devparportfd = -1;
+ }
+
+ if (!err)
+ err = ioctl (devparportfd, PPNEGOT, &m);
+
+ if (!err)
+ {
+ m = IEEE1284_MODE_NIBBLE | IEEE1284_DEVICEID;
+ err = ioctl (devparportfd, PPNEGOT, &m);
+ }
+
+ /* Make the file descriptor non-blocking to guard against
+ * bugs in the device. */
+ if (!err)
+ {
+ int f = fcntl (devparportfd, F_GETFL);
+ f |= O_NONBLOCK;
+ err = fcntl (devparportfd, F_SETFL, f);
+ }
+
+ /* Read the ID */
+ if (!err)
+ {
+ if (read (devparportfd, device_id, device_id_size) < 2)
+ err = 1;
+ else
+ got_id = 1;
+ }
+
+ if (devparportfd > -1)
+ {
+ ioctl (devparportfd, PPRELEASE);
+ close (devparportfd);
+ }
+ }
+ }
+ }
+ else
+ got_id = 1;
+
+ if (got_id)
{
/*
* Extract the length of the device ID string from the first two
@@ -168,6 +237,9 @@ backendGetDeviceID(
DEBUG_printf(("backendGetDeviceID: device_id=\"%s\"\n", device_id));
+ if (uri)
+ *uri = '\0';
+
if (!*device_id)
return (-1);
diff -up cups-1.3.3/backend/parallel.c.parallel-id cups-1.3.3/backend/parallel.c
--- cups-1.3.3/backend/parallel.c.parallel-id 2007-08-22 19:34:34.000000000 +0100
+++ cups-1.3.3/backend/parallel.c 2007-10-10 12:14:23.000000000 +0100
@@ -350,9 +350,12 @@ list_devices(void)
* Now grab the IEEE 1284 device ID string...
*/
+ char device_uri[255 + 9];
+ strcpy (device_uri, "parallel:");
+ strcpy (device_uri + 9, device);
if (!backendGetDeviceID(fd, device_id, sizeof(device_id),
make_model, sizeof(make_model),
- NULL, NULL, 0))
+ "parallel", device_uri, sizeof (device_uri)))
printf("direct parallel:%s \"%s\" \"%s LPT #%d\" \"%s\"\n", device,
make_model, make_model, i + 1, device_id);
else