aboutsummaryrefslogtreecommitdiff
path: root/src/rc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rc.c')
-rw-r--r--src/rc.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/rc.c b/src/rc.c
index bb9d25a..7586975 100644
--- a/src/rc.c
+++ b/src/rc.c
@@ -15,39 +15,43 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <cflow.h>
#include <parser.h>
#include <sys/stat.h>
#include <ctype.h>
-#include <argcv.h>
+#include <wordsplit.h>
#ifndef LOCAL_RC
# define LOCAL_RC ".cflowrc"
#endif
static void
expand_argcv(int *argc_ptr, char ***argv_ptr, int argc, char **argv)
{
int i;
*argv_ptr = xrealloc(*argv_ptr,
(*argc_ptr + argc + 1) * sizeof **argv_ptr);
- for (i = 0; i <= argc; i++)
- (*argv_ptr)[*argc_ptr + i] = argv[i];
+ for (i = 0; i < argc; i++)
+ (*argv_ptr)[*argc_ptr + i] = xstrdup(argv[i]);
+ (*argv_ptr)[*argc_ptr + i] = NULL;
*argc_ptr += argc;
}
/* Parse rc file
*/
void
parse_rc(int *argc_ptr, char ***argv_ptr, char *name)
{
struct stat st;
FILE *rcfile;
int size;
char *buf, *p;
+ struct wordsplit ws;
+ int wsflags;
+ int line;
if (stat(name, &st))
return;
buf = malloc(st.st_size+1);
if (!buf) {
error(0, 0, _("not enough memory to process rc file"));
@@ -59,20 +63,25 @@ parse_rc(int *argc_ptr, char ***argv_ptr, char *name)
return;
}
size = fread(buf, 1, st.st_size, rcfile);
buf[size] = 0;
fclose(rcfile);
+ ws.ws_comment = "#";
+ wsflags = WRDSF_DEFFLAGS | WRDSF_COMMENT;
+ line = 0;
for (p = strtok(buf, "\n"); p; p = strtok(NULL, "\n")) {
- int argc;
- char **argv;
-
- argcv_get(p, "", "#", &argc, &argv);
- expand_argcv(argc_ptr, argv_ptr, argc, argv);
- free(argv);
+ ++line;
+ if (wordsplit(p, &ws, wsflags))
+ error(1, 0, "%s:%d: %s", name, line, wordsplit_strerror(&ws));
+ wsflags |= WRDSF_REUSE;
+ if (ws.ws_wordc)
+ expand_argcv(argc_ptr, argv_ptr, ws.ws_wordc, ws.ws_wordv);
}
+ if (wsflags & WRDSF_REUSE)
+ wordsplit_free(&ws);
free(buf);
}
/* Process the value of the environment variable CFLOW_OPTIONS
* and of the rc file.
* Split the value into words and add them between (*ARGV_PTR)[0] and
@@ -91,18 +100,21 @@ sourcerc(int *argc_ptr, char ***argv_ptr)
xargv = xmalloc(2*sizeof *xargv);
xargv[0] = **argv_ptr;
xargv[1] = NULL;
env = getenv("CFLOW_OPTIONS");
if (env) {
- int argc;
- char **argv;
-
- argcv_get(env, "", "#", &argc, &argv);
- expand_argcv(&xargc, &xargv, argc, argv);
- free(argv);
+ struct wordsplit ws;
+
+ ws.ws_comment = "#";
+ if (wordsplit(env, &ws, WRDSF_DEFFLAGS | WRDSF_COMMENT))
+ error(1, 0, "failed to parse CFLOW_OPTIONS: %s",
+ wordsplit_strerror(&ws));
+ if (ws.ws_wordc)
+ expand_argcv(&xargc, &xargv, ws.ws_wordc, ws.ws_wordv);
+ wordsplit_free(&ws);
}
env = getenv("CFLOWRC");
if (env)
parse_rc(&xargc, &xargv, env);
else {

Return to:

Send suggestions and report system problems to the System administrator.