]> git.deb.at Git - pkg/abook.git/blobdiff - database.c
- make it compile with tcc
[pkg/abook.git] / database.c
index aecdf8271982151bbd926774d7a6e47e78afe01e..0b9b58e6b1c18e750fa508469727f8f73b364569 100644 (file)
@@ -100,39 +100,38 @@ parse_database(FILE *in)
 
        for(;;) {
                line = getaline(in);
-               if( feof(in) ) {
-                       if( item[NAME] && sec )
+               if(feof(in)) {
+                       if(item[NAME] && sec)
                                add_item2database(item);
                        else
                                free_list_item(item);
                        break;
                }
 
-               if( !*line || *line == '\n' || *line == '#' ) {
-                       free(line);
-                       continue;
-               } else if( *line == '[' ) {
+               if(!*line || *line == '\n' || *line == '#') {
+                       goto next;
+               } else if(*line == '[') {
                        if( item[NAME] && sec )
                                add_item2database(item);
                        else
                                free_list_item(item);
                        memset(&item, 0, sizeof(item));
                        sec = 1;
-                       if ( !(tmp = strchr(line, ']')))
+                       if(!(tmp = strchr(line, ']')))
                                sec = 0; /*incorrect section lines are skipped*/
-               } else if((tmp = strchr(line, '=') ) && sec ) {
+               } else if((tmp = strchr(line, '=') ) && sec) {
                        *tmp++ = '\0';
-                       for(i=0; i<ITEM_FIELDS; i++)
-                               if( !strcmp(abook_fields[i].key, line) ) {
+                       for(i = 0; i < ITEM_FIELDS; i++)
+                               if(!strcmp(abook_fields[i].key, line)) {
                                        item[i] = strdup(tmp);
                                        goto next;
                                }
                }
 next:
-               free(line);
+               xfree(line);
        }
 
-       free(line);
+       xfree(line);
        return 0;
 }
 
@@ -143,10 +142,10 @@ load_database(char *filename)
 {
        FILE *in;
 
-       if( database != NULL )
+       if(database != NULL)
                close_database();
 
-       if ( (in = abook_fopen(filename, "r")) == NULL )
+       if ((in = abook_fopen(filename, "r")) == NULL)
                return -1;
 
        parse_database(in);
@@ -282,12 +281,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);
@@ -303,27 +302,26 @@ remove_selected_items()
 {
        int i, j;
 
-       if( list_is_empty() )
+       if(list_is_empty())
                return;
 
-       if( ! selected_items() )
-               selected[ curitem ] = 1;
+       if(!selected_items())
+               selected[curitem] = 1;
 
-       for( j = LAST_ITEM; j >= 0; j-- ) {
-               if( selected[j] ) {
+       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--;
                }
        }
 
-       if( curitem > LAST_ITEM && items > 0 )
+       if(curitem > LAST_ITEM && items > 0)
                curitem = LAST_ITEM;
 
-
        adjust_list_capacity();
 
        select_none();
@@ -376,7 +374,7 @@ 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