예제 #1
0
파일: ft_sh1.c 프로젝트: WTSC/42_projects
int is_builtin(char *line, t_env **env)
{
	(*env)->av = ft_strsplit(line, ' ');	
	if (ft_strcmp(ft_strtolower((*env)->av[0]), "setenv") == 0)
	{
		ft_setenv(&(*env));
		return (1);	
	}	
	else if (ft_strcmp(ft_strtolower((*env)->av[0]), "unsetenv") == 0)
	{
		ft_unsetenv(&(*env));
		return (1);
	}	
	else if (ft_strcmp(ft_strtolower((*env)->av[0]), "cd") == 0)
	{
		ft_cd(&(*env));
		return (1);
	}
	else if (ft_strcmp(ft_strtolower((*env)->av[0]), "exit") == 0)
	{
		exit (0);
		return (1);	
	}
	else
		return (0);
}
예제 #2
0
void	ft_parse_input(t_shun **shell)
{
	if (*(*shell)->input)
	{
		(*shell)->argv = ft_parse_get_args((*shell)->input);
		(*shell)->argc = ft_tablen((*shell)->argv);
		if ((*shell)->argc != 0)
		{
			if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "exit") == 0)
				ft_exit(&(*shell));
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "env") == 0)
				ft_print_environ(*shell);
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "setenv") == 0)
				ft_setenv(&(*shell));
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]),
							"unsetenv") == 0)
				ft_unsetenv(&(*shell));
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "cd") == 0)
				ft_cd(&(*shell));
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "prompt") == 0)
				ft_chg_prompt(&(*shell));
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "pwd") == 0)
				ft_putendl(ft_get_pwd());
			else
				ft_exec_bin(&(*shell));
		}
	}
}
예제 #3
0
int			implemented_function(t_datas *datas, char **cmd)
{
	char			*tmp;
	static t_fblt	*fblt[11] =

	{
	&ft_cd, &ft_echo, &ft_history, &ft_env, &ft_setenv, &ft_unsetenv,
	&ft_set, &ft_unset, &ft_color, &ft_export, NULL
	};
	tmp = ft_strtolower(ft_strdup(cmd[0]));
	if (tmp == NULL)
		tmp = ft_strtolower(cmd[0]);
	if (ft_strcmp(tmp, "exit") == 0)
	{
		if (tmp != cmd[0])
			ft_strdel(&tmp);
		ft_exit(datas, ft_atoi(cmd[1]));
	}
	return (ft_find_blt(datas, fblt, cmd, &tmp));
}
예제 #4
0
char	*applyflag(t_opts *opts, char *str)
{
	if (opts->flags['#'] && opts->type == 'x' && ft_strlen(str))
		return (ft_strtolower(addhexachar(str, 1)));
	if (opts->flags['#'] && opts->type == 'X' && ft_strlen(str))
		return (addhexachar(str, 1));
	if (opts->flags['#'] && (opts->type == 'o' || opts->type == 'O'))
		return (addoctachar(str));
	if (issigned(opts) && opts->flags['+'])
		if (str[0] != '-')
			str = straddnchar(str, 0, 1, '+');
	if (issigned(opts) && ft_isdigit(str[0]) && opts->flags[' '])
		str = straddnchar(str, 0, 1, ' ');
	return (str);
}
예제 #5
0
void	ft_parse_input(t_shell **shell)
{
	if (*(*shell)->input)
	{
		(*shell)->argv = ft_parse_get_args((*shell)->input);
		(*shell)->argc = ft_count_arg((*shell)->argv);
		if ((*shell)->argc != 0)
		{
			if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "env") == 0)
				ft_print_environ(*shell);
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "setenv") == 0)
				ft_setenv(&(*shell));
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]),
								"unsetenv") == 0)
				ft_unsetenv(&(*shell));
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "exit") == 0)
				ft_exit(&(*shell));
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "cd") == 0)
				ft_cd(&(*shell));
			else
				ft_exec_bin(&(*shell));
		}
	}
}
예제 #6
0
char		*render_opts_numeric_uitoa(t_opts *opts, uintmax_t n)
{
	char	*s;

	if (opts->type == 'o')
		s = ft_uitoa_base(n, 8);
	else if (opts->type == 'O')
		s = ft_uitoa_base(n, 8);
	else if (opts->type == 'x')
		s = ft_strtolower(ft_uitoa_base(n, 16));
	else if (opts->type == 'X')
		s = ft_uitoa_base(n, 16);
	else if (opts->type == 'u')
		s = ft_uitoa_base(n, 10);
	else if (opts->type == 'b')
		s = ft_uitoa_base(n, 2);
	else
		s = ft_uitoa_base(n, 10);
	return (s);
}
예제 #7
0
static char	*ft_uintmax_to_ascii(uintmax_t val, int base, int xbase)
{
	int			s_len;
	char		*b_array;
	char		*s;
	uintmax_t	tmp_val;

	b_array = "0123456789ABCDEF";
	tmp_val = val;
	s_len = 0;
	while (++s_len && tmp_val >= (uintmax_t)base)
		tmp_val /= base;
	if (!(s = ft_strnew(s_len)))
		return (NULL);
	while (s_len--)
	{
		s[s_len] = b_array[val % base];
		val /= base;
	}
	(xbase == -1) ? ft_strtolower(&s) : 0;
	return (s);
}
예제 #8
0
void	ft_capitalize(char *str)
{
	int i;

	i = 0;
	str = ft_strtolower(str);
	if (str[0] >= 'a' && str[0] <= 'z')
		str[0] -= 32;
	while (str[i] != '\0')
	{
		if ((str[i - 1] >= 32 && str[i - 1] <= 38)
			|| (str[i - 1] >= 40 && str[i - 1] <= 44)
			|| (str[i - 1] >= 46 && str[i - 1] <= 47)
			|| (str[i - 1] >= 58 && str[i - 1] <= 64)
			|| (str[i - 1] >= 91 && str[i - 1] <= 96)
			|| (str[i - 1] >= 123 && str[i - 1] <= 126))
		{
			if (str[i] >= 'a' && str[i] <= 'z')
				str[i] -= 32;
		}
		ft_putchar(str[i]);
		i++;
	}
}
예제 #9
0
char				*get_string_hex(t_conversion *conversion
										, va_list arguments)
{
	char			*string;
	char			*final;
	uintmax_t		value;
	int				is_zero_value;

	value = get_unsigned_number_argument(conversion->length, arguments);
	if (!value && conversion->precision_set)
		string = ft_strdup("");
	else
		string = ft_basetoa(value, 16);
	if (conversion->specifier == HEX_LOWER)
		ft_strtolower(string);
	is_zero_value = string[0] == '0' || string[0] == '\0';
	add_precision_padding(conversion, &string);
	if ((conversion->flags.hashtag && !is_zero_value)
		&& !(conversion->precision_set && conversion->precision == 0))
	{
		final = ft_strjoin(conversion->specifier == HEX_LOWER ? "0x" : "0X"
							, string);
		free(string);
	}