File: sparse_names.h

package info (click to toggle)
libreswan 5.2-2.3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 81,644 kB
  • sloc: ansic: 129,988; sh: 32,018; xml: 20,646; python: 10,303; makefile: 3,022; javascript: 1,506; sed: 574; yacc: 511; perl: 264; awk: 52
file content (94 lines) | stat: -rw-r--r-- 3,211 bytes parent folder | download | duplicates (2)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* sparse_names, for libreswan
 *
 * Copyright (C) 1997 Angelos D. Keromytis.
 * Copyright (C) 1998-2002,2013 D. Hugh Redelmeier <hugh@mimosa.com>
 * Copyright (C) 2004-2008  Michael Richardson <mcr@xelerance.com>
 * Copyright (C) 2004-2009  Paul Wouters <paul@xelerance.com>
 * Copyright (C) 2008 Antony Antony <antony@xelerance.com>
 * Copyright (C) 2009 Avesh Agarwal <avagarwa@redhat.com>
 * Copyright (C) 2012 Paul Wouters <paul@libreswan.org>
 * Copyright (C) 2013 Tuomo Soini <tis@foobar.fi>
 * Copyright (C) 2019 Andrew Cagney <cagney@gnu.org>
 *
 * This program 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 2 of the License, or (at your
 * option) any later version.  See <https://www.gnu.org/licenses/gpl2.txt>.
 *
 * 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.
 */

#ifndef SPARSE_NAMES_H
#define SPARSE_NAMES_H

#include <stddef.h>		/* for size_t */

#include "shunk.h"
#include "names.h"

struct jambuf;

/*
 * sparse_names is much like enum_names, except values are not known
 * to be contiguous or ordered.
 *
 * The array is NULL terminated, as in .name==NULL; but suggest using
 * SPARSE_NULL in case that needs to change.
 */

#define SPARSE_NULL { NULL, 0, NULL, }
#define SPARSE(N, V) { .name = N, .value = V, }

struct sparse_name {
	/* field order (backwards?) dictated by started() */
	const char *const name;
	unsigned long value;
	const char *help;
};

struct sparse_names {
	size_t roof; /* when non-zero, limit on value */
	const char *prefix; /* what to remove from short names */
	struct sparse_name list[];
};

const struct sparse_name *sparse_lookup(const struct sparse_names *, shunk_t);

bool sparse_long(const struct sparse_names *sd, unsigned long val, name_buf *b);
bool sparse_short(const struct sparse_names *sd, unsigned long val, name_buf *b);

size_t jam_sparse_long(struct jambuf *buf, const struct sparse_names *sd, unsigned long val);
const char *str_sparse_long(const struct sparse_names *sd, unsigned long val, name_buf *buf);

size_t jam_sparse_short(struct jambuf *buf, const struct sparse_names *sd, unsigned long val);
const char *str_sparse_short(const struct sparse_names *sd, unsigned long val, name_buf *buf);

size_t jam_sparse_names(struct jambuf *buf, const struct sparse_names *names, const char *separator);

#define sparse_buf name_buf
#define jam_sparse jam_sparse_long
#define str_sparse str_sparse_long

/*
 * sparse_sparse_names is much like enum_enum_names, except, again the
 * values are neither assumed to be contingious or ordered.
 *
 * The array is terminated by a NULL entry.
 */

struct sparse_sparse_name {
	unsigned long value;
	const struct sparse_names *names;
};

struct sparse_sparse_names {
	size_t ignore_for_now;
	const struct sparse_sparse_name list[];
};

extern const char *sparse_sparse_name(const struct sparse_sparse_names *sd, unsigned long v1, unsigned long v2);

#endif /* _CONSTANTS_H_ */