From 09b30a0e3aeba620db7daa3d81b30bbb5727dda3 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 9 Nov 2008 13:15:42 +0100 Subject: [PATCH] Implement the new interactive command "source". --- interactive.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/interactive.c b/interactive.c index 7b5ca76..3cfb3a2 100644 --- a/interactive.c +++ b/interactive.c @@ -30,7 +30,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) \ @@ -164,6 +165,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]; -- 2.30.2