Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 1476) +++ trunk/src/Makefile.in (revision 1477) @@ -190,6 +190,7 @@ CLEANFILES=@/local/pcb/CLEANFILES@ CLEANRULES=@/local/pcb/CLEANRULES@ CC=@cc/cc@ +CQUOTE=../scconfig/cquote all: pcb-rnd @/local/pcb/all@ Index: trunk/src/hid_cfg.c =================================================================== --- trunk/src/hid_cfg.c (revision 1476) +++ trunk/src/hid_cfg.c (revision 1477) @@ -41,6 +41,15 @@ abort(); } +static int hid_cfg_load_error(lht_doc_t *doc, const char *filename, lht_err_t err) +{ + const char *fn; + int line, col; + lht_dom_loc_active(doc, &fn, &line, &col); + Message("Resource error: %s (%s:%d.%d)*\n", lht_err_str(err), filename, line+1, col+1); + return 1; +} + lht_doc_t *hid_cfg_load_lht(const char *filename) { FILE *f; @@ -48,6 +57,8 @@ int error = 0; f = fopen(filename, "r"); + if (f == NULL) + return NULL; doc = lht_dom_init(); lht_dom_loc_newfile(doc, filename); @@ -57,11 +68,7 @@ err = lht_dom_parser_char(doc, c); if (err != LHTE_SUCCESS) { if (err != LHTE_STOP) { - const char *fn; - int line, col; - lht_dom_loc_active(doc, &fn, &line, &col); - Message("Resource error: %s (%s:%d.%d)*\n", lht_err_str(err), filename, line+1, col+1); - error = 1; + error = hid_cfg_load_error(doc, filename, err); break; } break; /* error or stop, do not read anymore (would get LHTE_STOP without any processing all the time) */ @@ -77,6 +84,35 @@ return doc; } +lht_doc_t *hid_cfg_load_str(const char *text) +{ + lht_doc_t *doc; + int error = 0; + + doc = lht_dom_init(); + lht_dom_loc_newfile(doc, "embedded"); + + while(*text != '\0') { + lht_err_t err; + int c = *text++; + err = lht_dom_parser_char(doc, c); + if (err != LHTE_SUCCESS) { + if (err != LHTE_STOP) { + error = hid_cfg_load_error(doc, "internal", err); + break; + } + break; /* error or stop, do not read anymore (would get LHTE_STOP without any processing all the time) */ + } + } + + if (error) { + lht_dom_uninit(doc); + doc = NULL; + } + + return doc; +} + const char *hid_cfg_text_value(lht_doc_t *doc, const char *path) { lht_node_t *n = lht_tree_path(doc, "/", path, 1, NULL); @@ -99,6 +135,8 @@ doc = hid_cfg_load_lht(hidfn); if (doc == NULL) + doc = hid_cfg_load_str(embedded_fallback); + if (doc == NULL) return NULL; hr = calloc(sizeof(hid_cfg_t), 1); /* make sure the cache is cleared */ @@ -187,7 +225,7 @@ return 0; if (n->type != LHT_LIST) { hid_cfg_error(submenu, "Error: field %s should be a list (of submenus)\n", fldname); - return NULL; + return 0; } return 1; } Index: trunk/src_plugins/hid_gtk/Plug.tmpasm =================================================================== --- trunk/src_plugins/hid_gtk/Plug.tmpasm (revision 1476) +++ trunk/src_plugins/hid_gtk/Plug.tmpasm (revision 1477) @@ -22,6 +22,7 @@ $(PLUGDIR)/hid_gtk/gui-top-window.o $(PLUGDIR)/hid_gtk/gui-utils.o $(PLUGDIR)/hid_gtk/gtkhid-gdk.o + $(PLUGDIR)/hid_gtk/menu_lht.o @] switch /local/pcb/hid_gtk/controls @@ -29,6 +30,12 @@ default put /local/pcb/mod/CFLAGS /target/libs/gui/gtk2/cflags put /local/pcb/mod/LDFLAGS /target/libs/gui/gtk2/ldflags + append /local/pcb/RULES [@ +### lesstif menu embed +$(PLUGDIR)/hid_gtk/menu_lht.c: pcb-menu-gtk.lht + $(CQUOTE) -n hid_gtk_menu_default $(PLUGDIR)/hid_gtk/menu_lht.c +@] + end end Index: trunk/src_plugins/hid_gtk/gui-top-window.c =================================================================== --- trunk/src_plugins/hid_gtk/gui-top-window.c (revision 1476) +++ trunk/src_plugins/hid_gtk/gui-top-window.c (revision 1477) @@ -1757,10 +1757,9 @@ ghid_hotkey_actions[i].node = NULL; } -#warning TODO - const char *gpcb_menu_default = NULL; + extern const char *hid_gtk_menu_default; - ghid_cfg = hid_cfg_load("gtk", gpcb_menu_default); + ghid_cfg = hid_cfg_load("gtk", hid_gtk_menu_default); if (ghid_cfg == NULL) { Message("FATAL: can't load the gtk menu res either from file or from hardwired default."); abort(); Index: trunk/src_plugins/hid_lesstif/Plug.tmpasm =================================================================== --- trunk/src_plugins/hid_lesstif/Plug.tmpasm (revision 1476) +++ trunk/src_plugins/hid_lesstif/Plug.tmpasm (revision 1477) @@ -4,6 +4,7 @@ $(PLUGDIR)/hid_lesstif/library.o $(PLUGDIR)/hid_lesstif/main.o $(PLUGDIR)/hid_lesstif/menu.o + $(PLUGDIR)/hid_lesstif/menu_lht.o $(PLUGDIR)/hid_lesstif/netlist.o $(PLUGDIR)/hid_lesstif/styles.o $(PLUGDIR)/hid_lesstif/stdarg.o @@ -23,6 +24,13 @@ @/target/libs/gui/xinerama/ldflags@ @/target/libs/gui/xrender/ldflags@ @] + + append /local/pcb/RULES [@ +### lesstif menu embed +$(PLUGDIR)/hid_lesstif/menu_lht.c: pcb-menu-lesstif.lht + $(CQUOTE) -n lesstif_menu_default $(PLUGDIR)/hid_lesstif/menu_lht.c +@] + end end Index: trunk/src_plugins/hid_lesstif/menu.c =================================================================== --- trunk/src_plugins/hid_lesstif/menu.c (revision 1476) +++ trunk/src_plugins/hid_lesstif/menu.c (revision 1477) @@ -994,12 +994,11 @@ screen = DefaultScreen(display); cmap = DefaultColormap(display, screen); -#warning TODO - const char *lesstif_menu_default = NULL; + extern const char *lesstif_menu_default; r = hid_cfg_load("lesstif", lesstif_menu_default); if (r == NULL) { - Message("FATAL: can't load the gtk menu res either from file or from hardwired default."); + Message("FATAL: can't load the lesstif menu res either from file or from hardwired default."); abort(); }