summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2009-09-01 16:46:19 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-06-26 00:30:14 -0600
commit0c68c097a9d7fcc6fb90a0cf3ff54afe9b1fdabf (patch)
tree4b07ef7c15614805a19e42d552286e2cf17a787a
parent57ac88ce32736ae933c33b742392b4b4c2fba0cd (diff)
continue working
-rwxr-xr-xc/a.outbin0 -> 20519 bytes
-rw-r--r--c/plugin-debug.c40
-rw-r--r--c/plugin-parse.c138
-rw-r--r--c/plugin.c185
-rw-r--r--c/plugin.h49
-rw-r--r--c/rvs.c186
-rw-r--r--c/rvs.h76
-rw-r--r--c/test.c10
8 files changed, 501 insertions, 183 deletions
diff --git a/c/a.out b/c/a.out
new file mode 100755
index 0000000..403890d
--- /dev/null
+++ b/c/a.out
Binary files differ
diff --git a/c/plugin-debug.c b/c/plugin-debug.c
new file mode 100644
index 0000000..50e5497
--- /dev/null
+++ b/c/plugin-debug.c
@@ -0,0 +1,40 @@
+/* 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 print_commands(struct plugin_command *command)
+{
+ printf(" - %s\n",command->name);
+ if (command->depends != NULL) {
+ printf(" depend: %s\n",command->depends);
+ }
+ if (command->p_next != NULL) {
+ print_commands(command->p_next);
+ }
+}
+
+void print_plugins(struct plugin *plugin)
+{
+ printf("%s\n",plugin->name);
+ print_commands(plugin->child);
+ if (plugin->next != NULL) {
+ print_plugins(plugin->next);
+ }
+}
+
diff --git a/c/plugin-parse.c b/c/plugin-parse.c
new file mode 100644
index 0000000..0a2ec40
--- /dev/null
+++ b/c/plugin-parse.c
@@ -0,0 +1,138 @@
+/* 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 1. A user enters a username and passwthat 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 <unistd.h>
+#include <string.h>
+
+#include <errno.h>
+#include <error.h>
+
+#include "rvs.h"
+#include "plugin.h"
+
+void _parse_comment (FILE *file)
+{
+ char c;
+ while ( (c=getc(file)) != EOF ) {
+ if ( c == '\n' ) {
+ ungetc (c, file);
+ break;
+ }
+ }
+}
+
+char _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 *_parse_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);/* FIXME: DEBUG message */
+ ungetc (c[0], file);
+ break;
+ } else {
+ switch (c[0]) {
+ case '\\':
+ c[0]=_parse_escape(file);
+ stradds(&nbytes,&string,cs);
+ break;
+ case '#':
+ _parse_comment(file);
+ break;
+ default:
+ stradds(&nbytes,&string,cs);
+ break;
+ }
+ }
+ }
+ return string;
+}
+
+struct plugin_command *_parse_plugin (struct plugin *plugin, FILE *file)
+{
+ struct plugin_command *command;
+ 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);/* FIXME: debug code */
+ command->p_next=_parse_plugin(plugin, file);
+ break;
+ } else {
+ switch (c[0]) {
+ case '\\':
+ c[0]=_parse_escape(file);
+ stradds(&nbytes,&string,cs);
+ break;
+ case '#':
+ _parse_comment(file);
+ break;
+ case ':':
+ _parse_depend(file);
+ break;
+ default:
+ stradds(&nbytes,&string,cs);
+ break;
+ }
+ }
+ }
+ return command;
+}
+
+struct plugin *load_plugin (char *plug_name, char *plugin_conf)
+{
+ printf("loading plugin `%s'\n",plug_name);
+ struct plugin *plugin;
+ plugin->name=plug_name;
+
+ chdir(plug_name);
+ FILE *file = xfopen(plugin_conf,"r");
+
+ plugin->child=_parse_plugin(&plugin, file);
+
+ fclose( file );
+ chdir("..");
+ return plugin;
+}
+
diff --git a/c/plugin.c b/c/plugin.c
new file mode 100644
index 0000000..7b0146b
--- /dev/null
+++ b/c/plugin.c
@@ -0,0 +1,185 @@
+/* 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 1. A user enters a username and passwthat 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> /* EXIT_FAILURE */
+#include <unistd.h> /* file acces */
+#include <string.h>
+
+#include <errno.h>
+#include <error.h>
+
+#include <dirent.h>
+#include <sys/stat.h>
+
+#include "rvs.h"
+#include "plugin.h"
+
+void _parse_comment (FILE *file)
+{
+ char c;
+ while ( (c=getc(file)) != EOF ) {
+ if ( c == '\n' ) {
+ ungetc (c, file);
+ break;
+ }
+ }
+}
+
+char _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 *_parse_depend (FILE *file)
+{
+ size_t nbytes = 10;
+ char *string = (char *)xmalloc(nbytes);
+
+ 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]=_parse_escape(file);
+ stradds(&nbytes,&string,cs);
+ break;
+ case '#':
+ _parse_comment(file);
+ break;
+ default:
+ stradds(&nbytes,&string,cs);
+ break;
+ }
+ }
+ }
+ return string;
+}
+
+struct plugin_command *_parse_plugin (struct plugin *plugin, FILE *file)
+{
+ struct plugin_command *command;
+ command=(struct plugin_command *)xmalloc(sizeof(*command));
+ command->p_next=NULL;
+ command->depends=NULL;
+
+ size_t nbytes = 10;
+ char *string = (char *)xmalloc(nbytes);
+ strcpy(string,"");
+
+ 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) {
+ free(command);
+ free(string);
+ return _parse_plugin(plugin, file);
+ } else {
+ command->name=string;
+ command->p_next=_parse_plugin(plugin, file);
+ break;
+ }
+ } else {
+ switch (c[0]) {
+ case '\\':
+ c[0]=_parse_escape(file);
+ stradds(&nbytes,&string,cs);
+ break;
+ case '#':
+ _parse_comment(file);
+ break;
+ case ':':
+ command->depends=_parse_depend(file);
+ break;
+ default:
+ stradds(&nbytes,&string,cs);
+ break;
+ }
+ }
+ }
+ return command;
+}
+
+struct plugin *load_plugin (char *plug_name, char *plugin_conf)
+{
+ printf("loading plugin `%s'\n",plug_name);
+ struct plugin *plugin=(struct plugin *)xmalloc(sizeof(*plugin));
+ plugin->name=plug_name;
+ plugin->next=NULL;
+
+ chdir(plug_name);
+ FILE *file = xfopen(plugin_conf,"r");
+
+ plugin->child=_parse_plugin(plugin, file);
+
+ fclose( file );
+ chdir("..");
+ 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;
+ struct plugin *plugin;
+
+ chdir(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=load_plugin(dirent->d_name,plugin_conf);
+ *last=plugin;
+ last=&plugin->next;
+ }
+ }
+ }
+ closedir (cwd);
+ return tree;
+}
+
diff --git a/c/plugin.h b/c/plugin.h
new file mode 100644
index 0000000..92deed2
--- /dev/null
+++ b/c/plugin.h
@@ -0,0 +1,49 @@
+/* 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 *depend;
+};
+
diff --git a/c/rvs.c b/c/rvs.c
index 6c43a79..6997596 100644
--- a/c/rvs.c
+++ b/c/rvs.c
@@ -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;
}
diff --git a/c/rvs.h b/c/rvs.h
new file mode 100644
index 0000000..1bcbacf
--- /dev/null
+++ b/c/rvs.h
@@ -0,0 +1,76 @@
+/* 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 <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <error.h>
+
+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;
+}
+
+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;
+
+ char *string;
+ string = (char *) xrealloc (*dest, *size);
+ strcat(string, str);
+ }
+}
+
diff --git a/c/test.c b/c/test.c
new file mode 100644
index 0000000..3a10711
--- /dev/null
+++ b/c/test.c
@@ -0,0 +1,10 @@
+#include "plugin.c"
+#include "plugin-debug.c"
+
+int main()
+{
+ struct plugin_tree *plugins=load_plugins("plugins","plugin.conf");
+ print_plugins(plugins->plugins);
+ return 0;
+}
+