-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.cpp
75 lines (58 loc) · 1.74 KB
/
config.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <cstring>
#include <string>
#include "config.h"
using namespace std;
Config::Config() {
featOutFile = NULL
featSize = DEFAULT_FEATURE_SIZE;
featType = -1;
}
int Config::ReadConfigFile(const char * path) {
FILE *f = fopen(path, "r");
if (f == NULL) {
fprintf(stderr, "Cannot find config file!\n");
return -1;
}
char option[1024];
char str[1024];
while (fscanf(f, "%s", option) != EOF){
if (!strcmp(option, "authorship")) {
fscanf(f, "%s", sourceAuthorshipDir);
}
if (!strcmp(option, "binarypath")) {
fscanf(f, "%s", binPath);
}
if (!strcmp(option, "featuretype")) {
fscanf(f, "%s", str);
for (int i = 0; featString[i] != NULL && strcmp(featString[i], str); ++i);
if (featString[i] != NULL)
featType = i;
}
if (!strcmp(option, "featuresize")) {
fscanf(f, "%d", featSize);
}
if (!strcmp(option, "debug")){
debug = true;
}
}
fclose(f);
if (featType < 0) {
fprintf(stderr, "Incorrect feature type!\n");
return -1;
}
return 0;
}
void Config::Close(){
fclose(binaryFile);
if (statisticFile != NULL) fclose(statisticFile);
if (dataSetStatFile != NULL) fclose(dataSetStatFile);
if (funcToAuthorFile != NULL) fclose(funcToAuthorFile);
if (sourceFuncsFile != NULL) fclose(sourceFuncsFile);
if (idiomFeature) fclose(idiomFile);
if (graphletFeature) fclose(graphletFile);
if (libcallFeature) fclose(libcallFile);
if (ngramFeature) fclose(ngramFile);
if (dataFeature) fclose(dataFile);
if (statFeature) fclose(statFile);
if (featureList) fclose(featureListFile);
}