summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-11-06 23:13:26 +0100
committersalad <fmoenne-@student.le-101.fr>2020-11-06 23:13:26 +0100
commit296f228966acfe2c645a750b6f8c3fed9bddf615 (patch)
treeeb15406a14216e01493c69a6dbaf1416e78db3e5
parentstatic something (diff)
download42-minishell-296f228966acfe2c645a750b6f8c3fed9bddf615.tar.gz
42-minishell-296f228966acfe2c645a750b6f8c3fed9bddf615.tar.bz2
42-minishell-296f228966acfe2c645a750b6f8c3fed9bddf615.tar.xz
42-minishell-296f228966acfe2c645a750b6f8c3fed9bddf615.tar.zst
42-minishell-296f228966acfe2c645a750b6f8c3fed9bddf615.zip
c_ctrls
-rw-r--r--Makefile1
-rw-r--r--src/c_ctrls.c55
-rw-r--r--src/c_ctrls.h24
-rw-r--r--src/c_init.c2
-rw-r--r--src/c_input.c33
-rw-r--r--src/c_input.h1
-rw-r--r--src/c_keys.c19
7 files changed, 82 insertions, 53 deletions
diff --git a/Makefile b/Makefile
index 6445b7a..8bcb1d9 100644
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,7 @@ SRCS_NAME += b_sqb_nbr
SRCS_NAME += b_sqb_str
SRCS_NAME += b_type
SRCS_NAME += b_unset
+SRCS_NAME += c_ctrls
SRCS_NAME += c_init
SRCS_NAME += c_input
SRCS_NAME += c_keys
diff --git a/src/c_ctrls.c b/src/c_ctrls.c
new file mode 100644
index 0000000..2f066d6
--- /dev/null
+++ b/src/c_ctrls.c
@@ -0,0 +1,55 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* c_ctrls.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <signal.h>
+#include <libft.h>
+#include <unistd.h>
+#include <term.h>
+
+#include "c_ctrls.h"
+#include "c_utils.h"
+#include "m_prompt.h"
+
+short c_ctrl_l(char *line, t_caps *tcaps, t_msh *msh)
+{
+ tputs(tgetstr("cl", NULL), 1, ft_putchar);
+ m_prompt_psx(1, msh);
+ c_redraw_line(line, tcaps, msh);
+ return (1);
+}
+
+char *c_ctrl_c(char **line, char *buf, t_msh *msh)
+{
+ msh->ret = 130;
+ buf[0] = '\n';
+ write(1, "\n", 1);
+ ft_memdel((void**)line);
+ return (ft_strdup("\0"));
+}
+
+void c_signal_int(int signo)
+{
+ t_msh *msh;
+
+ msh = NULL;
+ signal(SIGINT, c_signal_int);
+ (void)signo;
+ msh->ret = 130;
+ ioctl(1, TIOCSTI, "\002");
+}
+
+void c_signal_ign(int signo)
+{
+ signal(SIGINT, c_signal_int);
+ (void)signo;
+ signal(SIGTSTP, SIG_IGN);
+}
diff --git a/src/c_ctrls.h b/src/c_ctrls.h
new file mode 100644
index 0000000..abce955
--- /dev/null
+++ b/src/c_ctrls.h
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* c_ctrls.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef C_CTRLS_H
+# define C_CTRLS_H
+
+# include "c_init.h"
+# include "s_struct.h"
+
+short c_ctrl_l(char *line, t_caps *tcaps, t_msh *msh);
+char *c_ctrl_c(char **line, char *buf, t_msh *msh);
+void c_signal_int(int signo);
+void c_signal_ign(int signo);
+
+#endif
diff --git a/src/c_init.c b/src/c_init.c
index bf3191f..0939b29 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -17,6 +17,7 @@
#include <string.h>
#include <term.h>
+#include "c_ctrls.h"
#include "c_init.h"
#include "c_keys.h"
#include "c_input.h"
@@ -89,7 +90,6 @@ static char
static char *line = NULL;
int i;
- c_get_struct(1, &msh);
i = -1;
if (line == NULL)
if (!(line = ft_calloc(1, sizeof(char))))
diff --git a/src/c_input.c b/src/c_input.c
index f26bbad..ce571ca 100644
--- a/src/c_input.c
+++ b/src/c_input.c
@@ -16,6 +16,7 @@
#include <signal.h>
#include <term.h>
+#include "c_ctrls.h"
#include "c_init.h"
#include "c_keys.h"
#include "c_input.h"
@@ -23,38 +24,6 @@
#include "m_prompt.h"
#include "m_loop.h"
-t_msh
- *c_get_struct(int mode, t_msh **msh)
-{
- static t_msh *mstruct = NULL;
-
- if (mode)
- {
- mstruct = *msh;
- }
- return (mstruct);
-}
-
-void c_signal_int(int signo)
-{
- t_msh *msh;
-
- msh = NULL;
- signal(SIGINT, c_signal_int);
- (void)signo;
- msh = c_get_struct(0, &msh);
- ft_printf("[%s]\n", msh->ps[0]);
- msh->ret = 130;
- ioctl(1, TIOCSTI, "\002");
-}
-
-void c_signal_ign(int signo)
-{
- signal(SIGINT, c_signal_int);
- (void)signo;
- signal(SIGTSTP, SIG_IGN);
-}
-
short
c_init_line(char psx, t_caps *tcaps)
{
diff --git a/src/c_input.h b/src/c_input.h
index 07c4e93..e2dc0da 100644
--- a/src/c_input.h
+++ b/src/c_input.h
@@ -18,7 +18,6 @@ unsigned int c_get_line_num(char *line, unsigned int cpos, unsigned int plen,
t_caps *tcaps);
short c_init_line(char psx, t_caps *tcaps);
unsigned short c_get_win_size(struct winsize *ws);
-t_msh *c_get_struct(int mode, t_msh **msh);
#endif
diff --git a/src/c_keys.c b/src/c_keys.c
index 8c06a85..3d80327 100644
--- a/src/c_keys.c
+++ b/src/c_keys.c
@@ -19,25 +19,6 @@
#include "m_prompt.h"
short
- c_ctrl_l(char *line, t_caps *tcaps, t_msh *msh)
-{
- tputs(tgetstr("cl", NULL), 1, ft_putchar);
- m_prompt_psx(1, msh);
- c_redraw_line(line, tcaps, msh);
- return (1);
-}
-
-char
- *c_ctrl_c(char **line, char *buf, t_msh *msh)
-{
- msh->ret = 130;
- buf[0] = '\n';
- write(1, "\n", 1);
- ft_memdel((void**)line);
- return (ft_strdup("\0"));
-}
-
-short
c_home_key(unsigned int plen, t_caps *tcaps)
{
unsigned int i;