-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.h
More file actions
103 lines (87 loc) · 2.51 KB
/
shell.h
File metadata and controls
103 lines (87 loc) · 2.51 KB
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
#ifndef __SHELL_H__
#define __SHELL_H__
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "env.h"
#include "commands.h"
#define CONFIGFILE ".bodashell.conf"
#define SHELL_INPUT_BUFFER_SIZE 256
#define SHELL_TOK_BUFFER_SIZE 256
#define SHELL_TOK_DELIMITER " \t\r\n\a"
static const char *colorTypes[] = {
"\033[1;30m", //Black
"\033[1;31m", //Red
"\033[1;32m", //Green
"\033[1;33m", //Yellow
"\033[1;34m", //Blue
"\033[1;35m", //Purple
"\033[1;36m", //Cyan
"\033[1;37m", //White
"\033[0m", //RESET
};
typedef struct SHELL_CONF_t
{
short root_color;
short user_color;
short path_color;
short show_path;
short show_hostname;
short hostname_color;
short warning_flag;
ENV_t *env;
}SHELL_CONF;
/**
* @brief Initialize the shell with some parameters if defined.
*
* @param conf Double pointer Shell conf structure that contains the parameters
* @post: *conf pointing so valid memory containing shell parameters fot it to work properly
* @return:
* 0 : If successfull
* -1 : If memory error
*/
int init_shell(SHELL_CONF **conf, char **envp);
/**
* @brief Read the config file if does exist.
*
* @param config Shell conf structure that contains the parameters
* @pre: @param config Pointing to a valid memory location
* @post: valid config parameter if found.
* @return:
* 0: If successfull
* -1: If error with the config file.
*/
short readShellConf(SHELL_CONF *config);
/**
* @brief show prompt with user attributes to the screen that invites him to enter some commands
*
* @param config Shell conf structure that contains the parameters
* @post: @param config Pointing to a valid memory location
* @pre: Print prompt to screen with proper attribute for the user
* @return nothing
*/
void show_prompt(SHELL_CONF *config);
/**
* @brief Get the user input command
*
* @return:
* NULL if unput is empty or a memory error occured
* char * to the user's command.
*/
char *readCommandInput(void);
/**
* @brief Free all the allocated memory to avoid memory leak
*
* @param conf Shell conf structure that contains the parameters
* @pre @param conf Pointing to a valid memory location
* @post free all allocated memory
*/
void free_shell(SHELL_CONF *conf);
char **splitCommandInput(char *commandInput);
int shell_launch(char **args);
int shell_execute(char **args, SHELL_CONF *config);
#endif