string function cleanups

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4714 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2009-11-07 22:44:32 +00:00
parent 9e817de2c8
commit e725e5ed8c
38 changed files with 423 additions and 420 deletions
+9 -9
View File
@@ -40,7 +40,7 @@ bool initlogging(const char *identity, int facility_, int consolethres, int file
if(filethres >= 0) filethreshold = min(filethres, (int)ACLOG_NUM);
if(syslogthres >= 0) syslogthreshold = min(syslogthres, (int)ACLOG_NUM);
facility &= 7;
s_sprintf(ident)("AssaultCube[%s]", identity);
formatstring(ident)("AssaultCube[%s]", identity);
if(syslogthreshold < ACLOG_NUM)
{
#ifdef AC_USE_SYSLOG
@@ -49,18 +49,18 @@ bool initlogging(const char *identity, int facility_, int consolethres, int file
if((logsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM)) == ENET_SOCKET_NULL || enet_address_set_host(&logdest, "localhost") < 0) syslogthreshold = ACLOG_NUM;
#endif
}
s_sprintf(filepath)("serverlog_%s_%s.txt", timestring(true), identity);
formatstring(filepath)("serverlog_%s_%s.txt", timestring(true), identity);
if(fp) { fclose(fp); fp = NULL; }
if(filethreshold < ACLOG_NUM)
{
fp = fopen(filepath, "w");
if(!fp) printf("failed to open \"%s\" for writing\n", filepath);
}
s_sprintfd(msg)("logging started: console(%s), file(%s", levelname[consolethreshold], levelname[fp ? filethreshold : ACLOG_NUM]);
if(fp) s_strcatf(msg, ", \"%s\"", filepath);
s_strcatf(msg, "), syslog(%s", levelname[syslogthreshold]);
if(syslogthreshold < ACLOG_NUM) s_strcatf(msg, ", \"%s\", local%d", ident, facility);
s_strcatf(msg, "), timestamp(%s)", timestamp ? "ENABLED" : "DISABLED");
defformatstring(msg)("logging started: console(%s), file(%s", levelname[consolethreshold], levelname[fp ? filethreshold : ACLOG_NUM]);
if(fp) concatformatstring(msg, ", \"%s\"", filepath);
concatformatstring(msg, "), syslog(%s", levelname[syslogthreshold]);
if(syslogthreshold < ACLOG_NUM) concatformatstring(msg, ", \"%s\", local%d", ident, facility);
concatformatstring(msg, "), timestamp(%s)", timestamp ? "ENABLED" : "DISABLED");
enabled = consolethreshold < ACLOG_NUM || fp || syslogthreshold < ACLOG_NUM;
if(enabled) printf("%s\n", msg);
return enabled;
@@ -80,7 +80,7 @@ bool logline(int level, const char *msg, ...)
{
if(!enabled) return false;
if(level < 0 || level >= ACLOG_NUM) return false;
s_sprintfdv(sf, msg);
defvformatstring(sf, msg, msg);
filtertext(sf, sf, 2);
const char *ts = timestamp ? timestring(true, "%b %d %H:%M:%S ") : "", *ld = levelprefix[level];
char *p, *l = sf;
@@ -94,7 +94,7 @@ bool logline(int level, const char *msg, ...)
syslog(levels[level], "%s", l);
#else
{
s_sprintfd(text)("<%d>%s: %s", (16 + facility) * 8 + levels[level], ident, l); // no TIMESTAMP, no hostname: syslog will add this
defformatstring(text)("<%d>%s: %s", (16 + facility) * 8 + levels[level], ident, l); // no TIMESTAMP, no hostname: syslog will add this
ENetBuffer buf;
buf.data = text;
buf.dataLength = strlen(text);