]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-main.c
2 * "$Id: hpgl-main.c 4494 2005-02-18 02:18:11Z mike $"
4 * HP-GL/2 filter main entry for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2005 by Easy Software Products.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * main() - Main entry for HP-GL/2 filter.
29 * compare_names() - Compare two command names.
33 * Include necessary headers...
42 * HP-GL/2 command table...
47 char name
[4]; /* Name of command */
48 void (*func
)(int, param_t
*); /* Function to call */
51 static name_t commands
[] =
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
},
63 { "AA", AA_arc_absolute
},
64 { "AR", AR_arc_relative
},
65 { "AT", AT_arc_absolute3
},
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
},
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
},
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
}
114 #define NUM_COMMANDS (sizeof(commands) / sizeof(name_t))
121 static int compare_names(const void *p1
, const void *p2
);
125 * 'main()' - Main entry for HP-GL/2 filter.
128 int /* O - Exit status */
129 main(int argc
, /* I - Number of command-line arguments */
130 char *argv
[]) /* I - Command-line arguments */
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 */
144 * Make sure status messages are not buffered...
147 setbuf(stdout
, NULL
);
148 setbuf(stderr
, NULL
);
151 * Check command-line...
154 if (argc
< 6 || argc
> 7)
156 fputs("ERROR: hpgltops job-id user title copies options [file]\n", stderr
);
161 * If we have 7 arguments, print the file named on the command-line.
162 * Otherwise, send stdin instead...
170 * Try to open the print file...
173 if ((fp
= fopen(argv
[6], "rb")) == NULL
)
175 perror("ERROR: unable to open print file - ");
181 * Process command-line options and write the prolog...
185 num_options
= cupsParseOptions(argv
[5], 0, &options
);
187 PPD
= SetCommonOptions(num_options
, options
, 1);
189 PlotSize
[0] = PageWidth
;
190 PlotSize
[1] = PageLength
;
195 if ((val
= cupsGetOption("blackplot", num_options
, options
)) != NULL
&&
196 strcasecmp(val
, "no") && strcasecmp(val
, "off") &&
197 strcasecmp(val
, "false"))
200 if ((val
= cupsGetOption("fitplot", num_options
, options
)) != NULL
&&
201 strcasecmp(val
, "no") && strcasecmp(val
, "off") &&
202 strcasecmp(val
, "false"))
205 if ((val
= cupsGetOption("penwidth", num_options
, options
)) != NULL
)
206 PenWidth
= (float)atoi(val
) * 0.001f
;
209 * Write the PostScript prolog and initialize the plotting "engine"...
212 OutputProlog(argv
[3], argv
[2], shading
);
214 IP_input_absolute(0, NULL
);
217 * Sort the command array...
220 qsort(commands
, NUM_COMMANDS
, sizeof(name_t
),
221 (int (*)(const void *, const void *))compare_names
);
224 * Read commands until we reach the end of file.
227 while ((num_params
= ParseCommand(fp
, name
.name
, ¶ms
)) >= 0)
229 Outputf("%% %s(%d)\n", name
.name
, num_params
);
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
);
239 fprintf(stderr
, " %f", params
[i
].value
.number
);
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
);
248 FreeParameters(num_params
, params
);
261 * 'compare_names()' - Compare two command names.
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 */
268 return (strcasecmp(((name_t
*)p1
)->name
, ((name_t
*)p2
)->name
));
273 * End of "$Id: hpgl-main.c 4494 2005-02-18 02:18:11Z mike $".