2
* JB, the Jean-Yves Lefort's Build System
3
* Copyright (C) 2008 Jean-Yves Lefort <jylefort@brutele.be>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
#include "jb-config.h"
22
#include "jb-variable.h"
31
config = g_string_new(NULL);
33
JB_LIST_FOREACH(l, jb_variables)
35
JBVariable *variable = l->data;
39
value = jb_variable_to_string(variable);
40
escaped = g_strescape(value, NULL);
43
g_string_append_printf(config,
46
jb_variable_get_type_name(variable),
52
jb_write_file_or_exit(JB_CONFIG_FILE, config->str);
53
g_string_free(config, TRUE);
63
config = jb_read_file_or_exit(JB_CONFIG_FILE);
64
lines = g_strsplit(config, "\n", 0);
67
for (i = 0; lines[i] != NULL; i++)
76
if (*lines[i] == '\0')
79
fields = g_strsplit(lines[i], "|", 4);
80
if (g_strv_length(fields) != 4)
81
jb_error("%s:%i: cannot parse line", JB_CONFIG_FILE, lineno);
83
type = jb_variable_get_type(fields[1]);
85
jb_error("%s:%i: invalid type \"%s\"", JB_CONFIG_FILE, lineno, fields[1]);
87
variable = jb_variable_get_variable(fields[0]);
89
variable = jb_variable_add(type, fields[0], NULL, NULL, atoi(fields[2]));
92
if (type != variable->type)
93
jb_error("%s:%i: inconsistent type \"%s\" (type \"%s\" expected)",
97
variable->type->name);
100
unescaped = g_strcompress(fields[3]);
102
if (! jb_variable_set_from_string(variable, unescaped, &err))
103
jb_error("%s:%i: invalid value for type \"%s\": %s",