]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-main.c
2 * "$Id: hpgl-main.c,v 1.16 1999/10/27 20:20:14 mike Exp $"
4 * HP-GL/2 filter main entry for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-1999 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-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Main entry for HP-GL/2 filter.
27 * compare_names() - Compare two command names.
31 * Include necessary headers...
40 * HP-GL/2 command table...
45 char name
[4]; /* Name of command */
46 void (*func
)(int, param_t
*); /* Function to call */
49 static name_t commands
[] =
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
},
61 { "AA", AA_arc_absolute
},
62 { "AR", AR_arc_relative
},
63 { "AT", AT_arc_absolute3
},
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
},
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
},
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
}
112 #define NUM_COMMANDS (sizeof(commands) / sizeof(name_t))
119 static int compare_names(const void *p1
, const void *p2
);
123 * 'main()' - Main entry for HP-GL/2 filter.
126 int /* O - Exit status */
127 main(int argc
, /* I - Number of command-line arguments */
128 char *argv
[]) /* I - Command-line arguments */
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 */
135 int num_options
; /* Number of print options */
136 cups_option_t
*options
; /* Print options */
137 const char *val
; /* Option value */
138 int shading
; /* -1 = black, 0 = grey, 1 = color */
139 float penwidth
; /* Default pen width */
142 if (argc
< 6 || argc
> 7)
144 fputs("ERROR: hpgltops job-id user title copies options [file]\n", stderr
);
149 * If we have 7 arguments, print the file named on the command-line.
150 * Otherwise, send stdin instead...
158 * Try to open the print file...
161 if ((fp
= fopen(argv
[6], "rb")) == NULL
)
163 perror("ERROR: unable to open print file - ");
169 * Process command-line options and write the prolog...
173 num_options
= cupsParseOptions(argv
[5], 0, &options
);
175 PPD
= SetCommonOptions(num_options
, options
, 1);
180 if ((val
= cupsGetOption("blackplot", num_options
, options
)) != NULL
)
183 if ((val
= cupsGetOption("fitplot", num_options
, options
)) != NULL
)
186 if ((val
= cupsGetOption("penwidth", num_options
, options
)) != NULL
)
187 penwidth
= (float)atof(val
);
190 * Write the PostScript prolog and initialize the plotting "engine"...
193 OutputProlog(argv
[3], argv
[2], shading
, penwidth
);
195 IP_input_absolute(0, NULL
);
198 * Sort the command array...
201 qsort(commands
, NUM_COMMANDS
, sizeof(name_t
),
202 (int (*)(const void *, const void *))compare_names
);
205 * Read commands until we reach the end of file.
208 while ((num_params
= ParseCommand(fp
, name
.name
, ¶ms
)) >= 0)
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
);
218 fprintf(stderr
, " %f", params
[i
].value
.number
);
223 if ((command
= bsearch(&name
, commands
, NUM_COMMANDS
, sizeof(name_t
),
224 (int (*)(const void *, const void *))compare_names
)) != NULL
)
225 (*command
->func
)(num_params
, params
);
227 FreeParameters(num_params
, params
);
240 * 'compare_names()' - Compare two command names.
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 */
247 return (strcasecmp(((name_t
*)p1
)->name
, ((name_t
*)p2
)->name
));
252 * End of "$Id: hpgl-main.c,v 1.16 1999/10/27 20:20:14 mike Exp $".