diff options
author | Timo Sirainen <cras@irssi.org> | 2000-10-27 18:30:36 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-10-27 18:30:36 +0000 |
commit | d813ecd194f46cc0813a7b67bdcb882337ad13f9 (patch) | |
tree | 86f0df7c2095b68f3beaf1cfc4448f40ae65425e /src | |
parent | 25fa27c5f0bc3997c3e6fdb8e40975f4d575e581 (diff) | |
download | irssi-d813ecd194f46cc0813a7b67bdcb882337ad13f9.zip |
A simple /EXEC command by Tinuk.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@788 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r-- | src/fe-common/core/fe-core-commands.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index 1478e73a..ac6b846c 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -301,6 +301,44 @@ static void cmd_cat(const char *data) close(f); } + +/* SYNTAX: EXEC <cmd line> */ +static void cmd_exec(const char *cmdline) +{ + int buflen = 512; + char tmpbuf[buflen]; + char *foo; + FILE *stream; + + stream = popen(cmdline, "r"); + + if (!stream) { + /* execution error of some kind */ + printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, + "Cannot open output stream."); + return; + } + + while (fgets(tmpbuf, buflen, stream)) { + /* strip \n characters appended from fgets + This is safer than using gets, though it is more work tbd + */ + foo = tmpbuf; + while (*foo != '\0') { + if (*foo == '\n') { + *foo = '\0'; + break; + } + foo++; + } + + printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s", tmpbuf); + } + + pclose(stream); +} + + /* SYNTAX: BEEP */ static void cmd_beep(void) { @@ -408,6 +446,7 @@ void fe_core_commands_init(void) command_bind("echo", NULL, (SIGNAL_FUNC) cmd_echo); command_bind("version", NULL, (SIGNAL_FUNC) cmd_version); command_bind("cat", NULL, (SIGNAL_FUNC) cmd_cat); + command_bind("exec", NULL, (SIGNAL_FUNC) cmd_exec); command_bind("beep", NULL, (SIGNAL_FUNC) cmd_beep); signal_add("send command", (SIGNAL_FUNC) event_command); @@ -422,6 +461,7 @@ void fe_core_commands_deinit(void) command_unbind("echo", (SIGNAL_FUNC) cmd_echo); command_unbind("version", (SIGNAL_FUNC) cmd_version); command_unbind("cat", (SIGNAL_FUNC) cmd_cat); + command_unbind("exec", (SIGNAL_FUNC) cmd_exec); command_unbind("beep", (SIGNAL_FUNC) cmd_beep); signal_remove("send command", (SIGNAL_FUNC) event_command); |