summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wrapper/plugin-depend.c126
-rw-r--r--wrapper/plugin-parse.c144
-rw-r--r--wrapper/plugin.c87
-rw-r--r--wrapper/plugin.h136
-rw-r--r--wrapper/rvs.c16
-rw-r--r--wrapper/rvs.h55
6 files changed, 49 insertions, 515 deletions
diff --git a/wrapper/plugin-depend.c b/wrapper/plugin-depend.c
deleted file mode 100644
index d562489..0000000
--- a/wrapper/plugin-depend.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/* Copyright (C) 2009 Luke Shumaker
-
- This file is part of rvs.
-
- rvs is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- rvs is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with rvs; see the file COPYING.
- If not, write to the Free Software Foundation,
- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#ifndef FILE_plugin_depend_c_SEEN
-#define FILE_plugin_depend_c_SEEN
-
-/* translates a string in format `plugin/command' into a pointer to the command
- DON'T plan on using the string again, it will be mutilated!
- (so we go ahead and free() it and set the pointer to NULL) */
-struct plugin_command *
-_plugin_depend_parse (char **string, struct plugin_command *root)
-{
- struct plugin_command *command=NULL;
-
- if (*string==NULL)
- *string=root;
- else {
- /* *string is in the format `plugin/command' */
- /* char *del=delimeter */
- char *del=strchr(*string,'/');
- del[0]='\0';
- /// *string = PLUGIN_NAME
- /// &del[1] = COMMAND_NAME
- struct plugin *plugin;
- plugin =_plugin_find_plugin(root, *string );
- if (plugin==NULL)
- error(EXIT_FAILURE,0,"cannot find plugin `%s'",*string);
- command=_plugin_find_plugin_command(plugin->child, &del[1] );
- if (command==NULL)
- error(EXIT_FAILURE,0,
- "plugin `%s' does not contain command `%s'",
- *string,&del[1]);
- xfree(*string);
- *string=NULL;
- }
- return command;
-}
-
-/* used by _plugin_depend_add */
-void
-_plugin_depend_add2 (struct plugin_command *prev,
- struct plugin_command *next)
-{
- if (prev->d_next==NULL) {
- prev->d_next=next;
- } else {
- _plugin_depend_add2(prev->d_next,next);
- }
-}
-
-/* _plugin_depend_add(depend,depender) */
-void
-_plugin_depend_add (struct plugin_command *depend,
- struct plugin_command *depender)
-{
- if (depend->child==NULL) {
- depend->child=depender;
- } else {
- _plugin_depend_add2(depend->child,depender);
- }
-}
-
-/* take care of depends for `command', and those after it (linked list) */
-void
-_plugin_depend_command (struct plugin_command *command,
- struct plugin_command *root)
-{
- if (command->depends == NULL) {
- command->depend=root;
- } else {
- command->depend=_plugin_depend_parse(root,command->depends);
- command->depends=NULL;
- }
- _plugin_depend_add(command->depend,command);
- if (command->p_next != NULL)
- _plugin_depend_command(command->p_next,root);
-}
-
-/* take care of commands for a `plugin', and those after it (linked list) */
-void
-_plugin_depend_plugin_all (struct plugin *plugin, struct plugin_command *root)
-{
- _plugin_depend_command(plugin->child,root);
- if (plugin->next != NULL) {
- _plugin_depend_plugin_all(plugin->next,root);
- }
-}
-
-/* take care of all depends */
-struct plugin_command *
-_plugin_depend_all (struct plugin_command *plugins)
-{
- struct plugin_command *root=mkcommand();
-
- _plugin_depend_plugin_all(*plugins,root);
- return root;
-}
-
-/* take care of all depends for a particular command */
-struct plugin_command *
-_plugin_depend_name (char *name, struct plugin_command *plugins)
-{
- struct plugin_command *root=mkcommand();
-
- /* code goes here */
- return root;
-}
-
-#endif
-
diff --git a/wrapper/plugin-parse.c b/wrapper/plugin-parse.c
deleted file mode 100644
index 800098f..0000000
--- a/wrapper/plugin-parse.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/* Copyright (C) 2009 Luke Shumaker
-
- This file is part of rvs.
-
- rvs is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- rvs is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with rvs; see the file COPYING.
- If not, write to the Free Software Foundation,
- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#ifndef FILE_plugin_parse_c_SEEN
-#define FILE_plugin_parse_c_SEEN
-
-#include <stdio.h>
-
-/* these 2 are only used in _plugin_parse_escape */
-#include <stdlib.h>
-#include <error.h>
-
-#include "rvs.h"
-#include "plugin.h"
-
-void
-_plugin_parse_comment (FILE *file)
-{
- char c;
- while ( (c=getc(file)) != EOF ) {
- if ( c == '\n' ) {
- ungetc (c, file);
- break;
- }
- }
-}
-
-char
-_plugin_parse_escape(FILE *file)
-{
- char c=getc(file);
- switch (c) {
- case 'n':
- c = '\n';
- case '\\':
- case '#':
- case ':':
- break;
- default:
- error(EXIT_FAILURE,0,"syntax error");
- break;
- }
- return c;
-}
-
-char *
-_plugin_parse_depend (FILE *file)
-{
- size_t nbytes = 10;
- char *string = (char *)xmalloc(nbytes);
- string[0]='\0';
-
- char c[2] = " \0";
- char *cs = (char *)&c;
- while ( (c[0]=getc(file)) != EOF ) {
- if (c[0] == '\n') {
- ungetc (c[0], file);
- break;
- } else {
- switch (c[0]) {
- case '\\':
- c[0]=_plugin_parse_escape(file);
- stradds(&nbytes,&string,cs);
- break;
- case '#':
- _plugin_parse_comment(file);
- break;
- default:
- stradds(&nbytes,&string,cs);
- break;
- }
- }
- }
- return string;
-}
-
-struct plugin_command *
-_plugin_parse (FILE *file)
-{
- struct plugin_command *command=mkcommand();
-
- size_t nbytes = 10;
- char *string = (char *)xmalloc(nbytes);
- string[0]='\0';
-
- char c[2] = " \0";
- char *cs = (char *)&c;
-
- if ( (c[0]=getc(file)) == EOF )
- return NULL;
- else
- ungetc (c[0], file);
-
- while ( (c[0]=getc(file)) != EOF ) {
- if (c[0] == '\n') {
- if (strlen(string)==0) {
- xfree(command);
- xfree(string);
- command=_plugin_parse(file);
- } else {
- command->name=string;
- command->next=_plugin_parse(file);
- }
- break;
- } else {
- switch (c[0]) {
- case '\\':
- c[0]=_plugin_parse_escape(file);
- stradds(&nbytes,&string,cs);
- break;
- case '#':
- _plugin_parse_comment(file);
- break;
- case ':':
- command->depends=_plugin_parse_depend(
- file);
- break;
- default:
- stradds(&nbytes,&string,cs);
- break;
- }
- }
- }
- return command;
-}
-
-#endif
-
diff --git a/wrapper/plugin.c b/wrapper/plugin.c
deleted file mode 100644
index 6301bbb..0000000
--- a/wrapper/plugin.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/* Copyright (C) 2009 Luke Shumaker
-
- This file is part of rvs.
-
- rvs is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- rvs is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with rvs; see the file COPYING.
- If not, write to the Free Software Foundation,
- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#ifndef FILE_plugin_c_SEEN
-#define FILE_plugin_c_SEEN
-
-#include "rvs.h"
-#include "plugin.h"
-
-#include "plugin-parse.c"
-
-/* directory listing for load_plugins */
-/* there seriously has to be a better way to do this */
-#include <string.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/stat.h>
-
-/* assume we're in rvs's libexecdir, where plugins are
- now, load plugin plug_name,
- whose configuration file is plugin_conf */
-struct plugin *
-_plugin_load (const char *plug_name, const char *plugin_conf)
-{
- struct plugin *plugin=xmalloc( sizeof(*plugin) );
- plugin->name=stralloc(plug_name);
- plugin->next=NULL;
- xchdir(plug_name);
- FILE *file = xfopen(plugin_conf,"r");
- plugin->commands=_plugin_parse(file);
- fclose( file );
-
- xchdir("..");
- return plugin;
-}
-
-/* load all the plugins in libexecdir, using the config file plugin_conf */
-struct plugin *
-load_plugins (const char *libexecdir, const char *plugin_conf)
-{
- struct plugin *first=NULL; /* we return this */
- struct plugin **prev=&first; /* this is the previous plugin->next */
- struct plugin *plugin; /* this is the current plugin */
-
- xchdir(libexecdir);
-
- /* Yeah, I know this next bit is pretty ugly. */
- DIR *cwd;
- struct dirent *dirent;
- int serr;
- struct stat sbuf;
- cwd = xopendir ("./");
- while ( (dirent = readdir (cwd)) != NULL ) {
- if ((strcmp(dirent->d_name,"." )!=0)&&
- (strcmp(dirent->d_name,"..")!=0)) {
- serr = stat(dirent->d_name, &sbuf);
- if (!serr && S_ISDIR(sbuf.st_mode)) {
- plugin=_plugin_load(dirent->d_name,plugin_conf);
- *prev=plugin;/* this sets the last's `next' */
- prev=&plugin->next;
- }
- }
- }
- closedir (cwd);
-
- xchdir("..");
- return first;
-}
-
-#endif
-
diff --git a/wrapper/plugin.h b/wrapper/plugin.h
deleted file mode 100644
index 4672895..0000000
--- a/wrapper/plugin.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/* Copyright (C) 2009 Luke Shumaker
-
- This file is part of rvs.
-
- rvs is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- rvs is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with rvs; see the file COPYING.
- If not, write to the Free Software Foundation,
- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#ifndef FILE_plugin_h_SEEN
-#define FILE_plugin_h_SEEN
-
-#include "rvs.h"
-
-/* a plugin */
-/* a generic binary tree emulating a n-ary tree via linked list */
-struct plugin
-{
- char *name;
- struct plugin_command *commands;/* left leaf */
- struct plugin *next; /* right leaf */
-};
-
-/* a single plugin command */
-struct plugin_command
-{
- /* node */
- char *name;
- struct plugin *plugin; /* which plugin does it belong to? */
- struct plugin_command *depend; /* what does this depend on? */
- char *depends;/* what does this depend on? (string) */
-
- /* linked list */
- struct plugin_command *next;
-};
-
-/* create a blank plugin_command */
-struct plugin_command *
-mkcommand()
-{
- struct plugin_command *command;
- command=(struct plugin_command *)xmalloc(sizeof(*command));
-
- /* node */
- command->name=NULL;
- command->plugin=NULL;
- command->depend=NULL;
- command->depends=NULL;
-
- /* linked list */
- command->next=NULL;
-
- return command;
-}
-
-
-struct plugin *
-plugin_find_plugin(struct plugin *node, char *name)
-{
-
- if (node==NULL)
- return node;
- else {
- if (strcmp(node->name,name) == 0)
- return node;
- else
- return plugin_find_plugin(node->next,name);
- }
-}
-
-struct plugin_command *
-plugin_find_plugin_command(struct plugin_command *node, char *name)
-{
- if (node==NULL)
- return node;
- else {
- if (strcmp(node->name,name) == 0)
- return node;
- else
- return plugin_find_plugin_command(node->next,name);
- }
-}
-
-/* returns the first command with `name' it finds
- Perhaps it should return a linked list of all commands with `name'?
- This would require a dedicated struct for the function.
- That makes me kind of want to move it to another file. */
-struct plugin_command *
-plugin_find_command(struct plugin *plugin, char *name)
-{
- struct plugin_command *ret;
- ret=plugin_find_plugin_command(plugin->commands,name);
- if (ret == NULL)
- ret=plugin_find_command(plugin->next,name);
- return ret;
-}
-
-void
-plugin_free_command(struct plugin_command *command)
-{
- if (command!=NULL) {
- #ifdef DEBUG
- printf(" + %s\n",command->name);
- #endif
- xfree(command->name);
- xfree(command->depends);
- xfree(command);
- plugin_free_command(command->next);
- }
-}
-
-void
-plugin_free_plugin(struct plugin *plugin)
-{
- if (plugin!=NULL) {
- #ifdef DEBUG
- printf(" - %s\n",plugin->name);
- #endif
- xfree(plugin->name);
- plugin_free_command(plugin->commands);
- plugin_free_plugin(plugin->next);
- }
-}
-
-#endif
-
diff --git a/wrapper/rvs.c b/wrapper/rvs.c
index 9125ff0..881b65f 100644
--- a/wrapper/rvs.c
+++ b/wrapper/rvs.c
@@ -20,19 +20,29 @@ const char *ver="0.8c";
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/*#define DEBUG*/
+#define DEBUG
#include "rvs.h"
-#include "plugin.c"
-/*#include "debug.h"*/
+#include "plugins.h"
+#include "plugin-load.h"
+#include "plugin-find.h"
+#include "plugin-depend.h"
const char *libexecdir="./plugins";
const char *plugin_conf="plugin.conf";
+void foobar(){puts("");}
+
int
main ( int argc, char *argv[] )
{
struct plugin *plugins=load_plugins(libexecdir,plugin_conf);
+ if (argc > 1) {
+ struct plugin_command_list *list;
+ list=plugin_find_commands(plugins,argv[1]);
+ plugin_depend_list(list,plugins);
+ }
plugin_free_plugin(plugins);
+ foobar();
return 0;
}
diff --git a/wrapper/rvs.h b/wrapper/rvs.h
index 447b533..bf8c1f5 100644
--- a/wrapper/rvs.h
+++ b/wrapper/rvs.h
@@ -1,4 +1,6 @@
-/* Copyright (C) 2009 Luke Shumaker
+/* wrapper/rvs.h -- rvs program header, contains most system-dependand code,
+ and general-purose functions.
+ Copyright (C) 2009 Luke Shumaker
This file is part of rvs.
@@ -21,19 +23,27 @@
#define FILE_rvs_h_SEEN
#include <stdio.h>
-#include <dirent.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <error.h>
+/* glibc */
extern char *program_invocation_name;
+extern char *program_invocation_short_name;
+
+/* stdlib.h */
+/*extern int EXIT_SUCCESS;*/
+/*extern int EXIT_FAILURE;*/
void *
xmalloc (size_t size)
{
void *value = malloc (size);
+ #ifdef DEBUG_ALLOC
+ printf("x=%p\n",value);
+ #endif
if (value == NULL) {
perror(program_invocation_name);
exit(EXIT_FAILURE);
@@ -45,6 +55,9 @@ void *
xrealloc (void *ptr, size_t size)
{
void *value = realloc (ptr, size);
+ #ifdef DEBUG_ALLOC
+ printf("x/%p -> %p\n",ptr,value);
+ #endif
if (value == NULL) {
perror(program_invocation_name);
exit(EXIT_FAILURE);
@@ -55,15 +68,17 @@ xrealloc (void *ptr, size_t size)
void
xfree (void *ptr)
{
- free (ptr);
+ if (ptr!=NULL)
+ #ifdef DEBUG_ALLOC
+ printf("x-%p\n",ptr);
+ #endif
+ free (ptr);
}
+/* unistd.h */
int
xchdir (const char *filename)
{
- #ifdef DEBUG
- puts (filename);
- #endif
int ret=chdir(filename);
if (ret != 0) {
error(EXIT_FAILURE,errno,"%s/",filename);
@@ -71,6 +86,7 @@ xchdir (const char *filename)
return ret;
}
+/* stdio.h */
FILE *
xfopen (const char *filename, const char *opentype)
{
@@ -83,17 +99,7 @@ xfopen (const char *filename, const char *opentype)
return file;
}
-DIR *
-xopendir (const char *dirname)
-{
- DIR *dir = opendir (dirname);
- if (dir == NULL) {
- error(EXIT_FAILURE,errno,"%s/",dirname);
- }
-
- return dir;
-}
-
+/* string funtions */
void
stradds(size_t *size, char **dest, char *str)
{
@@ -105,12 +111,23 @@ stradds(size_t *size, char **dest, char *str)
strcat(*dest, str);
}
}
-
+size_t
+xstrlen (const char *s)
+{
+ printf("xstrlen(%p)\n",s);
+ size_t size=0;
+ while (s[size] != '\0') {
+ printf("%i = %p `%c'\n",size,&s[size],s[size]);
+ size++;
+ }
+ return size;
+}
char *
stralloc (const char *string)
{
- char *copy = (char *)xmalloc(strlen(string)+1);
+ char *copy = (char *)xmalloc(xstrlen(string)+1);
strcpy(copy,string);
+ puts(copy);
return copy;
}