summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/c_init.c26
-rw-r--r--src/c_init.h43
-rw-r--r--src/c_input.c2
-rw-r--r--src/c_input.h12
-rw-r--r--src/c_keys.c24
-rw-r--r--src/c_keys.h4
-rw-r--r--src/c_utils.c4
-rw-r--r--src/c_utils.h12
8 files changed, 59 insertions, 68 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 69885fc..a77c326 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -59,16 +59,20 @@ int16_t
}
int16_t
-c_read_cap(char *buf, char *line, t_caps *tcaps, t_msh *msh)
+ c_read_cap(char *buf, char *line, t_caps *tcaps, t_msh *msh)
{
- if (((*((unsigned int *)buf)) == LEFT_K) || ((*((unsigned int *)buf)) == CTRL_B))
+ if (((*((unsigned int *)buf)) == LEFT_K) ||
+ ((*((unsigned int *)buf)) == CTRL_B))
return (c_key_left(ft_strlen(msh->ps[tcaps->psx]), tcaps));
- else if (((*((unsigned int *)buf)) == RIGHT_K) || ((*((unsigned int *)buf)) == CTRL_F))
- return (c_key_right(ft_strlen(line), ft_strlen(msh->ps[tcaps->psx]), tcaps));
+ else if (((*((unsigned int *)buf)) == RIGHT_K) ||
+ ((*((unsigned int *)buf)) == CTRL_F))
+ return (c_key_right(ft_strlen(line),
+ ft_strlen(msh->ps[tcaps->psx]), tcaps));
else if ((*((unsigned int *)buf)) == HOME_K)
return (c_home_key(tcaps));
else if ((*((unsigned int *)buf)) == END_K)
- return (c_end_key(ft_strlen(line), tcaps));
+ return (c_end_key(ft_strlen(line),
+ ft_strlen(msh->ps[tcaps->psx]), tcaps));
else if ((*((unsigned int *)buf)) == CTRL_C)
return (c_ctrl_c(NULL, tcaps, msh));
else if ((*((unsigned int *)buf)) == CTRL_L)
@@ -80,8 +84,8 @@ c_read_cap(char *buf, char *line, t_caps *tcaps, t_msh *msh)
static char
*c_process_key(char *buf, t_caps *tcaps, t_msh *msh)
{
- static char *line = NULL;
- int i;
+ static char *line = NULL;
+ int i;
i = -1;
if (line == NULL)
@@ -112,11 +116,11 @@ static char
}
int16_t
-c_gnl(int32_t fd, char **line, uint8_t psx, t_msh *msh)
+ c_gnl(int32_t fd, char **line, uint8_t psx, t_msh *msh)
{
- t_caps tcaps;
- char *term;
- char nread[5];
+ t_caps tcaps;
+ char *term;
+ char nread[5];
term = getenv("TERM");
if (!tgetent(NULL, term))
diff --git a/src/c_init.h b/src/c_init.h
index 86eb89a..cb10864 100644
--- a/src/c_init.h
+++ b/src/c_init.h
@@ -10,13 +10,13 @@
/* */
/* ************************************************************************** */
-#ifndef U_INIT_H
-#define U_INIT_H
+#ifndef C_INIT_H
+# define C_INIT_H
-#include <termios.h>
-#include <sys/ioctl.h>
+# include <termios.h>
+# include <sys/ioctl.h>
-#include "s_struct.h"
+# include "s_struct.h"
# define LEFT_K 0x445b1b
# define RIGHT_K 0x435b1b
@@ -30,30 +30,17 @@
# define CTRL_C 0x03
# define CTRL_L 0x0c
-
-typedef struct s_caps
+typedef struct s_caps
{
- struct termios tios;
- struct winsize ws;
- uint32_t cpos; /*cursor position (column)*/
- uint32_t lpos; /*cursor position (line)*/
- uint32_t nlines; /*cursor position (line)*/
- uint8_t psx; /*cursor position (line)*/
-} t_caps;
+ struct termios tios;
+ struct winsize ws;
+ uint32_t cpos;
+ uint32_t lpos;
+ uint32_t nlines;
+ uint8_t psx;
+} t_caps;
-int16_t c_gnl(int32_t fd, char **line, uint8_t psx, t_msh *msh);
-int16_t c_set_term_raw(uint8_t mode);
+int16_t c_gnl(int32_t fd, char **line, uint8_t psx, t_msh *msh);
+int16_t c_set_term_raw(uint8_t mode);
#endif
-
-/* cm_str; cursor mobility*/
-/* nl; newline, returned by tgoto()*/
-/* ks; indicate that keys transmit from now on*/
-/* ke; indicate that keys transmit from now on*/
-/* pc; padding char --> do not touch (default 0)*/
-/* bc; left one char*/
-/* le; left one char*/
-/* up; up one line*/
-/* DO; down one line*/
-/* nd; right one char*/
-/* cl; line clear*/
diff --git a/src/c_input.c b/src/c_input.c
index bbc6f5a..e1dce63 100644
--- a/src/c_input.c
+++ b/src/c_input.c
@@ -51,7 +51,7 @@ uint16_t
}
uint32_t
-c_get_line_num(char *line, uint32_t cpos, uint32_t plen, t_caps *tcaps)
+ c_get_line_num(char *line, uint32_t cpos, uint32_t plen, t_caps *tcaps)
{
uint32_t it;
uint32_t line_num;
diff --git a/src/c_input.h b/src/c_input.h
index a586e2f..541b712 100644
--- a/src/c_input.h
+++ b/src/c_input.h
@@ -11,12 +11,12 @@
/* ************************************************************************** */
#ifndef C_INPUT_H
-#define C_INPUT_H
+# define C_INPUT_H
-int16_t c_back_slash(char **line, uint32_t plen, t_caps *tcaps);
-int16_t c_ctrl_c(char *line, t_caps *tcaps, t_msh *msh);
-uint32_t c_get_line_num(char *line, uint32_t cpos, uint32_t plen, t_caps *tcaps);
-int16_t c_init_line(uint8_t psx, t_caps *tcaps);
-uint16_t c_get_win_size(struct winsize *ws);
+int16_t c_back_slash(char **line, uint32_t plen, t_caps *tcaps);
+int16_t c_ctrl_c(char *line, t_caps *tcaps, t_msh *msh);
+uint32_ c_get_line_num(char *line, uint32_t cpos, uint32_t plen, t_caps *tcaps);
+int16_t c_init_line(uint8_t psx, t_caps *tcaps);
+uint16_t c_get_win_size(struct winsize *ws);
#endif
diff --git a/src/c_keys.c b/src/c_keys.c
index cd3e6f1..78b3d8f 100644
--- a/src/c_keys.c
+++ b/src/c_keys.c
@@ -29,8 +29,8 @@ int16_t
int16_t
c_home_key(t_caps *tcaps)
{
- int16_t i;
- int16_t j;
+ uint32_t i;
+ int16_t j;
i = tcaps->cpos;
j = tcaps->lpos;
@@ -40,7 +40,7 @@ int16_t
while (--j > 0)
tputs(tgetstr("up", NULL), 1, ft_putchar);
tputs(tgetstr("cr", NULL), 1, ft_putchar);
- while ((uint32_t)++i <= 13)
+ while (++i <= 13)
tputs(tgetstr("nd", NULL), 1, ft_putchar);
}
else
@@ -54,24 +54,24 @@ int16_t
}
int16_t
- c_end_key(uint16_t size, t_caps *tcaps)
+ c_end_key(uint16_t size, uint32_t plen, t_caps *tcaps)
{
uint16_t i;
uint16_t j;
i = tcaps->cpos;
j = tcaps->lpos;
- if (tcaps->cpos < size && j < tcaps->nlines)
+ if ((tcaps->cpos < size) && (j < tcaps->nlines))
{
i = 0;
- while (j < (tcaps->nlines))
+ while (j < tcaps->nlines)
{
tputs(tgetstr("do", NULL), 1, ft_putchar);
i += tcaps->ws.ws_col;
j++;
}
tputs(tgetstr("cr", NULL), 1, ft_putchar);
- while (i++ < (size + 13))
+ while (i++ < (size + plen))
tputs(tgetstr("nd", NULL), 1, ft_putchar);
}
else
@@ -85,8 +85,8 @@ int16_t
int16_t
c_key_right(uint32_t len, uint32_t plen, t_caps *tcaps)
{
- if ((((tcaps->cpos + plen + 1) % (tcaps->ws.ws_col)) == 0)
- && tcaps->cpos < len)
+ if ((((tcaps->cpos + plen + 1) % (tcaps->ws.ws_col)) == 0) &&
+ tcaps->cpos < len)
{
tputs(tgetstr("do", NULL), 1, ft_putchar);
tputs(tgetstr("cr", NULL), 1, ft_putchar);
@@ -107,11 +107,11 @@ int16_t
int32_t pos;
pos = -1;
- if (((tcaps->cpos + plen) % (tcaps->ws.ws_col)) == 0
- && tcaps->cpos >= 1)
+ if (((tcaps->cpos + plen) % tcaps->ws.ws_col) == 0 &&
+ tcaps->cpos >= 1)
{
tputs(tgetstr("up", NULL), 1, ft_putchar);
- while(++pos <= (tcaps->ws.ws_col))
+ while (++pos <= tcaps->ws.ws_col)
tputs(tgetstr("nd", NULL), 1, ft_putchar);
tcaps->cpos--;
tcaps->lpos--;
diff --git a/src/c_keys.h b/src/c_keys.h
index 250b297..6a4924d 100644
--- a/src/c_keys.h
+++ b/src/c_keys.h
@@ -11,12 +11,12 @@
/* ************************************************************************** */
#ifndef C_KEYS_H
-#define C_KEYS_H
+# define C_KEYS_H
int16_t c_key_right(uint32_t len, uint32_t plen, t_caps *tcaps);
int16_t c_key_left(uint32_t plen, t_caps *tcaps);
int16_t c_home_key(t_caps *tcaps);
-int16_t c_end_key(uint16_t size, t_caps *tcaps);
+int16_t c_end_key(uint16_t size, uint32_t plen, t_caps *tcaps);
int16_t c_ctrl_l(char *line, t_caps *tcaps, t_msh *msh);
#endif
diff --git a/src/c_utils.c b/src/c_utils.c
index 3c21bff..de4e8d1 100644
--- a/src/c_utils.c
+++ b/src/c_utils.c
@@ -151,6 +151,6 @@ int16_t
tputs(tgetstr("nd", NULL), 1, ft_putchar);
ft_printf("%s", line);
return (((tcaps->cpos) != ft_strlen(line)) ?
- c_redraw_next(ft_strlen(msh->ps[tcaps->psx]), ft_strlen(line), tcaps) :
- ft_strlen(line));
+ c_redraw_next(ft_strlen(msh->ps[tcaps->psx]), ft_strlen(line), tcaps) :
+ ft_strlen(line));
}
diff --git a/src/c_utils.h b/src/c_utils.h
index 6aebca8..0cea972 100644
--- a/src/c_utils.h
+++ b/src/c_utils.h
@@ -11,13 +11,13 @@
/* ************************************************************************** */
#ifndef C_UTILS_H
-#define C_UTILS_H
+# define C_UTILS_H
-#include "s_struct.h"
+# include "s_struct.h"
-char *c_new_line(char *line, t_caps *tcaps);
-char *c_insert_char(char *str, char c, t_caps *tcaps);
-char *c_delchar(char *str, uint16_t cpos);
-int16_t c_redraw_line(char *line, t_caps *tcaps, t_msh *msh);
+char *c_new_line(char *line, t_caps *tcaps);
+char *c_insert_char(char *str, char c, t_caps *tcaps);
+char *c_delchar(char *str, uint16_t cpos);
+int16_t c_redraw_line(char *line, t_caps *tcaps, t_msh *msh);
#endif