-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmynotsominishell.h
145 lines (123 loc) · 3.2 KB
/
mynotsominishell.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef _MYNOTSOMINISHELL_H_
#define _MYNOTSOMINISHELL_H_
#include <sys/ioctl.h>
#include <stdio.h> /* for perror and things */
#include <fcntl.h>
#include <termios.h>
#include <sys/termios.h>
#include "../lib/my.h"
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <termcap.h>
#include <sys/wait.h> /* for wait */
#include <errno.h> /* for errno */
#include <string.h> /* for memcpy */
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define BUF_SZ 2097152 /* same buffer size as in BASH */
#define HISTORY_LIMIT 100 /* size of command history */
#define READTIME 1
/* used to return from read after 1/10th of second passed from the first byte read */
#define READMIN 3
/* used to return from read if 3 bytes have been read. Needed for things like characters which are \E[A B C or D */
#ifndef NULL
#define NULL (0)
#endif
#define SPACEBAR " "
#define ESC "\E"
#define BACKSPACE 127
#define ENTER "\n"
#define CTRL_A 1
#define CTRL_E 5
#define CTRL_K 11
#define CTRL_L 12
#define CTRL_Y 25
#define KU "\E[A"
#define KD "\E[B"
#define KR "\E[C"
#define KL "\E[D"
#define CLEAR "cl"
#define MOVE_LEFT "le"
#define MOVE_RIGHT "nd"
#define MOVE_DOWN "do"
#define MOVE_START "cr" /* move to start of line */
#define DEL_CHAR "dc"
#define CURSOROFF "vi"
#define CURSORON "ve"
typedef struct s_elem
{
char *elem;
unsigned int size;
} t_elem;
typedef struct s_env
{
char *move_left;
char *move_right;
char *move_down;
char *move_start;
char *clear;
char *delete_char;
char *cursoroff;
char *cursoron;
struct winsize win;
struct termio line_backup;
int stdio_backup;
int history_fd;
unsigned int pos; /* position of cursor relative to command's first character */
unsigned int cursor_col; /* column of cursor */
t_elem curr_dir; /* current directory path */
t_elem cmd_buffer; /* buffer for current command */
t_elem hst_buffer; /* buffer for command in history for editing */
t_elem cpy_buffer; /* buffer for copied command */
t_elem *curr_cmd; /* pointer to command being displayed */
t_elem *elements; /* represents command history */
unsigned int nbelems; /* number of commands in history */
unsigned int elem_last; /* index of last command in history */
unsigned int elem_first; /* index of most recent command in history */
unsigned int curr_elem; /* index of currently selected element in history */
} t_env;
t_env gl_env;
/* created as a structure to limit number of globals to 1 */
void init_terminal();
void restore_terminal();
char *term_get_cap(char*);
void init_caps();
int my_termprint(int);
void term_clear();
void term_vi();
void term_ve();
void check_character(char *c);
void check_command();
char add_character(char, unsigned int);
void remove_character(unsigned int);
char get_win_size();
void show_prompt();
void refreshin();
void refreshout();
void moveup();
void movedown();
void moveleft();
void moveright();
void movestart();
void moveend();
void addchar(char c);
void deletechar();
void getout();
void setup_env();
void set_curr_dir();
void cut_cmd();
void paste_cmd();
void print_prompt();
void print_cmd(unsigned int);
void term_move_left();
void term_move_right();
void term_delete_char();
void load_history();
void save_history();
void save_command();
#endif