]> git.deb.at Git - pkg/abook.git/blobdiff - database.c
- whitespace changes
[pkg/abook.git] / database.c
index 5da2e93eced4b440c54ac3accaa2713d9a92d264..259c63c6414cf359aa8867f06d209ddaa1412347 100644 (file)
 #      include "config.h"
 #endif
 
-static void    free_item(int i);
-
-
 list_item *database = NULL;
 
 int items = 0;
 
 #define INITIAL_LIST_CAPACITY  30
 
-int list_capacity = 0;
+static int list_capacity = 0;
 
 extern int first_list_item;
 extern int curitem;
 extern char *selected;
 
 extern char *datafile;
-extern char *rcfile;
 
 /*
  * field definitions
@@ -60,7 +56,7 @@ struct abook_field abook_fields[ITEM_FIELDS] = {
        {"Name",        "name",         TAB_CONTACT},/* NAME */
        {"E-mails",     "email",        TAB_CONTACT},/* EMAIL */
        {"Address",     "address",      TAB_ADDRESS},/* ADDRESS */
-       {"Address2",    "address2",     TAB_ADDRESS},/* ADDRESS2 */   
+       {"Address2",    "address2",     TAB_ADDRESS},/* ADDRESS2 */
        {"City",        "city",         TAB_ADDRESS},/* CITY */
        {"State/Province","state",      TAB_ADDRESS},/* STATE */
        {"ZIP/Postal Code","zip",       TAB_ADDRESS},/* ZIP */
@@ -101,7 +97,7 @@ parse_database(FILE *in)
        list_item item;
 
        memset(&item, 0, sizeof(item));
-       
+
        for(;;) {
                line = getaline(in);
                if( feof(in) ) {
@@ -140,7 +136,7 @@ next:
        return 0;
 }
 
-               
+
 
 int
 load_database(char *filename)
@@ -152,7 +148,7 @@ load_database(char *filename)
 
        if ( (in = abook_fopen(filename, "r")) == NULL )
                return -1;
-       
+
        parse_database(in);
 
        return (items == 0) ? 2 : 0;
@@ -198,17 +194,17 @@ save_database()
        if( (out = abook_fopen(datafile, "w")) == NULL )
                return -1;
 
-       if( list_is_empty() ) {
+       if(list_is_empty()) {
                fclose(out);
                unlink(datafile);
                return 1;
        }
 
-       
+
        write_database(out, e);
-       
+
        fclose(out);
-       
+
        return 0;
 }
 
@@ -231,7 +227,7 @@ void
 close_database()
 {
        int i;
-       
+
        for(i=0; i < items; i++)
                free_item(i);
 
@@ -253,7 +249,7 @@ validate_item(list_item item)
 {
        int i;
        char *tmp;
-       
+
        if(item[EMAIL] == NULL)
                item[EMAIL] = strdup("");
 
@@ -286,12 +282,12 @@ adjust_list_capacity()
 int
 add_item2database(list_item item)
 {
-       if( item[NAME] == NULL || ! *item[NAME] ) {
+       if(item[NAME] == NULL || ! *item[NAME]) {
                free_list_item(item);
                return 1;
        }
 
-       if( ++items > list_capacity)
+       if(++items > list_capacity)
                adjust_list_capacity();
 
        validate_item(item);
@@ -307,27 +303,26 @@ remove_selected_items()
 {
        int i, j;
 
-       if( list_is_empty() )
+       if(list_is_empty())
                return;
 
-       if( ! selected_items() )
-               selected[ curitem ] = 1;
-       
-       for( j = LAST_ITEM; j >= 0; j-- ) {
-               if( selected[j] ) {
+       if(!selected_items())
+               selected[curitem] = 1;
+
+       for(j = LAST_ITEM; j >= 0; j--) {
+               if(selected[j]) {
                        free_item(j); /* added for .4 data_s_ */
-                       for( i = j; i < LAST_ITEM; i++ ) {
-                               itemcpy(database[ i ], database[ i + 1 ]);
-                               selected[ i ] = selected[ i + 1 ];
+                       for(i = j; i < LAST_ITEM; i++) {
+                               itemcpy(database[i], database[i + 1]);
+                               selected[i] = selected[i + 1];
                        }
-                       items--;        
+                       items--;
                }
        }
 
-       if( curitem > LAST_ITEM && items > 0 )
+       if(curitem > LAST_ITEM && items > 0)
                curitem = LAST_ITEM;
 
-
        adjust_list_capacity();
 
        select_none();
@@ -379,8 +374,8 @@ namecmp(const void *i1, const void *i2)
 
        itemcpy(a, i1);
        itemcpy(b, i2);
-       
-       return safe_strcoll( a[sort_field], b[sort_field] );
+
+       return safe_strcoll(a[sort_field], b[sort_field]);
 }
 
 static int
@@ -415,7 +410,7 @@ sort_by_field(int field)
        }
 
        sort_field = field;
-       
+
        qsort((void *)database, items, sizeof(list_item), namecmp);
 
        refresh_screen();
@@ -482,7 +477,7 @@ real_db_enumerate_items(struct db_enumerator e)
 {
        int item = max(0, e.item + 1);
        int i;
-       
+
        switch(e.mode) {
 #ifdef DEBUG
                case ENUM_ALL:
@@ -533,7 +528,7 @@ assign_fieldname(const char *name, int i)
                 */
                if(strcasecmp(abook_fields[i].name, abook_fields[i].key))
                        xfree(abook_fields[i].name);
-               
+
                s = xmalloc_inc(MAX_FIELDNAME_LEN, 1);
                snprintf(s, MAX_FIELDNAME_LEN, "%s", name);
                abook_fields[i].name = s;