[libgtop] When pretty-printing an array, don't display 0 elements.
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgtop] When pretty-printing an array, don't display 0 elements.
- Date: Thu, 25 Jun 2015 23:58:31 +0000 (UTC)
commit e2348c24a092717e424b3b031294b72d1df5aca1
Author: Benoit Dejean <bdejean gmail com>
Date: Sat Feb 28 02:27:52 2015 +0100
When pretty-printing an array, don't display 0 elements.
examples/pprint.c | 23 +++++++++++++++--------
1 files changed, 15 insertions(+), 8 deletions(-)
---
diff --git a/examples/pprint.c b/examples/pprint.c
index c8f80b3..ae018ea 100644
--- a/examples/pprint.c
+++ b/examples/pprint.c
@@ -21,14 +21,21 @@
#define PPRINT(DATA, FORMAT) printf("\t%4lu B %3lu " #DATA " = " FORMAT "\n", \
(unsigned long) sizeof buf.DATA, (unsigned long) buf_offsetof(DATA), buf.DATA)
-#define PPRINT_ARRAY(ARRAY, SIZE, FORMAT) do { \
-size_t i; \
-printf("\t%4lu B %3lu " #ARRAY "[%lu] = { ", \
-(unsigned long) sizeof buf.ARRAY, (unsigned long) buf_offsetof(ARRAY),\
-(unsigned long) G_N_ELEMENTS(buf.ARRAY)); \
-for(i = 0; i < (SIZE - 1); ++i) printf(".%u = " FORMAT ", ", i, buf.ARRAY[i]); \
-printf(".%u = " FORMAT " }\n", SIZE - 1 , buf.ARRAY[SIZE - 1]); \
-} while(0)
+#define PPRINT_ARRAY(ARRAY, SIZE, FORMAT) do { \
+ size_t i; \
+ printf("\t%4lu B %3lu " #ARRAY "[%lu] = { ", \
+ (unsigned long) sizeof buf.ARRAY, \
+ (unsigned long) buf_offsetof(ARRAY), \
+ (unsigned long) G_N_ELEMENTS(buf.ARRAY)); \
+ for (i = 0; i < (SIZE); ++i) { \
+ printf(".%u = " FORMAT ", ", i, buf.ARRAY[i]); \
+ if (!buf.ARRAY[i] && i < (SIZE - 1) && !buf.ARRAY[i + 1]) { \
+ do { i++; } while (i < SIZE && !buf.ARRAY[i]); \
+ printf("..., "); \
+ } \
+ } \
+ printf("}\n"); \
+ } while(0)
#define PPRINT_ENTRY_ARRAY(ARRAY, SIZE) do { \
size_t i; \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]