summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-09-30 13:20:06 +0200
committerWerner Koch <wk@gnupg.org>2013-09-30 20:44:50 +0200
commitd69a13d3d1c14ad6a6aa7cd349d6d2dfb152d422 (patch)
tree5e96dcc38220ca22368d3b4b497f02a2fc9bdba4 /src
parent68cefd0f1d60ac33b58031df9b1d165cb1bf0f14 (diff)
downloadlibgcrypt-d69a13d3d1c14ad6a6aa7cd349d6d2dfb152d422.tar.gz
log: Try to print s-expressions in a more compact format.
* src/misc.c (count_closing_parens): New. (_gcry_log_printsxp): Use new function. * mpi/ec.c (_gcry_mpi_point_log): Take care of a NULL point. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src')
-rw-r--r--src/misc.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/misc.c b/src/misc.c
index d9b85cb1..d577b244 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -361,6 +361,22 @@ _gcry_log_printmpi (const char *text, gcry_mpi_t mpi)
}
}
+
+static int
+count_closing_parens (const char *p)
+{
+ int count = 0;
+
+ for (; *p; p++)
+ if (*p == ')')
+ count++;
+ else if (!strchr ("\n \t", *p))
+ return 0;
+
+ return count;
+}
+
+
/* Print SEXP in human readabale format. With TEXT of NULL print just the raw
dump without any wrappping, with TEXT an empty string, print a
trailing linefeed, otherwise print the full debug output. */
@@ -371,7 +387,7 @@ _gcry_log_printsxp (const char *text, gcry_sexp_t sexp)
if (text && *text)
{
- if ((with_lf = strchr (text, '\n')))
+ if ((with_lf = !!strchr (text, '\n')))
log_debug ("%s", text);
else
log_debug ("%s: ", text);
@@ -379,6 +395,7 @@ _gcry_log_printsxp (const char *text, gcry_sexp_t sexp)
if (sexp)
{
int any = 0;
+ int n_closing;
char *buf, *p, *pend;
size_t size;
@@ -395,18 +412,26 @@ _gcry_log_printsxp (const char *text, gcry_sexp_t sexp)
pend = strchr (p, '\n');
size = pend? (pend - p) : strlen (p);
if (with_lf)
- log_debug ("%.*s\n", (int)size, p);
+ log_debug ("%.*s", (int)size, p);
else
- log_printf ("%.*s\n", (int)size, p);
+ log_printf ("%.*s", (int)size, p);
if (pend)
p = pend + 1;
else
p += size;
+ n_closing = count_closing_parens (p);
+ if (n_closing)
+ {
+ while (n_closing--)
+ log_printf (")");
+ p = "";
+ }
+ log_printf ("\n");
}
while (*p);
gcry_free (buf);
}
- if (text)
+ else if (text)
log_printf ("\n");
}