3 Copyright (c) 2013, Broadcom Europe Ltd
4 Copyright (c) 2013, James Hughes
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 * Neither the name of the copyright holder nor the
15 names of its contributors may be used to endorse or promote products
16 derived from this software without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
22 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * Code for handling command line parameters
34 * \date 4th March 2013
35 * \Author: James Hughes
39 * Some functions/structures for command line parameter parsing
47 #include "interface/vcos/vcos.h"
53 * Convert a string from command line to a comand_id from the list
55 * @param commands Array of command to check
56 * @param num_command Number of commands in the array
57 * @param arg String to search for in the list
58 * @param num_parameters Returns the number of parameters used by the command
60 * @return command ID if found, -1 if not found
63 int raspicli_get_command_id(const COMMAND_LIST *commands, const int num_commands, const char *arg, int *num_parameters)
68 vcos_assert(commands);
69 vcos_assert(num_parameters);
72 if (!commands || !num_parameters || !arg)
75 for (j = 0; j < num_commands; j++)
77 if (!strcmp(arg, commands[j].command) ||
78 !strcmp(arg, commands[j].abbrev))
81 command_id = commands[j].id;
82 *num_parameters = commands[j].num_parameters;
92 * Display the list of commands in help format
94 * @param commands Array of command to check
95 * @param num_command Number of commands in the arry
99 void raspicli_display_help(const COMMAND_LIST *commands, const int num_commands)
103 vcos_assert(commands);
108 for (i = 0; i < num_commands; i++)
110 fprintf(stderr, "-%s, -%s\t: %s\n", commands[i].abbrev,
111 commands[i].command, commands[i].help);
117 * Function to take a string, a mapping, and return the int equivalent
118 * @param str Incoming string to match
119 * @param map Mapping data
120 * @param num_refs The number of items in the mapping data
121 * @return The integer match for the string, or -1 if no match
123 int raspicli_map_xref(const char *str, const XREF_T *map, int num_refs)
127 for (i=0;i<num_refs;i++)
129 if (!strcasecmp(str, map[i].mode))
131 return map[i].mmal_mode;
138 * Function to take a mmal enum (as int) and return the string equivalent
139 * @param en Incoming int to match
140 * @param map Mapping data
141 * @param num_refs The number of items in the mapping data
142 * @return const pointer to string, or NULL if no match
144 const char *raspicli_unmap_xref(const int en, const XREF_T *map, int num_refs)
148 for (i=0;i<num_refs;i++)
150 if (en == map[i].mmal_mode)