X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=interactive.c;h=4c0392784604d4af06701dcdee355197d7ba868a;hb=4e757d60f7642c61e09a20a2a1de442b23208966;hp=e184dbe4fce70b65a22b54d1cacb58cd74074e43;hpb=63ef06be534ab9a8f31865ef6c2324f0a951aef9;p=adu.git diff --git a/interactive.c b/interactive.c index e184dbe..4c03927 100644 --- a/interactive.c +++ b/interactive.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2008 Andre Noll + * + * Licensed under the GPL v2. For licencing details see COPYING. + */ + #include /* isspace() */ #include "adu.h" @@ -30,7 +36,8 @@ static struct format_info *fi; INTERACTIVE_COMMAND(set, "change the current configuration") \ INTERACTIVE_COMMAND(reset, "reset configuration to defaults") \ INTERACTIVE_COMMAND(help, "show list of commands and one-line descriptions") \ - INTERACTIVE_COMMAND(run, "start the query according to the current configuration") + INTERACTIVE_COMMAND(run, "start the query according to the current configuration") \ + INTERACTIVE_COMMAND(source, "read and execute interactive commands from a file") #define INTERACTIVE_COMMAND(name, desc) \ @@ -147,7 +154,7 @@ static int exec_interactive_command(char *line) else { *args = '\0'; args++; - /* let p point to the next non-whitespace char */ + /* let args point to the next non-whitespace char */ args += strspn(args, delim); if (!*args) args = NULL; @@ -164,6 +171,25 @@ static int exec_interactive_command(char *line) return ret; } +static int icom_source(char *args) +{ + char line[255]; + FILE *src = fopen(args, "r"); + int ret; + + if (!src) + return -ERRNO_TO_ERROR(errno); + while (fgets(line, sizeof(line), src)) { + ret = exec_interactive_command(line); + if (ret < 0) + goto out; + } + ret = 1; +out: + fclose(src); + return ret; +} + int com_interactive(void) { char line[255];