/******************************************************************************* ** ** gcoDUMP_FrameEnd ** ** Mark the end of a frame. ** ** INPUT: ** ** gcoDUMP Dump ** Pointer to a gcoDUMP object. ** ** OUTPUT: ** ** Nothing. */ gceSTATUS gcoDUMP_FrameEnd( IN gcoDUMP Dump ) { gceSTATUS status; gcsDUMP_DATA header; gctUINT32 pos; gcmHEADER_ARG("Dump=0x%x", Dump); /* Verify the arguments. */ gcmVERIFY_OBJECT(Dump, gcvOBJ_DUMP); if (Dump->file == gcvNULL) { /* There is no open dump file. */ gcmFOOTER_NO(); return gcvSTATUS_OK; } do { /* Get the current position. */ gcmERR_BREAK(gcoOS_GetPos(gcvNULL, Dump->file, &pos)); /* Seek to the beginning of the frame. */ gcmERR_BREAK(gcoOS_SetPos(gcvNULL, Dump->file, Dump->frameStart)); /* Make sure we got the right byte count. */ gcmASSERT(pos - Dump->frameStart == Dump->frameLength + sizeof(header)); /* Update the frame header. */ header.type = gcvTAG_FRAME; header.length = Dump->frameLength; header.address = ++ Dump->frameCount; gcmERR_BREAK(gcoOS_Write(gcvNULL, Dump->file, sizeof(header), &header)); /* Seek to the end of the file. */ gcmERR_BREAK(gcoOS_SetPos(gcvNULL, Dump->file, pos)); /* Mark the frame as ended. */ Dump->frameStart = 0; } while (gcvFALSE); /* Return the status. */ gcmFOOTER(); return status; }
static gctBOOL ReadSource( IN gcoOS Os, IN gctCONST_STRING FileName, OUT gctSIZE_T * SourceSize, OUT gctSTRING * Source ) { gceSTATUS status; gctFILE file; gctUINT32 count; gctSIZE_T byteRead; gctSTRING source; gcmASSERT(FileName); status = gcoOS_Open(Os, FileName, gcvFILE_READ, &file); if (gcmIS_ERROR(status)) { printf("*ERROR* Failed to open input file: %s\n", FileName); return gcvFALSE; } gcmVERIFY_OK(gcoOS_Seek(Os, file, 0, gcvFILE_SEEK_END)); gcmVERIFY_OK(gcoOS_GetPos(Os, file, &count)); status = gcoOS_Allocate(Os, count + 1, (gctPOINTER *) &source); if (!gcmIS_SUCCESS(status)) { printf("*ERROR* Not enough memory\n"); gcmVERIFY_OK(gcoOS_Close(Os, file)); return gcvFALSE; } gcmVERIFY_OK(gcoOS_SetPos(Os, file, 0)); status = gcoOS_Read(Os, file, count, source, &byteRead); if (!gcmIS_SUCCESS(status) || byteRead != count) { printf("*ERROR* Failed to open input file: %s\n", FileName); gcmVERIFY_OK(gcoOS_Close(Os, file)); return gcvFALSE; } source[count] = '\0'; gcmVERIFY_OK(gcoOS_Close(Os, file)); *SourceSize = count; *Source = source; return gcvTRUE; }
/******************************************************************************* ** ** gcoDUMP_Control ** ** Control dumping. ** ** INPUT: ** ** gcoDUMP Dump ** Pointer to a gcoDUMP object. ** ** gctSTRING FileName ** If 'FileName' is not gcvNULL, it points to the filename to be used for ** capturing all data. If 'FileName' is gcvNULL, turn off any current ** capturing. ** ** OUTPUT: ** ** Nothing. */ gceSTATUS gcoDUMP_Control( IN gcoDUMP Dump, IN gctSTRING FileName ) { gceSTATUS status = gcvSTATUS_OK; gcsDUMP_FILE header; gctUINT32 pos; gcmHEADER_ARG("Dump=0x%x FileName=0x%x", Dump, FileName); /* Verify the arguments. */ gcmVERIFY_OBJECT(Dump, gcvOBJ_DUMP); do { if (FileName != gcvNULL) { /* Need to create a new dump file. */ if (Dump->file == gcvNULL) { /* Create the dump file. */ gcmERR_BREAK(gcoOS_Open(gcvNULL, FileName, gcvFILE_CREATE, &Dump->file)); /* Write the file header. */ header.signature = gcvDUMP_FILE_SIGNATURE; header.length = Dump->length = 0; header.frames = Dump->frameCount = 0; gcmERR_BREAK(gcoOS_Write(gcvNULL, Dump->file, sizeof(header), &header)); /* Frame is not yet started. */ Dump->frameStart = 0; } } else { /* Need to close any current dump file. */ if (Dump->file != gcvNULL) { /* Close any open frame. */ if (Dump->frameStart != 0) { gcoDUMP_FrameEnd(Dump); gcoDUMP_FrameBegin(Dump); } /* Get the current position. */ gcmERR_BREAK(gcoOS_GetPos(gcvNULL, Dump->file, &pos)); /* Seek to the beginnnig of the file. */ gcmERR_BREAK(gcoOS_SetPos(gcvNULL, Dump->file, 0)); /* Make sure we have the correct size. */ gcmASSERT(pos == Dump->length + sizeof(header)); /* Update the file header. */ header.signature = gcvDUMP_FILE_SIGNATURE; header.length = Dump->length; header.frames = Dump->frameCount; gcmERR_BREAK(gcoOS_Write(gcvNULL, Dump->file, sizeof(header), &header)); /* Seek to the end of the file. */ gcmERR_BREAK(gcoOS_SetPos(gcvNULL, Dump->file, pos)); /* Close the file. */ gcmERR_BREAK(gcoOS_Close(gcvNULL, Dump->file)); /* Mark the file as closed. */ Dump->file = gcvNULL; } } } while (gcvFALSE); /* Return the status. */ gcmFOOTER(); return status; }