コード例 #1
0
ファイル: database.c プロジェクト: hhirsch/abook
/*
 * Merging works as follows:
 * - fields present only in source are copied over to dest
 * - multi-fields (email, groups) are checked for dupes ad merged
 * */
void
item_merge(list_item dest, list_item src)
{
	int i, found = 0;
	abook_list *dfield, *sfield, *ed, *es;

	for(i = 0; i < fields_count; i++)
		if (src[i]) {
			if (!dest[i])
			       dest[i] = xstrdup(src[i]);
			else if((i == field_id(EMAIL)) || (i == field_id(GROUPS))) {
				dfield = csv_to_abook_list(dest[i]);
				sfield = csv_to_abook_list(src[i]);
				for(es = sfield; es; es = es->next) {
					for(found=0, ed = dfield; (!found) && ed; ed = ed->next)
						found = (0 == strcmp(es->data,ed->data));
					if (!found)
						abook_list_append(&dfield, es->data);
				}
				xfree(dest[i]);
				dest[i] = abook_list_to_csv(dfield);
				abook_list_free(&dfield);
				abook_list_free(&sfield);
			}
		}

	item_empty(src);
}
コード例 #2
0
ファイル: database.c プロジェクト: jens-na/abook-call
/* Memory has to be freed by the caller */
char *
db_email_get(int item)
{
	int i;
	char *res;
	abook_field_list *cur;
	abook_list *emails = NULL;

	for(cur = fields_list, i = 0; cur; cur = cur->next, i++)
		if(cur->field->type == FIELD_EMAILS && *database[item][i])
			abook_list_append(&emails, database[item][i]);

	res = abook_list_to_csv(emails);
	abook_list_free(&emails);
	return res ? res : xstrdup("");
}