-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
271 lines (235 loc) · 4.46 KB
/
main.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dnessaiv <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/31 00:08:50 by dnessaiv #+# #+# */
/* Updated: 2016/08/31 00:08:53 by dnessaiv ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <unistd.h>
#include "ft_list.h"
#define MAX_READ 4096
/*
** Keep CPY_TYPE as char to trigger autovectorization (-O3)
*/
#define CPY_TYPE char
#define CPY_WSIZE sizeof(CPY_TYPE)
#define CPY_WMASK (CPY_WSIZE - 1)
void ft_memcpy_aligned(void *dst, void *src, size_t length)
{
size_t t;
if (!src)
return ;
src += length;
dst += length;
t = length / CPY_WSIZE;
while (t > 0)
{
src -= CPY_WSIZE;
dst -= CPY_WSIZE;
*(CPY_TYPE*)dst = *(CPY_TYPE*)src;
t--;
}
}
char *ft_realloc(char *buf, ssize_t *buf_cap)
{
ssize_t old_cap;
char *newbuf;
old_cap = *buf_cap;
*buf_cap = old_cap * 2;
newbuf = malloc(*buf_cap);
ft_memcpy_aligned(newbuf, buf, old_cap);
free(buf);
return (newbuf);
}
char *ft_read_input(int fd)
{
ssize_t read_size;
char *buf;
ssize_t buf_cap;
ssize_t buf_offset;
buf_cap = MAX_READ / 2;
buf = ft_realloc(NULL, &buf_cap);
buf_offset = 0;
while ((read_size = read(fd, buf + buf_offset, MAX_READ)) > 0)
{
buf_offset = buf_offset + read_size;
if (buf_cap - buf_offset < MAX_READ + 1)
buf = ft_realloc(buf, &buf_cap);
}
buf[buf_offset] = 0;
return (buf);
}
int test_errors(char *buff)
{
int i;
int size;
size = 0;
i = 4;
if (buff[i] != '\n')
return (0);
i++;
while (buff[i])
{
while (buff[i] != '\n')
{
i++;
size++;
}
while ()
{
return (0);
}
}
}
int ft_puterror(char *str)
{
int i;
i = 0;
while (str[i])
{
write(2, &str[i++], 1);
}
return (0);
}
void check_errors(buffer)
{
check true instances
otherwise
return (0);
}
char **build_2d(buffer, width, height)
{
char **our_array
int index;
int i;
int j;
i = 0;
j = 0;
index = 5;
our_array = malloc (sizeof(char *) * width)
while (buffer[index])
{
while (i < height)
{
our_array[i] = malloc(sizeof * width)
i++;
}
i = 0;
while (i < height && buffer[index])
{
if (buffer[index] = '\n')
{
index++;
i++;
}
while (j < width && buffer[index])
{
our_array[i][j] = buffer[index];
j++;
index++;
}
i++;
}
}
}
int get_width(buffer)
{
int i;
int width;
width = 0;
i = 6
if (buffer)
{
while (buffer[i] != '\n' && buffer[i])
{
++width;
++i;
}
}
return (width);
}
t_iterators solve_array(our_array, height, width)
{
int i;
int j;
t_iterators coordinates;
coordinates.size = 0
i = 0;
j = 0;
while (i < heigth)
{
while (j < width)
{
coordinates.x = i;
coordinates.y = j;
if (size < gsq(our_array, coordinates, obstacle, coordinates.size))
{
coordinates.prime_x = i;
coordinates.prime_y = j;
coordinates.size = gsq(our_array, coordinates, obstacle, coordinates.size)
}
j++;
}
i++;
}
return (coordinates);
}
void mod_array(char **our_array, t_iterator coordinates, full)
{
int i;
int j;
while (i<size)
{
while (j<size)
{
our_array[(coordinates.prime_x)+i][(coordinates.prime_y)+j] = full
j++;
}
i++;
}
}
void outputs_array(int width, int height, char **our_array)
{
int i;
int j;
i = 0;
j = 0;
while (i < height)
{
while (j < width)
{
write(1, our_array[i][j], 1);
j++;
}
i++;
}
}
int main()
{
int i;
int j;
int width;
int height;
char instructions[5];
char **our_array;
t_iterator coordinates;
i = 0;
j = 0;
buffer = get_buffer;
height = ft_atoi(buffer[0]);
empty = buffer[1];
obstacle = buffer[2];
full = buffer[3];
width = get_width(buffer);
check_errors(buffer, width);
our_array = build_2d(buffer, width, height);
coordinates = solve_array(our_array, height, width, obstacle);
mod_array(our_array, coordinates)
greatest_square_size(our_array, i, j);
return (0);
}