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