xref: /dragonfly/usr.sbin/installer/libdfui/dump.c (revision 91dc43dd)
1 /*
2  * Copyright (c)2004 Cat's Eye Technologies.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  *   Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  *
11  *   Redistributions in binary form must reproduce the above copyright
12  *   notice, this list of conditions and the following disclaimer in
13  *   the documentation and/or other materials provided with the
14  *   distribution.
15  *
16  *   Neither the name of Cat's Eye Technologies nor the names of its
17  *   contributors may be used to endorse or promote products derived
18  *   from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31  * OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * dump.c
36  * $Id: dump.c,v 1.5 2005/02/06 19:53:19 cpressey Exp $
37  * Debugging functions for libdfui.
38  * These functions are just stubs when libdfui is built without DEBUG.
39  */
40 
41 #include <stdarg.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 
45 #define NEEDS_DFUI_STRUCTURE_DEFINITIONS
46 #include "dfui.h"
47 #undef NEEDS_DFUI_STRUCTURE_DEFINITIONS
48 #include "dump.h"
49 
50 FILE *dfui_debug_file;
51 
52 #ifdef DEBUG
53 #define __debug_only
54 #else
55 #define __debug_only __unused
56 #endif
57 
58 void
59 dfui_info_dump(const struct dfui_info *info __debug_only)
60 {
61 #ifdef DEBUG
62 	fprintf(dfui_debug_file, "+ INFO:\n");
63 	if (info == NULL) {
64 		fprintf(dfui_debug_file, "  *NULL*");
65 		return;
66 	}
67 	fprintf(dfui_debug_file, "  name:       %s\n", info->name);
68 	fprintf(dfui_debug_file, "  short_desc: %s\n", info->short_desc);
69 	fprintf(dfui_debug_file, "  long_desc:  %s\n", info->long_desc);
70 #endif
71 }
72 
73 void
74 dfui_option_dump(const struct dfui_option *o __debug_only)
75 {
76 #ifdef DEBUG
77 	fprintf(dfui_debug_file, "+ OPTION:\n");
78 	if (o == NULL) {
79 		fprintf(dfui_debug_file, "  *NULL*");
80 		return;
81 	}
82 	fprintf(dfui_debug_file, "value: %s\n", o->value);
83 #endif
84 }
85 
86 void
87 dfui_field_dump(const struct dfui_field *fi __debug_only)
88 {
89 #ifdef DEBUG
90 	struct dfui_option *o;
91 
92 	fprintf(dfui_debug_file, "+ FIELD:\n");
93 	if (fi == NULL) {
94 		fprintf(dfui_debug_file, "  *NULL*");
95 		return;
96 	}
97 	fprintf(dfui_debug_file, "id: %s\n", fi->id);
98 	dfui_info_dump(fi->info);
99 	for (o = fi->option_head; o != NULL; o = o->next) {
100 		dfui_option_dump(o);
101 	}
102 #endif
103 }
104 
105 void
106 dfui_action_dump(const struct dfui_action *a __debug_only)
107 {
108 #ifdef DEBUG
109 	fprintf(dfui_debug_file, "+ ACTION:\n");
110 	if (a == NULL) {
111 		fprintf(dfui_debug_file, "  *NULL*");
112 		return;
113 	}
114 	fprintf(dfui_debug_file, "id: %s\n", a->id);
115 	dfui_info_dump(a->info);
116 	/* parameters */
117 #endif
118 }
119 
120 void
121 dfui_celldata_dump(const struct dfui_celldata *c __debug_only)
122 {
123 #ifdef DEBUG
124 	if (c == NULL) {
125 		fprintf(dfui_debug_file, "*NULL* ");
126 		return;
127 	}
128 	fprintf(dfui_debug_file, "{%s = %s}", c->field_id, c->value);
129 #endif
130 }
131 
132 void
133 dfui_dataset_dump(const struct dfui_dataset *ds __debug_only)
134 {
135 #ifdef DEBUG
136 	struct dfui_celldata *c;
137 
138 	fprintf(dfui_debug_file, "+ DATASET:\n");
139 	if (ds == NULL) {
140 		fprintf(dfui_debug_file, "  *NULL*");
141 		return;
142 	}
143 
144 	for (c = ds->celldata_head; c != NULL; c = c->next) {
145 		dfui_celldata_dump(c);
146 	}
147 	fprintf(dfui_debug_file, "\n");
148 #endif
149 }
150 
151 
152 void
153 dfui_form_dump(const struct dfui_form *f __debug_only)
154 {
155 #ifdef DEBUG
156 	struct dfui_field *fi;
157 	struct dfui_action *a;
158 	struct dfui_dataset *ds;
159 
160 	fprintf(dfui_debug_file, "FORM ------\n");
161 	if (f == NULL) {
162 		fprintf(dfui_debug_file, "*NULL*");
163 		return;
164 	}
165 
166 	fprintf(dfui_debug_file, "id: %s\n", f->id);
167 	dfui_info_dump(f->info);
168 
169 	fprintf(dfui_debug_file, "multiple: %d\n", f->multiple);
170 	fprintf(dfui_debug_file, "extensible: %d\n", f->extensible);
171 
172 	for (fi = f->field_head; fi != NULL; fi = fi->next) {
173 		dfui_field_dump(fi);
174 	}
175 	for (a = f->action_head; a != NULL; a = a->next) {
176 		dfui_action_dump(a);
177 	}
178 	for (ds = f->dataset_head; ds != NULL; ds = ds->next) {
179 		dfui_dataset_dump(ds);
180 	}
181 #endif
182 }
183 
184 void
185 dfui_response_dump(const struct dfui_response *r __debug_only)
186 {
187 #ifdef DEBUG
188 	struct dfui_dataset *ds;
189 
190 	fprintf(dfui_debug_file, "RESPONSE ------\n");
191 	if (r == NULL) {
192 		fprintf(dfui_debug_file, "*NULL*");
193 		return;
194 	}
195 	fprintf(dfui_debug_file, "form id: %s\n", r->form_id);
196 	fprintf(dfui_debug_file, "action id: %s\n", r->action_id);
197 
198 	for (ds = r->dataset_head; ds != NULL; ds = ds->next) {
199 		dfui_dataset_dump(ds);
200 	}
201 #endif
202 }
203 
204 void
205 dfui_progress_dump(const struct dfui_progress *pr __debug_only)
206 {
207 #ifdef DEBUG
208 	fprintf(dfui_debug_file, "PROGRESS ------\n");
209 	if (pr == NULL) {
210 		fprintf(dfui_debug_file, "*NULL*");
211 		return;
212 	}
213 
214 	/* fprintf(dfui_debug_file, "id: %s\n", pr->id); */
215 	dfui_info_dump(pr->info);
216 
217 	fprintf(dfui_debug_file, "amount: %d\n", pr->amount);
218 #endif
219 }
220 
221 void
222 dfui_debug(const char *fmt __debug_only, ...)
223 {
224 #ifdef DEBUG
225 	va_list args;
226 
227 	va_start(args, fmt);
228 	vfprintf(dfui_debug_file, fmt, args);
229 	va_end(args);
230 #endif
231 }
232