pcb 4.1.1
An interactive printed circuit board layout editor.
|
00001 #ifdef HAVE_CONFIG_H 00002 #include "config.h" 00003 #endif 00004 00005 #include <stdio.h> 00006 #include <stdarg.h> 00007 #include <stdlib.h> 00008 #include <string.h> 00009 #include <assert.h> 00010 00011 #include "global.h" 00012 #include "data.h" 00013 #include "misc.h" 00014 00015 #include "hid.h" 00016 #include "../hidint.h" 00017 #include "../ps/ps.h" 00018 #include "hid/common/hidnogui.h" 00019 #include "hid/common/hidinit.h" 00020 00021 #ifdef HAVE_LIBDMALLOC 00022 #include <dmalloc.h> 00023 #endif 00024 00025 #define CRASH fprintf(stderr, \ 00026 _("HID error: pcb called unimplemented PS function %s.\n"), \ 00027 __FUNCTION__); abort() 00028 00029 static HID_Attribute base_lpr_options[] = { 00030 00031 /* %start-doc options "98 lpr Printing Options" 00032 @ftable @code 00033 @item --lprcommand <string> 00034 Command to use for printing. Defaults to @code{lpr}. This can be used to produce 00035 PDF output with a virtual PDF printer. Example: @* 00036 @code{--lprcommand "lp -d CUPS-PDF-Printer"}. 00037 @end ftable 00038 @noindent In addition, all @ref{Postscript Export} options are valid. 00039 %end-doc 00040 */ 00041 {N_("lprcommand"), N_("Command to use for printing"), 00042 HID_String, 0, 0, {0, 0, 0}, 0, 0}, 00043 #define HA_lprcommand 0 00044 }; 00045 00046 #define NUM_OPTIONS (sizeof(lpr_options)/sizeof(lpr_options[0])) 00047 00048 static HID_Attribute *lpr_options = 0; 00049 static int num_lpr_options = 0; 00050 static HID_Attr_Val *lpr_values; 00051 00052 static HID_Attribute * 00053 lpr_get_export_options (int *n) 00054 { 00055 /* 00056 * We initialize the default value in this manner because the GUI 00057 * HID's may want to free() this string value and replace it with a 00058 * new one based on how a user fills out a print dialog. 00059 */ 00060 if (base_lpr_options[HA_lprcommand].default_val.str_value == NULL) 00061 { 00062 base_lpr_options[HA_lprcommand].default_val.str_value = strdup("lpr"); 00063 } 00064 00065 if (lpr_options == 0) 00066 { 00067 HID_Attribute *ps_opts = ps_hid.get_export_options (&num_lpr_options); 00068 lpr_options = 00069 (HID_Attribute *) calloc (num_lpr_options, sizeof (HID_Attribute)); 00070 memcpy (lpr_options, ps_opts, num_lpr_options * sizeof (HID_Attribute)); 00071 memcpy (lpr_options, base_lpr_options, sizeof (base_lpr_options)); 00072 lpr_values = 00073 (HID_Attr_Val *) calloc (num_lpr_options, sizeof (HID_Attr_Val)); 00074 } 00075 if (n) 00076 *n = num_lpr_options; 00077 return lpr_options; 00078 } 00079 00080 static void 00081 lpr_do_export (HID_Attr_Val * options) 00082 { 00083 FILE *f; 00084 int i; 00085 const char *filename; 00086 00087 if (!options) 00088 { 00089 lpr_get_export_options (0); 00090 for (i = 0; i < num_lpr_options; i++) 00091 lpr_values[i] = lpr_options[i].default_val; 00092 options = lpr_values; 00093 } 00094 00095 filename = options[HA_lprcommand].str_value; 00096 00097 printf (_("LPR: open %s\n"), filename); 00098 f = popen (filename, "w"); 00099 if (!f) 00100 { 00101 perror (filename); 00102 return; 00103 } 00104 00105 ps_hid_export_to_file (f, options); 00106 00107 pclose (f); 00108 } 00109 00110 static void 00111 lpr_parse_arguments (int *argc, char ***argv) 00112 { 00113 lpr_get_export_options (0); 00114 hid_register_attributes (lpr_options, num_lpr_options); 00115 hid_parse_command_line (argc, argv); 00116 } 00117 00118 static void 00119 lpr_calibrate (double xval, double yval) 00120 { 00121 ps_calibrate_1 (xval, yval, 1); 00122 } 00123 00124 static HID lpr_hid; 00125 00126 void 00127 hid_lpr_init () 00128 { 00129 memset (&lpr_hid, 0, sizeof (HID)); 00130 00131 common_nogui_init (&lpr_hid); 00132 ps_ps_init (&lpr_hid); 00133 00134 lpr_hid.struct_size = sizeof (HID); 00135 lpr_hid.name = "lpr"; 00136 lpr_hid.description = N_("Postscript print"); 00137 lpr_hid.printer = 1; 00138 lpr_hid.poly_before = 1; 00139 00140 lpr_hid.get_export_options = lpr_get_export_options; 00141 lpr_hid.do_export = lpr_do_export; 00142 lpr_hid.parse_arguments = lpr_parse_arguments; 00143 lpr_hid.calibrate = lpr_calibrate; 00144 00145 hid_register_hid (&lpr_hid); 00146 }