/* ::: :::::::: */
/* echo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
+/* By: lnikolov <lnikolov@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/26 11:43:48 by ljiriste #+# #+# */
-/* Updated: 2024/08/26 11:45:17 by ljiriste ### ########.fr */
+/* Updated: 2024/08/30 14:05:49 by lnikolov ### ########.fr */
/* */
/* ************************************************************************** */
int echo(int argc, char **argv)
{
- int i;
- int flag;
- int t;
+ int i;
+ int flag;
+ int t;
i = 1;
flag = 0;
/* ::: :::::::: */
/* exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
+/* By: lnikolov <lnikolov@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/27 14:49:17 by ljiriste #+# #+# */
-/* Updated: 2024/08/27 17:00:31 by ljiriste ### ########.fr */
+/* Updated: 2024/08/30 14:06:52 by lnikolov ### ########.fr */
/* */
/* ************************************************************************** */
}
if (!is_numeric(argv[1]))
{
- ft_dprintf(STDERR_FILENO, "exit: %s: numeric argument required\n", argv[1]);
+ ft_dprintf(STDERR_FILENO,
+ "exit: %s: numeric argument required\n", argv[1]);
return (2);
}
return (ft_atoi(argv[1]));
/* ::: :::::::: */
/* export.c :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* By: lnikolov <lnikolov@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/23 09:40:38 by ljiriste #+# #+# */
-/* Updated: 2024/08/30 09:16:28 by ljiriste ### ########.fr */
+/* Updated: 2024/08/30 14:08:30 by lnikolov ### ########.fr */
/* */
/* ************************************************************************** */
if (!has_valid_name(var))
{
- ft_dprintf(STDERR_FILENO, "export: '%s': not a valid identifier\n", var);
+ ft_dprintf(STDERR_FILENO,
+ "export: '%s': not a valid identifier\n", var);
return (1);
}
name = get_var_name(var);
/* ::: :::::::: */
/* unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
+/* By: lnikolov <lnikolov@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/26 08:18:30 by ljiriste #+# #+# */
-/* Updated: 2024/08/26 11:47:56 by ljiriste ### ########.fr */
+/* Updated: 2024/08/30 14:10:24 by lnikolov ### ########.fr */
/* */
/* ************************************************************************** */
#include "builtins.h"
#include "minishell_structs.h"
-void unset_single(const char *name, t_execution_env *env)
+void unset_single(const char *name, t_execution_env *env)
{
ssize_t index;
/* By: lnikolov <lnikolov@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/21 08:57:54 by ljiriste #+# #+# */
-/* Updated: 2024/08/30 17:31:53 by ljiriste ### ########.fr */
+/* Updated: 2024/08/31 11:30:11 by lnikolov ### ########.fr */
/* */
/* ************************************************************************** */
/* ::: :::::::: */
/* tokenization.c :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* By: lnikolov <lnikolov@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/21 16:34:43 by ljiriste #+# #+# */
-/* Updated: 2024/08/28 10:32:02 by ljiriste ### ########.fr */
+/* Updated: 2024/08/30 14:28:42 by lnikolov ### ########.fr */
/* */
/* ************************************************************************** */
if (!str)
return (1);
return (!ft_strncmp(str, "&&", size)
- || !ft_strncmp(str, "||", size)
- || !ft_strncmp(str, "<", size)
- || !ft_strncmp(str, ">", size)
- || !ft_strncmp(str, "<<", size)
- || !ft_strncmp(str, ">>", size)
- || !ft_strncmp(str, "|", size)
- || !ft_strncmp(str, "(", size)
- || !ft_strncmp(str, ")", size));
+ || !ft_strncmp(str, "||", size)
+ || !ft_strncmp(str, "<", size)
+ || !ft_strncmp(str, ">", size)
+ || !ft_strncmp(str, "<<", size)
+ || !ft_strncmp(str, ">>", size)
+ || !ft_strncmp(str, "|", size)
+ || !ft_strncmp(str, "(", size)
+ || !ft_strncmp(str, ")", size));
}
static int is_operator(t_vec *current_token)
char *continue_input(char *line, size_t *i)
{
- free(line);
- *i = 0;
- return (readline("> "));
+ free(line);
+ *i = 0;
+ return (readline("> "));
}
#else //NOLEAKS
int is_redirection_operator(const t_token *token)
{
return (token->type == g_tokens[LESS]
- || token->type == g_tokens[DLESS]
- || token->type == g_tokens[GREAT]
- || token->type == g_tokens[DGREAT]);
+ || token->type == g_tokens[DLESS]
+ || token->type == g_tokens[GREAT]
+ || token->type == g_tokens[DGREAT]);
}
void filter_assignment_word(t_vec *tokens)
}
prev_token = ft_vec_caccess(tokens, i - 1);
if (prev_token->type == g_tokens[ASSIGNMENT_WORD]
- || prev_token->type == g_tokens[AND_IF]
- || prev_token->type == g_tokens[OR_IF]
- || prev_token->type == g_tokens[LPARA])
+ || prev_token->type == g_tokens[AND_IF]
+ || prev_token->type == g_tokens[OR_IF]
+ || prev_token->type == g_tokens[LPARA])
{
++i;
continue ;
i = 0;
while (line[0][i] && res == 0)
{
- if (is_operator_start(current_token.vec, current_token.size) && can_expand_operator(¤t_token, line[0][i]))
+ if (is_operator_start(current_token.vec, current_token.size)
+ && can_expand_operator(¤t_token, line[0][i]))
res = (ft_vec_append(¤t_token, line[0] + (i++)) != success);
else if (is_operator(¤t_token))
res = finish_token(tokens, ¤t_token, '\0');
if (current_token.size > 0)
res = finish_token(tokens, ¤t_token, line[0][i]);
if (!ft_isspace(line[0][i]))
- res = res || ft_vec_append(¤t_token, line[0] + i) != success;
+ res = res || ft_vec_append(¤t_token, line[0] + i)
+ != success;
++i;
}
else if (current_token.size > 0)
/* ::: :::::::: */
/* vars.c :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* By: lnikolov <lnikolov@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 13:21:32 by ljiriste #+# #+# */
-/* Updated: 2024/08/30 09:14:10 by ljiriste ### ########.fr */
+/* Updated: 2024/08/30 14:30:49 by lnikolov ### ########.fr */
/* */
/* ************************************************************************** */
ssize_t get_var_index(const t_vec *vars, const char *var_name)
{
- size_t len;
- ssize_t i;
- const char *const *line;
+ size_t len;
+ ssize_t i;
+ const char *const *line;
len = ft_strlen(var_name);
i = 0;
const char *get_var_value(const t_vec *vars, const char *var_name)
{
- size_t len;
- ssize_t i;
- const char *const *line;
+ size_t len;
+ ssize_t i;
+ const char *const *line;
len = ft_strlen(var_name);
i = get_var_index(vars, var_name);
/* ::: :::::::: */
/* wildcards.c :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* By: lnikolov <lnikolov@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/08 10:50:26 by ljiriste #+# #+# */
-/* Updated: 2024/08/29 17:09:47 by ljiriste ### ########.fr */
+/* Updated: 2024/08/30 14:39:10 by lnikolov ### ########.fr */
/* */
/* ************************************************************************** */
if (g_last_signal != 0)
return (2);
info_dup = *info;
- if (!(*(info->current_expand_char + 1) == '/' && info->current_entry_char == info->entry))
+ if (!(*(info->current_expand_char + 1) == '/' && info->current_entry_char
+ == info->entry))
{
++info->current_expand_char;
if (add_conformant(expanded, info, '\0'))
++info->current_expand_char;
return (expand_further(expanded, *info));
}
- if (*info->current_expand_char == '/' && info->current_entry_char == info->entry)
+ if (*info->current_expand_char == '/' && info->current_entry_char
+ == info->entry)
{
++info->current_expand_char;
return (add_conformant(expanded, info, quote));
++info->current_expand_char;
return (add_conformant(expanded, info, quote));
}
- if ((*info->current_expand_char == '?' && *info->current_entry_char != '\0' && (*info->current_entry_char != '.' || info->current_entry_char != info->entry) && !quote)
- || (*info->current_expand_char == *info->current_entry_char && (*info->current_expand_char != '*' || quote)))
+ if ((*info->current_expand_char == '?' && *info->current_entry_char != '\0'
+ && (*info->current_entry_char != '.'
+ || info->current_entry_char != info->entry) && !quote)
+ || (*info->current_expand_char == *info->current_entry_char
+ && (*info->current_expand_char != '*' || quote)))
{
++info->current_expand_char;
++info->current_entry_char;
return (add_conformant(expanded, info, quote));
}
- if (*info->current_expand_char == '*' && (*info->current_entry_char != '.' || info->current_entry_char != info->entry) && !quote)
+ if (*info->current_expand_char == '*' && (*info->current_entry_char != '.'
+ || info->current_entry_char != info->entry) && !quote)
return (branch_at_star(expanded, info));
return (0);
}
unquote_field(unquoted_str);
if (unquoted_str[0] == '/')
res = ft_strdup("/");
- else if (unquoted_str[0] == '~' && (ft_isalpha(unquoted_str[1]) || unquoted_str[1] == '/' || unquoted_str[1] == '~' || unquoted_str[1] == '+' || unquoted_str[1] == '-'))
+ else if (unquoted_str[0] == '~' && (ft_isalpha(unquoted_str[1])
+ || unquoted_str[1] == '/' || unquoted_str[1] == '~'
+ || unquoted_str[1] == '+' || unquoted_str[1] == '-'))
{
if (unquoted_str[1] == '/' || unquoted_str[1] == '\0')
res = ft_strjoin(get_env_var_value(env, "HOME"), "/");
t_vec matched;
t_wildcard_info info;
int res;
- char last_char = str[0][ft_strlen(*str) - 1];
+ char last_char;
+ last_char = str[0][ft_strlen(*str) - 1];
if (last_char == '\n')
str[0][ft_strlen(*str) - 1] = '\0';
if (ft_vec_init(&matched, sizeof(char *)) != success)
i = 0;
while (word[i])
{
- if ((word[i] == '*' || (word[i] == '?' && !(i && word[i - 1] == '$'))) && quote_char == '\0')
+ if ((word[i] == '*' || (word[i] == '?' && !(i && word[i - 1] == '$')))
+ && quote_char == '\0')
return (1);
if (word[i] == '"')
{