]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-input.c
2 * "$Id: hpgl-input.c 6649 2007-07-11 21:46:42Z mike $"
4 * HP-GL/2 input processing for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1993-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * ParseCommand() - Parse an HPGL/2 command.
20 * FreeParameters() - Free all string parameter values.
24 * Include necessary headers...
29 #include <cups/i18n.h>
31 #define MAX_PARAMS 16384
35 * 'ParseCommand()' - Parse an HPGL/2 command.
37 * Returns the number of parameters seen or -1 on EOF.
40 int /* O - -1 on EOF, # params otherwise */
41 ParseCommand(FILE *fp
, /* I - File to read from */
42 char *name
, /* O - Name of command */
43 param_t
**params
) /* O - Parameter list */
45 int num_params
, /* Number of parameters seen */
46 ch
, /* Current char */
47 done
, /* Non-zero when the current command is read */
49 char buf
[262144], /* String buffer */
50 *bufptr
; /* Pointer into buffer */
51 static param_t p
[MAX_PARAMS
]; /* Parameter buffer */
59 while ((ch
= getc(fp
)) != EOF
)
60 if (strchr(" \t\r\n,;", ch
) == NULL
)
71 case '.' : /* HP-GL/2 job control */
74 if (strchr(")Z", i
) != NULL
)
77 * 'Printer Off' command - look for next 'Printer On' command...
82 while ((i
= getc(fp
)) != EOF
&& i
!= 0x1b);
90 if ((i
= getc(fp
)) == '(' ||
95 else if (strchr("@HIMNTI\003", i
) != NULL
)
97 while ((i
= getc(fp
)) != EOF
&& i
!= ':');
101 case '%' : /* PJL command? */
102 if ((i
= getc(fp
)) == '-')
103 if ((i
= getc(fp
)) == '1')
104 if ((i
= getc(fp
)) == '2')
107 * Yes, dump everything up to the "ENTER LANGUAGE" line...
110 while (fgets(buf
, sizeof(buf
), fp
) != NULL
)
111 if (strstr(buf
, "ENTER") && strstr(buf
, "LANGUAGE"))
118 default : /* HP RTL/PCL control */
119 while ((i
= getc(fp
)) != EOF
&& !isupper(i
& 255));
134 * If we get here, then more than likely we are faced with a raw PCL
135 * file which we can't handle - abort!
138 fputs(_("ERROR: Invalid HP-GL/2 command seen, unable to print file!\n"),
143 if (!strcasecmp(name
, "LB"))
146 while ((ch
= getc(fp
)) != StringTerminator
)
147 if (bufptr
< (buf
+ sizeof(buf
) - 1))
151 p
[num_params
].type
= PARAM_STRING
;
152 p
[num_params
].value
.string
= strdup(buf
);
155 else if (!strcasecmp(name
, "SM"))
159 p
[num_params
].type
= PARAM_STRING
;
160 p
[num_params
].value
.string
= strdup(buf
);
163 else if (!strcasecmp(name
, "DT"))
165 if ((buf
[0] = getc(fp
)) != ';')
168 p
[num_params
].type
= PARAM_STRING
;
169 p
[num_params
].value
.string
= strdup(buf
);
173 else if (!strcasecmp(name
, "PE"))
176 while ((ch
= getc(fp
)) != ';')
179 else if (bufptr
< (buf
+ sizeof(buf
) - 1))
183 p
[num_params
].type
= PARAM_STRING
;
184 p
[num_params
].value
.string
= strdup(buf
);
189 switch (ch
= getc(fp
))
203 fscanf(fp
, "%262143[^\"]\"", buf
);
204 if (num_params
< MAX_PARAMS
)
206 p
[num_params
].type
= PARAM_STRING
;
207 p
[num_params
].value
.string
= strdup(buf
);
215 fscanf(fp
, "%f", &(p
[num_params
].value
.number
));
216 if (num_params
< MAX_PARAMS
)
218 p
[num_params
].type
= PARAM_RELATIVE
;
234 fscanf(fp
, "%f", &(p
[num_params
].value
.number
));
235 if (num_params
< MAX_PARAMS
)
237 p
[num_params
].type
= PARAM_ABSOLUTE
;
253 * 'FreeParameters()' - Free all string parameter values.
257 FreeParameters(int num_params
, /* I - Number of parameters */
258 param_t
*params
) /* I - Parameter values */
260 int i
; /* Looping var */
263 for (i
= 0; i
< num_params
; i
++)
264 if (params
[i
].type
== PARAM_STRING
)
265 free(params
[i
].value
.string
);
270 * End of "$Id: hpgl-input.c 6649 2007-07-11 21:46:42Z mike $".