Mercurial > hg > Members > koba > t_dandy
view trace.c @ 55:2c33aa6a4a37
debug global_alloc.but new bugs appear
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 28 Jan 2011 19:05:00 +0900 |
parents | 56ef94618a0e |
children | 6cfd912a602d |
line wrap: on
line source
#include <stdio.h> #include "trace.h" static FILE *fileptr; const char *filename; void pad_trace(unsigned int pad) { fprintf(fileptr, "%d\n", pad); } int PadfileOpen(const char* name) { filename = name; fileptr = fopen(filename, "rb+"); if (!fileptr) { fileptr = fopen(filename, "wb+"); if (!fileptr) { printf("can't open output file.\n"); return 0; } } return 1; } void PadfileRead(TraceBuffPtr buff) { TraceBuffPtr tmp = buff; fread(buff->cappad, sizeof(SGO_PAD), PAD_BUFSIZE, fileptr); while (!feof(fileptr)) { TraceBuffPtr new_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff)); tmp->next = new_buff; new_buff->next = NULL; tmp = new_buff; fread(new_buff->cappad, sizeof(SGO_PAD), PAD_BUFSIZE, fileptr); } } void PadfileWrite(TraceBuffPtr buff) { TraceBuffPtr tmp = buff; fwrite(buff->cappad, sizeof(SGO_PAD), PAD_BUFSIZE, fileptr); while (tmp->next != NULL) { tmp = tmp->next; fwrite(tmp->cappad, sizeof(SGO_PAD), PAD_BUFSIZE, fileptr); } } TraceBuffPtr CapturePad(TraceBuffPtr buff, SGO_PAD *pad) { static int count; if (count !=PAD_BUFSIZE) { buff->cappad[count] = pad[0]; ++count; return buff; } else { TraceBuffPtr new_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff)); new_buff->cappad[0] = pad[0]; buff->next = new_buff; new_buff->next = NULL; count = 1; return new_buff; } } TraceBuffPtr TracePad(TraceBuffPtr buff, SGO_PAD *pad) { static int count; if (count !=PAD_BUFSIZE) { pad[0] = buff->cappad[count]; ++count; return buff; } else { buff = buff->next; pad[0] = buff->cappad[0]; count = 1; return buff; } } void PadfileClose(TraceBuffPtr buff) { fclose(fileptr); TraceBuffPtr trace = buff; while (trace->next != NULL) { TraceBuffPtr tmp = trace; trace = trace->next; free(tmp); } free(trace); } #ifdef USE_MYRAND static FILE *myrand_fp; extern int runmode; int myrand_open_file(char *filename) { myrand_fp = fopen(filename, "r+"); if (!myrand_fp) { myrand_fp = fopen(filename, "w+"); if (myrand_fp) { return 0; } else { return 1; } } return 0; } static char buf[16]; int myrand() { int r = 0; if (runmode) { if (runmode == 1) { r = rand(); fprintf(myrand_fp, "%d\n", r); } else if (runmode == 2) { // dbg_printf("check0\n"); if (fgets(buf, 16, myrand_fp)) { sscanf(buf, "%d", &r); } else { fseek(myrand_fp, 0, SEEK_SET); } } } else { r = rand(); } return r; } #endif // USE_MYRAND