-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
90 lines (74 loc) · 2.28 KB
/
main.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
#ifndef MAIN_H
#define MAIN_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <dirent.h>
#include <stdint.h>
extern char **environ;
volatile int break_loop;
/* struct & typedef */
/**
* struct bultin - struct for bultin cmd
* @name: name of cmd
* @handler: handler for the cmd
*/
typedef struct bultin
{
char *name;
void (*handler)(char **, char **);
} bultin;
typedef void (*sighandler_t)(int);
/*AUXILLIARY FUNCTIONS*/
int _putchar(char c);
int string_printer(char *str);
char *_strcpy(char *dest, char *src);
char *_strdup(char *str);
int _strlen(char *s);
char *_strcat(char *dest, char *src);
int _strcmp(char *s1, char *s2);
int _strspn(const char *s, const char *accept);
int _atoi(char *str);
char *_memset(char *s, char b, unsigned int n);
int _strncmp(char *s1, char *s2, int n);
/*MAIN FUNCTIONS*/
/*read_and_split_functions.c*/
void print_prompt(void);
ssize_t line_reader(char **buf, size_t *n);
char **token_generator(char *cmdline, const char *delim, int *ac);
/*execution functions*/
int spawn_and_exec_cmd(char **av, pid_t pid, int *cmdstatus);
char *_getfullpath(char **envp, char *shortcmd);
int exec_from_path(char **envp, pid_t pid, char **av, int *cmdstatus);
int is_builtin_cmd(char **av, char *cmdline, int status, char ***newenviron,
char **newentry, int ac);
/*env_functions*/
void _handle_set_unset(char **av, char ***newenviron, char **newentry);
void _addenv(char *name, char *value, int envlen, char ***newenviron,
char **newentry);
int _isvalidenvcmd(char **av);
void _printenv(char **av);
char *_getfullpath(char **envp, char *shortcmd);
/*exit_cleanup_error funcitons*/
void terminate_shell(int status, char **av, char *cmdline, char **newenviron,
char *newentry);
void cleanall(char **av, char *cmdline);
void err_notfound(char *shortcmd);
void clean_cmd(int __attribute__((unused)) ac, char **av);
int exec_cleanup(int exec_return, int ac, char **av);
/*change_dir functions*/
void _cd(char **av, int ac);
void change_pwd(char *oldpwdpath);
void change_oldpwd(char *pwdpath);
void get_home(char **homevar);
/*other_main_functions*/
void my_sigint(int signum);
void _updateenv(char **av);
#endif