Exemplo n.º 1
0
void	my_choice(char **arr, int i, int *j)
{
  int	choice;

  choice = 0;
  while (tabchoice[choice][0])
    {
      if (tabchoice[choice][0] == arr[i][*j + 1])
	{
      	(void)write(0, &tabchoice[choice][1], 1);
	*j +=1;
	return ;
	}
      choice++;
    }
  if (choice > 7 && arr[i][*j + 1] == 'x')
    {
      my_getnbr_base(arr[i], "0123456789abcdef", *j, 2);
      *j += 2;
    }
  if (choice > 7 && arr[i][*j + 1] == '0')
    {
      my_getnbr_base(arr[i], "012345678", *j, 3);
      *j += 3;
    }
}
Exemplo n.º 2
0
void	get_obj_params(t_obj *obj, char *s, short *nb_obj)
{
  if (s[0] == '<' && s[1] != '/')
    obj->type = get_type(s);
  get_prs_params(obj, s);
  obj->id_grp = get_data_short("ID_GRP = ", s, obj->id_grp);
  obj->ra = get_data_short("RA = ", s, obj->ra);
  obj->rb = get_data_float("RB = ", s, obj->rb);
  obj->sp = get_data_short("SP = ", s, obj->sp);
  obj->br = get_data_float("BR = ", s, obj->br);
  obj->kd = get_data_float("Kd = ", s, obj->kd);
  obj->ks = get_data_float("Ks = ", s, obj->ks);
  obj->kr = get_data_float("Kr = ", s, obj->kr);
  obj->damier = get_data_short("DAMIER = ", s, obj->damier);
  if (my_strncmp("COLOR = ", s, 8) == 0)
    obj->color = (int)my_getnbr_base(&s[8], "0123456789ABCDEF");
  else if (my_strncmp("COLOR_IN = ", s, 11) == 0)
    obj->color_in = (int)my_getnbr_base(&s[11], "0123456789ABCDEF");
  else if (my_strncmp("COLOR_SP = ", s, 11) == 0)
    obj->color_sp = (int)my_getnbr_base(&s[11], "0123456789ABCDEF");
  else if (my_strncmp("TEXTURE = ", s, 10) == 0)
    obj->tex.file = my_strncpy(&s[10], 0, my_strlen(&s[9]));
  else if (my_strncmp("</", s, 2) == 0)
    obj->id = (*nb_obj)++;
}
Exemplo n.º 3
0
static int	my_set_var(t_object *object, char *str, int i)
{
  if (i == 0)
    my_position_x(object, my_getnbr(str));
  else if (i == 1)
    my_position_y(object, my_getnbr(str));
  else if (i == 2)
    my_position_z(object, my_getnbr(str));
  else if (i == 3)
    my_rotation_x(object, my_getnbr(str));
  else if (i == 4)
    my_rotation_y(object, my_getnbr(str));
  else if (i == 5)
    my_rotation_z(object, my_getnbr(str));
  else if (i == 6)
    {
      object->rayon = my_getnbr(str);
      if (my_strcmp(object->name, "cone") == 0)
	object->rayon = tan(object->rayon * MY_PI / 180);
    }
  else if (i == 7)
    object->color.color = my_getnbr_base(str, "0123456789ABCDEF");
  else
    return (-1);
  return (i);
}
Exemplo n.º 4
0
char    *convert_base(char *nbr, char *base_from, char *base_to)
{
  int   i;
  int   x;
  int   y;
  char  *result;
  int	sign;

  i = 0;
  x = my_getnbr_base(nbr, base_from);
  sign = 0;
  if (x == 0)
    return (my_strdup("0"));
  result = malloc(sizeof(char) * 500);
  if (x < 0)
    {
      x = - x;
      sign = 1;
    }
  y = my_strlen(base_to);
  while (x > 0)
    {
      result[i] = base_to[x % y];
      x = x / y;
      i = i + 1;
    }
  return (end_convert_base(result, sign, i));
}
Exemplo n.º 5
0
int	get_base(char **str)
{
    int	ibase;
    int	cond;

    cond = 0;
    ibase = 10;
    if (match("b*:*", *str))
    {
        ibase = my_getnbr_base(*str + 1, "0123456789");
        while (**str != ':')
            (*str)++;
    }
    else if (match("0x*", *str))
    {
        *str += 1;
        ibase = 16;
    }
    else if (match("0*", *str))
        ibase = 8;
    else if (match("b*", *str))
        ibase = 2;
    else
        cond = 1;
    if (!cond)
        (*str)++;
    return (ibase);
}
Exemplo n.º 6
0
int     compile_raw_code(t_opc *op, char **args)
{
  int   i;

  if (op == NULL || args == NULL || (op->args = gbgc_malloc(NULL, 1)) == NULL)
    return (0);
  op->size = 1;
  i = -1;
  while (args[++i] != NULL)
    {
      if (my_strlen(args[i]) >= 2)
        {
          args[i][2] = '\0';
          op->args[i] = my_getnbr_base(args[i], "0123456789ABCDEF");
          op->size += 1;
          if ((op->args = gbgc_realloc(op->args, op->size - 1, op->size)) ==
              NULL)
            return (0);
        }
      else
        return (0);
    }
  op->size -= 1;
  return (1);
}
Exemplo n.º 7
0
char	*convert_base(char *nbr, char *base_from, char *base_to)
{
  char	*res;
  int	nb;
  int	i;
  int	neg;

  res = malloc(sizeof(*res) * 100);
  nb = my_getnbr_base(nbr, base_from);
  neg = 0;
  if (nb < 0 && (neg = 1))
    nb *= -1;
  i = 0;
  do
    {
      res[i] = base_to[nb % my_strlen(base_to)];
      nb /= my_strlen(base_to);
      i++;
    } while (nb > 0);
  if (neg == 1)
    {
      res[i] = '-';
      i++;
    }
  res[i] = '\0';
  res = my_revstr(res);
  return (res);
}
Exemplo n.º 8
0
int		param_code_calc(char **instruct, char opcode, char *code)
{
  char		*type;
  char		*param_code;
  int		param_code_nb;
  int		j;

  if (opcode == 1 || opcode == 9 || opcode == 12 || opcode == 15)
    return (RET_SUCCESS);
  param_code = xmalloc(sizeof(char) * 9);
  param_code[0] = '\0';
  j = 1;
  while (instruct[j])
    {
      type = param_type(instruct[j]);
      my_strcat(param_code, type);
      free(type);
      j++;
    }
  while (j++ < 4)
    my_strcat(param_code, "00");
  my_strcat(param_code, "00");
  param_code_nb = my_getnbr_base(param_code, "01");
  free(param_code);
  return (coffee_write_nbr(code, param_code_nb, 1, UNSIGNED));
}
Exemplo n.º 9
0
t_color	*init_color(char *str)
{
    t_color	*color;
    int	composante;

    if ((color = xmalloc(sizeof(*color))) == NULL)
        return (NULL);
    composante = my_getnbr_base(str, BASE_STRING);
    color->red = (double)(composante >> 16);
    color->green = (double)((composante >> 8) % 256);
    color->blue = (double)(composante % 256);
    return (color);
}
Exemplo n.º 10
0
int	my_atoi(char *str)
{
    char	*base;
    int	ibase;

    if (match("0", str))
        return (0);
    base = my_strdup("0123456789abcdefghijklmnopqrstuvwxyz");
    ibase = get_base(&str);
    base[ibase] = '\0';
    ibase = my_getnbr_base(str, base);
    xfree(base);
    return (ibase);
}
Exemplo n.º 11
0
Arquivo: server.c Projeto: Wobow/Tek1
void	prompt_letter()
{
  int	c;

  c = my_getnbr_base(g_letter, "01");
  my_putchar(c);
  if (c > 127)
    exit(my_putstr("\n\nAn error has occur. Please retry.\n"));
  c = 0;
  while (c < 8)
    {
      g_letter[c] = '-';
      c++;
    }
}
Exemplo n.º 12
0
void	get_light_params(t_light *light, char *s, short *nb_light)
{
  if (s[0] == '<' && s[1] != '/')
    light->name = my_strncpy(s, 1, my_strlen(s) - 1);
  light->p.x = get_data_short("PX = ", s, light->p.x);
  light->p.y = get_data_short("PY = ", s, light->p.y);
  light->p.z = get_data_short("PZ = ", s, light->p.z);
  light->r.x = get_data_float("RX = ", s, light->r.x);
  light->r.y = get_data_float("RY = ", s, light->r.y);
  light->r.z = get_data_float("RZ = ", s, light->r.z);
  light->intensity = get_data_float("INTENSITY = ", s, light->intensity);
  if (my_strncmp("COLOR = ", s, 8) == 0)
    light->color = (int)my_getnbr_base(&s[8], "0123456789ABCDEF");
  if (my_strncmp("</", s, 2) == 0)
    ++(*nb_light);
}
Exemplo n.º 13
0
void	fill_single_token(char **str, t_tokens *last_node, int type)
{
  int	number;

  if (type == TOK_NUMBER)
  {
    number = my_getnbr_base(*str, "0123456789");
    last_node->type = TOK_NUMBER;
    last_node->value = number;
    while (**str >= '0' && **str <= '9')
      *str += 1;
  }
  else
  {
    last_node->type = type;
    last_node->value = 0;
    *str += 1;
  }
}
Exemplo n.º 14
0
char		*convert_base(char *nbr, char *base_from, char *base_to)
{
  int		n;
  char		*nbr2;
  int		base_n;
  int		i;

  i = 0;
  base_n = my_strlen(base_to);
  if (*nbr == 0 || *base_from == 0 || *base_to == 0)
    return (0);
  n = my_getnbr_base(nbr, base_from);
  if ((nbr2 = malloc(my_strlen(nbr) * sizeof (*nbr))) == NULL)
    return (NULL);
  while (n != 0)
    {
      n = n / base_n;
      nbr2[i] = base_to[n % base_n];
	i++;
    }
  return (nbr2);
}
Exemplo n.º 15
0
int     my_getnbr_base(char *str, char *base)
{
  int   nb_final;
  int   sizeofbase;
  int   sizeofstr;
  int   conv_fact;

  if (str[0] == '\0' || base[0] == '\0')
    return (0);
  if (str[0] == '-')
    return (-my_getnbr_base(str + 1, base));
  sizeofbase = my_strlen(base);
  sizeofstr = my_strlen(str) - 1;
  conv_fact = 1;
  nb_final = 0;
  while (sizeofstr >= 0)
    {
      nb_final = nb_final + base_nbr(str[sizeofstr], base) * conv_fact;
      conv_fact = sizeofbase * conv_fact;
      sizeofstr--;
    }
  return (nb_final);
}
Exemplo n.º 16
0
int	main(int ac, char **av)
{
  my_putnbr(my_getnbr_base(av[1], av[2]));
  my_putchar('\n');
  return (0);
}
Exemplo n.º 17
0
int			main(int ac, char **av)
{
  printf("%d\n", my_getnbr_base(av[2], av[1]));
}
Exemplo n.º 18
0
int	my_getnbr(char *str)
{
  return (my_getnbr_base(str, "0123456789"));
}
Exemplo n.º 19
0
int		my_getnbr(const char *str)
{
  return (my_getnbr_base(str, BASE_DEC));
}