diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2009-08-30 19:46:00 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-06-26 00:30:14 -0600 |
commit | 57ac88ce32736ae933c33b742392b4b4c2fba0cd (patch) | |
tree | 96f77390fbcb132800b3f65a62e01dd6f65426c8 /c | |
parent | 24e77f63ae243c33e1d38792080eaec1db43f8f7 (diff) |
begin reimplementing the wrapper in C
Diffstat (limited to 'c')
-rwxr-xr-x | c/Makefile | 5 | ||||
l--------- | c/plugins | 1 | ||||
-rw-r--r-- | c/rvs.c | 214 |
3 files changed, 220 insertions, 0 deletions
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 @@ -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 <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <dirent.h> +#include <string.h> +#include <sys/stat.h> +#include <unistd.h> +#include <errno.h> +#include <error.h> + +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; +} + |