summaryrefslogtreecommitdiff
path: root/dviware/quicspool/libprofile/boolean.c
blob: a26df19a38963556e29e421662798e9ea488ce82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
static char *rcs = "$Header: boolean.c,v 1.1 88/01/15 12:16:56 simpson Rel $";
/*
$Log:	boolean.c,v $
 * Revision 1.1  88/01/15  12:16:56  simpson
 * initial release
 * 
 * Revision 0.1  87/12/11  17:02:10  simpson
 * beta test
 * 
*/
#include <ctype.h>
#include "profile.h"

static char *Yes[] = {
	"yes",
	"on",
	"true",
	"enable",
	"available",
	"present",
	0
};

static char *No[] = {
	"no",
	"off",
	"false",
	"disable",
	"unavailable",
	"absent",
	0
};

int profile_boolean (v)
PROFILE_VALUE *v;
{
	char x[16];
	int i;

	if (v == 0)
		return(0);

	switch (v->class) {
	case PROFILE_OTHER:
	case PROFILE_STRING:
		strncpy(x, v->value.s, sizeof(x)-1);
		x[sizeof(x)-1] = 0;
		downshift(x);
		for (i = 0; Yes[i]; i++)
			if (strcmp(x, Yes[i]) == 0)
				return(1);
			else if (strcmp(x, No[i]) == 0)
				return(0);
		return(-1);	/* unknown string */

	case PROFILE_HEX:
	case PROFILE_INTEGER:
	case PROFILE_OCTAL:
		return(v->value.i != 0);

	case PROFILE_CHARACTER:
		return(v->value.c != 0);

	case PROFILE_FLOAT:
		return(v->value.f != 0.0);

	default:
		return(-1);	/* unknown class */
	}
}

/* downshift a string in place */
static downshift (s)
char *s;
{
	for (; *s; s++)
		if (isupper(*s))
			*s = tolower(*s);
}