Skip to content

Commit

Permalink
hash fonctionnel
Browse files Browse the repository at this point in the history
  • Loading branch information
Irraky committed Apr 10, 2018
1 parent d8166c0 commit 2d29db6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/exec/execute_tokens_old.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: videsvau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/02 09:41:22 by videsvau #+# #+# */
/* Updated: 2018/04/10 14:49:12 by drecours ### ########.fr */
/* Updated: 2018/04/10 20:18:16 by drecours ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -75,6 +75,8 @@ char *command_path(t_env **env, char *command, t_sh *sh)
ret = NULL;
if (command[0] == '/' || command[0] == '.')
return (check_path_bin(command, sh));
if ((path = get_hash_path(&sh->hash, command, sh)))
return (ft_strdup(path));
if ((path = get_specific_env("PATH=", env)))
{
if ((split = ft_strsplit(path, ':')))
Expand Down
Binary file added src/hash/.hash_functions.c.swp
Binary file not shown.
7 changes: 6 additions & 1 deletion src/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: drecours <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/19 14:11:42 by drecours #+# #+# */
/* Updated: 2018/04/07 18:04:34 by drecours ### ########.fr */
/* Updated: 2018/04/10 20:13:50 by drecours ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -80,6 +80,7 @@ t_hash **hash_table(char *path, t_sh *sh)
if (!(path))
return (NULL);
lst = NULL;
hash = NULL;
init_bin_list(&lst, path);
free(path);
sh->hash_size = list_size(lst);
Expand All @@ -92,5 +93,9 @@ t_hash **hash_table(char *path, t_sh *sh)
tmp = tmp->next;
}
lst_del(&lst);
if (sh->hash_size == 0 && hash)
free(hash);
if (sh->hash_size == 0)
hash = NULL;
return (hash);
}
7 changes: 6 additions & 1 deletion src/hash/hash_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: drecours <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/19 16:08:14 by drecours #+# #+# */
/* Updated: 2018/04/07 18:08:43 by drecours ### ########.fr */
/* Updated: 2018/04/10 20:05:38 by drecours ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -43,11 +43,16 @@ char *get_hash_path(t_hash ***hash_addr, char *bin, t_sh *sh)
{
unsigned int id;
t_hash *hash;
int i;

i = -1;
if (!(*hash_addr) || !(**hash_addr) || !(bin))
return (NULL);
id = hash_algo(bin, sh->hash_size);
hash = (*hash_addr)[id];
while (++i <= (int)id)
if (!(*hash_addr)[i])
return (NULL);
while (hash)
{
if (hash && hash->bin != NULL)
Expand Down

0 comments on commit 2d29db6

Please sign in to comment.