xref: /haiku/src/libs/print/libprint/DbgMsg.cpp (revision 579f1dbca962a2a03df54f69fdc6e9423f91f20e)
1 /*
2  * DbgMsg.cpp
3  * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
4  */
5 
6 #include <cstdio>
7 #include <cstdarg>
8 
9 #include <Message.h>
10 #include <File.h>
11 #include <Directory.h>
12 #include <fs_attr.h>
13 
14 #include "DbgMsg.h"
15 
16 #ifdef DBG
17 
18 
19 using namespace std;
20 
21 
22 void write_debug_stream(const char *format, ...)
23 {
24 	va_list	ap;
25 	va_start(ap, format);
26 	FILE *f = fopen("/boot/home/libprint.log", "aw+");
27 	vfprintf(f, format, ap);
28 	fclose(f);
29 	va_end(ap);
30 }
31 
32 
33 void DUMP_BFILE(BFile *in, const char *path)
34 {
35 	off_t size;
36 	if (B_NO_ERROR == in->GetSize(&size)) {
37 		uchar *buffer = new uchar[size];
38 		in->Read(buffer, size);
39 		BFile out(path, B_WRITE_ONLY | B_CREATE_FILE);
40 		out.Write(buffer, size);
41 		in->Seek(0, SEEK_SET);
42 		delete [] buffer;
43 	}
44 }
45 
46 
47 void DUMP_BMESSAGE(BMessage *msg)
48 {
49 	uint32 i;
50 	int32 j;
51 	char *name  = "";
52 	uint32 type = 0;
53 	int32 count = 0;
54 
55 	DBGMSG(("\t************ START - DUMP BMessage ***********\n"));
56 	DBGMSG(("\taddress: 0x%x\n", (int)msg));
57 	if (!msg)
58 		return;
59 
60 //	DBGMSG(("\tmsg->what: 0x%x\n", msg->what));
61 	DBGMSG(("\tmsg->what: %c%c%c%c\n",
62 		*((char *)&msg->what + 3),
63 		*((char *)&msg->what + 2),
64 		*((char *)&msg->what + 1),
65 		*((char *)&msg->what + 0)));
66 
67 	for (i= 0; msg->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i++) {
68 		switch (type) {
69 		case B_BOOL_TYPE:
70 			for (j = 0; j < count; j++) {
71 				bool aBool;
72 				aBool = msg->FindBool(name, j);
73 				DBGMSG(("\t%s, B_BOOL_TYPE[%d]: %s\n",
74 					name, j, aBool ? "true" : "false"));
75 			}
76 			break;
77 
78 		case B_INT8_TYPE:
79 			for (j = 0; j < count; j++) {
80 				int8 anInt8;
81 				msg->FindInt8(name, j, &anInt8);
82 				DBGMSG(("\t%s, B_INT8_TYPE[%d]: %d\n", name, j, (int)anInt8));
83 			}
84 			break;
85 
86 		case B_INT16_TYPE:
87 			for (j = 0; j < count; j++) {
88 				int16 anInt16;
89 				msg->FindInt16(name, j, &anInt16);
90 				DBGMSG(("\t%s, B_INT16_TYPE[%d]: %d\n", name, j, (int)anInt16));
91 			}
92 			break;
93 
94 		case B_INT32_TYPE:
95 			for (j = 0; j < count; j++) {
96 				int32 anInt32;
97 				msg->FindInt32(name, j, &anInt32);
98 				DBGMSG(("\t%s, B_INT32_TYPE[%d]: %d\n", name, j, (int)anInt32));
99 			}
100 			break;
101 
102 		case B_INT64_TYPE:
103 			for (j = 0; j < count; j++) {
104 				int64 anInt64;
105 				msg->FindInt64(name, j, &anInt64);
106 				DBGMSG(("\t%s, B_INT64_TYPE[%d]: %d\n", name, j, (int)anInt64));
107 			}
108 			break;
109 
110 		case B_FLOAT_TYPE:
111 			for (j = 0; j < count; j++) {
112 				float aFloat;
113 				msg->FindFloat(name, j, &aFloat);
114 				DBGMSG(("\t%s, B_FLOAT_TYPE[%d]: %f\n", name, j, aFloat));
115 			}
116 			break;
117 
118 		case B_DOUBLE_TYPE:
119 			for (j = 0; j < count; j++) {
120 				double aDouble;
121 				msg->FindDouble(name, j, &aDouble);
122 				DBGMSG(("\t%s, B_DOUBLE_TYPE[%d]: %f\n", name, j, (float)aDouble));
123 			}
124 			break;
125 
126 		case B_STRING_TYPE:
127 			for (j = 0; j < count; j++) {
128 				const char *string;
129 				msg->FindString(name, j, &string);
130 				DBGMSG(("\t%s, B_STRING_TYPE[%d]: %s\n", name, j, string));
131 			}
132 			break;
133 
134 		case B_POINT_TYPE:
135 			for (j = 0; j < count; j++) {
136 				BPoint aPoint;
137 				msg->FindPoint(name, j, &aPoint);
138 				DBGMSG(("\t%s, B_POINT_TYPE[%d]: %f, %f\n",
139 					name, j, aPoint.x, aPoint.y));
140 			}
141 			break;
142 
143 		case B_RECT_TYPE:
144 			for (j = 0; j < count; j++) {
145 				BRect aRect;
146 				msg->FindRect(name, j, &aRect);
147 				DBGMSG(("\t%s, B_RECT_TYPE[%d]: %f, %f, %f, %f\n",
148 					name, j, aRect.left, aRect.top, aRect.right, aRect.bottom));
149 			}
150 			break;
151 
152 		case B_REF_TYPE:
153 		case B_MESSAGE_TYPE:
154 		case B_MESSENGER_TYPE:
155 		case B_POINTER_TYPE:
156 			DBGMSG(("\t%s, 0x%x, count: %d\n",
157 				name ? name : "(null)", type, count));
158 			break;
159 		default:
160 			DBGMSG(("\t%s, 0x%x, count: %d\n",
161 				name ? name : "(null)", type, count));
162 			break;
163 		}
164 
165 		name  = "";
166 		type  = 0;
167 		count = 0;
168 	}
169 	DBGMSG(("\t************ END - DUMP BMessage ***********\n"));
170 }
171 
172 #define PD_DRIVER_NAME		"Driver Name"
173 #define PD_PRINTER_NAME		"Printer Name"
174 #define PD_COMMENTS			"Comments"
175 
176 void DUMP_BDIRECTORY(BDirectory *dir)
177 {
178 	DUMP_BNODE(dir);
179 }
180 
181 void DUMP_BNODE(BNode *dir)
182 {
183 	char buffer1[256];
184 	char buffer2[256];
185 	attr_info info;
186 	int32 i;
187 	float f;
188 	BRect rc;
189 	bool b;
190 
191 	DBGMSG(("\t************ STRAT - DUMP BNode ***********\n"));
192 
193 	dir->RewindAttrs();
194 	while (dir->GetNextAttrName(buffer1) == B_NO_ERROR) {
195 		dir->GetAttrInfo(buffer1, &info);
196 		switch (info.type) {
197 		case B_ASCII_TYPE:
198 			dir->ReadAttr(buffer1, info.type, 0, buffer2, sizeof(buffer2));
199 			DBGMSG(("\t%s, B_ASCII_TYPE: %s\n", buffer1, buffer2));
200 			break;
201 		case B_STRING_TYPE:
202 			dir->ReadAttr(buffer1, info.type, 0, buffer2, sizeof(buffer2));
203 			DBGMSG(("\t%s, B_STRING_TYPE: %s\n", buffer1, buffer2));
204 			break;
205 		case B_INT32_TYPE:
206 			dir->ReadAttr(buffer1, info.type, 0, &i, sizeof(i));
207 			DBGMSG(("\t%s, B_INT32_TYPE: %d\n", buffer1, i));
208 			break;
209 		case B_FLOAT_TYPE:
210 			dir->ReadAttr(buffer1, info.type, 0, &f, sizeof(f));
211 			DBGMSG(("\t%s, B_FLOAT_TYPE: %f\n", buffer1, f));
212 			break;
213 		case B_RECT_TYPE:
214 			dir->ReadAttr(buffer1, info.type, 0, &rc, sizeof(rc));
215 			DBGMSG(("\t%s, B_RECT_TYPE: %f, %f, %f, %f\n", buffer1, rc.left, rc.top, rc.right, rc.bottom));
216 			break;
217 		case B_BOOL_TYPE:
218 			dir->ReadAttr(buffer1, info.type, 0, &b, sizeof(b));
219 			DBGMSG(("\t%s, B_BOOL_TYPE: %d\n", buffer1, (int)b));
220 			break;
221 		default:
222 			DBGMSG(("\t%s, %c%c%c%c\n",
223 				buffer1,
224 				*((char *)&info.type + 3),
225 				*((char *)&info.type + 2),
226 				*((char *)&info.type + 1),
227 				*((char *)&info.type + 0)));
228 			break;
229 		}
230 	}
231 
232 	DBGMSG(("\t************ END - DUMP BNode ***********\n"));
233 }
234 
235 #endif	/* DBG */
236