Skip to content

Commit

Permalink
norm and flag check
Browse files Browse the repository at this point in the history
  • Loading branch information
Rouhija committed Jan 12, 2020
1 parent 2f86cf2 commit e1f639f
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 82 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
# By: srouhe <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/10/15 16:29:02 by srouhe #+# #+# #
# Updated: 2020/01/08 19:58:21 by srouhe ### ########.fr #
# Updated: 2020/01/12 15:08:08 by srouhe ### ########.fr #
# #
# **************************************************************************** #

NAME = ft_select
C = gcc
FLAGS =
FLAGS = -Wall -Werror -Wextra

FILES = action.c \
args.c \
config.c \
input.c \
main.c \
misc.c \
print.c \
signal.c \
utils.c
Expand All @@ -43,4 +42,9 @@ fclean: clean

re: fclean all

.PHONY: all clean fclean re
norm:
norminette srcs/*.c
norminette includes/*.h
make norm -C libft

.PHONY: all clean fclean re norm
45 changes: 22 additions & 23 deletions includes/ft_select.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: srouhe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/06 18:15:52 by srouhe #+# #+# */
/* Updated: 2020/01/10 21:17:50 by srouhe ### ########.fr */
/* Updated: 2020/01/12 15:07:13 by srouhe ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -36,7 +36,6 @@

# define BUF_SIZE 4096
# define COLUMN_W 8
# define RETRY 30
# define HEADER 4
# define OUTPUT 2
# define JUMP 1
Expand All @@ -53,7 +52,7 @@
# define C_NO "\033[22;37m"
# define HEADING "\033[01;34m"

# define EXIT_0 "ft_select: successful exit."
# define EXIT_0 "ft_select: graceful exit."
# define EXIT_1 "usage: ./ft_select arg1 [arg2] ..."
# define EXIT_2 "ft_select: terminal configuration not found."
# define EXIT_3 "ft_select: malloc error."
Expand Down Expand Up @@ -128,31 +127,31 @@ t_sel g_sel;
** -------- FUNCTIONS --------
*/

int printnbr(int nbr);
int step_count(long key);
char *get_color(char *name);
int printnbr(int nbr);
int step_count(long key);
char *get_color(char *name);

int column_count(void);
void initial_config(void);
void reset_config(void);
void exit_program(char *arg, int code, int flag);
int column_count(void);
void initial_config(void);
void reset_config(void);
void exit_program(int code, int flag);

void monitor_signals(void);
void signal_handler(int signo);
void monitor_signals(void);
void signal_handler(int signo);

void wait_for_input(void);
void wait_for_input(void);

void set_args(char **av);
void free_arg(t_arg **arg);
void free_memory(void);
void set_args(char **av);
void free_arg(t_arg **arg);
void free_memory(void);

void print_args(void);
void print_selection(void);
void print_args(void);
void print_selection(void);

void cursor_move(int x, int y);
void action_bks(void);
void action_spc(void);
void action_arrow(long key);
void action_all(long key);
void cursor_move(int x, int y);
void action_bks(void);
void action_spc(void);
void action_arrow(long key);
void action_all(long key);

#endif
6 changes: 1 addition & 5 deletions libft/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: srouhe <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/10/15 16:29:02 by srouhe #+# #+# #
# Updated: 2020/01/10 20:55:05 by srouhe ### ########.fr #
# Updated: 2020/01/12 15:05:52 by srouhe ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -63,10 +63,6 @@ norm:
norminette includes/*.h
norminette ptf/*.c

test: re
@/bin/rm -f a.out
@$(C) $(FLAGS) main.c -I $(HDRS) -L. -lft

.PHONY: all
.PHONY: clean
.PHONY: fclean
Expand Down
6 changes: 3 additions & 3 deletions libft/srcs/ft_endswith.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: srouhe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/10 20:51:17 by srouhe #+# #+# */
/* Updated: 2020/01/10 21:03:05 by srouhe ### ########.fr */
/* Updated: 2020/01/12 14:34:42 by srouhe ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,5 +19,5 @@ int ft_endswith(const char *ends, char *with)
i = (int)(ft_strlen(ends) - ft_strlen(with));
if (i < 0)
return (0);
return (ft_strequ(&ends[i], with));
}
return (ft_strequ(&ends[i], with));
}
4 changes: 2 additions & 2 deletions libft/srcs/ft_rfind.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: srouhe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/07 18:04:30 by srouhe #+# #+# */
/* Updated: 2020/01/07 18:12:43 by srouhe ### ########.fr */
/* Updated: 2020/01/12 14:34:22 by srouhe ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -30,4 +30,4 @@ char *ft_rfind(const char *s, int c)
i--;
}
return (NULL);
}
}
4 changes: 2 additions & 2 deletions srcs/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: srouhe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/08 18:33:45 by srouhe #+# #+# */
/* Updated: 2020/01/10 15:04:40 by srouhe ### ########.fr */
/* Updated: 2020/01/12 14:39:23 by srouhe ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -41,7 +41,7 @@ void action_bks(void)
next->prev = prev;
}
else
exit_program(NULL, 0, 1);
exit_program(0, 1);
tputs(CL, 1, printnbr);
}

Expand Down
8 changes: 4 additions & 4 deletions srcs/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: srouhe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/07 18:23:56 by srouhe #+# #+# */
/* Updated: 2020/01/10 14:57:56 by srouhe ### ########.fr */
/* Updated: 2020/01/12 14:39:18 by srouhe ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -45,7 +45,7 @@ t_arg *new_arg(char *name)
t_arg *new;

if (!(new = (t_arg *)ft_memalloc(sizeof(t_arg))))
exit_program(NULL, 3, 0);
exit_program(3, 0);
new->toggle = 0;
new->name = ft_rfind(name, '/') ?
ft_strdup(ft_rfind(name, '/') + 1) : ft_strdup(name);
Expand Down Expand Up @@ -93,8 +93,8 @@ void set_args(char **av)
g_sel.max_w = 0;
while (av[++i])
{
g_sel.max_w = ft_strlen(av[i]) > g_sel.max_w ?
ft_strlen(av[i]) : g_sel.max_w;
g_sel.max_w = (int)ft_strlen(av[i]) > g_sel.max_w ?
(int)ft_strlen(av[i]) : g_sel.max_w;
insert_arg(av[i]);
}
}
10 changes: 5 additions & 5 deletions srcs/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: srouhe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/07 12:01:39 by srouhe #+# #+# */
/* Updated: 2020/01/10 15:27:07 by srouhe ### ########.fr */
/* Updated: 2020/01/12 14:39:43 by srouhe ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -25,14 +25,14 @@ void initial_config(void)
char buf[BUF_SIZE + 1];

if (!isatty(OUTPUT))
exit_program(NULL, 4, 0);
exit_program(4, 0);
if (!(term = getenv("TERM")))
exit_program(NULL, 7, 0);
exit_program(7, 0);
r = tgetent(buf, term);
if (r == -1)
exit_program(NULL, 5, 0);
exit_program(5, 0);
else if (r == 0)
exit_program(NULL, 6, 0);
exit_program(6, 0);
tcgetattr(OUTPUT, &g_sel.attr);
tcgetattr(OUTPUT, &g_sel.def);
g_sel.attr.c_oflag &= ~OPOST;
Expand Down
4 changes: 2 additions & 2 deletions srcs/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: srouhe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/07 12:56:18 by srouhe #+# #+# */
/* Updated: 2020/01/10 20:25:12 by srouhe ### ########.fr */
/* Updated: 2020/01/12 14:39:07 by srouhe ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -24,7 +24,7 @@ void wait_for_input(void)
if ((r = read(2, &key, 8)) < 1)
continue ;
if (key == ESC)
exit_program(NULL, 0, 1);
exit_program(0, 1);
else if (key == ENT)
break ;
else if (key == A_UP || key == A_LO)
Expand Down
6 changes: 3 additions & 3 deletions srcs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
/* By: srouhe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/06 19:10:26 by srouhe #+# #+# */
/* Updated: 2020/01/09 20:13:26 by srouhe ### ########.fr */
/* Updated: 2020/01/12 14:38:57 by srouhe ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_select.h"

void exit_program(char *arg, int code, int flag)
void exit_program(int code, int flag)
{
if (flag)
{
Expand All @@ -33,7 +33,7 @@ void exit_program(char *arg, int code, int flag)
int main(int ac, char **av)
{
if (ac < 2)
exit_program(NULL, 1, 0);
exit_program(1, 0);
monitor_signals();
set_args(av);
initial_config();
Expand Down
18 changes: 0 additions & 18 deletions srcs/misc.c

This file was deleted.

10 changes: 5 additions & 5 deletions srcs/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: srouhe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/07 23:17:05 by srouhe #+# #+# */
/* Updated: 2020/01/10 21:19:40 by srouhe ### ########.fr */
/* Updated: 2020/01/12 14:37:02 by srouhe ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -48,7 +48,8 @@ static void print_out(void)
g_sel.selected++;
}
ft_putstr_fd(g_sel.args->color, OUTPUT);
if (ft_endswith(g_sel.args->name, ".o") || ft_endswith(g_sel.args->name, ".c"))
if (ft_endswith(g_sel.args->name, ".o") ||
ft_endswith(g_sel.args->name, ".c"))
ft_printf(OUTPUT, "\e[3m%s\e[0m", g_sel.args->name);
else
ft_putstr_fd(g_sel.args->name, OUTPUT);
Expand Down Expand Up @@ -81,13 +82,13 @@ void print_args(void)
int i;
int j;

i = 0;
i = -1;
j = -1;
if (!column_count())
return ;
g_sel.selected = 0;
g_sel.args = g_sel.head;
while (i < g_sel.ac)
while (++i < g_sel.ac)
{
cursor_move(g_sel.x, g_sel.y);
g_sel.y += 1;
Expand All @@ -100,7 +101,6 @@ void print_args(void)
cursor_move(g_sel.x, 0);
}
g_sel.args = g_sel.args->next;
i++;
}
print_header();
cursor_move(0, 0);
Expand Down
6 changes: 3 additions & 3 deletions srcs/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: srouhe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/03 15:11:21 by srouhe #+# #+# */
/* Updated: 2020/01/10 23:08:12 by srouhe ### ########.fr */
/* Updated: 2020/01/12 14:39:58 by srouhe ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -52,9 +52,9 @@ void signal_handler(int signo)
signo == SIGSTOP || signo == SIGQUIT || signo == SIGABRT)
{
reset_config();
exit_program(NULL, 0, 1);
exit_program(0, 1);
}
else if (signo = SIGWINCH)
else if (signo == SIGWINCH)
{
tputs(CL, 1, printnbr);
print_args();
Expand Down
Loading

0 comments on commit e1f639f

Please sign in to comment.