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