From d45993dba438fe52d21aca365ea3dceb40d9beb7 Mon Sep 17 00:00:00 2001 From: vague666 Date: Fri, 22 Mar 2019 12:30:46 +0100 Subject: [PATCH] Add -out parameter to /CAT Change flag to -window Updated help Typo call printtext with server Only use server when target is not NULL --- docs/help/in/cat.in | 7 +++++-- src/fe-common/core/fe-core-commands.c | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/help/in/cat.in b/docs/help/in/cat.in index 9f9f242f..370c1796 100644 --- a/docs/help/in/cat.in +++ b/docs/help/in/cat.in @@ -5,19 +5,22 @@ %9Parameters:%9 + -window: Displays the output in the active window. + The file to display and optionally a position to seek in the file, in bytes. %9Description:%9 - Displays the contents of the specified file into the active window. + Displays the contents of the specified file in the active window if -window + is specified, otherwise to the closest matching window depending on levels. The seek position parameter is used internally to display away logs, if omitted the whole file is shown. %9Examples:%9 - /CAT /etc/network/interfaces + /CAT -window /etc/network/interfaces /CAT /home/mike/resume.txt /CAT contact_details.txt diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index 7e09cded..3da998bf 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -114,10 +114,11 @@ static void cmd_version(char *data) } } -/* SYNTAX: CAT [] */ -static void cmd_cat(const char *data) +/* SYNTAX: CAT [-window] [] */ +static void cmd_cat(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { - char *fname, *fposstr; + char *fname, *fposstr, *target; + GHashTable *optlist; void *free_arg; int fpos; GIOChannel *handle; @@ -127,12 +128,14 @@ static void cmd_cat(const char *data) int fd; #endif - if (!cmd_get_params(data, &free_arg, 2, &fname, &fposstr)) + g_return_if_fail(data != NULL); + + if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS, + "cat", &optlist, &fname, &fposstr)) return; fname = convert_home(fname); fpos = atoi(fposstr); - cmd_params_free(free_arg); #ifdef HAVE_CAPSICUM fd = capsicum_open_wrapper(fname, O_RDONLY, 0); @@ -152,15 +155,18 @@ static void cmd_cat(const char *data) return; } + target = g_hash_table_lookup(optlist, "window") != NULL ? item->name : NULL; + g_io_channel_set_encoding(handle, NULL, NULL); g_io_channel_seek_position(handle, fpos, G_SEEK_SET, NULL); buf = g_string_sized_new(512); while (g_io_channel_read_line_string(handle, buf, &tpos, NULL) == G_IO_STATUS_NORMAL) { buf->str[tpos] = '\0'; - printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP | + printtext(target != NULL ? server : NULL, target, MSGLEVEL_CLIENTCRAP | MSGLEVEL_NEVER, "%s", buf->str); } g_string_free(buf, TRUE); + cmd_params_free(free_arg); g_io_channel_unref(handle); } @@ -344,6 +350,7 @@ void fe_core_commands_init(void) signal_add("list subcommands", (SIGNAL_FUNC) event_list_subcommands); command_set_options("echo", "+level +window"); + command_set_options("cat", "window"); } void fe_core_commands_deinit(void)