summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2018-01-04 00:33:20 +0100
committerRichard Braun <rbraun@sceen.net>2018-01-04 00:33:20 +0100
commite73fbdf59b292e7329502e532ace765bcbbe3821 (patch)
tree149036a6e79a201e98415e1fb256b1c8596b6012
parentc1ebfc97887a8efbd02b25379cc40d1086d0ad46 (diff)
shell: new SHELL_REGISTER_CMDS macro
-rw-r--r--shell.c14
-rw-r--r--shell.h16
2 files changed, 17 insertions, 13 deletions
diff --git a/shell.c b/shell.c
index 05bfde5..820d020 100644
--- a/shell.c
+++ b/shell.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015 Richard Braun.
+ * Copyright (c) 2015-2018 Richard Braun.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1191,16 +1191,6 @@ shell_run(void)
void
shell_setup(void)
{
- unsigned long i;
- int error;
-
pthread_mutex_init(&shell_lock, NULL);
-
- for (i = 0; i < ARRAY_SIZE(shell_default_cmds); i++) {
- error = shell_cmd_register(&shell_default_cmds[i]);
-
- if (error) {
- error_die(error);
- }
- }
+ SHELL_REGISTER_CMDS(shell_default_cmds);
}
diff --git a/shell.h b/shell.h
index 367ef2e..b843a1a 100644
--- a/shell.h
+++ b/shell.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015 Richard Braun.
+ * Copyright (c) 2015-2018 Richard Braun.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -31,6 +31,20 @@
#include <stddef.h>
+#include <error.h>
+#include <macros.h>
+
+#define SHELL_REGISTER_CMDS(cmds) \
+MACRO_BEGIN \
+ size_t ___i; \
+ int ___error; \
+ \
+ for (___i = 0; ___i < ARRAY_SIZE(cmds); ___i++) { \
+ ___error = shell_cmd_register(&(cmds)[___i]); \
+ error_check(___error, __func__); \
+ } \
+MACRO_END
+
typedef void (*shell_fn_t)(int argc, char *argv[]);
struct shell_cmd {