]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-input.c
2 * "$Id: hpgl-input.c 7219 2008-01-14 22:00:02Z mike $"
4 * HP-GL/2 input processing for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 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 float temp
; /* Temporary parameter value */
52 static param_t p
[MAX_PARAMS
]; /* Parameter buffer */
60 while ((ch
= getc(fp
)) != EOF
)
61 if (strchr(" \t\r\n,;", ch
) == NULL
)
72 case '.' : /* HP-GL/2 job control */
75 if (strchr(")Z", i
) != NULL
)
78 * 'Printer Off' command - look for next 'Printer On' command...
83 while ((i
= getc(fp
)) != EOF
&& i
!= 0x1b);
91 if ((i
= getc(fp
)) == '(' ||
96 else if (strchr("@HIMNTI\003", i
) != NULL
)
98 while ((i
= getc(fp
)) != EOF
&& i
!= ':');
102 case '%' : /* PJL command? */
103 if ((i
= getc(fp
)) == '-')
104 if ((i
= getc(fp
)) == '1')
105 if ((i
= getc(fp
)) == '2')
108 * Yes, dump everything up to the "ENTER LANGUAGE" line...
111 while (fgets(buf
, sizeof(buf
), fp
) != NULL
)
112 if (strstr(buf
, "ENTER") && strstr(buf
, "LANGUAGE"))
119 default : /* HP RTL/PCL control */
120 while ((i
= getc(fp
)) != EOF
&& !isupper(i
& 255));
135 * If we get here, then more than likely we are faced with a raw PCL
136 * file which we can't handle - abort!
139 fputs(_("ERROR: Invalid HP-GL/2 command seen, unable to print file!\n"),
144 if (!strcasecmp(name
, "LB"))
147 while ((ch
= getc(fp
)) != StringTerminator
)
148 if (bufptr
< (buf
+ sizeof(buf
) - 1))
152 p
[num_params
].type
= PARAM_STRING
;
153 p
[num_params
].value
.string
= strdup(buf
);
156 else if (!strcasecmp(name
, "SM"))
160 p
[num_params
].type
= PARAM_STRING
;
161 p
[num_params
].value
.string
= strdup(buf
);
164 else if (!strcasecmp(name
, "DT"))
166 if ((buf
[0] = getc(fp
)) != ';')
169 p
[num_params
].type
= PARAM_STRING
;
170 p
[num_params
].value
.string
= strdup(buf
);
174 else if (!strcasecmp(name
, "PE"))
177 while ((ch
= getc(fp
)) != ';')
180 else if (bufptr
< (buf
+ sizeof(buf
) - 1))
184 p
[num_params
].type
= PARAM_STRING
;
185 p
[num_params
].value
.string
= strdup(buf
);
190 switch (ch
= getc(fp
))
204 fscanf(fp
, "%262143[^\"]\"", buf
);
205 if (num_params
< MAX_PARAMS
)
207 p
[num_params
].type
= PARAM_STRING
;
208 p
[num_params
].value
.string
= strdup(buf
);
216 if (fscanf(fp
, "%f", &temp
) == 1 && num_params
< MAX_PARAMS
)
218 p
[num_params
].type
= PARAM_RELATIVE
;
219 p
[num_params
].value
.number
= temp
;
235 if (fscanf(fp
, "%f", &temp
) == 1 && num_params
< MAX_PARAMS
)
237 p
[num_params
].type
= PARAM_ABSOLUTE
;
238 p
[num_params
].value
.number
= temp
;
254 * 'FreeParameters()' - Free all string parameter values.
258 FreeParameters(int num_params
, /* I - Number of parameters */
259 param_t
*params
) /* I - Parameter values */
261 int i
; /* Looping var */
264 for (i
= 0; i
< num_params
; i
++)
265 if (params
[i
].type
== PARAM_STRING
)
266 free(params
[i
].value
.string
);
271 * End of "$Id: hpgl-input.c 7219 2008-01-14 22:00:02Z mike $".