Index: trunk/src/buildin.c.in =================================================================== --- trunk/src/buildin.c.in (revision 8243) +++ trunk/src/buildin.c.in (nonexistent) @@ -1,14 +0,0 @@ -print [@ -/**** This file autogenerated by scconfig, do not edit ****/ -#include -#include "plugins.h" -#include "buildin.h" - -@?/local/pcb/buildin_init_extern@ - -void pcb_buildin_init(void) -{ - pcb_uninit_t uninit_func; -@?/local/pcb/buildin_init_code@ -} -@] Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 8243) +++ trunk/src/Makefile.in (revision 8244) @@ -168,6 +168,11 @@ ../src_3rd/qparse/qparse.o @] +put /local/pcb/LIBS [@ + ../src_3rd/puplug/libpuplug.a +@] + + # We do not compile these in the executable but we need rules for these for utils put /local/pcb/OBJS_UTIL [@ ../src_3rd/genvector/vts0.o @@ -268,6 +273,7 @@ CQUOTE=$(ROOT)/scconfig/cquote SPHASH_PATH=$(ROOT)/src_3rd/sphash SPHASH=$(SPHASH_PATH)/sphash +PUPLUG=$(ROOT)/src_3rd/puplug/util/puplug all: $(MAKE) revcheck @@ -286,6 +292,13 @@ $(SPHASH_PATH)/sphash: $(SPHASH_PATH)/sphash.c $(CC) -o pcb-rnd$(EXE) $(SPHASH_PATH)/sphash.c -o $(SPHASH_PATH)/sphash + +buildin.c: $(PLUGDIR)/.builtin.pups + cd $(PLUGDIR) && $(PUPLUG) buildin.c "-" < $(PLUGDIR)/.builtin.pups > $(ROOT)/src/buildin.c + +buildin.h: $(PLUGDIR)/.builtin.pups + $(PUPLUG) buildin.h > buildin.h + @] print [@ Index: trunk/src/buildin.h =================================================================== --- trunk/src/buildin.h (revision 8243) +++ trunk/src/buildin.h (revision 8244) @@ -1,2 +1,4 @@ -/* Run the init code of all buildins. */ -void pcb_buildin_init(void); +/* This file is generated by the puplug utility. Please DO NOT edit this file. */ + +#include +extern const pup_buildin_t pup_buildins[]; Index: trunk/src/hid_init.c =================================================================== --- trunk/src/hid_init.c (revision 8243) +++ trunk/src/hid_init.c (revision 8244) @@ -55,79 +55,6 @@ return h; } -/* dirname must be strdup()'d on the caller's side! */ -static int hid_load_dir(char *dirname) -{ - DIR *dir; - struct dirent *de; - int count = 0; - - dir = opendir(dirname); - if (!dir) { - hid_append_dir(dirname, 0); - return 0; - } - while ((de = readdir(dir)) != NULL) { - unsigned int phash; - void *sym; - pcb_uninit_t (*symv) (); - pcb_uninit_t uninit; - void *so; - char *basename, *path, *symname; - struct stat st; - - basename = pcb_strdup(de->d_name); - if (strlen(basename) > 3 && pcb_strcasecmp(basename + strlen(basename) - 3, ".so") == 0) - basename[strlen(basename) - 3] = 0; - else if (strlen(basename) > 4 && pcb_strcasecmp(basename + strlen(basename) - 4, ".dll") == 0) - basename[strlen(basename) - 4] = 0; - path = pcb_concat(dirname, PCB_DIR_SEPARATOR_S, de->d_name, NULL); - - if (stat(path, &st) == 0 && ( -/* mingw and win32 do not support S_IXGRP or S_IXOTH */ -#if defined(S_IXGRP) - (st.st_mode & S_IXGRP) || -#endif -#if defined(S_IXOTH) - (st.st_mode & S_IXOTH) || -#endif - (st.st_mode & S_IXUSR)) - && S_ISREG(st.st_mode)) { - if ((so = dlopen(path, RTLD_NOW | RTLD_GLOBAL)) == NULL) { - fprintf(stderr, "dl_error: %s\n", dlerror()); - } - else { - pcb_plugin_info_t *inf = plugin_find(basename); - phash = plugin_hash(path); - if (inf == NULL) { - symname = pcb_concat("hid_", basename, "_init", NULL); - if ((sym = dlsym(so, symname)) != NULL) { - symv = (pcb_uninit_t (*)())pcb_cast_d2f(sym); - uninit = symv(); - } - else if ((sym = dlsym(so, "pcb_plugin_init")) != NULL) { - symv = (pcb_uninit_t (*)()) pcb_cast_d2f(sym); - uninit = symv(); - } - else - uninit = NULL; - inf = pcb_plugin_register(basename, path, so, 1, uninit); - inf->hash = phash; - count++; - free(symname); - } - else if (phash != inf->hash) /* warn only if this is not the very same file in yet-another-copy */ - pcb_message(PCB_MSG_ERROR, "Can't load %s because it'd provide plugin %s that is already loaded from %s\n", path, basename, (*inf->path == '<' ? "" : inf->path)); - } - } - free(basename); - free(path); - } - closedir(dir); - hid_append_dir(dirname, count); - return count; -} - void pcb_hid_init() { int found; @@ -136,6 +63,8 @@ /* Setup a "nogui" default HID */ pcb_gui = pcb_hid_nogui_get_hid(); +#warning puplug TODO: rewrite this +#if 0 #warning TODO: make this configurable found = hid_load_dir(pcb_concat(conf_core.rc.path.exec_prefix, PCB_DIR_SEPARATOR_S, "lib", PCB_DIR_SEPARATOR_S, "pcb-rnd", PCB_DIR_SEPARATOR_S, "plugins", PCB_DIR_SEPARATOR_S, HOST, NULL)); @@ -153,6 +82,7 @@ } hid_load_dir(pcb_concat("plugins", PCB_DIR_SEPARATOR_S, HOST, NULL)); hid_load_dir(pcb_concat("plugins", NULL)); +#endif } void pcb_hid_uninit(void) Index: trunk/src/main.c =================================================================== --- trunk/src/main.c (revision 8243) +++ trunk/src/main.c (revision 8244) @@ -251,7 +251,7 @@ free(PCB); PCB = NULL; - pcb_plugins_uninit(); +#warning puplug TODO: call here: pcb_plugins_uninit(); pcb_hid_uninit(); pcb_text_uninit(); pcb_events_uninit(); @@ -425,10 +425,15 @@ pcb_events_init(); pcb_text_init(); - pcb_buildin_init(); + pup_init(&pcb_pup); + pcb_pup.error_stack_enable = 1; + pup_buildin_load(&pcb_pup, pup_buildins); + pup_autoload_dir(&pcb_pup, NULL, NULL); + pcb_hid_init(); - pcb_plugins_init(); +#warning puplug TODO: call here: pcb_plugins_init(); + { /* Now that plugins are already initialized, apply plugin config items */ int n; for(n = 0; n < vtptr_len(&plugin_cli_conf); n++) { Index: trunk/src/main_act.c =================================================================== --- trunk/src/main_act.c (revision 8243) +++ trunk/src/main_act.c (revision 8244) @@ -247,11 +247,14 @@ static const char pcb_acth_DumpPlugins[] = "Print plugins loaded."; +#warning puplug TODO: rewrite this and move int pcb_act_DumpPlugins(int argc, const char **argv, pcb_coord_t x, pcb_coord_t y) { +#if 0 pcb_plugin_info_t *i; for(i = plugins; i != NULL; i = i->next) printf("%s\t%s\n", i->name, i->path); +#endif return 0; } @@ -259,12 +262,14 @@ static const char pcb_acts_DumpPluginDirs[] = "DumpPluginDirs()"; static const char pcb_acth_DumpPluginDirs[] = "Print plugins directories and the number of plugins loaded from each."; - +#warning puplug TODO: rewrite this and move int pcb_act_DumpPluginDirs(int argc, const char **argv, pcb_coord_t x, pcb_coord_t y) { +#if 0 const pcb_plugin_dir_t *d; for(d = pcb_plugin_dir_first; d != NULL; d = d->next) printf("%s\t%d\n", d->path, d->num_plugins); +#endif return 0; } Index: trunk/src/plugins.c =================================================================== --- trunk/src/plugins.c (revision 8243) +++ trunk/src/plugins.c (revision 8244) @@ -33,54 +33,8 @@ #include "compat_misc.h" #include "hid.h" -pcb_plugin_info_t *plugins = NULL; +pup_context_t pcb_pup; -pcb_plugin_info_t *plugin_find(const char *name) -{ - pcb_plugin_info_t *i; - for(i = plugins; i != NULL; i = i->next) - if (strcmp(i->name, name) == 0) - return i; - return NULL; -} - -pcb_plugin_info_t *pcb_plugin_register(const char *name, const char *path, void *handle, int dynamic_loaded, void (*uninit)(void)) -{ - pcb_plugin_info_t *i = malloc(sizeof(pcb_plugin_info_t)); - - i->name = pcb_strdup(name); - i->path = pcb_strdup(path); - i->handle = handle; - i->dynamic_loaded = dynamic_loaded; - i->uninit = uninit; - i->hash = 0; - - i->next = plugins; - plugins = i; - return i; -} - -void pcb_plugins_init(void) -{ -} - - -void pcb_plugins_uninit(void) -{ - pcb_plugin_info_t *i, *next; - for(i = plugins; i != NULL; i = next) { - next = i->next; - free(i->name); - free(i->path); - if (i->uninit != NULL) - i->uninit(); - free(i); - } - plugins = NULL; -} - - - /* ---------------------------------------------------------------- */ static const char pcb_acts_ManagePlugins[] = "ManagePlugins()\n"; @@ -88,6 +42,8 @@ static int pcb_act_ManagePlugins(int argc, const char **argv, pcb_coord_t x, pcb_coord_t y) { +#warning puplug TODO: rewrite for puplug +#if 0 pcb_plugin_info_t *i; int nump = 0, numb = 0; gds_t str; @@ -131,6 +87,7 @@ gds_append_str(&str, "\n\nNOTE: this is the alpha version, can only list plugins/buildins\n"); pcb_gui->report_dialog("Manage plugins", str.array); gds_uninit(&str); +#endif return 0; } Index: trunk/src/plugins.h =================================================================== --- trunk/src/plugins.h (revision 8243) +++ trunk/src/plugins.h (revision 8244) @@ -26,34 +26,11 @@ #ifndef PCB_RND_PLUGINS_H #define PCB_RND_PLUGINS_H -typedef struct pcb_plugin_info_s pcb_plugin_info_t; +#include +#include -typedef void (*pcb_uninit_t)(void); +extern pup_context_t pcb_pup; -struct pcb_plugin_info_s { - char *name; - char *path; - void *handle; - int dynamic_loaded; - unsigned int hash; - pcb_uninit_t uninit; - pcb_plugin_info_t *next; -}; - -extern pcb_plugin_info_t *plugins; - -/* Init the plugin system */ -void pcb_plugins_init(void); - -/* Uninit each plugin then uninit the plugin system */ -void pcb_plugins_uninit(void); - -/* Register a new plugin (or buildin) */ -pcb_plugin_info_t *pcb_plugin_register(const char *name, const char *path, void *handle, int dynamic, pcb_uninit_t uninit); - -/* Find a plugin by name */ -pcb_plugin_info_t *plugin_find(const char *name); - /* Hook based plugin generics; plugins that implement a common API should use HOOK_REGISTER with an api struct. The core should run the plugins using HOOK_CALL */