From 74f9907cb38ae17507bfc6d18bc0642a2a6056de Mon Sep 17 00:00:00 2001 From: Ianos Gnatiuc Date: Fri, 10 Feb 2006 11:30:03 +0000 Subject: [PATCH] Added new @macros: @pipe{`command`} --- docs/notework.txt | 3 +++ golded3/gemsgs.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/docs/notework.txt b/docs/notework.txt index 7fdd862..8a5cd55 100644 --- a/docs/notework.txt +++ b/docs/notework.txt @@ -10,6 +10,9 @@ ______________________________________________________________________ Notes for GoldED+ 1.1.5, /snapshot/ ______________________________________________________________________ ++ Added new macro: @pipe{`command`}, that inserts command's stdout in + message template. + ! Changed keywords global defaults: DispSoftCR Yes UseSoftCrxLat No diff --git a/golded3/gemsgs.cpp b/golded3/gemsgs.cpp index 3196359..3fce0b6 100644 --- a/golded3/gemsgs.cpp +++ b/golded3/gemsgs.cpp @@ -468,6 +468,44 @@ char* TokenXlat(int mode, char* input, GMsg* msg, GMsg* oldmsg, int __origarea) } } + if (strnieql(dst, "@pipe{`", 7)) + { + char *argbeg = dst+7; + char *argend = strstr(argbeg, "`}"); + + char token[1024]; + size_t tlen = argend-dst+2; + + memcpy(token, dst, tlen); + *argend = token[tlen] = 0; + + FILE *pipe_in; + std::string pipe_buff; + + if ((pipe_in = _popen(argbeg, "rt")) != NULL ) + { + char buffer[1024]; + while (!feof(pipe_in)) + { + if (fgets(buffer, sizeof(buffer), pipe_in) != NULL) + pipe_buff += buffer; + } + + _pclose(pipe_in); + } + + *argend = '`'; + + for (size_t i = 0; i < pipe_buff.length(); i++) + { + if (pipe_buff[i] == LF) + pipe_buff[i] = CR; + } + + if (tokenxchg(dst, token, pipe_buff.c_str())) + continue; + } + dst++; } }