/* $Id: batch.c,v 1.2 2006/05/15 01:08:36 djdelorie Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include "global.h" #include "hid.h" #include "data.h" #ifdef HAVE_LIBDMALLOC #include #endif RCSID ("$Id: batch.c,v 1.2 2006/05/15 01:08:36 djdelorie Exp $"); /* This is a text-line "batch" HID, which exists for scripting and non-GUI needs. */ typedef struct hid_gc_struct { int nothing_interesting_here; } hid_gc_struct; static HID_Attribute * batch_get_export_options (int *n_ret) { return 0; } /* ----------------------------------------------------------------------------- */ static char *prompt = "pcb"; static int nop (int argc, char **argv, int x, int y) { return 0; } static int PCBChanged (int argc, char **argv, int x, int y) { if (PCB && PCB->Filename) { prompt = strrchr(PCB->Filename, '/'); if (prompt) prompt ++; else prompt = PCB->Filename; } else prompt = "no-board"; return 0; } static int help (int argc, char **argv, int x, int y) { print_actions (); return 0; } static int info (int argc, char **argv, int x, int y) { int i, j; int cg, sg; if (!PCB || !PCB->Data || !PCB->Filename) { printf("No PCB loaded.\n"); return 0; } printf("Filename: %s\n", PCB->Filename); printf("Size: %g x %g mils, %g x %g mm\n", PCB->MaxWidth / 100.0, PCB->MaxHeight / 100.0, PCB->MaxWidth * COOR_TO_MM, PCB->MaxHeight * COOR_TO_MM); cg = GetLayerGroupNumberByNumber (MAX_LAYER + COMPONENT_LAYER); sg = GetLayerGroupNumberByNumber (MAX_LAYER + SOLDER_LAYER); for (i=0; iData->Layer[i].Name); } return 0; } HID_Action batch_action_list[] = { {"PCBChanged", 0, PCBChanged }, {"RouteStylesChanged", 0, nop }, {"NetlistChanged", 0, nop }, {"LayersChanged", 0, nop }, {"LibraryChanged", 0, nop }, {"Help", 0, help }, {"Info", 0, info } }; REGISTER_ACTIONS (batch_action_list) /* ----------------------------------------------------------------------------- */ static void command_parse (char *s) { int n = 0, ws = 1; char *cp; char **argv; for (cp = s; *cp; cp++) { if (isspace ((int) *cp)) ws = 1; else { n += ws; ws = 0; } } argv = (char **) malloc ((n + 1) * sizeof (char *)); n = 0; ws = 1; for (cp = s; *cp; cp++) { if (isspace ((int) *cp)) { ws = 1; *cp = 0; } else { if (ws) argv[n++] = cp; ws = 0; } } argv[n] = 0; hid_actionv (argv[0], n - 1, argv + 1); } static void batch_do_export (HID_Attr_Val * options) { int interactive; char line[1000]; if (isatty (0)) interactive = 1; else interactive = 0; if (interactive) { printf("Entering %s version %s batch mode.\n", PACKAGE, VERSION); printf("See http://pcb.sourceforge.net for project information\n"); } while (1) { if (interactive) { printf("%s> ", prompt); fflush(stdout); } if (fgets(line, sizeof(line)-1, stdin) == NULL) return; if (strchr (line, '(')) hid_parse_actions (line, 0); else command_parse (line); } } static void batch_parse_arguments (int *argc, char ***argv) { hid_parse_command_line (argc, argv); } static void batch_invalidate_wh (int x, int y, int width, int height, int last) { } static void batch_invalidate_lr (int l, int r, int t, int b, int last) { } static void batch_invalidate_all (void) { } static int batch_set_layer (const char *name, int idx) { return 0; } static hidGC batch_make_gc (void) { return 0; } static void batch_destroy_gc (hidGC gc) { } static void batch_use_mask (int use_it) { } static void batch_set_color (hidGC gc, const char *name) { } static void batch_set_line_cap (hidGC gc, EndCapStyle style) { } static void batch_set_line_width (hidGC gc, int width) { } static void batch_set_draw_xor (hidGC gc, int xor) { } static void batch_set_draw_faded (hidGC gc, int faded) { } static void batch_set_line_cap_angle (hidGC gc, int x1, int y1, int x2, int y2) { } static void batch_draw_line (hidGC gc, int x1, int y1, int x2, int y2) { } static void batch_draw_arc (hidGC gc, int cx, int cy, int width, int height, int start_angle, int end_angle) { } static void batch_draw_rect (hidGC gc, int x1, int y1, int x2, int y2) { } static void batch_fill_circle (hidGC gc, int cx, int cy, int radius) { } static void batch_fill_polygon (hidGC gc, int n_coords, int *x, int *y) { } static void batch_fill_rect (hidGC gc, int x1, int y1, int x2, int y2) { } static void batch_calibrate (double xval, double yval) { } static int batch_shift_is_pressed (void) { return 0; } static int batch_control_is_pressed (void) { return 0; } static void batch_get_coords (const char *msg, int *x, int *y) { } static void batch_set_crosshair (int x, int y) { } static hidval batch_add_timer (void (*func) (hidval user_data), unsigned long milliseconds, hidval user_data) { hidval rv; rv.lval = 0; return rv; } static void batch_stop_timer (hidval timer) { } static void batch_log (const char *fmt, ...) { va_list ap; va_start (ap, fmt); vprintf (fmt, ap); va_end (ap); } static void batch_logv (const char *fmt, va_list ap) { vprintf (fmt, ap); } static int batch_confirm_dialog (char *msg, ...) { int rv; printf ("%s ? 0=cancel 1=ok : ", msg); fflush (stdout); scanf ("%d", &rv); return rv; } static void batch_report_dialog (char *title, char *msg) { printf ("--- %s ---\n%s\n", title, msg); } static char * batch_prompt_for (char *msg, char *default_string) { static char buf[1024]; if (default_string) printf ("%s [%s] : ", msg, default_string); else printf ("%s : ", msg); fgets (buf, 1024, stdin); if (buf[0] == 0 && default_string) strcpy (buf, default_string); return buf; } static int batch_attribute_dialog (HID_Attribute * attrs, int n_attrs, HID_Attr_Val * results) { } static void batch_show_item (void *item) { } static void batch_beep (void) { putchar (7); fflush (stdout); } HID batch_gui = { "batch", "Batch-mode GUI for non-interactive use.", 1, 0, 0, 0, 0, batch_get_export_options, batch_do_export, batch_parse_arguments, batch_invalidate_wh, batch_invalidate_lr, batch_invalidate_all, batch_set_layer, batch_make_gc, batch_destroy_gc, batch_use_mask, batch_set_color, batch_set_line_cap, batch_set_line_width, batch_set_draw_xor, batch_set_draw_faded, batch_set_line_cap_angle, batch_draw_line, batch_draw_arc, batch_draw_rect, batch_fill_circle, batch_fill_polygon, batch_fill_rect, batch_calibrate, batch_shift_is_pressed, batch_control_is_pressed, batch_get_coords, batch_set_crosshair, batch_add_timer, batch_stop_timer, batch_log, batch_logv, batch_confirm_dialog, batch_report_dialog, batch_prompt_for, batch_attribute_dialog, batch_show_item, batch_beep }; #include "dolists.h" void hid_batch_init () { hid_register_hid (&batch_gui); #include "batch_lists.h" }