about summary refs log tree commit diff stats
path: root/src/tools
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-04-09 21:31:43 +0100
committerJames Booth <boothj5@gmail.com>2014-04-09 21:31:43 +0100
commitc3e3759256bc9b8f53f1334c3a352877d28846e1 (patch)
treec6946ed61f0f7678ae7c5df758c7f201394b7b6f /src/tools
parent6275644de4a4177889950f852c8307002f629d47 (diff)
downloadprofani-tty-c3e3759256bc9b8f53f1334c3a352877d28846e1.tar.gz
Command argument parsers set result argument
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/parser.c14
-rw-r--r--src/tools/parser.h4
2 files changed, 12 insertions, 6 deletions
diff --git a/src/tools/parser.c b/src/tools/parser.c
index 4e746557..932fd9aa 100644
--- a/src/tools/parser.c
+++ b/src/tools/parser.c
@@ -48,9 +48,10 @@
  *
  */
 gchar **
-parse_args(const char * const inp, int min, int max)
+parse_args(const char * const inp, int min, int max, gboolean *result)
 {
     if (inp == NULL) {
+        *result = FALSE;
         return NULL;
     }
 
@@ -122,6 +123,7 @@ parse_args(const char * const inp, int min, int max)
     if ((num < min) || (num > max)) {
         g_slist_free_full(tokens, free);
         g_free(copy);
+        *result = FALSE;
         return NULL;
 
     // if min allowed is 0 and 0 found, return empty char* array
@@ -130,6 +132,7 @@ parse_args(const char * const inp, int min, int max)
         gchar **args = malloc((num + 1) * sizeof(*args));
         args[0] = NULL;
         g_free(copy);
+        *result = TRUE;
         return args;
 
     // otherwise return args array
@@ -147,7 +150,7 @@ parse_args(const char * const inp, int min, int max)
         args[arg_count] = NULL;
         g_slist_free_full(tokens, free);
         g_free(copy);
-
+        *result = TRUE;
         return args;
     }
 }
@@ -179,9 +182,10 @@ parse_args(const char * const inp, int min, int max)
  *
  */
 gchar **
-parse_args_with_freetext(const char * const inp, int min, int max)
+parse_args_with_freetext(const char * const inp, int min, int max, gboolean *result)
 {
     if (inp == NULL) {
+        *result = FALSE;
         return NULL;
     }
 
@@ -267,12 +271,14 @@ parse_args_with_freetext(const char * const inp, int min, int max)
     // if num args not valid return NULL
     if ((num < min) || (num > max)) {
         g_slist_free_full(tokens, free);
+        *result = FALSE;
         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;
+        *result = TRUE;
         return args;
 
     // otherwise return args array
@@ -289,7 +295,7 @@ parse_args_with_freetext(const char * const inp, int min, int max)
 
         args[arg_count] = NULL;
         g_slist_free_full(tokens, free);
-
+        *result = TRUE;
         return args;
     }
 }
diff --git a/src/tools/parser.h b/src/tools/parser.h
index c82199d4..f03fca81 100644
--- a/src/tools/parser.h
+++ b/src/tools/parser.h
@@ -25,8 +25,8 @@
 
 #include <glib.h>
 
-gchar** parse_args(const char * const inp, int min, int max);
-gchar** parse_args_with_freetext(const char * const inp, int min, int max);
+gchar** parse_args(const char * const inp, int min, int max, gboolean *result);
+gchar** parse_args_with_freetext(const char * const inp, int min, int max, gboolean *result);
 int count_tokens(char *string);
 char* get_start(char *string, int tokens);