]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-main.c
2 * "$Id: hpgl-main.c 6649 2007-07-11 21:46:42Z mike $"
4 * HP-GL/2 filter main entry for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1993-2007 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
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/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * main() - Main entry for HP-GL/2 filter.
20 * compare_names() - Compare two command names.
24 * Include necessary headers...
30 #include <cups/i18n.h>
34 * HP-GL/2 command table...
39 char name
[4]; /* Name of command */
40 void (*func
)(int, param_t
*); /* Function to call */
43 static name_t commands
[] =
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
},
55 { "AA", AA_arc_absolute
},
56 { "AR", AR_arc_relative
},
57 { "AT", AT_arc_absolute3
},
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
},
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
},
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
}
106 #define NUM_COMMANDS (sizeof(commands) / sizeof(name_t))
113 static int compare_names(const void *p1
, const void *p2
);
117 * 'main()' - Main entry for HP-GL/2 filter.
120 int /* O - Exit status */
121 main(int argc
, /* I - Number of command-line arguments */
122 char *argv
[]) /* I - Command-line arguments */
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 */
136 * Make sure status messages are not buffered...
139 setbuf(stdout
, NULL
);
140 setbuf(stderr
, NULL
);
143 * Check command-line...
146 if (argc
< 6 || argc
> 7)
148 fprintf(stderr
, _("Usage: %s job-id user title copies options [file]\n"),
154 * If we have 7 arguments, print the file named on the command-line.
155 * Otherwise, send stdin instead...
163 * Try to open the print file...
166 if ((fp
= fopen(argv
[6], "rb")) == NULL
)
168 perror("DEBUG: unable to open print file - ");
174 * Process command-line options and write the prolog...
178 num_options
= cupsParseOptions(argv
[5], 0, &options
);
180 PPD
= SetCommonOptions(num_options
, options
, 1);
182 PlotSize
[0] = PageWidth
;
183 PlotSize
[1] = PageLength
;
188 if ((val
= cupsGetOption("blackplot", num_options
, options
)) != NULL
&&
189 strcasecmp(val
, "no") && strcasecmp(val
, "off") &&
190 strcasecmp(val
, "false"))
193 if ((val
= cupsGetOption("fitplot", num_options
, options
)) != NULL
&&
194 strcasecmp(val
, "no") && strcasecmp(val
, "off") &&
195 strcasecmp(val
, "false"))
198 if ((val
= cupsGetOption("penwidth", num_options
, options
)) != NULL
)
199 PenWidth
= (float)atoi(val
) * 0.001f
;
202 * Write the PostScript prolog and initialize the plotting "engine"...
205 OutputProlog(argv
[3], argv
[2], shading
);
207 IP_input_absolute(0, NULL
);
210 * Sort the command array...
213 qsort(commands
, NUM_COMMANDS
, sizeof(name_t
),
214 (int (*)(const void *, const void *))compare_names
);
217 * Read commands until we reach the end of file.
220 while ((num_params
= ParseCommand(fp
, name
.name
, ¶ms
)) >= 0)
222 Outputf("%% %s(%d)\n", name
.name
, num_params
);
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
);
232 fprintf(stderr
, " %f", params
[i
].value
.number
);
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
);
241 FreeParameters(num_params
, params
);
254 * 'compare_names()' - Compare two command names.
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 */
261 return (strcasecmp(((name_t
*)p1
)->name
, ((name_t
*)p2
)->name
));
266 * End of "$Id: hpgl-main.c 6649 2007-07-11 21:46:42Z mike $".