port cmd_tagop() to ucx 3

Sun, 02 Jul 2023 10:37:44 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 02 Jul 2023 10:37:44 +0200
changeset 766
c4993f0991e4
parent 765
305ce525ad4a
child 767
f4acc783f25e

port cmd_tagop() to ucx 3

dav/sync.c file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Sun Jun 25 11:50:50 2023 +0200
+++ b/dav/sync.c	Sun Jul 02 10:37:44 2023 +0200
@@ -5242,10 +5242,6 @@
 }
 
 int cmd_tagop(CmdArgs *args, int cmd) {
-    // TODO: port to ucx 3
-    return 1;
-#if 0
-    
     SyncFile file;
     int ret = 0;
     char *path = args->argv[0];
@@ -5282,28 +5278,31 @@
         char *tagcolor = NULL; // TODO: get color
 
         tags = sync_get_file_tags(file.dir, localres, NULL, NULL);
-        CxList *x = NULL;
-        UCX_FOREACH(elm, tags) {
-            DavTag *t = elm->data;
+        CxIterator i = cxListIterator(tags ? tags : cxEmptyList);
+        int x = -1;
+        cx_foreach(DavTag *, t, i) {
             if(cmd == CMD_TAG_LIST) {
                 printf("%s\n", t->name);
             } else if(!strcmp(t->name, tag)) {
-                x = elm;
+                x = i.index;
                 break;
             }
         }
 
         if(cmd == CMD_TAG_ADD) {
-            if(!x) {
+            if(x < 0) {
                 DavTag *newtag = malloc(sizeof(DavTag));
                 newtag->name = tag;
                 newtag->color = tagcolor;
-                tags = ucx_list_append(tags, newtag);
+                if(!tags) {
+                    tags = cxLinkedListCreateSimple(CX_STORE_POINTERS);
+                }
+                cxListAdd(tags, newtag);
                 store_tags = TRUE;
             }
         } else if(cmd == CMD_TAG_REMOVE) {
-            if(tags) {
-                tags = ucx_list_remove(tags, x);
+            if(x >= 0) {
+                cxListRemove(tags, x);
             }
             store_tags = TRUE;
         }
@@ -5349,7 +5348,6 @@
     
     free(file.path);
     return ret;
-#endif
 }
 
 int isfileindir(SyncDirectory *dir, const char *path, SyncFile *f) {

mercurial