Skip to content

Commit

Permalink
refactor(history): Add history storage and begining of local variable…
Browse files Browse the repository at this point in the history
… with error handling
  • Loading branch information
MaxenceLgt authored and neo-jgrec committed May 13, 2023
1 parent ec60d27 commit 5f43f27
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ unit_tests
build
big_file
launch_test
history.txt
2 changes: 2 additions & 0 deletions include/my.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
char **env;
int *exit_status;
history_list_t *history;
char **var;
int last_return;
bool is_from_path;
TAILQ_HEAD(pid_list_head_s, pid_list_s) pid_list;
Expand Down Expand Up @@ -137,6 +138,7 @@
void remove_element_at_index(char **args, int index);

int is_executable(char ***args, char **env, term_t *term);
bool error_variable(char **args, term_t *term);
int is_builtins(char **args);
int execute_builtin_command(char **args, char **env,
term_t *term, my_fd_t fd);
Expand Down
2 changes: 0 additions & 2 deletions src/history/store_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ static void write_into_file(FILE *stream, history_list_t *history)
history_t *node = history->head;

for (; node; node = node->next){
printf("%i %s\n", node->pos, node->time);
fprintf(stream, "%i %s ", node->pos, node->time);
for (size_t i = 0; node->command[i]; i++){
fprintf(stream, "%s ", node->command[i]);
Expand All @@ -36,7 +35,6 @@ static void modify_chmod(void)
close(fd);
chmod("history.txt", 0755);
}
printf("%i\n", fd);
}

void store_history(history_list_t *history)
Expand Down
2 changes: 1 addition & 1 deletion src/minishell.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

char *clean_str_minishell(char *str, const char *to_clean);
int execute_commands(char **args, term_t *term);
int parsing_error(char **args);
int parsing_error(char **args, term_t *term);
char *read_stdin(term_t *term);
char **a_mkstw(char *str, char *sep);
char **edit_args_env(char **args, char **env);
Expand Down
13 changes: 6 additions & 7 deletions src/parsing/parsing_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
** parsing_error
*/

#include "parsing.h"
#include "my.h"

int is_there_only_char(char **args, char *to_find)
Expand Down Expand Up @@ -51,16 +52,14 @@ void handle_exit(char **args, int i)
}
}

int parsing_error(char **args)
int parsing_error(char **args, term_t *term)
{
if (!my_strcmp(args[0], ";"))
remove_element_at_index(args, 0);
for (int i = 0; args[i + 1] != NULL; i++) {
if (((my_strcmp(args[i], ">") == 0 || my_strcmp(args[i], "<") == 0) &&
(my_strcmp(args[i + 1], ">") == 0 || my_strcmp(args[i + 1], "<") == 0))
|| ((my_strcmp(args[i], ">>") == 0 || my_strcmp(args[i], "<<") == 0)
&& (my_strcmp(args[i + 1], ">>") == 0
|| my_strcmp(args[i + 1], "<<") == 0))) {
if (((IS_RDOUT(args[i]) || IS_RDIN(args[i])) && (IS_RDOUT(args[i + 1])
|| IS_RDIN(args[i + 1]))) || ((IS_DRDOUT(args[i]) || IS_DRDIN(args[i]))
&& (IS_DRDOUT(args[i + 1]) || IS_DRDIN(args[i + 1])))) {
my_printf("Missing name for redirect.\n");
return (1);
}
Expand All @@ -70,7 +69,7 @@ int parsing_error(char **args)
}
handle_exit(args, i);
}
if (all_char_check(args) == 1)
if (all_char_check(args) == 1 || error_variable(args, term))
return (1);
return (0);
}

0 comments on commit 5f43f27

Please sign in to comment.