diff --git a/conman.c b/conman.c index e069cc51..5a7e6974 100644 --- a/conman.c +++ b/conman.c @@ -2176,14 +2176,51 @@ int LogCapture(SConnection * pCon, SicsInterp * pSics, void *pData, argtolower(argc, argv); /* Branch according to argv[1] */ - if (strcmp(argv[1], "kill") == 0) { + if (strcmp(argv[1], "kill") == 0 || strcmp(argv[1], "none") == 0) { + SCPrintf(pCon, eLog, "getlog %s", argv[1]); KillCapture(pConMaster); return 1; + } else if (strcmp(argv[1], "what") == 0) { + unsigned int code_bits = 0; + pDynString buffer; + code_bits = (1 << iNoCodes) - 1; + buffer = CreateDynString(100, 100); + for (i = 0; i < iNoCodes; ++i) { + if (code_bits & (1 << i)) { + if (GetDynStringLength(buffer) > 0) + DynStringConcatChar(buffer, ','); + DynStringConcat(buffer, OutCodeToTxt(i)); + } + } + SCPrintf(pCon, eLog, "getlog %s", GetCharArray(buffer)); + DeleteDynString(buffer); + return 1; + } else if (strcmp(argv[1], "list") == 0) { + unsigned int code_bits = 0; + pDynString buffer; + code_bits = GetSICSLogHook(pConMaster); + if (code_bits == 0) { + SCPrintf(pCon, eLog, "getlog none"); + return 1; + } + buffer = CreateDynString(100, 100); + for (i = 0; i < iNoCodes; ++i) { + if (code_bits & (1 << i)) { + if (GetDynStringLength(buffer) > 0) + DynStringConcatChar(buffer, ','); + DynStringConcat(buffer, OutCodeToTxt(i)); + } + } + SCPrintf(pCon, eLog, "getlog %s", GetCharArray(buffer)); + DeleteDynString(buffer); + return 1; } else if (strcmp(argv[1], "all") == 0) { + SCPrintf(pCon, eLog, "getlog all"); AddSICSLogHook(hookFunc, "all", pConMaster); return 1; } else if (argc == 2) { /* must be outcode, try find it */ + SCPrintf(pCon, eLog, "getlog %s", argv[1]); AddSICSLogHook(hookFunc, argv[1], pConMaster); return 1; } else { @@ -2207,6 +2244,7 @@ int LogCapture(SConnection * pCon, SicsInterp * pSics, void *pData, strcpy(&pBuff[len], argv[i]); len += strlen(argv[i]); } + SCPrintf(pCon, eLog, "getlog %s", pBuff); AddSICSLogHook(hookFunc, pBuff, pConMaster); if (pBuff != pBueffel) free(pBuff); diff --git a/servlog.c b/servlog.c index da51c839..90ab59a8 100644 --- a/servlog.c +++ b/servlog.c @@ -140,14 +140,20 @@ int OutCodeFromText(const char *text, OutCode *outcode) } static unsigned int find_code_bits(const char *p1, const char *p2) { - /* must be outcode, try find it */ + /* may be outcode, try find it */ int i; + const char *pShort; + const char *pLong; size_t len = p2 - p1; - if (len == 3 && strncasecmp(p1, "all", 3)) - return ~0; + if (len == 3 && strncasecmp(p1, "all", 3) == 0) + return (1 << iNoCodes) - 1; for (i = 0; i < iNoCodes; ++i) { - if (pCode[i] != NULL && strlen(pCode[i]) == len) { - if (strncasecmp(p1, pCode[i], len) == 0) { + pShort = OutCodeToTxt(i); + if (pShort && strncasecmp(p1, pShort, len) == 0) + return 1 << i; + pLong = OutCodeToText(i); + if (pLong && strlen(pLong) == len) { + if (strncasecmp(p1, pLong, len) == 0) { return 1 << i; } } @@ -159,7 +165,7 @@ char *AddSICSLogHook(pSICSLogHook func, const char *pCodes, void *pData) { unsigned int code_bits = 0; if (strcasecmp("all", pCodes) == 0) - code_bits = ~0; + code_bits = (1 << iNoCodes) - 1; else { const char *p1, *p2; p1 = pCodes; @@ -221,6 +227,23 @@ char *RemSICSLogHook(void *pData) return NULL; } +/* Return bitmask of any and all hooks with this pData */ +unsigned int GetSICSLogHook(void *pData) +{ + pCaptureEntry pCurrent, pTemp; + unsigned int code_bits = 0; + + /* find first */ + pCurrent = pCapture; + while (pCurrent != NULL) { + if (pData == pCurrent->pData) { + code_bits |= pCurrent->code_bits; + } + pCurrent = pCurrent->pNext; + } + return code_bits; +} + /*--------------------------------------------------------------------------*/ static int HasLineFeed(char *pText) diff --git a/servlog.h b/servlog.h index ce5af4fb..99fafc0a 100644 --- a/servlog.h +++ b/servlog.h @@ -36,4 +36,5 @@ void SICSLogEnable(int flag); typedef void (*pSICSLogHook)(const char *pText, OutCode eOut, void *pData); char *AddSICSLogHook(pSICSLogHook func, const char *pCodes, void *pData); char *RemSICSLogHook(void *pData); +unsigned int GetSICSLogHook(void *pData); #endif