Line data Source code
1 : #include "../inc/header.h"
2 : #include "../inc/param_manager.h"
3 :
4 : #include "../inc/global_param.h"
5 :
6 : /**
7 : * \file init.cu
8 : * \author martigan
9 : * \brief Fichier pour la gestion du fichier de configuration en parametre
10 : * \fn int set_with_conf_file(char *conf_file)
11 : * \return 0 on success, other value on error
12 : *
13 : * modify the global variables nb_type, supported_type, supported_length, supported_last_file and supported_type_length
14 : * accordingly to content of conf file.
15 : */
16 :
17 :
18 :
19 : // VR 10-10-16 : est-ce bien utilisé, on dirait, donc les supported_type sont deprecated !
20 1 : void setdefault(GlobalParam & gp, LocalParam & lp)
21 : {
22 : // size_t NB_TYPE = 4;
23 :
24 : // VR 10-10-16 : on pourrait quand meme mettre cela dans une fonction
25 1 : uint32_t types[NB_TYPE] = {2, 22, 15, 16};
26 : //uint32_t lengths[NB_TYPE] = {4096, 4104, 9216, 9216};
27 : //uint32_t last_files[NB_TYPE] = {0,0, 0, 0};
28 1 : uint32_t types_lengths[NB_TYPE] = {4096, 4104, 9216, 9216}; // supported number bit
29 :
30 6 : for (int i = 0; i < NB_TYPE; ++i)
31 : {
32 5 : AddDTtoCache(gp, lp, types[i], types_lengths[i]);
33 : }
34 1 : }
35 :
36 2 : int set_with_conf_file(std::string conf_file_aux,GlobalParam & gp, LocalParam & lp)
37 : {
38 2 : char linebuf[256];
39 2 : std::vector<std::string> splited_buff;
40 :
41 2 : printf("file is %s\n", conf_file_aux.c_str());
42 2 : FILE *f = fopen(conf_file_aux.c_str(), "r");
43 2 : if (f == NULL)
44 : {
45 0 : printf("conf_file : %s does not exist, getting default type parameters\n", conf_file_aux.c_str());
46 : //conf_file = NULL;
47 0 : exit(1);
48 : } else {
49 2 : GlobalParam::Instance().nbtype_ = 0;
50 6 : while (fgets(linebuf, sizeof(linebuf), f)) {
51 5 : if (linebuf[0] == '\n')
52 : break;
53 4 : if (linebuf[0] == EOF) {
54 0 : if(GlobalParam::Instance().nbtype_ == 0) {
55 0 : puts("empty conf file");
56 0 : return 1;
57 : }
58 : break;
59 : }
60 4 : if (linebuf[0] == '#')
61 0 : continue;
62 8 : std::string buff(&linebuf[0]);
63 4 : boost::split(splited_buff, buff, boost::is_any_of(","));
64 4 : std::cout<<" buff : "<<buff<<std::endl;
65 4 : if (splited_buff.size()) {
66 4 : AddDTtoCache(gp, lp, (uint32_t)atoi(&(splited_buff[0].at(0))), (uint32_t)atoi(&(splited_buff[2].at(0))));
67 : }
68 : }
69 2 : if (GlobalParam::Instance().nbtype_ == 0) {
70 2 : printf("nothing usefull in conf file, exiting\n");
71 : return 1;
72 : }
73 2 : puts("conf file loaded");
74 2 : fclose(f);
75 : }
76 : return 0;
77 : }
|