FIX: NOBUG_LOG env parsing error
[nobug.git] / doc / dumpexample.txt
blob07c09188872ddd97a10f7bd990b54dbf9533b10c
1 PARA How to use the DUMP facilities;;
3 [source,c]
4 -------------------------------------------------------
5 struct STRUCTNAME
7   int INTEGER_MEMBER;
8   char * STRING_MEMBER;
9   struct STRUCTNAME* next;
11 -------------------------------------------------------
13 Thereafter, define a funcion as follows:
15 [source,c]
16 -------------------------------------------------------
17 void
18 nobug_STRUCTNAME_dump (const struct STRUCTNAME* self,
19                        const int depth,
20                        const struct nobug_context context,
21                        void* extra)
23   /* check for self != NULL and that the depth limit
24      was not exceeded in recursive data structures */
25   if (self && depth)
26   {
27     /* you may or may not do something with the extra
28        parameter here, extra is transparently
29        passed around */
30     (void) extra;
32     /* use DUMP_LOG not LOG to print the data */
33     DUMP_LOG("STRUCTNAME %p: int is %d, string is %s", self,
34                              self->INTEGER_MEMBER,
35                              self->STRING_MEMBER);
37     /* now recurse while decrementing depth */
38     nobug_STRUCTNAME_dump (self->next,
39                            depth-1,
40                            context,
41                            extra);
42   }
44 -------------------------------------------------------
46 Now you can use the DUMP() macros within the code
48 [source,c]
49 -------------------------------------------------------
50 example()
52   struct STRUCTNAME foo;
53   init(&foo);
55   /* extra can be anything,
56      NULL is suggested when you don't use it */
57   DUMP (my_flag, STRUCTNAME, &foo, 2, NULL);
59 -------------------------------------------------------