summaryrefslogtreecommitdiffstatshomepage
path: root/ui-diff.c
Commit message (Expand)AuthorAge
* ui-diff: make diffstat header a link to the full diffLars Hjemli2008-09-23
* ui-diff: fix links from diffstatLars Hjemli2008-09-23
* Include commit-id in link from diff-statLars Hjemli2008-05-18
* ui-diff: remove test on object typeLars Hjemli2008-04-24
* Integrate diffstat with diffLars Hjemli2008-04-24
* Add ui-shared.hLars Hjemli2008-03-24
* Introduce html.hLars Hjemli2008-03-18
* Introduce struct cgit_contextLars Hjemli2008-02-16
* Fix html error detected by test-suiteLars Hjemli2007-11-11
* ui-diff: add links to pre- and postversion of blobsLars Hjemli2007-10-01
* Add prefix parameter to cgit_print_diff()Lars Hjemli2007-10-01
* Add prefix parameter to cgit_diff_tree()Lars Hjemli2007-10-01
* Merge branch 'jo/dirlink'Lars Hjemli2007-09-03
|\
| * Rename dirlink to gitlink.Jeffrey C. Ollie2007-06-04
* | Add cgit_diff_link()Lars Hjemli2007-06-17
* | ui-diff: close td/tr/table properlyLars Hjemli2007-06-06
* | ui-diff: emit table/tr/td at better locationsLars Hjemli2007-06-05
|/
* Fixed unexpected tags in html output.Ondrej Jirman2007-05-31
* Don't die when diffing trees with subprojectsLars Hjemli2007-05-16
* Add support for commitdiff via h parameterLars Hjemli2007-05-16
* ui-diff: show /dev/null as filename for add/deleteLars Hjemli2007-05-15
* cgit.css: try to make diffs look a little bit nicerLars Hjemli2007-05-14
* Add commitdiff between commit and each of it's parentLars Hjemli2007-05-13
* Simplify ui-diff.c using the new file-level diff interfaceLars Hjemli2007-05-13
* Update to libgit 1.5.2-rc2Lars Hjemli2007-05-08
* Layout updateLars Hjemli2007-02-21
* Add basic diff viewLars Hjemli2006-12-20
#0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* configfile.c: parsing of config files
 *
 * Copyright (C) 2008 Lars Hjemli
 *
 * Licensed under GNU General Public License v2
 *   (see COPYING for full license text)
 */

#include <ctype.h>
#include <stdio.h>
#include "configfile.h"

int next_char(FILE *f)
{
	int c = fgetc(f);
	if (c=='\r') {
		c = fgetc(f);
		if (c!='\n') {
			ungetc(c, f);
			c = '\r';
		}
	}
	return c;
}

void skip_line(FILE *f)
{
	int c;

	while((c=next_char(f)) && c!='\n' && c!=EOF)
		;
}

int read_config_line(FILE *f, char *line, const char **value, int bufsize)
{
	int i = 0, isname = 0;

	*value = NULL;
	while(i<bufsize-1) {
		int c = next_char(f);
		if (!isname && (c=='#' || c==';')) {
			skip_line(f);
			continue;
		}
		if (!isname && isspace(c))
			continue;

		if (c=='=' && !*value) {
			line[i] = 0;
			*value = &line[i+1];
		} else if (c=='\n' && !isname) {
			i = 0;
			continue;
		} else if (c=='\n' || c==EOF) {
			line[i] = 0;
			break;
		} else {
			line[i]=c;
		}
		isname = 1;
		i++;
	}
	line[i+1] = 0;
	return i;
}

int parse_configfile(const char *filename, configfile_value_fn fn)
{
	static int nesting;
	int len;
	char line[256];
	const char *value;
	FILE *f;

	/* cancel deeply nested include-commands */
	if (nesting > 8)
		return -1;
	if (!(f = fopen(filename, "r")))
		return -1;
	nesting++;
	while((len = read_config_line(f, line, &value, sizeof(line))) > 0)
		fn(line, value);
	nesting--;
	fclose(f);
	return 0;
}