Skip to content

Commit

Permalink
adding space preprocessing on envvar
Browse files Browse the repository at this point in the history
  • Loading branch information
qfeuilla committed Jul 25, 2020
1 parent a23e55b commit 149098f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
Binary file modified working/srcs/launch_commands/minishell_launch_utils.o
Binary file not shown.
Binary file modified working/srcs/redirections/redirections_utils.o
Binary file not shown.
31 changes: 29 additions & 2 deletions working/srcs/token_expansion/get_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,39 @@
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/29 16:49:23 by frthierr #+# #+# */
/* Updated: 2020/07/22 18:56:58 by qfeuilla ### ########.fr */
/* Updated: 2020/07/25 19:30:58 by qfeuilla ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

char *preprocess_env(char *env_val)
{
char *preproc_env;
int i;
int j;
int prev_is_space;

if (!env_val)
return (NULL);
i = -1;
j = 0;
prev_is_space = 0;
preproc_env = (char *)malloc(ft_strlen(env_val) * sizeof(char));
while (env_val[++i])
{
if (!(env_val[i] == ' ' && prev_is_space == 1))
preproc_env[j++] = env_val[i];
if (env_val[i] == ' ')
prev_is_space = 1;
else
prev_is_space = 0;
}
preproc_env[j] = '\0';
free(env_val);
return (preproc_env);
}

char *get_env(char *key)
{
char *value;
Expand All @@ -31,7 +58,7 @@ char *get_env(char *key)
{
if (!(value = ft_strdup(&g_env[i][ft_strlen(key) + 1])))
return (NULL);
return (value);
return (preprocess_env(value));
}
i++;
}
Expand Down
Binary file modified working/srcs/token_expansion/get_env.o
Binary file not shown.

0 comments on commit 149098f

Please sign in to comment.