Exemple #1
0
int	search_coli(t_scene *scene, t_cam *cam, t_point *point)
{
  int		color;
  double	k;
  t_object	*tmp;
  t_object	*tmp2;
  t_point	*p;

  tmp2 = scene->obj;
  p = rotate(point, cam);
  k = search_k(scene, cam, p, &tmp);
  if (k <= 0.0)
    color = 0;
  else
    {
      if (tmp && search_attr(tmp->attr, COL_STR) != NULL)
	color = my_getnbr(search_attr(tmp->attr, COL_STR));
      else
	color = COLOR;
     scene->obj = tmp2;
      color = calc_light(tmp, calc_vect(p), scene, k);
    }
  scene->obj = tmp2;
  return (color);
}
Exemple #2
0
int conf_set_attr(const char *attr, const char *val)
{
	int old_len, new_len;
	struct sysconfig *cfg;
	char line[LINE_LEN];
	int ret = 0;

	cfg = _syscfg_open();

	ret = search_attr(cfg, attr);
	if (ret < 0) {
		SC_DEBUG("Attribute \"%s\" does not exists, set attr error\n", attr);
		goto L1;
	}

	old_len = ret + 1; // add  '\n'

	new_len = snprintf(line, sizeof(line), "%s = %s\n", attr, val);
	printf("new attr = %s\n", line);

	if (new_len != old_len) {
		memmove(cfg->data + cfg->offset - old_len + new_len,
			cfg->data + cfg->offset, cfg->size - cfg->offset);
		cfg->size += new_len - old_len;
	}

	memcpy(cfg->data + cfg->offset - old_len, line, new_len);

	cfg->is_dirty = true;

L1:
	_syscfg_close(cfg);

	return ret;
}
Exemple #3
0
int conf_del_attr(const char *attr)
{
	struct sysconfig *cfg;
	int ret = 0;
	int len;

	cfg = _syscfg_open();

	ret = search_attr(cfg, attr);
	if (ret < 0) {
		SC_DEBUG("Attribute \"%s\" does not exist, del attr error!\n", attr);
		goto L1;
	}

	len = ret + 1;

	memcpy(cfg->data + cfg->offset - len, cfg->data + cfg->offset, cfg->size - cfg->offset);

	cfg->size -= len;

	cfg->is_dirty = true;
L1:
	_syscfg_close(cfg);

	return ret;
}
Exemple #4
0
int conf_get_attr(const char *attr, char val[])
{
	const char *start, *end;
	struct sysconfig *cfg;
	char line[LINE_LEN];
	int ret = 0;

	cfg = _syscfg_open();

	ret = search_attr(cfg, attr);
	if (ret < 0) {
		SC_DEBUG("Attribute \"%s\" does not exists.\n", attr);
		goto L1;
	}

	cfg->offset -= ret + 1;
	_syscfg_read_line(cfg, line, sizeof(line));
	start = strchr(line, '=');
	start++;

	while (*start == ' ') start++;
	if (*start == '"') start++;

	end = line + strlen(line);
	while (end > line && *end == ' ') end--;

	if (*end == '"') end--;

	while (start <= end) {
		*val++ = *start;
		start++;
	}

	*val = '\0';

L1:
	_syscfg_close(cfg);

	return ret < 0 ? ret : 0;
}
Exemple #5
0
int conf_add_attr(const char *attr, const char *val)
{
	struct sysconfig *cfg;
	int ret = 0;

	cfg = _syscfg_open();

	if (search_attr(cfg, attr) > 0) {
		SC_DEBUG("Fail to add attribute \"%s\"! (already exists)\n", attr);
		ret = -EBUSY;
		goto L1;
	}

	cfg->size += sprintf(cfg->data + cfg->offset, "%s = %s\n", attr, val);

	cfg->is_dirty = true;

L1:
	_syscfg_close(cfg);

	return ret;
}