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