Пример #1
0
Файл: setenv.c Проект: kelu27/42
int				ft_setenv(char ***env, char *name, char *value, int overwrite)
{
	int		i;
	int		size;
	int		n;

	i = 0;
	size = strstrlen(*env);
	name = ft_strjoin(name, "=");
	n = ft_strlen(name);
	while (i < size)
	{
		if (ft_strnequ(name, (*env)[i], n) && overwrite != 0)
		{
			free((*env)[i]);
			(*env)[i] = get_new_value(name, value);
			if ((*env)[i] == NULL)
				return (0);
			return (1);
		}
		else if (ft_strnequ(name, (*env)[i], n) && overwrite == 0)
			return (0);
		i++;
	}
	if (i == size)
		add_in_env(env, name, value, size);
	return (1);
}
Пример #2
0
STATUS append_int_to_entry(int number, entry *entry_ptr)
{
	value *new_value_ptr;
	STATUS get_new_value_status = get_new_value(number, &new_value_ptr);
	if(get_new_value_status != OK)
	{
		DEBUG("append_int_to_entry->get_new_value_status !OK\n");
		return get_new_value_status;
	}
    return append_value_to_entry(new_value_ptr, entry_ptr);
}
Пример #3
0
STATUS push_int_on_entry(int number, entry *target_entry)
{
	value *new_value;
	STATUS get_new_value_status = get_new_value(number, &new_value);
	if(get_new_value_status != OK)
	{
		DEBUG("push_int_on_entry->get_new_value_status !OK\n");
		return get_new_value_status;
	}
	return push_value_on_entry(new_value, target_entry);
}
Пример #4
0
double
update_degree_of_membership() {
    int i, j;
    double new_uij;
    double max_diff = 0.0, diff;
    for (j = 0; j < num_clusters; j++) {
        for (i = 0; i < num_data_points; i++) {
            new_uij = get_new_value(i, j);
            diff = new_uij - degree_of_memb[i][j];
            if (diff > max_diff)
                max_diff = diff;
            degree_of_memb[i][j] = new_uij;
        }
    }
    return max_diff;
}
Пример #5
0
STATUS restore_snapshot_by_snapshot(snapshot *target_snapshot, entry *entry_head)
{
	STATUS free_entries_status = free_entries_from_head(entry_head);
	if(free_entries_status != OK)
	{
		DEBUG("restore_snapshot_by_snapshot->free_entries_status !OK\n");
		return free_entries_status;
	}
	entry *snapshot_entry_cursor = target_snapshot->entries->next;
	entry *entry_head_cursor = entry_head->next;
	while(snapshot_entry_cursor)
	{
		STATUS get_new_entry_status = get_new_entry(snapshot_entry_cursor->key, &entry_head_cursor);
		if(get_new_entry_status != OK)
		{
			DEBUG("restore_snapshot_by_snapshot->get_new_entry_status !OK\n");
			return get_new_entry_status;
		}
		STATUS append_entry_status = push_entry_on_entry_head(entry_head_cursor, entry_head);
		if(append_entry_status != OK)
		{
			DEBUG("restore_snapshot_by_snapshot->append_entry_status !OK\n");
			return append_entry_status;
		}
		value *snapshot_value_cursor = snapshot_entry_cursor->values->next;
		value *value_head_cursor = entry_head_cursor->values->next;
		while(snapshot_value_cursor)
		{
			STATUS get_new_value_status = get_new_value(snapshot_value_cursor->value, &value_head_cursor);
			if(get_new_value_status != OK)
			{
				DEBUG("restore_snapshot_by_snapshot->get_new_value_status !OK\n");
				return get_new_value_status;
			}
			STATUS append_value_status = append_value_to_entry(value_head_cursor, entry_head_cursor);
			if(append_value_status != OK)
			{
				DEBUG("restore_snapshot_by_snapshot->append_value_status !OK\n");
				return append_value_status;
			}
			snapshot_value_cursor = snapshot_value_cursor->next;
		}
		snapshot_entry_cursor = snapshot_entry_cursor->next;
		entry_head_cursor = entry_head_cursor->next;
	}
	return OK;
}
Пример #6
0
Файл: setenv.c Проект: kelu27/42
static void		add_in_env(char ***env, char *name, char *value, int size)
{
	char	**new_env;
	int		i;

	i = 0;
	if (!(new_env = (char **)malloc(sizeof(char *) * (size + 2))))
		ft_error(1, "add_in_env");
	while (i < size)
	{
		new_env[i] = ft_strdup(*(*env + i));
		i++;
	}
	new_env[i] = get_new_value(name, value);
	new_env[i + 1] = '\0';
	free(*env);
	*env = new_env;
}