Adding support for config file
This commit is contained in:
parent
dfc3ab4353
commit
a03d565b60
2 changed files with 82 additions and 16 deletions
49
extra/DSA/data.cfg
Normal file
49
extra/DSA/data.cfg
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#
|
||||||
|
# Made by Fry.
|
||||||
|
# 11.12.2016
|
||||||
|
#
|
||||||
|
|
||||||
|
version = "1.0";
|
||||||
|
|
||||||
|
application:
|
||||||
|
{
|
||||||
|
# The starting position of the player.
|
||||||
|
engineer:
|
||||||
|
{
|
||||||
|
row = 0;
|
||||||
|
column = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
# The location of the exit.
|
||||||
|
exit:
|
||||||
|
{
|
||||||
|
row = 3;
|
||||||
|
column = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
# The location of the walls.
|
||||||
|
walls = (
|
||||||
|
{
|
||||||
|
row = 0;
|
||||||
|
column = 3;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
row = 1;
|
||||||
|
column = 1;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
row = 2;
|
||||||
|
column = 1;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
row = 2;
|
||||||
|
column = 2;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
row = 2;
|
||||||
|
column = 3;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
|
@ -3,10 +3,13 @@
|
||||||
Date: 10.12.2016
|
Date: 10.12.2016
|
||||||
https://www.ryoko-rpg.ro
|
https://www.ryoko-rpg.ro
|
||||||
https://github.com/Metonimie
|
https://github.com/Metonimie
|
||||||
|
Dependencies:
|
||||||
|
- libconfig
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <libconfig.h>
|
||||||
|
|
||||||
#define VISITED_MASK ( (unsigned) 1 << 4)
|
#define VISITED_MASK ( (unsigned) 1 << 4)
|
||||||
#define DEATH_MASK ( (unsigned) 1 << 5)
|
#define DEATH_MASK ( (unsigned) 1 << 5)
|
||||||
|
@ -23,6 +26,9 @@
|
||||||
unsigned rows = 4;
|
unsigned rows = 4;
|
||||||
unsigned cols = 4;
|
unsigned cols = 4;
|
||||||
|
|
||||||
|
// Config settings.
|
||||||
|
config_t configuration;
|
||||||
|
|
||||||
unsigned testM[4][4] = {
|
unsigned testM[4][4] = {
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0},
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0},
|
||||||
|
@ -211,25 +217,36 @@ unsigned solve_mat(unsigned c, unsigned r) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Simple test code */
|
||||||
|
|
||||||
|
// make_exit_cell(&testM[3][3]);
|
||||||
|
// make_wall_cell(&testM[0][3]);
|
||||||
|
// make_wall_cell(&testM[1][1]);
|
||||||
|
// make_wall_cell(&testM[2][1]);
|
||||||
|
// make_wall_cell(&testM[2][2]);
|
||||||
|
// make_wall_cell(&testM[2][3]);
|
||||||
|
//
|
||||||
|
// for (unsigned i = 0; i < rows; ++i) {
|
||||||
|
// for (unsigned j = 0; j < cols; ++j) {
|
||||||
|
// set_timmer(i, j, 6);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// print_matrix2(testM, 4, 4);
|
||||||
|
// unsigned x = solve_mat(0, 0);
|
||||||
|
// printf("Solved: %d\n", x);
|
||||||
|
// print_matrix2(testM, 4, 4);
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
/* Initialize the configuration structure */
|
||||||
|
config_init(&configuration);
|
||||||
|
|
||||||
make_exit_cell(&testM[3][3]);
|
if ( config_read_file(&configuration, "data.cfg") != CONFIG_TRUE ) {
|
||||||
make_wall_cell(&testM[0][3]);
|
fprintf(stderr, "Configuration Error: %s\n", config_error_text(&configuration));
|
||||||
make_wall_cell(&testM[1][1]);
|
fprintf(stderr, "File: %s on line %d\n", config_error_file(&configuration),
|
||||||
make_wall_cell(&testM[2][1]);
|
config_error_line(&configuration));
|
||||||
make_wall_cell(&testM[2][2]);
|
return EXIT_FAILURE;
|
||||||
make_wall_cell(&testM[2][3]);
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < rows; ++i) {
|
|
||||||
for (unsigned j = 0; j < cols; ++j) {
|
|
||||||
set_timmer(i, j, 6);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_matrix2(testM, 4, 4);
|
|
||||||
unsigned x = solve_mat(0, 0);
|
|
||||||
printf("Solved: %d\n", x);
|
|
||||||
print_matrix2(testM, 4, 4);
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue