Ejemplo n.º 1
0
char	*handle_lenght(char *s1, t_opt *opt)
{
	int		cmp;
	char	*str;

	cmp = 0;
	while (ft_isdigit(s1[cmp]))
		cmp++;
	str = ft_strsub(s1, 0, cmp);
	opt->lenght = ft_atoi(str);
	free(str);
	s1 += cmp;
	return (s1);
}
Ejemplo n.º 2
0
int		cut_cut_cbegin(char *tmp, char *tmp2, int lenn)
{
	tmp2 = ft_strsub(tmp, lenn, ft_strlen(tmp) - 1);
	tmp2 = ft_strtrim(tmp2);
	if (ft_strlen(tmp2) > PROG_NAME_LENGTH)
	{
		ft_printf("Name too big\n");
		exit(0);
	}
	if (tmp2[0] == '"' && tmp2[ft_strlen(tmp2) - 1] == '"')
		return (100);
	else
		return (0);
}
Ejemplo n.º 3
0
void		ft_cut(t_cmd_line *line)
{
	int		sel_len;

	line->sel_mode = 0;
	sel_len = line->sel_end - line->sel_start + 1;
	ft_clipboard(ft_strsub(line->str, line->sel_start, sel_len));
	ft_key_home(line);
	while (line->pos < line->sel_start)
		ft_key_right(line);
	while (sel_len--)
		ft_key_del(line);
	ft_refresh_line(line);
}
Ejemplo n.º 4
0
static int			ft_truc2(char *str, int i)
{
	char		*left;
	char		*right;
	int			j;

	j = ft_getcharpos(str, g_opera_char[i], (i == 2) ? 1 : 0);
	left = ft_strsub(str, 0, j);
	right = ft_strdup(str + j + ((i < 2) ? 2 : 1));
	g_calculette[i](left, right);
	ft_strdel(&left);
	ft_strdel(&right);
	return (1);
}
Ejemplo n.º 5
0
t_path	*init_path(char *line)
{
	t_path		*newpath;
	int			score_pos;

	newpath = malloc(sizeof(t_path));
	if (!newpath)
		return (NULL);
	score_pos = (int)ft_strlchr(line, '-');
	newpath->door1 = ft_strsub(line, 0, score_pos);
	newpath->door2 = ft_strdup(line + score_pos + 1);
	free(line);
	return (newpath);
}
Ejemplo n.º 6
0
static t_litem	*get_date(t_dir_item *item)
{
    char	**tmp;
    t_litem	*date;
    char	**cur_time;
    time_t	today;

    date = NULL;
    today = time(0);
    cur_time = ft_strsplit(ctime(&today), ' ');
    tmp = ft_strsplit(ctime(&item->prop.st_mtime), ' ');
    t_litem_push(&date, t_litem_new(ft_strdup(tmp[1])));
    t_litem_push(&date, t_litem_new(ft_strdup(tmp[2])));
    if ((today - item->prop.st_mtime) >= 15768000
            || (today - item->prop.st_mtime) < 0)
        t_litem_push(&date, t_litem_new(ft_strsub(tmp[4], 0
                                        , ft_strchr(tmp[4], '\n') - tmp[4])));
    else
        t_litem_push(&date, t_litem_new(ft_strsub(tmp[3], 0, 5)));
    ft_freetab(tmp);
    ft_freetab(cur_time);
    return (date);
}
Ejemplo n.º 7
0
int		first(t_getline *sd, char **line)
{
	char	*tmp;
	int		ret;
	int		i;

	tmp = ft_strnew(BUFF_SIZE);
	if (sd && sd->str && (ret = ft_is(sd->str, '\n')))
	{
		i = ft_strlen(sd->str);
		*line = ft_strsub(sd->str , 0, ret);
		i = i - ft_strlen(*line);
		sd->str = ft_strsub(sd->str, ret + 1, i);
		return (1);
	}
	else if (sd && sd->str)
	{
		*line = sd->str;
		sd->str = NULL;
	}
	while (sd && (ret = read(sd->fd, tmp, BUFF_SIZE)))
	{
		if (!ret)
			return (0);
		if ((ret = ft_is(tmp, '\n')))
		{
			tmp[ret] = '\0';
			*line = ft_strjoin(*line, tmp);
			sd->str = ft_strjoin(sd->str, &(tmp[ret + 1]));
			tmp[ret] = '\n';
			return (1);
		}
		else
			*line = ft_strjoin(*line, tmp);
	}
	return (ret);
}
Ejemplo n.º 8
0
Archivo: dollar.c Proyecto: nsavry/42sh
static char		*var_dollar(char **var)
{
	char	*str;
	int		a;

	str = NULL;
	a = 1;
	if (ft_strchr(*var, '/') && ft_strchr(*var, '.'))
	{
		if (ft_strchr(*var, '/') - ft_strchr(*var, '.') > 0)
			a = 0;
	}
	if (ft_strchr(*var, '/') && a)
	{
		str = ft_strsub(*var, ft_strchr(*var, '/') - *var, ft_strlen(*var));
		*var = ft_strsub(*var, 0, ft_strchr(*var, '/') - *var);
	}
	else if (ft_strchr(*var, '.'))
	{
		str = ft_strsub(*var, ft_strchr(*var, '.') - *var, ft_strlen(*var));
		*var = ft_strsub(*var, 0, ft_strchr(*var, '.') - *var);
	}
	return (str);
}
static int		add_line(char **line, char **mem, char *str)
{
	int		len;

	if ((len = ft_strchri(str, '\n')) >= 0)
	{
		if (!(*line = ft_strfjoin(*line, ft_strsub(str, 0, len), TRUE, TRUE)))
			return (EX_ERROR);
		*mem = &str[len] + 1;
		return (EX_SUCCESS);
	}
	if (!(*line = ft_strfjoin(*line, str, TRUE, FALSE)))
		return (EX_ERROR);
	return (EX_CONTINUE);
}
Ejemplo n.º 10
0
static int			put_in_line(char **line, char **tmp)
{
	unsigned int		len;
	char				*temp;

	len = ft_strclen(*tmp, '\n') + 1;
	if (tmp[0][0] == '\n')
	{
		if ((*line = ft_strnew(1)) == NULL)
			return (-1);
	}
	else
	{
		if ((*line = ft_strsub(*tmp, 0, len)) == NULL)
			return (-1);
		line[0][len - 1] = '\0';
	}
	if ((temp = ft_strsub(*tmp, len, ft_strlen(*tmp) - len)) == NULL)
		return (-1);
	if (*tmp)
		free(*tmp);
	*tmp = temp;
	return (1);
}
Ejemplo n.º 11
0
char	*ft_save(char *characters, char **keep)
{
	char		*rest;
	int			index;
	int			len;

	len = 0;
	index = 0;
	while (characters[index] != '\n')
		index++;
	if (index == 0)
	{
		rest = "";
		len = (ft_strlen(characters) - (index + 1));
		*keep = ft_strsub(characters, (index + 1), len);
	}
	else
	{
		rest = ft_strsub(characters, 0, index);
		len = (ft_strlen(characters) - (index + 1));
		*keep = ft_strsub(characters, (index + 1), len);
	}
	return (rest);
}
Ejemplo n.º 12
0
int	main(void)
{
	char	*s;
	char	*c;
	int		n1;
	size_t	n2;

	n1 = 3;
	n2 = 5;
	s = "qwertyuiop";
	c = (char*)malloc(11 * sizeof(*c));
	c = ft_strsub(s, n1, n2);
	printf("\n%s\n\n%d - %ld\n\n%s\n\n", s, n1, n2, c);
	return (0);
}
Ejemplo n.º 13
0
static char		*ft_strdup_mod(char *s, char c)
{
	static size_t	i = 0;
	size_t			word_len;

	word_len = 0;
	while (s[i] != 0 && s[i] == c)
		i++;
	while (s[i] != 0 && s[i] != c)
	{
		word_len++;
		i++;
	}
	return (ft_strsub(s, i - word_len, word_len));
}
Ejemplo n.º 14
0
static int		ft_printf_not_argue(t_printf *conv, char *fmt, int i)
{
	int		a;

	a = i;
	while (fmt[a] != '%' && fmt[a] != '\0' && fmt[a] != '{')
		a++;
	conv->arg = ft_new_arg(conv->arg);
	conv->arg->value = ft_strsub(fmt, i, a - i);
	conv->arg->size = a - i;
	conv->return_value += a - i;
	if (fmt[a] == '{')
		a = ft_add_color(fmt, a, conv);
	return (a);
}
Ejemplo n.º 15
0
char	*ft_strtrim(char const *str)
{
	char const	*ptr_str;

	if (str == NULL)
		return (NULL);
	while (ft_isspace(*str) == 1)
		str++;
	if (*str == '\0')
		return (ft_strnew(0));
	ptr_str = str + ft_strlen(str) - 1;
	while (ft_isspace(*ptr_str) == 1)
		ptr_str--;
	return (ft_strsub(str, 0, ptr_str - str + 1));
}
Ejemplo n.º 16
0
char	*ft_strtrim(char const *s)
{
	int		i;
	int		len;

	i = 0;
	len = ft_strlen(s) - 1;
	while (s[len] == ' ' || s[len] == '\n' || s[len] == '\t')
		len--;
	while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
		i++;
	if (len <= i)
		len = i;
	return (ft_strsub(s, i, len - i + 1));
}
Ejemplo n.º 17
0
static int			ft_get_rsrcs(char *message)
{
	int		rsrc;
	char	*msg;

	rsrc = 0;
	msg = ft_strsub(message, 6, ft_strlen(message) - 7);
	while (rsrc < 7)
	{
		if (ft_strcmp(msg, g_rsrc[rsrc]) == 0)
			return (rsrc);
		rsrc++;
	}
	return (-1);
}
Ejemplo n.º 18
0
static int	fill_the_line(const int fd, char *tmp[fd], char **line)
{
	int		end;
	char	*temp;

	end = end_of_line(tmp[fd]);
	*line = ft_strsub(tmp[fd], 0, end);
	if (!(temp = (char *)malloc(sizeof(temp) * (ft_strlen(tmp[fd]) + 1))))
		return (-1);
	ft_strcpy(temp, &tmp[fd][end + 1]);
	ft_strclr(tmp[fd]);
	tmp[fd] = ft_strcpy(tmp[fd], temp);
	free(temp);
	return (1);
}
Ejemplo n.º 19
0
char			*ft_strtrim_n(char const *s)
{
	char		*result;
	int		end;

	if (!s)
		return (NULL);
	while (*s == '\n')
		s++;
	if (!*s)
		return (ft_strnew(1));
	end = ft_strchrnoprint2((char*)s, ft_strlen(s) - 1);
	result = ft_strsub((char*)s, 0, (ft_strlen(s) - end));
	return (result);
}
Ejemplo n.º 20
0
char			*skip_quotes(char **str, size_t *i, t_cmd *cmd)
{
	size_t		start;

	if (is_quote_open((*str)[*i]) && !is_escaped_char(*str, *i) &&
	!verif_empty_quote(*str, i))
		return (NULL);
	start = *i;
	skip_quotes_replace_string(cmd, str, i);
	if (start != *i)
	{
		return (ft_strsub(*str, start, *i - start));
	}
	return (NULL);
}
Ejemplo n.º 21
0
char			*ft_strtrim(char const *s)
{
	size_t			i;
	size_t			j;

	i = 0;
	j = ft_strlen(s) - 1;
	while (s[i] && ft_isspace(s[i]))
		++i;
	while (j && ft_isspace(s[j]))
		--j;
	if (j < i)
		return (ft_strnew(0));
	return (ft_strsub(s, i, j - i + 1));
}
Ejemplo n.º 22
0
static int		ft_get_precision_err(char *fmt, int i, t_printf *conv)
{
	int		a;

	a = i;
	if (fmt[a++] == '*')
		conv->wc_arg++;
	else
		while (fmt[a] >= 48 && fmt[a] < 58)
			a++;
	if (conv->precision != NULL)
		ft_memdel((void **)&conv->precision);
	conv->precision = ft_strsub(fmt, i, a - i);
	return (a - i);
}
Ejemplo n.º 23
0
static void	ft_new_cmd(t_cmd *cmd, int index, int count)
{
	char	*tmp;
	char	*begin;
	char	*result;

	tmp = NULL;
	result = ft_get_quoted();
	begin = ft_strsub(cmd->split[index], 0, count);
	count++;
	while (cmd->split[index][count] && cmd->split[index][count] != '`')
		count++;
	tmp = ft_strsub(cmd->split[index], count + 1,
		ft_strlen(cmd->split[index]) - 1 - count);
	free(cmd->split[index]);
	cmd->split[index] = ft_strjoin(begin, result);
	free(begin);
	begin = ft_strdup(cmd->split[index]);
	free(cmd->split[index]);
	cmd->split[index] = ft_strjoin(begin, tmp);
	free(begin);
	free(tmp);
	free(result);
}
Ejemplo n.º 24
0
int		ft_strcsub(char **dst, char *src, unsigned int start, char end)
{
	int		len;

	len = 0;
	if (!dst || !src)
	{
		*dst = NULL;
		return (-1);
	}
	while (src[len + start] && src[len + start] != end)
		++len;
	*dst = ft_strsub(src, start, len);
	return (len);
}
Ejemplo n.º 25
0
static inline char	*ft_strrtrim(char const *s)
{
	char	*t;
	char	*t2;

	t = (char *)s;
	t2 = t;
	while (*t != '\0')
	{
		if (!ft_is_white_space(*t))
			t2 = t + 1;
		t++;
	}
	return (ft_strsub(s, 0, t2 - s));
}
Ejemplo n.º 26
0
Archivo: get.c Proyecto: ntrancha/42
int			 get_next_line_split(char *all, char **line)
{
	int		 index;

	index = 0;
	while (all[index] != '\n' && all[index])
	{
		index++;
	}
	if (!all[index] && !index && all[0] != '\n')
		index = -1;
	ft_strdel(line);
	*line = ft_strsub(all, 0, index);
	return (index);
}
Ejemplo n.º 27
0
static void			register_conversion(t_prf *env, t_specs *specs, int to_copy,
		int save)
{
	char			*tmp;

	tmp = ft_strsub(env->format, save, to_copy);
	ft_strcpy(specs->conversion, tmp);
	ft_strdel(&tmp);
	specs->format = specs->conversion[to_copy - 1];
	if (specs->format == 'o' || specs->format == 'O')
		specs->base = 8;
	else if (specs->format == 'x' || specs->format == 'X'
			|| specs->format == 'p')
		specs->base = 16;
}
Ejemplo n.º 28
0
static char	*lx_op(char *str, t_cmd *op, int n)
{
    char	*tmp;
    char	*cpy;
    int		start;

    start = 0;
    if (n == 1)
        start = lx_pos_op(str, "|");
    else if (n == 3)
        start = lx_pos_op(str, ">");
    else if (n == 4)
        start = lx_pos_op(str, ">>");
    else if (n == 2)
        start = lx_pos_op(str, "<");
    tmp = ft_strsub(str, 0, start);
    lx_add_more(op, lx_new_more(tmp, n));
    if (n == 4)
        cpy = ft_strsub(str, start + 2, ft_strlen(str) - start);
    else
        cpy = ft_strsub(str, start + 1, ft_strlen(str) - start);
    free(str);
    return (cpy);
}
Ejemplo n.º 29
0
static void		cut_selection(int begin, int end, t_it *it)
{
	char	*first;
	char	*second;
	int		lenght;

	lenght = ft_strlen(it->line) - (end - it->offset);
	second = ft_strsub(it->line, end + 1, lenght - 1);
	first = ft_memalloc((sizeof(char) * begin) + 1);
	ft_strncpy(first, it->line, begin);
	ft_memdel((void**)&it->line);
	it->line = ft_strjoin(first, second);
	ft_memdel((void**)&first);
	ft_memdel((void**)&second);
}
Ejemplo n.º 30
0
char			*ft_itoa(int n)
{
	int		pow;
	size_t	len;
	char	*str;

	if (n == MIN_INT)
		return (ft_strsub("-2147483648", 0, 11));
	len = ft_sizealloc(n, &pow);
	str = malloc(sizeof(char) * len);
	if (!str)
		return (NULL);
	len--;
	return (ft_makestr(str, n, pow, len));
}