summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/lib/arg_helper.c25
-rw-r--r--apps/plugins/lib/arg_helper.h4
-rw-r--r--apps/plugins/pitch_screen.c5
3 files changed, 24 insertions, 10 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
34int string_parse(const char **parameter, char* buf, size_t buf_sz) 34int 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
82int char_parse(const char **parameter, char* character) 87int 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*/
212void argparse(const char *parameter, int parameter_len, int (*arg_callback)(char argchar, const char **parameter)) 221void 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, &parameter)) 246 if (!arg_callback(argchar, &parameter, userdata))
234 return; 247 return;
235 break; 248 break;
236 } 249 }
diff --git a/apps/plugins/lib/arg_helper.h b/apps/plugins/lib/arg_helper.h
index 2cf94ba1dd..638279ee42 100644
--- a/apps/plugins/lib/arg_helper.h
+++ b/apps/plugins/lib/arg_helper.h
@@ -54,7 +54,7 @@ int num_parse(const char **parameter, int *number, int *decimal);
54* Note: WS at beginning is stripped, **parameter starts at the first NON WS char 54* Note: WS at beginning is stripped, **parameter starts at the first NON WS char
55* return 0 for arg_callback to quit parsing immediately 55* return 0 for arg_callback to quit parsing immediately
56*/ 56*/
57void argparse(const char *parameter, int parameter_len, 57void argparse(const char *parameter, int parameter_len, void *userdata,
58 int (*arg_callback)(char argchar, const char **parameter)); 58 int (*arg_callback)(char argchar, const char **parameter, void *userdata));
59 59
60#endif /* _LIB_ARG_HELPER_H_ */ 60#endif /* _LIB_ARG_HELPER_H_ */
diff --git a/apps/plugins/pitch_screen.c b/apps/plugins/pitch_screen.c
index e24e0240a2..4af34fed3b 100644
--- a/apps/plugins/pitch_screen.c
+++ b/apps/plugins/pitch_screen.c
@@ -1120,8 +1120,9 @@ int gui_syncpitchscreen_run(void)
1120 return 0; 1120 return 0;
1121} 1121}
1122 1122
1123static int arg_callback(char argchar, const char **parameter) 1123static int arg_callback(char argchar, const char **parameter, void *userdata)
1124{ 1124{
1125 (void)userdata;
1125 int ret; 1126 int ret;
1126 long num, dec; 1127 long num, dec;
1127 bool bret; 1128 bool bret;
@@ -1232,7 +1233,7 @@ enum plugin_status plugin_start(const void* parameter)
1232 struct pvars cur; 1233 struct pvars cur;
1233 fill_pitchvars(&cur); 1234 fill_pitchvars(&cur);
1234 fill_pitchvars(&pitch_vars); 1235 fill_pitchvars(&pitch_vars);
1235 argparse((const char*) parameter, -1, &arg_callback); 1236 argparse((const char*) parameter, -1, NULL, &arg_callback);
1236 if (pitch_vars.pitch != cur.pitch) 1237 if (pitch_vars.pitch != cur.pitch)
1237 { 1238 {
1238 rb->sound_set_pitch(pitch_vars.pitch); 1239 rb->sound_set_pitch(pitch_vars.pitch);