]> git.deb.at Git - pkg/abook.git/blob - database.h
mutt import filter changes
[pkg/abook.git] / database.h
1 #ifndef _DATABASE_H
2 #define _DATABASE_H
3
4
5 #define MAX_EMAILS              4
6 #define MAX_EMAIL_LEN           80
7 #define MAX_EMAILSTR_LEN        (MAX_EMAILS*MAX_EMAIL_LEN + MAX_EMAILS + 1)
8 #define MAX_FIELD_LEN           81
9
10 enum {
11         NAME,
12         EMAIL,
13         ADDRESS,
14         ADDRESS2,
15         CITY,
16         STATE,
17         ZIP,
18         COUNTRY,
19         PHONE,
20         WORKPHONE,
21         FAX,
22         MOBILEPHONE,
23         NICK,
24         URL,
25         NOTES,
26         ITEM_FIELDS /* this is the last */
27 };
28
29 #define LAST_FIELD              (ITEM_FIELDS - 1)
30
31 typedef char * list_item[ITEM_FIELDS];
32
33 struct abook_field {
34         char *name;
35         char *key;
36         int tab;
37 };
38
39 enum {
40         ENUM_ALL,
41         ENUM_SELECTED
42 };
43
44 struct db_enumerator {
45         int item;
46         int mode; /* warning: read only */
47 };
48
49 int             parse_database(FILE *in);
50 int             write_database(FILE *out, struct db_enumerator e);
51 int             load_database(char *filename);
52 int             save_database();
53 void            close_database();
54 int             add_item2database(list_item item);
55 void            free_list_item(list_item item);
56 void            remove_selected_items();
57 void            sort_surname();
58 void            sort_by_field(int field);
59 char            *get_surname(char *s);
60 int             find_item(char *str, int start, int search_fields[]);
61 int             is_selected(int item);
62 int             is_valid_item(int item);
63
64 int             real_db_enumerate_items(struct db_enumerator e);
65 struct db_enumerator    init_db_enumerator(int mode);
66
67 #define LAST_ITEM       (items - 1)
68
69 #define itemcpy(dest, src)      memmove(dest, src, sizeof(list_item))
70
71 #define split_emailstr(item, emails) do {\
72         int _i,_j,_k,len; \
73         memset(&emails, 0, sizeof(emails) ); \
74         len = strlen(database[item][EMAIL]); \
75         for( _i=0,_j=0, _k=0; _i < len && _j < MAX_EMAILS; _i++ ) { \
76                 if( database[item][EMAIL][_i] ==',' ) { \
77                         _j++; \
78                         _k = 0; \
79                 } else \
80                         if( _k < MAX_EMAIL_LEN -1 ) \
81                                 emails[_j][_k++] = database[item][EMAIL][_i]; \
82         } \
83 } while(0)
84
85 #define have_multiple_emails(item) \
86         strchr(database[item][EMAIL], ',')
87
88 #define db_enumerate_items(e) \
89         while( -1 != (e.item = real_db_enumerate_items(e)))
90
91 #endif