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