introduces tag filter string parser (currently supporting a simple tag list)

Wed, 30 May 2018 16:25:57 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 30 May 2018 16:25:57 +0200
changeset 391
10305c5b0a16
parent 390
26998dc980f9
child 392
4853fbad5014

introduces tag filter string parser (currently supporting a simple tag list)

dav/sopt.c file | annotate | diff | comparison | revisions
dav/sync.c file | annotate | diff | comparison | revisions
dav/sync.h file | annotate | diff | comparison | revisions
--- a/dav/sopt.c	Wed May 30 16:06:03 2018 +0200
+++ b/dav/sopt.c	Wed May 30 16:25:57 2018 +0200
@@ -61,22 +61,6 @@
                         cmd_args_free(a);
                         return NULL;
                     }
-                    /*
-                    case 'k': {
-                        if(!option) {
-                            option = "key";
-                            optchar = 'k';
-                        } else {
-                            fprintf(
-                                    stderr,
-                                    "Missing argument for option -%c\n",
-                                    optchar);
-                            cmd_args_free(a);
-                            return NULL;
-                        }
-                        break;
-                    }
-                    */
                     case 'c': {
                         ucx_map_cstr_put(a->options, "conflict", NOARG);
                         break;
--- a/dav/sync.c	Wed May 30 16:06:03 2018 +0200
+++ b/dav/sync.c	Wed May 30 16:25:57 2018 +0200
@@ -255,6 +255,19 @@
     return 1;
 }
 
+SyncTagFilter* parse_tagfilter_string(const char* filterstring) {
+    if (!filterstring) {
+        return NULL;
+    }
+    
+    SyncTagFilter* tagfilter = malloc(sizeof(SyncTagFilter));
+    tagfilter->mode = DAV_SYNC_TAGFILTER_AND;
+    tagfilter->subfilter_count = 0;
+    tagfilter->tags = parse_csv_taglist(filterstring, strlen(filterstring));
+    
+    return tagfilter;
+}
+
 static int matches_tags_and(UcxList *dav_tags, UcxList *tags, int ignorecase) {
     UCX_FOREACH(e, tags) {
         if (!ucx_list_contains(dav_tags, e->data,
@@ -519,16 +532,8 @@
                 continue;
             }
             
-            // TODO: remove this fake and let the cmd parser store the filter
-            SyncTagFilter tagfilter;
-            tagfilter.mode = DAV_SYNC_TAGFILTER_AND;
-            tagfilter.subfilter_count = 0;
-            tagfilter.tags = NULL;
-            char *tags_str = cmd_getoption(a, "tags");
-            if(tags_str) {
-                tagfilter.tags = parse_csv_taglist(tags_str, strlen(tags_str));
-            }
-            if (!res_matches_tags(res, &tagfilter)) {
+            if (!res_matches_tags(res,
+                    parse_tagfilter_string(cmd_getoption(a, "tags")))) {
                 if(!cmd_getoption(a, "remove")) {
                     localres_keep(db, res->path);
                 }
--- a/dav/sync.h	Wed May 30 16:06:03 2018 +0200
+++ b/dav/sync.h	Wed May 30 16:25:57 2018 +0200
@@ -129,6 +129,7 @@
     size_t subfilter_count;
     SyncTagFilter* subfilters;
 };
+SyncTagFilter* parse_tagfilter_string(const char* filterstring);
 
 int cmd_add_tag(CmdArgs *args);
 int cmd_remove_tag(CmdArgs *args);

mercurial