aboutsummaryrefslogtreecommitdiff
path: root/include/env_flags.h
blob: 7e72523f02666e06db474b2c7d49f63b35ab49d1 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * (C) Copyright 2012
 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * 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.
 *
 * 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
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#ifndef __ENV_FLAGS_H__
#define __ENV_FLAGS_H__

enum env_flags_vartype {
	env_flags_vartype_string,
	env_flags_vartype_decimal,
	env_flags_vartype_hex,
	env_flags_vartype_bool,
#ifdef CONFIG_CMD_NET
	env_flags_vartype_ipaddr,
	env_flags_vartype_macaddr,
#endif
	env_flags_vartype_end
};

#define ENV_FLAGS_VAR ".flags"
#define ENV_FLAGS_ATTR_MAX_LEN 2
#define ENV_FLAGS_VARTYPE_LOC 0

#ifndef CONFIG_ENV_FLAGS_LIST_STATIC
#define CONFIG_ENV_FLAGS_LIST_STATIC ""
#endif

#define ENV_FLAGS_LIST_STATIC \
	CONFIG_ENV_FLAGS_LIST_STATIC

#ifdef CONFIG_CMD_ENV_FLAGS
/*
 * Print the whole list of available type flags.
 */
void env_flags_print_vartypes(void);
/*
 * Return the name of the type.
 */
const char *env_flags_get_vartype_name(enum env_flags_vartype type);
#endif

/*
 * Parse the flags string from a .flags attribute list into the vartype enum.
 */
enum env_flags_vartype env_flags_parse_vartype(const char *flags);

#ifdef USE_HOSTCC
/*
 * Look up the type of a variable directly from the .flags var.
 */
enum env_flags_vartype env_flags_get_type(const char *name);
/*
 * Validate the newval for its type to conform with the requirements defined by
 * its flags (directly looked at the .flags var).
 */
int env_flags_validate_type(const char *name, const char *newval);
/*
 * Validate the parameters passed to "env set" for type compliance
 */
int env_flags_validate_env_set_params(int argc, char * const argv[]);

#else /* !USE_HOSTCC */

#include <search.h>

/*
 * When adding a variable to the environment, initialize the flags for that
 * variable.
 */
void env_flags_init(ENTRY *var_entry);

/*
 * Validate the newval for to conform with the requirements defined by its flags
 */
int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
	int flag);

/*
 * These are the binary flags used in the environment entry->flags variable to
 * decribe properties of veriables in the table
 */
#define ENV_FLAGS_VARTYPE_BIN_MASK	0x00000007
/* The actual variable type values use the enum value (within the mask) */

#endif /* USE_HOSTCC */

#endif /* __ENV_FLAGS_H__ */