| 302 | } |
| 303 | |
| 304 | bool DbgFileView::openFile(const char *fileName) |
| 305 | { |
| 306 | if ((! fileName) || (! fileName[0])) |
| 307 | return false; |
| 308 | |
| 309 | StringTableEntry newFile = StringTable->insert(fileName); |
| 310 | if (mFileName == newFile) |
| 311 | return true; |
| 312 | |
| 313 | void *data = NULL; |
| 314 | U32 dataSize = 0; |
| 315 | Torque::FS::ReadFile(fileName, data, dataSize, true); |
| 316 | if(data == NULL) |
| 317 | { |
| 318 | Con::printf("DbgFileView: unable to open file %s.", fileName); |
| 319 | return false; |
| 320 | } |
| 321 | |
| 322 | //copy the file name |
| 323 | mFileName = newFile; |
| 324 | |
| 325 | //clear the old mFileView |
| 326 | clear(); |
| 327 | setSize(Point2I(1, 0)); |
| 328 | |
| 329 | //begin reading and parsing at each '\n' |
| 330 | char *parsePtr = (char *)data; |
| 331 | for(;;) { |
| 332 | char *tempPtr = dStrchr(parsePtr, '\n'); |
| 333 | if(tempPtr) |
| 334 | addLine(parsePtr, tempPtr - parsePtr); |
| 335 | else if(parsePtr[0]) |
| 336 | addLine(parsePtr, dStrlen(parsePtr)); |
| 337 | if(!tempPtr) |
| 338 | break; |
| 339 | parsePtr = tempPtr + 1; |
| 340 | } |
| 341 | //delete the buffer |
| 342 | delete [] static_cast<char*>(data); |
| 343 | |
| 344 | //set the file size |
| 345 | AdjustCellSize(); |
| 346 | setSize(Point2I(1, mFileView.size())); |
| 347 | |
| 348 | return true; |
| 349 | } |
| 350 | |
| 351 | void DbgFileView::scrollToLine(S32 lineNumber) |
| 352 | { |