1 /* SPDX-License-Identifier: BSD-2-Clause-Views */
4 * Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
5 * Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
6 * Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
7 * Copyright 2008 oharboe - Øyvind Harboe - oyvind.harboe@zylin.com
8 * Copyright 2008 Andrew Lunn <andrew@lunn.ch>
9 * Copyright 2008 Duane Ellis <openocd@duaneellis.com>
10 * Copyright 2008 Uwe Klein <uklein@klein-messgeraete.de>
11 * Copyright 2008 Steve Bennett <steveb@workware.net.au>
12 * Copyright 2009 Nico Coesel <ncoesel@dealogic.nl>
13 * Copyright 2009 Zachary T Welch zw@superlucidity.net
14 * Copyright 2009 David Brownell
15 * Copyright (c) 2005-2011 Jim Tcl Project. All rights reserved.
17 * This file is extracted from jim-nvp.h, originally part of jim TCL code.
20 #ifndef OPENOCD_HELPER_NVP_H
21 #define OPENOCD_HELPER_NVP_H
23 #include <helper/compiler.h>
25 /** Name Value Pairs, aka: NVP
26 * - Given a string - return the associated int.
27 * - Given a number - return the associated string.
30 * Very useful when the number is not a simple index into an array of
31 * known string, or there may be multiple strings (aliases) that mean then same
34 * An NVP Table is terminated with ".name = NULL".
36 * During the 'name2value' operation, if no matching string is found
37 * the pointer to the terminal element (with p->name == NULL) is returned.
41 * const struct nvp yn[] = {
50 * result = nvp_name2value(yn, "yes");
52 * result = nvp_name2value(yn, "no");
54 * result = nvp_name2value(yn, "Blah");
58 * During the number2name operation, the first matching value is returned.
66 struct command_invocation
;
68 /* Name Value Pairs Operations */
69 const struct nvp
*nvp_name2value(const struct nvp
*nvp_table
, const char *name
)
70 __returns_nonnull
__nonnull((1));
71 const struct nvp
*nvp_value2name(const struct nvp
*nvp_table
, int v
)
72 __returns_nonnull
__nonnull((1));
74 void nvp_unknown_command_print(struct command_invocation
*cmd
, const struct nvp
*nvp
,
75 const char *param_name
, const char *param_value
);
77 #endif /* OPENOCD_HELPER_NVP_H */