diff --git a/site_ansto/site_ansto.c b/site_ansto/site_ansto.c index ec04c1b7..8d2715bc 100644 --- a/site_ansto/site_ansto.c +++ b/site_ansto/site_ansto.c @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef SICS_VALGRIND #include @@ -322,6 +323,33 @@ int testLogCmd(SConnection *pCon, SicsInterp *pInter, void *pData, return OKOK; } +/** + * \brief Writes multiline output from a command to a client. + * This is useful for implementing Tcl proc wrappers for commands. + * NOTE: SICS-764, currently this sends output to the client as well as capturing it. + * We should try to improve this in Release 3.2 see SICS-765 + */ +int Ansto_Capture(SConnection *pCon, SicsInterp * pSics, void *pData, int argc, char *argv[]) { + char buffer[1024]; + char *command, *data; + int status, inMacro; + + if (argc < 2) { + SCWrite(pCon, "ERROR: insufficient arguments to capture", eError); + return 0; + } + command = Arg2Tcl(argc - 1, &argv[1], buffer, sizeof buffer); + inMacro = pCon->iMacro; + pCon->iMacro = 0; + status = InterpExecute(pSics, pCon, command); + pCon->iMacro = inMacro; + if (command != buffer) + free(command); + data = ANETgetWBuffer(pCon->sockHandle); + SCWrite(pCon, data, eValue); + return status; +} + void SiteInit(void) { #define INIT(F) { void F(void); F(); } /* insert here initialization routines ... */ @@ -376,6 +404,7 @@ static void AddCommands(SicsInterp *pInter) AddCommand(pInter, "sicslist", SicsList, NULL, NULL); AddCommand(pInter, "FileEvalGlob", MacroFileEvalGlob, NULL, NULL); AddCommand(pInter, "Valgrind", Ansto_Valgrind, NULL, NULL); + AddCommand(pInter, "anstocapture", Ansto_Capture, NULL, NULL); /* * Tcl 8.5 has implemented the clock command in tcl rather then C.