]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
f7faf1f5 | 2 | * "$Id: hpgl-main.c 4494 2005-02-18 02:18:11Z mike $" |
ef416fc2 | 3 | * |
4 | * HP-GL/2 filter main entry for the Common UNIX Printing System (CUPS). | |
5 | * | |
6 | * Copyright 1993-2005 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 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" | |
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(stdout, NULL); | |
148 | setbuf(stderr, NULL); | |
149 | ||
150 | /* | |
151 | * Check command-line... | |
152 | */ | |
153 | ||
154 | if (argc < 6 || argc > 7) | |
155 | { | |
156 | fputs("ERROR: hpgltops job-id user title copies options [file]\n", stderr); | |
157 | return (1); | |
158 | } | |
159 | ||
160 | /* | |
161 | * If we have 7 arguments, print the file named on the command-line. | |
162 | * Otherwise, send stdin instead... | |
163 | */ | |
164 | ||
165 | if (argc == 6) | |
166 | fp = stdin; | |
167 | else | |
168 | { | |
169 | /* | |
170 | * Try to open the print file... | |
171 | */ | |
172 | ||
173 | if ((fp = fopen(argv[6], "rb")) == NULL) | |
174 | { | |
175 | perror("ERROR: unable to open print file - "); | |
176 | return (1); | |
177 | } | |
178 | } | |
179 | ||
180 | /* | |
181 | * Process command-line options and write the prolog... | |
182 | */ | |
183 | ||
184 | options = NULL; | |
185 | num_options = cupsParseOptions(argv[5], 0, &options); | |
186 | ||
187 | PPD = SetCommonOptions(num_options, options, 1); | |
188 | ||
189 | PlotSize[0] = PageWidth; | |
190 | PlotSize[1] = PageLength; | |
191 | ||
192 | shading = 1; | |
193 | PenWidth = 1.0; | |
194 | ||
195 | if ((val = cupsGetOption("blackplot", num_options, options)) != NULL && | |
196 | strcasecmp(val, "no") && strcasecmp(val, "off") && | |
197 | strcasecmp(val, "false")) | |
198 | shading = 0; | |
199 | ||
200 | if ((val = cupsGetOption("fitplot", num_options, options)) != NULL && | |
201 | strcasecmp(val, "no") && strcasecmp(val, "off") && | |
202 | strcasecmp(val, "false")) | |
203 | FitPlot = 1; | |
204 | ||
205 | if ((val = cupsGetOption("penwidth", num_options, options)) != NULL) | |
206 | PenWidth = (float)atoi(val) * 0.001f; | |
207 | ||
208 | /* | |
209 | * Write the PostScript prolog and initialize the plotting "engine"... | |
210 | */ | |
211 | ||
212 | OutputProlog(argv[3], argv[2], shading); | |
213 | ||
214 | IP_input_absolute(0, NULL); | |
215 | ||
216 | /* | |
217 | * Sort the command array... | |
218 | */ | |
219 | ||
220 | qsort(commands, NUM_COMMANDS, sizeof(name_t), | |
221 | (int (*)(const void *, const void *))compare_names); | |
222 | ||
223 | /* | |
224 | * Read commands until we reach the end of file. | |
225 | */ | |
226 | ||
227 | while ((num_params = ParseCommand(fp, name.name, ¶ms)) >= 0) | |
228 | { | |
229 | Outputf("%% %s(%d)\n", name.name, num_params); | |
230 | ||
231 | #ifdef DEBUG | |
232 | { | |
233 | int i; | |
234 | fprintf(stderr, "DEBUG: %s(%d)", name.name, num_params); | |
235 | for (i = 0; i < num_params; i ++) | |
236 | if (params[i].type == PARAM_STRING) | |
237 | fprintf(stderr, " \'%s\'", params[i].value.string); | |
238 | else | |
239 | fprintf(stderr, " %f", params[i].value.number); | |
240 | fputs("\n", stderr); | |
241 | } | |
242 | #endif /* DEBUG */ | |
243 | ||
244 | if ((command = bsearch(&name, commands, NUM_COMMANDS, sizeof(name_t), | |
245 | (int (*)(const void *, const void *))compare_names)) != NULL) | |
246 | (*command->func)(num_params, params); | |
247 | ||
248 | FreeParameters(num_params, params); | |
249 | } | |
250 | ||
251 | OutputTrailer(); | |
252 | ||
253 | if (fp != stdin) | |
254 | fclose(fp); | |
255 | ||
256 | return (0); | |
257 | } | |
258 | ||
259 | ||
260 | /* | |
261 | * 'compare_names()' - Compare two command names. | |
262 | */ | |
263 | ||
264 | static int /* O - Result of strcasecmp() on names */ | |
265 | compare_names(const void *p1, /* I - First name */ | |
266 | const void *p2) /* I - Second name */ | |
267 | { | |
268 | return (strcasecmp(((name_t *)p1)->name, ((name_t *)p2)->name)); | |
269 | } | |
270 | ||
271 | ||
272 | /* | |
f7faf1f5 | 273 | * End of "$Id: hpgl-main.c 4494 2005-02-18 02:18:11Z mike $". |
ef416fc2 | 274 | */ |