]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/nstreval.c
symbol: Make actofgod.c's fmtflags() public as symbol_set_fmt()
[empserver] / src / lib / common / nstreval.c
index b7e5cf5132c706bbfcf2893b0596b3a09fc93f66..3e49b4789f5b3dd24e4c6120bf44d325b1caba78 100644 (file)
  *  Known contributors to this file:
  *     Dave Pare, 1989
  *     Steve McClure, 1997
- *     Markus Armbruster, 2004-2014
+ *     Markus Armbruster, 2004-2015
  */
 
 #include <config.h>
 
 #include <limits.h>
+#include <stdio.h>
 #include <string.h>
 #include "file.h"
 #include "nat.h"
@@ -258,3 +259,31 @@ symbol_by_value(int key, struct symbol *table)
 
     return NULL;
 }
+
+int
+symbol_set_fmt(char *buf, size_t sz, int flags, struct symbol symtab[],
+              int all)
+{
+    char *sep = "";
+    int n, i;
+    char *p;
+
+    if (buf && sz)
+       buf[0] = 0;
+    n = 0;
+    for (i = 0; i < 32; i++) {
+       if (!(flags & bit(i)))
+           continue;
+       p = symbol_by_value(bit(i), symtab);
+       if (p)
+           n += snprintf(buf + n, sz - n, "%s%s", sep, p);
+       else if (all)
+           n += snprintf(buf + n, sz - n, "%s#%d", sep, i);
+       if ((size_t)n >= sz)
+           sz = n;
+       sep = ", ";
+    }
+
+    CANT_HAPPEN((size_t)n >= sz && buf);
+    return n;
+}