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