print_quoted_string.c \
print_time.c \
printflags.c \
- printxval.c \
+ printxval-Xabbrev.c \
+ printxval-Xraw.c \
+ printxval-Xverbose.c \
signal2name.c \
skip_unavailable.c \
sprintrc.c \
pipe.expected \
print_user_desc.c \
printsignal.c \
+ printxval.c \
process_vm_readv_writev.c \
pure_executables.list \
qual_fault-exit_group.expected \
errstr = sprintrc(rc);
# if XLAT_RAW
printf("ioprio_get(0x1, 0) = %s\n", errstr);
-# elif XLAT_VERBOSE
- printf("ioprio_get(0x1 /* IOPRIO_WHO_PROCESS */, 0) = %s", errstr);
- if (rc >= 0) {
- printf(" (IOPRIO_PRIO_VALUE(%u /* ", (unsigned int) rc >> 13);
- printxval(ioprio_class, (unsigned int) rc >> 13,
- "IOPRIO_CLASS_???");
- printf(" */, %u))", (unsigned int) rc & 0x1fff);
- }
- puts("");
# else /* XLAT_ABBREV */
+# if XLAT_VERBOSE
+ printf("ioprio_get(0x1 /* IOPRIO_WHO_PROCESS */, 0) = %s", errstr);
+# else
printf("ioprio_get(IOPRIO_WHO_PROCESS, 0) = %s", errstr);
+# endif
if (rc >= 0) {
printf(" (IOPRIO_PRIO_VALUE(");
printxval(ioprio_class, (unsigned int) rc >> 13,
--- /dev/null
+#define XLAT_NAME(s_) s_##_abbrev
+#include "printxval.c"
--- /dev/null
+#define XLAT_RAW 1
+#define XLAT_NAME(s_) s_##_raw
+#include "printxval.c"
--- /dev/null
+#define XLAT_VERBOSE 1
+#define XLAT_NAME(s_) s_##_verbose
+#include "printxval.c"
#include "xlat.h"
#include <stdio.h>
-int
-printxval(const struct xlat *xlat, unsigned long long val,
- const char *const dflt)
+#if !XLAT_RAW
+static const char *
+lookup_xlat(const struct xlat *xlat, unsigned long long val)
{
const struct xlat_data *xd = xlat->data;
continue;
if (xd->val == val) {
- fputs(xd->str, stdout);
- return 1;
+ return xd->str;
}
}
+ return NULL;
+}
+#endif
+
+int
+XLAT_NAME(printxval)(const struct xlat *xlat, unsigned long long val,
+ const char *const dflt)
+{
+#if XLAT_RAW
+ printf("%#llx", val);
+
+ return 1;
+#else
+ const char *str = lookup_xlat(xlat, val);
+
+# if XLAT_VERBOSE
printf("%#llx", val);
+ if (str || dflt)
+ printf(" /* %s */", str ?: dflt);
+# else
+ if (str) {
+ fputs(str, stdout);
+ } else {
+ printf("%#llx", val);
+ if (dflt)
+ printf(" /* %s */", dflt);
+ }
+# endif /* XLAT_VERBOSE */
+
+ return !!str;
+#endif /* XLAT_RAW */
+}
+
+const char *
+XLAT_NAME(sprintxlat)(const char *str, unsigned long long val,
+ const char *const dflt)
+{
+ static char buf[256];
+
+#if XLAT_RAW
+ snprintf(buf, sizeof(buf), "%#llx", val);
+#elif XLAT_VERBOSE
+ if (str || dflt)
+ snprintf(buf, sizeof(buf), "%#llx /* %s */", val, str ?: dflt);
+ else
+ snprintf(buf, sizeof(buf), "%#llx", val);
+#else
+ if (str)
+ return str;
+
if (dflt)
- printf(" /* %s */", dflt);
- return 0;
+ snprintf(buf, sizeof(buf), "%#llx /* %s */", val, dflt);
+ else
+ snprintf(buf, sizeof(buf), "%#llx", val);
+#endif
+
+ return buf;
+}
+
+const char *
+XLAT_NAME(sprintxval)(const struct xlat *xlat, unsigned long long val,
+ const char *const dflt)
+{
+#if XLAT_RAW
+ return sprintxlat(NULL, val, dflt);
+#else
+ return sprintxlat(lookup_xlat(xlat, val), val, dflt);
+#endif
}
int printflags(const struct xlat *, const unsigned long long, const char *);
/* Print constant in symbolic form according to xlat table. */
-int printxval(const struct xlat *, const unsigned long long, const char *);
+int printxval_abbrev(const struct xlat *, const unsigned long long,
+ const char *);
+int printxval_raw(const struct xlat *, const unsigned long long, const char *);
+int printxval_verbose(const struct xlat *, const unsigned long long,
+ const char *);
+
+/* Print constant in symbolic form according to xlat table. */
+const char *sprintxlat_abbrev(const char *, const unsigned long long,
+ const char *);
+const char *sprintxlat_raw(const char *, const unsigned long long,
+ const char *);
+const char *sprintxlat_verbose(const char *, const unsigned long long,
+ const char *);
+
+/* Print constant in symbolic form according to xlat table. */
+const char *sprintxval_abbrev(const struct xlat *, const unsigned long long,
+ const char *);
+const char *sprintxval_raw(const struct xlat *, const unsigned long long,
+ const char *);
+const char *sprintxval_verbose(const struct xlat *, const unsigned long long,
+ const char *);
+
+# if XLAT_RAW
+# define printxval printxval_raw
+# define sprintxlat sprintxlat_raw
+# define sprintxval sprintxval_raw
+# elif XLAT_VERBOSE
+# define printxval printxval_verbose
+# define sprintxlat sprintxlat_verbose
+# define sprintxval sprintxval_verbose
+# else
+# define printxval printxval_abbrev
+# define sprintxlat sprintxlat_abbrev
+# define sprintxval sprintxval_abbrev
+# endif
/* Invoke a socket syscall, either directly or via __NR_socketcall. */
int socketcall(const int nr, const int call,