-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_ubuntu.c
335 lines (308 loc) · 9.4 KB
/
main_ubuntu.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
This main works on ubuntu
Remove the first "_" on function call names in order to get MacOSX compatibility
compile linux:
nasm -f elf64 ft_strcat.nasm;\
nasm -f elf64 ft_bzero.nasm;\
nasm -f elf64 ft_isalpha.nasm;\
nasm -f elf64 ft_isdigit.nasm;\
nasm -f elf64 ft_isalnum.nasm;\
nasm -f elf64 ft_isascii.nasm;\
nasm -f elf64 ft_isprint.nasm;\
nasm -f elf64 ft_toupper.nasm;\
nasm -f elf64 ft_tolower.nasm;\
nasm -f elf64 ft_puts.nasm;\
gcc -Wall -Wextra -Werror -o asmlib ft_strcat.o ft_bzero.o ft_isalpha.o ft_isdigit.o ft_isalnum.o ft_isascii.o ft_isprint.o ft_toupper.o ft_tolower.o ft_puts.o main_ubuntu.c; rm *.o;\
./asmlib;\
rm asmlib
*/
#include <unistd.h>
#include <stdio.h>
void _ft_strcat(char *str, char *str2);
void _ft_bzero(char *str, unsigned int size);
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);
void _ft_puts(char *str);
int main ( void ) {
char teststr[20];
teststr[0] = 'b';
teststr[1] = 'z';
teststr[2] = 'e';
teststr[3] = 'r';
teststr[4] = 'o';
teststr[5] = 'b';
teststr[6] = 'z';
teststr[7] = 'e';
teststr[8] = 'r';
teststr[9] = 'o';
teststr[10] = 0;
teststr[11] = 0;
teststr[12] = 0;
teststr[13] = 0;
teststr[14] = 0;
teststr[15] = 0;
teststr[16] = 0;
teststr[17] = 0;
teststr[18] = 0;
teststr[19] = 0;
/* bzero tests */
printf("\n ----------- \n");
printf(" -- bzero -- \n");
printf(" ----------- \n");
printf(" - string : \n");
write(1, teststr, 20);
printf("\n - result (expected : bzeroo) : \n");
_ft_bzero(teststr + 5, (unsigned int) 4);
write(1, teststr, 20);
teststr[0] = 'b';
teststr[1] = 'z';
teststr[2] = 'e';
teststr[3] = 'r';
teststr[4] = 'o';
teststr[5] = 'b';
teststr[6] = 'z';
teststr[7] = 'e';
teststr[8] = 'r';
teststr[9] = 'o';
teststr[10] = '0';
teststr[11] = '0';
teststr[12] = '0';
teststr[13] = '0';
teststr[14] = '0';
teststr[15] = '0';
teststr[16] = '0';
teststr[17] = '0';
teststr[18] = '0';
teststr[19] = 0;
_ft_bzero(teststr, 17);
printf("\n - result (expected : 0) : \n");
_ft_bzero(teststr, (unsigned int) 18);
write(1, teststr, 20);
teststr[18] = 0;
printf("\n\n");
/* strcat tests */
teststr[0] = 'b';
teststr[1] = 'z';
teststr[2] = 'e';
teststr[3] = 'r';
teststr[4] = 'o';
teststr[5] = 0;
printf(" ------------ \n");
printf(" -- strcat -- \n");
printf(" ------------ \n");
printf(" - string : \n");
write(1, teststr, 20);
printf("\n - result (expected : bzerobzero) : \n");
_ft_strcat(teststr, "bzero");
write(1, teststr, 20);
printf("\n\n");
/* isalpha tests */
printf(" ------------- \n");
printf(" -- isalpha -- \n");
printf(" ------------- \n");
if (_ft_isalpha('a') == 0)
printf("/!\\ erreur sur is alpha a\n");
else if (_ft_isalpha('z') == 0)
printf("/!\\ erreur sur is alpha z\n");
else if (_ft_isalpha('A') == 0)
printf("/!\\ erreur sur is alpha A\n");
else if (_ft_isalpha('Z') == 0)
printf("/!\\ erreur sur is alpha Z\n");
else if (_ft_isalpha('0') != 0)
printf("/!\\ erreur sur is alpha 0\n");
else if (_ft_isalpha('9') != 0)
printf("/!\\ erreur sur is alpha 9\n");
else if (_ft_isalpha(' ') != 0)
printf("/!\\ erreur sur is alpha ' '\n");
else if (_ft_isalpha('/') != 0)
printf("/!\\ erreur sur is alpha '/'\n");
else if (_ft_isalpha(':') != 0)
printf("/!\\ erreur sur is alpha ':'\n");
else if (_ft_isalpha('@') != 0)
printf("/!\\ erreur sur is alpha '@'\n");
else if (_ft_isalpha('[') != 0)
printf("/!\\ erreur sur is alpha '['\n");
else if (_ft_isalpha('`') != 0)
printf("/!\\ erreur sur is alpha '`'\n");
else if (_ft_isalpha('{') != 0)
printf("/!\\ erreur sur is alpha '{'\n");
else
printf("all good on is alpha");
printf("\n\n");
/* isdigit tests */
printf(" ------------- \n");
printf(" -- isdigit -- \n");
printf(" ------------- \n");
if (_ft_isdigit('a') != 0)
printf("/!\\ erreur sur is digit a\n");
else if (_ft_isdigit('z') != 0)
printf("/!\\ erreur sur is digit z\n");
else if (_ft_isdigit('A') != 0)
printf("/!\\ erreur sur is digit A\n");
else if (_ft_isdigit('Z') != 0)
printf("/!\\ erreur sur is digit Z\n");
else if (_ft_isdigit('0') == 0)
printf("/!\\ erreur sur is digit 0\n");
else if (_ft_isdigit('9') == 0)
printf("/!\\ erreur sur is digit 9\n");
else if (_ft_isdigit(' ') != 0)
printf("/!\\ erreur sur is digit ' '\n");
else if (_ft_isdigit('/') != 0)
printf("/!\\ erreur sur is digit '/'\n");
else if (_ft_isdigit(':') != 0)
printf("/!\\ erreur sur is digit ':'\n");
else if (_ft_isdigit('@') != 0)
printf("/!\\ erreur sur is digit '@'\n");
else if (_ft_isdigit('[') != 0)
printf("/!\\ erreur sur is digit '['\n");
else if (_ft_isdigit('`') != 0)
printf("/!\\ erreur sur is digit '`'\n");
else if (_ft_isdigit('{') != 0)
printf("/!\\ erreur sur is digit '{'\n");
else
printf("all good on is digit");
printf("\n\n");
/* isalnum tests */
printf(" ------------- \n");
printf(" -- isalnum -- \n");
printf(" ------------- \n");
if (_ft_isalnum('a') == 0)
printf("/!\\ erreur sur is alnum a\n");
else if (_ft_isalnum('z') == 0)
printf("/!\\ erreur sur is alnum z\n");
else if (_ft_isalnum('A') == 0)
printf("/!\\ erreur sur is alnum A\n");
else if (_ft_isalnum('Z') == 0)
printf("/!\\ erreur sur is alnum Z\n");
else if (_ft_isalnum('0') == 0)
printf("/!\\ erreur sur is alnum 0\n");
else if (_ft_isalnum('9') == 0)
printf("/!\\ erreur sur is alnum 9\n");
else if (_ft_isalnum(' ') != 0)
printf("/!\\ erreur sur is alnum ' '\n");
else if (_ft_isalnum('/') != 0)
printf("/!\\ erreur sur is alnum '/'\n");
else if (_ft_isalnum(':') != 0)
printf("/!\\ erreur sur is alnum':'\n");
else if (_ft_isalnum('@') != 0)
printf("/!\\ erreur sur is alnum '@'\n");
else if (_ft_isalnum('[') != 0)
printf("/!\\ erreur sur is alnum '['\n");
else if (_ft_isalnum('`') != 0)
printf("/!\\ erreur sur is alnum '`'\n");
else if (_ft_isalnum('{') != 0)
printf("/!\\ erreur sur is alnum '{'\n");
else
printf("all good on is alnum");
printf("\n\n");
/* isascii tests */
printf(" ------------- \n");
printf(" -- isascii -- \n");
printf(" ------------- \n");
if (_ft_isascii(0) == 0)
printf("/!\\ erreur sur is ascii 0\n");
else if (_ft_isascii(63) == 0)
printf("/!\\ erreur sur is ascii 63\n");
else if (_ft_isascii(127) == 0)
printf("/!\\ erreur sur is ascii 127\n");
else if (_ft_isascii(-1) != 0)
printf("/!\\ erreur sur is ascii -1\n");
else if (_ft_isascii(-127) != 0)
printf("/!\\ erreur sur is ascii -127\n");
else if (_ft_isascii(128) != 0)
printf("/!\\ erreur sur is ascii 128\n");
else if (_ft_isascii(255) != 0)
printf("/!\\ erreur sur is ascii 255\n");
else
printf("all good on is ascii");
printf("\n\n");
/* isprint tests */
printf(" ------------- \n");
printf(" -- isprint -- \n");
printf(" ------------- \n");
if (_ft_isprint(0) != 0)
printf("/!\\ erreur sur is print 0\n");
else if (_ft_isprint(31) != 0)
printf("/!\\ erreur sur is print 31\n");
else if (_ft_isprint(32) == 0)
printf("/!\\ erreur sur is print 32\n");
else if (_ft_isprint(63) == 0)
printf("/!\\ erreur sur is print 63\n");
else if (_ft_isprint(126) == 0)
printf("/!\\ erreur sur is print 126\n");
else if (_ft_isprint(127) != 0)
printf("/!\\ erreur sur is print 127\n");
else if (_ft_isprint(-63) != 0)
printf("/!\\ erreur sur is print -63\n");
else if (_ft_isprint(255) != 0)
printf("/!\\ erreur sur is print 255\n");
else
printf("all good on is print");
printf("\n\n");
/* toupper tests */
printf(" ------------- \n");
printf(" -- toupper -- \n");
printf(" ------------- \n");
if (_ft_toupper(97) != 65)
printf("/!\\ erreur sur to upper 97\n");
else if (_ft_toupper(107) != 75)
printf("/!\\ erreur sur to upper 107\n");
else if (_ft_toupper(122) != 90)
printf("/!\\ erreur sur to upper 122\n");
else if (_ft_toupper(96) != 96)
printf("/!\\ erreur sur to upper 96\n");
else if (_ft_toupper(123) != 123)
printf("/!\\ erreur sur to upper 123\n");
else if (_ft_toupper(70) != 70)
printf("/!\\ erreur sur to upper 70\n");
else if (_ft_toupper(-63) != -63)
printf("/!\\ erreur sur to upper -63\n");
else if (_ft_toupper(50) != 50)
printf("/!\\ erreur sur to upper 50\n");
else
printf("all good on to upper");
printf("\n\n");
/* tolower tests */
printf(" ------------- \n");
printf(" -- tolower -- \n");
printf(" ------------- \n");
if (_ft_tolower(97) != 97)
printf("/!\\ erreur sur to lower 97\n");
else if (_ft_tolower(107) != 107)
printf("/!\\ erreur sur to lower 107\n");
else if (_ft_tolower(122) != 122)
printf("/!\\ erreur sur to lower 122\n");
else if (_ft_tolower(96) != 96)
printf("/!\\ erreur sur to lower 96\n");
else if (_ft_tolower(123) != 123)
printf("/!\\ erreur sur to lower 123\n");
else if (_ft_tolower(127) != 127)
printf("/!\\ erreur sur to lower 127\n");
else if (_ft_tolower(-63) != -63)
printf("/!\\ erreur sur to lower -63\n");
else if (_ft_tolower(255) != 255)
printf("/!\\ erreur sur to lower 255\n");
else if (_ft_tolower(65) != 97)
printf("/!\\ erreur sur to lower 65\n");
else if (_ft_tolower(90) != 122)
printf("/!\\ erreur sur to lower 122\n");
else if (_ft_tolower(80) != 112)
printf("/!\\ erreur sur to lower 80\n");
else
printf("all good on to lower");
printf("\n\n");
/* ft_puts tests */
printf(" ---------- \n");
printf(" -- puts -- \n");
printf(" ---------- \n");
char *testputs = "string in ftputs !!!";
printf("if nothing if wrote below: it's not a feature; it's a bug.\n");
_ft_puts(testputs);
printf("\n\n");
return ( 0 );
}