Index: trunk/src/global_typedefs.h =================================================================== --- trunk/src/global_typedefs.h (revision 26932) +++ trunk/src/global_typedefs.h (revision 26933) @@ -102,6 +102,10 @@ pcb_core_gc_t core_gc; */ typedef struct hid_gc_s *pcb_hid_gc_t; +typedef struct pcb_hid_attr_val_s pcb_hid_attr_val_t; +typedef struct pcb_hid_attribute_s pcb_hid_attribute_t; +typedef struct pcb_export_opt_s pcb_export_opt_t; + #include "pcb_bool.h" #endif Index: trunk/src/hid.h =================================================================== --- trunk/src/hid.h (revision 26932) +++ trunk/src/hid.h (revision 26933) @@ -24,11 +24,6 @@ PCB_HID_MOUSE_POPUP /* "right click", open context-specific popup */ } pcb_hid_mouse_ev_t; - -typedef struct pcb_hid_attr_val_s pcb_hid_attr_val_t; -typedef struct pcb_hid_attribute_s pcb_hid_attribute_t; -typedef struct pcb_hid_attribute_s pcb_export_opt_t; - /* Human Interface Device */ /* @@ -406,7 +401,7 @@ by window placement. Returns opaque hid_ctx. (Hid_ctx shall save pcb_hid_t so subsequent attr_dlg_*() calls don't have it as an argument) */ - void *(*attr_dlg_new)(pcb_hid_t *hid, const char *id, pcb_export_opt_t *attrs, int n_attrs, pcb_hid_attr_val_t *results, const char *title, void *caller_data, pcb_bool modal, void (*button_cb)(void *caller_data, pcb_hid_attr_ev_t ev), int defx, int defy, int minx, int miny); + void *(*attr_dlg_new)(pcb_hid_t *hid, const char *id, pcb_hid_attribute_t *attrs, int n_attrs, pcb_hid_attr_val_t *results, const char *title, void *caller_data, pcb_bool modal, void (*button_cb)(void *caller_data, pcb_hid_attr_ev_t ev), int defx, int defy, int minx, int miny); int (*attr_dlg_run)(void *hid_ctx); void (*attr_dlg_raise)(void *hid_ctx); /* raise the window to top */ void (*attr_dlg_free)(void *hid_ctx); /* results_ is avalibale after this call */ @@ -620,7 +615,7 @@ /* non-zero if DAD dialogs are available currently */ #define PCB_HAVE_GUI_ATTR_DLG \ ((pcb_gui != NULL) && (pcb_gui->gui) && (pcb_gui->attr_dlg_new != NULL) && (pcb_gui->attr_dlg_new != pcb_nogui_attr_dlg_new)) -void *pcb_nogui_attr_dlg_new(pcb_hid_t *hid, const char *id, pcb_export_opt_t *attrs_, int n_attrs_, pcb_hid_attr_val_t * results_, const char *title_, void *caller_data, pcb_bool modal, void (*button_cb)(void *caller_data, pcb_hid_attr_ev_t ev), int defx, int defy, int minx, int miny); +void *pcb_nogui_attr_dlg_new(pcb_hid_t *hid, const char *id, pcb_hid_attribute_t *attrs_, int n_attrs_, pcb_hid_attr_val_t * results_, const char *title_, void *caller_data, pcb_bool modal, void (*button_cb)(void *caller_data, pcb_hid_attr_ev_t ev), int defx, int defy, int minx, int miny); int pcb_hid_dock_enter(pcb_hid_dad_subdialog_t *sub, pcb_hid_dock_t where, const char *id); void pcb_hid_dock_leave(pcb_hid_dad_subdialog_t *sub); Index: trunk/src/hid_attrib.c =================================================================== --- trunk/src/hid_attrib.c (revision 26932) +++ trunk/src/hid_attrib.c (revision 26933) @@ -73,7 +73,7 @@ return 0; } -void pcb_hid_register_attributes(pcb_hid_attribute_t * a, int n, const char *cookie, int copy) +void pcb_hid_register_attributes(pcb_export_opt_t *a, int n, const char *cookie, int copy) { pcb_hid_attr_node_t *ha; @@ -81,7 +81,7 @@ ha = malloc(sizeof(pcb_hid_attr_node_t)); ha->next = hid_attr_nodes; hid_attr_nodes = ha; - ha->attributes = a; + ha->opts = a; ha->n = n; ha->cookie = cookie; } @@ -92,7 +92,7 @@ for (ha = hid_attr_nodes; ha; ha = next) { next = ha->next; if (ha->cookie != NULL) - fprintf(stderr, "WARNING: attribute %s by %s is not uninited, check your plugins' uninit!\n", ha->attributes->name, ha->cookie); + fprintf(stderr, "WARNING: attribute %s by %s is not uninited, check your plugins' uninit!\n", ha->opts->name, ha->cookie); free(ha); } hid_attr_nodes = NULL; @@ -123,7 +123,7 @@ for (ha = hid_attr_nodes; ha; ha = ha->next) for (i = 0; i < ha->n; i++) { - pcb_hid_attribute_t *a = ha->attributes + i; + pcb_export_opt_t *a = ha->opts + i; switch (a->type) { case PCB_HATT_LABEL: break; @@ -171,11 +171,11 @@ try_no_arg: for (ha = hid_attr_nodes; ha; ha = ha->next) for (i = 0; i < ha->n; i++) - if (strcmp((*argv)[0] + arg_ofs, ha->attributes[i].name) == 0) { - pcb_hid_attribute_t *a = ha->attributes + i; + if (strcmp((*argv)[0] + arg_ofs, ha->opts[i].name) == 0) { + pcb_export_opt_t *a = ha->opts + i; char *ep; const pcb_unit_t *unit; - switch (ha->attributes[i].type) { + switch (ha->opts[i].type) { case PCB_HATT_LABEL: break; case PCB_HATT_INTEGER: @@ -288,7 +288,7 @@ fprintf(stderr, "%-20s %s\n", name, help); } -void pcb_hid_usage(pcb_hid_attribute_t * a, int numa) +void pcb_hid_usage(pcb_export_opt_t *a, int numa) { for (; numa > 0; numa--,a++) { const char *help; Index: trunk/src/hid_attrib.h =================================================================== --- trunk/src/hid_attrib.h (revision 26932) +++ trunk/src/hid_attrib.h (revision 26933) @@ -210,7 +210,22 @@ unsigned int hatt_flags; }; -extern void pcb_hid_register_attributes(pcb_hid_attribute_t *, int, const char *cookie, int copy); +struct pcb_export_opt_s { + const char *name; + const char *help_text; + pcb_hids_t type; + double min_val, max_val; /* for integer and real */ + pcb_hid_attr_val_t default_val; + const char **enumerations; /* NULL terminated list of values for a PCB_HATT_ENUM */ + + + /* If set, this is used for global attributes (i.e. those set + statically with REGISTER_ATTRIBUTES below) instead of changing + the default_val. */ + void *value; +}; + +extern void pcb_hid_register_attributes(pcb_export_opt_t *, int, const char *cookie, int copy); #define PCB_REGISTER_ATTRIBUTES(a, cookie) PCB_HIDCONCAT(void register_,a) ()\ { pcb_hid_register_attributes(a, sizeof(a)/sizeof(a[0]), cookie, 0); } @@ -222,7 +237,7 @@ typedef struct pcb_hid_attr_node_s { struct pcb_hid_attr_node_s *next; - pcb_hid_attribute_t *attributes; + pcb_export_opt_t *opts; int n; const char *cookie; } pcb_hid_attr_node_t; @@ -229,7 +244,7 @@ extern pcb_hid_attr_node_t *hid_attr_nodes; -void pcb_hid_usage(pcb_hid_attribute_t * a, int numa); +void pcb_hid_usage(pcb_export_opt_t *a, int numa); void pcb_hid_usage_option(const char *name, const char *help); /* Count the number of direct children, start_from the first children */ Index: trunk/src/hid_dad.h =================================================================== --- trunk/src/hid_dad.h (revision 26932) +++ trunk/src/hid_dad.h (revision 26933) @@ -344,7 +344,22 @@ PCB_DAD_UPDATE_INTERNAL(table, table ## _len-1); \ } while(0) +#define PCB_DAD_DUP_EXPOPT(table, opt) \ +do { \ + pcb_export_opt_t *__opt__ = (opt); \ + PCB_DAD_ALLOC(table, 0); \ + table[table ## _len-1].name = __opt__->name; \ + table[table ## _len-1].help_text = __opt__->help_text; \ + table[table ## _len-1].type = __opt__->type; \ + table[table ## _len-1].min_val = __opt__->min_val; \ + table[table ## _len-1].max_val = __opt__->max_val; \ + table[table ## _len-1].default_val = __opt__->default_val; \ + table[table ## _len-1].enumerations = __opt__->enumerations; \ + table[table ## _len-1].value = __opt__->value; \ + PCB_DAD_UPDATE_INTERNAL(table, table ## _len-1); \ +} while(0) + /* Set properties of the current item */ #define PCB_DAD_MINVAL(table, val) PCB_DAD_SET_ATTR_FIELD(table, min_val, val) #define PCB_DAD_MAXVAL(table, val) PCB_DAD_SET_ATTR_FIELD(table, max_val, val) Index: trunk/src/hid_nogui.c =================================================================== --- trunk/src/hid_nogui.c (revision 26932) +++ trunk/src/hid_nogui.c (revision 26933) @@ -350,7 +350,7 @@ return pcb_strdup(answer); } -void *pcb_nogui_attr_dlg_new(pcb_hid_t *hid, const char *id, pcb_export_opt_t *attrs_, int n_attrs_, pcb_hid_attr_val_t * results_, const char *title_, void *caller_data, pcb_bool modal, void (*button_cb)(void *caller_data, pcb_hid_attr_ev_t ev), int defx, int defy, int minx, int miny) +void *pcb_nogui_attr_dlg_new(pcb_hid_t *hid, const char *id, pcb_hid_attribute_t *attrs_, int n_attrs_, pcb_hid_attr_val_t * results_, const char *title_, void *caller_data, pcb_bool modal, void (*button_cb)(void *caller_data, pcb_hid_attr_ev_t ev), int defx, int defy, int minx, int miny) { CRASH("attr_dlg_new"); } Index: trunk/src/hid_nogui.h =================================================================== --- trunk/src/hid_nogui.h (revision 26932) +++ trunk/src/hid_nogui.h (revision 26933) @@ -5,7 +5,7 @@ pcb_hid_t *pcb_hid_nogui_get_hid(void); /* For checking if attr dialogs are not available: */ -void *pcb_nogui_attr_dlg_new(pcb_hid_t *hid, const char *id, pcb_export_opt_t *attrs_, int n_attrs_, pcb_hid_attr_val_t * results_, const char *title_, void *caller_data, pcb_bool modal, void (*button_cb)(void *caller_data, pcb_hid_attr_ev_t ev), int defx, int defy, int minx, int miny); +void *pcb_nogui_attr_dlg_new(pcb_hid_t *hid, const char *id, pcb_hid_attribute_t *attrs_, int n_attrs_, pcb_hid_attr_val_t * results_, const char *title_, void *caller_data, pcb_bool modal, void (*button_cb)(void *caller_data, pcb_hid_attr_ev_t ev), int defx, int defy, int minx, int miny); int pcb_nogui_progress(long so_far, long total, const char *message); Index: trunk/src_plugins/cam/cam.c =================================================================== --- trunk/src_plugins/cam/cam.c (revision 26932) +++ trunk/src_plugins/cam/cam.c (revision 26933) @@ -208,7 +208,7 @@ PCB_REGISTER_ACTIONS(cam_action_list, cam_cookie) -static pcb_hid_attribute_t *export_cam_get_export_options(pcb_hid_t *hid, int *n) +static pcb_export_opt_t *export_cam_get_export_options(pcb_hid_t *hid, int *n) { return 0; } Index: trunk/src_plugins/dialogs/dlg_export.c =================================================================== --- trunk/src_plugins/dialogs/dlg_export.c (revision 26932) +++ trunk/src_plugins/dialogs/dlg_export.c (revision 26933) @@ -47,8 +47,8 @@ const char **tab_name; int **exp_attr; /* widget IDs of the attributes holding the actual data; outer array is indexed by exporter, inner array is by exporter option index from 0*/ int *button; /* widget ID of the export button for a specific exporter */ - int *numa; /* number of exporter attributes */ - pcb_hid_attribute_t **ea; /* original exporter attribute arrays */ + int *numo; /* number of exporter options */ + pcb_export_opt_t **ea; /* original export option arrays */ } export_ctx_t; export_ctx_t export_ctx; @@ -56,12 +56,12 @@ static pcb_hid_attr_val_t *get_results(export_ctx_t *export_ctx, int id) { pcb_hid_attr_val_t *r; - int *exp_attr, n, numa = export_ctx->numa[id]; + int *exp_attr, n, numo = export_ctx->numo[id]; - r = malloc(sizeof(pcb_hid_attr_val_t) * numa); + r = malloc(sizeof(pcb_hid_attr_val_t) * numo); exp_attr = export_ctx->exp_attr[id]; - for(n = 0; n < numa; n++) { + for(n = 0; n < numo; n++) { int src = exp_attr[n]; memcpy(&r[n], &(export_ctx->dlg[src].default_val), sizeof(pcb_hid_attr_val_t)); } @@ -111,10 +111,10 @@ for(n = 0; n < ctx->len; n++) { int *exp_attr = export_ctx.exp_attr[n]; - int numa = export_ctx.numa[n]; - pcb_hid_attribute_t *attrs = export_ctx.ea[n]; + int numo = export_ctx.numo[n]; + pcb_export_opt_t *attrs = export_ctx.ea[n]; - for(i = 0; i < numa; i++) + for(i = 0; i < numo; i++) memcpy(&attrs[i].default_val, &ctx->dlg[exp_attr[i]].default_val, sizeof(pcb_hid_attr_val_t)); } } @@ -133,7 +133,7 @@ free(ctx->exp_attr[n]); free(ctx->exp_attr); free(ctx->button); - free(ctx->numa); + free(ctx->numo); free(ctx->ea); memset(ctx, 0, sizeof(export_ctx_t)); /* reset all states to the initial - includes ctx->active = 0; */ } @@ -162,7 +162,7 @@ export_ctx.hid = malloc(sizeof(pcb_hid_t *) * (export_ctx.len)); export_ctx.exp_attr = malloc(sizeof(int *) * (export_ctx.len)); export_ctx.button = malloc(sizeof(int) * (export_ctx.len)); - export_ctx.numa = malloc(sizeof(int) * (export_ctx.len)); + export_ctx.numo = malloc(sizeof(int) * (export_ctx.len)); export_ctx.ea = malloc(sizeof(pcb_hid_attribute_t *) * (export_ctx.len)); for(i = n = 0; hids[n] != NULL; n++) { @@ -181,47 +181,47 @@ PCB_DAD_COMPFLAG(export_ctx.dlg, PCB_HATF_LEFT_TAB); export_ctx.tabs = PCB_DAD_CURRENT(export_ctx.dlg); for(n = 0; n < export_ctx.len; n++) { - int numa; - pcb_hid_attribute_t *attrs = export_ctx.hid[n]->get_export_options(export_ctx.hid[n], &numa); - export_ctx.numa[n] = numa; - export_ctx.ea[n] = attrs; - if (numa < 1) { + int numo; + pcb_export_opt_t *opts = export_ctx.hid[n]->get_export_options(export_ctx.hid[n], &numo); + export_ctx.numo[n] = numo; + export_ctx.ea[n] = opts; + if (numo < 1) { PCB_DAD_LABEL(export_ctx.dlg, "Exporter unavailable for direct export"); continue; } PCB_DAD_BEGIN_VBOX(export_ctx.dlg); - if (numa > 12) + if (numo > 12) PCB_DAD_COMPFLAG(export_ctx.dlg, PCB_HATF_SCROLL); - export_ctx.exp_attr[n] = exp_attr = malloc(sizeof(int) * numa); - for(i = 0; i < numa; i++) { + export_ctx.exp_attr[n] = exp_attr = malloc(sizeof(int) * numo); + for(i = 0; i < numo; i++) { PCB_DAD_BEGIN_HBOX(export_ctx.dlg) /* hid attributes are atomic while DAD widgets may be compound */ - switch(attrs[i].type) { + switch(opts[i].type) { case PCB_HATT_COORD: - PCB_DAD_COORD(export_ctx.dlg, attrs[i].name); - PCB_DAD_MINMAX(export_ctx.dlg, attrs[i].min_val, attrs[i].max_val); - PCB_DAD_DEFAULT_NUM(export_ctx.dlg, attrs[i].default_val.coord_value); + PCB_DAD_COORD(export_ctx.dlg, opts[i].name); + PCB_DAD_MINMAX(export_ctx.dlg, opts[i].min_val, opts[i].max_val); + PCB_DAD_DEFAULT_NUM(export_ctx.dlg, opts[i].default_val.coord_value); break; case PCB_HATT_INTEGER: - PCB_DAD_INTEGER(export_ctx.dlg, attrs[i].name); - PCB_DAD_MINMAX(export_ctx.dlg, attrs[i].min_val, attrs[i].max_val); - PCB_DAD_DEFAULT_NUM(export_ctx.dlg, attrs[i].default_val.int_value); + PCB_DAD_INTEGER(export_ctx.dlg, opts[i].name); + PCB_DAD_MINMAX(export_ctx.dlg, opts[i].min_val, opts[i].max_val); + PCB_DAD_DEFAULT_NUM(export_ctx.dlg, opts[i].default_val.int_value); break; case PCB_HATT_REAL: - PCB_DAD_REAL(export_ctx.dlg, attrs[i].name); - PCB_DAD_MINMAX(export_ctx.dlg, attrs[i].min_val, attrs[i].max_val); - PCB_DAD_DEFAULT_NUM(export_ctx.dlg, attrs[i].default_val.real_value); + PCB_DAD_REAL(export_ctx.dlg, opts[i].name); + PCB_DAD_MINMAX(export_ctx.dlg, opts[i].min_val, opts[i].max_val); + PCB_DAD_DEFAULT_NUM(export_ctx.dlg, opts[i].default_val.real_value); break; case PCB_HATT_UNIT: PCB_DAD_UNIT(export_ctx.dlg, PCB_UNIT_METRIC | PCB_UNIT_IMPERIAL); - PCB_DAD_DEFAULT_NUM(export_ctx.dlg, attrs[i].default_val.int_value); + PCB_DAD_DEFAULT_NUM(export_ctx.dlg, opts[i].default_val.int_value); break; default: - PCB_DAD_DUP_ATTR(export_ctx.dlg, attrs+i); + PCB_DAD_DUP_EXPOPT(export_ctx.dlg, &(opts[i])); } exp_attr[i] = PCB_DAD_CURRENT(export_ctx.dlg); - if (attrs[i].name != NULL) - PCB_DAD_LABEL(export_ctx.dlg, attrs[i].name); + if (opts[i].name != NULL) + PCB_DAD_LABEL(export_ctx.dlg, opts[i].name); PCB_DAD_END(export_ctx.dlg); } PCB_DAD_LABEL(export_ctx.dlg, " "); /* ugly way of inserting some vertical spacing */ Index: trunk/src_plugins/export_lpr/lpr.c =================================================================== --- trunk/src_plugins/export_lpr/lpr.c (revision 26932) +++ trunk/src_plugins/export_lpr/lpr.c (revision 26933) @@ -20,7 +20,7 @@ const char *lpr_cookie = "lpr HID"; -static pcb_hid_attribute_t base_lpr_options[] = { +static pcb_export_opt_t base_lpr_options[] = { /* %start-doc options "98 lpr Printing Options" @ftable @code @@ -39,11 +39,11 @@ #define NUM_OPTIONS (sizeof(lpr_options)/sizeof(lpr_options[0])) -static pcb_hid_attribute_t *lpr_options = 0; +static pcb_export_opt_t *lpr_options = 0; static int num_lpr_options = 0; static pcb_hid_attr_val_t *lpr_values; -static pcb_hid_attribute_t *lpr_get_export_options(pcb_hid_t *hid, int *n) +static pcb_export_opt_t *lpr_get_export_options(pcb_hid_t *hid, int *n) { /* * We initialize the default value in this manner because the GUI @@ -55,8 +55,8 @@ } if (lpr_options == 0) { - pcb_hid_attribute_t *ps_opts = ps_hid.get_export_options(&ps_hid, &num_lpr_options); - lpr_options = (pcb_hid_attribute_t *) calloc(num_lpr_options, sizeof(pcb_hid_attribute_t)); + pcb_export_opt_t *ps_opts = ps_hid.get_export_options(&ps_hid, &num_lpr_options); + lpr_options = calloc(num_lpr_options, sizeof(pcb_hid_attribute_t)); memcpy(lpr_options, ps_opts, num_lpr_options * sizeof(pcb_hid_attribute_t)); memcpy(lpr_options, base_lpr_options, sizeof(base_lpr_options)); lpr_values = (pcb_hid_attr_val_t *) calloc(num_lpr_options, sizeof(pcb_hid_attr_val_t)); Index: trunk/src_plugins/export_ps/ps.c =================================================================== --- trunk/src_plugins/export_ps/ps.c (revision 26932) +++ trunk/src_plugins/export_ps/ps.c (revision 26933) @@ -1238,7 +1238,7 @@ pcb_fprintf(global.f, "%mi %mi %mi %mi r\n", x1, y1, x2, y2); } -pcb_export_opt_t ps_calib_attribute_list[] = { +pcb_hid_attribute_t ps_calib_attribute_list[] = { {"lprcommand", "Command to print", PCB_HATT_STRING, 0, 0, {0, 0, 0}, 0, 0}, }; Index: trunk/src_plugins/hid_lesstif/main.c =================================================================== --- trunk/src_plugins/hid_lesstif/main.c (revision 26932) +++ trunk/src_plugins/hid_lesstif/main.c (revision 26933) @@ -1638,7 +1638,7 @@ for (ha = hid_attr_nodes; ha; ha = ha->next) for (i = 0; i < ha->n; i++) { - pcb_export_opt_t *a = ha->attributes + i; + pcb_export_opt_t *a = ha->opts + i; switch (a->type) { case PCB_HATT_INTEGER: case PCB_HATT_COORD: @@ -1674,7 +1674,7 @@ for (ha = hid_attr_nodes; ha; ha = ha->next) for (i = 0; i < ha->n; i++) { - pcb_export_opt_t *a = ha->attributes + i; + pcb_export_opt_t *a = ha->opts + i; XrmOptionDescRec *o = new_options + acount; char *tmpopt, *tmpres; XtResource *r = new_resources + rcount; @@ -1790,7 +1790,7 @@ rcount = 0; for (ha = hid_attr_nodes; ha; ha = ha->next) for (i = 0; i < ha->n; i++) { - pcb_export_opt_t *a = ha->attributes + i; + pcb_export_opt_t *a = ha->opts + i; val_union *v = new_values + rcount; switch (a->type) { case PCB_HATT_INTEGER: Index: trunk/src_plugins/loghid/hid-logger.c =================================================================== --- trunk/src_plugins/loghid/hid-logger.c (revision 26932) +++ trunk/src_plugins/loghid/hid-logger.c (revision 26933) @@ -15,9 +15,9 @@ static pcb_hid_t *delegatee_ = NULL; static FILE *out_ = NULL; -static pcb_hid_attribute_t *log_get_export_options(pcb_hid_t *hid, int *ret) +static pcb_export_opt_t *log_get_export_options(pcb_hid_t *hid, int *ret) { - pcb_hid_attribute_t *result = delegatee_->get_export_options(hid, ret); + pcb_export_opt_t *result = delegatee_->get_export_options(hid, ret); if (ret != NULL) pcb_fprintf(out_, "get_export_options(ret) -> ret=%d\n", *ret); else Index: trunk/src_plugins/loghid/loghid.c =================================================================== --- trunk/src_plugins/loghid/loghid.c (revision 26932) +++ trunk/src_plugins/loghid/loghid.c (revision 26933) @@ -48,7 +48,7 @@ static pcb_hid_t loghid_gui; static pcb_hid_t loghid_exp; -pcb_hid_attribute_t loghid_attribute_list[] = { +pcb_export_opt_t loghid_attribute_list[] = { {"target-hid", "the real GUI or export HID to relay calls to", PCB_HATT_STRING, 0, 0, {0, 0, 0}, 0, 0} #define HA_target_hid 0 @@ -102,7 +102,7 @@ PCB_REGISTER_ATTRIBUTES(loghid_attribute_list, loghid_cookie) -static pcb_hid_attribute_t *loghid_get_export_options(pcb_hid_t *hid, int *n) +static pcb_export_opt_t *loghid_get_export_options(pcb_hid_t *hid, int *n) { /* loghid_attribute_list[HA_psfile] = pcb_strdup("default?");*/