OpenOCD
nvp.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-2-Clause-Views
2 
3 /*
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.
16  *
17  * This file is extracted from jim-nvp.c, originally part of jim TCL code.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include <string.h>
25 
26 #include <helper/command.h>
27 #include <helper/nvp.h>
28 
29 const struct nvp *nvp_name2value(const struct nvp *p, const char *name)
30 {
31  while (p->name) {
32  if (strcmp(name, p->name) == 0)
33  break;
34  p++;
35  }
36  return p;
37 }
38 
39 const struct nvp *nvp_value2name(const struct nvp *p, int value)
40 {
41  while (p->name) {
42  if (value == p->value)
43  break;
44  p++;
45  }
46  return p;
47 }
48 
50  const char *param_name, const char *param_value)
51 {
52  if (param_name)
53  command_print_sameline(cmd, "%s: Unknown: %s, try one of: ", param_name, param_value);
54  else
55  command_print_sameline(cmd, "Unknown param: %s, try one of: ", param_value);
56 
57  while (nvp->name) {
58  if ((nvp + 1)->name)
60  else
61  command_print(cmd, "or %s", nvp->name);
62 
63  nvp++;
64  }
65 
66  /* We assume nvp to be not empty and loop has been taken; no need to add a '\n' */
67 }
const char * name
Definition: armv4_5.c:76
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
Definition: command.c:420
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:443
void nvp_unknown_command_print(struct command_invocation *cmd, const struct nvp *nvp, const char *param_name, const char *param_value)
Definition: nvp.c:49
const struct nvp * nvp_name2value(const struct nvp *p, const char *name)
Definition: nvp.c:29
const struct nvp * nvp_value2name(const struct nvp *p, int value)
Definition: nvp.c:39
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Definition: command.h:76
Name Value Pairs, aka: NVP.
Definition: nvp.h:61
int value
Definition: nvp.h:63
const char * name
Definition: nvp.h:62
uint8_t cmd
Definition: vdebug.c:1