]>
git.ipfire.org Git - thirdparty/cups.git/blob - monitor/bcp.c
2 * "$Id: bcp.c 5087 2006-02-07 03:43:29Z mike $"
4 * TBCP port monitor for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2006 by Easy Software Products.
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.txt" 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.
31 * Include necessary headers...
34 #include <cups/string.h>
35 #include <cups/cups.h>
42 static char *psgets(char *buf
, size_t *bytes
, FILE *fp
);
43 static size_t pswrite(const char *buf
, size_t bytes
, FILE *fp
);
47 * 'main()' - Main entry...
50 int /* O - Exit status */
51 main(int argc
, /* I - Number of command-line args */
52 char *argv
[]) /* I - Command-line arguments */
54 FILE *fp
; /* File to print */
55 int copies
; /* Number of copies left */
56 char line
[1024]; /* Line/buffer from stream/file */
57 size_t linelen
; /* Length of line */
58 ppd_file_t
*ppd
; /* PPD file */
62 * Check command-line...
65 if (argc
< 6 || argc
> 7)
67 fputs("ERROR: tbcp job-id user title copies options [file]\n", stderr
);
78 copies
= atoi(argv
[4]);
79 fp
= fopen(argv
[6], "rb");
89 * Open the PPD file as needed...
92 ppd
= ppdOpenFile(getenv("PPD"));
95 * Copy the print file to stdout...
102 if (ppd
&& ppd
->jcl_begin
)
103 fputs(ppd
->jcl_begin
, stdout
);
104 if (ppd
&& ppd
->jcl_ps
)
105 fputs(ppd
->jcl_ps
, stdout
);
107 if (!ppd
|| ppd
->language_level
== 1)
110 * Use setsoftwareiomode for BCP mode...
113 puts("%!PS-Adobe-3.0 ExitServer");
114 puts("%%Title: (BCP - Level 1)");
115 puts("%%EndComments");
116 puts("%%BeginExitServer: 0");
117 puts("serverdict begin 0 exitserver");
118 puts("%%EndExitServer");
119 puts("statusdict begin");
120 puts("/setsoftwareiomode known {100 setsoftwareiomode}");
127 * Use setdevparams for BCP mode...
130 puts("%!PS-Adobe-3.0");
131 puts("%%Title: (BCP - Level 2)");
132 puts("%%EndComments");
133 puts("currentsysparams");
134 puts("/CurInputDevice 2 copy known {");
136 puts("<</Protocol /Binary>> setdevparams");
143 if (ppd
&& ppd
->jcl_end
)
144 fputs(ppd
->jcl_end
, stdout
);
145 else if (!ppd
|| ppd
->num_filters
== 0)
149 * Loop until we see end-of-file...
154 linelen
= sizeof(line
);
155 if (psgets(line
, &linelen
, fp
) == NULL
)
158 while (pswrite(line
, linelen
, stdout
) > 0);
168 * 'psgets()' - Get a line from a file.
172 * This function differs from the gets() function in that it
173 * handles any combination of CR, LF, or CR LF to end input
177 static char * /* O - String or NULL if EOF */
178 psgets(char *buf
, /* I - Buffer to read into */
179 size_t *bytes
, /* IO - Length of buffer */
180 FILE *fp
) /* I - File to read from */
182 char *bufptr
; /* Pointer into buffer */
183 int ch
; /* Character from file */
184 size_t len
; /* Max length of string */
191 while ((bufptr
- buf
) < len
)
193 if ((ch
= getc(fp
)) == EOF
)
199 * Got a CR; see if there is a LF as well...
204 if (ch
!= EOF
&& ch
!= '\n')
206 ungetc(ch
, fp
); /* Nope, save it for later... */
220 * Add a trailing newline if it is there...
223 if (ch
== '\n' || ch
== '\r')
225 if ((bufptr
- buf
) < len
)
232 * Nul-terminate the string and return it (or NULL for EOF).
236 *bytes
= bufptr
- buf
;
238 if (ch
== EOF
&& bufptr
== buf
)
246 * 'pswrite()' - Write data from a file.
249 static size_t /* O - Number of bytes written */
250 pswrite(const char *buf
, /* I - Buffer to write */
251 size_t bytes
, /* I - Bytes to write */
252 FILE *fp
) /* I - File to write to */
254 size_t count
; /* Remaining bytes */
257 for (count
= bytes
; count
> 0; count
--, buf
++)
260 case 0x01 : /* CTRL-A */
261 case 0x03 : /* CTRL-C */
262 case 0x04 : /* CTRL-D */
263 case 0x05 : /* CTRL-E */
264 case 0x11 : /* CTRL-Q */
265 case 0x13 : /* CTRL-S */
266 case 0x14 : /* CTRL-T */
267 case 0x1c : /* CTRL-\ */
268 if (putchar(0x01) < 0)
270 if (putchar(*buf
^ 0x40) < 0)
275 if (putchar(*buf
) < 0)
285 * End of "$Id: bcp.c 5087 2006-02-07 03:43:29Z mike $".