From: glenlow Date: Fri, 27 Jun 2008 08:33:15 +0000 (+0000) Subject: made gvplugin_list public and removed gvFirstPlugin, gvNextPlugin, gvPluginType;... X-Git-Tag: LAST_LIBGRAPH~32^2~3915 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=243a6ea1192ad6afbeef7dfba3944fe3bb015e98;p=graphviz made gvplugin_list public and removed gvFirstPlugin, gvNextPlugin, gvPluginType; simplified GVGraph interface to plugin lists --- diff --git a/lib/gvc/gvc.c b/lib/gvc/gvc.c index ce2c0f29d..a79578d0a 100644 --- a/lib/gvc/gvc.c +++ b/lib/gvc/gvc.c @@ -30,6 +30,7 @@ extern GVC_t *gvNEWcontext(char **info, char *user); extern char *gvUsername(void); extern int gvRenderJobs (GVC_t * gvc, graph_t * g); +extern char *gvplugin_list(GVC_t * gvc, api_t api, char *str); static char *LibInfo[] = { "libgvc", /* Program */ @@ -199,8 +200,3 @@ char **gvcInfo(GVC_t* gvc) { return gvc->common.info; } char *gvcUsername(GVC_t* gvc) { return gvc->common.user; } char *gvcVersion(GVC_t* gvc) { return gvc->common.info[1]; } char *gvcBuildDate(GVC_t* gvc) { return gvc->common.info[2]; } - -gvplugin_available_t *gvFirstPlugin(GVC_t *gvc, api_t api) { return gvc->apis[api]; } -gvplugin_available_t *gvNextPlugin(gvplugin_available_t *plugin) { return plugin->next; } -char *gvPluginType(gvplugin_available_t *plugin) { return plugin->typestr; } - diff --git a/lib/gvc/gvc.h b/lib/gvc/gvc.h index 71608bd6e..1040fbda7 100644 --- a/lib/gvc/gvc.h +++ b/lib/gvc/gvc.h @@ -68,9 +68,7 @@ extern char *gvcBuildDate(GVC_t*); extern char *gvcUsername(GVC_t*); /* get plugins associated with a graphviz context */ -extern gvplugin_available_t *gvFirstPlugin(GVC_t *gvc, api_t api); -extern gvplugin_available_t *gvNextPlugin(gvplugin_available_t *plugin); -extern char *gvPluginType(gvplugin_available_t *plugin); +extern char *gvplugin_list(GVC_t * gvc, api_t api, char *str); /* parse command line args - minimally argv[0] sets layout engine */ extern int gvParseArgs(GVC_t *gvc, int argc, char **argv); diff --git a/lib/gvc/gvcproc.h b/lib/gvc/gvcproc.h index 10506884e..7f9257b04 100644 --- a/lib/gvc/gvcproc.h +++ b/lib/gvc/gvcproc.h @@ -38,7 +38,6 @@ extern "C" { gvplugin_installed_t * typeptr); extern gvplugin_available_t *gvplugin_load(GVC_t * gvc, api_t api, char *type); extern gvplugin_library_t *gvplugin_library_load(GVC_t *gvc, char *path); - extern const char *gvplugin_list(GVC_t * gvc, api_t api, char *str); extern api_t gvplugin_api(char *str); extern char * gvplugin_api_name(api_t api); extern void gvplugin_write_status(GVC_t * gvc); diff --git a/lib/gvc/gvplugin.c b/lib/gvc/gvplugin.c index a3d59834f..f137ee025 100644 --- a/lib/gvc/gvplugin.c +++ b/lib/gvc/gvplugin.c @@ -367,10 +367,10 @@ static const char *append_buf(char sep, char *str, boolean new) } /* assemble a string list of available plugins */ -const char *gvplugin_list(GVC_t * gvc, api_t api, char *str) +char *gvplugin_list(GVC_t * gvc, api_t api, char *str) { gvplugin_available_t **pnext, **plugin; - const char *buf = NULL; + char *buf = NULL; char *s, *p, *q, *typestr_last; boolean new = TRUE; diff --git a/macosx/GVExportViewController.m b/macosx/GVExportViewController.m index b7c1ba8af..5734e77bd 100644 --- a/macosx/GVExportViewController.m +++ b/macosx/GVExportViewController.m @@ -31,9 +31,7 @@ NSMutableArray *_formatRenders = nil; NSString *lastFormat = nil; NSMutableArray *lastRenders = nil; - for (NSString *device in [GVGraph devices]) { - NSLog (@"%@", device); - + for (NSString *device in [GVGraph pluginsWithAPI:API_device]) { NSArray *deviceComponents = [device componentsSeparatedByString:@":"]; NSUInteger componentCount = [deviceComponents count]; diff --git a/macosx/GVGraph.m b/macosx/GVGraph.m index 4175ee90d..5bf6753f8 100644 --- a/macosx/GVGraph.m +++ b/macosx/GVGraph.m @@ -22,73 +22,6 @@ extern double PSinputscale; static GVC_t *_graphContext = nil; -@interface GVGraphPluginEnumerator : NSEnumerator -{ - gvplugin_available_t *_plugin; - NSMutableSet *_distinctPlugins; -} - -- (id)initWithAPI:(api_t)api; -- (NSArray *)allObjects; -- (id)nextObject; -- (void)dealloc; - -@end - -@implementation GVGraphPluginEnumerator - -- (id)initWithAPI:(api_t)api -{ - if (self = [super init]) { - _plugin = gvFirstPlugin(_graphContext, api); - _distinctPlugins = [[NSMutableSet alloc] init]; - } - return self; -} - -- (NSArray *)allObjects -{ - NSMutableArray *allPlugins = [NSMutableArray array]; - for (; _plugin; _plugin = gvNextPlugin(_plugin)) { - /* get the type */ - char *pluginType = gvPluginType(_plugin); - NSString *nextPlugin = [[[NSString alloc] initWithBytesNoCopy:pluginType length:strlen(pluginType) encoding:NSUTF8StringEncoding freeWhenDone:NO] autorelease]; - - /* if distinct, add to the list */ - if (![_distinctPlugins containsObject:nextPlugin]) { - [_distinctPlugins addObject:nextPlugin]; - [allPlugins addObject:nextPlugin]; - } - } - return allPlugins; -} - -- (id)nextObject -{ - NSString *nextPlugin = nil; - BOOL plugging = YES; - for (; plugging && _plugin; _plugin = gvNextPlugin(_plugin)) { - /* get the type */ - char *pluginType = gvPluginType(_plugin); - nextPlugin = [[[NSString alloc] initWithBytesNoCopy:pluginType length:strlen(pluginType) encoding:NSUTF8StringEncoding freeWhenDone:NO] autorelease]; - - /* if distinct, stop plugging away */ - if (![_distinctPlugins containsObject:nextPlugin]) { - [_distinctPlugins addObject:nextPlugin]; - plugging = NO; - } - } - - return nextPlugin; -} - -- (void)dealloc -{ - [_distinctPlugins release]; - [super dealloc]; -} -@end - @implementation GVGraph @synthesize graph = _graph; @@ -102,9 +35,32 @@ static GVC_t *_graphContext = nil; _graphContext = gvContext(); } -+ (NSEnumerator *)devices ++ (NSArray *)pluginsWithAPI:(api_t)api { - return [[[GVGraphPluginEnumerator alloc] initWithAPI:API_device] autorelease]; + /* need to filter out repeated plugins i.e. plugins that have the same format + render but different package */ + NSMutableSet *distinctPlugins = [NSMutableSet set]; + NSMutableArray *plugins = [NSMutableArray array]; + + /* go through each non-empty plugin in the list, ignoring the package part */ + char *pluginList = gvplugin_list(_graphContext, api, ":"); + char *restOfPlugins; + char *nextPlugin; + for (restOfPlugins = pluginList; nextPlugin = strsep(&restOfPlugins, " ");) { + if (*nextPlugin) { + char *lastColon = strrchr(nextPlugin, ':'); + if (lastColon) { + *lastColon = '\0'; + NSString *plugin = [NSString stringWithCString:nextPlugin encoding:NSUTF8StringEncoding]; + if (![distinctPlugins containsObject:plugin]) { + [plugins addObject:plugin]; + [distinctPlugins addObject:plugin]; + } + } + } + } + free(pluginList); + + return plugins; } - (id)initWithURL:(NSURL *)URL error:(NSError **)outError