···3131#ifdef PLUGIN
3232 #define strchr rb->strchr
3333#endif
3434-int string_parse(const char **parameter, char* buf, size_t buf_sz)
3434+int string_parse(const char **parameter, char *buf, size_t buf_sz)
3535{
3636/* fills buf with a string upto buf_sz, null terminates the buffer
3737 * strings break on WS by default but can be enclosed in single or double quotes
···4444 char stopchars[] = "\'\"";
4545 int skipped = 0;
4646 int found = 0;
4747+ if (!parameter || !*parameter)
4848+ {
4949+ *buf = '\0';
5050+ return 0;
5151+ }
4752 const char* start = *parameter;
48534954 if (strchr(stopchars, *start))
···7984 return found + skipped;
8085}
81868282-int char_parse(const char **parameter, char* character)
8787+int char_parse(const char **parameter, char *character)
8388{
8489/* passes *character a single character eats remaining non-WS characters */
8590 char buf[2];
···95100/* determine true false using the first character the rest are skipped/ignored */
96101 int found = 0;
97102 const char tf_val[]="fn0ty1";/* false chars on left f/t should be balanced fffttt */
103103+ if (!parameter || !*parameter)
104104+ return 0;
98105 const char* start = *parameter;
99106100107···133140 int neg = 0;
134141 int digits = 0;
135142 //logf ("n: %s\n", *parameter);
136136- const char *start = *parameter;
143143+ if (!parameter || !*parameter)
144144+ return 0;
145145+ const char* start = *parameter;
137146138147 if (*start == '-')
139148 {
···209218* Note: WS at beginning is stripped, **parameter starts at the first NON WS char
210219* return 0 for arg_callback to quit parsing immediately
211220*/
212212-void argparse(const char *parameter, int parameter_len, int (*arg_callback)(char argchar, const char **parameter))
221221+void argparse(const char *parameter, int parameter_len, void *userdata,
222222+ int (*arg_callback)(char argchar, const char **parameter, void *userdata))
213223{
214224 bool lastchr;
215225 char argchar;
···222232 {
223233 if ((*parameter) == '\0')
224234 return;
225225- logf ("%s\n",parameter);
235235+236236+ if (parameter_len < 0) { logf ("%s\n", parameter); }
237237+ else { logf ("%.*s\n", plen, parameter); }
238238+226239 argchar = *parameter;
227240 lastchr = (*(parameter + 1) == '\0');
228241 while (*++parameter || lastchr)
···230243 lastchr = false;
231244 if (isspace(*parameter))
232245 continue; /* eat spaces at beginning */
233233- if (!arg_callback(argchar, ¶meter))
246246+ if (!arg_callback(argchar, ¶meter, userdata))
234247 return;
235248 break;
236249 }
+2-2
apps/plugins/lib/arg_helper.h
···5454* Note: WS at beginning is stripped, **parameter starts at the first NON WS char
5555* return 0 for arg_callback to quit parsing immediately
5656*/
5757-void argparse(const char *parameter, int parameter_len,
5858- int (*arg_callback)(char argchar, const char **parameter));
5757+void argparse(const char *parameter, int parameter_len, void *userdata,
5858+ int (*arg_callback)(char argchar, const char **parameter, void *userdata));
59596060#endif /* _LIB_ARG_HELPER_H_ */