1 /*
2 ** Copyright 2003 Double Precision, Inc.
3 ** See COPYING for distribution information.
4 */
5 
6 #if	HAVE_CONFIG_H
7 #include	"config.h"
8 #endif
9 #include	<stdio.h>
10 #include	<stdlib.h>
11 #include	<string.h>
12 #include	<errno.h>
13 #if	HAVE_UNISTD_H
14 #include	<unistd.h>
15 #endif
16 #include	"maildir/maildirkeywords.h"
17 
18 static struct libmail_kwHashtable h;
19 
20 int smapflag=0;
21 
count_flags(struct libmail_keywordEntry * dummy1,void * dummy)22 static int count_flags(struct libmail_keywordEntry *dummy1, void *dummy)
23 {
24 	++*(size_t *)dummy;
25 
26 	return 0;
27 }
28 
29 static struct libmail_kwMessage *msgs[3];
30 static const char * const flags[]={"apple", "banana", "pear", "grape"};
31 
32 
dump()33 static int dump()
34 {
35 	size_t cnt=0;
36 
37 	if (libmail_kwEnumerate(&h, &count_flags, &cnt))
38 		return -1;
39 
40 	printf("%d flags\n", (int)cnt);
41 
42 	for (cnt=0; cnt<sizeof(msgs)/sizeof(msgs[0]); cnt++)
43 	{
44 		struct libmail_kwMessageEntry *e;
45 
46 		printf("%d:", (int)cnt);
47 
48 		for (e=msgs[cnt]->firstEntry; e; e=e->next)
49 			printf(" %s", keywordName(e->libmail_keywordEntryPtr));
50 		printf("\n");
51 	}
52 	return 0;
53 
54 }
55 
main()56 int main()
57 {
58 	size_t i;
59 
60 	libmail_kwhInit(&h);
61 
62 	for (i=0; i<sizeof(msgs)/sizeof(msgs[0]); i++)
63 	{
64 		if ((msgs[i]=libmail_kwmCreate()) == NULL)
65 		{
66 			perror("malloc");
67 			exit(1);
68 		}
69 
70 		msgs[i]->u.userNum=i;
71 	}
72 
73 	if (libmail_kwmSetName(&h, msgs[0], flags[0]) >= 0 &&
74 	    libmail_kwmSetName(&h, msgs[1], flags[1]) >= 0 &&
75 	    libmail_kwmSetName(&h, msgs[2], flags[2]) >= 0 &&
76 	    libmail_kwmSetName(&h, msgs[0], flags[0]) >= 0 &&
77 	    libmail_kwmSetName(&h, msgs[0], flags[1]) >= 0 &&
78 	    libmail_kwmSetName(&h, msgs[1], flags[2]) >= 0 &&
79 	    libmail_kwmSetName(&h, msgs[2], flags[3]) >= 0)
80 	{
81 
82 		if (dump() == 0)
83 		{
84 			libmail_kwmClearName(msgs[2], flags[3]);
85 			libmail_kwmClearName(msgs[2], flags[3]);
86 			libmail_kwmClearName(msgs[0], flags[1]);
87 
88 			if (dump() == 0)
89 				exit(0);
90 		}
91 
92 	}
93 
94 	perror("ERROR");
95 	exit(1);
96 	return 0;
97 }
98