Implement 'sicslog' command for driver logging

This commit is contained in:
Douglas Clowes
2014-04-23 16:26:18 +10:00
parent 0e0fd86da0
commit a557cf577a
4 changed files with 99 additions and 2 deletions

View File

@ -87,6 +87,9 @@ int KillCapture(SConnection * pCon);
int LogCapture(SConnection * pCon, SicsInterp * pInter, void *pData,
int argc, char *argv[]);
int LogOutput(SConnection * pCon, SicsInterp * pInter, void *pData,
int argc, char *argv[]);
/*------ Max Size of Command Stack */
#define MAXSTACK 1024
/*---------- Magic ID Header */
@ -2194,6 +2197,60 @@ int LogCapture(SConnection * pCon, SicsInterp * pSics, void *pData,
}
return 0;
}
/* ------------------------------------------------------------------------
the command function:
Syntax:
LogOutput [OutCode] <text>
Logs <text> with outcode OutCode default eLog
-------------------------------------------------------------------------- */
int LogOutput(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
char pBueffel[512];
char *pBuff;
int i, len, result, start;
OutCode outcode;
/* check no af args */
if (argc < 2) {
snprintf(pBueffel,sizeof(pBueffel)-1, "Insufficient number of arguments to %s", argv[0]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
/* assume default eLog unless told otherwise */
start = 1;
outcode = eLog;
if (argv[1][0] == '@') {
result = OutCodeFromText(&argv[1][1], &outcode);
if (result >= 0) {
start = 2;
}
}
/* make it a string */
for (i = start, len = 0; i < argc; ++i)
len += strlen(argv[i]) + 1;
if (len > sizeof(pBueffel))
pBuff = malloc(len+10);
else
pBuff = pBueffel;
if (pBuff == NULL) {
SCWrite(pCon, "Out of memory in LogOutput\n", eError);
return 1;
}
for (i = start, len = 0; i < argc; ++i) {
if (i > start)
pBuff[len++] = ' ';
strcpy(&pBuff[len], argv[i]);
len += strlen(argv[i]);
}
SICSLogWrite(pBuff, outcode);
if (pBuff != pBueffel)
free(pBuff);
return 1;
}
/*--------------------------------------------------------------------------*/
int SCTaskFunction(void *pData)
{