home *** CD-ROM | disk | FTP | other *** search
- #include <string.h>
-
- #include "DeskLib:File.h"
- #include "DeskLib:LinkList.h"
-
- #include "Shell.TextRect.h"
- #include "Shell.Printf.h"
-
- /*#define HEAPGRAPH*/
- #include "HeapGraph.HeapGraph.h"
-
- #include "Structs.h"
- #include "ScanFile.h"
- #include "StartApp.h"
- #include "AddBlock.h"
- #include "MoveBlock.h"
- #include "RemoveBloc.h"
- #include "StatDispl.h"
-
- #define BUFFERLEN 256
- #define code_MAXLENGTH (4*3+1)
-
- /*char HeapGraph_filename[ 256];*/
- /* This is only included here because when amu-ing a ddt version */
- /* of this program, the linker expects every extern to be present. */
- /* In HeapGraph.h, HeapGraph_filename is declared, but !HeapDisp isn't */
- /* linked with HeapGraph, so we need to make our own HeapGraph_filename */
-
- void ReadFromFile(
- file_handle file, const char *filename, int filelen, apps_anchorblock *apps
- )
- {
- app_block *app;
- char buffer[ 1+BUFFERLEN];
- int bufferpos;
- BOOL statschanged = FALSE;
- UNUSED( filelen);
-
- /*Shell_Printf( "Reading from file '%s', file handle %i\n", filename, file);*/
-
- for ( app=LinkList_FirstItem( &apps->anchor); app; app = LinkList_NextItem( app)) {
- if ( !strcmp( app->filename, filename)) break;
- }
-
- if (!app) app = StartApp( filename, apps);
-
-
- bufferpos = 0;
- for(;;) {
- int byte = File_ReadByte( file);
- /*Shell_Printf( "Read byte %i, file_lasterror=%p\n", byte, file_lasterror);*/
-
- if (file_lasterror) break;
-
- if ( byte==HeapGraph_COLOUR) { /* Code used by ACELib to change colour of */
- File_ReadByte( file); /* text. Not possible with Shell. */
- }
-
- if ( byte==HeapGraph_MALLOC) {
- int pos = File_ReadInt( file);
- int size = File_ReadInt( file);
- int ref = File_ReadInt( file);
- if (!file_lasterror && pos) {
- AddBlock( app, pos, size, ref);
- statschanged = TRUE;
- /*Shell_TextRectPrintf( app->textrect, "MALLOC\n");*/
- }
- }
-
- else if ( byte==HeapGraph_REALLOC) {
- int oldpos = File_ReadInt( file);
- int newpos = File_ReadInt( file);
- int newsize = File_ReadInt( file);
- if (!file_lasterror && newpos) {
- if ( oldpos != 0) MoveBlock( app, oldpos, newpos, newsize);
- else AddBlock( app, newpos, newsize, 0);
- statschanged = TRUE;
- /*Shell_TextRectPrintf( app->textrect, "REALLOC\n");*/
- }
- }
-
- else if ( byte==HeapGraph_FREE) {
- int oldpos = File_ReadInt( file);
- if (!file_lasterror) {
- if ( oldpos != 0) RemoveBlock( app, oldpos);
- statschanged = TRUE;
- /*Shell_TextRectPrintf( app->textrect, "FREE\n");*/
- }
- }
-
- else {
- buffer[ bufferpos++] = byte;
- if ( bufferpos == BUFFERLEN) {
- buffer[ bufferpos] = 0;
- Shell_TextRectPrint( app->textrect, buffer);
- bufferpos = 0;
- }
- }
- }
-
- buffer[ bufferpos] = 0;
- if ( bufferpos>0) buffer[ bufferpos-1] = 0; /* Last chr from File_ReadInt is rubbish*/
- Shell_TextRectPrint( app->textrect, buffer);
- /*fprintf( stderr, buffer);*/
- if ( statschanged) UpdateAppStatsDisplay( app);
- return;
- }
-
-