gt: Make defining default function for command_parse possible
authorPawel Szewczyk <p.szewczyk@samsung.com>
Wed, 13 Aug 2014 11:46:49 +0000 (13:46 +0200)
committerPawel Szewczyk <p.szewczyk@samsung.com>
Wed, 20 Aug 2014 13:31:58 +0000 (15:31 +0200)
It's not error, when standard command parse reach end of arguments list.
We can define some non-help-printing behavior for this situation.

Change-Id: Ib4bed570f385883d8cda5f79b648cfc31cef1e2a
Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
source/base/src/command.c

index c56124d..90808d8 100644 (file)
 
 static inline bool name_matches(const char *candidate, const char *pattern)
 {
-       // If string is NULL it suits to all strings
+       // If pattern is NULL it suits only to NULL
+       if (!pattern)
+               return !candidate;
+       // If candidate is NULL it suits to all strings
        return (candidate && (strcmp(candidate, pattern) == 0))
                        || (!candidate);
 }
@@ -40,12 +43,6 @@ void command_parse(const Command *cmd, int argc, char **argv,
        const Command *next = cmd->getChildren(cmd);
        bool found = false;
 
-       // If there is nothing more to parse it's error
-       if (argc == 0) {
-               executable_command_set(exec, cmd->printHelp, data, NULL);
-               return;
-       }
-
        while (next->parse) {
                if (name_matches(next->name, *argv)) {
                        found = true;