]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-input.c
4 * HP-GL/2 input processing for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2004 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
)
77 case '.' : /* HP-GL/2 job control */
80 if (strchr(")Z", i
) != NULL
)
83 * 'Printer Off' command - look for next 'Printer On' command...
88 while ((i
= getc(fp
)) != EOF
&& i
!= 0x1b);
96 if ((i
= getc(fp
)) == '(' ||
101 else if (strchr("@HIMNTI\003", i
) != NULL
)
103 while ((i
= getc(fp
)) != EOF
&& i
!= ':');
107 case '%' : /* PJL command? */
111 * Yes, dump everything up to the "ENTER LANGUAGE" line...
114 while (fgets(buf
, sizeof(buf
), fp
) != NULL
)
115 if (strstr(buf
, "ENTER") && strstr(buf
, "LANGUAGE"))
120 default : /* HP RTL/PCL control */
121 while ((i
= getc(fp
)) != EOF
&& !isupper(i
& 255));
130 if (strcasecmp(name
, "LB") == 0)
133 while ((ch
= getc(fp
)) != StringTerminator
)
134 if (bufptr
< (buf
+ sizeof(buf
) - 1))
138 p
[num_params
].type
= PARAM_STRING
;
139 p
[num_params
].value
.string
= strdup(buf
);
142 else if (strcasecmp(name
, "SM") == 0)
146 p
[num_params
].type
= PARAM_STRING
;
147 p
[num_params
].value
.string
= strdup(buf
);
150 else if (strcasecmp(name
, "DT") == 0)
152 if ((buf
[0] = getc(fp
)) != ';')
155 p
[num_params
].type
= PARAM_STRING
;
156 p
[num_params
].value
.string
= strdup(buf
);
160 else if (strcasecmp(name
, "PE") == 0)
163 while ((ch
= getc(fp
)) != ';')
164 if (bufptr
< (buf
+ sizeof(buf
) - 1))
168 p
[num_params
].type
= PARAM_STRING
;
169 p
[num_params
].value
.string
= strdup(buf
);
174 switch (ch
= getc(fp
))
184 fscanf(fp
, "%262143[^\"]\"", buf
);
185 if (num_params
< MAX_PARAMS
)
187 p
[num_params
].type
= PARAM_STRING
;
188 p
[num_params
].value
.string
= strdup(buf
);
196 fscanf(fp
, "%f", &(p
[num_params
].value
.number
));
197 if (num_params
< MAX_PARAMS
)
199 p
[num_params
].type
= PARAM_RELATIVE
;
215 fscanf(fp
, "%f", &(p
[num_params
].value
.number
));
216 if (num_params
< MAX_PARAMS
)
218 p
[num_params
].type
= PARAM_ABSOLUTE
;
234 * 'FreeParameters()' - Free all string parameter values.
238 FreeParameters(int num_params
, /* I - Number of parameters */
239 param_t
*params
) /* I - Parameter values */
241 int i
; /* Looping var */
244 for (i
= 0; i
< num_params
; i
++)
245 if (params
[i
].type
== PARAM_STRING
)
246 free(params
[i
].value
.string
);