Compare commits
No commits in common. "cdde24f0d076f83373f525d3a79629efeadcbc13" and "94f48602d1901cfd9ef72cbe4fd27123dd0ab8d2" have entirely different histories.
cdde24f0d0
...
94f48602d1
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */
|
/* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/02/22 13:23:16 by erey-bet ### ########.fr */
|
/* Updated: 2023/02/21 23:31:04 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -18,44 +18,80 @@ int is_space(char c)
|
|||||||
|| c == '\r' || c == '\n');
|
|| c == '\r' || c == '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_argument(char *str, int *check)
|
int check_argument(char *str, int *check, int i)
|
||||||
{
|
{
|
||||||
int i;
|
int y;
|
||||||
|
|
||||||
|
y = 0;
|
||||||
|
if (str[i] == '-')
|
||||||
|
{
|
||||||
|
while (!is_space(str[i]) || (str[i + 1] == '-' ))
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
if (is_space(str[i]))
|
||||||
|
{
|
||||||
|
y = i;
|
||||||
|
*check = 1;
|
||||||
|
}
|
||||||
|
else if (str[i] == '-' && str[i - 1] != '-')
|
||||||
|
;
|
||||||
|
else if (str[i] != 'n')
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
i = y;
|
||||||
|
while (is_space(str[i]))
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *conca(char **strs)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
char *str;
|
||||||
|
char *p;
|
||||||
|
int i;
|
||||||
|
|
||||||
i = -1;
|
i = -1;
|
||||||
while (str[++i])
|
len = 0;
|
||||||
if (str[i] != '-' && str[i] != 'n')
|
while (strs[++i] != NULL)
|
||||||
return (1);
|
len += ft_strlen(strs[i]) + 2;
|
||||||
if (ft_strnstr(str, "n", ft_strlen(str)))
|
str = (char *) ft_calloc(len + 1, sizeof(char));
|
||||||
*check = 1;
|
if (str == NULL)
|
||||||
return (0);
|
return NULL;
|
||||||
|
i = -1;
|
||||||
|
while (strs[++i] != NULL)
|
||||||
|
{
|
||||||
|
ft_strlcat(str, strs[i], ft_strlen(str) + ft_strlen(strs[i]) + 2);
|
||||||
|
if (strs[i + 1] != NULL)
|
||||||
|
str[ft_strlen(str)] = ' ';
|
||||||
|
}
|
||||||
|
str[ft_strlen(str)] = '\0';
|
||||||
|
return (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
int echo(int fd, char **strs)
|
int echo(int fd, char **strs)
|
||||||
{
|
{
|
||||||
int check;
|
int check;
|
||||||
int i;
|
int i;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = conca(strs);
|
||||||
check = 0;
|
check = 0;
|
||||||
i = -1;
|
i = 0;
|
||||||
while (strs[++i])
|
while (is_space(str[i]))
|
||||||
{
|
i++;
|
||||||
while (is_space(*strs[i]))
|
i = check_argument(str, &check, i);
|
||||||
strs[i]++;
|
while (str[i])
|
||||||
if (check == 1 || check_argument(strs[i], &check))
|
ft_putchar_fd(str[i++], fd);
|
||||||
{
|
|
||||||
ft_putstr_fd(strs[i], fd);
|
|
||||||
if (strs[i + 1] != NULL)
|
|
||||||
write(fd, " ", 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!check)
|
if (!check)
|
||||||
write(fd, "\n", 1);
|
write(fd, "\n", 1);
|
||||||
|
free(str);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*int main(int argc, char *argv[])
|
/*int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
echo(1, argv + 1);
|
echo(1, argv);
|
||||||
return (0);
|
return (0);
|
||||||
}*/
|
}*/
|
||||||
|
23
env3.c
23
env3.c
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */
|
/* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/02/22 01:41:04 by erey-bet ### ########.fr */
|
/* Updated: 2023/02/21 14:09:42 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -61,24 +61,3 @@ int create_value_by_key_dup(char *key, char *value, t_list **env)
|
|||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int delete_by_key(char *key, t_list **head)
|
|
||||||
{
|
|
||||||
t_list *last;
|
|
||||||
t_list *current;
|
|
||||||
|
|
||||||
current = *head;
|
|
||||||
while (current->next != NULL)
|
|
||||||
{
|
|
||||||
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
|
|
||||||
{
|
|
||||||
if (last->next != NULL)
|
|
||||||
last->next = current->next;
|
|
||||||
else
|
|
||||||
*head = current->next;
|
|
||||||
}
|
|
||||||
last = current;
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
|
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/22 01:47:21 by erey-bet ### ########.fr */
|
/* Updated: 2023/02/21 22:03:41 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -65,7 +65,6 @@ void env_del(void *ptr);
|
|||||||
char **env_to_strs(t_list **head);
|
char **env_to_strs(t_list **head);
|
||||||
char *get_value(char *str);
|
char *get_value(char *str);
|
||||||
char *get_key(char *str);
|
char *get_key(char *str);
|
||||||
int delete_by_key(char *key, t_list **head);
|
|
||||||
|
|
||||||
/* Echo */
|
/* Echo */
|
||||||
int echo(int fd, char **strs);
|
int echo(int fd, char **strs);
|
||||||
|
Loading…
Reference in New Issue
Block a user