Beispiel #1
0
int	config_prompt(char *str, t_config *config)
{
  char	**tab;
  char	*base;
  char	*prompt;

  base = DELIM_PROMPT_STRING;
  if (str == NULL || config == NULL)
    return (EXIT_FAILURE);
  prompt = NULL;
  if ((tab = my_strtok(str, base, TOK_DELIM)) == NULL ||
      my_tablen(tab) != PROMPT_STRING_NUMBER ||
      (prompt = xmalloc(sizeof(*prompt) * (my_strlen(tab[1]) + 1))) == NULL ||
      fill_prompt(prompt, tab[1]) == EXIT_FAILURE)
    {
      (tab) ? my_free_tab(tab) : (tab = NULL);
      (prompt) ? free(prompt) : (prompt = NULL);
      return (EXIT_FAILURE);
    }
  if (config->prompt != NULL)
    free(config->prompt);
  my_free_tab(tab);
  config->prompt = prompt;
  return (EXIT_SUCCESS);
}
Beispiel #2
0
int	config_alias(char *str, t_config *config)
{
  char	**tab;
  char	**spec;
  char	*base;

  base = DELIM_ALIAS_STRING;
  if ((tab = my_strtok(str, base, TOK_DELIM)) == NULL ||
      my_tablen(tab) != ALIAS_STRING_NUMBER)
    {
      (tab) ? my_free_tab(tab) : (tab = NULL);
      return (EXIT_FAILURE);
    }
  base = DELIM_SPACE_STRING;
  if ((spec = my_strtok(tab[0], base, TOK_DELIM)) == NULL ||
      my_tablen(spec) != ALIAS_STRING_NUMBER)
    {
      (tab) ? my_free_tab(tab) : (tab = NULL);
      (spec) ? my_free_tab(spec) : (spec = NULL);
      return (EXIT_FAILURE);
    }
  my_putalias(&config->alias, spec[1], tab[1]);
  (tab) ? my_free_tab(tab) : (tab = NULL);
  (spec) ? my_free_tab(spec) : (spec = NULL);
  return (EXIT_SUCCESS);
}
Beispiel #3
0
t_xtree	*xml_find_in_tree(t_xtree *tree, char *find)
{
  char	**tab;
  int	i;
  t_xtree	*tmp;
  t_xtree	*tmp2;

  tab = my_strtok(find, "/ \n\t", TOK_DELIM);
  i = 0;
  tmp = NULL;
  while (tree && tab && tab[i])
    {
      if (tmp == NULL)
	tmp = tree;
      tmp2 = tmp;
      tmp = NULL;
      while (tmp2 && !tmp)
	{
	  if (!tab[i + 1] && my_strcmp(tmp2->name, tab[i]) == 0)
	    {
	      my_free_tab(tab);
	      return (tmp2);
	    }
	  tmp = xml_find_one_node(tmp2->sun, tab[i]);
	  if (tmp == NULL)
	    tmp2 = tmp2->next;
	}
      i++;
    }
  my_free_tab(tab);
  return (tmp);
}
Beispiel #4
0
int     redir_left(t_node *node, t_env *env)
{
  int   pfd[2];
  char  **cmd;
  char  *pathcmd;
  int   pid;

  if (pipe(pfd) == -1)
    return (-1);
  redir_left_rec(node->p_nx1, pfd, env);
  close(pfd[1]);
  cmd = my_str_to_wordtab(node->p_nx2->data);
  pid = fork();
  if (pid == 0)
    {
      dup2(pfd[0], 0);
      pathcmd = my_check_access(cmd[0], my_get_path(env));
      execve(pathcmd, cmd, tab_env(env));
      return (-3);
    }
  else
    wait(&pid);
  my_free_tab(cmd);
  return (0);
}
Beispiel #5
0
int	launch_options_process(char **path, char **env, char **av, int i)
{
  int	j;
  char	**tmp;
  char	*cmd_path;

  while (av[i] && my_find_in_str(av[i], '=') != -1)
    if ((env = set_env_option(av, env, &i)) == NULL)
      return (-1);
  if (!av[i])
    return (printenv_option(env));
  j = i;
  if ((tmp = cut_env_cmd(av, &i, &j)) == NULL)
    return (-1);
  if (!path || !(cmd_path = get_cmd_path(tmp[0], path)))
    return (0);
  my_free(tmp[0]);
  tmp[0] = cmd_path;
  env = launch_appropriate_cmd(tmp, env);
  if (!env)
    return (-1);
  if (env != NULL + 1)
    my_free_tab(env);
  return (0);
}
Beispiel #6
0
void	find_cd(char *str, t_struct *pile)
{
  int	n;
  int	flag;
  char	*tmp;
  char	**path;

  n = 0;
  flag = 0;
  tmp = my_strdup(str);
  path = my_str_towordtab_cd(tmp, '/');
  while (path[n] != 0)
    {
      if (path[n + 1] == 0)
	flag = 1;
      if (my_strncmp(path[n], "..", 2) == 0)
	my_cd_back(pile, flag);
      else if ((n == 0) && (path[n][0] == '-'))
	my_cd_minus(path[n], pile);
      else
	my_cd_opendir(path[n], pile, flag);
      n++;
    }
  my_free_tab(path);
  free(path);
  free(tmp);
}
Beispiel #7
0
static void
aff_rch(char **tab, t_global *global, t_line *line)
{
  char	**tmp;
  int	i;

  i = -1;
  termcap_action(1, CURSER_OFF, NULL, 0);
  termcap_action((edit_listlen(line) - edit_cp(line)),
		 RIGHT_MOVE_STRING, global, 1);
  termcap_action(1, DOWN_MOVE_STRING, NULL, 0);
  termcap_action(global->dom[X], LEFT_MOVE_STRING, NULL, 0);
  while (tab && tab[++i])
    {
      termcap_action(1, UNDERLINE_ON, NULL, 0);
      if ((tmp = my_strtok(tab[i], "/", TOK_DELIM)) != NULL)
	{
	  printf("%s\n", tmp[my_tablen(tmp) - 1]);
	  my_free_tab(tmp);
	}
      termcap_action(1, UNDERLINE_OFF, NULL, 0);
    }
  my_putstr(global->prompt);
  edit_global(global, 1);
  termcap_action(edit_cp(line), RIGHT_MOVE_STRING, global, 1);
  termcap_action(1, CURSER_ON, NULL, 0);
}
Beispiel #8
0
static t_line
*edit_autocomplete(char *str, char *path, t_global *global, t_line *line)
{
  t_line	*complete;
  char	**tab;
  int	len;

  complete = NULL;
  if ((tab = my_strtok(str, " \t", TOK_DELIM)) == NULL)
    return (NULL);
  len = my_tablen(tab);
  if (len == 1)
    {
      if (tab[0][my_strlen(tab[0]) - 1] == '*')
	complete = NULL;
      else
	complete = edit_convertstr(&tab[0][my_strlen(path) - 1]);
    }
  else
    {
      complete = edit_recurrence(tab, my_strlen(path) - 1);
      aff_rch(tab, global, line);
    }
  my_free_tab(tab);
  return (complete);
}
Beispiel #9
0
int	printenv_option(char **env)
{
  char	**tmp;

  tmp = malloc(sizeof(*tmp) * 2);
  if (!tmp)
    return (msg_error("mysh: error: malloc failed.\n"));
  tmp[0] = my_strdup("env");
  tmp[1] = NULL;
  if (!tmp[0])
    return (-1);
  my_printenv(tmp, env, 0);
  tmp = my_free_tab(tmp);
  env = my_free_tab(env);
  return (0);
}
Beispiel #10
0
int	parsing(char *str, t_shenv *shenv, int n)
{
  char	**cmd;
  int	ret;
  int	i;

  i = -1;
  if (!(init_parsing(&str, shenv, &ret, &cmd)))
    return (EXIT_SUCCESS);
  while (cmd && cmd[++i])
    {
      if (!strncmp(cmd[i], ";", 1) && cmd[i + 1]
	  && strncmp(cmd[i + 1], ";", 1))
	ret = parse_cmd(cmd[++i], shenv, n);
      if (!strncmp(cmd[i], "&&", 2) && cmd[i + 1]
	  && strncmp(cmd[i + 1], "&&", 2))
	(!ret) ? (ret = parse_cmd(cmd[++i], shenv, n)) : ++i;
      if (!strncmp(cmd[i], "||", 2) && cmd[i + 1]
	  && strncmp(cmd[i + 1], "||", 2))
	(ret == EXIT_FAILURE) ? (ret = parse_cmd(cmd[++i], shenv, n)) : ++i;
      if (ret == -1)
	return (EXIT_FAILURE);
      n = 0;
    }
  my_free_tab(cmd);
  return (EXIT_SUCCESS);
}
Beispiel #11
0
int		operation(char *tmp, t_struct *pile)
{
  int		n;
  char		**tab;

  n = 0;
  tab = my_get_line_com(tmp);
  while (tab[n] != 0)
    {
      pile->fd = 1;
      pile->fd_g = 0;
      tab[n] = my_check_alias(tab[n], pile);
      if (my_strcmp(tab[n], EXIT) == 0)
	{
	  pile->flag_exit = OK;
	  break;
	}
      if ((tab[n] != 0) && (pile->e == OK) && (my_strcmp(tab[n], EXIT) != 0))
	go_init(tab, n, pile);
      else if (pile->e == NOT_OK)
	pile->e = OK;
      n++;
    }
  my_free_tab(tab);
  free(tab);
  return (0);
}
Beispiel #12
0
int	handle_key(int keycode, t_rt *scene)
{
  int	i;

  if (keycode == ESC)
    {
      i = -1;
      while (++i < NTHREAD)
	{
	  my_free_tab((void **)scene[i].objs);
	  my_free_tab((void **)scene[i].spots);
	}
      exit(EXIT_SUCCESS);
    }
  if (keycode == 's' || keycode == 'b')
    save_scene(scene[0].mlx->img);
  return (EXIT_SUCCESS);
}
Beispiel #13
0
void	make_instruction_tab(char *file, char *name_file, header_t *header)
{
    char	**tab;

    remove_comment_and_name(file);
    tab = fill_instruction_tab(file, -1, -1, 0);
    free(file);
    make_compile(name_file, header, tab);
    my_free_tab(tab);
}
Beispiel #14
0
/*
** Retourne le path adequate a a partir de la chaine path 
*/
char	*recup_goodpath(char **cmd, char *pathline)
{
  char	**path_tab;
  int	i;
  char	*full_path;

  i = 0;
  path_tab = my_str_to_wordtab2(del_label(pathline, "PATH"), ':');
  while (path_tab[i])
    {
      full_path = mk_fullpath(path_tab[i], cmd[0]);
      if (access(full_path, F_OK) == 0)
	{
	  my_free_tab(path_tab);
	  return (full_path);
	}
      i++;
      free(full_path);
    }
  my_free_tab(path_tab);
  return (NULL);
}
static int	check_input_champ(char **ag, t_list **list,
				  t_game *game, int i)
{
  char		**tab;

  if (ag[i] == NULL)
    return (my_perror(ERR_ARG));
  while (ag[i] != NULL)
    {
      if ((tab = my_str_to_word_tab(ag[i])) == NULL)
	return (my_perror(STR_TAB));
      if ((use_input(tab, list)) == ERROR)
	{
	  my_free_tab(tab);
	  return (ERROR);
	}
      i = i + 1;
      my_free_tab(tab);
    }
  if (i == 1 && game->dump_cycle == -1)
    return (my_perror(ERR_ARG));
  return (GOOD);
}
Beispiel #16
0
void		main_manager(char *s, t_main **my_env)
{
  t_main	*list;
  char		**env;

  env = list_to_tab(*my_env);
  list = NULL;
  parsing_entree(&list, s);
  if (list != NULL)
    {
      if (execution(list, my_env, env) != -1)
	my_free_list(list);
    }
  my_free_tab(env);
}
Beispiel #17
0
char	*glob_in_dir(char *str, char *new_str, int flag)
{
  int	i;
  char	**tab;

  i = 0;
  tab = my_strtok(str, " \t\n", TOK_DELIM);
  while (tab[i])
    {
      new_str = make_globing(new_str, tab[i], flag);
      if (new_str == NULL)
	return (NULL);
      new_str = realloc(new_str, my_strlen(new_str) + 1);
      if (new_str == NULL)
	return (NULL);
      if (tab[i + 1])
	new_str = strcat(new_str, " ");
      i++;
    }
  my_free_tab(tab);
  return (new_str);
}