Ejemplo n.º 1
0
/* Raw parsing */
static uint16_t hb_parse_character( hb_csv_file_t * file )
{
    int byte;
    uint16_t c = 0;
    int need_char = 1;

    if( file == NULL )
    {
        return CSV_CHAR_ERROR;
    }

    while( need_char )
    {
        byte = fgetc( file->fileref );
        if( feof( file->fileref ) )
        {
            return CSV_CHAR_EOF;
        }
        if( ferror( file->fileref ) )
        {
            return CSV_CHAR_ERROR;
        }

        if( file->parse_state == CSV_PARSE_SEEK && is_white(byte) )
        {
            continue;
        }
        else if( file->parse_state != CSV_PARSE_ESC && is_esc(byte) )
        {
            file->parse_state = CSV_PARSE_ESC;
            continue;
        }
        else if( file->parse_state != CSV_PARSE_ESC && is_sep(byte) )
        {
            file->parse_state = CSV_PARSE_SEEK;
            need_char = 0;
            c = CSV_CHAR_COLSEP;
        }
        else if( file->parse_state == CSV_PARSE_ESC )
        {
            file->parse_state = CSV_PARSE_NORMAL;
            need_char = 0;
            c = (uint16_t)byte;
        }
        else if( is_newline(byte) )
        {
            file->parse_state = CSV_PARSE_SEEK;
            need_char = 0;
            c = CSV_CHAR_ROWSEP;
        }
        else
        {
            file->parse_state = CSV_PARSE_NORMAL;
            need_char = 0;
            c = (uint16_t)byte;
        }
    }

    return c;
}
Ejemplo n.º 2
0
void			handle_key(t_elem **list, struct termios *backup)
{
	char	*buf;
	int		update_screen;
	int		*enought_space;

	buf = ft_strnew(4);
	update_screen = 1;
	enought_space = get_enought_space();
	while (!is_esc(buf))
	{
		*enought_space = check_window_size(*list);
		if (update_screen && *enought_space)
			print_arg_list(*list);
		ft_bzero(buf, ft_strlen(buf));
		if (read(0, buf, 3) == -1)
			ft_error("Read error", 1);
		if (*enought_space
				&& (update_screen = check_key(list, backup, buf)) == -1)
			break ;
	}
	ft_strdel(&buf);
}