-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathminishell.h
130 lines (119 loc) · 3.4 KB
/
minishell.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/21 11:23:43 by apuchill #+# #+# */
/* Updated: 2021/06/20 19:33:47 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
/*
** -.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-
** HEADERS
*/
# include <stdbool.h>
# include <limits.h>
# include <unistd.h>
# include <signal.h>
# include <term.h>
# include "libft.h"
# include "errors.h"
/*
** -.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-
** MACROS
*/
# define PROMPT 0
# define EOT 4
# define DEL 127
# define ARROW_UP "\e[A"
# define ARROW_DO "\e[B"
# define ARROW_LE "\e[C"
# define ARROW_RI "\e[D"
# define C_END "\033[0m"
# define C_BOLD "\033[1m"
# define C_PINK "\033[38;5;13m"
# define C_BLUE "\033[38;5;75m"
# define C_MAGENTA "\033[38;5;199m"
# define C_GREEN "\033[1;32m"
# define C_RED "\033[1;31m"
# define C_YELLOW "\033[1;33m"
/*
** -.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-
** STRUCT DECLARATIONS
*/
typedef struct s_hist
{
int nbr;
char *cmd_line;
struct s_hist *prev;
struct s_hist *next;
} t_hist;
typedef struct s_stream
{
int len_prompt;
bool is_history;
char *tmp_input;
char *cmd_line;
} t_stream;
typedef struct s_msh
{
t_dict *dict_env;
struct termios orig_term;
t_stream stream;
t_hist *history;
t_hist *hist_curr;
} t_msh;
/*
** -.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-
** GLOBAL VARIABLES
*/
t_msh g_msh;
/*
** -.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-
** FUNCTION PROTOTYPES
*/
/*
** FILE: utils.c
*/
char *ft_getenv(char *env);
void print_prompt(char *user, int *len_prompt);
void set_exit_status(int status);
void msh_destroy(void);
/*
** FILE: signal.c
*/
void signal_handler(short int caller);
void sig_prompt(int signum);
/*
** FILE: termcap.c
*/
void get_terminal_data(char *termtype);
void init_terminal_data(char *termtype);
void restore_terminal_data(bool from_msh_destroy);
/*
** FILE: term_handler.c
*/
int terminal_handler(char *termtype, t_stream *stream, char *buf);
void term_backspace(t_stream *stream, int max_len, int col);
/*
** FILE: term_utils.c
*/
int ft_putchar_int(int c);
int get_nbr_len(int nbr);
void term_clear_line(t_stream *stream, int max_len, int col);
/*
** FILE: history.c
*/
void put_input_in_history(char *input_line);
void erase_history(t_hist **lst);
void history_go_to_last(t_hist **lst);
/*
** FOLDER: builtins.c
*/
void builtin_exit(void);
void builtin_history(t_hist *lst);
#endif