Remove unused functions {LO,PV}TouchesLine() and their callbacks
[geda-pcb/pcjc2.git] / src / hid / lpr / lpr.c
bloba03b19c88857bb1f58e045478314574a28daee1b
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
5 #include <stdio.h>
6 #include <stdarg.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <assert.h>
11 #include "global.h"
12 #include "data.h"
13 #include "misc.h"
15 #include "hid.h"
16 #include "../hidint.h"
17 #include "../ps/ps.h"
18 #include "hid/common/hidnogui.h"
19 #include "hid/common/hidinit.h"
21 #ifdef HAVE_LIBDMALLOC
22 #include <dmalloc.h>
23 #endif
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"
30 @ftable @code
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"}.
35 @end ftable
36 @noindent In addition, all @ref{Postscript Export} options are valid.
37 %end-doc
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");
63 if (lpr_options == 0)
65 HID_Attribute *ps_opts = ps_hid.get_export_options (&num_lpr_options);
66 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));
70 lpr_values =
71 (HID_Attr_Val *) calloc (num_lpr_options, sizeof (HID_Attr_Val));
73 if (n)
74 *n = num_lpr_options;
75 return lpr_options;
78 static void
79 lpr_do_export (HID_Attr_Val * options)
81 FILE *f;
82 int i;
83 const char *filename;
85 if (!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;
90 options = lpr_values;
93 filename = options[HA_lprcommand].str_value;
95 printf ("LPR: open %s\n", filename);
96 f = popen (filename, "w");
97 if (!f)
99 perror (filename);
100 return;
103 ps_hid_export_to_file (f, options);
105 pclose (f);
108 static void
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);
116 static void
117 lpr_calibrate (double xval, double yval)
119 ps_calibrate_1 (xval, yval, 1);
122 static HID lpr_hid;
124 void
125 hid_lpr_init ()
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";
135 lpr_hid.printer = 1;
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);