Handle commands with min 0 args

This commit is contained in:
James Booth
2012-11-18 00:38:37 +00:00
parent 191ab83c9b
commit 312d362eaa
3 changed files with 39 additions and 0 deletions

View File

@@ -75,6 +75,12 @@ parse_args(const char * const inp, int min, int max, int *num)
*num = 0;
return NULL;
// if min allowed is 0 and 0 found, return empty char* array
} else if (min == 0 && *num == 0) {
gchar **args = malloc((*num + 1) * sizeof(*args));
args[0] = NULL;
return args;
// otherwise return args array
} else {
gchar **args = malloc((*num + 1) * sizeof(*args));
@@ -151,6 +157,12 @@ parse_args_with_freetext(const char * const inp, int min, int max, int *num)
*num = 0;
return NULL;
// if min allowed is 0 and 0 found, return empty char* array
} else if (min == 0 && *num == 0) {
gchar **args = malloc((*num + 1) * sizeof(*args));
args[0] = NULL;
return args;
// otherwise return args array
} else {
gchar **args = malloc((*num + 1) * sizeof(*args));

View File

@@ -26,5 +26,6 @@
#include <glib.h>
gchar** parse_args(const char * const inp, int min, int max, int *num);
gchar** parse_args_with_freetext(const char * const inp, int min, int max, int *num);
#endif