[PATCH 10/25] efw-downloader: add parser for sub commands

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This tool consists of sub commands for different functionalities.

This commit adds parser for sub commands. Actual implementation for
each sub command will be added in future commits.

Signed-off-by: Takashi Sakamoto <o-takashi@xxxxxxxxxxxxx>
---
 efw-downloader/src/main.c | 42 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/efw-downloader/src/main.c b/efw-downloader/src/main.c
index 31ac349..499e67e 100644
--- a/efw-downloader/src/main.c
+++ b/efw-downloader/src/main.c
@@ -1,8 +1,48 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 // Copyright (c) 2020 Takashi Sakamoto
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+
+static void print_help()
+{
+    printf("Usage\n"
+           "  efw-downloader SUBCOMMAND OPTIONS\n"
+           "\n"
+           "where:\n"
+           "  SUBCOMMAND:\n"
+           "    help:       print help\n"
+           "  OPTIONS:      optional arguments dependent on the subcommand\n");
+}
 
 int main(int argc, char **argv)
 {
-    return EXIT_SUCCESS;
+    static const struct {
+        const char *name;
+    size_t size;
+        int (*op)(int argc, char **argv);
+    } *entry, entries[] = {
+    };
+    const char *subcmd;
+    int i;
+
+    if (argc < 2) {
+        print_help();
+        return EXIT_FAILURE;
+    }
+    subcmd = argv[1];
+
+    for (i = 0; i < sizeof(entries) / sizeof(entries[0]); ++i) {
+        entry = entries + i;
+        if (strncmp(subcmd, entry->name, entry->size) == 0) {
+            entry = &entries[i];
+            break;
+        }
+    }
+    if (i == sizeof(entries) / sizeof(entries[0])) {
+        print_help();
+        return EXIT_FAILURE;
+    }
+
+    return entry->op(argc, argv);
 }
-- 
2.25.1




[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux