From a55f52c205d2fdd9cc542541e208f7020a3fd583 Mon Sep 17 00:00:00 2001 From: dcp1990 Date: Sun, 12 Jun 2005 17:03:35 +0000 Subject: [PATCH] Use %b qualifier just like printf(9) --- phoned/log.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/phoned/log.c b/phoned/log.c index 001d571..1e2fd45 100644 --- a/phoned/log.c +++ b/phoned/log.c @@ -59,6 +59,10 @@ int lprintf(enum ltype logtype, const char* fmt, ...) char* str; void* voi; int maxsize; + int tmp; + const char *p; + long num; + unsigned n; time_t now; char tmt[128]; now = time(NULL); @@ -98,6 +102,24 @@ int lprintf(enum ltype logtype, const char* fmt, ...) uns = va_arg(ap, unsigned); cnt += fprintf(logf, ofmt, uns); break; + case 'b': + num = (unsigned int)va_arg(ap, int); + p = va_arg(ap, char *); + if(num == 0) break; + for(tmp = 0; *p;) { + n = (int)p++; + if(num & (1 << (n - 1))) { + fputc(tmp ? ',' : '<', logf); + for(;(n = *p) > ' '; ++p) + fputc(n, logf); + tmp = 1; + } else + for(;*p > ' '; ++p) + continue; + } + if(tmp) + fputc('>', logf); + break; case 'c': cha = (char) va_arg(ap, int); cnt += fprintf(logf, ofmt, cha);