# HG changeset patch # User Mike Becker # Date 1527690357 -7200 # Node ID 10305c5b0a16e9f73dea584e63e26a9f232a393a # Parent 26998dc980f97efdaeafbf0c7c8af20dcc023ef8 introduces tag filter string parser (currently supporting a simple tag list) diff -r 26998dc980f9 -r 10305c5b0a16 dav/sopt.c --- 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; diff -r 26998dc980f9 -r 10305c5b0a16 dav/sync.c --- 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); } diff -r 26998dc980f9 -r 10305c5b0a16 dav/sync.h --- 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);