]> git.deb.at Git - pkg/abook.git/commitdiff
Remove duplicates
authorFabio Zanini <fabio.zanini@fastmail.fm>
Mon, 2 Jul 2012 11:34:30 +0000 (13:34 +0200)
committerRaphaël Droz <raphael.droz+floss@gmail.com>
Wed, 24 Oct 2012 14:11:37 +0000 (16:11 +0200)
database.c
database.h
help.h
ui.c
ui.h

index b38dbe0947aad033b3b5269e7a01618749b9e7dc..03d0abbe9443db5a8bc3c7efe32c38a10da37675 100644 (file)
@@ -557,6 +557,33 @@ void merge_selected_items()
        select_none();
 }
 
+void remove_duplicates()
+{
+       int i,j,k;
+       char *tmpj;
+       if(list_is_empty())
+               return;
+
+       /* Scan from the last one */
+       for(j = LAST_ITEM - 1; j >= 0; j--) {
+               tmpj = db_name_get(j);
+               for(i = LAST_ITEM; i > j; i--)
+                       /* Check name and merge if dups */
+                       if (0 == strcmp(tmpj,db_name_get(i))) {
+                               item_merge(database[j],database[i]);
+                               if (curitem == i) curitem--;
+                               for(k = i; k < LAST_ITEM; k++) {
+                                       item_copy(database[k], database[k + 1]);
+                               }
+                               item_free(&database[LAST_ITEM]);
+                               items--;
+                       }
+       }
+
+       adjust_list_capacity();
+}
+
+
 char *
 get_surname(char *s)
 {
index 13e137dd6951a016ca589fab9e80e4da8ce96e23..4d33ff478179f0886f2b09571881c6119752ce42 100644 (file)
@@ -82,6 +82,7 @@ int write_database(FILE *out, struct db_enumerator e);
 int save_database();
 void remove_selected_items();
 void merge_selected_items();
+void remove_duplicates();
 void sort_surname();
 void sort_by_field(char *field);
 void close_database();
diff --git a/help.h b/help.h
index a97b5ecbedb3b1b9aa17544db312780c1a620f42..1e713b68bdda90ac6879ddd95d79c85abfc2dda3 100644 (file)
--- a/help.h
+++ b/help.h
@@ -20,6 +20,7 @@ N_("  a               add item\n"),
 N_("   r / del         remove selected items\n"),
 N_("   M               merge selected items (into top one)\n"),
 N_("   D               duplicate item\n"),
+N_("   U               remove duplicates\n"),
 "\n",
 N_("   space           select item\n"),
 N_("   +               select all\n"),
diff --git a/ui.c b/ui.c
index 2e5756547533523946aa5a3225a9dafcb99e44c2..8fd38ae0ecb6b2ce69ebacb16be44157e138f0c3 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -579,6 +579,7 @@ get_commands()
                        case 'r': ui_remove_items();    break;
                        case 'M': ui_merge_items();     break;
                        case 'D': duplicate_item();     break;
+                       case 'U': ui_remove_duplicates(); break;
                        case 12: refresh_screen();      break;
 
                        case 'k':
@@ -669,6 +670,15 @@ ui_merge_items()
        refresh_list();
 }
 
+void           ui_remove_duplicates()
+{
+       if(statusline_ask_boolean(_("Remove duplicates"), TRUE))
+               remove_duplicates();
+       
+       clear_statusline();
+       refresh_list();
+}
+
 void
 ui_clear_database()
 {
diff --git a/ui.h b/ui.h
index 3faed77be1fb47bc11d8a92424987a5add7210b6..b94bffea4189973e3e5229fb6d8a51fe02c3c975 100644 (file)
--- a/ui.h
+++ b/ui.h
@@ -30,6 +30,7 @@ void          refresh_statusline();
 void           get_commands();
 void           ui_remove_items();
 void           ui_merge_items();
+void           ui_remove_duplicates();
 void           ui_clear_database();
 void           ui_find(int next);
 void           ui_print_number_of_items();