hid/gcode: Make gcode_hid structure static
[geda-pcb/pcjc2.git] / src / hid / batch / batch.c
blobf49bc1940ad9a456ad49a865d6ce98f2cdedfebb
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 <unistd.h>
11 #include "global.h"
12 #include "hid.h"
13 #include "data.h"
14 #include "misc.h"
15 #include "hid.h"
16 #include "../hidint.h"
17 #include "pcb-printf.h"
19 #include "hid/common/draw_helpers.h"
20 #include "hid/common/hidnogui.h"
21 #include "hid/common/actions.h"
22 #include "hid/common/hidinit.h"
24 #ifdef HAVE_LIBDMALLOC
25 #include <dmalloc.h>
26 #endif
28 /* This is a text-line "batch" HID, which exists for scripting and
29 non-GUI needs. */
31 typedef struct hid_gc_struct
33 int nothing_interesting_here;
34 } hid_gc_struct;
36 static HID_Attribute *
37 batch_get_export_options (int *n_ret)
39 return 0;
42 /* ----------------------------------------------------------------------------- */
44 static char *prompt = "pcb";
46 static int
47 nop (int argc, char **argv, Coord x, Coord y)
49 return 0;
52 static int
53 PCBChanged (int argc, char **argv, Coord x, Coord y)
55 if (PCB && PCB->Filename)
57 prompt = strrchr(PCB->Filename, '/');
58 if (prompt)
59 prompt ++;
60 else
61 prompt = PCB->Filename;
63 else
64 prompt = "no-board";
65 return 0;
68 static int
69 help (int argc, char **argv, Coord x, Coord y)
71 print_actions ();
72 return 0;
75 static int
76 info (int argc, char **argv, Coord x, Coord y)
78 int i, j;
79 int cg, sg;
80 if (!PCB || !PCB->Data || !PCB->Filename)
82 printf("No PCB loaded.\n");
83 return 0;
85 printf("Filename: %s\n", PCB->Filename);
86 pcb_printf("Size: %ml x %ml mils, %mm x %mm mm\n",
87 PCB->MaxWidth, PCB->MaxHeight,
88 PCB->MaxWidth, PCB->MaxHeight);
89 cg = GetLayerGroupNumberByNumber (component_silk_layer);
90 sg = GetLayerGroupNumberByNumber (solder_silk_layer);
91 for (i=0; i<MAX_LAYER; i++)
94 int lg = GetLayerGroupNumberByNumber (i);
95 for (j=0; j<MAX_LAYER; j++)
96 putchar(j==lg ? '#' : '-');
97 printf(" %c %s\n", lg==cg ? 'c' : lg==sg ? 's' : '-',
98 PCB->Data->Layer[i].Name);
100 return 0;
104 HID_Action batch_action_list[] = {
105 {"PCBChanged", 0, PCBChanged },
106 {"RouteStylesChanged", 0, nop },
107 {"NetlistChanged", 0, nop },
108 {"LayersChanged", 0, nop },
109 {"LibraryChanged", 0, nop },
110 {"Busy", 0, nop },
111 {"Help", 0, help },
112 {"Info", 0, info }
115 REGISTER_ACTIONS (batch_action_list)
118 /* ----------------------------------------------------------------------------- */
120 static void
121 batch_do_export (HID_Attr_Val * options)
123 int interactive;
124 char line[1000];
126 if (isatty (0))
127 interactive = 1;
128 else
129 interactive = 0;
131 if (interactive)
133 printf("Entering %s version %s batch mode.\n", PACKAGE, VERSION);
134 printf("See http://pcb.geda-project.org for project information\n");
136 while (1)
138 if (interactive)
140 printf("%s> ", prompt);
141 fflush(stdout);
143 if (fgets(line, sizeof(line)-1, stdin) == NULL)
144 return;
145 hid_parse_command (line);
149 static void
150 batch_parse_arguments (int *argc, char ***argv)
152 hid_parse_command_line (argc, argv);
155 static void
156 batch_invalidate_lr (int l, int r, int t, int b)
160 static void
161 batch_invalidate_all (void)
165 static int
166 batch_set_layer (const char *name, int idx, int empty)
168 return 0;
171 static hidGC
172 batch_make_gc (void)
174 return 0;
177 static void
178 batch_destroy_gc (hidGC gc)
182 static void
183 batch_use_mask (int use_it)
187 static void
188 batch_set_color (hidGC gc, const char *name)
192 static void
193 batch_set_line_cap (hidGC gc, EndCapStyle style)
197 static void
198 batch_set_line_width (hidGC gc, Coord width)
202 static void
203 batch_set_draw_xor (hidGC gc, int xor_set)
207 static void
208 batch_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
212 static void
213 batch_draw_arc (hidGC gc, Coord cx, Coord cy, Coord width, Coord height,
214 Angle start_angle, Angle end_angle)
218 static void
219 batch_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
223 static void
224 batch_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius)
228 static void
229 batch_fill_polygon (hidGC gc, int n_coords, Coord *x, Coord *y)
233 static void
234 batch_fill_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
238 static void
239 batch_calibrate (double xval, double yval)
243 static int
244 batch_shift_is_pressed (void)
246 return 0;
249 static int
250 batch_control_is_pressed (void)
252 return 0;
255 static int
256 batch_mod1_is_pressed (void)
258 return 0;
261 static void
262 batch_get_coords (const char *msg, Coord *x, Coord *y)
266 static void
267 batch_set_crosshair (int x, int y, int action)
271 static hidval
272 batch_add_timer (void (*func) (hidval user_data),
273 unsigned long milliseconds, hidval user_data)
275 hidval rv;
276 rv.lval = 0;
277 return rv;
280 static void
281 batch_stop_timer (hidval timer)
285 hidval
286 batch_watch_file (int fd, unsigned int condition, void (*func) (hidval watch, int fd, unsigned int condition, hidval user_data),
287 hidval user_data)
289 hidval ret;
290 ret.ptr = NULL;
291 return ret;
294 void
295 batch_unwatch_file (hidval data)
299 static hidval
300 batch_add_block_hook (void (*func) (hidval data), hidval user_data )
302 hidval ret;
303 ret.ptr = NULL;
304 return ret;
307 static void
308 batch_stop_block_hook (hidval mlpoll)
312 static int
313 batch_attribute_dialog (HID_Attribute * attrs_,
314 int n_attrs_, HID_Attr_Val * results_,
315 const char *title_, const char *descr_)
317 return 0;
320 static void
321 batch_show_item (void *item)
325 #include "dolists.h"
327 static HID batch_hid;
329 void
330 hid_batch_init ()
332 memset (&batch_hid, 0, sizeof (HID));
334 common_nogui_init (&batch_hid);
335 common_draw_helpers_init (&batch_hid);
337 batch_hid.struct_size = sizeof (HID);
338 batch_hid.name = "batch";
339 batch_hid.description = "Batch-mode GUI for non-interactive use.";
340 batch_hid.gui = 1;
342 batch_hid.get_export_options = batch_get_export_options;
343 batch_hid.do_export = batch_do_export;
344 batch_hid.parse_arguments = batch_parse_arguments;
345 batch_hid.invalidate_lr = batch_invalidate_lr;
346 batch_hid.invalidate_all = batch_invalidate_all;
347 batch_hid.set_layer = batch_set_layer;
348 batch_hid.make_gc = batch_make_gc;
349 batch_hid.destroy_gc = batch_destroy_gc;
350 batch_hid.use_mask = batch_use_mask;
351 batch_hid.set_color = batch_set_color;
352 batch_hid.set_line_cap = batch_set_line_cap;
353 batch_hid.set_line_width = batch_set_line_width;
354 batch_hid.set_draw_xor = batch_set_draw_xor;
355 batch_hid.draw_line = batch_draw_line;
356 batch_hid.draw_arc = batch_draw_arc;
357 batch_hid.draw_rect = batch_draw_rect;
358 batch_hid.fill_circle = batch_fill_circle;
359 batch_hid.fill_polygon = batch_fill_polygon;
360 batch_hid.fill_rect = batch_fill_rect;
361 batch_hid.calibrate = batch_calibrate;
362 batch_hid.shift_is_pressed = batch_shift_is_pressed;
363 batch_hid.control_is_pressed = batch_control_is_pressed;
364 batch_hid.mod1_is_pressed = batch_mod1_is_pressed;
365 batch_hid.get_coords = batch_get_coords;
366 batch_hid.set_crosshair = batch_set_crosshair;
367 batch_hid.add_timer = batch_add_timer;
368 batch_hid.stop_timer = batch_stop_timer;
369 batch_hid.watch_file = batch_watch_file;
370 batch_hid.unwatch_file = batch_unwatch_file;
371 batch_hid.add_block_hook = batch_add_block_hook;
372 batch_hid.stop_block_hook = batch_stop_block_hook;
373 batch_hid.attribute_dialog = batch_attribute_dialog;
374 batch_hid.show_item = batch_show_item;
376 hid_register_hid (&batch_hid);
377 #include "batch_lists.h"