maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
libft.h File Reference
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#include <unistd.h>
#include <stdarg.h>
#include <signal.h>
#include <stdbool.h>
#include <math.h>
Include dependency graph for libft.h:

Go to the source code of this file.

Macros

#define BUFFER_SIZE   32
 
#define TRUE   1
 
#define FALSE   0
 
#define STDIN   0
 
#define STDOUT   1
 
#define STDERR   2
 
#define RESET   "\033[0m"
 
#define BLK   "\033[0;30m"
 
#define RED   "\033[0;31m"
 
#define GRN   "\033[0;32m"
 
#define YEL   "\033[0;33m"
 
#define BLU   "\033[0;34m"
 
#define MAG   "\033[0;35m"
 
#define CYA   "\033[0;36m"
 
#define WHI   "\033[0;37m"
 
#define B_BLK   "\033[1;30m"
 
#define B_RED   "\033[1;31m"
 
#define B_GRN   "\033[1;32m"
 
#define B_YEL   "\033[1;33m"
 
#define B_BLU   "\033[1;34m"
 
#define B_MAG   "\033[1;35m"
 
#define B_CYA   "\033[1;36m"
 
#define B_WHI   "\033[1;37m"
 

Functions

int ft_abs (int n)
 
int ft_isalpha (int c)
 
int ft_isdigit (int c)
 
int ft_isalnum (int c)
 
int ft_isascii (int c)
 
int ft_isprint (int c)
 
int ft_toupper (int c)
 
int ft_tolower (int c)
 
int ft_print_int (int n)
 
int ft_print_char (int c)
 
int ft_print_percent (void)
 
int ft_print_str (char *str)
 
int list_len_char (char a[])
 
int list_len_str (char *a[])
 
int ft_atoi (const char *str)
 
int ft_is_num (const char *n)
 
int ft_ptr_len (uintptr_t num)
 
int ft_len_2d_arr (char **array)
 
int ft_is_double (const char *n)
 
int isnum_from_str (const char *str)
 
int ft_printf (const char *format,...)
 
int find_max_in_list (int a[], int size)
 
int ft_print_ptr (unsigned long long ptr)
 
int ft_print_unsigned_dec (unsigned int n)
 
int list_repeat_check_int (int a[], int size)
 
int ft_count_bits (unsigned char current_char)
 
int ft_strcmp (const char *s1, const char *s2)
 
int list_repeat_check_str (char *a[], int size)
 
int ft_strncmp (const char *s1, const char *s2, size_t n)
 
int ft_memcmp (const void *s1, const void *s2, size_t n)
 
int ft_print_unsigned_hex (unsigned int num, const char format)
 
char * ft_itoa (int n)
 
char * ft_strdup (const char *s)
 
char * ft_get_next_line (int fd)
 
char * ft_strchr (const char *s, int c)
 
char * ft_strcat (char *dest, char *src)
 
char * ft_strrchr (const char *s, int c)
 
char ** ft_split (char const *s, char c)
 
char * ft_strndup (const char *s, size_t n)
 
char * ft_strjoin_free (char *s1, char *s2)
 
char * ft_strcpy (char *dest, const char *src)
 
char * ft_strjoin (char const *s1, char const *s2)
 
char * ft_strtrim (char const *s1, char const *set)
 
char * ft_remove_quotes (char *str, char quote_type)
 
char * ft_strstr (const char *big, const char *little)
 
char * ft_strcat_const (const char *dest, const char *src)
 
char * ft_strmapi (char const *s, char(*f)(unsigned int, char))
 
char * ft_substr (char const *s, unsigned int start, size_t len)
 
char ** ft_realloc_array (char **array, int old_size, int new_size)
 
char * ft_strnstr (const char *haystack, const char *needle, size_t len)
 
void ft_put_ptr (uintptr_t num)
 
void ft_free_2d_arr (char **arr)
 
void ft_bzero (void *s, size_t n)
 
void ft_putnbr_fd (int n, int fd)
 
void ft_putchar_fd (char c, int fd)
 
void ft_putstr_fd (char *s, int fd)
 
void ft_putendl_fd (char *s, int fd)
 
void * ft_memset (void *s, int c, size_t n)
 
void * ft_calloc (size_t count, size_t size)
 
void ft_print_2d_arr (char **arr, char *name)
 
void * ft_memchr (const void *s, int c, size_t n)
 
void * ft_memcpy (void *dest, const void *src, size_t n)
 
void * ft_memmove (void *dest, const void *src, size_t n)
 
void ft_striteri (char *s, void(*f)(unsigned int, char *))
 
size_t ft_strlen (const char *s)
 
size_t ft_strlcpy (char *dest, const char *src, size_t size)
 
size_t ft_strlcat (char *dest, const char *src, size_t size)
 
double ft_atof (const char *str)
 
long ft_atol (const char *nptr)
 
const char * ft_exclude_delimiters (const char *str, char *delims)
 

Macro Definition Documentation

◆ B_BLK

#define B_BLK   "\033[1;30m"

Definition at line 122 of file libft.h.

◆ B_BLU

#define B_BLU   "\033[1;34m"

Definition at line 126 of file libft.h.

◆ B_CYA

#define B_CYA   "\033[1;36m"

Definition at line 128 of file libft.h.

◆ B_GRN

#define B_GRN   "\033[1;32m"

Definition at line 124 of file libft.h.

◆ B_MAG

#define B_MAG   "\033[1;35m"

Definition at line 127 of file libft.h.

◆ B_RED

#define B_RED   "\033[1;31m"

Definition at line 123 of file libft.h.

◆ B_WHI

#define B_WHI   "\033[1;37m"

Definition at line 129 of file libft.h.

◆ B_YEL

#define B_YEL   "\033[1;33m"

Definition at line 125 of file libft.h.

◆ BLK

#define BLK   "\033[0;30m"

Definition at line 113 of file libft.h.

◆ BLU

#define BLU   "\033[0;34m"

Definition at line 117 of file libft.h.

◆ BUFFER_SIZE

#define BUFFER_SIZE   32

Definition at line 25 of file libft.h.

◆ CYA

#define CYA   "\033[0;36m"

Definition at line 119 of file libft.h.

◆ FALSE

#define FALSE   0

Definition at line 105 of file libft.h.

◆ GRN

#define GRN   "\033[0;32m"

Definition at line 115 of file libft.h.

◆ MAG

#define MAG   "\033[0;35m"

Definition at line 118 of file libft.h.

◆ RED

#define RED   "\033[0;31m"

Definition at line 114 of file libft.h.

◆ RESET

#define RESET   "\033[0m"

Definition at line 111 of file libft.h.

◆ STDERR

#define STDERR   2

Definition at line 109 of file libft.h.

◆ STDIN

#define STDIN   0

Definition at line 107 of file libft.h.

◆ STDOUT

#define STDOUT   1

Definition at line 108 of file libft.h.

◆ TRUE

#define TRUE   1

Definition at line 104 of file libft.h.

◆ WHI

#define WHI   "\033[0;37m"

Definition at line 120 of file libft.h.

◆ YEL

#define YEL   "\033[0;33m"

Definition at line 116 of file libft.h.

Function Documentation

◆ find_max_in_list()

int find_max_in_list ( int  a[],
int  size 
)

Definition at line 15 of file find_max_in_list.c.

16{
17 int max;
18 int i;
19
20 max = INT_MIN;
21 i = 0;
22 while (i < size)
23 {
24 if (a[i] > max)
25 max = a[i];
26 i++;
27 }
28 return (max);
29}

◆ ft_abs()

int ft_abs ( int  n)

Definition at line 15 of file ft_abs.c.

16{
17 if (n < 0)
18 return (-n);
19 return (n);
20}

◆ ft_atof()

double ft_atof ( const char *  str)

Definition at line 15 of file ft_atof.c.

16{
17 double res;
18 double neg;
19 double divider;
20 size_t i;
21
22 divider = 0.1;
23 res = 0;
24 neg = 1;
25 i = -1;
26 while (str[i] < '0' || str[i] > '9')
27 if (str[i++] == '-')
28 neg = -1;
29 while (str[i] >= '0' && str[i] <= '9')
30 {
31 res = res * 10 + str[i++] - 48;
32 }
33 if (str[i] == '.' || str[i] == ',')
34 i++;
35 while (str[i] >= '0' && str[i] <= '9')
36 {
37 res = res + (str[i] - 48) * divider;
38 divider /= 10;
39 i++;
40 }
41 return (res * neg);
42}

◆ ft_atoi()

int ft_atoi ( const char *  str)

Referenced by builtin_exit().

Here is the caller graph for this function:

◆ ft_atol()

long ft_atol ( const char *  nptr)

Definition at line 15 of file ft_atol.c.

16{
17 int i;
18 int neg;
19 long res;
20
21 i = 0;
22 neg = 1;
23 res = 0;
24 while (nptr[i] == '\t' || nptr[i] == '\v' || nptr[i] == '\n'
25 || nptr[i] == '\f' || nptr[i] == '\r' || nptr[i] == ' ')
26 i++;
27 if (nptr[i] == '-' || nptr[i] == '+')
28 {
29 if (nptr[i] == '-')
30 neg = -neg;
31 i++;
32 }
33 while (nptr[i] >= '0' && nptr[i] <= '9')
34 res = res * 10 + (nptr[i++] - 48);
35 return (res * neg);
36}

◆ ft_bzero()

void ft_bzero ( void *  s,
size_t  n 
)

Definition at line 21 of file ft_bzero.c.

22{
23 char *p;
24
25 p = s;
26 while (n--)
27 *p++ = '\0';
28}

◆ ft_calloc()

void * ft_calloc ( size_t  count,
size_t  size 
)

Definition at line 23 of file ft_calloc.c.

24{
25 void *ptr;
26
27 if (size != 0 && count > SIZE_MAX / size)
28 return (NULL);
29 ptr = malloc(count * size);
30 if (!ptr)
31 return (NULL);
32 ft_memset(ptr, 0, count * size);
33 return (ptr);
34}
void * ft_memset(void *s, int c, size_t n)
Definition ft_memset.c:28

References ft_memset().

Here is the call graph for this function:

◆ ft_count_bits()

int ft_count_bits ( unsigned char  current_char)

Definition at line 13 of file ft_count_bits.c.

14{
15 int i;
16
17 i = 0;
18 while (current_char)
19 {
20 i += 1;
21 current_char >>= 1;
22 }
23 return (i);
24}

◆ ft_exclude_delimiters()

const char * ft_exclude_delimiters ( const char *  str,
char *  delims 
)

Definition at line 15 of file ft_exclude_delimiters.c.

16{
17 while (*str && (ft_strchr(delims, *str) != NULL))
18 str++;
19 return (str);
20}
char * ft_strchr(const char *s, int c)
Definition ft_strchr.c:25

References ft_strchr().

Referenced by valid_operator().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_free_2d_arr()

void ft_free_2d_arr ( char **  arr)

Definition at line 15 of file ft_free_2d_arr.c.

16{
17 int i;
18
19 if (!arr)
20 return ;
21 i = -1;
22 while (arr[++i] != NULL)
23 free(arr[i]);
24 free(arr);
25}

◆ ft_get_next_line()

char * ft_get_next_line ( int  fd)

◆ ft_is_double()

int ft_is_double ( const char *  n)

Definition at line 15 of file ft_is_double.c.

16{
17 unsigned long i;
18 int p;
19
20 i = 0;
21 while (n[i] && (n[i] == '\t' || n[i] == '\n' || n[i] == '\v'
22 || n[i] == '\f' || n[i] == '\r' || n[i] == ' '))
23 i++;
24 if (n[i] && (n[i] == '+' || n[i] == '-'))
25 i++;
26 if (!n[i])
27 return (FALSE);
28 p = FALSE;
29 while (n[i])
30 {
31 if (!ft_isdigit(n[i]) && n[i] != '.' && n[i] != ',')
32 return (FALSE);
33 if ((n[i] == '.' || n[i] == ',') && p == TRUE)
34 return (FALSE);
35 if (n[i] == '.' || n[i] == ',')
36 p = TRUE;
37 i++;
38 }
39 return (TRUE);
40}
int ft_isdigit(int c)
Definition ft_isdigit.c:13
#define TRUE
Definition libft.h:104
#define FALSE
Definition libft.h:105

References FALSE, ft_isdigit(), and TRUE.

Here is the call graph for this function:

◆ ft_is_num()

int ft_is_num ( const char *  n)

Definition at line 15 of file ft_is_num.c.

16{
17 unsigned long i;
18
19 i = 0;
20 while (n[i] && (n[i] == '\t' || n[i] == '\n' || n[i] == '\v'
21 || n[i] == '\f' || n[i] == '\r' || n[i] == ' '))
22 i++;
23 if (n[i] && (n[i] == '+' || n[i] == '-'))
24 i++;
25 if (!n[i])
26 return (FALSE);
27 while (n[i])
28 {
29 if (!ft_isdigit(n[i]))
30 return (FALSE);
31 i++;
32 }
33 return (TRUE);
34}

References FALSE, ft_isdigit(), and TRUE.

Here is the call graph for this function:

◆ ft_isalnum()

int ft_isalnum ( int  c)

Definition at line 15 of file ft_isalnum.c.

16{
17 return (ft_isalpha(c) || ft_isdigit(c));
18}
int ft_isalpha(int c)
Definition ft_isalpha.c:13

References ft_isalpha(), and ft_isdigit().

Referenced by ev_loop(), and handle_local_vars().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_isalpha()

int ft_isalpha ( int  c)

Definition at line 13 of file ft_isalpha.c.

14{
15 return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
16}

Referenced by ft_isalnum().

Here is the caller graph for this function:

◆ ft_isascii()

int ft_isascii ( int  c)

Definition at line 13 of file ft_isascii.c.

14{
15 return (c >= 0 && c <= 127);
16}

◆ ft_isdigit()

int ft_isdigit ( int  c)

Definition at line 13 of file ft_isdigit.c.

14{
15 return (c >= '0' && c <= '9');
16}

Referenced by ft_is_double(), ft_is_num(), ft_isalnum(), ft_isnumber(), tmp_adj(), and token_adj().

Here is the caller graph for this function:

◆ ft_isprint()

int ft_isprint ( int  c)

Definition at line 13 of file ft_isprint.c.

14{
15 return (c >= ' ' && c <= '~');
16}

◆ ft_itoa()

char * ft_itoa ( int  n)

Definition at line 40 of file ft_itoa.c.

41{
42 int len;
43 char *str;
44
45 if (n == INT_MIN)
46 return (ft_strdup("-2147483648"));
47 if (n == 0)
48 return (ft_strdup("0"));
49 len = count_digits(n);
50 str = (char *)malloc(len + 1);
51 if (!str)
52 return (NULL);
53 str[len--] = '\0';
54 if (n < 0)
55 {
56 str[0] = '-';
57 n = -n;
58 }
59 while (n)
60 {
61 str[len--] = n % 10 + '0';
62 n /= 10;
63 }
64 return (str);
65}
static int count_digits(int n)
Definition ft_itoa.c:23
char * ft_strdup(const char *s)
Definition ft_strdup.c:23

References count_digits(), and ft_strdup().

Referenced by builtin_env(), ft_print_int(), handle_exit(), set_shell_var_handler(), and shell_variable_update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_len_2d_arr()

int ft_len_2d_arr ( char **  array)

Definition at line 15 of file ft_len_2d_arr.c.

16{
17 int count;
18
19 count = 0;
20 while (array && array[count])
21 count++;
22 return (count);
23}

Referenced by split_loc_vars().

Here is the caller graph for this function:

◆ ft_memchr()

void * ft_memchr ( const void *  s,
int  c,
size_t  n 
)

Definition at line 29 of file ft_memchr.c.

30{
31 const unsigned char *st;
32 unsigned char ct;
33
34 st = s;
35 ct = (unsigned char)c;
36 while (n--)
37 {
38 if (*st == ct)
39 return ((void *)st);
40 st++;
41 }
42 return (NULL);
43}

◆ ft_memcmp()

int ft_memcmp ( const void *  s1,
const void *  s2,
size_t  n 
)

Definition at line 23 of file ft_memcmp.c.

24{
25 const unsigned char *st1;
26 const unsigned char *st2;
27
28 st1 = s1;
29 st2 = s2;
30 while (n--)
31 {
32 if (*st1 != *st2)
33 return (*st1 - *st2);
34 st1++;
35 st2++;
36 }
37 return (0);
38}

◆ ft_memcpy()

void * ft_memcpy ( void *  dest,
const void *  src,
size_t  n 
)

Definition at line 22 of file ft_memcpy.c.

23{
24 char *d;
25 const char *s;
26
27 if (!dest && !src)
28 return (NULL);
29 s = src;
30 d = dest;
31 while (n--)
32 *d++ = *s++;
33 return (dest);
34}

Referenced by ft_memmove(), and strndup().

Here is the caller graph for this function:

◆ ft_memmove()

void * ft_memmove ( void *  dest,
const void *  src,
size_t  n 
)

Definition at line 24 of file ft_memmove.c.

25{
26 char *d;
27 const char *s;
28
29 d = dest;
30 s = src;
31 if (d == s)
32 return (dest);
33 if (d < s || d >= s + n)
34 ft_memcpy(d, s, n);
35 else
36 {
37 d += n;
38 s += n;
39 while (n--)
40 *(--d) = *(--s);
41 }
42 return (dest);
43}
void * ft_memcpy(void *dest, const void *src, size_t n)
Definition ft_memcpy.c:22

References ft_memcpy().

Here is the call graph for this function:

◆ ft_memset()

void * ft_memset ( void *  s,
int  c,
size_t  n 
)

Definition at line 28 of file ft_memset.c.

29{
30 unsigned char *ptr;
31
32 ptr = s;
33 while (n-- > 0)
34 *ptr++ = (unsigned char)c;
35 return (s);
36}

Referenced by ft_calloc(), and signal_handler().

Here is the caller graph for this function:

◆ ft_print_2d_arr()

void ft_print_2d_arr ( char **  arr,
char *  name 
)

Definition at line 15 of file ft_print_2d_arr.c.

16{
17 int i;
18
19 i = 0;
20 if (ft_strlen(name) > 0)
21 ft_printf(GRN"----- %s[] -----\n"RESET, name);
22 while (arr && arr[i])
23 {
24 ft_printf(GRN"arr[%d]: %s at add: %p \n"RESET, \
25 i, arr[i], arr[i]);
26 i++;
27 }
28}
int ft_printf(const char *format,...)
Definition ft_printf.c:37
#define RESET
Definition libft.h:111
size_t ft_strlen(const char *s)
Definition ft_strlen.c:15
#define GRN
Definition libft.h:115

References ft_printf(), ft_strlen(), GRN, and RESET.

Referenced by final_quote_removal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_print_char()

int ft_print_char ( int  c)

Definition at line 15 of file ft_print_char.c.

16{
17 ft_putchar_fd(c, 1);
18 return (1);
19}
void ft_putchar_fd(char c, int fd)

References ft_putchar_fd().

Referenced by ft_formatssssss(), and ft_printf().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_print_int()

int ft_print_int ( int  n)

Definition at line 15 of file ft_print_int.c.

16{
17 int len;
18 char *num;
19
20 num = ft_itoa(n);
21 len = ft_print_str(num);
22 free(num);
23 return (len);
24}
int ft_print_str(char *str)
char * ft_itoa(int n)
Definition ft_itoa.c:40

References ft_itoa(), and ft_print_str().

Referenced by ft_formatssssss().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_print_percent()

int ft_print_percent ( void  )

Definition at line 15 of file ft_print_percent.c.

16{
17 ft_putchar_fd('%', 1);
18 return (1);
19}

References ft_putchar_fd().

Referenced by ft_formatssssss().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_print_ptr()

int ft_print_ptr ( unsigned long long  ptr)

Definition at line 44 of file ft_print_ptr.c.

45{
46 int print_length;
47
48 print_length = 0;
49 if (ptr == 0)
50 print_length += write(1, "(nil)", 5);
51 else
52 {
53 print_length += write(1, "0x", 2);
54 ft_put_ptr(ptr);
55 print_length += ft_ptr_len(ptr);
56 }
57 return (print_length);
58}
void ft_put_ptr(uintptr_t num)
int ft_ptr_len(uintptr_t num)

References ft_ptr_len(), and ft_put_ptr().

Referenced by ft_formatssssss().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_print_str()

int ft_print_str ( char *  str)

Definition at line 15 of file ft_print_str.c.

16{
17 int len;
18
19 len = 0;
20 if (str == NULL)
21 {
22 ft_putstr_fd("(null)", 1);
23 return (6);
24 }
25 while (*str)
26 {
27 ft_putchar_fd(*str++, 1);
28 len++;
29 }
30 return (len);
31}
void ft_putstr_fd(char *s, int fd)

References ft_putchar_fd(), and ft_putstr_fd().

Referenced by ft_formatssssss(), ft_print_int(), and ft_print_unsigned_dec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_print_unsigned_dec()

int ft_print_unsigned_dec ( unsigned int  n)

Definition at line 47 of file ft_print_unsigned_dec.c.

48{
49 int count;
50 char *num;
51
52 count = 0;
53 if (n == 0)
54 count += write(1, "0", 1);
55 else
56 {
57 num = ft_uitoa(n);
58 count += ft_print_str(num);
59 free(num);
60 }
61 return (count);
62}
char * ft_uitoa(unsigned int n)

References ft_print_str(), and ft_uitoa().

Referenced by ft_formatssssss().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_print_unsigned_hex()

int ft_print_unsigned_hex ( unsigned int  num,
const char  format 
)

Definition at line 49 of file ft_print_unsigned_hex.c.

50{
51 if (n == 0)
52 {
53 ft_putchar_fd('0', 1);
54 return (1);
55 }
56 else
57 ft_put_hex(n, upper_lower);
58 return (ft_hex_len(n));
59}
int ft_hex_len(unsigned int n)
void ft_put_hex(unsigned int n, const char upper_lower)

References ft_hex_len(), ft_put_hex(), and ft_putchar_fd().

Referenced by ft_formatssssss().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_printf()

int ft_printf ( const char *  format,
  ... 
)

Definition at line 37 of file ft_printf.c.

38{
39 int i;
40 va_list args;
41 int len;
42
43 i = 0;
44 len = 0;
45 va_start(args, str);
46 while (str[i])
47 {
48 if (str[i] == '%')
49 {
50 len += ft_formatssssss(args, str[i + 1]);
51 i++;
52 }
53 else
54 len += ft_print_char(str[i]);
55 i++;
56 }
57 va_end(args);
58 return (len);
59}
int ft_formatssssss(va_list args, const char format)
Definition ft_printf.c:15
int ft_print_char(int c)

References ft_formatssssss(), and ft_print_char().

Referenced by append_word_if_valid(), env_tests(), ft_print_2d_arr(), initialise(), input_error_checks(), main(), new_process(), pipe_tests(), print_ast_args(), print_ast_node(), print_env(), print_env_stack(), print_maxishell(), print_stack(), print_t_env(), print_tokens(), test_get_env(), test_init_env(), test_set_env(), and test_unset_env().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_ptr_len()

int ft_ptr_len ( uintptr_t  num)

Definition at line 15 of file ft_print_ptr.c.

16{
17 int len;
18
19 len = 0;
20 while (num != 0)
21 {
22 len++;
23 num = num / 16;
24 }
25 return (len);
26}

Referenced by ft_print_ptr().

Here is the caller graph for this function:

◆ ft_put_ptr()

void ft_put_ptr ( uintptr_t  num)

Definition at line 28 of file ft_print_ptr.c.

29{
30 if (num >= 16)
31 {
32 ft_put_ptr(num / 16);
33 ft_put_ptr(num % 16);
34 }
35 else
36 {
37 if (num <= 9)
38 ft_putchar_fd((num + '0'), 1);
39 else
40 ft_putchar_fd((num - 10 + 'a'), 1);
41 }
42}

References ft_put_ptr(), and ft_putchar_fd().

Referenced by ft_print_ptr(), and ft_put_ptr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_putchar_fd()

void ft_putchar_fd ( char  c,
int  fd 
)

Definition at line 20 of file ft_putchar_fd.c.

21{
22 write(fd, &c, 1);
23}

Referenced by ft_print_char(), ft_print_percent(), ft_print_str(), ft_print_unsigned_hex(), ft_put_hex(), ft_put_ptr(), ft_putendl_fd(), and ft_putnbr_fd().

Here is the caller graph for this function:

◆ ft_putendl_fd()

void ft_putendl_fd ( char *  s,
int  fd 
)

Definition at line 21 of file ft_putendl_fd.c.

22{
23 if (s)
24 {
25 ft_putstr_fd(s, fd);
26 ft_putchar_fd('\n', fd);
27 }
28}

References ft_putchar_fd(), and ft_putstr_fd().

Referenced by builtin_export(), builtin_pwd(), ft_puterror(), and handle_exit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_putnbr_fd()

void ft_putnbr_fd ( int  n,
int  fd 
)

Definition at line 20 of file ft_putnbr_fd.c.

21{
22 if (n == -2147483648)
23 ft_putstr_fd("-2147483648", fd);
24 else
25 {
26 if (n < 0)
27 {
28 ft_putchar_fd('-', fd);
29 n = -n;
30 }
31 if (n >= 10)
32 ft_putnbr_fd(n / 10, fd);
33 ft_putchar_fd((n % 10) + '0', fd);
34 }
35}
void ft_putnbr_fd(int n, int fd)

References ft_putchar_fd(), ft_putnbr_fd(), and ft_putstr_fd().

Referenced by ft_putnbr_fd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_putstr_fd()

void ft_putstr_fd ( char *  s,
int  fd 
)

Definition at line 20 of file ft_putstr_fd.c.

21{
22 if (s)
23 write(fd, s, ft_strlen(s));
24}

References ft_strlen().

Referenced by builtin_echo(), builtin_env(), ft_print_str(), ft_putendl_fd(), ft_puterror(), ft_putnbr_fd(), handle_exec_errors(), and handle_get_shell_variable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_realloc_array()

char ** ft_realloc_array ( char **  array,
int  old_size,
int  new_size 
)

Definition at line 15 of file ft_realloc_array.c.

16{
17 char **new_array;
18 int i;
19
20 new_array = malloc(sizeof(char *) * (new_size + 1));
21 if (!new_array)
22 exit(1);
23 i = 0;
24 while (i < old_size)
25 {
26 new_array[i] = array[i];
27 i++;
28 }
29 while (i < new_size)
30 {
31 new_array[i] = NULL;
32 i++;
33 }
34 free(array);
35 return (new_array);
36}

Referenced by handle_split_allocation().

Here is the caller graph for this function:

◆ ft_remove_quotes()

char * ft_remove_quotes ( char *  str,
char  quote_type 
)

Definition at line 15 of file ft_remove_quotes.c.

16{
17 int len;
18 char *new_str;
19
20 len = ft_strlen(str);
21 new_str = NULL;
22 if (len > 1 && str[0] == quote_type && str[len - 1] == quote_type)
23 {
24 new_str = ft_strndup(str + 1, len - 2);
25 return (new_str);
26 }
27 return (ft_strdup(str));
28}
char * ft_strndup(const char *s, size_t n)
Definition ft_strndup.c:23

References ft_strdup(), ft_strlen(), and ft_strndup().

Referenced by handle_add_set_shell_variable(), and post_process_command_args().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_split()

char ** ft_split ( char const *  s,
char  c 
)

Definition at line 95 of file ft_split.c.

96{
97 char **result;
98 int word_count;
99
100 if (!s)
101 return (NULL);
102 word_count = count_words(s, c);
103 result = malloc(sizeof(char *) * (word_count + 1));
104 if (!result)
105 return (NULL);
106 split_into_words(result, s, c);
107 return (result);
108}
static void split_into_words(char **result, const char *s, char c)
Definition ft_split.c:68
static int count_words(const char *s, char c)
Definition ft_split.c:32

References count_words(), and split_into_words().

Referenced by builtin_pipe_test(), ft_find_path(), process_and_reassemble(), and split_loc_vars().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_strcat()

char * ft_strcat ( char *  dest,
char *  src 
)

Definition at line 26 of file ft_strcat.c.

27{
28 int i;
29 int j;
30
31 i = 0;
32 while (dest[i] != '\0')
33 i++;
34 j = 0;
35 while (src[j] != '\0')
36 {
37 dest[i + j] = src[j];
38 j++;
39 }
40 dest[i + j] = '\0';
41 return (dest);
42}

Referenced by assemble_result(), generate_prompt(), and token_adj().

Here is the caller graph for this function:

◆ ft_strcat_const()

char * ft_strcat_const ( const char *  dest,
const char *  src 
)

Definition at line 15 of file ft_strcat_const.c.

16{
17 int i;
18 int j;
19 char *result;
20
21 result = malloc(sizeof(char) * (ft_strlen(dest) + ft_strlen(src) + 1));
22 if (!result)
23 return (NULL);
24 i = 0;
25 while (dest[i] != '\0')
26 {
27 result[i] = dest[i];
28 i++;
29 }
30 j = 0;
31 while (src[j] != '\0')
32 {
33 result[i + j] = src[j];
34 j++;
35 }
36 result[i + j] = '\0';
37 return (result);
38}

References ft_strlen().

Referenced by check_operators().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_strchr()

char * ft_strchr ( const char *  s,
int  c 
)

Definition at line 25 of file ft_strchr.c.

26{
27 unsigned char uc;
28
29 uc = (unsigned char)c;
30 while (*s != '\0' && *s != uc)
31 s++;
32 if (*s == uc)
33 return ((char *)s);
34 return (NULL);
35}

Referenced by add_env(), add_env_node(), add_shell_var_node(), ft_exclude_delimiters(), handle_add_set_shell_variable(), handle_local_vars(), handle_phrase(), and tokenise().

Here is the caller graph for this function:

◆ ft_strcmp()

int ft_strcmp ( const char *  s1,
const char *  s2 
)

Definition at line 24 of file ft_strcmp.c.

25{
26 while (*s1 != '\0' || *s2 != '\0')
27 {
28 if (*s1 != *s2)
29 return ((unsigned char)*s1 - (unsigned char)*s2);
30 s1++;
31 s2++;
32 }
33 return (0);
34}

Referenced by builtin_echo(), builtin_env(), builtin_export(), execute(), exit_status_adj(), expand_env_and_loc_var(), get_env(), get_shell_variable(), open_file(), open_tmp_file(), print_env(), set_env(), set_shell_var(), str_start_adj(), test_get_env(), test_set_env(), test_unset_env(), unset_env(), and write_heredoc_lines().

Here is the caller graph for this function:

◆ ft_strcpy()

char * ft_strcpy ( char *  dest,
const char *  src 
)

Definition at line 25 of file ft_strcpy.c.

26{
27 unsigned int i;
28
29 i = 0;
30 while (src[i] != '\0')
31 {
32 dest[i] = src[i];
33 i++;
34 }
35 dest[i] = src[i];
36 return (dest);
37}

Referenced by generate_prompt(), and token_adj().

Here is the caller graph for this function:

◆ ft_strdup()

char * ft_strdup ( const char *  s)

Definition at line 23 of file ft_strdup.c.

24{
25 size_t n;
26 char *new;
27
28 n = ft_strlen(s);
29 if (!s)
30 return (NULL);
31 new = malloc((n + 1) * sizeof(char));
32 if (!new)
33 return (NULL);
34 ft_strlcpy(new, s, n + 1);
35 return (new);
36}
size_t ft_strlcpy(char *dest, const char *src, size_t size)
Definition ft_strlcpy.c:25

References ft_strlcpy(), and ft_strlen().

Referenced by add_env_node(), add_shell_var_node(), append_expanded_var(), child_process(), create_pipe_node(), create_redir_node(), expand_env_and_loc_var(), expand_variable(), finalize_token(), ft_find_path(), ft_itoa(), ft_remove_quotes(), get_env_variable(), get_exit_status(), list_to_array(), new_token(), process_argument(), redirect_here_doc(), set_command_args(), set_env(), set_shell_var(), split_loc_vars(), tmp_adj(), and token_adj().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_striteri()

void ft_striteri ( char *  s,
void(*)(unsigned int, char *)  f 
)

Definition at line 28 of file ft_striteri.c.

29{
30 unsigned int i;
31
32 i = 0;
33 if (!s || !f)
34 return ;
35 while (s[i] != '\0')
36 {
37 f(i, &s[i]);
38 i++;
39 }
40}

◆ ft_strjoin()

char * ft_strjoin ( char const *  s1,
char const *  s2 
)

Definition at line 23 of file ft_strjoin.c.

24{
25 size_t len;
26 char *pt;
27 char *result;
28
29 if (!s1 || !s2)
30 return (NULL);
31 len = ft_strlen(s1) + ft_strlen (s2) + 1;
32 if (len == 0)
33 return (NULL);
34 pt = (char *)malloc(sizeof(char) * len);
35 if (!pt)
36 return (NULL);
37 result = pt;
38 while (*s1)
39 *pt++ = *s1++;
40 while (*s2)
41 *pt++ = *s2++;
42 *pt = '\0';
43 return (result);
44}

References ft_strlen().

Referenced by append_literal(), builtin_cd(), builtin_export(), env_to_array(), ft_strjoin_free(), generate_prompt_string(), handle_numeric_error(), and relative_path_handle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_strjoin_free()

char * ft_strjoin_free ( char *  s1,
char *  s2 
)

Definition at line 15 of file ft_strjoin_free.c.

16{
17 char *result;
18
19 if (!s1 || !s2)
20 return (NULL);
21 result = ft_strjoin(s1, s2);
22 free(s1);
23 return (result);
24}
char * ft_strjoin(char const *s1, char const *s2)
Definition ft_strjoin.c:23

References ft_strjoin().

Referenced by append_expanded_var(), ev_loop(), and expand_variable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_strlcat()

size_t ft_strlcat ( char *  dest,
const char *  src,
size_t  size 
)

Definition at line 26 of file ft_strlcat.c.

27{
28 char *d;
29 const char *s;
30 size_t len_dst;
31 size_t remaining_space;
32
33 len_dst = 0;
34 s = src;
35 d = dst;
36 while (size > 0 && *d != '\0')
37 {
38 d++;
39 size--;
40 len_dst++;
41 }
42 remaining_space = size;
43 if (remaining_space == 0)
44 return (len_dst + ft_strlen(src));
45 while (--remaining_space > 0 && *s != '\0')
46 *d++ = *s++;
47 *d = '\0';
48 return (len_dst + ft_strlen(src));
49}

References ft_strlen().

Here is the call graph for this function:

◆ ft_strlcpy()

size_t ft_strlcpy ( char *  dest,
const char *  src,
size_t  size 
)

Definition at line 25 of file ft_strlcpy.c.

26{
27 char *d;
28 const char *s;
29 size_t n;
30
31 d = dst;
32 s = src;
33 n = size;
34 if (n > 0)
35 {
36 while (--n > 0 && *s != '\0')
37 *d++ = *s++;
38 *d = '\0';
39 }
40 while (*s != '\0')
41 s++;
42 return (s - src);
43}

Referenced by ft_strdup(), and ft_strndup().

Here is the caller graph for this function:

◆ ft_strlen()

size_t ft_strlen ( const char *  s)

◆ ft_strmapi()

char * ft_strmapi ( char const *  s,
char(*)(unsigned int, char)  f 
)

Definition at line 28 of file ft_strmapi.c.

29{
30 char *result;
31 size_t len;
32 size_t i;
33
34 if (!s || !f)
35 return (NULL);
36 len = 0;
37 while (s[len] != '\0')
38 len++;
39 result = (char *)malloc((len + 1) * sizeof(char));
40 if (!result)
41 return (NULL);
42 i = 0;
43 while (i < len)
44 {
45 result[i] = f(i, s[i]);
46 i++;
47 }
48 result[len] = '\0';
49 return (result);
50}

◆ ft_strncmp()

int ft_strncmp ( const char *  s1,
const char *  s2,
size_t  n 
)

Definition at line 24 of file ft_strncmp.c.

25{
26 while (n > 0 && (*s1 != '\0' || *s2 != '\0'))
27 {
28 if (*s1 != *s2)
29 return ((unsigned char)*s1 - (unsigned char)*s2);
30 s1++;
31 s2++;
32 n--;
33 }
34 return (0);
35}

Referenced by child_process(), ft_find_path(), ft_strnstr(), ft_strstr(), generate_prompt_string(), list_repeat_check_str(), and main_loop().

Here is the caller graph for this function:

◆ ft_strndup()

char * ft_strndup ( const char *  s,
size_t  n 
)

Definition at line 23 of file ft_strndup.c.

24{
25 size_t len;
26 char *new;
27
28 len = ft_strlen(s);
29 if (!s)
30 return (NULL);
31 new = malloc((n + 1) * sizeof(char));
32 if (!new)
33 return (NULL);
34 if (n > len)
35 n = len;
36 ft_strlcpy(new, s, n + 1);
37 return (new);
38}

References ft_strlcpy(), and ft_strlen().

Referenced by add_env_node(), append_word_if_valid(), final_quote_removal(), and ft_remove_quotes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_strnstr()

char * ft_strnstr ( const char *  haystack,
const char *  needle,
size_t  len 
)

Definition at line 25 of file ft_strnstr.c.

26{
27 size_t little_len;
28
29 if (!big && n == 0)
30 return (NULL);
31 little_len = ft_strlen(little);
32 if (little[0] == '\0')
33 return ((char *)big);
34 while (*big != '\0' && n >= little_len)
35 {
36 if (ft_strncmp(big, little, little_len) == 0)
37 return ((char *)big);
38 big++;
39 n--;
40 }
41 return (NULL);
42}
int ft_strncmp(const char *s1, const char *s2, size_t n)
Definition ft_strncmp.c:24

References ft_strlen(), and ft_strncmp().

Here is the call graph for this function:

◆ ft_strrchr()

char * ft_strrchr ( const char *  s,
int  c 
)

Definition at line 24 of file ft_strrchr.c.

25{
26 unsigned char uc;
27 const char *last_occurrence;
28
29 last_occurrence = NULL;
30 uc = (unsigned char)c;
31 while (*s != '\0')
32 {
33 if (*s == uc)
34 last_occurrence = s;
35 s++;
36 }
37 if (*s == uc)
38 return ((char *)s);
39 return ((char *)last_occurrence);
40}

◆ ft_strstr()

char * ft_strstr ( const char *  big,
const char *  little 
)

Definition at line 24 of file ft_strstr.c.

25{
26 size_t little_len;
27
28 if (!big)
29 return (NULL);
30 little_len = ft_strlen(little);
31 if (little[0] == '\0')
32 return ((char *)big);
33 while (*big != '\0')
34 {
35 if (ft_strncmp(big, little, little_len) == 0)
36 return ((char *)big);
37 big++;
38 }
39 return (NULL);
40}

References ft_strlen(), and ft_strncmp().

Here is the call graph for this function:

◆ ft_strtrim()

char * ft_strtrim ( char const *  s1,
char const *  set 
)

Definition at line 39 of file ft_strtrim.c.

40{
41 char *str;
42 size_t i;
43 size_t start;
44 size_t end;
45
46 if (!s1 || !set)
47 return (NULL);
48 start = 0;
49 while (s1[start] && ft_char_in_set(s1[start], set))
50 start++;
51 end = ft_strlen(s1);
52 while (end > start && ft_char_in_set(s1[end - 1], set))
53 end--;
54 str = (char *)malloc(sizeof(*s1) * (end - start + 1));
55 if (!str)
56 return (NULL);
57 i = 0;
58 while (start < end)
59 str[i++] = s1[start++];
60 str[i] = 0;
61 return (str);
62}
static int ft_char_in_set(char c, char const *set)
Definition ft_strtrim.c:25

References ft_char_in_set(), and ft_strlen().

Referenced by trim_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_substr()

char * ft_substr ( char const *  s,
unsigned int  start,
size_t  len 
)

Definition at line 27 of file ft_substr.c.

28{
29 char *new_str;
30 size_t i;
31 size_t j;
32 size_t size;
33
34 size = ft_strlen(s) - start;
35 if (start > ft_strlen(s))
36 size = 0;
37 else if (size > len)
38 size = len;
39 new_str = (char *)malloc(size + 1);
40 if (!s || !new_str)
41 return (0);
42 i = start;
43 j = 0;
44 while (i < ft_strlen(s) && j < len)
45 new_str[j++] = s[i++];
46 new_str[j] = '\0';
47 return (new_str);
48}

References ft_strlen().

Referenced by append_literal(), ev_loop(), expand_variable(), and post_process_command_args().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_tolower()

int ft_tolower ( int  c)

Definition at line 15 of file ft_tolower.c.

16{
17 if (c >= 'A' && c <= 'Z')
18 return (c + ('a' - 'A'));
19 return (c);
20}

◆ ft_toupper()

int ft_toupper ( int  c)

Definition at line 15 of file ft_toupper.c.

16{
17 if (c >= 'a' && c <= 'z')
18 return (c - ('a' - 'A'));
19 return (c);
20}

◆ isnum_from_str()

int isnum_from_str ( const char *  str)

Definition at line 15 of file isnum_from_str.c.

16{
17 if (!str || *str == '\0')
18 return (0);
19 if (*str == '-' || *str == '+')
20 {
21 str++;
22 if (*str == '\0')
23 return (0);
24 }
25 while (*str)
26 {
27 if (*str < '0' || *str > '9')
28 return (0);
29 str++;
30 }
31 return (1);
32}

◆ list_len_char()

int list_len_char ( char  a[])

Definition at line 13 of file list_len_char.c.

14{
15 int i;
16
17 i = 0;
18 while (a[i] != '\0')
19 i++;
20 return (i);
21}

◆ list_len_str()

int list_len_str ( char *  a[])

Definition at line 15 of file list_len_str.c.

16{
17 int i;
18
19 i = 0;
20 while (a[i])
21 i++;
22 return (i);
23}

◆ list_repeat_check_int()

int list_repeat_check_int ( int  a[],
int  size 
)

Definition at line 15 of file list_repeat_check_int.c.

16{
17 int i;
18 int j;
19
20 i = 0;
21 while (i < size - 1)
22 {
23 j = i + 1;
24 while (j < size)
25 {
26 if (a[i] == a[j])
27 return (1);
28 j++;
29 }
30 i++;
31 }
32 return (0);
33}

◆ list_repeat_check_str()

int list_repeat_check_str ( char *  a[],
int  size 
)

Definition at line 15 of file list_repeat_check_str.c.

16{
17 int i;
18 int j;
19
20 i = 0;
21 while (i < size - 1)
22 {
23 j = i + 1;
24 while (j < size)
25 {
26 if (ft_strncmp(a[i], a[j], size) == 0)
27 return (1);
28 j++;
29 }
30 i++;
31 }
32 return (0);
33}

References ft_strncmp().

Here is the call graph for this function: