16 #include "../hidint.h"
18 #include "hid/common/hidnogui.h"
19 #include "hid/common/hidinit.h"
21 #ifdef HAVE_LIBDMALLOC
25 #define CRASH fprintf(stderr, "HID error: pcb called unimplemented PS function %s.\n", __FUNCTION__); abort()
27 static HID_Attribute base_lpr_options
[] = {
29 /* %start-doc options "98 lpr Printing Options"
31 @item --lprcommand <string>
32 Command to use for printing. Defaults to @code{lpr}. This can be used to produce
33 PDF output with a virtual PDF printer. Example: @*
34 @code{--lprcommand "lp -d CUPS-PDF-Printer"}.
36 @noindent In addition, all @ref{Postscript Export} options are valid.
39 {"lprcommand", "Command to use for printing",
40 HID_String
, 0, 0, {0, 0, 0}, 0, 0},
41 #define HA_lprcommand 0
44 #define NUM_OPTIONS (sizeof(lpr_options)/sizeof(lpr_options[0]))
46 static HID_Attribute
*lpr_options
= 0;
47 static int num_lpr_options
= 0;
48 static HID_Attr_Val
*lpr_values
;
50 static HID_Attribute
*
51 lpr_get_export_options (int *n
)
54 * We initialize the default value in this manner because the GUI
55 * HID's may want to free() this string value and replace it with a
56 * new one based on how a user fills out a print dialog.
58 if (base_lpr_options
[HA_lprcommand
].default_val
.str_value
== NULL
)
60 base_lpr_options
[HA_lprcommand
].default_val
.str_value
= strdup("lpr");
65 HID_Attribute
*ps_opts
= ps_hid
.get_export_options (&num_lpr_options
);
67 (HID_Attribute
*) calloc (num_lpr_options
, sizeof (HID_Attribute
));
68 memcpy (lpr_options
, ps_opts
, num_lpr_options
* sizeof (HID_Attribute
));
69 memcpy (lpr_options
, base_lpr_options
, sizeof (base_lpr_options
));
71 (HID_Attr_Val
*) calloc (num_lpr_options
, sizeof (HID_Attr_Val
));
79 lpr_do_export (HID_Attr_Val
* options
)
87 lpr_get_export_options (0);
88 for (i
= 0; i
< num_lpr_options
; i
++)
89 lpr_values
[i
] = lpr_options
[i
].default_val
;
93 filename
= options
[HA_lprcommand
].str_value
;
95 printf ("LPR: open %s\n", filename
);
96 f
= popen (filename
, "w");
103 ps_hid_export_to_file (f
, options
);
109 lpr_parse_arguments (int *argc
, char ***argv
)
111 lpr_get_export_options (0);
112 hid_register_attributes (lpr_options
, num_lpr_options
);
113 hid_parse_command_line (argc
, argv
);
117 lpr_calibrate (double xval
, double yval
)
119 ps_calibrate_1 (xval
, yval
, 1);
127 memset (&lpr_hid
, 0, sizeof (HID
));
129 common_nogui_init (&lpr_hid
);
130 ps_ps_init (&lpr_hid
);
132 lpr_hid
.struct_size
= sizeof (HID
);
133 lpr_hid
.name
= "lpr";
134 lpr_hid
.description
= "Postscript print";
136 lpr_hid
.poly_before
= 1;
138 lpr_hid
.get_export_options
= lpr_get_export_options
;
139 lpr_hid
.do_export
= lpr_do_export
;
140 lpr_hid
.parse_arguments
= lpr_parse_arguments
;
141 lpr_hid
.calibrate
= lpr_calibrate
;
143 hid_register_hid (&lpr_hid
);