ignore.c 2.45 KB
Newer Older
Bernhard Link's avatar
Bernhard Link committed
1 2 3
/*  This file is part of "reprepro"
 *  Copyright (C) 2005 Bernhard R. Link
 *  This program is free software; you can redistribute it and/or modify
4
 *  it under the terms of the GNU General Public License version 2 as
Bernhard Link's avatar
Bernhard Link committed
5
 *  published by the Free Software Foundation.
Bernhard Link's avatar
Bernhard Link committed
6 7 8 9 10 11 12 13
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
Bernhard Link's avatar
Bernhard Link committed
14
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1301  USA
Bernhard Link's avatar
Bernhard Link committed
15
 */
16 17
#include <config.h>

18
#include <assert.h>
19
#include <stdio.h>
20
#include <string.h>
21
#include <stdlib.h>
22 23 24 25

#include "ignore.h"

int ignored[IGN_COUNT];
26
bool ignore[IGN_COUNT];
27
enum config_option_owner owner_ignore[IGN_COUNT];
28

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
static const char * const ignores[] = {
#define IGN(what) #what ,
	VALID_IGNORES
#undef IGN
};

bool print_ignore_type_message(bool i, enum ignore what) {
	ignored[what]++;
	if (ignore[what])
		fprintf(stderr, "%s as --ignore=%s given.\n",
				i ? "Ignoring" : "Not rejecting",
				ignores[what]);
	else
		fprintf(stderr, "To ignore use --ignore=%s.\n",
				ignores[what]);
	return ignore[what];
45 46
}

47
static retvalue set(const char *given, size_t len, bool newvalue, enum config_option_owner newowner) {
48 49 50 51
	int i;

	//TODO: allow multiple values sperated by some sign here...

52 53 54 55
	for (i = 0 ; i < IGN_COUNT ; i++) {
		if (strncmp(given, ignores[i], len) == 0 &&
				ignores[i][len] == '\0') {
			if (owner_ignore[i] <= newowner) {
56 57 58
				ignore[i] = newvalue;
				owner_ignore[i] = newowner;
			}
59 60 61
			break;
		}
	}
62 63 64 65
	if (i == IGN_COUNT) {
		char *str = strndup(given, len);
		if (IGNORING(ignore,
"Unknown --ignore value: '%s'!\n", (str!=NULL)?str:given)) {
66
			free(str);
67
			return RET_NOTHING;
68 69
		} else {
			free(str);
70
			return RET_ERROR;
71
		}
72 73 74
	} else
		return RET_OK;
}
75

76
retvalue set_ignore(const char *given, bool newvalue, enum config_option_owner newowner) {
77
	const char *g, *p;
78 79
	retvalue r;

80
	assert (given != NULL);
81 82 83

	g = given;

84
	while (true) {
85
		p = g;
86
		while (*p != '\0' && *p != ',')
87
			p++;
88 89 90 91
		if (p == g) {
			fprintf(stderr,
"Empty ignore option in --ignore='%s'!\n",
					given);
92 93
			return RET_ERROR_MISSING;
		}
94 95
		r = set(g, p - g, newvalue, newowner);
		if (RET_WAS_ERROR(r))
96
			return r;
97
		if (*p == '\0')
98 99 100 101
			return RET_OK;
		g = p+1;
	}
}