7 static FILE *config_file;
8 static int config_linenr;
9 static int get_next_char(void)
15 if ((f = config_file) != NULL) {
27 static char *parse_value(void)
29 static char value[1024];
30 int quote = 0, comment = 0, len = 0, space = 0;
33 int c = get_next_char();
34 if (len >= sizeof(value))
44 if (isspace(c) && !quote) {
67 /* Some characters escape as themselves */
70 /* Reject unknown escape sequences */
82 if (c == ';' || c == '#') {
91 static int get_value(config_fn_t fn, char *name, unsigned int len)
96 /* Get the full name */
103 name[len++] = tolower(c);
108 while (c == ' ' || c == '\t')
115 value = parse_value();
119 return fn(name, value);
122 static int get_base_var(char *name)
127 int c = get_next_char();
134 if (baselen > MAXNAME / 2)
136 name[baselen++] = tolower(c);
140 static int git_parse_file(config_fn_t fn)
144 static char var[MAXNAME];
147 int c = get_next_char();
155 if (comment || isspace(c))
157 if (c == '#' || c == ';') {
162 baselen = get_base_var(var);
165 var[baselen++] = '.';
172 if (get_value(fn, var, baselen+1) < 0)
175 die("bad config file line %d", config_linenr);
178 int git_config_int(const char *name, const char *value)
180 if (value && *value) {
182 int val = strtol(value, &end, 0);
186 die("bad config value for '%s'", name);
189 int git_config_bool(const char *name, const char *value)
195 if (!strcasecmp(value, "true"))
197 if (!strcasecmp(value, "false"))
199 return git_config_int(name, value) != 0;
202 int git_default_config(const char *var, const char *value)
204 /* This needs a better name */
205 if (!strcmp(var, "core.filemode")) {
206 trust_executable_bit = git_config_bool(var, value);
210 if (!strcmp(var, "user.name")) {
211 strncpy(git_default_name, value, sizeof(git_default_name));
215 if (!strcmp(var, "user.email")) {
216 strncpy(git_default_email, value, sizeof(git_default_email));
220 /* Add other config variables here.. */
224 int git_config(config_fn_t fn)
227 FILE *f = fopen(git_path("config"), "r");
233 ret = git_parse_file(fn);