diff options
Diffstat (limited to 'apps/plugins/lib/arg_helper.c')
-rw-r--r-- | apps/plugins/lib/arg_helper.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/apps/plugins/lib/arg_helper.c b/apps/plugins/lib/arg_helper.c index 3ea5ba714d..63b7acbb2b 100644 --- a/apps/plugins/lib/arg_helper.c +++ b/apps/plugins/lib/arg_helper.c | |||
@@ -31,7 +31,7 @@ | |||
31 | #ifdef PLUGIN | 31 | #ifdef PLUGIN |
32 | #define strchr rb->strchr | 32 | #define strchr rb->strchr |
33 | #endif | 33 | #endif |
34 | int string_parse(const char **parameter, char* buf, size_t buf_sz) | 34 | int string_parse(const char **parameter, char *buf, size_t buf_sz) |
35 | { | 35 | { |
36 | /* fills buf with a string upto buf_sz, null terminates the buffer | 36 | /* fills buf with a string upto buf_sz, null terminates the buffer |
37 | * strings break on WS by default but can be enclosed in single or double quotes | 37 | * strings break on WS by default but can be enclosed in single or double quotes |
@@ -44,6 +44,11 @@ int string_parse(const char **parameter, char* buf, size_t buf_sz) | |||
44 | char stopchars[] = "\'\""; | 44 | char stopchars[] = "\'\""; |
45 | int skipped = 0; | 45 | int skipped = 0; |
46 | int found = 0; | 46 | int found = 0; |
47 | if (!parameter || !*parameter) | ||
48 | { | ||
49 | *buf = '\0'; | ||
50 | return 0; | ||
51 | } | ||
47 | const char* start = *parameter; | 52 | const char* start = *parameter; |
48 | 53 | ||
49 | if (strchr(stopchars, *start)) | 54 | if (strchr(stopchars, *start)) |
@@ -79,7 +84,7 @@ int string_parse(const char **parameter, char* buf, size_t buf_sz) | |||
79 | return found + skipped; | 84 | return found + skipped; |
80 | } | 85 | } |
81 | 86 | ||
82 | int char_parse(const char **parameter, char* character) | 87 | int char_parse(const char **parameter, char *character) |
83 | { | 88 | { |
84 | /* passes *character a single character eats remaining non-WS characters */ | 89 | /* passes *character a single character eats remaining non-WS characters */ |
85 | char buf[2]; | 90 | char buf[2]; |
@@ -95,6 +100,8 @@ int bool_parse(const char **parameter, bool *choice) | |||
95 | /* determine true false using the first character the rest are skipped/ignored */ | 100 | /* determine true false using the first character the rest are skipped/ignored */ |
96 | int found = 0; | 101 | int found = 0; |
97 | const char tf_val[]="fn0ty1";/* false chars on left f/t should be balanced fffttt */ | 102 | const char tf_val[]="fn0ty1";/* false chars on left f/t should be balanced fffttt */ |
103 | if (!parameter || !*parameter) | ||
104 | return 0; | ||
98 | const char* start = *parameter; | 105 | const char* start = *parameter; |
99 | 106 | ||
100 | 107 | ||
@@ -133,7 +140,9 @@ int longnum_parse(const char **parameter, long *number, long *decimal) | |||
133 | int neg = 0; | 140 | int neg = 0; |
134 | int digits = 0; | 141 | int digits = 0; |
135 | //logf ("n: %s\n", *parameter); | 142 | //logf ("n: %s\n", *parameter); |
136 | const char *start = *parameter; | 143 | if (!parameter || !*parameter) |
144 | return 0; | ||
145 | const char* start = *parameter; | ||
137 | 146 | ||
138 | if (*start == '-') | 147 | if (*start == '-') |
139 | { | 148 | { |
@@ -209,7 +218,8 @@ int num_parse(const char **parameter, int *number, int *decimal) | |||
209 | * Note: WS at beginning is stripped, **parameter starts at the first NON WS char | 218 | * Note: WS at beginning is stripped, **parameter starts at the first NON WS char |
210 | * return 0 for arg_callback to quit parsing immediately | 219 | * return 0 for arg_callback to quit parsing immediately |
211 | */ | 220 | */ |
212 | void argparse(const char *parameter, int parameter_len, int (*arg_callback)(char argchar, const char **parameter)) | 221 | void argparse(const char *parameter, int parameter_len, void *userdata, |
222 | int (*arg_callback)(char argchar, const char **parameter, void *userdata)) | ||
213 | { | 223 | { |
214 | bool lastchr; | 224 | bool lastchr; |
215 | char argchar; | 225 | char argchar; |
@@ -222,7 +232,10 @@ void argparse(const char *parameter, int parameter_len, int (*arg_callback)(char | |||
222 | { | 232 | { |
223 | if ((*parameter) == '\0') | 233 | if ((*parameter) == '\0') |
224 | return; | 234 | return; |
225 | logf ("%s\n",parameter); | 235 | |
236 | if (parameter_len < 0) { logf ("%s\n", parameter); } | ||
237 | else { logf ("%.*s\n", plen, parameter); } | ||
238 | |||
226 | argchar = *parameter; | 239 | argchar = *parameter; |
227 | lastchr = (*(parameter + 1) == '\0'); | 240 | lastchr = (*(parameter + 1) == '\0'); |
228 | while (*++parameter || lastchr) | 241 | while (*++parameter || lastchr) |
@@ -230,7 +243,7 @@ void argparse(const char *parameter, int parameter_len, int (*arg_callback)(char | |||
230 | lastchr = false; | 243 | lastchr = false; |
231 | if (isspace(*parameter)) | 244 | if (isspace(*parameter)) |
232 | continue; /* eat spaces at beginning */ | 245 | continue; /* eat spaces at beginning */ |
233 | if (!arg_callback(argchar, ¶meter)) | 246 | if (!arg_callback(argchar, ¶meter, userdata)) |
234 | return; | 247 | return; |
235 | break; | 248 | break; |
236 | } | 249 | } |