]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/parallel.c
2 * "$Id: parallel.c 6068 2006-10-27 17:10:34Z mike $"
4 * Parallel port backend for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * main() - Send a file to the specified parallel port.
29 * list_devices() - List all parallel devices.
33 * Include necessary headers.
36 #include "backend-private.h"
39 # include <sys/time.h>
41 # include <sys/select.h>
50 # include <sys/socket.h>
55 # ifndef INV_EPP_ECP_PLP
56 # define INV_EPP_ECP_PLP 6 /* From 6.3/6.4/6.5 sys/invent.h */
57 # define INV_ASO_SERIAL 14 /* serial portion of SGI ASO board */
58 # define INV_IOC3_DMA 16 /* DMA mode IOC3 serial */
59 # define INV_IOC3_PIO 17 /* PIO mode IOC3 serial */
60 # define INV_ISA_DMA 19 /* DMA mode ISA serial -- O2 */
61 # endif /* !INV_EPP_ECP_PLP */
69 void list_devices(void);
73 * 'main()' - Send a file to the specified parallel port.
77 * printer-uri job-id user title copies options [file]
80 int /* O - Exit status */
81 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
82 char *argv
[]) /* I - Command-line arguments */
84 char method
[255], /* Method in URI */
85 hostname
[1024], /* Hostname */
86 username
[255], /* Username info (not used) */
87 resource
[1024], /* Resource info (device and options) */
88 *options
; /* Pointer to options */
89 int port
; /* Port number (not used) */
90 int print_fd
, /* Print file */
91 device_fd
, /* Parallel device */
92 use_bc
; /* Read back-channel data? */
93 int copies
; /* Number of copies to print */
94 size_t tbytes
; /* Total number of bytes written */
95 struct termios opts
; /* Parallel port options */
96 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
97 struct sigaction action
; /* Actions for POSIX signals */
98 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
102 * Make sure status messages are not buffered...
105 setbuf(stderr
, NULL
);
108 * Ignore SIGPIPE signals...
112 sigset(SIGPIPE
, SIG_IGN
);
113 #elif defined(HAVE_SIGACTION)
114 memset(&action
, 0, sizeof(action
));
115 action
.sa_handler
= SIG_IGN
;
116 sigaction(SIGPIPE
, &action
, NULL
);
118 signal(SIGPIPE
, SIG_IGN
);
119 #endif /* HAVE_SIGSET */
122 * Check command-line...
128 return (CUPS_BACKEND_OK
);
130 else if (argc
< 6 || argc
> 7)
132 fputs("Usage: parallel job-id user title copies options [file]\n", stderr
);
133 return (CUPS_BACKEND_FAILED
);
137 * If we have 7 arguments, print the file named on the command-line.
138 * Otherwise, send stdin instead...
149 * Try to open the print file...
152 if ((print_fd
= open(argv
[6], O_RDONLY
)) < 0)
154 perror("ERROR: unable to open print file");
155 return (CUPS_BACKEND_FAILED
);
158 copies
= atoi(argv
[4]);
162 * Extract the device name and options from the URI...
165 httpSeparateURI(HTTP_URI_CODING_ALL
, cupsBackendDeviceURI(argv
),
166 method
, sizeof(method
), username
, sizeof(username
),
167 hostname
, sizeof(hostname
), &port
,
168 resource
, sizeof(resource
));
171 * See if there are any options...
174 if ((options
= strchr(resource
, '?')) != NULL
)
177 * Yup, terminate the device name string and move to the first
178 * character of the options...
185 * Open the parallel port device...
188 fputs("STATE: +connecting-to-device\n", stderr
);
194 * The Linux parallel port driver currently is broken WRT select()
195 * and bidirection I/O...
198 device_fd
= open(resource
, O_WRONLY
| O_EXCL
);
202 if ((device_fd
= open(resource
, O_RDWR
| O_EXCL
)) < 0)
204 device_fd
= open(resource
, O_WRONLY
| O_EXCL
);
213 if (getenv("CLASS") != NULL
)
216 * If the CLASS environment variable is set, the job was submitted
217 * to a class and not to a specific queue. In this case, we want
218 * to abort immediately so that the job can be requeued on the next
219 * available printer in the class.
222 fputs("INFO: Unable to open parallel port, queuing on next printer "
223 "in class...\n", stderr
);
226 * Sleep 5 seconds to keep the job from requeuing too rapidly...
231 return (CUPS_BACKEND_FAILED
);
236 fputs("INFO: Parallel port busy; will retry in 30 seconds...\n",
240 else if (errno
== ENXIO
|| errno
== EIO
|| errno
== ENOENT
)
242 fputs("INFO: Printer not connected; will retry in 30 seconds...\n",
249 "ERROR: Unable to open parallel port device file \"%s\": %s\n",
250 resource
, strerror(errno
));
251 return (CUPS_BACKEND_FAILED
);
255 while (device_fd
< 0);
257 fputs("STATE: -connecting-to-device\n", stderr
);
260 * Set any options provided...
263 tcgetattr(device_fd
, &opts
);
265 opts
.c_lflag
&= ~(ICANON
| ECHO
| ISIG
); /* Raw mode */
267 /**** No options supported yet ****/
269 tcsetattr(device_fd
, TCSANOW
, &opts
);
272 * Finally, send the print file...
277 while (copies
> 0 && tbytes
>= 0)
283 fputs("PAGE: 1 1\n", stderr
);
284 lseek(print_fd
, 0, SEEK_SET
);
287 tbytes
= backendRunLoop(print_fd
, device_fd
, use_bc
);
289 if (print_fd
!= 0 && tbytes
>= 0)
290 fprintf(stderr
, "INFO: Sent print file, " CUPS_LLFMT
" bytes...\n",
295 * Close the socket connection and input file and return...
303 return (tbytes
< 0 ? CUPS_BACKEND_FAILED
: CUPS_BACKEND_OK
);
308 * 'list_devices()' - List all parallel devices.
314 #if defined(__hpux) || defined(__sgi) || defined(__sun)
315 static char *funky_hex
= "0123456789abcdefghijklmnopqrstuvwxyz";
316 /* Funky hex numbering used for some devices */
317 #endif /* __hpux || __sgi || __sun */
320 int i
; /* Looping var */
321 int fd
; /* File descriptor */
322 char device
[255], /* Device filename */
323 basedevice
[255], /* Base device filename for ports */
324 device_id
[1024], /* Device ID string */
325 make_model
[1024]; /* Make and model */
328 if (!access("/dev/parallel/", 0))
329 strcpy(basedevice
, "/dev/parallel/");
330 else if (!access("/dev/printers/", 0))
331 strcpy(basedevice
, "/dev/printers/");
333 strcpy(basedevice
, "/dev/lp");
335 for (i
= 0; i
< 4; i
++)
338 * Open the port, if available...
341 sprintf(device
, "%s%d", basedevice
, i
);
342 if ((fd
= open(device
, O_RDWR
| O_EXCL
)) < 0)
343 fd
= open(device
, O_WRONLY
);
348 * Now grab the IEEE 1284 device ID string...
351 if (!backendGetDeviceID(fd
, device_id
, sizeof(device_id
),
352 make_model
, sizeof(make_model
),
354 printf("direct parallel:%s \"%s\" \"%s LPT #%d\" \"%s\"\n", device
,
355 make_model
, make_model
, i
+ 1, device_id
);
357 printf("direct parallel:%s \"Unknown\" \"LPT #%d\"\n", device
, i
+ 1);
363 int i
, j
, n
; /* Looping vars */
364 char device
[255]; /* Device filename */
365 inventory_t
*inv
; /* Hardware inventory info */
369 * IRIX maintains a hardware inventory of most devices...
374 while ((inv
= getinvent()) != NULL
)
376 if (inv
->inv_class
== INV_PARALLEL
&&
377 (inv
->inv_type
== INV_ONBOARD_PLP
||
378 inv
->inv_type
== INV_EPP_ECP_PLP
))
381 * Standard parallel port...
384 puts("direct parallel:/dev/plp \"Unknown\" \"Onboard Parallel Port\"");
386 else if (inv
->inv_class
== INV_PARALLEL
&&
387 inv
->inv_type
== INV_EPC_PLP
)
390 * EPC parallel port...
393 printf("direct parallel:/dev/plp%d \"Unknown\" \"Integral EPC parallel port, Ebus slot %d\"\n",
394 inv
->inv_controller
, inv
->inv_controller
);
401 * Central Data makes serial and parallel "servers" that can be
402 * connected in a number of ways. Look for ports...
405 for (i
= 0; i
< 10; i
++)
406 for (j
= 0; j
< 8; j
++)
407 for (n
= 0; n
< 32; n
++)
409 if (i
== 8) /* EtherLite */
410 sprintf(device
, "/dev/lpn%d%c", j
, funky_hex
[n
]);
411 else if (i
== 9) /* PCI */
412 sprintf(device
, "/dev/lpp%d%c", j
, funky_hex
[n
]);
414 sprintf(device
, "/dev/lp%d%d%c", i
, j
, funky_hex
[n
]);
416 if (access(device
, 0) == 0)
419 printf("direct parallel:%s \"Unknown\" \"Central Data EtherLite Parallel Port, ID %d, port %d\"\n",
422 printf("direct parallel:%s \"Unknown\" \"Central Data PCI Parallel Port, ID %d, port %d\"\n",
425 printf("direct parallel:%s \"Unknown\" \"Central Data SCSI Parallel Port, logical bus %d, ID %d, port %d\"\n",
430 int i
, j
, n
; /* Looping vars */
431 char device
[255]; /* Device filename */
435 * Standard parallel ports...
438 for (i
= 0; i
< 10; i
++)
440 sprintf(device
, "/dev/ecpp%d", i
);
441 if (access(device
, 0) == 0)
442 printf("direct parallel:%s \"Unknown\" \"Sun IEEE-1284 Parallel Port #%d\"\n",
446 for (i
= 0; i
< 10; i
++)
448 sprintf(device
, "/dev/bpp%d", i
);
449 if (access(device
, 0) == 0)
450 printf("direct parallel:%s \"Unknown\" \"Sun Standard Parallel Port #%d\"\n",
454 for (i
= 0; i
< 3; i
++)
456 sprintf(device
, "/dev/lp%d", i
);
458 if (access(device
, 0) == 0)
459 printf("direct parallel:%s \"Unknown\" \"PC Parallel Port #%d\"\n",
464 * MAGMA parallel ports...
467 for (i
= 0; i
< 40; i
++)
469 sprintf(device
, "/dev/pm%02d", i
);
470 if (access(device
, 0) == 0)
471 printf("direct parallel:%s \"Unknown\" \"MAGMA Parallel Board #%d Port #%d\"\n",
472 device
, (i
/ 10) + 1, (i
% 10) + 1);
476 * Central Data parallel ports...
479 for (i
= 0; i
< 9; i
++)
480 for (j
= 0; j
< 8; j
++)
481 for (n
= 0; n
< 32; n
++)
483 if (i
== 8) /* EtherLite */
484 sprintf(device
, "/dev/sts/lpN%d%c", j
, funky_hex
[n
]);
486 sprintf(device
, "/dev/sts/lp%c%d%c", i
+ 'C', j
,
489 if (access(device
, 0) == 0)
492 printf("direct parallel:%s \"Unknown\" \"Central Data EtherLite Parallel Port, ID %d, port %d\"\n",
495 printf("direct parallel:%s \"Unknown\" \"Central Data SCSI Parallel Port, logical bus %d, ID %d, port %d\"\n",
499 #elif defined(__hpux)
500 int i
, j
, n
; /* Looping vars */
501 char device
[255]; /* Device filename */
505 * Standard parallel ports...
508 if (access("/dev/rlp", 0) == 0)
509 puts("direct parallel:/dev/rlp \"Unknown\" \"Standard Parallel Port (/dev/rlp)\"");
511 for (i
= 0; i
< 7; i
++)
512 for (j
= 0; j
< 7; j
++)
514 sprintf(device
, "/dev/c%dt%dd0_lp", i
, j
);
515 if (access(device
, 0) == 0)
516 printf("direct parallel:%s \"Unknown\" \"Parallel Port #%d,%d\"\n",
521 * Central Data parallel ports...
524 for (i
= 0; i
< 9; i
++)
525 for (j
= 0; j
< 8; j
++)
526 for (n
= 0; n
< 32; n
++)
528 if (i
== 8) /* EtherLite */
529 sprintf(device
, "/dev/lpN%d%c", j
, funky_hex
[n
]);
531 sprintf(device
, "/dev/lp%c%d%c", i
+ 'C', j
,
534 if (access(device
, 0) == 0)
537 printf("direct parallel:%s \"Unknown\" \"Central Data EtherLite Parallel Port, ID %d, port %d\"\n",
540 printf("direct parallel:%s \"Unknown\" \"Central Data SCSI Parallel Port, logical bus %d, ID %d, port %d\"\n",
544 #elif defined(__osf__)
545 int i
; /* Looping var */
546 int fd
; /* File descriptor */
547 char device
[255]; /* Device filename */
550 for (i
= 0; i
< 3; i
++)
552 sprintf(device
, "/dev/lp%d", i
);
553 if ((fd
= open(device
, O_WRONLY
)) >= 0)
556 printf("direct parallel:%s \"Unknown\" \"Parallel Port #%d\"\n", device
, i
+ 1);
559 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
560 int i
; /* Looping var */
561 int fd
; /* File descriptor */
562 char device
[255]; /* Device filename */
565 for (i
= 0; i
< 3; i
++)
567 sprintf(device
, "/dev/lpt%d", i
);
568 if ((fd
= open(device
, O_WRONLY
)) >= 0)
571 printf("direct parallel:%s \"Unknown\" \"Parallel Port #%d (interrupt-driven)\"\n", device
, i
+ 1);
574 sprintf(device
, "/dev/lpa%d", i
);
575 if ((fd
= open(device
, O_WRONLY
)) >= 0)
578 printf("direct parallel:%s \"Unknown\" \"Parallel Port #%d (polled)\"\n", device
, i
+ 1);
582 int i
; /* Looping var */
583 int fd
; /* File descriptor */
584 char device
[255]; /* Device filename */
587 for (i
= 0; i
< 8; i
++)
589 sprintf(device
, "/dev/lp%d", i
);
590 if ((fd
= open(device
, O_WRONLY
)) >= 0)
593 printf("direct parallel:%s \"Unknown\" \"Parallel Port #%d\"\n", device
, i
+ 1);
601 * End of "$Id: parallel.c 6068 2006-10-27 17:10:34Z mike $".