Mercurial > hg > Members > koba > t_dandy
annotate 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 |
rev | line source |
---|---|
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1 #include <stdio.h> |
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2 #include "trace.h" |
43 | 3 |
0 | 4 |
43 | 5 static FILE *fileptr; |
6 const char *filename; | |
0 | 7 |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
8 void |
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
9 pad_trace(unsigned int pad) |
0 | 10 { |
43 | 11 fprintf(fileptr, "%d\n", pad); |
12 } | |
13 | |
14 | |
15 int | |
16 PadfileOpen(const char* name) | |
17 { | |
18 filename = name; | |
19 fileptr = fopen(filename, "rb+"); | |
20 | |
21 if (!fileptr) { | |
22 fileptr = fopen(filename, "wb+"); | |
23 if (!fileptr) { | |
24 printf("can't open output file.\n"); | |
25 return 0; | |
26 } | |
27 } | |
28 | |
29 return 1; | |
0 | 30 } |
31 | |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
32 |
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
33 void |
43 | 34 PadfileRead(TraceBuffPtr buff) |
0 | 35 { |
43 | 36 TraceBuffPtr tmp = buff; |
37 fread(buff->cappad, sizeof(SGO_PAD), PAD_BUFSIZE, fileptr); | |
38 | |
39 while (!feof(fileptr)) { | |
40 TraceBuffPtr new_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff)); | |
41 tmp->next = new_buff; | |
42 new_buff->next = NULL; | |
43 tmp = new_buff; | |
44 | |
45 fread(new_buff->cappad, sizeof(SGO_PAD), PAD_BUFSIZE, fileptr); | |
0 | 46 } |
47 } | |
48 | |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
49 |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
50 void |
43 | 51 PadfileWrite(TraceBuffPtr buff) |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
52 { |
43 | 53 TraceBuffPtr tmp = buff; |
54 fwrite(buff->cappad, sizeof(SGO_PAD), PAD_BUFSIZE, fileptr); | |
55 | |
56 while (tmp->next != NULL) { | |
57 tmp = tmp->next; | |
58 fwrite(tmp->cappad, sizeof(SGO_PAD), PAD_BUFSIZE, fileptr); | |
59 } | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
60 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
61 |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
62 |
43 | 63 TraceBuffPtr |
64 CapturePad(TraceBuffPtr buff, SGO_PAD *pad) | |
0 | 65 { |
43 | 66 static int count; |
67 | |
68 if (count !=PAD_BUFSIZE) { | |
69 buff->cappad[count] = pad[0]; | |
70 ++count; | |
71 return buff; | |
72 } else { | |
73 TraceBuffPtr new_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff)); | |
74 new_buff->cappad[0] = pad[0]; | |
75 buff->next = new_buff; | |
76 new_buff->next = NULL; | |
77 | |
78 count = 1; | |
79 return new_buff; | |
80 } | |
81 } | |
82 | |
83 | |
84 TraceBuffPtr | |
85 TracePad(TraceBuffPtr buff, SGO_PAD *pad) | |
86 { | |
87 static int count; | |
88 | |
89 if (count !=PAD_BUFSIZE) { | |
90 pad[0] = buff->cappad[count]; | |
91 ++count; | |
92 return buff; | |
93 } else { | |
94 buff = buff->next; | |
95 pad[0] = buff->cappad[0]; | |
96 | |
97 count = 1; | |
98 return buff; | |
99 } | |
0 | 100 } |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
101 |
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
102 |
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
103 void |
43 | 104 PadfileClose(TraceBuffPtr buff) |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
105 { |
43 | 106 fclose(fileptr); |
107 | |
108 TraceBuffPtr trace = buff; | |
109 | |
110 while (trace->next != NULL) { | |
111 TraceBuffPtr tmp = trace; | |
112 trace = trace->next; | |
113 free(tmp); | |
114 } | |
115 free(trace); | |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
116 } |
0 | 117 |
118 #ifdef USE_MYRAND | |
119 static FILE *myrand_fp; | |
120 extern int runmode; | |
121 | |
122 int myrand_open_file(char *filename) | |
123 { | |
124 myrand_fp = fopen(filename, "r+"); | |
125 if (!myrand_fp) { | |
126 myrand_fp = fopen(filename, "w+"); | |
127 if (myrand_fp) { | |
128 return 0; | |
129 } else { | |
130 return 1; | |
131 } | |
132 } | |
133 return 0; | |
134 } | |
135 | |
136 static char buf[16]; | |
137 | |
138 int myrand() | |
139 { | |
140 int r = 0; | |
141 if (runmode) { | |
142 if (runmode == 1) { | |
143 r = rand(); | |
144 fprintf(myrand_fp, "%d\n", r); | |
145 } else if (runmode == 2) { | |
146 // dbg_printf("check0\n"); | |
147 if (fgets(buf, 16, myrand_fp)) { | |
148 sscanf(buf, "%d", &r); | |
149 } else { | |
150 fseek(myrand_fp, 0, SEEK_SET); | |
151 } | |
152 } | |
153 } else { | |
154 r = rand(); | |
155 } | |
156 return r; | |
157 } | |
158 #endif // USE_MYRAND |