From: Fabio Zanini Date: Mon, 2 Jul 2012 11:34:30 +0000 (+0200) Subject: Remove duplicates X-Git-Tag: upstream/0.6.1~2^2~57 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=e39ba13b9c7e5518770173245751780896ae542f;p=pkg%2Fabook.git Remove duplicates --- diff --git a/database.c b/database.c index b38dbe0..03d0abb 100644 --- a/database.c +++ b/database.c @@ -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) { diff --git a/database.h b/database.h index 13e137d..4d33ff4 100644 --- a/database.h +++ b/database.h @@ -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 a97b5ec..1e713b6 100644 --- 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 2e57565..8fd38ae 100644 --- 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 3faed77..b94bffe 100644 --- 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();