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 */
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; }
-
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);
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);
}
/* 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;
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;
_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