From ea8a13dfa2a25f52cc245a8992fbff5d1e41106d Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 5 Sep 2009 13:00:55 -0400 Subject: work on tieing it all together --- Makefile.in | 49 ++++++++--------- c/Makefile | 8 --- c/plugin-debug.c | 87 ----------------------------- c/plugin-depend.c | 102 ---------------------------------- c/plugin-parse.c | 135 --------------------------------------------- c/plugin.c | 124 ----------------------------------------- c/plugin.h | 49 ----------------- c/rvs.c | 35 ------------ c/rvs.h | 91 ------------------------------ c/test.c | 9 --- configure | 3 +- plugins/repo/Makefile.in | 1 + plugins/users/Makefile.in | 1 + wrapper/Makefile.in | 77 ++++++++++++++++++++++++++ wrapper/plugin-debug.c | 91 ++++++++++++++++++++++++++++++ wrapper/plugin-depend.c | 106 +++++++++++++++++++++++++++++++++++ wrapper/plugin-parse.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++ wrapper/plugin.c | 128 +++++++++++++++++++++++++++++++++++++++++++ wrapper/plugin.h | 53 ++++++++++++++++++ wrapper/rvs.c | 35 ++++++++++++ wrapper/rvs.h | 95 ++++++++++++++++++++++++++++++++ wrapper/test.c | 9 +++ 22 files changed, 759 insertions(+), 666 deletions(-) delete mode 100755 c/Makefile delete mode 100644 c/plugin-debug.c delete mode 100644 c/plugin-depend.c delete mode 100644 c/plugin-parse.c delete mode 100644 c/plugin.c delete mode 100644 c/plugin.h delete mode 100644 c/rvs.c delete mode 100644 c/rvs.h delete mode 100644 c/test.c create mode 100755 wrapper/Makefile.in create mode 100644 wrapper/plugin-debug.c create mode 100644 wrapper/plugin-depend.c create mode 100644 wrapper/plugin-parse.c create mode 100644 wrapper/plugin.c create mode 100644 wrapper/plugin.h create mode 100644 wrapper/rvs.c create mode 100644 wrapper/rvs.h create mode 100644 wrapper/test.c diff --git a/Makefile.in b/Makefile.in index 165d11b..bef0841 100644 --- a/Makefile.in +++ b/Makefile.in @@ -31,6 +31,7 @@ dirs = $(srcdir) $(prefix) $(exec_prefix) $(bindir) $(sbindir) $(libexecdir)/ export srcdir prefix exec_prefix bindir sbindir libexecdir # programs ######################################################### +CC = @CC@ RVS = @RVS@ SHELL = @SHELL@ RM = rm -f @@ -44,40 +45,29 @@ TOUCH = touch export RVS SHELL RM CP SED INSTALL MKDIR INSTALL_PROGRAM INSTALL_DATA TOUCH # plugins ########################################################## -plugins = $(patsubst $(srcdir)/plugins/%,%,\ +plugins = $(patsubst $(srcdir)/plugins/%,%, \ $(shell find $(srcdir)/plugins/* -maxdepth 0 -type d)) build-plugins = $(addprefix p-,$(plugins)) -install-plugins = $(addprefix install-p-,$(plugins)) +#install-plugins = $(addprefix install-p-,$(plugins)) +uninstall-plugins = $(addprefix uninstall-p-,$(plugins)) clean-plugins = $(addprefix clean-p-,$(plugins)) distclean-plugins = $(addprefix distclean-p-,$(plugins)) - -#uninstall-plugins = $(addprefix uninstall-p-,$(plugins)) -#dist-plugins = $(addprefix dist-p-,$(plugins)) +dist-plugins = $(addprefix dist-p-,$(plugins)) # phony targets #################################################### all : $(rvs) $(build-plugins) -.PHONY : install uninstall clean distclean libexec +.PHONY : install uninstall clean distclean dist libexec $(build-plugins) $(rvs)\ +$(install-plugins) $(uninstall-plugins) $(clean-plugins) $(distclean-plugins) \ + install-$(rvs) uninstall-$(rvs) clean-$(rvs) distclean-$(rvs) \ +$(dist-plugins) \ + dist-$(rvs) .SUFFIXES : -# build ############################################################ -b := @ -$(rvs) : $(srcdir)/rvs.sh - $(SED) \ - -e 's/$bSHELL@/$(subst /,\/,$(SHELL))/g' \ - -e 's/$blibexecdir@/$(subst /,\/,$(libexecdir))/g' \ - -e 's/$bname@/$(subst /,\/,$(name))/g' \ - < $< > $@ - # install ########################################################## -install : install-$(name) libexec $(install-plugins) +install : install-$(rvs) libexec $(install-plugins) -# core executable -install-$(name) : $(RVS) -$(RVS) : $(rvs) $(bindir) - $(INSTALL_PROGRAM) $< $@ - # $(libexecdir)/rvs/* libexec : $(libexecdir)/$(rvs)/plugins $(libexecdir)/$(rvs)/plugins : $(libexecdir)/$(rvs) @@ -91,12 +81,10 @@ uninstall : # clean ############################################################ -clean : $(clean-plugins) - $(RM) var.sed +clean : $(clean-plugins) clean-$(rvs) -distclean : clean $(distclean-plugins) +distclean : clean $(distclean-plugins) distclean-$(rvs) $(RM) Makefile - $(RM) $(rvs) # dist ############################################################# @@ -110,6 +98,17 @@ $(d) : distclean $(INSTALL) -m 777 -d $@ $(CP) -r $(srcdir)/* $@ +# wrapper ########################################################## + +$(rvs) : wrapper/ wrapper/Makefile; $(MAKE) -C $< +uninstall-$(rvs) : wrapper/ wrapper/Makefile; $(MAKE) -C $< uninstall +clean-$(rvs) : wrapper/ wrapper/Makefile; $(MAKE) -C $< clean +distclean-$(rvs) : wrapper/ wrapper/Makefile; $(MAKE) -C $< distclean +dist-$(rvs) : wrapper/ wrapper/Makefile; $(MAKE) -C $< dist + +install-$(rvs) : wrapper/ wrapper/Makefile $(rvs); $(MAKE) -C $< install +$(RVS) : install-$(rvs) + # plugins ########################################################## install-p-% : plugins/% plugins/%/Makefile p-% libexec $(RVS) diff --git a/c/Makefile b/c/Makefile deleted file mode 100755 index 61a4763..0000000 --- a/c/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/make -f -CC = gcc - -all : - $(CC) rvs.c -Wall -ansi -g -o rvs - -test : test.c rvs.h plugin.c plugin.h plugin-debug.c plugin-depends.c - $(CC) test.c -Wall -ansi -g -o test diff --git a/c/plugin-debug.c b/c/plugin-debug.c deleted file mode 100644 index 553237d..0000000 --- a/c/plugin-debug.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. -*/ - -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; -} - -void _plugin_print_plugin_command(struct plugin_command *command) -{ - if (command != NULL) { - printf(" - %s\n",command->name); - if (command->depends != NULL) - printf(" depend string: %s\n",command->depends); - if (command->depend->plugin == NULL) { - puts (" depend: "); - } else { - printf(" depend: %s / %s\n", - command->depend->plugin->name, - command->depend->name); - } - _plugin_print_plugin_command(command->p_next); - } -} - -void _plugin_print_plugin(struct plugin *plugin) -{ - if (plugin != NULL) { - printf(" %s\n",plugin->name); - _plugin_print_plugin_command(plugin->child); - _plugin_print_plugin(plugin->next); - } -} - -void _plugin_print_depend(struct plugin_command *command,size_t indent) -{ - int i=0; - while (i < indent) { - printf(" "); - i++; - } - if (command->name == NULL) { - puts(""); - } else { - printf("%s / %s\n", - command->plugin->name, - command->name); - } - if (command->child != NULL) { - _plugin_print_depend(command->child,indent+1); - } - if (command->d_next != NULL) { - _plugin_print_depend(command->d_next,indent); - } -} - -void _plugin_print(struct plugin_tree *tree) -{ - puts("Plugins:"); - _plugin_print_plugin(tree->plugins); - puts("\nDepends:"); - _plugin_print_depend(tree->depends,0); -} - diff --git a/c/plugin-depend.c b/c/plugin-depend.c deleted file mode 100644 index 4101fe1..0000000 --- a/c/plugin-depend.c +++ /dev/null @@ -1,102 +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. -*/ - -/* translates a string in syntax `plugin/command' into a pointer to the commnad - DON'T plan on using the string again, it will be mutilated! - (so we go ahead and free() it) */ -struct plugin_command * -_plugin_depend_parse(struct plugin *root, char *string) -{ - char *c=strchr(string,'/'); - c[0]='\0'; - return _plugin_find_command( - _plugin_find_plugin(root,string)->child, - &c[1]); - xfree(string); -} - -/* 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_tree *tree) -{ - if (command->depends == NULL) { - command->depend=tree->depends; - } else { - command->depend=_plugin_depend_parse(tree->plugins,command->depends); - command->depends=NULL; - } - _plugin_depend_add(command->depend,command); - if (command->p_next != NULL) - _plugin_depend_command(command->p_next,tree); -} - -/* take care of commands for a `plugin', and those after it (linked list) */ -void -_plugin_depend_plugin(struct plugin *plugin, struct plugin_tree *tree) -{ - _plugin_depend_command(plugin->child,tree); - if (plugin->next != NULL) { - _plugin_depend_plugin(plugin->next,tree); - } -} - -/* take care of all depends */ -void -_plugin_depend(struct plugin_tree *tree) -{ - /* add a blank `root' command for those that don't have depends */ - struct plugin_command *command; - command=(struct plugin_command *)xmalloc(sizeof(*command)); - command->name=NULL; - command->plugin=NULL; - command->p_next=NULL; - command->depend=NULL; - command->depends=NULL; - command->child=NULL;/*<--only variable of any value */ - command->d_next=NULL; - - tree->depends=command; - - /* parse all commands */ - _plugin_depend_plugin(tree->plugins,tree); -} - diff --git a/c/plugin-parse.c b/c/plugin-parse.c deleted file mode 100644 index c333193..0000000 --- a/c/plugin-parse.c +++ /dev/null @@ -1,135 +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. -*/ - - -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 (struct plugin *plugin, FILE *file) -{ - struct plugin_command *command; - command=(struct plugin_command *)xmalloc(sizeof(*command)); - - command->plugin=plugin; - command->p_next=NULL; - - command->depend=NULL; - command->depends=NULL; - command->child=NULL; - command->d_next=NULL; - - 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 (strcmp(string,"")==0) { - xfree(command); - xfree(string); - command=_plugin_parse(plugin, file); - } else { - command->name=string; - command->p_next=_plugin_parse(plugin, 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; -} - diff --git a/c/plugin.c b/c/plugin.c deleted file mode 100644 index 7182626..0000000 --- a/c/plugin.c +++ /dev/null @@ -1,124 +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. -*/ - -#include -#include /* EXIT_FAILURE */ -#include /* file acces */ -#include - -#include -#include - -#include -#include - -#include "rvs.h" -#include "plugin.h" - -/* finds a plugin with `name'. Start looking at `plugin' (linked list) */ -struct plugin * -_plugin_find_plugin(struct plugin *plugin, char *name) -{ - if (strcmp(plugin->name,name) == 0) { - return plugin; - } else { - if (plugin->next==NULL) { - error(EXIT_FAILURE,0,"cannot find plugin `%s'",name); - return NULL; - } else { - return _plugin_find_plugin(plugin->next,name); - } - } -} - -/* finds a command with `name'. Start looking at `command' (linked list) */ -struct plugin_command * -_plugin_find_command(struct plugin_command *command, char *name) -{ - if (strcmp(command->name,name) == 0) { - return command; - } else { - if (command->p_next==NULL) { - error(EXIT_FAILURE,0, - "plugin `%s' does not contain command `%s'", - command->plugin->name,name); - return NULL; - } else { - return _plugin_find_command(command->p_next,name); - } - } -} - -#include "plugin-parse.c" -#include "plugin-depend.c" - -struct plugin * -_plugin_load (char *plug_name, char *plugin_conf) -{ - struct plugin *plugin=(struct plugin *)xmalloc(sizeof(*plugin)); - char *plug_name2 = (char *)xmalloc(strlen(plug_name)+1); - strcpy(plug_name2,plug_name); - plugin->name=plug_name2; - plugin->next=NULL; - - xchdir(plug_name); - FILE *file = xfopen(plugin_conf,"r"); - - plugin->child=_plugin_parse(plugin, file); - - fclose( file ); - xchdir(".."); - return plugin; -} - -struct plugin_tree * -load_plugins (char *libexecdir, char *plugin_conf) -{ - struct plugin_tree *tree=(struct plugin_tree *)xmalloc(sizeof(*tree)); - struct plugin **last=&tree->plugins; - *last=NULL; - struct plugin *plugin; - - xchdir(libexecdir); - - 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); - *last=plugin;/* this sets the last's `next' */ - last=&plugin->next; - } - } - } - closedir (cwd); - - _plugin_depend(tree); - - xchdir(".."); - return tree; -} - diff --git a/c/plugin.h b/c/plugin.h deleted file mode 100644 index d5ede8f..0000000 --- a/c/plugin.h +++ /dev/null @@ -1,49 +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. -*/ - -struct plugin -{ - char *name; - - struct plugin_command *child; - struct plugin *next; -}; - -struct plugin_command -{ - char *name; - - /*plugin ID*/ - struct plugin *plugin; /* which plugin does it belong to? */ - struct plugin_command *p_next; /* next command in this plugin (linked list)*/ - - /*dependancy tree*/ - struct plugin_command *depend; /* what does this depend on? */ - char *depends;/* what does this depend on? */ - struct plugin_command *child; /* what depends on this? (linked list) */ - struct plugin_command *d_next; /* next command w/ same dependancy (linked list) */ -}; - -struct plugin_tree -{ - struct plugin *plugins; - struct plugin_command *depends; -}; - diff --git a/c/rvs.c b/c/rvs.c deleted file mode 100644 index 56162ac..0000000 --- a/c/rvs.c +++ /dev/null @@ -1,35 +0,0 @@ -const char *name="rvs"; -const char *ver="0.8c"; -/* 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. -*/ - -#include "rvs.h" -#include "plugin.c" - -const char *libexecdir="./plugins"; -const char *plugin_conf="plugin.conf"; - -int -main (void) -{ - struct plugin_tree *plugins=load_plugins(libexecdir,plugin_conf); - return 0; -} - diff --git a/c/rvs.h b/c/rvs.h deleted file mode 100644 index 5301b09..0000000 --- a/c/rvs.h +++ /dev/null @@ -1,91 +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. -*/ - -#include -#include -#include -#include -#include -#include -#include - -void *xmalloc (size_t size) -{ - void *value = malloc (size); - if (value == NULL) - error(EXIT_FAILURE,0,"virtual memory exhausted"); - return value; -} - -void *xrealloc (void *ptr, size_t size) -{ - void *value = realloc (ptr, size); - if (value == NULL) - error(EXIT_FAILURE,0,"virtual memory exhausted"); - return value; -} - -void xfree (void *ptr) -{ - free (ptr); -} - -int xchdir (const char *filename) -{ - int ret=chdir(filename); - if (ret != 0) { - error(EXIT_FAILURE,errno,"%s/",filename); - } - return ret; -} - -FILE *xfopen (const char *filename, const char *opentype) -{ - FILE *file = fopen(filename,opentype); - /* fopen gives NULL on failure */ - if ( file == NULL ) { - error(EXIT_FAILURE,errno,"%s",filename); - } - - return file; -} - -DIR *xopendir (const char *dirname) -{ - DIR *dir = opendir (dirname); - if (dir == NULL) { - error(EXIT_FAILURE,errno,"%s/",dirname); - } - - return dir; -} - -void stradds(size_t *size, char **dest, char *str) -{ - if (*size > ( strlen(*dest) + strlen(str) )) { - strcat(*dest, str); - } else { - *size = strlen(*dest) + strlen(str) + 1; - - *dest = (char *) xrealloc (*dest, *size); - strcat(*dest, str); - } -} - diff --git a/c/test.c b/c/test.c deleted file mode 100644 index 3a9abc9..0000000 --- a/c/test.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "plugin.c" -#include "plugin-debug.c" - -int main() { - struct plugin_tree *plugins=load_plugins("plugins","plugin.conf"); - _plugin_print(plugins); - return 0; -} - diff --git a/configure b/configure index 69fcd32..5e19b16 100755 --- a/configure +++ b/configure @@ -20,6 +20,7 @@ name='configure' # rvs configureation script # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. _name='rvs' + _CC='gcc' _RVS='$(bindir)/$(rvs)' _SHELL='/bin/sh' _prefix='/usr/local' @@ -29,7 +30,7 @@ _exec_prefix='$(prefix)' _libexecdir='$(exec_prefix)/libexec' _srcdir=$(readlink -f `dirname "$0"`) -vars='name RVS SHELL prefix exec_prefix bindir sbindir libexecdir srcdir' +vars='name CC RVS SHELL prefix exec_prefix bindir sbindir libexecdir srcdir' error() { echo "$name: $1" >> /dev/stderr diff --git a/plugins/repo/Makefile.in b/plugins/repo/Makefile.in index 8409705..412fb8e 100644 --- a/plugins/repo/Makefile.in +++ b/plugins/repo/Makefile.in @@ -31,6 +31,7 @@ dirs = $(srcdir) $(prefix) $(exec_prefix) $(bindir) $(sbindir) $(libexecdir)/ #export srcdir prefix exec_prefix bindir sbindir libexecdir # programs ######################################################### +CC ?= @CC@ RVS ?= @RVS@ SHELL ?= @SHELL@ RM ?= rm diff --git a/plugins/users/Makefile.in b/plugins/users/Makefile.in index 5de6cb3..4d9df82 100644 --- a/plugins/users/Makefile.in +++ b/plugins/users/Makefile.in @@ -31,6 +31,7 @@ dirs = $(srcdir) $(prefix) $(exec_prefix) $(bindir) $(sbindir) $(libexecdir)/ #export srcdir prefix exec_prefix bindir sbindir libexecdir # programs ######################################################### +CC ?= @CC@ RVS ?= @RVS@ SHELL ?= @SHELL@ RM ?= rm diff --git a/wrapper/Makefile.in b/wrapper/Makefile.in new file mode 100755 index 0000000..85f56f7 --- /dev/null +++ b/wrapper/Makefile.in @@ -0,0 +1,77 @@ +#!/usr/bin/make -f +name = @name@ +ver = 0.8c +# 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. + +export rvs ?= @name@ +# directories ###################################################### +srcdir ?= @srcdir@ +prefix ?= @prefix@ +exec_prefix ?= @exec_prefix@ +bindir ?= @bindir@ +sbindir ?= @sbindir@ +libexecdir ?= @libexecdir@ +dirs = $(srcdir) $(prefix) $(exec_prefix) $(bindir) $(sbindir) $(libexecdir)/ +#export srcdir prefix exec_prefix bindir sbindir libexecdir + +# programs ######################################################### +RVS ?= @RVS@ +SHELL ?= @SHELL@ +RM ?= rm +CP ?= cp +SED ?= sed +INSTALL ?= install +MKDIR ?= $(INSTALL) -d #mkdir -p +INSTALL_PROGRAM ?= $(INSTALL) +INSTALL_DATA ?= $(INSTALL) -m 644 +TOUCH ?= touch # This file doesn't use touch +#export RVS SHELL RM CP SED INSTALL MKDIR INSTALL_PROGRAM INSTALL_DATA TOUCH + +# phony targets #################################################### +all : rvs +.PHONY : install uninstall clean distclean dist +.SUFFIXES : .c .o +VPATH = $(srcdir)/wrapper + +# most everything ################################################## +install : $(RVS) +$(RVS) : rvs $(bindir) + $(INSTALL_PROGRAM) $< $@ + +uninstall : + $(RM) $(RVS) + +clean : + +distclean : clean + $(RM) rvs + $(RM) Makefile + +# dist ############################################################# + +d = $(name)-$(ver) +dist : $(d).tar.gz + +$(d).tar.gz : $(d) + tar -czf $@ $< + +$(d) : distclean + $(INSTALL) -m 777 -d $@ + $(CP) -r $(srcdir)/* $@ + diff --git a/wrapper/plugin-debug.c b/wrapper/plugin-debug.c new file mode 100644 index 0000000..a0c8022 --- /dev/null +++ b/wrapper/plugin-debug.c @@ -0,0 +1,91 @@ +/* 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-debug.c_SEEN +#define FILE_plugin-debug.c_SEEN + +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; +} + +void _plugin_print_plugin_command(struct plugin_command *command) +{ + if (command != NULL) { + printf(" - %s\n",command->name); + if (command->depends != NULL) + printf(" depend string: %s\n",command->depends); + if (command->depend->plugin == NULL) { + puts (" depend: "); + } else { + printf(" depend: %s / %s\n", + command->depend->plugin->name, + command->depend->name); + } + _plugin_print_plugin_command(command->p_next); + } +} + +void _plugin_print_plugin(struct plugin *plugin) +{ + if (plugin != NULL) { + printf(" %s\n",plugin->name); + _plugin_print_plugin_command(plugin->child); + _plugin_print_plugin(plugin->next); + } +} + +void _plugin_print_depend(struct plugin_command *command,size_t indent) +{ + int i=0; + while (i < indent) { + printf(" "); + i++; + } + if (command->name == NULL) { + puts(""); + } else { + printf("%s / %s\n", + command->plugin->name, + command->name); + } + if (command->child != NULL) { + _plugin_print_depend(command->child,indent+1); + } + if (command->d_next != NULL) { + _plugin_print_depend(command->d_next,indent); + } +} + +void _plugin_print(struct plugin_tree *tree) +{ + puts("Plugins:"); + _plugin_print_plugin(tree->plugins); + puts("\nDepends:"); + _plugin_print_depend(tree->depends,0); +} + +#endif + diff --git a/wrapper/plugin-depend.c b/wrapper/plugin-depend.c new file mode 100644 index 0000000..3dfbf1b --- /dev/null +++ b/wrapper/plugin-depend.c @@ -0,0 +1,106 @@ +/* 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 syntax `plugin/command' into a pointer to the commnad + DON'T plan on using the string again, it will be mutilated! + (so we go ahead and free() it) */ +struct plugin_command * +_plugin_depend_parse(struct plugin *root, char *string) +{ + char *c=strchr(string,'/'); + c[0]='\0'; + return _plugin_find_command( + _plugin_find_plugin(root,string)->child, + &c[1]); + xfree(string); +} + +/* 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_tree *tree) +{ + if (command->depends == NULL) { + command->depend=tree->depends; + } else { + command->depend=_plugin_depend_parse(tree->plugins,command->depends); + command->depends=NULL; + } + _plugin_depend_add(command->depend,command); + if (command->p_next != NULL) + _plugin_depend_command(command->p_next,tree); +} + +/* take care of commands for a `plugin', and those after it (linked list) */ +void +_plugin_depend_plugin(struct plugin *plugin, struct plugin_tree *tree) +{ + _plugin_depend_command(plugin->child,tree); + if (plugin->next != NULL) { + _plugin_depend_plugin(plugin->next,tree); + } +} + +/* take care of all depends */ +void +_plugin_depend(struct plugin_tree *tree) +{ + /* add a blank `root' command for those that don't have depends */ + struct plugin_command *command; + command=(struct plugin_command *)xmalloc(sizeof(*command)); + command->name=NULL; + command->plugin=NULL; + command->p_next=NULL; + command->depend=NULL; + command->depends=NULL; + command->child=NULL;/*<--only variable of any value */ + command->d_next=NULL; + + tree->depends=command; + + /* parse all commands */ + _plugin_depend_plugin(tree->plugins,tree); +} + +#endif + diff --git a/wrapper/plugin-parse.c b/wrapper/plugin-parse.c new file mode 100644 index 0000000..3be7543 --- /dev/null +++ b/wrapper/plugin-parse.c @@ -0,0 +1,137 @@ +/* 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 + +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 (struct plugin *plugin, FILE *file) +{ + struct plugin_command *command; + command=(struct plugin_command *)xmalloc(sizeof(*command)); + + command->plugin=plugin; + command->p_next=NULL; + + command->depend=NULL; + command->depends=NULL; + command->child=NULL; + command->d_next=NULL; + + 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 (strcmp(string,"")==0) { + xfree(command); + xfree(string); + command=_plugin_parse(plugin, file); + } else { + command->name=string; + command->p_next=_plugin_parse(plugin, 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 new file mode 100644 index 0000000..c5d8f38 --- /dev/null +++ b/wrapper/plugin.c @@ -0,0 +1,128 @@ +/* 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 +#include /* EXIT_FAILURE */ +#include /* file acces */ +#include + +#include +#include + +#include +#include + +/*#include "rvs.h"*/ +#include "plugin.h" + +/* finds a plugin with `name'. Start looking at `plugin' (linked list) */ +struct plugin * +_plugin_find_plugin(struct plugin *plugin, char *name) +{ + if (strcmp(plugin->name,name) == 0) { + return plugin; + } else { + if (plugin->next==NULL) { + error(EXIT_FAILURE,0,"cannot find plugin `%s'",name); + return NULL; + } else { + return _plugin_find_plugin(plugin->next,name); + } + } +} + +/* finds a command with `name'. Start looking at `command' (linked list) */ +struct plugin_command * +_plugin_find_command(struct plugin_command *command, char *name) +{ + if (strcmp(command->name,name) == 0) { + return command; + } else { + if (command->p_next==NULL) { + error(EXIT_FAILURE,0, + "plugin `%s' does not contain command `%s'", + command->plugin->name,name); + return NULL; + } else { + return _plugin_find_command(command->p_next,name); + } + } +} + +#include "plugin-parse.c" +#include "plugin-depend.c" + +struct plugin * +_plugin_load (char *plug_name, char *plugin_conf) +{ + struct plugin *plugin=(struct plugin *)xmalloc(sizeof(*plugin)); + char *plug_name2 = (char *)xmalloc(strlen(plug_name)+1); + strcpy(plug_name2,plug_name); + plugin->name=plug_name2; + plugin->next=NULL; + + xchdir(plug_name); + FILE *file = xfopen(plugin_conf,"r"); + + plugin->child=_plugin_parse(plugin, file); + + fclose( file ); + xchdir(".."); + return plugin; +} + +struct plugin_tree * +load_plugins (char *libexecdir, char *plugin_conf) +{ + struct plugin_tree *tree=(struct plugin_tree *)xmalloc(sizeof(*tree)); + struct plugin **last=&tree->plugins; + *last=NULL; + struct plugin *plugin; + + xchdir(libexecdir); + + 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); + *last=plugin;/* this sets the last's `next' */ + last=&plugin->next; + } + } + } + closedir (cwd); + + _plugin_depend(tree); + + xchdir(".."); + return tree; +} + +#endif + diff --git a/wrapper/plugin.h b/wrapper/plugin.h new file mode 100644 index 0000000..5eff78e --- /dev/null +++ b/wrapper/plugin.h @@ -0,0 +1,53 @@ +/* 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 + +struct plugin +{ + char *name; + + struct plugin_command *child; + struct plugin *next; +}; + +struct plugin_command +{ + char *name; + + /*plugin ID*/ + struct plugin *plugin; /* which plugin does it belong to? */ + struct plugin_command *p_next; /* next command in this plugin (linked list)*/ + + /*dependancy tree*/ + struct plugin_command *depend; /* what does this depend on? */ + char *depends;/* what does this depend on? */ + struct plugin_command *child; /* what depends on this? (linked list) */ + struct plugin_command *d_next; /* next command w/ same dependancy (linked list) */ +}; + +struct plugin_tree +{ + struct plugin *plugins; + struct plugin_command *depends; +}; + +#endif + diff --git a/wrapper/rvs.c b/wrapper/rvs.c new file mode 100644 index 0000000..56162ac --- /dev/null +++ b/wrapper/rvs.c @@ -0,0 +1,35 @@ +const char *name="rvs"; +const char *ver="0.8c"; +/* 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. +*/ + +#include "rvs.h" +#include "plugin.c" + +const char *libexecdir="./plugins"; +const char *plugin_conf="plugin.conf"; + +int +main (void) +{ + struct plugin_tree *plugins=load_plugins(libexecdir,plugin_conf); + return 0; +} + diff --git a/wrapper/rvs.h b/wrapper/rvs.h new file mode 100644 index 0000000..adef3b1 --- /dev/null +++ b/wrapper/rvs.h @@ -0,0 +1,95 @@ +/* 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_rvs.h_SEEN +#define FILE_rvs.h_SEEN + +#include +#include +#include +#include +#include +#include +#include + +void *xmalloc (size_t size) +{ + void *value = malloc (size); + if (value == NULL) + error(EXIT_FAILURE,0,"virtual memory exhausted"); + return value; +} + +void *xrealloc (void *ptr, size_t size) +{ + void *value = realloc (ptr, size); + if (value == NULL) + error(EXIT_FAILURE,0,"virtual memory exhausted"); + return value; +} + +void xfree (void *ptr) +{ + free (ptr); +} + +int xchdir (const char *filename) +{ + int ret=chdir(filename); + if (ret != 0) { + error(EXIT_FAILURE,errno,"%s/",filename); + } + return ret; +} + +FILE *xfopen (const char *filename, const char *opentype) +{ + FILE *file = fopen(filename,opentype); + /* fopen gives NULL on failure */ + if ( file == NULL ) { + error(EXIT_FAILURE,errno,"%s",filename); + } + + return file; +} + +DIR *xopendir (const char *dirname) +{ + DIR *dir = opendir (dirname); + if (dir == NULL) { + error(EXIT_FAILURE,errno,"%s/",dirname); + } + + return dir; +} + +void stradds(size_t *size, char **dest, char *str) +{ + if (*size > ( strlen(*dest) + strlen(str) )) { + strcat(*dest, str); + } else { + *size = strlen(*dest) + strlen(str) + 1; + + *dest = (char *) xrealloc (*dest, *size); + strcat(*dest, str); + } +} + +#endif + diff --git a/wrapper/test.c b/wrapper/test.c new file mode 100644 index 0000000..3a9abc9 --- /dev/null +++ b/wrapper/test.c @@ -0,0 +1,9 @@ +#include "plugin.c" +#include "plugin-debug.c" + +int main() { + struct plugin_tree *plugins=load_plugins("plugins","plugin.conf"); + _plugin_print(plugins); + return 0; +} + -- cgit v1.2.3-2-g168b