Add a "bool" lens
diff --git a/ChangeLog b/ChangeLog
index 62152a8..2047db3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2012-01-09 Petr Machata <pmachata@redhat.com>
+ * lens_default.c, lens_default.h (bool_lens): New global variable
+ * read_config_file.c: Plug it in
+ * testsuite/ltrace.main/parameters*: Test it
+
+2012-01-09 Petr Machata <pmachata@redhat.com>
+
* sysdeps/linux-gnu/x86_64/trace.c: Rewrite
2012-01-09 Petr Machata <pmachata@redhat.com>
diff --git a/lens_default.c b/lens_default.c
index f4e2bd8..75b8abe 100644
--- a/lens_default.c
+++ b/lens_default.c
@@ -419,6 +419,44 @@
static int
+bool_lens_format_cb(struct lens *lens, FILE *stream,
+ struct value *value, struct value_dict *arguments)
+{
+ switch (value->type->type) {
+ case ARGTYPE_VOID:
+ case ARGTYPE_FLOAT:
+ case ARGTYPE_DOUBLE:
+ case ARGTYPE_STRUCT:
+ case ARGTYPE_POINTER:
+ case ARGTYPE_ARRAY:
+ return toplevel_format_lens(lens, stream, value,
+ arguments, INT_FMT_i);
+
+ int zero;
+ case ARGTYPE_ENUM:
+ case ARGTYPE_SHORT:
+ case ARGTYPE_INT:
+ case ARGTYPE_LONG:
+ case ARGTYPE_USHORT:
+ case ARGTYPE_UINT:
+ case ARGTYPE_ULONG:
+ case ARGTYPE_CHAR:
+ if ((zero = value_is_zero(value, arguments)) < 0)
+ return -1;
+ if (zero)
+ return fprintf(stream, "false");
+ else
+ return fprintf(stream, "true");
+ }
+ abort();
+}
+
+struct lens bool_lens = {
+ .format_cb = bool_lens_format_cb,
+};
+
+
+static int
string_lens_format_cb(struct lens *lens, FILE *stream,
struct value *value, struct value_dict *arguments)
{
diff --git a/lens_default.h b/lens_default.h
index 7895a91..9a9d0c6 100644
--- a/lens_default.h
+++ b/lens_default.h
@@ -35,6 +35,9 @@
/* A lens that formats integers in hexadecimal. */
extern struct lens hex_lens;
+/* A lens that formats integers as either "true" or "false". */
+extern struct lens bool_lens;
+
/* A lens that tries to guess whether the value is "large" (i.e. a
* pointer, and should be formatted in hex), or "small" (and should be
* formatted in decimal). */
diff --git a/read_config_file.c b/read_config_file.c
index bb133b3..9faa5cf 100644
--- a/read_config_file.c
+++ b/read_config_file.c
@@ -804,6 +804,7 @@
{ "hide", &blind_lens },
{ "octal", &octal_lens },
{ "hex", &hex_lens },
+ { "bool", &bool_lens },
{ "guess", &guess_lens },
};