-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.c
99 lines (89 loc) · 1.9 KB
/
funcs.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* funcs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ebalgruu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/27 01:39:43 by ebalgruu #+# #+# */
/* Updated: 2021/11/27 01:39:45 by ebalgruu ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static int getlen_pars(unsigned int num)
{
int len;
len = 1;
while (num / 10 > 0)
{
num = num / 10;
len++;
}
return (len);
}
static char *res_pars(char *str, int len, unsigned int num, int sign)
{
str[len--] = 0;
str[len--] = num % 10 + 48;
while (num / 10 > 0)
{
num = num / 10;
str[len--] = num % 10 + 48;
}
if (sign)
str[0] = 45;
return (str);
}
char *ft_itoa_pars(int n, t_arg *arg)
{
char *str;
int sign;
int len;
unsigned int num;
sign = 0;
num = n;
if (n < 0)
{
sign = 1;
num = -n;
}
len = getlen_pars(num) + sign;
str = malloc((len + 1) * sizeof(*str));
if (str == NULL)
ft_exit(12, "malloc", arg);
return (res_pars(str, len, num, sign));
}
void ft_gap2(char *str, int *i)
{
int j;
j = *i;
j++;
while (str[j])
{
if (str[j] == '\"')
{
*i = j + 1;
return ;
}
else
j++;
}
(*i)++;
}
void ft_gap(char *str, int *i)
{
int j;
j = *i;
j++;
while (str[j])
{
if (str[j] == '\'')
{
*i = j + 1;
return ;
}
else
j++;
}
(*i)++;
}