mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
Expansion: pre split discussion
I forgot to code the minishell_split function.
This commit is contained in:
parent
de53d2b8bc
commit
efae95950e
3 changed files with 36 additions and 4 deletions
|
|
@ -18,6 +18,7 @@ typedef enum e_errno
|
||||||
FT_EERRNO = -2,
|
FT_EERRNO = -2,
|
||||||
FT_EGET = -1,
|
FT_EGET = -1,
|
||||||
FT_ESUCCESS = 0,
|
FT_ESUCCESS = 0,
|
||||||
|
FT_ENOMEM,
|
||||||
FT_EINVAL,
|
FT_EINVAL,
|
||||||
FT_EBADID,
|
FT_EBADID,
|
||||||
FT_EUNEXPECTED_PIPE,
|
FT_EUNEXPECTED_PIPE,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/25 13:02:59 by jguelen #+# #+# */
|
/* Created: 2025/02/25 13:02:59 by jguelen #+# #+# */
|
||||||
/* Updated: 2025/03/08 14:52:42 by jguelen ### ########.fr */
|
/* Updated: 2025/03/10 18:30:20 by jguelen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,22 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* simple_filename_exp.c :+: :+: :+: */
|
/* simple_filename_exp.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/02 13:40:10 by jguelen #+# #+# */
|
/* Created: 2025/03/02 13:40:10 by jguelen #+# #+# */
|
||||||
/* Updated: 2025/03/07 17:25:18 by jguelen ### ########.fr */
|
/* Updated: 2025/03/11 14:46:17 by jguelen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
#include "ft_errno.h"
|
#include "../ft_errno.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Returns a malloc-allocated string corresponding to
|
||||||
|
** "path_dir/name"
|
||||||
|
*/
|
||||||
char *alloc_path(char *path_dir, char *name)
|
char *alloc_path(char *path_dir, char *name)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
|
|
@ -44,10 +49,15 @@ static char **get_paths_array(t_env *env)
|
||||||
return (path_array);
|
return (path_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** TODO Check if filename refers to an actual file or a directory and what to
|
||||||
|
** do about that case.
|
||||||
|
*/
|
||||||
char *filepath_from_env(char *filename, t_minishell *app)
|
char *filepath_from_env(char *filename, t_minishell *app)
|
||||||
{
|
{
|
||||||
char *filepath;
|
char *filepath;
|
||||||
char **path;
|
char **path;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
path = get_paths_array(app->env);
|
path = get_paths_array(app->env);
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
|
|
@ -63,3 +73,24 @@ char *filepath_from_env(char *filename, t_minishell *app)
|
||||||
destroy_split_array(path);
|
destroy_split_array(path);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Returns a malloc-allocated string representing the full path to
|
||||||
|
** the command or executable corresponding to name or NULL in case of
|
||||||
|
** failure or .
|
||||||
|
** NOTE: if name contains a '/' character then name is considered to
|
||||||
|
** be an absolute path.
|
||||||
|
*/
|
||||||
|
char *get_filepath(const char *name, t_minishell *app)
|
||||||
|
{
|
||||||
|
char *cmd_path;
|
||||||
|
|
||||||
|
if (ft_strchr(name, '/'))
|
||||||
|
{
|
||||||
|
cmd_path = ft_strdup(name);
|
||||||
|
if (!cmd_path)
|
||||||
|
return (ft_errno(FT_ENOMEM), NULL);
|
||||||
|
return (cmd_path);
|
||||||
|
}
|
||||||
|
return (filepath_from_env(name, app));
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue