Repository navigation
Expand file tree
/
Copy pathmain.h
More file actions
144 lines (126 loc) · 3.73 KB
/
Copy pathmain.h
File metadata and controls
144 lines (126 loc) · 3.73 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
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
#ifndef MAIN_H
#define MAIN_H
/* C standard library header files */
#include <unistd.h>
#include <stdlib.h>
#include <limits.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdarg.h>
#include <string.h>/*added this...*/
#define BUF_CAPACITY 1024
#define BUF_CLEARING -1
#define EMPTY_STRING "(null)"
/** STRUCTURE FOR BUILT IN COMMANDS */
/**
* struct built_in - structure for builtin cmds
* @cmd_name: the name of the built in command
* @handler: the function that handles the command
*/
typedef struct built_in
{
char *cmd_name;
int (*handler)(char **args);
} built_in;
/** ==== HANDLER FUNCTIONS FOR BUILT IN CMDS **/
int get_built_cmd_func(char **args);
int handle_cd(char **args);
int handle_exit(char **args);
int handle_env(char **args);
/*SUPPLEMENTARY FUNCTIONS */
long int _strtol(const char *nptr, char **endptr);
/** STRUCTURE FOR LINKED LIST OF DIRECTORIES*/
/**
* struct dir_node - structure for directory of linked lists
* @dir: the directory string
* @next: the pointer to the next node in the list
*/
typedef struct dir_node
{
char *dir;
struct dir_node *next;
} dir_node;
/** LINKED LIST FUNCTIONS PROTOYPES */
dir_node *create_dir_node(char *dir);/*creates a new dir node*/
void add_directory(dir_node **head, char *dir);
dir_node *build_dir_list(void);
void free_dir_list(dir_node *head);
char *find_cmd_in_path(char *cmd, dir_node *dir_list);
/** ENVIRON VARIABLE */
extern char **environ;
int exit_status;
/** GET ENV FUNCTION */
char *_getenv(const char *name);
/* function prototypes */
int _putchar(int c, int fd);
int (*find_format_handlers(const char *format))(va_list arg);
int (*find_format_handlers2(const char *format))(va_list arg);
int print_spec_c_match(va_list arg);
int print_spec_d_match(va_list arg);
int print_spec_s_match(va_list arg);
int print_spec_s_match2(va_list arg);
int print_percent(va_list arg);
int print_percent2(va_list arg);
/*string1.c*/
char *_memcpy(char *dest, char *src, unsigned int n);
char *_memset(char *s, char b, unsigned int n);
void _puts(char *str);
char *_strcat(char *dest, char *src);
char *_strchr(char *s, char c);
/*string2.c*/
char *_strncpy(char *dest, char *src, int n);
char *_strdup(char *str);
int _strcmp(char *s1, char *s2);
char *_strcpy(char *dest, char *src);
int _strlen(char *s);
/*string3.c*/
char *_strncat(char *dest, char *src, int n);
char *_strstr(char *haystack, char *needle);
/*======= SIMPLE SHELL FUNCTIONS =========*/
char **parse_tokens(char *input, int *argc);
void *_realloc(void *ptr, unsigned int old_size, unsigned int new_size);
int exec_tokens(char **tokens, dir_node *dir_list);
char *_strtok(char *str, const char *delim);
ssize_t _getline(char **lineptr, size_t *n, FILE *stream);
/*==================================================================*/
/* Helper functions 1*/
char *convert_to(long int num, int base);
int print_number(unsigned int digit, unsigned int base, char *hex_base);
int _printf(const char *format, ...);
int _fprintf(const char *format, ...);
/**
* struct conversion_table - data structure for storing hex conversion notation
* @numConst: integer
* @numStr: associated hex notation
*/
typedef struct conversion_table
{
unsigned int numConst;
char *numStr;
} c_t;
/**
* struct format_handler - Struct token
* @format_char: the format token
* @handler_func: The function associated
*/
typedef struct format_handler
{
char *format_char;
int (*handler_func)(va_list);
} format_handler;
/**
* struct format_handler2 - Struct token
* @format_char: the format token
* @handler_func2: The function associated
*/
typedef struct format_handler2
{
char *format_char;
int (*handler_func2)(va_list);
} format_handler2;
#endif /* MAIN_H */