diff options
Diffstat (limited to 'c/rvs.c')
-rw-r--r-- | c/rvs.c | 186 |
1 files changed, 3 insertions, 183 deletions
@@ -20,195 +20,15 @@ const char *ver="0.8c"; 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> +#include "rvs.h" +#include "plugin.c" 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(); + load_plugins(libexecdir,plugin_conf); return 0; } |