From a1bfa4250debf9ebbf4f5fcae4213917fa8cc755 Mon Sep 17 00:00:00 2001 From: ellson Date: Wed, 4 May 2005 19:31:59 +0000 Subject: [PATCH] separate packagename from library path: all packages, including libraries and builtins, have a packagename only dynamically loaded libraries have a path plugin listings (e.g. -Tps:? ) now show packagename rather than path selection takes packagename, not path, (e.g. -Tps:text ) config file saves path and packagename --- lib/common/input.c | 9 +++++++-- lib/gvc/gvc.h | 4 ++-- lib/gvc/gvcint.h | 18 ++++++++++++------ lib/gvc/gvconfig.c | 21 ++++++++++----------- lib/gvc/gvplugin.c | 40 +++++++++++++++++++++++++++------------- lib/gvc/gvplugin.h | 4 ++-- lib/gvc/gvrender.c | 2 +- tclpkg/tcldot/tcldot.c | 2 +- 8 files changed, 62 insertions(+), 38 deletions(-) diff --git a/lib/common/input.c b/lib/common/input.c index 4b88c1202..61908bce1 100644 --- a/lib/common/input.c +++ b/lib/common/input.c @@ -873,7 +873,12 @@ void config_codegen_builtins(GVC_t * gvc) codegen_info_t *p; for (p = cg; p->name; ++p) - gvplugin_install(gvc, API_render, p->name, 0, "cg", - (gvplugin_type_t *) p); + gvplugin_install(gvc, + API_render, + p->name, + 0, + "cg", + NULL, + (gvplugin_type_t *) p); #endif } diff --git a/lib/gvc/gvc.h b/lib/gvc/gvc.h index 68786cb99..9f1b918df 100644 --- a/lib/gvc/gvc.h +++ b/lib/gvc/gvc.h @@ -39,8 +39,8 @@ extern "C" { /* plugins */ extern boolean gvplugin_install(GVC_t * gvc, api_t api, - char *typestr, int quality, char *path, - gvplugin_type_t * typeptr); + char *typestr, int quality, char *packagename, char *path, + gvplugin_type_t * typeptr); extern gv_plugin_t *gvplugin_load(GVC_t * gvc, api_t api, char *type); extern gvplugin_library_t *gvplugin_library_load(char *path); extern const char *gvplugin_list(GVC_t * gvc, api_t api, char *str); diff --git a/lib/gvc/gvcint.h b/lib/gvc/gvcint.h index f4f84fd83..7a960d58e 100644 --- a/lib/gvc/gvcint.h +++ b/lib/gvc/gvcint.h @@ -135,15 +135,21 @@ extern "C" { void *window; /* display-specific data for gvrender plugin */ }; -/* gv_plugin_t is a descriptor for available plugins; gvplugin_t is for installed plugins */ +/* gv_plugin_t is a descriptor for available plugins; + gvplugin_t is for installed plugins */ typedef struct gv_plugin_s gv_plugin_t; struct gv_plugin_s { - gv_plugin_t *next; - char *typestr; - int quality; - char *path; - gvplugin_type_t *typeptr; + gv_plugin_t *next; /* next plugin in linked list, or NULL */ + char *typestr; /* type string, e.g. "png" or "ps" */ + int quality; /* programmer assigned quality + ranking within type (+ve or -ve int) + - codegens have quality = 0 */ + char *path; /* file path to library containing plugin, + or NULL if builtin */ + char *packagename; /* package name */ + gvplugin_type_t *typeptr; /* pointer to jumptable for plugin, + or NULL if not yet loaded */ }; typedef int (*gvevent_key_callback_t) (GVJ_t * job); diff --git a/lib/gvc/gvconfig.c b/lib/gvc/gvconfig.c index fc846e09d..06d622347 100644 --- a/lib/gvc/gvconfig.c +++ b/lib/gvc/gvconfig.c @@ -132,7 +132,7 @@ static char *token(int *nest, char **tokens) static void gvconfig_plugin_install_from_config(GVC_t * gvc, char *s) { - char *path, *api, *type; + char *path, *packagename, *api, *type; api_t gv_api; int quality, rc; int nest = 0; @@ -140,6 +140,7 @@ static void gvconfig_plugin_install_from_config(GVC_t * gvc, char *s) separator(&nest, &s); while (*s) { path = token(&nest, &s); + packagename = token(&nest, &s); do { api = token(&nest, &s); gv_api = gvplugin_api(api); @@ -153,7 +154,8 @@ static void gvconfig_plugin_install_from_config(GVC_t * gvc, char *s) quality = atoi(token(&nest, &s)); else quality = 0; - rc = gvplugin_install (gvc, gv_api, type, quality, path, NULL); + rc = gvplugin_install (gvc, gv_api, + type, quality, packagename, path, NULL); if (!rc) { fprintf(stderr, "config error: %s %s %s\n", path, api, type); return; @@ -163,7 +165,7 @@ static void gvconfig_plugin_install_from_config(GVC_t * gvc, char *s) } } -static void gvconfig_plugin_install_from_library(GVC_t * gvc, gvplugin_library_t *library) +static void gvconfig_plugin_install_from_library(GVC_t * gvc, char *path, gvplugin_library_t *library) { gvplugin_api_t *apis; gvplugin_type_t *types; @@ -172,7 +174,7 @@ static void gvconfig_plugin_install_from_library(GVC_t * gvc, gvplugin_library_t for (apis = library->apis; (types = apis->types); apis++) { for (i = 0; types[i].type; i++) { gvplugin_install(gvc, apis->api, types[i].type, - types[i].quality, library->name, &types[i]); + types[i].quality, library->packagename, path, &types[i]); } } } @@ -183,12 +185,9 @@ static void gvconfig_write_library_config(char *path, gvplugin_library_t *librar gvplugin_type_t *types; int i; - fputs (path, f); - fputs (" {\n", f); + fprintf(f, "%s %s {\n", path, library->packagename); for (apis = library->apis; (types = apis->types); apis++) { - fputs ("\t", f); - fputs (gvplugin_api_name(apis->api), f); - fputs (" {\n", f); + fprintf(f, "\t%s {\n", gvplugin_api_name(apis->api)); for (i = 0; types[i].type; i++) { fprintf(f, "\t\t%s %d\n", types[i].type, types[i].quality); } @@ -232,7 +231,7 @@ void gvconfig(GVC_t * gvc) #ifdef DISABLE_LTDL for (libraryp = builtins; *libraryp; libraryp++) { - gvconfig_plugin_install_from_library(gvc, *libraryp); + gvconfig_plugin_install_from_library(gvc, NULL, *libraryp); } #else /* see if there are any new plugins */ @@ -294,7 +293,7 @@ void gvconfig(GVC_t * gvc) for (i = 0; i < globbuf.gl_pathc; i++) { library = gvplugin_library_load(globbuf.gl_pathv[i]); if (library) { - gvconfig_plugin_install_from_library(gvc, library); + gvconfig_plugin_install_from_library(gvc, globbuf.gl_pathv[i], library); if (f) { gvconfig_write_library_config(globbuf.gl_pathv[i], library, f); } diff --git a/lib/gvc/gvplugin.c b/lib/gvc/gvplugin.c index ecb04f414..1f95d6f77 100644 --- a/lib/gvc/gvplugin.c +++ b/lib/gvc/gvplugin.c @@ -63,8 +63,8 @@ char *gvplugin_api_name(api_t api) /* list is alpha sorted by type, the quality sorted within the type, then, if qualities are the same, last install wins */ boolean gvplugin_install(GVC_t * gvc, api_t api, - char *typestr, int quality, char *path, - gvplugin_type_t * typeptr) + char *typestr, int quality, char *packagename, char *path, + gvplugin_type_t * typeptr) { gv_plugin_t *plugin, **pnext; @@ -88,7 +88,8 @@ boolean gvplugin_install(GVC_t * gvc, api_t api, *pnext = plugin; plugin->typestr = typestr; plugin->quality = quality; - plugin->path = path; /* filepath for .so, shortname for builtins */ + plugin->packagename = packagename; /* packagename, all packages */ + plugin->path = path; /* filepath for .so, or NULL for builtins */ plugin->typeptr = typeptr; /* null if not loaded */ return TRUE; @@ -100,6 +101,7 @@ gvplugin_library_t *gvplugin_library_load(char *path) lt_dlhandle hndl; lt_ptr ptr; char *s, *sym; + int len; char *suffix = "_LTX_library"; @@ -114,10 +116,15 @@ gvplugin_library_t *gvplugin_library_load(char *path) } s = strrchr(path, '/'); - sym = malloc(strlen(s) + strlen(suffix) + 1); + len = strlen(s); + if (len < strlen("libgvplugin_x")) { + fprintf(stderr,"invalid plugin path \"%s\"\n", path); + return NULL; + } + sym = malloc(len + strlen(suffix) + 1); strcpy(sym, s+4); /* strip leading "/lib" */ s = strchr(sym, '.'); /* strip trailing ".so.0" */ - strcpy(s,"_LTX_library"); /* append "_LTX_library" */ + strcpy(s,suffix); /* append "_LTX_library" */ ptr = lt_dlsym (hndl, sym); if (!ptr) { @@ -134,7 +141,8 @@ gvplugin_library_t *gvplugin_library_load(char *path) } -/* load a plugin of type=str where str can optionally contain a ":path" modifier */ +/* load a plugin of type=str + where str can optionally contain a ":packagename" modifier */ gv_plugin_t *gvplugin_load(GVC_t * gvc, api_t api, char *str) { gv_plugin_t **pnext, *rv; @@ -149,7 +157,7 @@ gv_plugin_t *gvplugin_load(GVC_t * gvc, api_t api, char *str) if (api < 0) return NULL; - /* does str have a :path modifier? */ + /* does str have a :packagename modifier? */ s = strdup(str); p = strchr(s, ':'); if (p) @@ -161,7 +169,7 @@ gv_plugin_t *gvplugin_load(GVC_t * gvc, api_t api, char *str) while (*pnext) { if (strcmp(s, (*pnext)->typestr) == 0) { if (p) { - if (strcmp(p, (*pnext)->path) == 0) + if (strcmp(p, (*pnext)->packagename) == 0) break; } else @@ -186,8 +194,13 @@ gv_plugin_t *gvplugin_load(GVC_t * gvc, api_t api, char *str) /* Now reinsert the library with real type ptrs */ for (apis = library->apis; (types = apis->types); apis++) { for (i = 0; types[i].type; i++) { - gvplugin_install(gvc, apis->api, types[i].type, - types[i].quality, library->name, &types[i]); + gvplugin_install(gvc, + apis->api, + types[i].type, + types[i].quality, + library->packagename, + (*pnext)->path, + &types[i]); } } @@ -196,7 +209,7 @@ gv_plugin_t *gvplugin_load(GVC_t * gvc, api_t api, char *str) while (*pnext) { if (strcmp(s, (*pnext)->typestr) == 0) { if (p) { - if (strcmp(p, (*pnext)->path) == 0) + if (strcmp(p, (*pnext)->packagename) == 0) break; } else @@ -215,7 +228,8 @@ gv_plugin_t *gvplugin_load(GVC_t * gvc, api_t api, char *str) return rv; } -/* string buffer management - FIXME - must have 20 solutions for this same thing */ +/* string buffer management + - FIXME - must have 20 solutions for this same thing */ static const char *append_buf(char sep, char *str, boolean new) { static char *buf; @@ -266,7 +280,7 @@ const char *gvplugin_list(GVC_t * gvc, api_t api, char *str) if (strcmp(s, (*pnext)->typestr) == 0) { /* list each member of the matching type as "type:path" */ append_buf(' ', (*pnext)->typestr, new); - buf = append_buf(':', (*pnext)->path, FALSE); + buf = append_buf(':', (*pnext)->packagename, FALSE); new = FALSE; } pnext = &((*pnext)->next); diff --git a/lib/gvc/gvplugin.h b/lib/gvc/gvplugin.h index 16b646ac5..da56e1e3a 100644 --- a/lib/gvc/gvplugin.h +++ b/lib/gvc/gvplugin.h @@ -70,8 +70,8 @@ extern "C" { } gvplugin_api_t; typedef struct { - char *name; /* used instead of a file pathname - when this plugin is loaded */ + char *packagename; /* used when this plugin is builtin and has + no pathname */ gvplugin_api_t *apis; } gvplugin_library_t; diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index 389a2523d..c81715851 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -60,7 +60,7 @@ int gvrender_select(GVJ_t * job, char *str) plugin = gvplugin_load(gvc, API_render, str); if (plugin) { #ifndef DISABLE_CODEGENS - if (strcmp(plugin->path, "cg") == 0) { + if (strcmp(plugin->packagename, "cg") == 0) { cg_info = (codegen_info_t *) (plugin->typeptr); job->codegen = cg_info->cg; return cg_info->id; diff --git a/tclpkg/tcldot/tcldot.c b/tclpkg/tcldot/tcldot.c index 164347426..1797377fe 100644 --- a/tclpkg/tcldot/tcldot.c +++ b/tclpkg/tcldot/tcldot.c @@ -1651,7 +1651,7 @@ int Tcldot_Init(Tcl_Interp * interp) gvconfig(gvc); /* additional codegens */ for (p = cg; p->name; ++p) - gvplugin_install(gvc, API_render, p->name, 0, "cg", + gvplugin_install(gvc, API_render, p->name, 0, "cg", NULL, (gvplugin_type_t *) p); #ifndef TCLOBJ -- 2.40.0