#define _HPGL_MAIN_C_
#include "hpgltops.h"
typedef struct
{
char name[4];
void (*func)(int, param_t *);
} name_t;
static name_t commands[] =
{
{ "BP", BP_begin_plot },
{ "DF", DF_default_values },
{ "IN", IN_initialize },
{ "IP", IP_input_absolute },
{ "IR", IR_input_relative },
{ "IW", IW_input_window },
{ "PG", PG_advance_page },
{ "RO", RO_rotate },
{ "RP", RP_replot },
{ "SC", SC_scale },
{ "AA", AA_arc_absolute },
{ "AR", AR_arc_relative },
{ "AT", AT_arc_absolute3 },
{ "CI", CI_circle },
{ "PA", PA_plot_absolute },
{ "PD", PD_pen_down },
{ "PE", PE_polyline_encoded },
{ "PR", PR_plot_relative },
{ "PS", PS_plot_size },
{ "PU", PU_pen_up },
{ "RT", RT_arc_relative3 },
{ "EA", EA_edge_rect_absolute },
{ "EP", EP_edge_polygon },
{ "ER", ER_edge_rect_relative },
{ "EW", EW_edge_wedge },
{ "FP", FP_fill_polygon },
{ "PM", PM_polygon_mode },
{ "RA", RA_fill_rect_absolute },
{ "RR", RR_fill_rect_relative },
{ "WG", WG_fill_wedge },
{ "AD", AD_define_alternate },
{ "CF", CF_character_fill },
{ "CP", CP_character_plot },
{ "DI", DI_absolute_direction },
{ "DR", DR_relative_direction },
{ "DT", DT_define_label_term },
{ "DV", DV_define_variable_path },
{ "ES", ES_extra_space },
{ "LB", LB_label },
{ "LO", LO_label_origin },
{ "SA", SA_select_alternate },
{ "SD", SD_define_standard },
{ "SI", SI_absolute_size },
{ "SL", SL_character_slant },
{ "SR", SR_relative_size },
{ "SS", SS_select_standard },
{ "TD", TD_transparent_data },
{ "AC", AC_anchor_corner },
{ "FT", FT_fill_type },
{ "LA", LA_line_attributes },
{ "LT", LT_line_type },
{ "NP", NP_number_pens },
{ "PC", PC_pen_color },
{ "CR", CR_color_range },
{ "PW", PW_pen_width },
{ "RF", RF_raster_fill },
{ "SM", SM_symbol_mode },
{ "SP", SP_select_pen },
{ "UL", UL_user_line_type },
{ "WU", WU_width_units }
};
#define NUM_COMMANDS (sizeof(commands) / sizeof(name_t))
static int compare_names(const void *p1, const void *p2);
int
main(int argc,
char *argv[])
{
FILE *fp;
int num_params;
param_t *params;
name_t *command,
name;
int num_options;
cups_option_t *options;
const char *val;
int shading;
setbuf(stdout, NULL);
setbuf(stderr, NULL);
if (argc < 6 || argc > 7)
{
fputs("ERROR: hpgltops job-id user title copies options [file]\n", stderr);
return (1);
}
if (argc == 6)
fp = stdin;
else
{
if ((fp = fopen(argv[6], "rb")) == NULL)
{
perror("ERROR: unable to open print file - ");
return (1);
}
}
options = NULL;
num_options = cupsParseOptions(argv[5], 0, &options);
PPD = SetCommonOptions(num_options, options, 1);
PlotSize[0] = PageWidth;
PlotSize[1] = PageLength;
shading = 1;
PenWidth = 1.0;
if ((val = cupsGetOption("blackplot", num_options, options)) != NULL &&
strcasecmp(val, "no") && strcasecmp(val, "off") &&
strcasecmp(val, "false"))
shading = 0;
if ((val = cupsGetOption("fitplot", num_options, options)) != NULL &&
strcasecmp(val, "no") && strcasecmp(val, "off") &&
strcasecmp(val, "false"))
FitPlot = 1;
if ((val = cupsGetOption("penwidth", num_options, options)) != NULL)
PenWidth = (float)atoi(val) * 0.001f;
OutputProlog(argv[3], argv[2], shading);
IP_input_absolute(0, NULL);
qsort(commands, NUM_COMMANDS, sizeof(name_t),
(int (*)(const void *, const void *))compare_names);
while ((num_params = ParseCommand(fp, name.name, ¶ms)) >= 0)
{
Outputf("%% %s(%d)\n", name.name, num_params);
#ifdef DEBUG
{
int i;
fprintf(stderr, "DEBUG: %s(%d)", name.name, num_params);
for (i = 0; i < num_params; i ++)
if (params[i].type == PARAM_STRING)
fprintf(stderr, " \'%s\'", params[i].value.string);
else
fprintf(stderr, " %f", params[i].value.number);
fputs("\n", stderr);
}
#endif
if ((command = bsearch(&name, commands, NUM_COMMANDS, sizeof(name_t),
(int (*)(const void *, const void *))compare_names)) != NULL)
(*command->func)(num_params, params);
FreeParameters(num_params, params);
}
OutputTrailer();
if (fp != stdin)
fclose(fp);
return (0);
}
static int
compare_names(const void *p1,
const void *p2)
{
return (strcasecmp(((name_t *)p1)->name, ((name_t *)p2)->name));
}