From 0734923f3099f9d30cec159a992543cc74ec4964 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 29 Jan 2007 12:22:39 +0100 Subject: [PATCH] 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]. --- lib/lib.h | 1 + lib/string.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) 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; +} -- 2.39.5