You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

76 lines
2.0 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/12 14:33:58 by mea #+# #+# */
/* Updated: 2022/05/12 14:51:17 by mea ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int is_valid_identifier(char *ident)
{
int i;
i = 0;
if (ft_isalpha(ident[0]) || ident[0] == '_')
{
while (ident[i])
{
if (!ft_isalpha(ident[i]) && !ft_isdigit(ident[i]
&& ident[i] != '_'))
{
ft_putstr_fd("export: not an identifier: ", 2);
ft_putstr_fd(ident, 2);
ft_putchar_fd('\n', 2);
return (0);
}
i++;
}
return (1);
}
ft_putstr_fd("export: not an identifier: ", 2);
ft_putstr_fd(ident, 2);
ft_putchar_fd('\n', 2);
return (0);
}
int create_wc(t_lexer *lex, char *tmp)
{
int i;
int j;
int skip ;
DIR * direct;
struct dirent *file;
direct = opendir(".");
file = (readdir(direct), readdir(direct), readdir(direct));
while (file)
{
i = 0;
j = 0;
skip = (tmp[0] != '.' && file->d_name[0] == '.');
while (tmp[i] && !skip)
{
if (tmp[i] == '*')
while (file->d_name[j] && file->d_name[j] != tmp[i + 1])
j++;
if (tmp[i] != '*' && file->d_name[j] != tmp[i])
skip = 1;
else if (++i)
++j;
}
if (!skip)
create_token(lex, file->d_name);
file = readdir(direct);
}
closedir(direct);
lex->wc = 0;
return (1);
}