]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-input.c
2 * "$Id: hpgl-input.c 4494 2005-02-18 02:18:11Z mike $"
4 * HP-GL/2 input processing for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2005 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.
28 * ParseCommand() - Parse an HPGL/2 command.
29 * FreeParameters() - Free all string parameter values.
33 * Include necessary headers...
39 #define MAX_PARAMS 16384
43 * 'ParseCommand()' - Parse an HPGL/2 command.
45 * Returns the number of parameters seen or -1 on EOF.
48 int /* O - -1 on EOF, # params otherwise */
49 ParseCommand(FILE *fp
, /* I - File to read from */
50 char *name
, /* O - Name of command */
51 param_t
**params
) /* O - Parameter list */
53 int num_params
, /* Number of parameters seen */
54 ch
, /* Current char */
55 done
, /* Non-zero when the current command is read */
57 char buf
[262144], /* String buffer */
58 *bufptr
; /* Pointer into buffer */
59 static param_t p
[MAX_PARAMS
]; /* Parameter buffer */
67 while ((ch
= getc(fp
)) != EOF
)
68 if (strchr(" \t\r\n,;", ch
) == NULL
)
79 case '.' : /* HP-GL/2 job control */
82 if (strchr(")Z", i
) != NULL
)
85 * 'Printer Off' command - look for next 'Printer On' command...
90 while ((i
= getc(fp
)) != EOF
&& i
!= 0x1b);
98 if ((i
= getc(fp
)) == '(' ||
103 else if (strchr("@HIMNTI\003", i
) != NULL
)
105 while ((i
= getc(fp
)) != EOF
&& i
!= ':');
109 case '%' : /* PJL command? */
110 if ((i
= getc(fp
)) == '-')
111 if ((i
= getc(fp
)) == '1')
112 if ((i
= getc(fp
)) == '2')
115 * Yes, dump everything up to the "ENTER LANGUAGE" line...
118 while (fgets(buf
, sizeof(buf
), fp
) != NULL
)
119 if (strstr(buf
, "ENTER") && strstr(buf
, "LANGUAGE"))
126 default : /* HP RTL/PCL control */
127 while ((i
= getc(fp
)) != EOF
&& !isupper(i
& 255));
136 if (strcasecmp(name
, "LB") == 0)
139 while ((ch
= getc(fp
)) != StringTerminator
)
140 if (bufptr
< (buf
+ sizeof(buf
) - 1))
144 p
[num_params
].type
= PARAM_STRING
;
145 p
[num_params
].value
.string
= strdup(buf
);
148 else if (strcasecmp(name
, "SM") == 0)
152 p
[num_params
].type
= PARAM_STRING
;
153 p
[num_params
].value
.string
= strdup(buf
);
156 else if (strcasecmp(name
, "DT") == 0)
158 if ((buf
[0] = getc(fp
)) != ';')
161 p
[num_params
].type
= PARAM_STRING
;
162 p
[num_params
].value
.string
= strdup(buf
);
166 else if (strcasecmp(name
, "PE") == 0)
169 while ((ch
= getc(fp
)) != ';')
170 if (bufptr
< (buf
+ sizeof(buf
) - 1))
174 p
[num_params
].type
= PARAM_STRING
;
175 p
[num_params
].value
.string
= strdup(buf
);
180 switch (ch
= getc(fp
))
190 fscanf(fp
, "%262143[^\"]\"", buf
);
191 if (num_params
< MAX_PARAMS
)
193 p
[num_params
].type
= PARAM_STRING
;
194 p
[num_params
].value
.string
= strdup(buf
);
202 fscanf(fp
, "%f", &(p
[num_params
].value
.number
));
203 if (num_params
< MAX_PARAMS
)
205 p
[num_params
].type
= PARAM_RELATIVE
;
221 fscanf(fp
, "%f", &(p
[num_params
].value
.number
));
222 if (num_params
< MAX_PARAMS
)
224 p
[num_params
].type
= PARAM_ABSOLUTE
;
240 * 'FreeParameters()' - Free all string parameter values.
244 FreeParameters(int num_params
, /* I - Number of parameters */
245 param_t
*params
) /* I - Parameter values */
247 int i
; /* Looping var */
250 for (i
= 0; i
< num_params
; i
++)
251 if (params
[i
].type
== PARAM_STRING
)
252 free(params
[i
].value
.string
);
257 * End of "$Id: hpgl-input.c 4494 2005-02-18 02:18:11Z mike $".