From acc687b3a74e3c8d750630c323d223f1c63599db Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 25 Jun 2015 23:56:37 -0600 Subject: mkdir rvs; mv * rvs --- rvs/wrapper/Makefile.in | 114 ++++++++++++++++++++++++++++++++++ rvs/wrapper/TODO | 12 ++++ rvs/wrapper/plugin-depend.c | 146 ++++++++++++++++++++++++++++++++++++++++++++ rvs/wrapper/plugin-depend.h | 83 +++++++++++++++++++++++++ rvs/wrapper/plugin-find.c | 103 +++++++++++++++++++++++++++++++ rvs/wrapper/plugin-find.h | 64 +++++++++++++++++++ rvs/wrapper/plugin-load.c | 78 +++++++++++++++++++++++ rvs/wrapper/plugin-load.h | 47 ++++++++++++++ rvs/wrapper/plugin-parse.c | 132 +++++++++++++++++++++++++++++++++++++++ rvs/wrapper/plugin-parse.h | 49 +++++++++++++++ rvs/wrapper/plugin-run.c | 89 +++++++++++++++++++++++++++ rvs/wrapper/plugin-run.h | 47 ++++++++++++++ rvs/wrapper/plugins.c | 71 +++++++++++++++++++++ rvs/wrapper/plugins.h | 69 +++++++++++++++++++++ rvs/wrapper/runcom.c | 74 ++++++++++++++++++++++ rvs/wrapper/rvs.c | 117 +++++++++++++++++++++++++++++++++++ rvs/wrapper/rvs.h | 76 +++++++++++++++++++++++ rvs/wrapper/rvs.sh | 110 +++++++++++++++++++++++++++++++++ 18 files changed, 1481 insertions(+) create mode 100644 rvs/wrapper/Makefile.in create mode 100644 rvs/wrapper/TODO create mode 100644 rvs/wrapper/plugin-depend.c create mode 100644 rvs/wrapper/plugin-depend.h create mode 100644 rvs/wrapper/plugin-find.c create mode 100644 rvs/wrapper/plugin-find.h create mode 100644 rvs/wrapper/plugin-load.c create mode 100644 rvs/wrapper/plugin-load.h create mode 100644 rvs/wrapper/plugin-parse.c create mode 100644 rvs/wrapper/plugin-parse.h create mode 100644 rvs/wrapper/plugin-run.c create mode 100644 rvs/wrapper/plugin-run.h create mode 100644 rvs/wrapper/plugins.c create mode 100644 rvs/wrapper/plugins.h create mode 100644 rvs/wrapper/runcom.c create mode 100644 rvs/wrapper/rvs.c create mode 100644 rvs/wrapper/rvs.h create mode 100644 rvs/wrapper/rvs.sh (limited to 'rvs/wrapper') diff --git a/rvs/wrapper/Makefile.in b/rvs/wrapper/Makefile.in new file mode 100644 index 0000000..9584a2a --- /dev/null +++ b/rvs/wrapper/Makefile.in @@ -0,0 +1,114 @@ +#!/usr/bin/make -f +name = @name@ +ver = 0.8r60 +# 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 ######################################################### +CC = @CC@ +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 + +CFLAGS = -g \ + -DNAME=\"$(name)\" \ + -DVER=\"$(ver)\" \ + -Dlibexecdir=\"$(libexecdir)/$(rvs)\" \ + -Dplugin_conf=\"plugin.conf\" + +# phony targets #################################################### +all : rvs runcom +.PHONY : install uninstall clean distclean dist install-runcom +.SUFFIXES : .c .o +VPATH = $(srcdir)/wrapper + +# most everything ################################################## +RUNCOM = $(libexecdir)/$(rvs)/runcom +install : $(RVS) $(RUNCOM) +$(RVS) : rvs $(dir $(RVS)) + $(INSTALL_PROGRAM) $< $@ + +OBJ = runcom.o rvs.o plugins.o \ + plugin-depend.o \ + plugin-find.o \ + plugin-load.o \ + plugin-parse.o \ + plugin-run.o \ + +runcom: $(OBJ) + gcc -o $@ $^ + +$(RUNCOM): runcom $(dir $(RUNCOM)) + $(INSTALL_PROGRAM) $< $@ + +b := @ +# build shell scripts +rvs : rvs.sh + $(INSTALL_PROGRAM) $< $@ + $(SED) -i \ + -e 's/$bSHELL@/$(subst /,\/,$(SHELL))/g' \ + -e 's/$bname@/$(rvs)/g' \ + -e 's/$blibexecdir@/$(subst /,\/,$(libexecdir))/g' \ + $@ + +uninstall : + $(RM) $(RVS) + $(RM) $(libexecdir)/$(rvs)/runcom + +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)/* $@ + +# implicit rules ################################################### + +$(dirs) $(libexecdir)/$(rvs) : + $(MKDIR) $@ + diff --git a/rvs/wrapper/TODO b/rvs/wrapper/TODO new file mode 100644 index 0000000..9734938 --- /dev/null +++ b/rvs/wrapper/TODO @@ -0,0 +1,12 @@ +#! /bin/more + +* actually launch the plugins +* plugin-run.h: + the function _plugin_sh_mktemp() is an ugly hack, it exists + because a) it is secure b) it is easier to write a hack using + methods I understand, than learn those I don't c) point b + especially when I just want to get it working. + +~ Luke Shumaker +Happy Hacking! + diff --git a/rvs/wrapper/plugin-depend.c b/rvs/wrapper/plugin-depend.c new file mode 100644 index 0000000..de21a93 --- /dev/null +++ b/rvs/wrapper/plugin-depend.c @@ -0,0 +1,146 @@ +/* wrapper/plugin-depend.c -- load a command dependancy tree + system depends: + 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 "rvs.h" +#include "plugin-find.h" + +#include "plugin-depend.h" + +/* 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 *plugins, + struct plugin_command *root) +{ + struct plugin_command *command=NULL; + + if (*string==NULL) + command=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(plugins, *string ); + if (plugin==NULL) + error(EXIT_FAILURE,0,"cannot find plugin `%s'",*string); + command=plugin_find_plugin_command(plugin->commands, &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_add (struct plugin_command *prev, + struct plugin_command *next) +{ + if (prev->d_next==NULL) { + prev->d_next=next; + } else { + _plugin_depend_add(prev->d_next,next); + } +} + +/* plugin_depend_add(depend,depender) */ +void +plugin_depend_add (struct plugin_command *depend, + struct plugin_command *depender) +{ + if (depend->d_child==NULL) { + depend->d_child=depender; + } else { + _plugin_depend_add(depend->d_child,depender); + } +} + +/* take care of depends for `command' */ +void +plugin_depend_command (struct plugin_command *command, + struct plugin *plugins, + struct plugin_command *root, int ind) +{ + if (command!=NULL) { + if (command->depend == NULL) { + /* the depend still needs to be parsed */ + command->depend=plugin_depend_parse( + &(command->depends),plugins,root); + } + plugin_depend_add(command->depend,command); + } +} + +/* take care of commands for a `plugin', and those after it (linked list) */ +void +plugin_depend_plugin_all (struct plugin *plugin, + struct plugin *plugins, + struct plugin_command *root) +{ + plugin_depend_command(plugin->commands,plugins,root,0); + if (plugin->next != NULL) { + plugin_depend_plugin_all(plugin->next,plugins,root); + } +} + +/* take care of all depends */ +struct plugin_command * +plugin_depend_all (struct plugin *plugins) +{ + struct plugin_command *root=plugin_mk_command(); + + plugin_depend_plugin_all(plugins,plugins,root); + return root; +} + +void +_plugin_depend_list (struct plugin_command_list *commands, + struct plugin *plugins, + struct plugin_command *root,int ind) +{ + if (commands!=NULL) { + plugin_depend_command(commands->command,plugins,root,ind++); + _plugin_depend_list(commands->next,plugins,root,ind++); + } +} + +struct plugin_command * +plugin_depend_list (struct plugin_command_list *commands, + struct plugin *plugins) +{ + struct plugin_command *root=plugin_mk_command(); + _plugin_depend_list(commands,plugins,root,0); + return root; +} + diff --git a/rvs/wrapper/plugin-depend.h b/rvs/wrapper/plugin-depend.h new file mode 100644 index 0000000..580c03f --- /dev/null +++ b/rvs/wrapper/plugin-depend.h @@ -0,0 +1,83 @@ +/* wrapper/plugin-parse.h -- parse rvs plugin config files + system depends: + 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_h_SEEN +#define FILE_plugin_depend_h_SEEN + +#include "plugins.h" +#include "plugin-find.h" + +/* 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) */ +extern +struct plugin_command * +plugin_depend_parse (char **string, + struct plugin *plugins, + struct plugin_command *root); + +/* used by plugin_depend_add */ +extern +void +_plugin_depend_add (struct plugin_command *prev, + struct plugin_command *next); + +/* plugin_depend_add(depend,depender) */ +extern +void +plugin_depend_add (struct plugin_command *depend, + struct plugin_command *depender); + +/* take care of depends for `command' */ +extern +void +plugin_depend_command (struct plugin_command *command, + struct plugin *plugins, + struct plugin_command *root, int ind); + +/* take care of commands for a `plugin', and those after it (linked list) */ +extern +void +plugin_depend_plugin_all (struct plugin *plugin, + struct plugin *plugins, + struct plugin_command *root); + +/* take care of all depends */ +extern +struct plugin_command * +plugin_depend_all (struct plugin *plugins); + +extern +void +_plugin_depend_list (struct plugin_command_list *commands, + struct plugin *plugins, + struct plugin_command *root,int ind); + +extern +struct plugin_command * +plugin_depend_list (struct plugin_command_list *commands, + struct plugin *plugins); + + + + +#endif + diff --git a/rvs/wrapper/plugin-find.c b/rvs/wrapper/plugin-find.c new file mode 100644 index 0000000..98e16af --- /dev/null +++ b/rvs/wrapper/plugin-find.c @@ -0,0 +1,103 @@ +/* wrapper/plugin-find.h -- search functions for rvs plugins + system depends: + 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 /* only uses `strcmp' */ + +#include "rvs.h" +#include "plugins.h" + +#include "plugin-find.h" + +/* returns first plugin with `name' (duplicates are... unwise) */ +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); + } +} + +/* returns plugin `name within plugin `node' */ +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 */ +struct plugin_command * +plugin_find_command(struct plugin *plugin, char *name) +{ + if (plugin==NULL) + return NULL; + else { + struct plugin_command *ret; + ret=plugin_find_plugin_command(plugin->commands,name); + if (ret == NULL) + ret=plugin_find_command(plugin->next,name); + return ret; + } +} + +/* returns a linked list of all commands with `name' it finds */ +struct plugin_command_list * +plugin_find_commands(struct plugin *plugin, char *name) +{ + if (plugin==NULL) + return NULL; + else { + struct plugin_command *command; + command=plugin_find_command(plugin,name); + struct plugin_command_list *node; + if (command==NULL) + node=plugin_find_commands(plugin->next,name); + else { + node=xmalloc( sizeof *node ); + node->command=command; + node->next=plugin_find_commands(plugin->next,name); + } + return node; + } +} + +void +plugin_free_list(struct plugin_command_list *node) +{ + if (node!=NULL) { + plugin_free_list(node->next); + xfree(node); + } +} + diff --git a/rvs/wrapper/plugin-find.h b/rvs/wrapper/plugin-find.h new file mode 100644 index 0000000..0185117 --- /dev/null +++ b/rvs/wrapper/plugin-find.h @@ -0,0 +1,64 @@ +/* wrapper/plugin-find.h -- search functions for rvs plugins + system depends: + 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_find_h_SEEN +#define FILE_plugin_find_h_SEEN + +#include /* only uses `strcmp' */ + +#include "rvs.h" +#include "plugins.h" + +/*------------------------------struct------------------------------*/ +/* a linked list of commands, for use by `plugin_find_commands' */ +struct plugin_command_list +{ + struct plugin_command *command; + struct plugin_command_list *next; +}; + +/*-----------------------------function-----------------------------*/ +/* returns first plugin with `name' (duplicates are... unwise) */ +extern +struct plugin * +plugin_find_plugin(struct plugin *node, char *name); + +/* returns plugin `name within plugin `node' */ +extern +struct plugin_command * +plugin_find_plugin_command(struct plugin_command *node, char *name); + +/* returns the first command with `name' it finds */ +extern +struct plugin_command * +plugin_find_command(struct plugin *plugin, char *name); + +/* returns a linked list of all commands with `name' it finds */ +extern +struct plugin_command_list * +plugin_find_commands(struct plugin *plugin, char *name); + +extern +void +plugin_free_list(struct plugin_command_list *node); + +#endif + diff --git a/rvs/wrapper/plugin-load.c b/rvs/wrapper/plugin-load.c new file mode 100644 index 0000000..142fcd5 --- /dev/null +++ b/rvs/wrapper/plugin-load.c @@ -0,0 +1,78 @@ +/* wrapper/plugin-load.h -- load rvs plugins into mem + system depens: , GNU + 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 "rvs.h" +#include "plugins.h" +#include "plugin-parse.h" + +#include "plugin-load.h" + +/*- plugin_load ----------------------------------------------------*\ + now, load plugin plug_name, +\* whose configuration file is plugin_conf */ +struct plugin * +plugin_load (const char *plug_name) +{ + 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(plugin, file); + fclose( file ); + xchdir(".."); + + return plugin; +} + +/*- load_plugins ---------------------------------------------------*\ + Load all the plugins + assume we're in rvs's libexecdir, where plugins are +\* Use `plugin_conf' as the name of the config file for each plugin */ + +struct plugin * +load_plugins (FILE *list) +{ + 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 */ + + size_t nbytes = 10; + char *plug_name=(char *)xmalloc(nbytes); + while ( getline(&plug_name, &nbytes, list) > 0 ) { + char *del=strchr(plug_name,'\n'); + del[0]='\0'; + /*if (strlen(plug_name)!=0) {*/ + if (plug_name[0]!='\0') {; + plugin=plugin_load(plug_name); + *prev=plugin;/* this sets the last's `next' */ + prev=&plugin->next; + } + } + + return first; +} + diff --git a/rvs/wrapper/plugin-load.h b/rvs/wrapper/plugin-load.h new file mode 100644 index 0000000..f214151 --- /dev/null +++ b/rvs/wrapper/plugin-load.h @@ -0,0 +1,47 @@ +/* wrapper/plugin-load.h -- load rvs plugins into mem + system depens: , GNU + 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_load_h_SEEN +#define FILE_plugin_load_h_SEEN + +#include +#include + +#include "rvs.h" +#include "plugins.h" +#include "plugin-parse.h" + +/*- plugin_load ----------------------------------------------------*\ + now, load plugin plug_name, +\* whose configuration file is plugin_conf */ +extern +struct plugin * +plugin_load (const char *plug_name); + +/*- load_plugins ---------------------------------------------------*\ + Load all the plugins + assume we're in rvs's libexecdir, where plugins are +\* Use `plugin_conf' as the name of the config file for each plugin */ +extern +struct plugin * +load_plugins (FILE *list); +#endif + diff --git a/rvs/wrapper/plugin-parse.c b/rvs/wrapper/plugin-parse.c new file mode 100644 index 0000000..4a35586 --- /dev/null +++ b/rvs/wrapper/plugin-parse.c @@ -0,0 +1,132 @@ +/* wrapper/plugin-parse.c -- parse rvs plugin config files + system depends: + 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 /* only used in `plugin_parse_escape' for `error' */ + +#include "rvs.h" +#include "plugins.h" + +#include "plugin-parse.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; +} + +#define _parse_share(string) \ + case '#':\ + plugin_parse_comment(file);\ + break;\ + case '\\':\ + c[0]=plugin_parse_escape(file);\ + default:\ + stradds(&nbytes,string,(char *)&c);\ + break; + +char * +plugin_parse_depend (FILE *file) +{ + size_t nbytes = 10; + char *string = (char *)xmalloc(nbytes); + string[0]='\0'; + + char c[2] = " \0"; + while ( (c[0]=getc(file)) != EOF ) { + switch (c[0]) { + case '\n': + ungetc (c[0], file); + return string; + break; + _parse_share(&string) + } + } + return string; +} + +struct plugin_command * +plugin_parse (struct plugin *plugin, FILE *file) +{ + struct plugin_command *command; + + char c[2] = " \0"; + c[0]=getc(file); + + if (c[0]==EOF) + command=NULL; + else { + ungetc (c[0], file); + command=plugin_mk_command(); + command->plugin=plugin; + + size_t nbytes = 10; + command->name = (char *)xmalloc(nbytes); + command->name[0]='\0'; + + while ( (c[0]=getc(file)) != EOF ) { + switch (c[0]) { + case '\n': + /*if (strlen(command->name)==0) {*/ + if (command->name[0]=='\0') { + plugin_free_command(command); + return plugin_parse(plugin,file); + } else + command->next=plugin_parse( + plugin,file); + break; + case ':': + command->depends=plugin_parse_depend( + file); + break; + _parse_share(&(command->name)) + } + } + } + return command; +} + diff --git a/rvs/wrapper/plugin-parse.h b/rvs/wrapper/plugin-parse.h new file mode 100644 index 0000000..67ee06f --- /dev/null +++ b/rvs/wrapper/plugin-parse.h @@ -0,0 +1,49 @@ +/* wrapper/plugin-parse.c -- parse rvs plugin config files + system depends: + 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_h_SEEN +#define FILE_plugin_parse_h_SEEN + +#include +#include +#include /* only used in `plugin_parse_escape' for `error' */ + +#include "rvs.h" +#include "plugins.h" + +extern +void +plugin_parse_comment (FILE *file); + +extern +char +plugin_parse_escape(FILE *file); + +extern +char * +plugin_parse_depend (FILE *file); + +extern +struct plugin_command * +plugin_parse (struct plugin *plugin, FILE *file); + +#endif + diff --git a/rvs/wrapper/plugin-run.c b/rvs/wrapper/plugin-run.c new file mode 100644 index 0000000..26d4480 --- /dev/null +++ b/rvs/wrapper/plugin-run.c @@ -0,0 +1,89 @@ +/* wrapper/plugin-run.c -- run a heiarchy of commands + system depens: + 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 "rvs.h" +#include "plugins.h" +#include "plugin-find.h" + +#include "plugin-run.h" + +/* this function is an ugly hack */ +char * +_plugin_sh_mktemp() +{ + size_t nbytes = 10; + char *string = (char *)malloc(nbytes); + string[0]='\0'; + + FILE *out=popen("mktemp -t rvs-XXXXXXXXXX","r"); + char c[2]=" \0"; + while ( (c[0]=getc(out)) != '\n' ) { + stradds(&nbytes,&string,(char *)&c); + } + pclose(out); + return string; +} + +void +plugin_run_command(struct plugin_command *command, char *args, char *depfile) +{ + if (command!=NULL) { + char *outfile=_plugin_sh_mktemp(); + /* make command string: + `libexecdir/plugin_name/command < depfile > outfile' + */ + int nbytes=20; + char *coms=(char *)xmalloc(nbytes); + coms[0]='\0'; + stradds(&nbytes,&coms,libexecdir); + stradds(&nbytes,&coms,"/"); + stradds(&nbytes,&coms,command->plugin->name); + stradds(&nbytes,&coms,"/"); + stradds(&nbytes,&coms,command->name); + stradds(&nbytes,&coms," "); + stradds(&nbytes,&coms,args); + stradds(&nbytes,&coms," < "); + stradds(&nbytes,&coms,depfile); + stradds(&nbytes,&coms," > "); + stradds(&nbytes,&coms,outfile); + + xsystem(coms); + xfree(coms); + plugin_run_command(command->d_child,args,outfile); + xfree(outfile); + plugin_run_command(command->d_next ,args,depfile); + } +} + +/* needs to take the root command */ +void +plugin_run(struct plugin_command *command,char *args) +{ + /*plugin_run_command(command->d_child,"/dev/null");*/ + char *outfile=_plugin_sh_mktemp(); + plugin_run_command(command->d_child,args,outfile); + xfree(outfile); +} + diff --git a/rvs/wrapper/plugin-run.h b/rvs/wrapper/plugin-run.h new file mode 100644 index 0000000..99beff4 --- /dev/null +++ b/rvs/wrapper/plugin-run.h @@ -0,0 +1,47 @@ +/* wrapper/plugin-run.h -- run a heiarchy of commands + system depens: + 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_run_h_SEEN +#define FILE_plugin_run_h_SEEN + +#include +#include + +#include "rvs.h" +#include "plugins.h" +#include "plugin-find.h" + +/* this function is an ugly hack */ +extern +char * +_plugin_sh_mktemp(); + +extern +void +plugin_run_command(struct plugin_command *command, char *args, char *depfile); + +/* needs to take the root command */ +extern +void +plugin_run(struct plugin_command *command, char *args); + +#endif + diff --git a/rvs/wrapper/plugins.c b/rvs/wrapper/plugins.c new file mode 100644 index 0000000..70ce3e1 --- /dev/null +++ b/rvs/wrapper/plugins.c @@ -0,0 +1,71 @@ +/* wrapper/plugins.c -- struct definitions and basic functions for rvs plugins + system depends: this file is truly system-independant + 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 "plugins.h" + +/* create a blank plugin_command */ +struct plugin_command * +plugin_mk_command() +{ + 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; + + /* depends */ + command->d_child=NULL; + command->d_next=NULL; + + return command; +} + +void +plugin_free_command(struct plugin_command *command) +{ + if (command!=NULL) { + plugin_free_command(command->next); + xfree(command->name); + xfree(command->depends); + xfree(command); + } +} + +void +plugin_free_plugin(struct plugin *plugin) +{ + if (plugin!=NULL) { + xfree(plugin->name); + plugin_free_command(plugin->commands); + plugin_free_plugin(plugin->next); + xfree(plugin); + } +} + diff --git a/rvs/wrapper/plugins.h b/rvs/wrapper/plugins.h new file mode 100644 index 0000000..2b5a96e --- /dev/null +++ b/rvs/wrapper/plugins.h @@ -0,0 +1,69 @@ +/* wrapper/plugins.h -- struct definitions and basic functions for rvs plugins + system depends: this file is truly system-independant + 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_plugins_h_SEEN +#define FILE_plugins_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; + + /* depends, linked list */ + /* for a dependancy tree, this seems like it should be a *\ + \* separate struct, but this is the simplest way. */ + struct plugin_command *d_child; + struct plugin_command *d_next; +}; + +/* create a blank plugin_command */ +extern +struct plugin_command * +plugin_mk_command(); + +extern +void +plugin_free_command(struct plugin_command *command); + +extern +void +plugin_free_plugin(struct plugin *plugin); + +#endif + diff --git a/rvs/wrapper/runcom.c b/rvs/wrapper/runcom.c new file mode 100644 index 0000000..10e9919 --- /dev/null +++ b/rvs/wrapper/runcom.c @@ -0,0 +1,74 @@ +/* wrapper/runcom.c -- main program loop + system depends: this file is truly system-independant + 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. +*/ + +const char *name=NAME; +const char *ver=VER; + +#include "rvs.h" +#include "plugins.h" +#include "plugin-load.h" +#include "plugin-find.h" +#include "plugin-depend.h" +#include "plugin-run.h" + +int +main ( int argc, char *argv[] ) +{ + if (argc > 1) { + /*load*/ + char *cwd=getcwd(NULL,0); + xchdir(libexecdir); + struct plugin *plugins; + plugins=load_plugins(stdin); + struct plugin_command_list *list; + list=plugin_find_commands(plugins,argv[1]); + if (list==NULL) + error(EXIT_FAILURE,0,"unrecognized command `%s'", + argv[1]); + struct plugin_command *root; + root=plugin_depend_list(list,plugins); + + /*do*/ + xchdir(cwd); + int nbytes=10; + char *args=xmalloc(nbytes); + args[0]='\0'; + int i; + for (i=2; i + 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 "rvs.h" + +void * +xmalloc (size_t size) +{ + void *value = malloc (size); + if (value == NULL) { + perror(program_invocation_name); + exit(EXIT_FAILURE); + } + return value; +} + +void * +xrealloc (void *ptr, size_t size) +{ + void *value = realloc (ptr, size); + if (value == NULL) { + perror(program_invocation_name); + exit(EXIT_FAILURE); + } + return value; +} + +void +xfree (void *ptr) +{ + if (ptr!=NULL) + free (ptr); +} + +void +xsystem (const char *command) +{ + int stat=system(command); + if (stat!=0) { + if (stat==-1) { + fprintf(stderr, + "%s: unable to launch run command", + program_invocation_name); + exit(EXIT_FAILURE); + } else + exit(EXIT_FAILURE); + } +} + +/* unistd.h */ +int +xchdir (const char *filename) +{ + int ret=chdir(filename); + if (ret != 0) + error(EXIT_FAILURE,errno,"%s/",filename); + return ret; +} + +/* stdio.h */ +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; +} + +/* string funtions */ +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); + } +} + +char * +stralloc (const char *string) +{ + char *copy = (char *)xmalloc(strlen(string)+1); + strcpy(copy,string); + return copy; +} + diff --git a/rvs/wrapper/rvs.h b/rvs/wrapper/rvs.h new file mode 100644 index 0000000..bdd5c68 --- /dev/null +++ b/rvs/wrapper/rvs.h @@ -0,0 +1,76 @@ +/* wrapper/rvs.h -- general and machine specific functions for rvs. + system depends: + 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 + +/* glibc */ +extern char *program_invocation_name; +extern char *program_invocation_short_name; + +/* stdlib.h */ +/*extern int EXIT_SUCCESS;*/ +/*extern int EXIT_FAILURE;*/ + +extern +void * +xmalloc (size_t size); + +extern +void * +xrealloc (void *ptr, size_t size); + +extern +void +xfree (void *ptr); + +extern +void +xsystem (const char *command); + +/* unistd.h */ +extern +int +xchdir (const char *filename); + +/* stdio.h */ +extern +FILE * +xfopen (const char *filename, const char *opentype); + +/* string funtions */ +extern +void +stradds(size_t *size, char **dest, char *str); + +extern +char * +stralloc (const char *string); + +#endif + diff --git a/rvs/wrapper/rvs.sh b/rvs/wrapper/rvs.sh new file mode 100644 index 0000000..a515f2d --- /dev/null +++ b/rvs/wrapper/rvs.sh @@ -0,0 +1,110 @@ +#!@SHELL@ +name='@name@' +ver='0.8r61' +# 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. + +RVS="$0" #RVS="@rvs@" +libexecdir="@libexecdir@/$name" + +_error() { + echo "$RVS: $1" >> /dev/stderr + exit 1 +} + +_repo() { + repo=".$name" + pwd=`pwd` + owd="$pwd" + + while [ "$pwd" != "`pwd`" ] && [ ! -e "`pwd`/$repo" ]; do + pwd=`pwd` + cd .. + done + + if [ -e "`pwd`/$repo" ]; then + echo "`pwd`/$repo" + else + _error "no $name repository found" + fi + cd "$owd" +} + +_init() { + repo=`_repo 2> /dev/null` + if [ -z "$repo" ]; then + repo=".$name" + install -d "$repo" + install -m644 -T $libexecdir/plugins $repo/plugins + while read plugin; do + echo "initializing plugin \`$plugin'" + install -d "$repo/$plugin" + export REPO=.rvs/$plugin + if [ -e "$libexecdir/$plugin/init" ]; then + "$libexecdir/$plugin/init" + fi + done < $repo/plugins + else + _error "repository already exists at \`$repo'" + fi +} + +_install() { + id=$1 + dir=${2-$id} + name=`echo $id | sed 's/-.*$//'` + if (grep "^$name-" "$libexecdir/plugins" &> /dev/null); then + # an entry for this plugin already exists, though possibly a + # different version + sed -i "s/^$name-.*$/$id/" "$libexecdir/plugins" + else + echo "$id" >> "$libexecdir/plugins" + fi + rm -rf "$libexecdir/$id" + cp -rpT "$dir" "$libexecdir/$id" +} + +_uninstall() { + id=$1 + sed -i "/^$id$/ d" "$libexecdir/plugins" + rm -rf "$libexecdir/$id" +} + +# START OPTION HANDLING # +com=$1; +# END OPTION HANDLING # +case "$com" in + '') _error 'no command specified';; + # 'repo') _repo; exit $?;; + 'init') _init; exit $?;; + 'install') shift; _install $@; exit $?;; + 'uninstall') shift; _uninstall $@; exit $?;; + *) REPO=`_repo` + if [ "$?" = '0' ]; then + export RVS libexecdir REPO + "$libexecdir/runcom" $@ < $REPO/plugins + exit $? + else + _error "cannot find an existing repository" + fi + :;; +esac + +# Copy/Paste Virus 1.3c Please copy and paste this text anywhere. Track +# its progress by searching for this MD5#f7eac285ebfe21c4587bfebb9582f90d + -- cgit v1.2.3-54-g00ecf