Convert mask type to enum
[geda-pcb/pcjc2.git] / src / hid / common / hidnogui.c
bloba6ae852eb0284f11da190e47cf7f578a20db07c8
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>
10 #include "global.h"
11 #include "hid.h"
13 #ifdef HAVE_LIBDMALLOC
14 #include <dmalloc.h>
15 #endif
17 /* This is the "gui" that is installed at startup, and is used when
18 there is no other real GUI to use. For the most part, it just
19 stops the application from (1) crashing randomly, and (2) doing
20 gui-specific things when it shouldn't. */
22 #define CRASH fprintf(stderr, "HID error: pcb called GUI function %s without having a GUI available.\n", __FUNCTION__); abort()
24 typedef struct hid_gc_struct
26 int nothing_interesting_here;
27 } hid_gc_struct;
29 static HID_Attribute *
30 nogui_get_export_options (int *n_ret)
32 CRASH;
33 return 0;
36 static void
37 nogui_do_export (HID_Attr_Val * options)
39 CRASH;
42 static void
43 nogui_parse_arguments (int *argc, char ***argv)
45 CRASH;
48 static void
49 nogui_invalidate_lr (int l, int r, int t, int b)
51 CRASH;
54 static void
55 nogui_invalidate_all (void)
57 CRASH;
60 static int
61 nogui_set_layer (const char *name, int idx, int empty)
63 CRASH;
64 return 0;
67 static void
68 nogui_end_layer (void)
72 static hidGC
73 nogui_make_gc (void)
75 return 0;
78 static void
79 nogui_destroy_gc (hidGC gc)
83 static void
84 nogui_use_mask (enum mask_mode mode)
86 CRASH;
89 static void
90 nogui_set_color (hidGC gc, const char *name)
92 CRASH;
95 static void
96 nogui_set_line_cap (hidGC gc, EndCapStyle style)
98 CRASH;
101 static void
102 nogui_set_line_width (hidGC gc, Coord width)
104 CRASH;
107 static void
108 nogui_set_draw_xor (hidGC gc, int xor_)
110 CRASH;
113 static void
114 nogui_set_draw_faded (hidGC gc, int faded)
118 static void
119 nogui_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
121 CRASH;
124 static void
125 nogui_draw_arc (hidGC gc, Coord cx, Coord cy, Coord width, Coord height,
126 Angle start_angle, Angle end_angle)
128 CRASH;
131 static void
132 nogui_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
134 CRASH;
137 static void
138 nogui_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius)
140 CRASH;
143 static void
144 nogui_fill_polygon (hidGC gc, int n_coords, Coord *x, Coord *y)
146 CRASH;
149 static void
150 nogui_fill_pcb_polygon (hidGC gc, PolygonType *poly, const BoxType *clip_box)
152 CRASH;
155 static void
156 nogui_fill_pcb_pad (hidGC gc, PadType *pad, bool clear, bool mask)
158 CRASH;
161 static void
162 nogui_thindraw_pcb_pad (hidGC gc, PadType *pad, bool clear, bool mask)
164 CRASH;
167 static void
168 nogui_fill_pcb_pv (hidGC fg_gc, hidGC bg_gc, PinType *pad, bool drawHole, bool mask)
170 CRASH;
173 static void
174 nogui_thindraw_pcb_pv (hidGC fg_gc, hidGC bg_gc, PinType *pad, bool drawHole, bool mask)
176 CRASH;
179 static void
180 nogui_fill_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
182 CRASH;
185 static void
186 nogui_calibrate (double xval, double yval)
188 CRASH;
191 static int
192 nogui_shift_is_pressed (void)
194 /* This is called from FitCrosshairIntoGrid() when the board is loaded. */
195 return 0;
198 static int
199 nogui_control_is_pressed (void)
201 CRASH;
202 return 0;
205 static int
206 nogui_mod1_is_pressed (void)
208 CRASH;
209 return 0;
212 static void
213 nogui_get_coords (const char *msg, Coord *x, Coord *y)
215 CRASH;
218 static void
219 nogui_set_crosshair (int x, int y, int action)
223 static hidval
224 nogui_add_timer (void (*func) (hidval user_data),
225 unsigned long milliseconds, hidval user_data)
227 hidval rv;
228 CRASH;
229 rv.lval = 0;
230 return rv;
233 static void
234 nogui_stop_timer (hidval timer)
236 CRASH;
239 static hidval
240 nogui_watch_file (int fd, unsigned int condition, void (*func) (hidval watch, int fd, unsigned int condition, hidval user_data),
241 hidval user_data)
243 hidval rv;
244 CRASH;
245 rv.lval = 0;
246 return rv;
249 static void
250 nogui_unwatch_file (hidval watch)
252 CRASH;
255 static hidval
256 nogui_add_block_hook (void (*func) (hidval data), hidval data)
258 hidval rv;
259 CRASH;
260 rv.ptr = NULL;
261 return rv;
264 static void
265 nogui_stop_block_hook (hidval block_hook)
267 CRASH;
270 static void
271 nogui_log (const char *fmt, ...)
273 va_list ap;
274 va_start (ap, fmt);
275 vprintf (fmt, ap);
276 va_end (ap);
279 static void
280 nogui_logv (const char *fmt, va_list ap)
282 vprintf (fmt, ap);
285 /* Return a line of user input text, stripped of any newline characters.
286 * Returns NULL if the user simply presses enter, or otherwise gives no input.
288 #define MAX_LINE_LENGTH 1024
289 static char *
290 read_stdin_line (void)
292 static char buf[MAX_LINE_LENGTH];
293 char *s;
294 int i;
296 s = fgets (buf, MAX_LINE_LENGTH, stdin);
297 if (s == NULL)
299 printf ("\n");
300 return NULL;
303 /* Strip any trailing newline characters */
304 for (i = strlen (s) - 1; i >= 0; i--)
305 if (s[i] == '\r' || s[i] == '\n')
306 s[i] = '\0';
308 if (s[0] == '\0')
309 return NULL;
311 return strdup (s);
313 #undef MAX_LINE_LENGTH
315 static int
316 nogui_confirm_dialog (char *msg, ...)
318 char *answer;
319 int ret = 0;
320 bool valid_answer = false;
321 va_list args;
325 va_start (args, msg);
326 vprintf (msg, args);
327 va_end (args);
329 printf (" ? 0=cancel 1 = ok : ");
331 answer = read_stdin_line ();
333 if (answer == NULL)
334 continue;
336 if (answer[0] == '0' && answer[1] == '\0')
338 ret = 0;
339 valid_answer = true;
342 if (answer[0] == '1' && answer[1] == '\0')
344 ret = 1;
345 valid_answer = true;
348 free (answer);
350 while (!valid_answer);
351 return ret;
354 static int
355 nogui_close_confirm_dialog ()
357 return nogui_confirm_dialog (_("OK to lose data ?"), NULL);
360 static void
361 nogui_report_dialog (char *title, char *msg)
363 printf ("--- %s ---\n%s\n", title, msg);
366 static char *
367 nogui_prompt_for (const char *msg, const char *default_string)
369 char *answer;
371 if (default_string)
372 printf ("%s [%s] : ", msg, default_string);
373 else
374 printf ("%s : ", msg);
376 answer = read_stdin_line ();
377 if (answer == NULL)
378 return strdup ((default_string != NULL) ? default_string : "");
379 else
380 return answer;
383 /* FIXME - this could use some enhancement to actually use the other
384 args */
385 static char *
386 nogui_fileselect (const char *title, const char *descr,
387 char *default_file, char *default_ext,
388 const char *history_tag, int flags)
390 char *answer;
392 if (default_file)
393 printf ("%s [%s] : ", title, default_file);
394 else
395 printf ("%s : ", title);
397 answer = read_stdin_line ();
398 if (answer == NULL)
399 return (default_file != NULL) ? strdup (default_file) : NULL;
400 else
401 return answer;
404 static int
405 nogui_attribute_dialog (HID_Attribute * attrs,
406 int n_attrs, HID_Attr_Val * results,
407 const char * title, const char * descr)
409 CRASH;
412 static void
413 nogui_show_item (void *item)
415 CRASH;
418 static void
419 nogui_beep (void)
421 putchar (7);
422 fflush (stdout);
425 static int
426 nogui_progress (int so_far, int total, const char *message)
428 return 0;
431 static HID *
432 nogui_request_debug_draw (void)
434 return NULL;
437 static void
438 nogui_flush_debug_draw (void)
442 static void
443 nogui_finish_debug_draw (void)
447 void
448 common_nogui_init (HID *hid)
450 hid->get_export_options = nogui_get_export_options;
451 hid->do_export = nogui_do_export;
452 hid->parse_arguments = nogui_parse_arguments;
453 hid->invalidate_lr = nogui_invalidate_lr;
454 hid->invalidate_all = nogui_invalidate_all;
455 hid->set_layer = nogui_set_layer;
456 hid->end_layer = nogui_end_layer;
457 hid->make_gc = nogui_make_gc;
458 hid->destroy_gc = nogui_destroy_gc;
459 hid->use_mask = nogui_use_mask;
460 hid->set_color = nogui_set_color;
461 hid->set_line_cap = nogui_set_line_cap;
462 hid->set_line_width = nogui_set_line_width;
463 hid->set_draw_xor = nogui_set_draw_xor;
464 hid->set_draw_faded = nogui_set_draw_faded;
465 hid->draw_line = nogui_draw_line;
466 hid->draw_arc = nogui_draw_arc;
467 hid->draw_rect = nogui_draw_rect;
468 hid->fill_circle = nogui_fill_circle;
469 hid->fill_polygon = nogui_fill_polygon;
470 hid->fill_pcb_polygon = nogui_fill_pcb_polygon;
471 hid->fill_pcb_pad = nogui_fill_pcb_pad;
472 hid->thindraw_pcb_pad = nogui_thindraw_pcb_pad;
473 hid->fill_pcb_pv = nogui_fill_pcb_pv;
474 hid->thindraw_pcb_pv = nogui_thindraw_pcb_pv;
475 hid->fill_rect = nogui_fill_rect;
476 hid->calibrate = nogui_calibrate;
477 hid->shift_is_pressed = nogui_shift_is_pressed;
478 hid->control_is_pressed = nogui_control_is_pressed;
479 hid->mod1_is_pressed = nogui_mod1_is_pressed;
480 hid->get_coords = nogui_get_coords;
481 hid->set_crosshair = nogui_set_crosshair;
482 hid->add_timer = nogui_add_timer;
483 hid->stop_timer = nogui_stop_timer;
484 hid->watch_file = nogui_watch_file;
485 hid->unwatch_file = nogui_unwatch_file;
486 hid->add_block_hook = nogui_add_block_hook;
487 hid->stop_block_hook = nogui_stop_block_hook;
488 hid->log = nogui_log;
489 hid->logv = nogui_logv;
490 hid->confirm_dialog = nogui_confirm_dialog;
491 hid->close_confirm_dialog = nogui_close_confirm_dialog;
492 hid->report_dialog = nogui_report_dialog;
493 hid->prompt_for = nogui_prompt_for;
494 hid->fileselect = nogui_fileselect;
495 hid->attribute_dialog = nogui_attribute_dialog;
496 hid->show_item = nogui_show_item;
497 hid->beep = nogui_beep;
498 hid->progress = nogui_progress;
499 hid->request_debug_draw = nogui_request_debug_draw;
500 hid->flush_debug_draw = nogui_flush_debug_draw;
501 hid->finish_debug_draw = nogui_finish_debug_draw;
504 static HID nogui_hid;
506 HID *
507 hid_nogui_get_hid (void)
509 memset (&nogui_hid, 0, sizeof (HID));
511 nogui_hid.struct_size = sizeof (HID);
512 nogui_hid.name = "nogui";
513 nogui_hid.description = "Default GUI when no other GUI is present. "
514 "Does nothing.";
516 common_nogui_init (&nogui_hid);
518 return &nogui_hid;