~nloomans/ft_select

dbeabde07cde5b5c2615ececd04fea9677fc59a2 — Noah Loomans 1 year, 8 months ago 1339fc3
fix all easy norm errors
M inc/action.h => inc/action.h +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#ifndef ACTION_H
# define ACTION_H


M inc/derive.h => inc/derive.h +19 -2
@@ 1,29 1,46 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#ifndef DERIVE_H
# define DERIVE_H

#include "state.h"
#include "error.h"
# include "state.h"
# include "error.h"

/*
** empty line followed by a vertical bar
*/
# define DERIVE_PADDING_TOP 2

/*
** vertical bar followed by an empty line
*/
# define DERIVE_PADDING_BOTTOM 2

/*
** 2 spaces followed by a horizontal bar followed by a single space
*/
# define DERIVE_PADDING_LEFT 4

/*
** single space followed by a horizontal bar followed by 2 spaces
*/
# define DERIVE_PADDING_RIGHT 4

/*
** Either '  ', '[ ', or '[*'
*/
# define DERIVE_OPTION_PADDING_LEFT 2

/*
** Either ' ', ']'
*/

M inc/error.h => inc/error.h +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#ifndef ERROR_H
# define ERROR_H


M inc/event.h => inc/event.h +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#ifndef EVENT_H
# define EVENT_H


M inc/list2.h => inc/list2.h +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#ifndef LIST2_H
# define LIST2_H


M inc/read.h => inc/read.h +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#ifndef READ_H
# define READ_H


M inc/render.h => inc/render.h +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#ifndef RENDER_H
# define RENDER_H


M inc/state.h => inc/state.h +15 -3
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#ifndef STATE_H
# define STATE_H



@@ 5,20 17,20 @@
# include "list2.h"
# include "error.h"

struct	s_state_terminal
struct					s_state_terminal
{
	size_t	rows;
	size_t	columns;
};

struct	s_state_option
struct					s_state_option
{
	char				*name;
	bool				selected;
	struct s_list2_conn	conn;
};

struct	s_state
struct					s_state
{
	struct s_state_terminal	terminal;
	t_list2_meta			options;

M inc/terminal.h => inc/terminal.h +13 -1
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#ifndef TERMINAL_H
# define TERMINAL_H



@@ 19,7 31,7 @@

void	terminal_send(char *cmd);

enum e_terminal_configure_action {
enum	e_terminal_configure_action {
	TERMINAL_CONFIGURE_SETUP,
	TERMINAL_CONFIGURE_RESTORE,
};

M src/action/confirm.c => src/action/confirm.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <stdlib.h>
#include <ft_printf.h>
#include "terminal.h"

M src/action/delete.c => src/action/delete.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <stdlib.h>
#include <libft.h>
#include "action.h"

M src/action/move.c => src/action/move.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include "action.h"
#include "derive.h"


M src/action/noop.c => src/action/noop.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include "action.h"

void			action_noop(struct s_state *state)

M src/action/quit.c => src/action/quit.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <stdlib.h>
#include "terminal.h"
#include "action.h"

M src/action/select.c => src/action/select.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include "action.h"
#include "state.h"


M src/action/update_size.c => src/action/update_size.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <sys/ioctl.h>
#include <unistd.h>
#include <libft.h>

M src/derive.c => src/derive.c +15 -4
@@ 1,5 1,16 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
# include <ft_printf.h>
#include "derive.h"

static size_t	max(size_t a, size_t b)


@@ 33,7 44,7 @@ t_error			derive_column_width(

	*res = ft_memalloc(dimensions.columns * sizeof(**res));
	if (*res == NULL)
		return errorf("unable to malloc column width array");
		return (errorf("unable to malloc column width array"));
	conn = options.first;
	column_index = 0;
	while (column_index < dimensions.columns)


@@ 60,13 71,13 @@ static t_error	malloc_rows(

	*res = ft_memalloc(sizeof(**res) * dimensions.rows);
	if (*res == NULL)
		return errorf("unable to malloc rows array");
		return (errorf("unable to malloc rows array"));
	row_index = 0;
	while (row_index < dimensions.rows)
	{
		(*res)[row_index] = ft_memalloc(sizeof(***res) * dimensions.columns);
		if ((*res)[row_index] == NULL)
			return errorf("unable to malloc column in rows array");
			return (errorf("unable to malloc column in rows array"));
		row_index++;
	}
	return (ERROR_NULL);

M src/error.c => src/error.c +23 -9
@@ 1,22 1,36 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <ft_printf.h>
#include "error.h"

t_error         errorf(char *fmt, ...)
t_error	errorf(char *fmt, ...)
{
	va_list		vlist;
	ssize_t		ret;
    t_error     dest;
	va_list	vlist;
	ssize_t	ret;
	t_error	dest;

	va_start(vlist, fmt);
	ret = ft_vsnprintf(dest.msg, sizeof(dest.msg), fmt, vlist);
	va_end(vlist);
    if (ret == -1)
        return ((t_error){
	if (ret == -1)
	{
		return ((t_error){
			.msg = "an error occurred during the generation of this error" });
    return (dest);
	}
	return (dest);
}

bool			is_error(t_error error)
bool	is_error(t_error error)
{
		return (error.msg[0] != '\0');
	return (error.msg[0] != '\0');
}

M src/event.c => src/event.c +32 -21
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>


@@ 26,7 38,7 @@ static void						handle_suspend(int signum)
	terminal_configure(TERMINAL_CONFIGURE_RESTORE);
	signal(SIGTSTP, SIG_DFL);
	tcgetattr(STDIN_FILENO, &attr);
	ioctl(STDIN_FILENO, TIOCSTI, (char []){attr.c_cc[VSUSP], '\0'});
	ioctl(STDIN_FILENO, TIOCSTI, (char[]){attr.c_cc[VSUSP], '\0'});
}

static void						handle_continue(int signum)


@@ 89,28 101,27 @@ static void						handle_generic(int signum)
}

const t_action	g_event_key_map[READ_TYPE_AMOUNT][128] = {
	[ READ_TYPE_REG ] = {
		[ 'q' ] = action_quit,
		[ 'j' ] = action_down,
		[ 'k' ] = action_up,
		[ 'h' ] = action_left,
		[ 'l' ] = action_right,
		[ ' ' ] = action_select,
		[ '\x7f' ] = action_delete,
		[ '\n' ] = action_confirm,
	[READ_TYPE_REG] = {
		['q'] = action_quit,
		['j'] = action_down,
		['k'] = action_up,
		['h'] = action_left,
		['l'] = action_right,
		[' '] = action_select,
		['\x7f'] = action_delete,
		['\n'] = action_confirm,
	},
	[ READ_TYPE_ESC ] = {
		[ 'A' ] = action_up,
		[ 'B' ] = action_down,
		[ 'D' ] = action_left,
		[ 'C' ] = action_right,
	[READ_TYPE_ESC] = {
		['A'] = action_up,
		['B'] = action_down,
		['D'] = action_left,
		['C'] = action_right,
	},
	[ READ_TYPE_ESC_SQL ] = {
		[ '3' ] = action_delete,
	[READ_TYPE_ESC_SQL] = {
		['3'] = action_delete,
	},
};


t_error							event_init(void)
{
	size_t	signum;


@@ 139,7 150,7 @@ t_error							event_init(void)
	return (ERROR_NULL);
}

static t_action				next_signal(void)
static t_action					next_signal(void)
{
	size_t	signum;



@@ 157,7 168,7 @@ static t_action				next_signal(void)
	return (NULL);
}

static t_error				next_key(t_action *dest)
static t_error					next_key(t_action *dest)
{
	struct s_read_seq	seq;



@@ 168,7 179,7 @@ static t_error				next_key(t_action *dest)
	return (ERROR_NULL);
}

t_error						event_next(t_action *dest)
t_error							event_next(t_action *dest)
{
	t_error			error;


M src/list2.c => src/list2.c +15 -3
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include "list2.h"



@@ 28,9 40,9 @@ void	list2_insert(
	meta->len++;
}

void			list2_unlink(
					t_list2_meta *meta,
					t_list2_conn *conn)
void	list2_unlink(
			t_list2_meta *meta,
			t_list2_conn *conn)
{
	if (meta->first == conn)
		meta->first = conn->next;

M src/list2_test.c => src/list2_test.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <criterion/criterion.h>
#include "list2.h"


M src/main.c => src/main.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <stdlib.h>
#include <libft.h>
#include <ft_printf.h>

M src/read.c => src/read.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <unistd.h>
#include <errno.h>
#include <libft.h>

M src/render.c => src/render.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <stdbool.h>
#include <unistd.h>
#include <ft_printf.h>

M src/render.debug.c => src/render.debug.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include "state.h"
#include "terminal.h"
#include "render.h"

M src/state.c => src/state.c +12 -0
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include <ft_printf.h>
#include <string.h>

M src/terminal.c => src/terminal.c +15 -3
@@ 1,3 1,15 @@
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <stdlib.h>
#include <termios.h>
#include <unistd.h>


@@ 5,12 17,12 @@
#include <unistd.h>
#include "terminal.h"

static int ft_putchar(int c)
static int	ft_putchar(int c)
{
	return (write(STDERR_FILENO, &c, 1));
}

void	terminal_send(char *cmd)
void		terminal_send(char *cmd)
{
	tputs(tgetstr(cmd, NULL), 1, ft_putchar);
}


@@ 23,7 35,7 @@ void	terminal_send(char *cmd)
** - VTIME = 1: A maximum of 100ms per keypress;
*/

void	terminal_configure(enum e_terminal_configure_action action)
void		terminal_configure(enum e_terminal_configure_action action)
{
	static struct termios	original;
	struct termios			new;