]> git.ipfire.org Git - thirdparty/cups.git/blame - filter/hpgl-main.c
Merge changes from CUPS 1.5svn-r8950.
[thirdparty/cups.git] / filter / hpgl-main.c
CommitLineData
ef416fc2 1/*
bc44d920 2 * "$Id: hpgl-main.c 6649 2007-07-11 21:46:42Z mike $"
ef416fc2 3 *
4 * HP-GL/2 filter main entry for the Common UNIX Printing System (CUPS).
5 *
ed6e7faf 6 * Copyright 2007-2008 by Apple Inc.
c0e1af83 7 * Copyright 1993-2007 by Easy Software Products.
ef416fc2 8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 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/".
ef416fc2 14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 *
17 * Contents:
18 *
19 * main() - Main entry for HP-GL/2 filter.
20 * compare_names() - Compare two command names.
21 */
22
23/*
24 * Include necessary headers...
25 */
26
27/*#define DEBUG*/
28#define _HPGL_MAIN_C_
29#include "hpgltops.h"
c0e1af83 30#include <cups/i18n.h>
ef416fc2 31
32
33/*
34 * HP-GL/2 command table...
35 */
36
37typedef struct
38{
39 char name[4]; /* Name of command */
40 void (*func)(int, param_t *); /* Function to call */
41} name_t;
42
43static name_t commands[] =
44{
45 { "BP", BP_begin_plot },
46 { "DF", DF_default_values },
47 { "IN", IN_initialize },
48 { "IP", IP_input_absolute },
49 { "IR", IR_input_relative },
50 { "IW", IW_input_window },
51 { "PG", PG_advance_page },
52 { "RO", RO_rotate },
53 { "RP", RP_replot },
54 { "SC", SC_scale },
55 { "AA", AA_arc_absolute },
56 { "AR", AR_arc_relative },
57 { "AT", AT_arc_absolute3 },
58 { "CI", CI_circle },
59 { "PA", PA_plot_absolute },
60 { "PD", PD_pen_down },
61 { "PE", PE_polyline_encoded },
62 { "PR", PR_plot_relative },
63 { "PS", PS_plot_size },
64 { "PU", PU_pen_up },
65 { "RT", RT_arc_relative3 },
66 { "EA", EA_edge_rect_absolute },
67 { "EP", EP_edge_polygon },
68 { "ER", ER_edge_rect_relative },
69 { "EW", EW_edge_wedge },
70 { "FP", FP_fill_polygon },
71 { "PM", PM_polygon_mode },
72 { "RA", RA_fill_rect_absolute },
73 { "RR", RR_fill_rect_relative },
74 { "WG", WG_fill_wedge },
75 { "AD", AD_define_alternate },
76 { "CF", CF_character_fill },
77 { "CP", CP_character_plot },
78 { "DI", DI_absolute_direction },
79 { "DR", DR_relative_direction },
80 { "DT", DT_define_label_term },
81 { "DV", DV_define_variable_path },
82 { "ES", ES_extra_space },
83 { "LB", LB_label },
84 { "LO", LO_label_origin },
85 { "SA", SA_select_alternate },
86 { "SD", SD_define_standard },
87 { "SI", SI_absolute_size },
88 { "SL", SL_character_slant },
89 { "SR", SR_relative_size },
90 { "SS", SS_select_standard },
91 { "TD", TD_transparent_data },
92 { "AC", AC_anchor_corner },
93 { "FT", FT_fill_type },
94 { "LA", LA_line_attributes },
95 { "LT", LT_line_type },
96 { "NP", NP_number_pens },
97 { "PC", PC_pen_color },
98 { "CR", CR_color_range },
99 { "PW", PW_pen_width },
100 { "RF", RF_raster_fill },
101 { "SM", SM_symbol_mode },
102 { "SP", SP_select_pen },
103 { "UL", UL_user_line_type },
104 { "WU", WU_width_units }
105};
106#define NUM_COMMANDS (sizeof(commands) / sizeof(name_t))
107
108
109/*
110 * Local functions...
111 */
112
113static int compare_names(const void *p1, const void *p2);
114
115
116/*
117 * 'main()' - Main entry for HP-GL/2 filter.
118 */
119
120int /* O - Exit status */
121main(int argc, /* I - Number of command-line arguments */
122 char *argv[]) /* I - Command-line arguments */
123{
124 FILE *fp; /* Input file */
125 int num_params; /* Number of parameters */
126 param_t *params; /* Command parameters */
127 name_t *command, /* Command */
128 name; /* Name of command */
129 int num_options; /* Number of print options */
130 cups_option_t *options; /* Print options */
131 const char *val; /* Option value */
132 int shading; /* -1 = black, 0 = grey, 1 = color */
133
134
135 /*
136 * Make sure status messages are not buffered...
137 */
138
139 setbuf(stdout, NULL);
140 setbuf(stderr, NULL);
141
142 /*
143 * Check command-line...
144 */
145
146 if (argc < 6 || argc > 7)
147 {
c0e1af83 148 fprintf(stderr, _("Usage: %s job-id user title copies options [file]\n"),
149 argv[0]);
ef416fc2 150 return (1);
151 }
152
153 /*
154 * If we have 7 arguments, print the file named on the command-line.
155 * Otherwise, send stdin instead...
156 */
157
158 if (argc == 6)
159 fp = stdin;
160 else
161 {
162 /*
163 * Try to open the print file...
164 */
165
166 if ((fp = fopen(argv[6], "rb")) == NULL)
167 {
c0e1af83 168 perror("DEBUG: unable to open print file - ");
ef416fc2 169 return (1);
170 }
171 }
172
173 /*
174 * Process command-line options and write the prolog...
175 */
176
177 options = NULL;
178 num_options = cupsParseOptions(argv[5], 0, &options);
179
180 PPD = SetCommonOptions(num_options, options, 1);
181
182 PlotSize[0] = PageWidth;
183 PlotSize[1] = PageLength;
184
185 shading = 1;
186 PenWidth = 1.0;
187
188 if ((val = cupsGetOption("blackplot", num_options, options)) != NULL &&
189 strcasecmp(val, "no") && strcasecmp(val, "off") &&
190 strcasecmp(val, "false"))
191 shading = 0;
192
193 if ((val = cupsGetOption("fitplot", num_options, options)) != NULL &&
ed6e7faf
MS
194 !strcasecmp(val, "true"))
195 FitPlot = 1;
196 else if ((val = cupsGetOption("fit-to-page", num_options, options)) != NULL &&
197 !strcasecmp(val, "true"))
ef416fc2 198 FitPlot = 1;
199
200 if ((val = cupsGetOption("penwidth", num_options, options)) != NULL)
201 PenWidth = (float)atoi(val) * 0.001f;
202
203 /*
204 * Write the PostScript prolog and initialize the plotting "engine"...
205 */
206
207 OutputProlog(argv[3], argv[2], shading);
208
209 IP_input_absolute(0, NULL);
210
211 /*
212 * Sort the command array...
213 */
214
215 qsort(commands, NUM_COMMANDS, sizeof(name_t),
216 (int (*)(const void *, const void *))compare_names);
217
218 /*
219 * Read commands until we reach the end of file.
220 */
221
222 while ((num_params = ParseCommand(fp, name.name, &params)) >= 0)
223 {
224 Outputf("%% %s(%d)\n", name.name, num_params);
225
226#ifdef DEBUG
227 {
228 int i;
229 fprintf(stderr, "DEBUG: %s(%d)", name.name, num_params);
230 for (i = 0; i < num_params; i ++)
231 if (params[i].type == PARAM_STRING)
232 fprintf(stderr, " \'%s\'", params[i].value.string);
233 else
234 fprintf(stderr, " %f", params[i].value.number);
235 fputs("\n", stderr);
236 }
237#endif /* DEBUG */
238
239 if ((command = bsearch(&name, commands, NUM_COMMANDS, sizeof(name_t),
240 (int (*)(const void *, const void *))compare_names)) != NULL)
241 (*command->func)(num_params, params);
242
243 FreeParameters(num_params, params);
244 }
245
246 OutputTrailer();
247
248 if (fp != stdin)
249 fclose(fp);
250
251 return (0);
252}
253
254
255/*
256 * 'compare_names()' - Compare two command names.
257 */
258
259static int /* O - Result of strcasecmp() on names */
260compare_names(const void *p1, /* I - First name */
261 const void *p2) /* I - Second name */
262{
263 return (strcasecmp(((name_t *)p1)->name, ((name_t *)p2)->name));
264}
265
266
267/*
bc44d920 268 * End of "$Id: hpgl-main.c 6649 2007-07-11 21:46:42Z mike $".
ef416fc2 269 */