]> git.deb.at Git - pkg/abook.git/blob - database.h
mutt import filter is better nowadays
[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 };
27
28 #define LAST_FIELD              NOTES
29
30 #define ITEM_FIELDS             (LAST_FIELD+1)
31
32 typedef char * list_item[ITEM_FIELDS];
33
34 struct abook_field {
35         char *name;
36         char *key;
37         int tab;
38 };
39
40 enum {
41         ENUM_ALL,
42         ENUM_SELECTED
43 };
44
45 struct db_enumerator {
46         int item;
47         int mode; /* warning: read only */
48 };
49
50 int             parse_database(FILE *in);
51 int             write_database(FILE *out, struct db_enumerator e);
52 int             load_database(char *filename);
53 int             save_database();
54 void            close_database();
55 int             add_item2database(list_item item);
56 void            free_list_item(list_item item);
57 void            remove_selected_items();
58 void            sort_surname();
59 void            sort_database();
60 char            *get_surname(char *s);
61 int             find_item(char *str, int start, int search_fields[]);
62 int             is_selected(int item);
63 int             is_valid_item(int item);
64
65 int             real_db_enumerate_items(struct db_enumerator e);
66 struct db_enumerator    init_db_enumerator(int mode);
67
68 #define LAST_ITEM       (items - 1)
69
70 #define itemcpy(dest, src)      memmove(dest, src, sizeof(list_item))
71
72 #define split_emailstr(item, emails) do {\
73         int _i,_j,_k,len; \
74         memset(&emails, 0, sizeof(emails) ); \
75         len = strlen(database[item][EMAIL]); \
76         for( _i=0,_j=0, _k=0; _i < len && _j < MAX_EMAILS; _i++ ) { \
77                 if( database[item][EMAIL][_i] ==',' ) { \
78                         _j++; \
79                         _k = 0; \
80                 } else \
81                         if( _k < MAX_EMAIL_LEN -1 ) \
82                                 emails[_j][_k++] = database[item][EMAIL][_i]; \
83         } \
84 } while(0)
85
86 #define have_multiple_emails(item) \
87         strchr(database[item][EMAIL], ',')
88
89 #define db_enumerate_items(e) \
90         while( -1 != (e.item = real_db_enumerate_items(e)))
91
92 #endif