app: Split subtree argument
Split the argument string on the first colon (:) character
to get the namespace and interface.
Change-Id: Ia9c67bd149c23e68945fd80252a93a2f1fe78382
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/libmapper/app.c b/libmapper/app.c
index 9713835..501a191 100644
--- a/libmapper/app.c
+++ b/libmapper/app.c
@@ -140,10 +140,21 @@
static int subtree_main(int argc, char *argv[])
{
int r = 0;
+ static const char* token = ":";
+ char* tmp = NULL;
+ char* namespace = NULL;
+ char* interface = NULL;
if (argc != 3) {
fprintf(stderr, "Usage: %s subtree-remove "
- "NAMESPACE:INTERFACE\n", argv[0]);
+ "NAMESPACE%sINTERFACE\n", argv[0], token);
+ exit(EXIT_FAILURE);
+ }
+
+ namespace = strtok_r(argv[2], token, &tmp);
+ interface = strtok_r(NULL, token, &tmp);
+ if ((namespace == NULL) || (interface == NULL)) {
+ fprintf(stderr, "Token '%s' was not found in '%s'\n", token, argv[2]);
exit(EXIT_FAILURE);
}