bin/pc: Mark non-returning function as void
[haiku.git] / src / add-ons / print / transports / shared / DbgMsg.cpp
blob726eb5115629e0be16c8cacd770daba12fc69667
1 // Sun, 18 Jun 2000
2 // Y.Takagi
4 #include <cstdio>
5 #include <cstdarg>
7 #include <Message.h>
8 #include <File.h>
9 #include <Directory.h>
10 #include <fs_attr.h>
12 #include "DbgMsg.h"
14 #ifdef _DEBUG
16 #if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE))
17 using namespace std;
18 #else
19 #define std
20 #endif
22 void write_debug_stream(const char *format, ...)
24 va_list ap;
25 va_start(ap, format);
26 FILE *f = fopen("/boot/home/transport.log", "aw+");
27 vfprintf(f, format, ap);
28 fclose(f);
29 va_end(ap);
33 void DUMP_BFILE(BFile *in, const char *path)
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;
47 void DUMP_BMESSAGE(BMessage *msg)
49 uint32 i;
50 int32 j;
51 char *name = "";
52 uint32 type = 0;
53 int32 count = 0;
55 DBGMSG(("\t************ START - DUMP BMessage ***********\n"));
56 DBGMSG(("\taddress: 0x%x\n", (int)msg));
57 if (!msg)
58 return;
60 #if (!__MWERKS__)
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 #else
67 DBGMSG(("\tmsg->what: %c%c%c%c\n",
68 *((char *)&msg->what + 0),
69 *((char *)&msg->what + 1),
70 *((char *)&msg->what + 2),
71 *((char *)&msg->what + 3)));
72 #endif
74 for (i= 0; msg->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i++) {
75 switch (type) {
76 case B_BOOL_TYPE:
77 for (j = 0; j < count; j++) {
78 bool aBool;
79 aBool = msg->FindBool(name, j);
80 DBGMSG(("\t%s, B_BOOL_TYPE[%d]: %s\n",
81 name, j, aBool ? "true" : "false"));
83 break;
85 case B_INT8_TYPE:
86 for (j = 0; j < count; j++) {
87 int8 anInt8;
88 msg->FindInt8(name, j, &anInt8);
89 DBGMSG(("\t%s, B_INT8_TYPE[%d]: %d\n", name, j, (int)anInt8));
91 break;
93 case B_INT16_TYPE:
94 for (j = 0; j < count; j++) {
95 int16 anInt16;
96 msg->FindInt16(name, j, &anInt16);
97 DBGMSG(("\t%s, B_INT16_TYPE[%d]: %d\n", name, j, (int)anInt16));
99 break;
101 case B_INT32_TYPE:
102 for (j = 0; j < count; j++) {
103 int32 anInt32;
104 msg->FindInt32(name, j, &anInt32);
105 DBGMSG(("\t%s, B_INT32_TYPE[%d]: %d\n", name, j, (int)anInt32));
107 break;
109 case B_INT64_TYPE:
110 for (j = 0; j < count; j++) {
111 int64 anInt64;
112 msg->FindInt64(name, j, &anInt64);
113 DBGMSG(("\t%s, B_INT64_TYPE[%d]: %d\n", name, j, (int)anInt64));
115 break;
117 case B_FLOAT_TYPE:
118 for (j = 0; j < count; j++) {
119 float aFloat;
120 msg->FindFloat(name, j, &aFloat);
121 DBGMSG(("\t%s, B_FLOAT_TYPE[%d]: %f\n", name, j, aFloat));
123 break;
125 case B_DOUBLE_TYPE:
126 for (j = 0; j < count; j++) {
127 double aDouble;
128 msg->FindDouble(name, j, &aDouble);
129 DBGMSG(("\t%s, B_DOUBLE_TYPE[%d]: %f\n", name, j, (float)aDouble));
131 break;
133 case B_STRING_TYPE:
134 for (j = 0; j < count; j++) {
135 const char *string;
136 msg->FindString(name, j, &string);
137 DBGMSG(("\t%s, B_STRING_TYPE[%d]: %s\n", name, j, string));
139 break;
141 case B_POINT_TYPE:
142 for (j = 0; j < count; j++) {
143 BPoint aPoint;
144 msg->FindPoint(name, j, &aPoint);
145 DBGMSG(("\t%s, B_POINT_TYPE[%d]: %f, %f\n",
146 name, j, aPoint.x, aPoint.y));
148 break;
150 case B_RECT_TYPE:
151 for (j = 0; j < count; j++) {
152 BRect aRect;
153 msg->FindRect(name, j, &aRect);
154 DBGMSG(("\t%s, B_RECT_TYPE[%d]: %f, %f, %f, %f\n",
155 name, j, aRect.left, aRect.top, aRect.right, aRect.bottom));
157 break;
159 case B_REF_TYPE:
160 case B_MESSAGE_TYPE:
161 case B_MESSENGER_TYPE:
162 case B_POINTER_TYPE:
163 DBGMSG(("\t%s, 0x%x, count: %d\n",
164 name ? name : "(null)", type, count));
165 break;
166 default:
167 DBGMSG(("\t%s, 0x%x, count: %d\n",
168 name ? name : "(null)", type, count));
169 break;
172 name = "";
173 type = 0;
174 count = 0;
176 DBGMSG(("\t************ END - DUMP BMessage ***********\n"));
179 #define PD_DRIVER_NAME "Driver Name"
180 #define PD_PRINTER_NAME "Printer Name"
181 #define PD_COMMENTS "Comments"
183 void DUMP_BDIRECTORY(BDirectory *dir)
185 char buffer1[256];
186 char buffer2[256];
187 attr_info info;
188 int32 i;
189 float f;
190 BRect rc;
191 bool b;
193 DBGMSG(("\t************ STRAT - DUMP BDirectory ***********\n"));
195 dir->RewindAttrs();
196 while (dir->GetNextAttrName(buffer1) == B_NO_ERROR) {
197 dir->GetAttrInfo(buffer1, &info);
198 switch (info.type) {
199 case B_ASCII_TYPE:
200 dir->ReadAttr(buffer1, info.type, 0, buffer2, sizeof(buffer2));
201 DBGMSG(("\t%s, B_ASCII_TYPE: %s\n", buffer1, buffer2));
202 break;
203 case B_STRING_TYPE:
204 dir->ReadAttr(buffer1, info.type, 0, buffer2, sizeof(buffer2));
205 DBGMSG(("\t%s, B_STRING_TYPE: %s\n", buffer1, buffer2));
206 break;
207 case B_INT32_TYPE:
208 dir->ReadAttr(buffer1, info.type, 0, &i, sizeof(i));
209 DBGMSG(("\t%s, B_INT32_TYPE: %d\n", buffer1, i));
210 break;
211 case B_FLOAT_TYPE:
212 dir->ReadAttr(buffer1, info.type, 0, &f, sizeof(f));
213 DBGMSG(("\t%s, B_FLOAT_TYPE: %f\n", buffer1, f));
214 break;
215 case B_RECT_TYPE:
216 dir->ReadAttr(buffer1, info.type, 0, &rc, sizeof(rc));
217 DBGMSG(("\t%s, B_RECT_TYPE: %f, %f, %f, %f\n", buffer1, rc.left, rc.top, rc.right, rc.bottom));
218 break;
219 case B_BOOL_TYPE:
220 dir->ReadAttr(buffer1, info.type, 0, &b, sizeof(b));
221 DBGMSG(("\t%s, B_BOOL_TYPE: %d\n", buffer1, (int)b));
222 break;
223 default:
224 DBGMSG(("\t%s, %c%c%c%c\n",
225 buffer1,
226 *((char *)&info.type + 3),
227 *((char *)&info.type + 2),
228 *((char *)&info.type + 1),
229 *((char *)&info.type + 0)));
230 break;
234 DBGMSG(("\t************ END - DUMP BDirectory ***********\n"));
237 #endif /* _DEBUG */