예제 #1
0
void	resolv(char *base, char *opers, int *i, char **tabexpr, t_list **op, t_list **nb)
{
  char		*expr1;
  char		*operator;
  char		*expr2;
  
  my_put_in_list(op, tabexpr[*i]);
  *i = *i + 1;
  if (is_num(base, opers, tabexpr[*i]) == 1)
    my_put_in_list(nb, tabexpr[*i]);
  if (is_open_parent(opers, tabexpr[*i]) == 1)
    my_put_in_list(nb, parenthesis_mode(base, opers, i, tabexpr));
  if (is_low_op(opers, tabexpr[*i]))
    my_put_in_list(nb, check_sp_low(base, opers, i, tabexpr));
  if ((expr2 = malloc(sizeof(*expr2) * (my_strlen((*nb)->data) + 1))) == 0)
    exit(-1);
  expr2 = (*nb)->data;
  depile(nb);
  operator = malloc(sizeof(*operator) * (my_strlen((*op)->data) + 1));
  operator = (*op)->data;
  depile(op);
  if ((expr1 = malloc(sizeof(*expr1) * (my_strlen((*nb)->data) + 1))) == 0)
    exit(-1);
  expr1 = (*nb)->data;
  depile(nb);
  my_put_in_list(nb, operations(base, opers, expr1, operator, expr2));
}
예제 #2
0
파일: eval_expr.c 프로젝트: Sun42/piscine
int		eval_expr(char *str)
{
  int		i;
  char		**tabstring;
  t_list	*op;
  t_list	*nb;
  
  op = 0;
  nb = 0;
  i = 0;
  tabstring = str_to_tab_string(str);
  show_tab_string(tabstring);
  my_putstr("\n");
  while (tabstring[i] != 0)
    {
      if (is_operator(tabstring[i]) == 3)//si '(' on empile le retour de pqrenthesis mode
	my_put_in_list(&nb, parenthesis_mode(&i, tabstring));
      if (is_operator(tabstring[i]) == 0)// si nombre on empile
	my_put_in_list(&nb, tabstring[i]);
      if (is_operator(tabstring[i]) == 1)//si operateur de basse priorite on empile 
	my_put_in_list(&op, tabstring[i]);
      if (is_operator(tabstring[i]) == 2)// si operqteur de priorite on resolv
	resolv(&i, tabstring, &op, &nb);
      i = i + 1;
    }
  return (depile_all(op, nb));
}
예제 #3
0
char		*eval_expr(char *base, char *operators, char *expr, int size)
{
  char		**tabexpr;
  t_list	*op;
  t_list	*nb;
  int		i;
  
  tabexpr = str_to_tab_string(base, expr, operators);
  op = 0;
  nb = 0;
  i = 0;
  while (tabexpr[i] != 0)
    {
      if (is_open_parent(operators, tabexpr[i]) == 1)
	my_put_in_list(&nb, parenthesis_mode(base, operators, &i, tabexpr));
      if (is_num(base, operators, tabexpr[i]) == 1)
	my_put_in_list(&nb, tabexpr[i]);
      if (is_low_op(operators, tabexpr[i]) == 1)
	my_put_in_list(&op, tabexpr[i]);
      if (is_high_op(operators, tabexpr[i]) == 1)
	resolv(base, operators, &i, tabexpr, &op, &nb);
      i = i + 1;
    }
  return (depile_all(base, operators, op, nb));
}
예제 #4
0
파일: eval_expr.c 프로젝트: Sun42/piscine
void		resolv(int *i, char **tabstring, t_list **op, t_list **nb)
  {
    char	*save;
    int		new_val;
    char	*str;
    my_put_in_list(op, tabstring[*i]);
    *i =*i + 1;
    if  (is_operator(tabstring[*i]) == 0)
      my_put_in_list(nb, tabstring[*i]);
    if (is_operator(tabstring[*i]) == 3) 
      my_put_in_list(nb, parenthesis_mode(i, tabstring));
    //if (is_operator(tabstring[*i]) == 1)
    //{
    //save = malloc(sizeof(*save) * (my_strlen((*nb)->data) + 1));
    //save = (*nb)->data;
    //*i = *i + 1;
    //my_strncat(save,(*nb)->data,my_strlen((*nb)->data));
    // }
    //else 
    //{
	save = malloc(sizeof(*save) * (my_strlen((*nb)->data) + 1));
	save =(*nb)->data;
	//}
    depile(nb);
    if (my_list_size(*(nb)) == 0)
      my_put_in_list(nb, "0");
    new_val = eval(my_getnbr((*nb)->data), *(*op)->data, my_getnbr(save));
    depile(op);
    depile(nb);
    str = malloc(sizeof(*str) * (digit_len(new_val) + 1));
    my_itoa(new_val, str);
    my_put_in_list(nb, str);
    free(save);
  }
예제 #5
0
파일: eval_expr.c 프로젝트: Sun42/piscine
int		eval_expr(char *str)
{
  int		i;
  char		**tabstring;
  t_list	*op;
  t_list	*nb;
  
  op = 0;
  nb = 0;
  i = 0;
  tabstring = str_to_tab_string(str);
  while (tabstring[i] != 0)
    {
      if (is_operator(tabstring[i]) == 3)
	my_put_in_list(&nb, parenthesis_mode(&i, tabstring));
      if (is_operator(tabstring[i]) == 0)
	my_put_in_list(&nb, tabstring[i]);
      if (is_operator(tabstring[i]) == 1) 
	my_put_in_list(&op, tabstring[i]);
      if (is_operator(tabstring[i]) == 2)
	resolv(&i, tabstring, &op, &nb);
      i = i + 1;
    }
  return (depile_all(op, nb));
}
예제 #6
0
int             my_ls(char *d, char *options)
{
  DIR           *dir;
  t_dirent      *file;
  t_list        *list;
  char          *tmp;

  list = NULL;
  dir = opendir(d);
  check_dir_functions(d, dir, 0);
  while (file = readdir(dir))
    {
      if (file->d_name[0] != '.')
        {
          if (find_in_tab(options, 'l') == 0 || find_in_tab(options, 'd') == 0)
            launch_options(file, options, &list, d);
          else
            my_put_in_list(&list, file->d_name, file->d_type, d);
        }
    }
  check_dir_functions(d, dir, 1);
  if (find_in_tab(options, 'l') == 0)
    clean_list_syntax(list);
  my_sort_list(list, options);
  my_show_long_list(list, options, d);
  return (0);
}
예제 #7
0
char	*depile_all(char *base, char *operators, t_list *op, t_list *nb)
{
  char	*operator;
  char	*expr1;
  char	*expr2;
 
  if (my_list_size(op) > 0)
    {
      my_rev_list(&op);
      my_rev_list(&nb);
    }
  while (my_list_size(op) > 0)
    {
      operator = op->data;
      depile(&op);
      expr1 = nb->data;
      depile(&nb);
      if (my_list_size(nb) == 0)
	return (special_case_one_expr_only(base, operators, expr1, operator));
      expr2 = nb->data;
      depile(&nb);
      my_put_in_list(&nb, operations(base, operators, expr1, operator, expr2));
  }
  return (nb->data);
}
예제 #8
0
파일: eval_expr.c 프로젝트: Sun42/piscine
/*
** fin empilage, on depile et calcul
 */
int	depile_all(t_list *op, t_list *nb)
{
  char	*operator;
  char	*nb1;
  char	*nb2;
  char	*newval;
  int	inew_val;
  
  if (my_list_size(op) > 0)
    {
      my_rev_list(&op);
      my_rev_list(&nb);
    }
  while (my_list_size(op) > 0)
    {
      nb1 = nb->data;
      depile(&nb);
      nb2=nb->data;
      depile(&nb);
      operator = op->data;
      depile(&op);
      inew_val = eval(my_getnbr(nb1), *operator, my_getnbr(nb2));
      newval = malloc(sizeof(*newval) * (digit_len(inew_val) + 1));
      my_itoa(inew_val, newval);
      my_put_in_list(&nb, newval);
      free(newval);
    }
  return (my_getnbr(nb->data));
}
예제 #9
0
void		_env_copy(char **env)
{
  int		i;
  t_env		*begin;

  begin = NULL;
  i = 0;
  while (env[i])
    my_put_in_list(&begin, env[i++]);
  gl_st.st_env = begin;
}
예제 #10
0
파일: history.c 프로젝트: Yopes/42sh
static int	get_history_line(int fd, t_hist *hist)
{
  char		*tmp;

  while ((tmp = get_next_line(fd)) != NULL)
    {
      if (is_empty(tmp) == 0)
	{
	  if (my_put_in_list(hist, tmp) == -1)
	    return (-1);
	}
      else
      	free(tmp);
    }
  return (0);
}
예제 #11
0
int		my_params_in_list(int ac, char **av,
                          t_list **list, int *verbose)
{
    int		order;

    order = ASCENDING;
    while (ac > 1)
    {
        if (my_strcmp(av[ac - 1], "-r") || my_strcmp(av[ac - 1] , "--reverse"))
            order = DESCENDING;
        else if (my_strcmp(av[ac - 1], "-v") ||
                 my_strcmp(av[ac - 1], "--verbose"))
            *verbose = 1;
        else if (my_put_in_list(list, my_getnbr(av[ac - 1])))
            return (1);
        ac--;
    }
    return (order);
}
예제 #12
0
t_list		*my_str_to_wordlist(char *str, char *sep)
{
  t_list	*backup;
  t_list	*wordlist;
  int		i;

  i = -1;
  backup = NULL;
  wordlist = NULL;
  while (str[++i])
    if (is_sep(str[i], sep) == 0 && (i == 0 || is_sep(str[i - 1], sep) == 1))
      {
	if ((wordlist = my_put_in_list(str + i, wordlist)) == NULL)
	  {
	    my_free_list(backup);
	    return (NULL);
	  }
	backup = wordlist;
      }
    else if (is_sep(str[i], sep) == 1)
      str[i] = '\0';
  return (wordlist);
}