]> granicus.if.org Git - graphviz/commitdiff
made gvplugin_list public and removed gvFirstPlugin, gvNextPlugin, gvPluginType;...
authorglenlow <devnull@localhost>
Fri, 27 Jun 2008 08:33:15 +0000 (08:33 +0000)
committerglenlow <devnull@localhost>
Fri, 27 Jun 2008 08:33:15 +0000 (08:33 +0000)
lib/gvc/gvc.c
lib/gvc/gvc.h
lib/gvc/gvcproc.h
lib/gvc/gvplugin.c
macosx/GVExportViewController.m
macosx/GVGraph.m

index ce2c0f29d1ccd8c7d9748709798a5f54c199a933..a79578d0a9cdf6241ee6046c62b5d95f73df6584 100644 (file)
@@ -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; }
-
index 71608bd6ea1554ce78ebe3789962aa089d095cb1..1040fbda7ac8e3df97f330abbd9f6f346bd02644 100644 (file)
@@ -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);
index 10506884efc92534ccbe794f34f942188ec1404c..7f9257b042d21ec165a6e0ea42f991dcc5c1e54b 100644 (file)
@@ -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);
index a3d59834f2c1d7b50dc7000b2b6d041b5e549785..f137ee025a4f2287579270845063590eda11b443 100644 (file)
@@ -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;
 
index b7c1ba8af262a6196808cb343788b99390ac5813..5734e77bd6bd1d60c3c28fa234069ddd88c7b4c8 100644 (file)
@@ -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];
                        
index 4175ee90d3f4f3548a60ad0ea8ae6194aacbeb55..5bf6753f8eb00428a1e0174508cafd22b239974d 100644 (file)
@@ -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