/*
* GIT - The information manager from hell
*
* Copyright (C) Linus Torvalds, 2005
* Copyright (C) Johannes Schindelin, 2005
*
*/
#include "cache.h"
#include "exec_cmd.h"
#include "strbuf.h"
#define MAXNAME (256)
static FILE *config_file;
static const char *config_file_name;
static int config_linenr;
static int config_file_eof;
static int zlib_compression_seen;
const char *config_exclusive_filename = NULL;
struct config_item
{
struct config_item *next;
char *name;
char *value;
};
static struct config_item *config_parameters;
static struct config_item **config_parameters_tail = &config_parameters;
static void lowercase(char *p)
{
for (; *p; p++)
*p = tolower(*p);
}
int git_config_parse_parameter(const char *text)
{
struct config_item *ct;
struct strbuf tmp = STRBUF_INIT;
struct strbuf **pair;
strbuf_addstr(&tmp, text);
pair = strbuf_split(&tmp, '=');
if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=')
strbuf_setlen(pair[0], pair[0]->len - 1);
strbuf_trim(pair[0]);
if (!pair[0]->len) {
strbuf_list_free(pair);
return -1;
}
ct = xcalloc(1, sizeof(struct config_item));
ct->name = strbuf_detach(pair[0], NULL);
if (pair[1]) {
strbuf_trim(pair[1]);
ct->value = strbuf_detach(pair[1], NULL);
}
strbuf_list_free(pair);
lowercase(ct->name);
*config_parameters_tail = ct;
config_parameters_tail = &ct->next;
return 0;
}
static int get_next_char(void)
{
int c;
FILE *f;
c = '\n';
if ((f = config_file) != NULL) {
c = fgetc(f);
if (c == '\r') {
/* DOS like systems */
c = fgetc(f);
if (c != '\n') {
ungetc(c, f);
c = '\r';
}
}
if (c == '\n')
config_linenr++;
if (c == EOF) {
config_file_eof = 1;
c = '\n';
}
}
return c;
}
static char *parse_value(void)
{
static char value[1024];
int quote = 0, comment = 0, len = 0, space = 0;
for (;;) {
int c = get_next_char();
if (len >= sizeof(value) - 1)
return NULL;
if (c == '\n') {
if (quote)
return NULL;
value[len] = 0;
<
|