]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/parallel.c
2 * "$Id: parallel.c,v 1.9 2000/01/25 03:50:47 mike Exp $"
4 * Parallel port backend for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2000 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-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Send a file to the specified parallel port.
27 * list_devices() - List all parallel devices.
31 * Include necessary headers.
34 #include <cups/cups.h>
37 #include <cups/string.h>
39 #if defined(WIN32) || defined(__EMX__)
45 #endif /* WIN32 || __EMX__ */
52 void list_devices(void);
56 * 'main()' - Send a file to the specified parallel port.
60 * printer-uri job-id user title copies options [file]
63 int /* O - Exit status */
64 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
65 char *argv
[]) /* I - Command-line arguments */
67 char method
[255], /* Method in URI */
68 hostname
[1024], /* Hostname */
69 username
[255], /* Username info (not used) */
70 resource
[1024], /* Resource info (device and options) */
71 *options
; /* Pointer to options */
72 int port
; /* Port number (not used) */
73 FILE *fp
; /* Print file */
74 int copies
; /* Number of copies to print */
75 int fd
; /* Parallel device */
76 int error
; /* Error code (if any) */
77 size_t nbytes
, /* Number of bytes written */
78 tbytes
; /* Total number of bytes written */
79 char buffer
[8192]; /* Output buffer */
80 struct termios opts
; /* Parallel port options */
88 else if (argc
< 6 || argc
> 7)
90 fputs("Usage: parallel job-id user title copies options [file]\n", stderr
);
95 * If we have 7 arguments, print the file named on the command-line.
96 * Otherwise, send stdin instead...
107 * Try to open the print file...
110 if ((fp
= fopen(argv
[6], "rb")) == NULL
)
112 perror("ERROR: unable to open print file");
116 copies
= atoi(argv
[4]);
120 * Extract the device name and options from the URI...
123 httpSeparate(argv
[0], method
, username
, hostname
, &port
, resource
);
126 * See if there are any options...
129 if ((options
= strchr(resource
, '?')) != NULL
)
132 * Yup, terminate the device name string and move to the first
133 * character of the options...
140 * Open the parallel port device...
143 if ((fd
= open(resource
, O_WRONLY
)) == -1)
145 perror("ERROR: Unable to open parallel port device file");
150 * Set any options provided...
153 tcgetattr(fd
, &opts
);
155 opts
.c_lflag
&= ~(ICANON
| ECHO
| ISIG
); /* Raw mode */
157 /**** No options supported yet ****/
159 tcsetattr(fd
, TCSANOW
, &opts
);
162 * Finally, send the print file...
171 fputs("PAGE: 1 1\n", stderr
);
176 while ((nbytes
= fread(buffer
, 1, sizeof(buffer
), fp
)) > 0)
179 * Write the print data to the printer...
182 if (write(fd
, buffer
, nbytes
) < nbytes
)
184 perror("ERROR: Unable to send print file to printer");
191 fprintf(stderr
, "INFO: Sending print file, %u bytes...\n", tbytes
);
196 * Close the socket connection and input file and return...
208 * 'list_devices()' - List all parallel devices.
215 int i
; /* Looping var */
216 char device
[255]; /* Device filename */
219 for (i
= 0; i
< 4; i
++)
221 sprintf(device
, "/dev/lp%d", i
);
222 if (access(device
, F_OK
) == 0)
223 fprintf(stderr
, "parallel parallel:/dev/lp%d \"\" \"Parallel Port #%d\"\n",
228 #elif defined(__hpux)
230 #elif defined(FreeBSD) || defined(OpenBSD) || defined(NetBSD)
236 * End of "$Id: parallel.c,v 1.9 2000/01/25 03:50:47 mike Exp $".