-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
68 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -36,7 +36,6 @@ | |
|
||
# define BUF_SIZE 4096 | ||
# define COLUMN_W 8 | ||
# define RETRY 30 | ||
# define HEADER 4 | ||
# define OUTPUT 2 | ||
# define JUMP 1 | ||
|
@@ -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." | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 # | ||
# # | ||
# **************************************************************************** # | ||
|
||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -30,4 +30,4 @@ char *ft_rfind(const char *s, int c) | |
i--; | ||
} | ||
return (NULL); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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); | ||
|
@@ -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]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
{ | ||
|
@@ -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(); | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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); | ||
|
@@ -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; | ||
|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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(); | ||
|
Oops, something went wrong.