aboutsummaryrefslogtreecommitdiff
path: root/lib/kwtab.c
blob: 2fb2b1c4b8d7d862bb879c9ddb06e5212a4b24f1 (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
/* This file is part of Smap.
   Copyright (C) 2006, 2007, 2010 Sergey Poznyakoff

   Smap is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   Smap 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 Smap.  If not, see <http://www.gnu.org/licenses/>. */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>
#include "smap/kwtab.h"

int
smap_kwtab_nametotok_len(struct smap_kwtab *kwtab, const char *str,
			 size_t len, int *pres)
{
	for (; kwtab->name; kwtab++) {
		size_t kwlen = strlen(kwtab->name);
		if (kwlen == len && memcmp(kwtab->name, str, len) == 0) {
			*pres = kwtab->tok;
			return 0;
		}
	}
	return 1;
}

int
smap_kwtab_nametotok(struct smap_kwtab *kwtab, const char *str, int *pres)
{
	for (; kwtab->name; kwtab++) {
		if (strcmp(kwtab->name, str) == 0) {
			*pres = kwtab->tok;
			return 0;
		}
	}
	return 1;
}

int
smap_kwtab_toktoname(struct smap_kwtab *kwtab, int tok, const char **pres)
{
	for (; kwtab->name; kwtab++)
		if (kwtab->tok == tok) {
			*pres = kwtab->name;
			return 0;
		}
	return 1;
}

Return to:

Send suggestions and report system problems to the System administrator.