mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
fix: does not compile
This commit is contained in:
parent
174449cde7
commit
63df02aec5
7 changed files with 54 additions and 40 deletions
3
Makefile
3
Makefile
|
|
@ -60,6 +60,9 @@ srcs = \
|
|||
src/postprocess/redirections/redirection_parsing.c \
|
||||
src/postprocess/redirections/redirection_type.c \
|
||||
src/subst/replace_substr.c \
|
||||
src/subst/variable_subst.c \
|
||||
src/subst/variable_subst_utils.c \
|
||||
src/subst/wildcard_exp.c \
|
||||
|
||||
objs = $(srcs:.c=.o)
|
||||
export objs
|
||||
|
|
|
|||
|
|
@ -3,16 +3,18 @@
|
|||
/* ::: :::::::: */
|
||||
/* minishell.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/24 12:51:21 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/01 16:59:30 by jguelen ### ########.fr */
|
||||
/* Created: 2025/03/06 12:46/06 by khais #+# #+# */
|
||||
/* Updated: 2025/03/06 12:46:06 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MINISHELL_H
|
||||
# define MINISHELL_H
|
||||
|
||||
# include "env/env.h"
|
||||
|
||||
typedef struct s_minishell
|
||||
{
|
||||
t_env *env;
|
||||
|
|
|
|||
|
|
@ -3,22 +3,24 @@
|
|||
/* ::: :::::::: */
|
||||
/* subst.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/23 15:01:40 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/01 17:00:52 by jguelen ### ########.fr */
|
||||
/* Created: 2025/03/06 13:06/10 by khais #+# #+# */
|
||||
/* Updated: 2025/03/06 13:06:10 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SUBST_H
|
||||
# define SUBST_H
|
||||
|
||||
# include <stdlib.h>
|
||||
# include "../parser/wordlist/wordlist.h"
|
||||
# include "../minishell.h"
|
||||
|
||||
int expand_question_mark(t_minishell *app);
|
||||
t_wordlist *wordlist_var_expansion(t_wordlist *list, t_env *env);
|
||||
char *expand_question_mark(t_minishell *app);
|
||||
t_wordlist *wordlist_var_expansion(t_wordlist *list, t_minishell *app);
|
||||
t_worddesc *word_var_expansion(t_worddesc *word, t_minishell *app);
|
||||
t_wordlist *expand_star(char *file_pattern);
|
||||
char *construct_repeting_char_string(char c, size_t len);
|
||||
char *ft_get_longest_identifier(char *str);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,17 +3,16 @@
|
|||
/* ::: :::::::: */
|
||||
/* variable_subst.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/23 15:02:37 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/01 17:01:47 by jguelen ### ########.fr */
|
||||
/* Created: 2025/03/06 12:48/00 by khais #+# #+# */
|
||||
/* Updated: 2025/03/06 12:48:00 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "subst.h"
|
||||
#include "../minishell.h"
|
||||
#include "replace_substr.h"
|
||||
#include "../env/env.h"
|
||||
#include "../env/env_manip.h"
|
||||
|
||||
static char *word_update(t_worddesc *word, size_t i, size_t id_len, char *rep)
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* variable_subst_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/01 13:04:27 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/01 17:02:27 by jguelen ### ########.fr */
|
||||
/* Created: 2025/03/06 13:03/41 by khais #+# #+# */
|
||||
/* Updated: 2025/03/06 13:03:41 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,7 +14,6 @@
|
|||
#include "../minishell.h"
|
||||
#include "replace_substr.h"
|
||||
#include "../env/env.h"
|
||||
#include "../env/env_manip.h"
|
||||
|
||||
/*
|
||||
** Returns a C-compliant malloc-allocated string of length len and complosed
|
||||
|
|
|
|||
|
|
@ -3,14 +3,16 @@
|
|||
/* ::: :::::::: */
|
||||
/* wildcard_exp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/23 15:02:59 by jguelen #+# #+# */
|
||||
/* Updated: 2025/02/25 10:07:59 by jguelen ### ########.fr */
|
||||
/* Created: 2025/03/06 13:02/36 by khais #+# #+# */
|
||||
/* Updated: 2025/03/06 13:02:36 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
#include "subst.h"
|
||||
#include "unistd.h"
|
||||
|
||||
/*
|
||||
** TODO
|
||||
|
|
@ -26,4 +28,7 @@
|
|||
*/
|
||||
t_wordlist *expand_star(char *file_pattern)
|
||||
{
|
||||
(void)file_pattern;
|
||||
ft_dprintf(STDERR_FILENO, "Not implemented: expand_star\n");
|
||||
return (NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,20 +3,20 @@
|
|||
/* ::: :::::::: */
|
||||
/* expansion.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/23 15:00:18 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/01 11:07:17 by jguelen ### ########.fr */
|
||||
/* Created: 2025/03/06 13:01/15 by khais #+# #+# */
|
||||
/* Updated: 2025/03/06 13:01:15 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include "testutil.h"
|
||||
#include "../src/subst/subst.h"
|
||||
#include "../src/subst/replace_substr.h"
|
||||
#include "../../env/env.h"
|
||||
#include "../../env/env_manip.h"
|
||||
#include "../src/subst/subst.h"
|
||||
#include "../src/env/env.h"
|
||||
#include "../src/env/env_manip.h"
|
||||
|
||||
/*
|
||||
** Test file for the different expansion/substitution types of minishell.
|
||||
|
|
@ -46,48 +46,52 @@ static void test_insert_instr(void)
|
|||
//Test to be remade since structures changed in the function calls and returns.
|
||||
static void test_env_variable_expansion(void)
|
||||
{
|
||||
char *token;
|
||||
char *tk;
|
||||
t_worddesc *token;
|
||||
t_worddesc *tk;
|
||||
t_env *env;
|
||||
struct s_minishell app;
|
||||
|
||||
token = ft_strdup("$USER");
|
||||
app.last_return_value = 0;
|
||||
|
||||
token = worddesc_create(ft_strdup("$USER"), W_HASDOLLAR);
|
||||
if (!token)
|
||||
assert("ft_strdup failed" && false);
|
||||
env = NULL;
|
||||
app.env = env;
|
||||
env = env_set_entry(&env, "USER", "jguelen");
|
||||
if (env == NULL)
|
||||
assert("malloc failed" && false);
|
||||
env = env_set_entry(&env, "_canard", "coing coing");
|
||||
if (!env)
|
||||
assert("malloc failed: slipped on a duck" && false);
|
||||
tk = word_var_expansion(&token, env);
|
||||
tk = word_var_expansion(token, &app);
|
||||
if (!tk)
|
||||
assert("internal word_var_expansion failure" && false);
|
||||
assert_strequal("jguelen", tk);
|
||||
assert_strequal("jguelen", tk->word);
|
||||
free(token);
|
||||
token = ft_strdup("\"$_caneton\"");
|
||||
token = worddesc_create(ft_strdup("\"$_caneton\""), W_HASDOLLAR);
|
||||
if (!token)
|
||||
assert("ft_strdup failed" && false);
|
||||
tk = word_var_expansion(&token, env);
|
||||
tk = word_var_expansion(token, &app);
|
||||
if (!tk)
|
||||
assert("internal word_var_expansion failure" && false);
|
||||
assert_strequal("\"\"", tk);
|
||||
assert_strequal("\"\"", tk->word);
|
||||
free(token);
|
||||
token = ft_strdup("$_canard$USER$''$USER\"\"\"$_canard\"$");
|
||||
token = worddesc_create(ft_strdup("$_canard$USER$''$USER\"\"\"$_canard\"$"), W_HASDOLLAR);
|
||||
if (!token)
|
||||
assert("ft_strdup failed" && false);
|
||||
tk = word_var_expansion(token, env);
|
||||
tk = word_var_expansion(token, &app);
|
||||
if (!tk)
|
||||
assert("internal word_var_expansion failure" && false);
|
||||
assert_strequal("coing coingjguelen''jguelencoing coing$", tk);
|
||||
assert_strequal("coing coingjguelen''jguelencoing coing$", tk->word);
|
||||
free(token);
|
||||
token = ft_strdup("$_can'a'rd");
|
||||
token = worddesc_create(ft_strdup("$_can'a'rd"), W_HASDOLLAR);
|
||||
if (!token)
|
||||
assert("ft_strdup failed" && false);
|
||||
tk = word_var_expansion(token, env);
|
||||
tk = word_var_expansion(token, &app);
|
||||
if (!tk)
|
||||
assert("internal word_var_expansion failure" && false);
|
||||
assert_strequal("'a'rd", tk);
|
||||
assert_strequal("'a'rd", tk->word);
|
||||
free(token);
|
||||
env_destroy(env);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue