From d0c910dc4257b3c4ab80710375191d68d08da4ae Mon Sep 17 00:00:00 2001
From: Alessandro Rubini <rubini@gnudd.com>
Date: Thu, 27 Oct 2016 11:27:28 +0200
Subject: [PATCH] shell/cmd_ptp: use a data structure for arguments

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
---
 shell/cmd_ptp.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/shell/cmd_ptp.c b/shell/cmd_ptp.c
index bd61a8845..43e449a68 100644
--- a/shell/cmd_ptp.c
+++ b/shell/cmd_ptp.c
@@ -6,19 +6,28 @@
 
 #include <errno.h>
 #include <string.h>
+#include <wrpc.h>
 #include "wrc_ptp.h"
 #include "shell.h"
 
+struct subcmd {
+	char *name;
+	int (*fun)(int);
+	int arg;
+} subcmd[] = {
+	{"start", wrc_ptp_run, 1},
+	{"stop", wrc_ptp_run, 0},
+};
+
 static int cmd_ptp(const char *args[])
 {
-	if (!strcasecmp(args[0], "start"))
-		return wrc_ptp_start();
-	else if (!strcasecmp(args[0], "stop"))
-		return wrc_ptp_stop();
-	else
-		return -EINVAL;
+	int i;
+	struct subcmd *c;
 
-	return 0;
+	for (i = 0, c = subcmd; i < ARRAY_SIZE(subcmd); i++, c++)
+		if (!strcasecmp(args[0], c->name))
+			return c->fun(c->arg);
+	return -EINVAL;
 }
 
 DEFINE_WRC_COMMAND(ptp) = {
-- 
GitLab