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 #if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE)) 19 using namespace std; 20 #else 21 #define std 22 #endif 23 24 void write_debug_stream(const char *format, ...) 25 { 26 va_list ap; 27 va_start(ap, format); 28 FILE *f = fopen("/boot/home/libprint.log", "aw+"); 29 vfprintf(f, format, ap); 30 fclose(f); 31 va_end(ap); 32 } 33 34 35 void DUMP_BFILE(BFile *in, const char *path) 36 { 37 off_t size; 38 if (B_NO_ERROR == in->GetSize(&size)) { 39 uchar *buffer = new uchar[size]; 40 in->Read(buffer, size); 41 BFile out(path, B_WRITE_ONLY | B_CREATE_FILE); 42 out.Write(buffer, size); 43 in->Seek(0, SEEK_SET); 44 delete [] buffer; 45 } 46 } 47 48 49 void DUMP_BMESSAGE(BMessage *msg) 50 { 51 uint32 i; 52 int32 j; 53 char *name = ""; 54 uint32 type = 0; 55 int32 count = 0; 56 57 DBGMSG(("\t************ START - DUMP BMessage ***********\n")); 58 DBGMSG(("\taddress: 0x%x\n", (int)msg)); 59 if (!msg) 60 return; 61 62 // DBGMSG(("\tmsg->what: 0x%x\n", msg->what)); 63 DBGMSG(("\tmsg->what: %c%c%c%c\n", 64 *((char *)&msg->what + 3), 65 *((char *)&msg->what + 2), 66 *((char *)&msg->what + 1), 67 *((char *)&msg->what + 0))); 68 69 for (i= 0; msg->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i++) { 70 switch (type) { 71 case B_BOOL_TYPE: 72 for (j = 0; j < count; j++) { 73 bool aBool; 74 aBool = msg->FindBool(name, j); 75 DBGMSG(("\t%s, B_BOOL_TYPE[%d]: %s\n", 76 name, j, aBool ? "true" : "false")); 77 } 78 break; 79 80 case B_INT8_TYPE: 81 for (j = 0; j < count; j++) { 82 int8 anInt8; 83 msg->FindInt8(name, j, &anInt8); 84 DBGMSG(("\t%s, B_INT8_TYPE[%d]: %d\n", name, j, (int)anInt8)); 85 } 86 break; 87 88 case B_INT16_TYPE: 89 for (j = 0; j < count; j++) { 90 int16 anInt16; 91 msg->FindInt16(name, j, &anInt16); 92 DBGMSG(("\t%s, B_INT16_TYPE[%d]: %d\n", name, j, (int)anInt16)); 93 } 94 break; 95 96 case B_INT32_TYPE: 97 for (j = 0; j < count; j++) { 98 int32 anInt32; 99 msg->FindInt32(name, j, &anInt32); 100 DBGMSG(("\t%s, B_INT32_TYPE[%d]: %d\n", name, j, (int)anInt32)); 101 } 102 break; 103 104 case B_INT64_TYPE: 105 for (j = 0; j < count; j++) { 106 int64 anInt64; 107 msg->FindInt64(name, j, &anInt64); 108 DBGMSG(("\t%s, B_INT64_TYPE[%d]: %d\n", name, j, (int)anInt64)); 109 } 110 break; 111 112 case B_FLOAT_TYPE: 113 for (j = 0; j < count; j++) { 114 float aFloat; 115 msg->FindFloat(name, j, &aFloat); 116 DBGMSG(("\t%s, B_FLOAT_TYPE[%d]: %f\n", name, j, aFloat)); 117 } 118 break; 119 120 case B_DOUBLE_TYPE: 121 for (j = 0; j < count; j++) { 122 double aDouble; 123 msg->FindDouble(name, j, &aDouble); 124 DBGMSG(("\t%s, B_DOUBLE_TYPE[%d]: %f\n", name, j, (float)aDouble)); 125 } 126 break; 127 128 case B_STRING_TYPE: 129 for (j = 0; j < count; j++) { 130 const char *string; 131 msg->FindString(name, j, &string); 132 DBGMSG(("\t%s, B_STRING_TYPE[%d]: %s\n", name, j, string)); 133 } 134 break; 135 136 case B_POINT_TYPE: 137 for (j = 0; j < count; j++) { 138 BPoint aPoint; 139 msg->FindPoint(name, j, &aPoint); 140 DBGMSG(("\t%s, B_POINT_TYPE[%d]: %f, %f\n", 141 name, j, aPoint.x, aPoint.y)); 142 } 143 break; 144 145 case B_RECT_TYPE: 146 for (j = 0; j < count; j++) { 147 BRect aRect; 148 msg->FindRect(name, j, &aRect); 149 DBGMSG(("\t%s, B_RECT_TYPE[%d]: %f, %f, %f, %f\n", 150 name, j, aRect.left, aRect.top, aRect.right, aRect.bottom)); 151 } 152 break; 153 154 case B_REF_TYPE: 155 case B_MESSAGE_TYPE: 156 case B_MESSENGER_TYPE: 157 case B_POINTER_TYPE: 158 DBGMSG(("\t%s, 0x%x, count: %d\n", 159 name ? name : "(null)", type, count)); 160 break; 161 default: 162 DBGMSG(("\t%s, 0x%x, count: %d\n", 163 name ? name : "(null)", type, count)); 164 break; 165 } 166 167 name = ""; 168 type = 0; 169 count = 0; 170 } 171 DBGMSG(("\t************ END - DUMP BMessage ***********\n")); 172 } 173 174 #define PD_DRIVER_NAME "Driver Name" 175 #define PD_PRINTER_NAME "Printer Name" 176 #define PD_COMMENTS "Comments" 177 178 void DUMP_BDIRECTORY(BDirectory *dir) 179 { 180 DUMP_BNODE(dir); 181 } 182 183 void DUMP_BNODE(BNode *dir) 184 { 185 char buffer1[256]; 186 char buffer2[256]; 187 attr_info info; 188 int32 i; 189 float f; 190 BRect rc; 191 bool b; 192 193 DBGMSG(("\t************ STRAT - DUMP BNode ***********\n")); 194 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; 231 } 232 } 233 234 DBGMSG(("\t************ END - DUMP BNode ***********\n")); 235 } 236 237 #endif /* DBG */ 238