]> mj.ucw.cz Git - libucw.git/commitdiff
Unified printing of flags.
authorMartin Mares <mj@ucw.cz>
Mon, 29 Jan 2007 11:22:39 +0000 (12:22 +0100)
committerMartin Mares <mj@ucw.cz>
Mon, 29 Jan 2007 11:22:39 +0000 (12:22 +0100)
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
lib/string.c

index 27a7511b1308260c67196a23dc87a48fee16bc96..c56d5e3b7f6c0016420913695a0bfa4cc97c0dc8 100644 (file)
--- 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 */
 
index 454910252f57c70246579e084eb50e96c016befe..3f4c045fcea62011dac2bc8f67b779edc95848b2 100644 (file)
@@ -2,6 +2,7 @@
  *     UCW Library -- String Routines
  *
  *     (c) 2006 Pavel Charvat <pchar@ucw.cz>
+ *     (c) 2007 Martin Mares <mj@ucw.cz>
  *
  *     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;
+}