6 static FILE *config_file;
7 static int config_linenr;
8 static int get_next_char(void)
14 if ((f = config_file) != NULL) {
26 static char *parse_value(void)
28 static char value[1024];
29 int quote = 0, comment = 0, len = 0, space = 0;
32 int c = get_next_char();
33 if (len >= sizeof(value))
43 if (isspace(c) && !quote) {
66 /* Some characters escape as themselves */
69 /* Reject unknown escape sequences */
81 if (c == ';' || c == '#') {
90 static int get_value(config_fn_t fn, char *name, unsigned int len)
95 /* Get the full name */
102 name[len++] = tolower(c);
107 while (c == ' ' || c == '\t')
114 value = parse_value();
118 return fn(name, value);
121 static int get_base_var(char *name)
126 int c = get_next_char();
133 if (baselen > MAXNAME / 2)
135 name[baselen++] = tolower(c);
139 static int git_parse_file(config_fn_t fn)
143 static char var[MAXNAME];
146 int c = get_next_char();
154 if (comment || isspace(c))
156 if (c == '#' || c == ';') {
161 baselen = get_base_var(var);
164 var[baselen++] = '.';
170 var[baselen] = tolower(c);
171 if (get_value(fn, var, baselen+1) < 0)
174 die("bad config file line %d", config_linenr);
177 int git_config_int(const char *name, const char *value)
179 if (value && *value) {
181 int val = strtol(value, &end, 0);
185 die("bad config value for '%s'", name);
188 int git_config_bool(const char *name, const char *value)
194 if (!strcasecmp(value, "true"))
196 if (!strcasecmp(value, "false"))
198 return git_config_int(name, value) != 0;
201 int git_default_config(const char *var, const char *value)
203 /* This needs a better name */
204 if (!strcmp(var, "core.filemode")) {
205 trust_executable_bit = git_config_bool(var, value);
209 if (!strcmp(var, "user.name")) {
210 strncpy(git_default_name, value, sizeof(git_default_name));
214 if (!strcmp(var, "user.email")) {
215 strncpy(git_default_email, value, sizeof(git_default_email));
219 /* Add other config variables here.. */
223 int git_config(config_fn_t fn)
226 FILE *f = fopen(git_path("config"), "r");
232 ret = git_parse_file(fn);