Browse Source

[mod] move tilde handling with cli parsing.

Moul 4 years ago
parent
commit
82fd7aab53
3 changed files with 20 additions and 20 deletions
  1. 19 0
      src/cmd_split.c
  2. 1 1
      src/sh.h
  3. 0 19
      src/tools.c

+ 19 - 0
src/cmd_split.c

@@ -48,3 +48,22 @@ int		count_words(char const *s, char c, char d)
 	}
 	return (sp);
 }
+
+/*
+** Change ~ to HOME var
+*/
+
+char	**change_tilde_to_home(char **cmd)
+{
+	int		i;
+
+	i = -1;
+	while (++i < ft_tabsize(cmd))
+	{
+		if (cmd[i] && ft_strcmp(cmd[i], "~") == 0 && g_home != NULL)
+			cmd[i] = ft_strdup(g_home);
+		if (cmd[i] && cmd[i][0] == '~' && cmd[i][1] == '/')
+			cmd[i] = ft_strjoin(g_home, &cmd[i][1]);
+	}
+	return (cmd);
+}

+ 1 - 1
src/sh.h

@@ -55,6 +55,7 @@ void	handle_multi_piping(int **fd, int pipe_nbr, char ***cmd_opt, int i);
 */
 char	**cmd_split(char const *str, char c, char d);
 int		count_words(char const *s, char c, char d);
+char	**change_tilde_to_home(char **cmd);
 /*
 ** exec.c
 */
@@ -84,7 +85,6 @@ char	*get_pwd();
 */
 void	sighandler();
 void	error_message(char *one, char *two, char *three);
-char	**change_tilde_to_home(char **cmd);
 int		check_cmd_presence(char *cmd);
 
 #endif

+ 0 - 19
src/tools.c

@@ -33,22 +33,3 @@ int		check_cmd_presence(char *cmd)
 			return (1);
 	return (0);
 }
-
-/*
-** Change ~ to HOME var
-*/
-
-char	**change_tilde_to_home(char **cmd)
-{
-	int		i;
-
-	i = -1;
-	while (++i < ft_tabsize(cmd))
-	{
-		if (cmd[i] && ft_strcmp(cmd[i], "~") == 0 && g_home != NULL)
-			cmd[i] = ft_strdup(g_home);
-		if (cmd[i] && cmd[i][0] == '~' && cmd[i][1] == '/')
-			cmd[i] = ft_strjoin(g_home, &cmd[i][1]);
-	}
-	return (cmd);
-}