-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.h
82 lines (71 loc) · 2 KB
/
shell.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
#ifndef SHELL_H
#define SHELL_H
#include <stdio.h>
#include <stddef.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <string.h>
#include <stdbool.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/stat.h>
#define BUFFER_SIZE 1024
#define DELIMITERS " \t\r\n\a"
extern char **environ;
/******* Structs **********/
/**
* struct data - struct for data fed to the shell
* @exe: executable file
* @input: pointer to the input
* @command: pointer to a command typed by the user
* @fd: file descriptor
* @tokens: tokenized input
* @env: environ
* @no_of_executions: no of shhell executions
*/
typedef struct data
{
char *exe;
char *input;
char *command;
char **tokens;
char **env;
int no_of_executions;
int fd;
} shell_data;
/****** Prototypes *****/
/****** Implement the shell ******/
void shell_loop(shell_data *shell);
int read_input(shell_data *shell, size_t buffer_size);
char **split_input(shell_data *shell);
char *handle_path(shell_data *shell);
int check_file(char *path);
int is_exe(shell_data *shell);
int compare_env_var(char *variable, char *name);
char *get_env_value(char *variable, shell_data *shell);
int execute_commands(shell_data *shell);
void add_data_to_shell(shell_data *shell, int ac, char *av[]);
char *malloc_string(char *string);
int int_length(int n);
char *_itoa(int n);
int check_execute_permissions(char *path, shell_data *shell);
void handle_signal(int signal);
/******* Print functions ********/
int print_string(char *s);
int print_e(char *string);
int print_error(int error, shell_data *shell);
int str_cmp(char *s1, char *s2);
/****** Memory functions *******/
void *_calloc(unsigned int nmem, unsigned int size);
void free_shell_data(shell_data *shell);
void free_without_input(shell_data *shell);
/******** String functions *******/
int str_len(char *string);
char *str_dup(char *string);
char *str_cpy(char *dest, char *src);
char *str_cat(char *dest, char *src);
int _strncmp(char *str1, char *str2, size_t n);
#endif