mirror of
https://github.com/owntracks/recorder.git
synced 2026-08-27 16:57:21 +00:00
ocat: splitter: properly this time
This commit is contained in:
@@ -166,12 +166,7 @@ int main(int argc, char **argv)
|
||||
|
||||
switch (c) {
|
||||
case 1: /* No short option */
|
||||
fields = json_mkarray();
|
||||
char *f[60], **ff;
|
||||
splitter(optarg, ",", f);
|
||||
for (ff = f; ff && *ff; ff++) {
|
||||
json_append_element(fields, json_mkstring(*ff));
|
||||
}
|
||||
fields = json_splitter(optarg, ",");
|
||||
break;
|
||||
case 'l':
|
||||
list = 1;
|
||||
|
||||
@@ -140,3 +140,24 @@ int splitter(char *s, char *sep, char **parts)
|
||||
free(ds);
|
||||
return (nt);
|
||||
}
|
||||
|
||||
/*
|
||||
* Split a string separated by characters in `sep' into a JSON
|
||||
* array and return that.
|
||||
*/
|
||||
|
||||
JsonNode *json_splitter(char *s, char *sep)
|
||||
{
|
||||
char *token, *ds = strdup(s);
|
||||
JsonNode *array = json_mkarray();
|
||||
|
||||
if (!ds || !array)
|
||||
return (NULL);
|
||||
|
||||
for (token = strtok(ds, sep); token && *token; token = strtok(NULL, sep)) {
|
||||
json_append_element(array, json_mkstring(token));
|
||||
}
|
||||
|
||||
free(ds);
|
||||
return (array);
|
||||
}
|
||||
|
||||
@@ -14,5 +14,6 @@ char *slurp_file(char *filename, int fold_newlines);
|
||||
int json_copy_to_object(JsonNode * obj, JsonNode * object_or_array, int clobber);
|
||||
int json_copy_from_file(JsonNode * obj, char *filename);
|
||||
int splitter(char *s, char *sep, char **parts);
|
||||
JsonNode *json_splitter(char *s, char *sep);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user