aboutsummaryrefslogtreecommitdiff
path: root/include/command.h
diff options
context:
space:
mode:
authorSimon Glass2023-11-18 14:05:20 -0700
committerTom Rini2023-12-13 11:51:24 -0500
commit8632b36b96d38a85f2e71603a6f90ec9e4e5e37e (patch)
tree90955cdb3d121e37567fe4226f9862566220af57 /include/command.h
parent1047b5340c1203f825c0a68b33997b787be0123e (diff)
command: Introduce functions to obtain command arguments
Add some functions which provide an argument to a command, or NULL if the argument does not exist. Use the same numbering as argv[] since it seems less confusing than the previous idea. Signed-off-by: Simon Glass <sjg@chromium.org> Suggested-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'include/command.h')
-rw-r--r--include/command.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/include/command.h b/include/command.h
index 5bd3ecbe8f9..4cec6345453 100644
--- a/include/command.h
+++ b/include/command.h
@@ -60,6 +60,39 @@ struct cmd_tbl {
#endif
};
+/**
+ * cmd_arg_get() - Get a particular argument
+ *
+ * @argc: Number of arguments
+ * @argv: Argument vector of length @argc
+ * @argnum: Argument to get (0=first)
+ * Return: Pointer to argument @argnum if it exists, else NULL
+ */
+static inline const char *cmd_arg_get(int argc, char *const argv[], int argnum)
+{
+ return argc > argnum ? argv[argnum] : NULL;
+}
+
+static inline const char *cmd_arg0(int argc, char *const argv[])
+{
+ return cmd_arg_get(argc, argv, 0);
+}
+
+static inline const char *cmd_arg1(int argc, char *const argv[])
+{
+ return cmd_arg_get(argc, argv, 1);
+}
+
+static inline const char *cmd_arg2(int argc, char *const argv[])
+{
+ return cmd_arg_get(argc, argv, 2);
+}
+
+static inline const char *cmd_arg3(int argc, char *const argv[])
+{
+ return cmd_arg_get(argc, argv, 3);
+}
+
#if defined(CONFIG_CMD_RUN)
int do_run(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[]);