示例#1
0
int		ft_getline(t_file *file, char **line)
{
	char	*end;
	char	*temp;
	char	tmp[BUFF_SIZE + 1];
	int		in;

	if ((in = read(file->fd, tmp, BUFF_SIZE)) == -1)
		return (-1);
	tmp[in] = '\0';
	if (file->buff)
	{
	   file->buff = ft_strjoinfree(file->buff, tmp, 1);
		end = ft_strchr(file->buff, '\n');
	}
	else
		return (ft_last(file, line));
	if (end == NULL)
		return ((in == 0) ? ft_last(file, line) : ft_getline(file, line));
	*end = '\0';
	*line = ft_strdup(file->buff);
	*end = '\n';
	temp = file->buff;
	file->buff = ft_strdup(end + 1);
	ft_memdel((void **)&temp);
	return (1);
}
示例#2
0
文件: wp_helper.c 项目: Yatty1/libft
char			*adjust_precision(char *str, t_flag *flag)
{
	char	*tmp;
	char	*prec;
	int		len;

	len = flag->precision - ft_strlen(str);
	if (len > 0 && (flag->zero || !flag->str))
	{
		prec = (char *)ft_memset(ft_strnew(len), '0', len);
		tmp = ft_strjoinfree(prec, str);
	}
	else if (len >= 0 || flag->precision < 0)
	{
		flag->zero_processed = 1;
		return (str);
	}
	else if (flag->str)
		tmp = ft_strsubfree(str, 0, flag->precision);
	else if (flag->dot && flag->precision == 0 && *str == '0')
		tmp = zero_precision(str, *flag);
	else
		tmp = str;
	flag->zero_processed = 1;
	return (tmp);
}
示例#3
0
void	server_ls(int cs)
{
	char			path[BUF_SIZE];
	char			*output;
	DIR				*dir;
	struct dirent	*entry;

	dir = opendir(getcwd(path, BUF_SIZE));
	output = ft_strdup("SUCCESS:");
	while (ft_strjoinfree(&output, "\n"), entry = readdir(dir), entry != NULL)
		ft_strjoinfree(&output, entry->d_name);
	closedir(dir);
	server_sendint(cs, ft_strlen(output) + 1);
	server_sendstr(cs, output, ft_strlen(output) + 1);
	free(output);
}
示例#4
0
char	*ft_intab(va_list va, t_format *opt)
{
	int		size;
	int		*tab;
	char	*buff;

	buff = NULL;
	opt->type = STR_V;
	size = va_arg(va, int);
	tab = va_arg(va, int *);
	buff = ft_anytoa_bin(*tab, 1, -1, 0);
	buff = ft_strjoinfree(buff, " ", 1);
	while (--size)
	{
		buff = ft_strjoinfree(buff, ft_anytoa_bin(*(++tab), 1, -1, 0), 3);
		if (size != 1)
			buff = ft_strjoinfree(buff, " ", 1);
	}
	return (buff);
}
示例#5
0
文件: main.c 项目: sploadie/ft-ls
static int	deal_options(char **options, int listsize, char **list)
{
	int	i;

	i = 1;
	while (i < listsize && tru_arg(list[i]) && isoption(list[i]))
		ft_strjoinfree(options, list[i++] + 1);
	check_options(*options);
	if (i < listsize && ft_strcmp(list[i], "--") == 0)
		i++;
	return (i);
}
示例#6
0
文件: main.c 项目: armou/piscine42
static void		ft_parsefdf(t_windata *t_fdf, int fd)
{
	char	*line;
	int		i;
	int		j;

	t_fdf->ymax = 0;
	t_fdf->map = ft_strnew(BUFF_SIZE);
	while (get_next_line(fd, &line))
	{
		if (!t_fdf->xmax)
			t_fdf->xmax = ft_calc_x(line);
		t_fdf->map = ft_strjoinfree(t_fdf->map, line);
		t_fdf->map = ft_strjoinfree(t_fdf->map, "\n");
		t_fdf->ymax++;
		free(line);
	}
	if (!(t_fdf->tab = (char***)ft_memalloc(sizeof(char**) * (t_fdf->ymax + 1))))
		ft_exit();
	//	printf("map = %s\n", t_fdf->map);
	t_fdf->split = ft_strsplit(t_fdf->map, '\n');
//	i = -1;
//	while (++i < t_fdf->ymax)
//		printf("strsplit[i] = %s\n", t_fdf->split[i]);
	i = -1;
	while (t_fdf->split[++i])
	{
		t_fdf->tab[i] = ft_strsplit(t_fdf->split[i], ' ');
		free(t_fdf->split[i]);
	}
	free(t_fdf->split);
//	i = -1;
//	while (t_fdf->tab[++i])
//	{
//		j = -1;
//		while (t_fdf->tab[i][++j])
//			printf("tab[%d][%d] = %s\n", i, j, t_fdf->tab[i][j]);
//	}
}
示例#7
0
int	get_next_line(int const fd, char **line)
{
  static char stck[BUFF_SIZE];
  char *buf;
  char *tmp;
  int i;
  
  if (BUFF_SIZE < 1 || !line)
    return (-1);
  if (!(buf = malloc(sizeof(char) * BUFF_SIZE + 1)))
    return (-1);
  if (!(tmp = ft_strncpy(ft_strnew(BUFF_SIZE), stck, BUFF_SIZE)))
    return (-1);
  while (ft_strchr(tmp, '\n') == 0)
    {
      if ((i = read(fd, buf, BUFF_SIZE)) == -1)
	return (-1);
      if (i == 0 && ft_strlen(tmp))
	{
	  *line = ft_strncpy(ft_strnew(ft_strlen(tmp)), tmp, ft_strlen(tmp));
	  free(tmp);
	  free(buf);
	  ft_bzero(stck, BUFF_SIZE);
	  i = 1;
          return (0);
	}
      else if (i == 0)
      {
            *line = NULL;
          return (0);
    }
    buf[i] = '\0';
    tmp = ft_strjoinfree(tmp, buf, 1);
    }
  free(buf);
  i = (size_t)(ft_strchr(tmp, '\n') - tmp);
  *line = ft_strncpy(ft_strnew(i), tmp, i);
  ft_bzero(stck, BUFF_SIZE);
  ft_strncpy(stck, ft_strchr(tmp, '\n') + 1, BUFF_SIZE);
  free(tmp);
  return (1);
}