From: Martin Mares Date: Mon, 29 Jan 2007 11:22:39 +0000 (+0100) Subject: Unified printing of flags. X-Git-Tag: holmes-import~506^2~110 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=0734923f3099f9d30cec159a992543cc74ec4964;p=libucw.git Unified printing of flags. I've moved format_flags() from idxdump to libucw and used it where possible. I've also unified the direction in which flag bits are printed, so the order of the state flags has changed [but I don't think anything relies on it]. --- diff --git a/lib/lib.h b/lib/lib.h index 27a7511b..c56d5e3b 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -268,6 +268,7 @@ sh_sighandler_t set_signal_handler(int signum, sh_sighandler_t new); /* string.c */ byte *str_unesc(byte *dest, byte *src); +byte *str_format_flags(byte *dest, const byte *fmt, uns flags); /* bigalloc.c */ diff --git a/lib/string.c b/lib/string.c index 45491025..3f4c045f 100644 --- a/lib/string.c +++ b/lib/string.c @@ -2,6 +2,7 @@ * UCW Library -- String Routines * * (c) 2006 Pavel Charvat + * (c) 2007 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -72,3 +73,18 @@ str_unesc(byte *d, byte *s) *d = 0; return d; } + +byte * +str_format_flags(byte *dest, const byte *fmt, uns flags) +{ + byte *start = dest; + for (uns i=0; fmt[i]; i++) + { + if (flags & (1 << i)) + *dest++ = fmt[i]; + else + *dest++ = '-'; + } + *dest = 0; + return start; +}