/* By: lnikolov <lnikolov@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/21 08:57:54 by ljiriste #+# #+# */
-/* Updated: 2024/08/31 11:30:11 by lnikolov ### ########.fr */
+/* Updated: 2024/08/31 12:43:50 by lnikolov ### ########.fr */
/* */
/* ************************************************************************** */
return ;
}
-int add_word(t_vec *exp_str, const char *word, const t_execution_env *env, int quote);
+int add_word(t_vec *exp_str, const char *word,
+ const t_execution_env *env, int quote);
-int add_assignment(t_vec *assignments, const char *assignment, const t_execution_env *env)
+int add_assignment(t_vec *assignments, const char *assignment,
+ const t_execution_env *env)
{
t_vec advanced_copy;
char *copy;
return (1);
}
-int save_assignments_prefix(t_vec *assignments, t_parse_tree_node *prefix, const t_execution_env *env)
+int save_assignments_prefix(t_vec *assignments, t_parse_tree_node *prefix,
+ const t_execution_env *env)
{
size_t i;
t_parse_tree_node *subnode;
return (0);
}
-int save_assignments(t_vec *assignments, t_parse_tree_node *simple_command, const t_execution_env *env)
+int save_assignments(t_vec *assignments, t_parse_tree_node *simple_command,
+ const t_execution_env *env)
{
t_parse_tree_node *subnode;
return (0);
}
-int add_redirection_file(t_vec *redirections, t_parse_tree_node *io_file, int fd, t_execution_env *env)
+int add_redirection_file(t_vec *redirections,
+ t_parse_tree_node *io_file, int fd, t_execution_env *env)
{
t_redirection redir;
const t_parse_tree_node *operator;
if (fd < 0)
fd = STDOUT_FILENO;
if (is_token_type(operator, "GREAT"))
- sec_fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
+ sec_fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC,
+ S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
else
- sec_fd = open(filename, O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
+ sec_fd = open(filename, O_CREAT | O_WRONLY | O_APPEND,
+ S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
if (sec_fd == -1)
{
free(filename);
return (ft_vec_append(redirections, &redir) != success);
}
-int write_line_to_pipe(int pipe_fd, const char *line, const t_execution_env *env, int expand)
+int write_line_to_pipe(int pipe_fd, const char *line,
+ const t_execution_env *env, int expand)
{
size_t i;
char *var;
return (res);
}
-int here_file_to_pipe(int pipe_fd, const char *delimiter, const t_execution_env *env)
+int here_file_to_pipe(int pipe_fd, const char *delimiter,
+ const t_execution_env *env)
{
int expand;
char *line;
line = get_next_line(STDIN_FILENO);
}
if (!line)
- ft_printf("minishell: warning: here-document delimited by EOF instead of %s!\n", unquoted_delimiter);
+ ft_printf
+ ("minishell: warning: here-document delimited by EOF instead of %s!\n",
+ unquoted_delimiter);
get_next_line(-1);
free(line);
free(unquoted_delimiter);
return (0);
}
-int add_redirection_here(t_vec *redirections, t_parse_tree_node *io_here, int fd, const t_execution_env *env)
+int add_redirection_here(t_vec *redirections,
+ t_parse_tree_node *io_here, int fd, const t_execution_env *env)
{
char *delimiter;
int pipe_fds[2];
free(delimiter);
if (err)
return (1);
- redir = (t_redirection){.from_to_fds[0] = fd, .from_to_fds[1] = pipe_fds[0]};
+ redir = (t_redirection){.from_to_fds[0] = fd,
+ .from_to_fds[1] = pipe_fds[0]};
return (ft_vec_append(redirections, &redir) != success);
}
-int add_redirection(t_vec *redirections, t_parse_tree_node *redirect, t_execution_env *env)
+int add_redirection(t_vec *redirections,
+ t_parse_tree_node *redirect, t_execution_env *env)
{
- int fd;
+ int fd;
t_parse_tree_node *subnode;
fd = -1;
return (add_redirection_here(redirections, subnode, fd, env));
}
-int save_redirections_psfix(t_vec *redirections, t_parse_tree_node *node, t_execution_env *env)
+int save_redirections_psfix(t_vec *redirections,
+ t_parse_tree_node *node, t_execution_env *env)
{
size_t i;
t_parse_tree_node *subnode;
if (add_redirection(redirections, subnode, env))
return (1);
}
- else if (is_token_type(subnode, "cmd_suffix") || is_token_type(subnode, "cmd_prefix"))
+ else if (is_token_type(subnode, "cmd_suffix")
+ || is_token_type(subnode, "cmd_prefix"))
if (save_redirections_psfix(redirections, subnode, env))
return (1);
++i;
return (0);
}
-int save_redirections(t_vec *redirections, t_parse_tree_node *simple_command, t_execution_env *env)
+int save_redirections(t_vec *redirections,
+ t_parse_tree_node *simple_command, t_execution_env *env)
{
t_parse_tree_node *subnode;
if (is_token_type(subnode, "cmd_prefix"))
if (save_redirections_psfix(redirections, subnode, env))
return (1);
- subnode = ft_vec_access(&simple_command->children, simple_command->children.size - 1);
+ subnode = ft_vec_access(&simple_command->children,
+ simple_command->children.size - 1);
if (is_token_type(subnode, "cmd_suffix"))
if (save_redirections_psfix(redirections, subnode, env))
return (1);
static const char space = ' ';
-int add_word(t_vec *exp_str, const char *word, const t_execution_env *env, int enquote_result)
+int add_word(t_vec *exp_str, const char *word,
+ const t_execution_env *env, int enquote_result)
{
size_t i;
char *var;
quote = '\'' * !quote;
else if (word[i] == '"' && quote != '\'')
quote = '"' * !quote;
- if (word[i] == '$' && quote != '\'' && (ft_isalnum(word[i + 1]) || word[i + 1] == '_' || word[i + 1] == '?'))
+ if (word[i] == '$' && quote != '\'' && (ft_isalnum(word[i + 1])
+ || word[i + 1] == '_' || word[i + 1] == '?'))
{
++i;
if (word[i] == '?')
const_val = get_env_var_value(env, var);
free(var);
if (!const_val)
- continue;
+ continue ;
value = ft_strdup(const_val);
}
if (!value)
return (1);
if (enquote_result)
error = error || ft_vec_append(exp_str, "'") != success;
- error = error || ft_vec_append_range(exp_str, value, ft_strlen(value)) != success;
+ error = error || ft_vec_append_range(exp_str,
+ value, ft_strlen(value)) != success;
if (enquote_result)
error = error || ft_vec_append(exp_str, "'") != success;
free(value);
return (0);
}
-int expand_cmd(t_vec *exp_str, const t_parse_tree_node *node, const t_execution_env *env)
+int expand_cmd(t_vec *exp_str,
+ const t_parse_tree_node *node, const t_execution_env *env)
{
size_t i;
const t_parse_tree_node *subnode;
while (i < simple_command->children.size)
{
subnode = ft_vec_access(&simple_command->children, i);
- if (is_token_type(subnode, "cmd_name")
+ if ((is_token_type(subnode, "cmd_name")
|| is_token_type(subnode, "cmd_word")
|| is_token_type(subnode, "cmd_suffix"))
- if (expand_cmd(&expanded_str, subnode, env))
- {
- ft_vec_free(&expanded_str, NULL);
- return (NULL);
- }
+ && expand_cmd(&expanded_str, subnode, env))
+ {
+ ft_vec_free(&expanded_str, NULL);
+ return (NULL);
+ }
++i;
}
if (ft_vec_append(&expanded_str, &null_char) != success)
var_name = get_var_name(var_line);
if (!var_name)
return (1);
- if (set_env_var_value(env, var_name, var_line + ft_strlen(var_name) + 1))
+ if (set_env_var_value(env, var_name,
+ var_line + ft_strlen(var_name) + 1))
{
free(var_name);
return (1);
return ;
}
-int add_exported(__attribute__((unused)) t_vec *assignments, __attribute__((unused)) const t_execution_env *env)
+int add_exported(__attribute__((unused))
+ t_vec *assignments, __attribute__((unused)) const t_execution_env *env)
{
- size_t i;
- char *var;
+ size_t i;
+ char *var;
const t_vec *exported;
exported = &env->vars->exported;
while (i < exported->size)
{
var = ft_strdup(*(char *const *)ft_vec_caccess(exported, i));
- if (ft_vec_append(assignments, &var) != success) // Should exported be overwritten?
+ if (ft_vec_append(assignments, &var) != success)
return (1);
++i;
}
return (0);
}
-int ex_builtin(char **fields, __attribute__((unused)) t_vec *assignments, __attribute__((unused)) const t_vec *redirections, t_execution_env *env)
+int ex_builtin(char **fields, __attribute__((unused))
+ t_vec *assignments, __attribute__((unused)) const t_vec *redirections,
+ t_execution_env *env)
{
int fds[3];
else if (!ft_strcmp(fields[0], "unset"))
env->last_builtin_ret_val = unset(count_fields(fields), fields, env);
else if (!ft_strcmp(fields[0], "exit"))
- env->last_builtin_ret_val = execute_exit(count_fields(fields), fields, env);
+ env->last_builtin_ret_val = execute_exit(count_fields(fields),
+ fields, env);
else
return (1);
env->last_was_builtin = 1;
return ;
}
-int ex_fields(char **fields, t_vec *assignments, const t_vec *redirections, t_execution_env *env)
+int ex_fields(char **fields, t_vec *assignments,
+ const t_vec *redirections, t_execution_env *env)
{
pid_t pid;
char *path;
t_ft_stat v_strcopy(void *v_dest, const void *v_src)
{
- char **dest;
- const char *const *src;
+ char **dest;
+ const char *const *src;
dest = v_dest;
src = v_src;
{
if (env->child_pids.size == 0)
return ;
- last_pid = *(pid_t *)ft_vec_access(&env->child_pids, env->child_pids.size - 1);
+ last_pid = *(pid_t *)ft_vec_access(&env->child_pids,
+ env->child_pids.size - 1);
waitpid(last_pid, &status, 0);
if (g_last_signal != 0)
killall(&env->child_pids, g_last_signal);