예제 #1
0
void
remove_selected_items()
{
	int i, j;

	if(list_is_empty())
		return;

	if(!selected_items())
		selected[curitem] = 1;

	for(j = LAST_ITEM; j >= 0; j--) {
		if(selected[j]) {
			db_free_item(j); /* added for .4 data_s_ */
			for(i = j; i < LAST_ITEM; i++) {
				item_copy(database[i], database[i + 1]);
				selected[i] = selected[i + 1];
			}
			item_free(&database[LAST_ITEM]);
			items--;
		}
	}

	if(curitem > LAST_ITEM && items > 0)
		curitem = LAST_ITEM;

	adjust_list_capacity();

	select_none();
}
예제 #2
0
파일: database.c 프로젝트: hhirsch/abook
void remove_duplicates()
{
	int i,j,k;
	char *tmpj;
	if(list_is_empty())
		return;

	/* Scan from the last one */
	for(j = LAST_ITEM - 1; j >= 0; j--) {
		tmpj = db_name_get(j);
		for(i = LAST_ITEM; i > j; i--)
			/* Check name and merge if dups */
			if (0 == strcmp(tmpj,db_name_get(i))) {
				item_merge(database[j],database[i]);
				if (curitem == i) curitem--;
				for(k = i; k < LAST_ITEM; k++) {
					item_copy(database[k], database[k + 1]);
				}
				item_free(&database[LAST_ITEM]);
				items--;
			}
	}

	adjust_list_capacity();
}
예제 #3
0
파일: database.c 프로젝트: hhirsch/abook
void merge_selected_items()
{
	int i, j;
	int destitem = -1;

	if((list_is_empty()) || (selected_items() < 2))
		return;

	/* Find the top item */
	for(j=0; destitem < 0; j++)
		if(selected[j])
			destitem = j;

	/* Merge pairwise */
	for(j = LAST_ITEM; j > destitem; j--) {
		if(selected[j]) {
			item_merge(database[destitem],database[j]);
			for(i = j; i < LAST_ITEM; i++) {
				/* TODO: this can be done by moving pointers */
				item_copy(database[i], database[i + 1]);
				selected[i] = selected[i + 1];
			}
			item_free(&database[LAST_ITEM]);
			items--;
		}
	}

	if(curitem > LAST_ITEM && items > 0)
		curitem = LAST_ITEM;

	adjust_list_capacity();

	select_none();
}
예제 #4
0
int
add_item2database(list_item item)
{
	/* 'name' field is mandatory */
	if((item[field_id(NAME)] == NULL) || ! *item[field_id(NAME)]) {
		item_empty(item);
		return 1;
	}

	if(++items > list_capacity)
		adjust_list_capacity();

	validate_item(item);

	selected[LAST_ITEM] = 0;

	database[LAST_ITEM] = item_create();
        item_copy(database[LAST_ITEM], item);

	return 0;
}