]> git.ipfire.org Git - thirdparty/cups.git/blame - backend/parallel.c
Finished implementation of parallel, serial, and AppSocket backends.
[thirdparty/cups.git] / backend / parallel.c
CommitLineData
43e2fc22 1/*
7c88bf41 2 * "$Id: parallel.c,v 1.4 1999/04/16 20:43:53 mike Exp $"
43e2fc22 3 *
e73c6c0a 4 * Parallel port backend for the Common UNIX Printing System (CUPS).
43e2fc22 5 *
3a193f5e 6 * Copyright 1997-1999 by Easy Software Products, all rights reserved.
43e2fc22 7 *
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
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44145 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
43e2fc22 26 */
27
28/*
29 * Include necessary headers.
30 */
31
e73c6c0a 32#include <cups/cups.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <cups/string.h>
36
7c88bf41 37#if defined(WIN32) || defined(__EMX__)
38# include <io.h>
39#else
40# include <unistd.h>
41# include <fcntl.h>
42# include <termios.h>
43#endif /* WIN32 || __EMX__ */
44
e73c6c0a 45
46/*
7c88bf41 47 * 'main()' - Send a file to the specified parallel port.
e73c6c0a 48 *
49 * Usage:
50 *
51 * printer-uri job-id user title copies options [file]
52 */
53
54int /* O - Exit status */
55main(int argc, /* I - Number of command-line arguments (6 or 7) */
56 char *argv[]) /* I - Command-line arguments */
57{
7c88bf41 58 char method[255], /* Method in URI */
59 hostname[1024], /* Hostname */
60 username[255], /* Username info (not used) */
61 resource[1024], /* Resource info (device and options) */
62 *options; /* Pointer to options */
63 int port; /* Port number (not used) */
64 FILE *fp; /* Print file */
65 int fd; /* Parallel device */
66 int error; /* Error code (if any) */
67 size_t nbytes, /* Number of bytes written */
68 tbytes; /* Total number of bytes written */
69 char buffer[8192]; /* Output buffer */
70 struct termios opts; /* Parallel port options */
71
72
e73c6c0a 73 if (argc < 6 || argc > 7)
74 {
7c88bf41 75 fputs("Usage: parallel job-id user title copies options [file]\n", stderr);
76 return (1);
77 }
78
79 /*
80 * If we have 7 arguments, print the file named on the command-line.
81 * Otherwise, send stdin instead...
82 */
83
84 if (argc == 6)
85 fp = stdin;
86 else
87 {
88 /*
89 * Try to open the print file...
90 */
91
92 if ((fp = fopen(argv[6], "rb")) == NULL)
93 {
94 perror("ERROR: unable to open print file - ");
95 return (1);
96 }
97 }
98
99 /*
100 * Extract the device name and options from the URI...
101 */
102
103 httpSeparate(argv[0], method, username, hostname, &port, resource);
104
105 /*
106 * See if there are any options...
107 */
108
109 if ((options = strchr(resource, '?')) != NULL)
110 {
111 /*
112 * Yup, terminate the device name string and move to the first
113 * character of the options...
114 */
115
116 *options++ = '\0';
117 }
118
119 /*
120 * Open the parallel port device...
121 */
122
123 if ((fd = open(resource, O_WRONLY)) == -1)
124 {
125 perror("ERROR: Unable to open parallel port device file - ");
e73c6c0a 126 return (1);
127 }
128
7c88bf41 129 /*
130 * Set any options provided...
131 */
132
133 tcgetattr(fd, &opts);
134
135 opts.c_lflag &= ~(ICANON | ECHO | ISIG); /* Raw mode */
136
137 /**** No options supported yet ****/
138
139 tcsetattr(fd, TCSANOW, &opts);
140
141 /*
142 * Finally, send the print file...
143 */
144
145 tbytes = 0;
146 while ((nbytes = fread(buffer, 1, sizeof(buffer), fp)) > 0)
147 {
148 /*
149 * Write the print data to the printer...
150 */
151
152 if (write(fd, buffer, nbytes) < nbytes)
153 {
154 perror("ERROR: Unable to send print file to printer - ");
155 break;
156 }
157 else
158 tbytes += nbytes;
159
160 fprintf(stderr, "INFO: Sending print file, %u bytes...\n", tbytes);
161 }
162
163 /*
164 * Close the socket connection and input file and return...
165 */
166
167 close(fd);
168 if (fp != stdin)
169 fclose(fp);
e73c6c0a 170
7c88bf41 171 return (0);
e73c6c0a 172}
43e2fc22 173
174
175/*
7c88bf41 176 * End of "$Id: parallel.c,v 1.4 1999/04/16 20:43:53 mike Exp $".
43e2fc22 177 */