improve indent to match existing
This commit is contained in:
354
servlog.c
354
servlog.c
@@ -246,7 +246,7 @@ int OpenVerifyLogFile()
|
|||||||
char *pChar = NULL;
|
char *pChar = NULL;
|
||||||
char fPath[1024];
|
char fPath[1024];
|
||||||
|
|
||||||
/* snprintf(fPath, 1023, "%s/", getenv("SICS_INIT_LOGPATH")); */
|
/* snprintf(fPath, 1023, "%s/", getenv("SICS_INIT_LOGPATH")); */
|
||||||
snprintf(fPath, 1023, "%s/", "../log");
|
snprintf(fPath, 1023, "%s/", "../log");
|
||||||
|
|
||||||
pChar = IFindOption(pSICSOptions, "LogFileBaseName");
|
pChar = IFindOption(pSICSOptions, "LogFileBaseName");
|
||||||
@@ -310,7 +310,7 @@ static void SICSLogWriteFile(char *pText, OutCode eOut, struct timeval *tp)
|
|||||||
|
|
||||||
/* switch file if too many lines */
|
/* switch file if too many lines */
|
||||||
if (iLineCount >= MAXLOG) {
|
if (iLineCount >= MAXLOG) {
|
||||||
fprintf(fLogFile,"%s: <<<close logfile>>>\n", timestamp(NULL));
|
fprintf(fLogFile, "%s: <<<close logfile>>>\n", timestamp(NULL));
|
||||||
fclose(fLogFile);
|
fclose(fLogFile);
|
||||||
fLogFile = NULL;
|
fLogFile = NULL;
|
||||||
iFile++;
|
iFile++;
|
||||||
@@ -321,205 +321,210 @@ static void SICSLogWriteFile(char *pText, OutCode eOut, struct timeval *tp)
|
|||||||
iLogUsable = OpenVerifyLogFile();
|
iLogUsable = OpenVerifyLogFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(1 == iLogUsable)
|
if (1 == iLogUsable) {
|
||||||
{
|
|
||||||
|
|
||||||
if (iLineCount == 0)
|
if (iLineCount == 0)
|
||||||
fprintf(fLogFile,"%s: <<<open logfile>>>\n", timestamp(NULL));
|
fprintf(fLogFile, "%s: <<<open logfile>>>\n", timestamp(NULL));
|
||||||
fprintf(fLogFile,"%s: ", timestamp(tp));
|
fprintf(fLogFile, "%s: ", timestamp(tp));
|
||||||
fprintf(fLogFile,"%s", pText);
|
fprintf(fLogFile, "%s", pText);
|
||||||
if (text_len < 1 || pText[text_len - 1] != '\n')
|
if (text_len < 1 || pText[text_len - 1] != '\n')
|
||||||
fprintf(fLogFile,"\n");
|
fprintf(fLogFile, "\n");
|
||||||
fflush(fLogFile);
|
fflush(fLogFile);
|
||||||
iLineCount++;
|
iLineCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SICSLogWriteTime(char *pText, OutCode eOut, struct timeval *tp) {
|
void SICSLogWriteTime(char *pText, OutCode eOut, struct timeval *tp)
|
||||||
char buf[200];
|
{
|
||||||
const char *cp = pText;
|
char buf[200];
|
||||||
int idx = 0;
|
const char *cp = pText;
|
||||||
struct timeval tv;
|
int idx = 0;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
if (tp == NULL) {
|
if (tp == NULL) {
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
tp = &tv;
|
tp = &tv;
|
||||||
}
|
}
|
||||||
while (*cp) {
|
while (*cp) {
|
||||||
if (*cp == '\n') {
|
if (*cp == '\n') {
|
||||||
buf[idx++] = '\n';
|
|
||||||
buf[idx++] = '\0';
|
|
||||||
SICSLogWriteFile(buf, eOut, tp);
|
|
||||||
idx = 0;
|
|
||||||
}
|
|
||||||
else if (*cp == '\r') {
|
|
||||||
buf[idx++] = '\\';
|
|
||||||
buf[idx++] = 'r';
|
|
||||||
}
|
|
||||||
else if (*cp == '\t') {
|
|
||||||
buf[idx++] = '\\';
|
|
||||||
buf[idx++] = 't';
|
|
||||||
}
|
|
||||||
else if (*cp < ' ' || *cp > '~') {
|
|
||||||
const char hex[] = "0123456789ABCDEF";
|
|
||||||
buf[idx++] = '<';
|
|
||||||
buf[idx++] = hex[(*cp >> 4) & 0xF];
|
|
||||||
buf[idx++] = hex[(*cp) & 0xF];
|
|
||||||
buf[idx++] = '>';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
buf[idx++] = *cp;
|
|
||||||
}
|
|
||||||
cp++;
|
|
||||||
if (idx > 132) {
|
|
||||||
buf[idx++] = '\n';
|
|
||||||
buf[idx++] = '\0';
|
|
||||||
SICSLogWriteFile(buf, eOut, tp);
|
|
||||||
idx = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (idx > 0) {
|
|
||||||
buf[idx++] = '\n';
|
buf[idx++] = '\n';
|
||||||
buf[idx++] = '\0';
|
buf[idx++] = '\0';
|
||||||
SICSLogWriteFile(buf, eOut, tp);
|
SICSLogWriteFile(buf, eOut, tp);
|
||||||
|
idx = 0;
|
||||||
|
} else if (*cp == '\r') {
|
||||||
|
buf[idx++] = '\\';
|
||||||
|
buf[idx++] = 'r';
|
||||||
|
} else if (*cp == '\t') {
|
||||||
|
buf[idx++] = '\\';
|
||||||
|
buf[idx++] = 't';
|
||||||
|
} else if (*cp < ' ' || *cp > '~') {
|
||||||
|
const char hex[] = "0123456789ABCDEF";
|
||||||
|
buf[idx++] = '<';
|
||||||
|
buf[idx++] = hex[(*cp >> 4) & 0xF];
|
||||||
|
buf[idx++] = hex[(*cp) & 0xF];
|
||||||
|
buf[idx++] = '>';
|
||||||
|
} else {
|
||||||
|
buf[idx++] = *cp;
|
||||||
|
}
|
||||||
|
cp++;
|
||||||
|
if (idx > 132) {
|
||||||
|
buf[idx++] = '\n';
|
||||||
|
buf[idx++] = '\0';
|
||||||
|
SICSLogWriteFile(buf, eOut, tp);
|
||||||
|
idx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (idx > 0) {
|
||||||
void SICSLogWrite(char *pText, OutCode eOut) {
|
buf[idx++] = '\n';
|
||||||
struct timeval tv;
|
buf[idx++] = '\0';
|
||||||
gettimeofday(&tv, NULL);
|
SICSLogWriteFile(buf, eOut, tp);
|
||||||
SICSLogWriteTime(pText, eOut, &tv);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SICSLogWriteHexTime(const char* text, int count, OutCode eOut, struct timeval *tp) {
|
void SICSLogWrite(char *pText, OutCode eOut)
|
||||||
const char hex[] = "0123456789ABCDEF";
|
{
|
||||||
char addr[20], left[80], right[80];
|
struct timeval tv;
|
||||||
char *lp = left;
|
gettimeofday(&tv, NULL);
|
||||||
char *rp = right;
|
SICSLogWriteTime(pText, eOut, &tv);
|
||||||
int i;
|
}
|
||||||
int duplicates;
|
|
||||||
/* Limit the output */
|
void SICSLogWriteHexTime(const char *text, int count, OutCode eOut,
|
||||||
if (count > 1024)
|
struct timeval *tp)
|
||||||
count = 1024;
|
{
|
||||||
duplicates = 0;
|
const char hex[] = "0123456789ABCDEF";
|
||||||
for (i = 0; i < count; ++i) {
|
char addr[20], left[80], right[80];
|
||||||
if ((i & 0xF) == 0) {
|
char *lp = left;
|
||||||
if (i > 0) {
|
char *rp = right;
|
||||||
|
int i;
|
||||||
|
int duplicates;
|
||||||
|
/* Limit the output */
|
||||||
|
if (count > 1024)
|
||||||
|
count = 1024;
|
||||||
|
duplicates = 0;
|
||||||
|
for (i = 0; i < count; ++i) {
|
||||||
|
if ((i & 0xF) == 0) {
|
||||||
|
if (i > 0) {
|
||||||
|
char line[132];
|
||||||
|
snprintf(line, sizeof(line) - 1, "%-6s: %-49s | %-17s |", addr,
|
||||||
|
left, right);
|
||||||
|
SICSLogWriteTime(line, eOut, tp);
|
||||||
|
}
|
||||||
|
snprintf(addr, sizeof(addr) - 1, "0x%04X", i);
|
||||||
|
while (i >= 16 && i + 16 < count) {
|
||||||
|
if (memcmp(&text[i - 16], &text[i], 16) != 0)
|
||||||
|
break;
|
||||||
|
++duplicates;
|
||||||
|
i += 16;
|
||||||
|
}
|
||||||
|
if (duplicates > 0) {
|
||||||
|
if (duplicates > 1) {
|
||||||
char line[132];
|
char line[132];
|
||||||
snprintf(line, sizeof(line)-1, "%-6s: %-49s | %-17s |", addr, left, right);
|
snprintf(line, sizeof(line) - 1, "%-6s: ... (%d duplicates)",
|
||||||
|
addr, duplicates);
|
||||||
|
SICSLogWriteTime(line, eOut, tp);
|
||||||
|
} else {
|
||||||
|
char line[132];
|
||||||
|
snprintf(line, sizeof(line) - 1, "%-6s: %-49s | %-17s |", addr,
|
||||||
|
left, right);
|
||||||
SICSLogWriteTime(line, eOut, tp);
|
SICSLogWriteTime(line, eOut, tp);
|
||||||
}
|
}
|
||||||
snprintf(addr, sizeof(addr)-1, "0x%04X", i);
|
duplicates = 0;
|
||||||
while (i >= 16 && i + 16 < count) {
|
|
||||||
if (memcmp(&text[i-16], &text[i], 16) != 0)
|
|
||||||
break;
|
|
||||||
++duplicates;
|
|
||||||
i += 16;
|
|
||||||
}
|
|
||||||
if (duplicates > 0) {
|
|
||||||
if (duplicates > 1) {
|
|
||||||
char line[132];
|
|
||||||
snprintf(line, sizeof(line)-1, "%-6s: ... (%d duplicates)", addr, duplicates);
|
|
||||||
SICSLogWriteTime(line, eOut, tp);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
char line[132];
|
|
||||||
snprintf(line, sizeof(line)-1, "%-6s: %-49s | %-17s |", addr, left, right);
|
|
||||||
SICSLogWriteTime(line, eOut, tp);
|
|
||||||
}
|
|
||||||
duplicates = 0;
|
|
||||||
}
|
|
||||||
snprintf(addr, sizeof(addr)-1, "0x%04X", i);
|
|
||||||
lp = left;
|
|
||||||
rp = right;
|
|
||||||
}
|
}
|
||||||
*lp++ = hex[(text[i] >> 4) & 0xF];
|
snprintf(addr, sizeof(addr) - 1, "0x%04X", i);
|
||||||
*lp++ = hex[(text[i]) & 0xF];
|
lp = left;
|
||||||
|
rp = right;
|
||||||
|
}
|
||||||
|
*lp++ = hex[(text[i] >> 4) & 0xF];
|
||||||
|
*lp++ = hex[(text[i]) & 0xF];
|
||||||
|
*lp++ = ' ';
|
||||||
|
if (text[i] >= ' ' && text[i] <= '~')
|
||||||
|
*rp++ = text[i];
|
||||||
|
else
|
||||||
|
*rp++ = '.';
|
||||||
|
/* if we just did slot 7, insert an extra space */
|
||||||
|
if ((i & 0xF) == 7) {
|
||||||
*lp++ = ' ';
|
*lp++ = ' ';
|
||||||
if (text[i]>= ' ' && text[i] <= '~')
|
*rp++ = ' ';
|
||||||
*rp++ = text[i];
|
|
||||||
else
|
|
||||||
*rp++ = '.';
|
|
||||||
/* if we just did slot 7, insert an extra space */
|
|
||||||
if ((i & 0xF) == 7) {
|
|
||||||
*lp++ = ' ';
|
|
||||||
*rp++ = ' ';
|
|
||||||
}
|
|
||||||
*lp = *rp = '\0';
|
|
||||||
}
|
}
|
||||||
if (i > 0) {
|
*lp = *rp = '\0';
|
||||||
char line[132];
|
}
|
||||||
snprintf(line, sizeof(line)-1, "%-6s: %-49s | %-17s |", addr, left, right);
|
if (i > 0) {
|
||||||
SICSLogWriteTime(line, eOut, tp);
|
char line[132];
|
||||||
|
snprintf(line, sizeof(line) - 1, "%-6s: %-49s | %-17s |", addr, left,
|
||||||
|
right);
|
||||||
|
SICSLogWriteTime(line, eOut, tp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SICSLogWriteHex(const char *text, int count, OutCode eOut)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
SICSLogWriteHexTime(text, count, eOut, &tv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SICSLogTimePrintf(OutCode eOut, struct timeval *tp, const char *fmt,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char buf[256];
|
||||||
|
char *dyn;
|
||||||
|
unsigned int l;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
l = vsnprintf(buf, sizeof buf, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (l >= sizeof buf) {
|
||||||
|
/* we have probably a C99 conforming snprintf and
|
||||||
|
need a larger buffer
|
||||||
|
*/
|
||||||
|
dyn = malloc(l + 1);
|
||||||
|
if (dyn != NULL) {
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(dyn, l + 1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
SICSLogWriteTime(dyn, eOut, tp);
|
||||||
|
free(dyn);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SICSLogWriteTime(buf, eOut, tp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void SICSLogWriteHex(const char* text, int count, OutCode eOut) {
|
void SICSLogPrintf(OutCode eOut, const char *fmt, ...)
|
||||||
struct timeval tv;
|
{
|
||||||
gettimeofday(&tv, NULL);
|
va_list ap;
|
||||||
SICSLogWriteHexTime(text, count, eOut, &tv);
|
char buf[256];
|
||||||
}
|
char *dyn;
|
||||||
|
unsigned int l;
|
||||||
|
int res;
|
||||||
|
|
||||||
void SICSLogTimePrintf(OutCode eOut, struct timeval *tp, const char *fmt, ...)
|
va_start(ap, fmt);
|
||||||
{
|
l = vsnprintf(buf, sizeof buf, fmt, ap);
|
||||||
va_list ap;
|
va_end(ap);
|
||||||
char buf[256];
|
if (l >= sizeof buf) {
|
||||||
char *dyn;
|
/* we have probably a C99 conforming snprintf and
|
||||||
unsigned int l;
|
need a larger buffer
|
||||||
int res;
|
*/
|
||||||
|
dyn = malloc(l + 1);
|
||||||
va_start(ap, fmt);
|
if (dyn != NULL) {
|
||||||
l = vsnprintf(buf, sizeof buf, fmt, ap);
|
va_start(ap, fmt);
|
||||||
va_end(ap);
|
vsnprintf(dyn, l + 1, fmt, ap);
|
||||||
if (l >= sizeof buf) {
|
va_end(ap);
|
||||||
/* we have probably a C99 conforming snprintf and
|
SICSLogWrite(dyn, eOut);
|
||||||
need a larger buffer
|
free(dyn);
|
||||||
*/
|
return;
|
||||||
dyn = malloc(l+1);
|
|
||||||
if (dyn != NULL) {
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vsnprintf(dyn, l+1, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
SICSLogWriteTime(dyn, eOut, tp);
|
|
||||||
free(dyn);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
SICSLogWriteTime(buf, eOut, tp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SICSLogPrintf(OutCode eOut, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
char buf[256];
|
|
||||||
char *dyn;
|
|
||||||
unsigned int l;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
l = vsnprintf(buf, sizeof buf, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
if (l >= sizeof buf) {
|
|
||||||
/* we have probably a C99 conforming snprintf and
|
|
||||||
need a larger buffer
|
|
||||||
*/
|
|
||||||
dyn = malloc(l+1);
|
|
||||||
if (dyn != NULL) {
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vsnprintf(dyn, l+1, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
SICSLogWrite(dyn, eOut);
|
|
||||||
free(dyn);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SICSLogWrite(buf, eOut);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
SICSLogWrite(buf, eOut);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Test of the logging facilities */
|
/* Test of the logging facilities */
|
||||||
int testLogCmd(SConnection *pCon, SicsInterp *pInter, void *pData, int argc, char *argv[]) {
|
int testLogCmd(SConnection *pCon, SicsInterp *pInter, void *pData,
|
||||||
|
int argc, char *argv[]) {
|
||||||
char lbuf[2048];
|
char lbuf[2048];
|
||||||
char sbuf[1000];
|
char sbuf[1000];
|
||||||
int i;
|
int i;
|
||||||
@@ -529,17 +534,16 @@ int testLogCmd(SConnection *pCon, SicsInterp *pInter, void *pData, int argc, cha
|
|||||||
SICSLogPrintf(eStatus, "Hexlog %d all zero bytes", sizeof(lbuf));
|
SICSLogPrintf(eStatus, "Hexlog %d all zero bytes", sizeof(lbuf));
|
||||||
SICSLogWriteHex(lbuf, sizeof(lbuf), eStatus);
|
SICSLogWriteHex(lbuf, sizeof(lbuf), eStatus);
|
||||||
for (i = 0; i <= 128; ++i)
|
for (i = 0; i <= 128; ++i)
|
||||||
sbuf[i] = sbuf[sizeof(sbuf)-1 - i] = i;
|
sbuf[i] = sbuf[sizeof(sbuf) - 1 - i] = i;
|
||||||
sbuf[sizeof(sbuf)/2] = '!';
|
sbuf[sizeof(sbuf) / 2] = '!';
|
||||||
SICSLogPrintf(eStatus, "Hexlog %d mid space bytes", sizeof(sbuf));
|
SICSLogPrintf(eStatus, "Hexlog %d mid space bytes", sizeof(sbuf));
|
||||||
SICSLogWriteHex(sbuf, sizeof(sbuf), eStatus);
|
SICSLogWriteHex(sbuf, sizeof(sbuf), eStatus);
|
||||||
for (i = 0; i < 1000; ++i)
|
for (i = 0; i < 1000; ++i)
|
||||||
sbuf[i] = ' ' + (i % 96);
|
sbuf[i] = ' ' + (i % 96);
|
||||||
sbuf[sizeof(sbuf)-1] = '\0';
|
sbuf[sizeof(sbuf) - 1] = '\0';
|
||||||
SICSLogWrite("Very long line 1000 bytes", eStatus);
|
SICSLogWrite("Very long line 1000 bytes", eStatus);
|
||||||
SICSLogWrite(sbuf, eStatus);
|
SICSLogWrite(sbuf, eStatus);
|
||||||
SCSendOK(pCon);
|
SCSendOK(pCon);
|
||||||
return OKOK;
|
return OKOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user