-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.c
More file actions
92 lines (84 loc) · 1.47 KB
/
generator.c
File metadata and controls
92 lines (84 loc) · 1.47 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
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
size_t ft_strlen(const char *s)
{
int i;
i = 0;
while (s[i])
i++;
return (i);
}
char *ft_strjoin(char const *s1, char const *s2)
{
int i;
int k;
char *str;
if (!s1 || !s2)
return (NULL);
i = ft_strlen(s1);
k = ft_strlen(s2);
str = malloc(sizeof(char) * (i + k) + 1);
if (!(str))
return (0);
i = 0;
k = 0;
while (s1[i])
str[k++] = s1[i++];
i = 0;
while (s2[i])
{
str[k] = s2[i];
k++;
i++;
}
str[k] = '\0';
return (str);
}
char *ft_strjoin3(char *s1, char *s2, char *s3)
{
char *tmp;
char *tmp2;
if (!s1 || !s2 || !s3)
return (NULL);
tmp = ft_strjoin(s1, s2);
if (tmp == NULL)
return (NULL);
tmp2 = ft_strjoin(tmp, s3);
free(tmp);
if (tmp2 == NULL)
return (NULL);
return (tmp2);
}
int main(int ac, char **av)
{
int i;
int fd;
char *tmp;
i = 2;
tmp = ft_strjoin(av[1], "Makefile");
fd = open(tmp, O_WRONLY | O_TRUNC | O_CREAT, 0644);
free(tmp);
if (fd == -1)
{
printf("DA FUCK.1\n");
return (1);
}
close(fd);
while (i < ac)
{
tmp = ft_strjoin3(av[1], av[i], ".hpp");
fd = open(tmp, O_WRONLY | O_TRUNC | O_CREAT, 0644);
free(tmp);
close(fd);
tmp = ft_strjoin3(av[1], av[i], ".cpp");
fd = open(tmp, O_WRONLY | O_TRUNC | O_CREAT, 0644);
free(tmp);
close(fd);
i++;
}
return (0);
}