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