From 57ac88ce32736ae933c33b742392b4b4c2fba0cd Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 30 Aug 2009 19:46:00 -0400 Subject: begin reimplementing the wrapper in C --- c/Makefile | 5 ++ c/plugins | 1 + c/rvs.c | 214 ++++++++++++++++++++++++++++++++++++++++++++++ plugins/file | 0 plugins/repo/plugin.conf | 6 ++ plugins/repo/stdio.sh | 68 +++++++++++++++ plugins/users/plugin.conf | 6 ++ plugins/users/stdio.sh | 68 +++++++++++++++ 8 files changed, 368 insertions(+) create mode 100755 c/Makefile create mode 120000 c/plugins create mode 100644 c/rvs.c create mode 100644 plugins/file create mode 100644 plugins/repo/plugin.conf create mode 100644 plugins/repo/stdio.sh create mode 100644 plugins/users/plugin.conf create mode 100644 plugins/users/stdio.sh diff --git a/c/Makefile b/c/Makefile new file mode 100755 index 0000000..65238ab --- /dev/null +++ b/c/Makefile @@ -0,0 +1,5 @@ +#!/usr/bin/make -f +CC = gcc + +all : + $(CC) rvs.c -Wall -ansi -g -o rvs diff --git a/c/plugins b/c/plugins new file mode 120000 index 0000000..b1f2dbf --- /dev/null +++ b/c/plugins @@ -0,0 +1 @@ +../plugins/ \ No newline at end of file diff --git a/c/rvs.c b/c/rvs.c new file mode 100644 index 0000000..6c43a79 --- /dev/null +++ b/c/rvs.c @@ -0,0 +1,214 @@ +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 +#include +#include +#include +#include +#include +#include +#include +#include + +const char *libexecdir="./plugins"; +const char *plugin_conf="plugin.conf"; + +const size_t strgran=10; + +void *xmalloc (size_t size) +{ + register void *value = malloc (size); + if (value == 0) + error(EXIT_FAILURE,0,"virtual memory exhausted"); + return value; +} + +void *xrealloc (void *ptr, size_t size) +{ + register void *value = realloc (ptr, size); + if (value == 0) + error(EXIT_FAILURE,0,"virtual memory exhausted"); + return value; +} + +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; + + char *string; + string = (char *) xrealloc (*dest, *size); + strcat(string, str); + } +} + +void load_plugin_comment (FILE *file) +{ + char c; + while ( (c=getc(file)) != EOF ) { + if ( c == '\n' ) { + ungetc (c, file); + break; + } + } +} + +int load_plugin_command (FILE *file); + +int load_plugin_depend (FILE *file) +{ + int nbytes = 10; + char *string = (char *) malloc(nbytes); + + char c[2] = " \0"; + char *cs = &c; + while ( (c[0]=getc(file)) != EOF ) { + if (c[0] == '\n') { + printf("%s | ",string); + ungetc (c[0], file); + break; + } else { + switch (c[0]) { + case '\\': + c[0]=getc(file); + switch (c[0]) { + case 'n': + c[0] = '\n'; + case '\\': + case '#': + stradds(&nbytes,&string,cs); + break; + default: + error(EXIT_FAILURE,0,"syntax error"); + break; + } + break; + case '#': + load_plugin_comment(file); + break; + default: + stradds(&nbytes,&string,cs); + break; + } + } + } + return 0; +} + +int load_plugin_command (FILE *file) +{ + int nbytes = 10; + char *string = (char *) malloc(nbytes); + + char c[2] = " \0"; + char *cs = &c; + while ( (c[0]=getc(file)) != EOF ) { + if (c[0] == '\n') { + printf("%s\n",string); + load_plugin_command(file); + break; + } else { + switch (c[0]) { + case '\\': + c[0]=getc(file); + switch (c[0]) { + case 'n': + c[0] = '\n'; + case '\\': + case '#': + case ':': + stradds(&nbytes,&string,cs); + break; + default: + error(EXIT_FAILURE,0,"syntax error"); + break; + } + break; + case '#': + load_plugin_comment(file); + break; + case ':': + load_plugin_depend(file); + break; + default: + stradds(&nbytes,&string,cs); + break; + } + } + } + return 0; +} + +int load_plugin (char *plug_name) +{ + printf("loading plugin `%s'\n",plug_name); + + chdir(plug_name); + FILE *file = fopen(plugin_conf,"r"); + + /* fopen gives NULL on failure */ + if ( file == NULL ) { + error(EXIT_FAILURE,errno, + "%s/%s/%s",libexecdir,plug_name,plugin_conf); + } else { + load_plugin_command(file); + } + fclose( file ); + chdir(".."); + return 0; +} + +int load_plugins () +{ + chdir(libexecdir); + + DIR *dp; + struct dirent *ep; + int serr; + struct stat sbuf; + dp = opendir ("./"); + if (dp != NULL) { + while (ep = readdir (dp)) { + if ((strcmp(ep->d_name,"." )!=0)&& + (strcmp(ep->d_name,"..")!=0)) { + serr = stat(ep->d_name, &sbuf); + if (!serr && S_ISDIR(sbuf.st_mode)) { + load_plugin(ep->d_name); + } + } + } + (void) closedir (dp); + } + else + error(EXIT_FAILURE,errno,"%s/",libexecdir); + return 0; +} + +int main (void) +{ + load_plugins(); + return 0; +} + diff --git a/plugins/file b/plugins/file new file mode 100644 index 0000000..e69de29 diff --git a/plugins/repo/plugin.conf b/plugins/repo/plugin.conf new file mode 100644 index 0000000..61cebc7 --- /dev/null +++ b/plugins/repo/plugin.conf @@ -0,0 +1,6 @@ +commit +commit.d +commit.f +get +get.d +get.f diff --git a/plugins/repo/stdio.sh b/plugins/repo/stdio.sh new file mode 100644 index 0000000..c1a1b6b --- /dev/null +++ b/plugins/repo/stdio.sh @@ -0,0 +1,68 @@ +#!@SHELL@ +#name='rvs repo stdio' +#ver='0.7.3' +# 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. + +verbose() { + if [ "$volume" == '-v' ]; then + echo $@ >> /dev/stderr + fi +} + +out() { + if [ "$volume" != '-q' ]; then + echo $@ >> /dev/stderr + fi +} + +warn () { + echo "$name: $1" >> /dev/stderr +} + +fatal () { + warn "$1" + exit 1 +} + +error() { + warn "$1" + cat << __error__ >> /dev/stderr +Usage: $name $usage + +Try \`$name --help\' for more options. +__error__ + exit 1 +} + +version() { + echo "$name $ver" + if [ "$volume" != '-q' ]; then + cat << __disclaimer__ +$name is copyright (C) 2009 Luke Shumaker +This program 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. + +Originally written by Luke Shumaker . +__disclaimer__ + fi + exit 0 +} + diff --git a/plugins/users/plugin.conf b/plugins/users/plugin.conf new file mode 100644 index 0000000..b0e70b2 --- /dev/null +++ b/plugins/users/plugin.conf @@ -0,0 +1,6 @@ +# users-0.7beta plugins.conf +commit:repo-0.7beta/commit +login +logout +mkuser +rmuser diff --git a/plugins/users/stdio.sh b/plugins/users/stdio.sh new file mode 100644 index 0000000..1149284 --- /dev/null +++ b/plugins/users/stdio.sh @@ -0,0 +1,68 @@ +#!@SHELL@ +#name='rvs users stdio' +#ver='0.7.3' +# 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. + +verbose() { + if [ "$volume" == '-v' ]; then + echo $@ >> /dev/stderr + fi +} + +out() { + if [ "$volume" != '-q' ]; then + echo $@ >> /dev/stderr + fi +} + +warn () { + echo "$name: $1" >> /dev/stderr +} + +fatal () { + warn "$1" + exit 1 +} + +error() { + warn "$1" + cat << __error__ >> /dev/stderr +Usage: $name $usage + +Try \`$name --help\' for more options. +__error__ + exit 1 +} + +version() { + echo "$name $ver" + if [ "$volume" != '-q' ]; then + cat << __disclaimer__ +$name is copyright (C) 2009 Luke Shumaker +This program 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. + +Originally written by Luke Shumaker . +__disclaimer__ + fi + exit 0 +} + -- cgit v1.2.3