Mercurial > hg > Members > kono > tree_dandy2
view trace.c @ 0:01387a2e419e
initial version
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 07 Dec 2010 15:39:45 +0900 |
parents | |
children |
line wrap: on
line source
#include<stdio.h> #define PAD_BUFSIZ 32 #define RESET_BUTTON 768 #ifdef ENABLE_TRACEMODE static FILE *pad_fp; static char pad_buf[PAD_BUFSIZ]; void pad_trace(unsigned int pad) { fprintf(pad_fp, "%d\n", pad); } int pad_file_open(char *f) { pad_fp = fopen(f, "r+"); if (!pad_fp) { // 本当はerrnoをチェックするのがいいんだろうなぁ pad_fp = fopen(f, "w+"); if (pad_fp) { return 0; } // goto dbg_abort(4); return 1; } return 0; } int pad_file_read() { int padd; if (fgets(pad_buf, PAD_BUFSIZ, pad_fp)) { sscanf(pad_buf, "%d", &padd); return padd; } return RESET_BUTTON; } #endif //ENABLE_TRACEMODE #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