Gentoo Archives: gentoo-commits

From: "Tim Harder (radhermit)" <radhermit@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in app-misc/abook/files: abook-0.6.0_pre2-vcard-import.patch abook-0.6.0_pre2-vcard-fix.patch
Date: Sun, 03 Oct 2010 22:18:44
Message-Id: 20101003221840.7B8DD20051@flycatcher.gentoo.org
1 radhermit 10/10/03 22:18:40
2
3 Added: abook-0.6.0_pre2-vcard-import.patch
4 abook-0.6.0_pre2-vcard-fix.patch
5 Log:
6 Version bump (fixes bug #301502, thanks to Roger <rogerx@×××.org> for reporting), update to EAPI=3, apply patches for vCard import support, and use emake instead of make.
7
8 (Portage version: 2.2_rc88/cvs/Linux x86_64)
9
10 Revision Changes Path
11 1.1 app-misc/abook/files/abook-0.6.0_pre2-vcard-import.patch
12
13 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-misc/abook/files/abook-0.6.0_pre2-vcard-import.patch?rev=1.1&view=markup
14 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-misc/abook/files/abook-0.6.0_pre2-vcard-import.patch?rev=1.1&content-type=text/plain
15
16 Index: abook-0.6.0_pre2-vcard-import.patch
17 ===================================================================
18 diff -ru a/filter.c b/filter.c
19 --- a/filter.c 2006-09-06 07:26:10.000000000 +0200
20 +++ b/filter.c 2008-05-18 20:55:12.000000000 +0200
21 @@ -44,6 +44,7 @@
22 static int csv_parse_file(FILE *in);
23 static int allcsv_parse_file(FILE *in);
24 static int palmcsv_parse_file(FILE *in);
25 +static int vcard_parse_file(FILE *in);
26
27 /*
28 * export filter prototypes
29 @@ -75,6 +76,7 @@
30 { "csv", N_("comma separated values"), csv_parse_file },
31 { "allcsv", N_("comma separated values (all fields)"), allcsv_parse_file },
32 { "palmcsv", N_("Palm comma separated values"), palmcsv_parse_file },
33 + { "vcard", N_("vCard file"), vcard_parse_file },
34 { "\0", NULL, NULL }
35 };
36
37 @@ -1331,6 +1333,262 @@
38 */
39
40 /*
41 + * vCard import filter
42 + */
43 +
44 +static char *vcard_fields[] = {
45 + "FN", /* NAME */
46 + "EMAIL", /* EMAIL */
47 + "ADR", /* ADDRESS */
48 + "ADR", /* ADDRESS2 - not used */
49 + "ADR", /* CITY */
50 + "ADR", /* STATE */
51 + "ADR", /* ZIP */
52 + "ADR", /* COUNTRY */
53 + "TEL", /* PHONE */
54 + "TEL", /* WORKPHONE */
55 + "TEL", /* FAX */
56 + "TEL", /* MOBILEPHONE */
57 + "NICKNAME", /* NICK */
58 + "URL", /* URL */
59 + "NOTE", /* NOTES */
60 + NULL /* not implemented: ANNIVERSARY, ITEM_FIELDS */
61 +};
62 +
63 +/*
64 + * mappings between vCard ADR field and abook's ADDRESS
65 + * see rfc2426 section 3.2.1
66 + */
67 +static int vcard_address_fields[] = {
68 + -1, /* vCard(post office box) - not used */
69 + -1, /* vCard(the extended address) - not used */
70 + 2, /* vCard(the street address) - ADDRESS */
71 + 4, /* vCard(the locality) - CITY */
72 + 5, /* vCard(the region) - STATE */
73 + 6, /* vCard(the postal code) - ZIP */
74 + 7 /* vCard(the country name) - COUNTRY */
75 +};
76 +
77 +enum {
78 + VCARD_KEY = 0,
79 + VCARD_KEY_ATTRIBUTE,
80 + VCARD_VALUE,
81 +};
82 +
83 +static char *
84 +vcard_get_line_element(char *line, int element)
85 +{
86 + int i;
87 + char *line_copy = 0;
88 + char *result = 0;
89 + char *key = 0;
90 + char *key_attr = 0;
91 + char *value = 0;
92 +
93 + line_copy = xstrdup(line);
94 +
95 + /* make newline characters if exist end of string */
96 + for(i=0; line_copy[i]; i++) {
97 + if(line_copy[i] == '\r' || line_copy[i] == '\n') {
98 + line_copy[i] = '\0';
99 + break;
100 + }
101 + }
102 +
103 + /* separate key from value */
104 + for(i=0; line_copy[i]; i++) {
105 + if(line_copy[i] == ':') {
106 + line_copy[i] = '\0';
107 + key = line_copy;
108 + value = &line_copy[i+1];
109 + break;
110 + }
111 + }
112 +
113 + /* separate key from key attributes */
114 + if (key) {
115 + for(i=0; key[i]; i++) {
116 + if(key[i] == ';') {
117 + key[i] = '\0';
118 + key_attr = &key[i+1];
119 + break;
120 + }
121 + }
122 + }
123 +
124 + switch(element) {
125 + case VCARD_KEY:
126 + if(key)
127 + result = xstrdup(key);
128 + break;
129 + case VCARD_KEY_ATTRIBUTE:
130 + if(key_attr)
131 + result = xstrdup(key_attr);
132 + break;
133 + case VCARD_VALUE:
134 + if(value)
135 + result = xstrdup(value);
136 + break;
137 + }
138 +
139 + xfree(line_copy);
140 + return result;
141 +}
142 +
143 +static void
144 +vcard_parse_email(list_item item, char *line)
145 +{
146 + char *email;
147 +
148 + email = vcard_get_line_element(line, VCARD_VALUE);
149 +
150 + if(item[1]) {
151 + item[1] = strconcat(item[1], ",", email, 0);
152 + xfree(email);
153 + }
154 + else {
155 + item[1] = email;
156 + }
157 +}
158 +
159 +static void
160 +vcard_parse_address(list_item item, char *line)
161 +{
162 + int i;
163 + int k;
164 + char *value;
165 + char *address_field;
166 +
167 + value = vcard_get_line_element(line, VCARD_VALUE);
168 + if(!value)
169 + return;
170 +
171 + address_field = value;
172 + for(i=k=0; value[i]; i++) {
173 + if(value[i] == ';') {
174 + value[i] = '\0';
175 + if(vcard_address_fields[k] >= 0) {
176 + item[vcard_address_fields[k]] = xstrdup(address_field);
177 + }
178 + address_field = &value[i+1];
179 + k++;
180 + if((k+1)==(sizeof(vcard_address_fields)/sizeof(*vcard_address_fields)))
181 + break;
182 + }
183 + }
184 + item[vcard_address_fields[k]] = xstrdup(address_field);
185 + xfree(value);
186 +}
187 +
188 +static void
189 +vcard_parse_phone(list_item item, char *line)
190 +{
191 + int index = 8;
192 + char *type = vcard_get_line_element(line, VCARD_KEY_ATTRIBUTE);
193 + char *value = vcard_get_line_element(line, VCARD_VALUE);
194 +
195 + /* set the standard number */
196 + if (!type) {
197 + item[index] = value;
198 + }
199 +
200 + /*
201 + * see rfc2426 section 3.3.1
202 + */
203 + else if (strstr(type, "TYPE=") == type){
204 + if (strcasestr(type, "home")) {
205 + item[index] = xstrdup(value);
206 + }
207 + if (strcasestr(type, "work")) {
208 + item[index+1] = xstrdup(value);
209 + }
210 + if (strcasestr(type, "fax")) {
211 + item[index+2] = xstrdup(value);
212 + }
213 + if (strcasestr(type, "cell")) {
214 + item[index+3] = xstrdup(value);
215 + }
216 +
217 + xfree(type);
218 + xfree(value);
219 + }
220 +}
221 +
222 +static void
223 +vcard_parse_line(list_item item, char *line)
224 +{
225 + int i;
226 + char *key;
227 +
228 + for(i=0; vcard_fields[i]; i++) {
229 + key = vcard_fields[i];
230 +
231 + if(!strncmp(key, line, strlen(key))) {
232 + if(i == 1) {
233 + vcard_parse_email(item, line);
234 + }
235 + else if(i == 2) {
236 + vcard_parse_address(item, line);
237 + }
238 + else if(i == 8) {
239 + vcard_parse_phone(item, line);
240 + }
241 + else {
242 + item[i] = vcard_get_line_element(line, VCARD_VALUE);
243 + }
244 + break;
245 + }
246 + }
247 +}
248 +
249 +static void
250 +vcard_parse_item(FILE *in)
251 +{
252 + char *line = NULL;
253 + list_item item = item_create();
254 +
255 + while(!feof(in)) {
256 + line = getaline(in);
257 +
258 + if(line && !strncmp("END:VCARD", line, 9)) {
259 + xfree(line);
260 + break;
261 + }
262 + else if(line) {
263 + vcard_parse_line(item, line);
264 + xfree(line);
265 + }
266 + }
267 +
268 + add_item2database(item);
269 + item_free(&item);
270 +}
271 +
272 +static int
273 +vcard_parse_file(FILE *in)
274 +{
275 + char *line = NULL;
276 +
277 + while(!feof(in)) {
278 + line = getaline(in);
279 +
280 + if(line && !strncmp("BEGIN:VCARD", line, 11)) {
281 + xfree(line);
282 + vcard_parse_item(in);
283 + }
284 + else if(line) {
285 + xfree(line);
286 + }
287 + }
288 +
289 + return 0;
290 +}
291 +
292 +/*
293 + * end of vCard import filter
294 + */
295 +
296 +/*
297 * csv addressbook export filters
298 */
299
300 diff -ru a/misc.c b/misc.c
301 --- a/misc.c 2006-09-04 21:24:18.000000000 +0200
302 +++ b/misc.c 2008-05-18 18:00:33.000000000 +0200
303 @@ -77,6 +77,27 @@
304 return 1;
305 }
306
307 +char *
308 +strcasestr(char *haystack, char *needle)
309 +{
310 + int i;
311 + int k;
312 +
313 + assert(haystack != NULL);
314 + assert(needle != NULL);
315 +
316 + for(i=0; i<strlen(haystack)-strlen(needle)+1; i++) {
317 + for(k=0; k<strlen(needle); k++, i++) {
318 + if (tolower(haystack[i]) != tolower(needle[k]))
319 + break;
320 + else if ((k+1) == strlen(needle))
321 + return &haystack[i];
322 + }
323 + }
324 +
325 + return NULL;
326 +}
327 +
328
329 #ifdef HAVE_CONFIG_H
330 # include "config.h"
331 diff -ru a/misc.h b/misc.h
332 --- a/misc.h 2006-09-04 21:24:18.000000000 +0200
333 +++ b/misc.h 2008-05-18 17:55:59.000000000 +0200
334 @@ -18,6 +18,8 @@
335
336 int is_number(char *s);
337
338 +char *strcasestr(char *haystack, char *needle);
339 +
340 char *strdup_printf(const char *format, ... );
341 char *strconcat(const char *str, ...);
342
343
344
345
346 1.1 app-misc/abook/files/abook-0.6.0_pre2-vcard-fix.patch
347
348 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-misc/abook/files/abook-0.6.0_pre2-vcard-fix.patch?rev=1.1&view=markup
349 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-misc/abook/files/abook-0.6.0_pre2-vcard-fix.patch?rev=1.1&content-type=text/plain
350
351 Index: abook-0.6.0_pre2-vcard-fix.patch
352 ===================================================================
353 --- abook-0.6.0pre2/abook.c.orig 2010-10-03 14:54:23.827767178 -0700
354 +++ abook-0.6.0pre2/abook.c 2010-10-03 14:54:55.738042419 -0700
355 @@ -708,6 +708,7 @@
356 check_abook_directory();
357 init_opts();
358 load_opts(rcfile);
359 + init_standard_fields();
360 atexit(free_opts);
361
362 /*