Added new @macros: @pipe{command}

This commit is contained in:
Ianos Gnatiuc 2006-02-10 11:30:03 +00:00
parent a55a5efef1
commit 74f9907cb3
2 changed files with 41 additions and 0 deletions

View File

@ -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

View File

@ -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++;
}
}