-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinitor.cpp
More file actions
58 lines (52 loc) · 1.31 KB
/
initor.cpp
File metadata and controls
58 lines (52 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef __INITOR__
#define __INITOR__
#ifndef fp
#define fp stdout
#endif
#include "brainhandler.h"
#include "dealhandler.h"
#include <cstdlib>
#include <cstdio>
int initor(const char * const address, _Brainhandler * brainhandler, _Dealhandler * dealhandler){
FILE * file = fopen(address, "r");
if(fp){
fseek(file, 0, SEEK_END);
int size = ftell(file);
char str[] = ": \n";
char * buffer = (char *)malloc(sizeof(char)*size + 1);
memset(buffer, 0, size + 1);
fseek(file, 0, SEEK_SET);
fread(buffer, sizeof(char), size, file);
char * token;
int o1;
double o2;
int d1;
double d[3];
token = strtok(buffer, str);
while(1){
if(!strcmp(token, "brain")){
o1 = atoi(strtok(NULL, str));
o2 = atof(strtok(NULL, str));
brainhandler->init_brain(o1, o2);
fprintf(fp, "initor : brain init_brain(%d, %f)\n", o1, o2);
}
if(!strcmp(token, "deal")){
d1 = atoi(strtok(NULL, str));
d[0] = atof(strtok(NULL, str));
d[1] = atof(strtok(NULL, str));
d[2] = atof(strtok(NULL, str));
dealhandler->init_deal(d1, d[0],d[1],d[2]);
fprintf(fp, "initor : deal init_deal(%d, %f, %f, %f)\n", d1, d[0], d[1], d[2]);
}
token = strtok(NULL, str);
if(!token) break;
}
free(buffer);
fclose(file);
}
else{
fprintf(fp, "There is no initalizer file!\n");
}
return 0;
}
#endif