-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: drecours <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2017/11/29 15:01:36 by drecours #+# #+# */ | ||
/* Updated: 2018/04/18 16:00:42 by drecours ### ########.fr */ | ||
/* Updated: 2018/04/18 17:43:11 by drecours ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -107,5 +107,6 @@ void suppr_letter(t_inp **c); | |
char **env_in_tab(t_env **env); | ||
int in_it(int len, int i, int max, int lg); | ||
int in_this(int len, int i, int max, int lg); | ||
int insert_args(char *fg, t_sh *sh, char **exec); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: drecours <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/02/26 17:11:21 by drecours #+# #+# */ | ||
/* Updated: 2018/04/18 16:07:53 by drecours ### ########.fr */ | ||
/* Updated: 2018/04/18 17:40:56 by drecours ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -23,12 +23,13 @@ int show_err(int err, char c, char *fg) | |
{ | ||
ft_putstr_fd("history: illegal option -- ", STDERR_FILENO); | ||
ft_putchar_fd(c, STDERR_FILENO); | ||
ft_putendl_fd("\nusage: history [-nA | -C] [[0]n]", STDERR_FILENO); | ||
ft_putstr_fd("\nusage: history [-n] [[-C|c]", STDERR_FILENO); | ||
ft_putendl_fd(" | [-I [args ...]] | [[-A] [[0]n]]]", STDERR_FILENO); | ||
} | ||
if (err == 3) | ||
ft_putendl_fd("history: Arguments must be numerical.", STDERR_FILENO); | ||
if (err == 4) | ||
ft_putendl_fd("history: -A and -C together is illegal", STDERR_FILENO); | ||
ft_putendl_fd("history: I|A + C|c together is illegal", STDERR_FILENO); | ||
return (err); | ||
} | ||
|
||
|
@@ -42,14 +43,16 @@ int put(char c, char *fg) | |
fg[2] = 'n'; | ||
if (c == 'c') | ||
fg[3] = 'c'; | ||
if (c == 'I') | ||
fg[4] = 'I'; | ||
return (0); | ||
} | ||
|
||
int built_err(char **exec, char *fg) | ||
{ | ||
int i; | ||
int j; | ||
const char *flag = "ACnc"; | ||
const char *flag = "ACncI"; | ||
|
||
i = 0; | ||
j = 0; | ||
|
@@ -108,23 +111,22 @@ int builtin_history(char **exec, t_sh *sh) | |
char *fg; | ||
int lg; | ||
|
||
fg = ft_strdup("0000"); | ||
fg = ft_strdup("00000"); | ||
lg = -1; | ||
if (too_big(exec) || (err = built_err(exec, fg)) > 0) | ||
return (erase_fg(fg, 3)); | ||
if (fg[0] == 'A' && (fg[1] == 'C' || fg[3] == 'c')) | ||
if ((fg[0] == 'A' || fg[4] == 'I') && (fg[1] == 'C' || fg[3] == 'c')) | ||
return (erase_fg(fg, 4)); | ||
if (fg[1] == 'C' || fg[3] == 'c') | ||
{ | ||
ft_putendl("breby"); | ||
if (fg[4] == 'I') | ||
err = insert_args(fg, sh, exec); | ||
else if (fg[1] == 'C' || fg[3] == 'c') | ||
err = history_clean(fg, &sh->history, sh); | ||
} | ||
else if (!(err = get_beg(&i, &sh->history, exec)) && | ||
!(err = get_lg(&lg, exec))) | ||
{ | ||
lg = (lg == -1) ? history_len(&sh->history) : lg; | ||
i = (i > 0) ? i + 1 : i; | ||
err = builtin_hist(i, &sh->history, lg, fg); | ||
} | ||
return (erase_fg(fg, 0)); | ||
return (erase_fg(fg, err)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: drecours <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/03/03 14:42:12 by drecours #+# #+# */ | ||
/* Updated: 2018/04/18 16:02:28 by drecours ### ########.fr */ | ||
/* Updated: 2018/04/18 17:33:40 by drecours ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* history_flag_i.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: drecours <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/04/18 16:56:20 by drecours #+# #+# */ | ||
/* Updated: 2018/04/18 17:43:25 by drecours ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "../../inc/header.h" | ||
#include "builtin.h" | ||
|
||
void history_push(t_his **history, t_his *his) | ||
{ | ||
if (!(*history)) | ||
(*history) = his; | ||
else | ||
{ | ||
while ((*history)->previous) | ||
(*history) = (*history)->previous; | ||
(*history)->previous = his; | ||
his->next = (*history); | ||
(*history) = his; | ||
} | ||
} | ||
|
||
int first_arg(char **exec) | ||
{ | ||
int i; | ||
|
||
i = 1; | ||
while (exec[i]) | ||
{ | ||
if (ft_strcmp("--", exec[i]) == 0) | ||
{ | ||
i++; | ||
break ; | ||
} | ||
if (exec[i][0] != '-') | ||
break ; | ||
i++; | ||
} | ||
return (i); | ||
} | ||
|
||
int insert_err(void) | ||
{ | ||
ft_putendl_fd("Add problem too insert an arg in history", STDERR_FILENO); | ||
return (2); | ||
} | ||
|
||
int insert_args(char *fg, t_sh *sh, char **exec) | ||
{ | ||
int i; | ||
int j; | ||
t_his *ret; | ||
|
||
i = 0; | ||
i = first_arg(exec); | ||
j = i; | ||
while (exec[i]) | ||
{ | ||
if ((ret = new_his(exec[i]))) | ||
history_push(&sh->history, ret); | ||
else | ||
return (insert_err()); | ||
i++; | ||
} | ||
if (fg[2] == 'n') | ||
{ | ||
ft_putnbr(i - j); | ||
ft_putendl(" new entries in history."); | ||
} | ||
return (0); | ||
} |