summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2009-09-13 00:09:41 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-06-26 00:30:15 -0600
commitdbd499c654ffc8f1195fc03bd06680045bc0e306 (patch)
tree0f6e7b121c9687fea7e8b1d5fd342835489d4fbd
parentccd574f08659e191cddbd63f00c0e9e9760827d4 (diff)
I like this
-rw-r--r--wrapper/plugin-find.h9
-rw-r--r--wrapper/plugin-parse.h90
-rw-r--r--wrapper/plugins.h8
-rw-r--r--wrapper/rvs.c3
4 files changed, 51 insertions, 59 deletions
diff --git a/wrapper/plugin-find.h b/wrapper/plugin-find.h
index 9444f55..f2d102f 100644
--- a/wrapper/plugin-find.h
+++ b/wrapper/plugin-find.h
@@ -95,13 +95,14 @@ plugin_find_commands(struct plugin *plugin, char *name)
}
}
-#ifdef DEBUG
void
-plugin_print_command_list(struct plugin_command_list *list, int ind)
+plugin_free_list(struct plugin_command_list *node)
{
-
+ if (node!=NULL) {
+ plugin_free_list(node->next);
+ xfree(node);
+ }
}
-#endif /*DEBUG*/
#endif
diff --git a/wrapper/plugin-parse.h b/wrapper/plugin-parse.h
index c75b1fe..4cad0bc 100644
--- a/wrapper/plugin-parse.h
+++ b/wrapper/plugin-parse.h
@@ -23,7 +23,7 @@
#define FILE_plugin_parse_h_SEEN
#include <stdio.h>
-#include <error.h> /* only used in `plugin_parse_escape' for `error' */
+#include <error.h> /* only used in `plugin_parse_escape' for `error'*/
#include "rvs.h"
#include "plugins.h"
@@ -66,24 +66,20 @@ plugin_parse_depend (FILE *file)
string[0]='\0';
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]=plugin_parse_escape(file);
- stradds(&nbytes,&string,cs);
- break;
- case '#':
- plugin_parse_comment(file);
- break;
- default:
- stradds(&nbytes,&string,cs);
- break;
- }
+ switch (c[0]) {
+ case '\n':
+ ungetc (c[0], file);
+ return string;
+ break;
+ case '#':
+ plugin_parse_comment(file);
+ break;
+ case '\\':
+ c[0]=plugin_parse_escape(file);
+ default:
+ stradds(&nbytes,&string,(char *)&c);
+ break;
}
}
return string;
@@ -95,45 +91,35 @@ plugin_parse (FILE *file)
struct plugin_command *command=plugin_mk_command();
size_t nbytes = 10;
- char *string = (char *)xmalloc(nbytes);
- string[0]='\0';
+ command->name = (char *)xmalloc(nbytes);
+ command->name[0]='\0';
char c[2] = " \0";
- char *cs = (char *)&c;
- if ( (c[0]=getc(file)) == EOF )
- return NULL;
- else
- ungetc (c[0], file);
+ c[0]=getc(file);
+ if (c[0]==EOF) return NULL;
+ else ungetc (c[0], file);
while ( (c[0]=getc(file)) != EOF ) {
- if (c[0] == '\n') {
- if (strlen(string)==0) {
- xfree(command);
- xfree(string);
- command=plugin_parse(file);
- } else {
- command->name=string;
- command->next=plugin_parse(file);
- }
- break;
- } else {
- switch (c[0]) {
- case '\\':
- c[0]=plugin_parse_escape(file);
- stradds(&nbytes,&string,cs);
- break;
- case '#':
- plugin_parse_comment(file);
- break;
- case ':':
- command->depends=plugin_parse_depend(
- file);
- break;
- default:
- stradds(&nbytes,&string,cs);
- break;
- }
+ switch (c[0]) {
+ case '\n':
+ if (strlen(command->name)==0) {
+ plugin_free_command(command);
+ command=plugin_parse(file);
+ } else
+ command->next=plugin_parse(file);
+ break;
+ case ':':
+ command->depends=plugin_parse_depend(file);
+ break;
+ case '#':
+ plugin_parse_comment(file);
+ break;
+ case '\\':
+ c[0]=plugin_parse_escape(file);
+ default:
+ stradds(&nbytes,&(command->name),(char *)&c);
+ break;
}
}
return command;
diff --git a/wrapper/plugins.h b/wrapper/plugins.h
index 739fce8..1e88279 100644
--- a/wrapper/plugins.h
+++ b/wrapper/plugins.h
@@ -58,6 +58,9 @@ plugin_mk_command()
{
struct plugin_command *command;
command=(struct plugin_command *)xmalloc(sizeof(*command));
+ #ifdef DEBUG
+ printf("malloc'd command: %p\n",command);
+ #endif
/* node */
command->name=NULL;
@@ -79,8 +82,11 @@ void
plugin_free_command(struct plugin_command *command)
{
if (command!=NULL) {
- printf("%p\n",command->next);
plugin_free_command(command->next);
+ #ifdef DEBUG
+ printf(" free'd command: %p \"%s\"\n",
+ command,command->name);
+ #endif
xfree(command->name);
xfree(command->depends);
xfree(command);
diff --git a/wrapper/rvs.c b/wrapper/rvs.c
index cf2b708..50343e4 100644
--- a/wrapper/rvs.c
+++ b/wrapper/rvs.c
@@ -38,9 +38,8 @@ main ( int argc, char *argv[] )
struct plugin_command_list *list;
list=plugin_find_commands(plugins,argv[1]);
plugin_depend_list(list,plugins);
- puts("");
+ plugin_free_list(list);
}
- puts("freeing...");
plugin_free_plugin(plugins);
return 0;
}