Ejemplo n.º 1
0
void
move_curitem(int direction)
{
        list_item tmp;

        if(curitem < 0 || curitem > last_item())
                return;

	tmp = item_create();
	item_copy(tmp, db_item_get(curitem));

	switch(direction) {
		case MOVE_ITEM_UP:
			if( curitem < 1 )
				goto out_move;
			item_copy(db_item_get(curitem),
					db_item_get(curitem - 1));
			item_copy(db_item_get(curitem-1), tmp);
			scroll_up();
			break;

		case MOVE_ITEM_DOWN:
			if(curitem >= last_item())
				goto out_move;
			item_copy(db_item_get(curitem),
					db_item_get(curitem + 1));
			item_copy(db_item_get(curitem + 1), tmp);
			scroll_down();
			break;
	}

out_move:
	item_free(&tmp);
}
Ejemplo n.º 2
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();
}
Ejemplo n.º 3
0
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();
}
Ejemplo n.º 4
0
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();
}
Ejemplo n.º 5
0
Archivo: dict.c Proyecto: HarmtH/vim
/*
 * Make a copy of dict "d".  Shallow if "deep" is FALSE.
 * The refcount of the new dict is set to 1.
 * See item_copy() for "copyID".
 * Returns NULL when out of memory.
 */
    dict_T *
dict_copy(dict_T *orig, int deep, int copyID)
{
    dict_T	*copy;
    dictitem_T	*di;
    int		todo;
    hashitem_T	*hi;

    if (orig == NULL)
	return NULL;

    copy = dict_alloc();
    if (copy != NULL)
    {
	if (copyID != 0)
	{
	    orig->dv_copyID = copyID;
	    orig->dv_copydict = copy;
	}
	todo = (int)orig->dv_hashtab.ht_used;
	for (hi = orig->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi)
	{
	    if (!HASHITEM_EMPTY(hi))
	    {
		--todo;

		di = dictitem_alloc(hi->hi_key);
		if (di == NULL)
		    break;
		if (deep)
		{
		    if (item_copy(&HI2DI(hi)->di_tv, &di->di_tv, deep,
							      copyID) == FAIL)
		    {
			vim_free(di);
			break;
		    }
		}
		else
		    copy_tv(&HI2DI(hi)->di_tv, &di->di_tv);
		if (dict_add(copy, di) == FAIL)
		{
		    dictitem_free(di);
		    break;
		}
	    }
	}

	++copy->dv_refcount;
	if (todo > 0)
	{
	    dict_unref(copy);
	    copy = NULL;
	}
    }

    return copy;
}
Ejemplo n.º 6
0
void domain_copy(domain ds, domain dt) {
  int i;
  /* don't copy things that will be unchanged */
  frontlist_copy(ds->classorder, dt->classorder);
  for (i = 0; i < ds->nclassmax; i++) {
    itemclass_copy(ds->classes[i], dt->classes[i]);   
  }
  for (i = 0; i < ds->nitem; i++) {
    item_copy(ds->items[i], dt->items[i]);   
  }
  dt->alpha = ds->alpha;
  dt->prior = ds->prior;
}
Ejemplo n.º 7
0
/*
 * Make a copy of list "orig".  Shallow if "deep" is FALSE.
 * The refcount of the new list is set to 1.
 * See item_copy() for "copyID".
 * Returns NULL when out of memory.
 */
    list_T *
list_copy(list_T *orig, int deep, int copyID)
{
    list_T	*copy;
    listitem_T	*item;
    listitem_T	*ni;

    if (orig == NULL)
	return NULL;

    copy = list_alloc();
    if (copy != NULL)
    {
	if (copyID != 0)
	{
	    /* Do this before adding the items, because one of the items may
	     * refer back to this list. */
	    orig->lv_copyID = copyID;
	    orig->lv_copylist = copy;
	}
	for (item = orig->lv_first; item != NULL && !got_int;
							 item = item->li_next)
	{
	    ni = listitem_alloc();
	    if (ni == NULL)
		break;
	    if (deep)
	    {
		if (item_copy(&item->li_tv, &ni->li_tv, deep, copyID) == FAIL)
		{
		    vim_free(ni);
		    break;
		}
	    }
	    else
		copy_tv(&item->li_tv, &ni->li_tv);
	    list_append(copy, ni);
	}
	++copy->lv_refcount;
	if (item != NULL)
	{
	    list_unref(copy);
	    copy = NULL;
	}
    }

    return copy;
}
Ejemplo n.º 8
0
item * gen_item(gclass_t * cl, int lvl)
{
	gclass_t * mat_cl;
	item * it;

	it = item_copy(gen(cl, lvl));

	if (it->mat_class != NULL) {
		mat_cl = get_gclass(it->mat_class, world.gmats);
		item_apply_mat(it, gen(mat_cl, lvl));
	}
	
	info("Generated a %s", it->name);

	return it;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
static int item(struct dir *item) {
  struct dir *t;

  /* Go back to parent dir */
  if(!item) {
    curdir = curdir->parent;
    return 0;
  }

  item = item_copy(item);
  item_add(item);

  /* Ensure that any next items will go to this directory */
  if(item->flags & FF_DIR)
    curdir = item;

  /* Special-case the name of the root item to be empty instead of "/". This is
   * what getpath() expects. */
  if(item == root && strcmp(item->name, "/") == 0)
    item->name[0] = 0;

  /* Update stats of parents. Don't update the size/asize fields if this is a
   * possible hard link, because hlnk_check() will take care of it in that
   * case. */
  if(item->flags & FF_HLNKC) {
    addparentstats(item->parent, 0, 0, 1);
    hlink_check(item);
  } else
    addparentstats(item->parent, item->size, item->asize, 1);

  /* propagate ERR and SERR back up to the root */
  if(item->flags & FF_SERR || item->flags & FF_ERR)
    for(t=item->parent; t; t=t->parent)
      t->flags |= FF_SERR;

  dir_output.size = root->size;
  dir_output.items = root->items;

  return 0;
}