File tree Expand file tree Collapse file tree 8 files changed +127
-0
lines changed Expand file tree Collapse file tree 8 files changed +127
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ #include <stdio.h>
3+ #include <string.h>
4+
5+ #include "./macros.h"
6+ #include "./structs.h"
7+
8+ unsigned char getConfiguration (Configuration * config , const char * path ) {
9+ char line [CONFIGURATION_LINE_LENGTH ];
10+
11+ char * fieldStart ;
12+ char * fieldEnd ;
13+
14+ char * lineBreak ;
15+
16+ FILE * file = fopen (path , "rt" );
17+ if (file == NULL ) return 1 ;
18+
19+ if (fgets (line , sizeof (line ), file ) == NULL ) return 1 ;
20+
21+ fieldStart = line ;
22+ fieldEnd = strchr (fieldStart , ' ' );
23+ if (fieldEnd == NULL ) return 1 ;
24+
25+ * fieldEnd = '\0' ;
26+ if (strlen (fieldStart ) == 0 ) return 1 ;
27+ strcpy (config -> apiURL , fieldStart );
28+
29+ fieldStart = fieldEnd + 1 ;
30+ fieldEnd = strchr (fieldStart , ' ' );
31+ if (fieldEnd == NULL ) return 1 ;
32+
33+ fieldStart = fieldEnd + 1 ;
34+ lineBreak = strrchr (fieldStart , '\n' );
35+ if (lineBreak != NULL ) {
36+ * lineBreak = '\0' ;
37+ };
38+
39+ strcpy (config -> teamName , fieldStart );
40+
41+ if (fgets (line , sizeof (line ), file ) == NULL ) return 1 ;
42+
43+ sscanf (line , "%d" , & config -> gamesPerPlayer );
44+
45+ return 0 ;
46+ }
Original file line number Diff line number Diff line change 1+
2+ #ifndef SRC__CONFIG_FUNCTIONS_H_INCLUDED
3+ #define SRC__CONFIG_FUNCTIONS_H_INCLUDED
4+
5+ #include "./structs.h"
6+
7+ unsigned char getConfiguration (Configuration * config , const char * path );
8+
9+ #endif // SRC__CONFIG_FUNCTIONS_H_INCLUDED
Original file line number Diff line number Diff line change 1+ #include "./main.h"
2+
3+ #include <stdio.h>
4+
5+ void reprConfiguration (Configuration * config ) {
6+ if (config == NULL ) {
7+ printf ("Configuration 0x%p (NULL);" , (void * )& config );
8+ return ;
9+ };
10+
11+ printf ("Configuration 0x%p {\n" , (void * )& config );
12+ printf (" char apiURL[MAXIMUM_API_URL_LENGTH] = \"%s\",\n" , config -> apiURL );
13+ printf (" char teamName[TEAM_NAME_LENGTH] = \"%s\",\n" , config -> teamName );
14+ printf (" int gamesPerPlayer = %d,\n" , config -> gamesPerPlayer );
15+ printf ("};" );
16+ }
Original file line number Diff line number Diff line change 1+ #ifndef SRC__CONFIG_LOG_H_INCLUDED
2+ #define SRC__CONFIG_LOG_H_INCLUDED
3+
4+ #include "../structs.h"
5+
6+ void reprConfiguration (Configuration * config );
7+
8+ #endif // SRC__CONFIG_LOG_H_INCLUDED
Original file line number Diff line number Diff line change 1+ #ifndef SRC__CONFIG_MACRO_H_INCLUDED
2+ #define SRC__CONFIG_MACRO_H_INCLUDED
3+
4+ #define MAXIMUM_API_URL_LENGTH 256
5+
6+ #define CONFIGURATION_LINE_LENGTH 256
7+
8+ #endif // SRC__CONFIG_MACRO_H_INCLUDED
Original file line number Diff line number Diff line change 1+
2+ #ifndef SRC__CONFIG_MAIN_H_INCLUDED
3+ #define SRC__CONFIG_MAIN_H_INCLUDED
4+
5+ // Logs
6+ #include "./logs/main.h"
7+
8+ // Root
9+ #include "./functions.h"
10+ #include "./macros.h"
11+ #include "./structs.h"
12+
13+ #endif // SRC__CONFIG_MAIN_H_INCLUDED
Original file line number Diff line number Diff line change 1+
2+ #ifndef SRC__CONFIG_STRUCTS_H_INCLUDED
3+ #define SRC__CONFIG_STRUCTS_H_INCLUDED
4+
5+ #include "../macros.h"
6+ #include "./macros.h"
7+
8+ typedef struct {
9+ char apiURL [MAXIMUM_API_URL_LENGTH ];
10+ char teamName [TEAM_NAME_LENGTH ];
11+ int gamesPerPlayer ;
12+ } Configuration ;
13+
14+ #endif // SRC__CONFIG_STRUCTS_H_INCLUDED
Original file line number Diff line number Diff line change 3535 <Add library =" ../libs/bin/Debug/libs.a" />
3636 <Add library =" ../libs/bin/Release/libs.a" />
3737 </Linker >
38+ <Unit filename =" configuration/functions.c" >
39+ <Option compilerVar =" CC" />
40+ </Unit >
41+ <Unit filename =" configuration/functions.h" />
42+ <Unit filename =" configuration/logs/main.c" >
43+ <Option compilerVar =" CC" />
44+ </Unit >
45+ <Unit filename =" configuration/logs/main.h" />
46+ <Unit filename =" configuration/macros.h" />
47+ <Unit filename =" configuration/main.h" />
48+ <Unit filename =" configuration/structs.h" />
49+ <Unit filename =" macros.h" />
3850 <Unit filename =" main.c" >
3951 <Option compilerVar =" CC" />
4052 </Unit >
53+ <Unit filename =" structs.h" />
4154 <Unit filename =" utilities.c" >
4255 <Option compilerVar =" CC" />
4356 </Unit >
You can’t perform that action at this time.
0 commit comments