mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Add -out parameter to /CAT
Change flag to -window Updated help Typo call printtext with server Only use server when target is not NULL
This commit is contained in:
parent
6933134352
commit
d45993dba4
@ -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
|
||||
|
||||
|
@ -114,10 +114,11 @@ static void cmd_version(char *data)
|
||||
}
|
||||
}
|
||||
|
||||
/* SYNTAX: CAT <file> [<seek position>] */
|
||||
static void cmd_cat(const char *data)
|
||||
/* SYNTAX: CAT [-window] <file> [<seek position>] */
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user