Compare commits

..

31 Commits

Author SHA1 Message Date
e417a01f9a add: positive num test to ntoa_s 2023-07-26 23:35:56 +02:00
21c78421a4 rename LOCATION to GALLOC 2023-07-26 19:35:27 +02:00
f05f3945fe add: map size 2023-07-26 18:23:54 +02:00
ba9c1f8c11 add: map enum 2023-07-26 18:21:26 +02:00
7f6225d8dd Update README.md 2023-07-26 11:07:47 +00:00
0b09f0d262 test only .🗿 file 2023-07-26 13:05:16 +02:00
69a044b3fa Cringios 2023-07-26 11:00:26 +00:00
kdx
e9bf776069 j'ai cringe 2023-07-26 12:57:10 +02:00
ed23a887f9 fix geadline (#6) 2023-07-26 10:55:07 +00:00
kdx
4bd9f50bd4 fix geadline 2023-07-26 12:53:38 +02:00
58f9c0cf9e Add wiki/strncpy.md 2023-07-26 10:34:17 +00:00
cc965024d6 Update wiki/strcpy.md 2023-07-26 10:28:27 +00:00
2421c51116 Add wiki/strcpy 2023-07-26 10:28:14 +00:00
78bc62c044 Add wiki/strcat.md 2023-07-26 10:26:06 +00:00
57de93e799 Add wiki/strlen.md 2023-07-26 10:20:13 +00:00
9a23536491 remove: useless func strchri 2023-07-26 12:13:10 +02:00
54370e872e auto check if file.input exist 2023-07-26 12:05:04 +02:00
106d2da5a0 add: geadline test 2023-07-26 10:20:02 +02:00
c41ebf6ff5 use insane new feature of golem 2023-07-26 09:57:11 +02:00
a84415a953 Merge pull request 'geadline2' (#5) from kdx/IronGOLEM:master into master
Reviewed-on: #5
2023-07-25 07:53:38 +00:00
470b97446b Merge branch 'master' into master 2023-07-25 07:53:20 +00:00
09e0d32c15 clean and opti 2023-07-25 09:48:20 +02:00
2b97d38b7e rename replace func to replace_index 2023-07-25 09:41:07 +02:00
cb41e69bdb clean: remove test to deleted func (reallocarray) 2023-07-25 09:39:27 +02:00
kdx
cc53b0cda5 geadline2 2023-07-25 09:24:38 +02:00
kdx
a432fd32c5 geadline: use getchar 2023-07-25 07:56:22 +02:00
15d00356e4 Merge pull request 'getchar' (#4) from kdx/IronGOLEM:master into master
Reviewed-on: #4
2023-07-25 05:43:57 +00:00
kdx
c4ce5b8566 getchar 2023-07-25 07:43:11 +02:00
kdx
1452a70b85 various optimisations 2023-07-25 05:43:10 +02:00
kdx
575ed7aa64 reduce galloc memory 2023-07-25 05:27:21 +02:00
kdx
46d7e9c85c geadline: move cursor 2023-07-25 05:10:15 +02:00
41 changed files with 381 additions and 184 deletions

View File

@ -17,8 +17,20 @@ You can simply add the [latest release](https://git.chauvet.pro/starnakin/IronGO
- [aton](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/aton)
- [aton_s](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/aton_s)
- [bzero](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/bzero)
- [aton_s](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/aton_s)
- [galloc](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/galloc)
- [free](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/free)
- [leaks](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/leaks)
- [ntoa](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/ntoa)
- [ntoa_s](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/ntoa_s)
- [ntoa_s](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/ntoa_s)
- [geadline](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/geadline)
- [geadline2](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/geadline2)
- [strcat](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strcat)
- [strcpy](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strcpy)
- [strncpy](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strncpy)
- [strlen](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strlen)
- [strncmp](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strncmp)
- [strcmp](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strcmp)
- [strchr](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strchr)
- [strstr](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strstr)
- [strndup](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strndup)
- [strdup](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strdup)

View File

@ -1,18 +1,16 @@
aton(str)
{
local i = 0;
local out = 0;
loop {
if ([str + i] != '+')
if ([str] != '+')
break;
i++;
str++;
}
loop {
if ([str + i] == 0 | isdigit([str + i]) == 0)
break;
out = out * 10 + [str + i] - '0';
i++;
if ([str] == 0 | isdigit([str]) == 0)
return out;
out = out * 10 + [str] - '0';
str++;
}
return out;
}

View File

@ -1,23 +1,19 @@
aton_s(str)
{
local i = 0;
local sign = 0;
local out = 0;
loop {
if ([str + i] == '-')
if ([str] == '-')
sign = sign == 0;
else if ([str + i] != '+')
else if ([str] != '+')
break;
i++;
str++;
}
loop {
if ([str + i] == 0 | isdigit([str + i]) == 0)
break;
out = out * 10 + [str + i] - '0';
i++;
if ([str] == 0 | isdigit([str]) == 0)
return (sign * (0 - out)) | ((sign == 0) * out);
out = out * 10 + [str] - '0';
str++;
}
if (sign)
return (0 - out);
return out;
}

View File

@ -1 +1 @@
bzero(tab, size) memset(tab, size, 0);
bzero(tab, size) => memset(tab, size, 0);

View File

@ -1,14 +1,11 @@
contain_only(to_big, to_find)
{
local tmp;
tmp = to_big;
loop
{
if ([tmp] == 0)
if ([to_big] == 0)
return 1;
if (strchr(to_find, [tmp]) == 0)
if (strchr(to_find, [to_big]) == 0)
return 0;
tmp++;
to_big++;
}
}

View File

@ -1,3 +1,6 @@
enum MAP_KEY, MAP_VALUE;
define MAP_SIZE=2;
define NUM_MAX = 0xffff;
define NUM_MIN = 0x0000;
define NUM_S_MIN = 0x8000;

View File

@ -9,5 +9,5 @@ free_tab(tab)
free([tmp]);
tmp++;
}
free(tab);
return free(tab);
}

51
src/galgrind.🗿 Normal file
View File

@ -0,0 +1,51 @@
invalid_write(ptr, i)
{
if (i < GALLOC_PADDING_SIZE & [ptr + GALLOC_HEADER_SIZE + i])
return ptr + GALLOC_HEADER_SIZE + i;
if (i >= GALLOC_PADDING_SIZE & [ptr + GALLOC_DATA + i - GALLOC_PADDING_SIZE + [ptr + GALLOC_SIZE]])
return ptr + GALLOC_DATA + i - GALLOC_PADDING_SIZE + [ptr + GALLOC_SIZE];
return 0;
}
galgrind()
{
local ptr = heap;
local i;
loop
{
if (ptr == NULL)
return 0;
if ([ptr + GALLOC_USED] == 1)
{
putstr("block: ");
putnum(ptr - heap);
putstr(", size: ");
putnum([ptr + GALLOC_SIZE]);
putstr("cases");
putstr(", start: ");
putnum(ptr - heap + GALLOC_DATA);
putstr(", end: ");
putnum(ptr - heap + GALLOC_DATA + [ptr + GALLOC_SIZE]);
putstr(", start galloc block: ");
putnum(ptr - heap);
putstr(", end galloc block: ");
putnum(ptr - heap + GALLOC_DATA + [ptr + GALLOC_SIZE] + GALLOC_PADDING_SIZE);
putchar('\n');
i = 0;
loop
{
if (i == GALLOC_PADDING_SIZE * 2)
break;
if (invalid_write(ptr, i))
{
putnum(invalid_write(ptr, i) - heap);
putchar('\n');
}
i++;
}
putchar('\n');
}
ptr = [ptr + GALLOC_NEXT];
}
}

View File

@ -1,8 +1,8 @@
define HEAP_SIZE = 0x8000;
define HEAP_SIZE = 0x4000;
global heap[HEAP_SIZE] = 0;
define PADDING_SIZE = 4;
define HEADER_SIZE = 5;
define GALLOC_PADDING_SIZE = 4;
define GALLOC_HEADER_SIZE = 5;
🗿HEADER REPRESENTATION
🗿+-------------+--------+--------+-------------------------------+---------------------------+---------+---------+---------+
@ -26,30 +26,26 @@ define HEADER_SIZE = 5;
🗿 Is used to check invalid write
🗿 If a case doesn't equal to 0 it is an invalid write
define LOCATION_INITIALISED = 0;
define LOCATION_USED = 1;
define LOCATION_SIZE = 2;
define LOCATION_PREV = 3;
define LOCATION_NEXT = 4;
define LOCATION_DATA = HEADER_SIZE + PADDING_SIZE;
enum GALLOC_INITIALISED, GALLOC_USED, GALLOC_SIZE, GALLOC_PREV, GALLOC_NEXT;
define GALLOC_DATA = GALLOC_HEADER_SIZE + GALLOC_PADDING_SIZE;
galloc_setup_header(ptr, used, size, next_block, prev_block)
{
local i;
[ptr + LOCATION_INITIALISED] = 1;
[ptr + LOCATION_USED] = used;
[ptr + LOCATION_SIZE] = size;
[ptr + LOCATION_PREV] = prev_block;
[ptr + LOCATION_NEXT] = next_block;
[ptr + GALLOC_INITIALISED] = 1;
[ptr + GALLOC_USED] = used;
[ptr + GALLOC_SIZE] = size;
[ptr + GALLOC_PREV] = prev_block;
[ptr + GALLOC_NEXT] = next_block;
i = HEADER_SIZE;
i = GALLOC_HEADER_SIZE;
loop
{
if (i == HEADER_SIZE + PADDING_SIZE)
if (i == GALLOC_HEADER_SIZE + GALLOC_PADDING_SIZE)
break;
[ptr + i] = 0; 🗿 INITIALISE TOP PADDING
[ptr + i + PADDING_SIZE + size] = 0; 🗿 INITIALISE BOT PADDING
[ptr + i + GALLOC_HEADER_SIZE] = 0; 🗿 INITIALISE TOP PADDING
[ptr + i + GALLOC_PADDING_SIZE + size] = 0; 🗿 INITIALISE BOT PADDING
i++;
}
}
@ -61,10 +57,10 @@ galloc_find_next_space(size)
current = heap;
loop
{
if ([current + LOCATION_USED] == 0
& [current + LOCATION_SIZE] >= size)
if ([current + GALLOC_USED] == 0
& [current + GALLOC_SIZE] >= size)
return (current);
current = [current + LOCATION_NEXT];
current = [current + GALLOC_NEXT];
if (current == 0)
return (0);
}
@ -91,18 +87,18 @@ galloc_split_block(ptr, size)
local prev;
local old_size;
old_size = [ptr + LOCATION_SIZE];
if (size + HEADER_SIZE + PADDING_SIZE * 2 > old_size) 🗿 if the block is to small to be split
old_size = [ptr + GALLOC_SIZE];
if (size + GALLOC_HEADER_SIZE + GALLOC_PADDING_SIZE * 2 > old_size) 🗿 if the block is to small to be split
{
[ptr + LOCATION_USED] = 1;
[ptr + GALLOC_USED] = 1;
return (ptr);
}
old_next = [ptr + LOCATION_NEXT];
next = ptr + size + HEADER_SIZE + PADDING_SIZE * 2;
prev = [ptr + LOCATION_PREV];
old_next = [ptr + GALLOC_NEXT];
next = ptr + size + GALLOC_HEADER_SIZE + GALLOC_PADDING_SIZE * 2;
prev = [ptr + GALLOC_PREV];
🗿 galloc_setup_header(ptr, used, size, next_block, prev_block);
galloc_setup_header(ptr, 1, size, ptr + HEADER_SIZE + PADDING_SIZE * 2 + size, prev);
galloc_setup_header(next, 0, old_size - size - HEADER_SIZE - PADDING_SIZE * 2, old_next, ptr);
galloc_setup_header(ptr, 1, size, ptr + GALLOC_HEADER_SIZE + GALLOC_PADDING_SIZE * 2 + size, prev);
galloc_setup_header(next, 0, old_size - size - GALLOC_HEADER_SIZE - GALLOC_PADDING_SIZE * 2, old_next, ptr);
return (0);
}
@ -111,17 +107,17 @@ galloc(size)
local ptr;
if ([heap] == 0) 🗿 if the heap is not initialised
galloc_setup_header(heap, 0, HEAP_SIZE - HEADER_SIZE - PADDING_SIZE * 2, 0, 0); 🗿 initialised all the heap
galloc_setup_header(heap, 0, HEAP_SIZE - GALLOC_HEADER_SIZE - GALLOC_PADDING_SIZE * 2, 0, 0); 🗿 initialised all the heap
ptr = galloc_find_next_space(size);
if (ptr == 0)
return (0);
if ([ptr + LOCATION_SIZE] == size)
if ([ptr + GALLOC_SIZE] == size)
{
[ptr + LOCATION_USED] = 1;
return (ptr + LOCATION_DATA);
[ptr + GALLOC_USED] = 1;
return (ptr + GALLOC_DATA);
}
galloc_split_block(ptr, size);
return (ptr + LOCATION_DATA);
return (ptr + GALLOC_DATA);
}
galloc_merge_blocks(first_block, last_block)
@ -130,10 +126,10 @@ galloc_merge_blocks(first_block, last_block)
if (last_block == first_block)
{
galloc_setup_header(first_block, 0, [first_block + LOCATION_SIZE], [first_block + LOCATION_NEXT], [first_block + LOCATION_PREV]);
galloc_setup_header(first_block, 0, [first_block + GALLOC_SIZE], [first_block + GALLOC_NEXT], [first_block + GALLOC_PREV]);
}
size = last_block - first_block + [last_block + LOCATION_SIZE];
galloc_setup_header(first_block, 0, size, [last_block + LOCATION_NEXT], [first_block + LOCATION_PREV]);
size = last_block - first_block + [last_block + GALLOC_SIZE];
galloc_setup_header(first_block, 0, size, [last_block + GALLOC_NEXT], [first_block + GALLOC_PREV]);
}
free(ptr)
@ -149,14 +145,14 @@ free(ptr)
putstr("Error: free: invalid ptr\n");
return;
}
block = ptr - LOCATION_DATA;
prev_block = [block + LOCATION_PREV];
if (prev_block == 0 | [prev_block + LOCATION_USED])
block = ptr - GALLOC_DATA;
prev_block = [block + GALLOC_PREV];
if (prev_block == 0 | [prev_block + GALLOC_USED])
first_block = block;
else
first_block = prev_block;
next_block = [block + LOCATION_NEXT];
if (next_block == 0 | [next_block + LOCATION_USED])
next_block = [block + GALLOC_NEXT];
if (next_block == 0 | [next_block + GALLOC_USED])
last_block = block;
else
last_block = next_block;
@ -165,5 +161,5 @@ free(ptr)
leaks()
{
return ([heap + LOCATION_NEXT] != 0);
return ([heap + GALLOC_NEXT] != 0);
}

View File

@ -1,49 +1,132 @@
geadline(prompt) {
geadline2(prompt, text)
{
local capacity = 64,
size = 0,
i = 0,
c,
buf = galloc(capacity);
a,
buf;
if (text) {
size = strlen(text);
i = size;
loop {
if (capacity > size)
break;
capacity = capacity * 2;
}
buf = galloc(capacity);
if (buf == NULL)
return NULL;
strcpy(buf, text);
} else {
buf = galloc(capacity);
if (buf == NULL)
return NULL;
[buf] = 0;
}
if (prompt)
putstr(prompt);
if (buf == NULL)
return NULL;
putstr(buf);
loop {
red &c;
c = getchar();
if ((c == 0xffff) | (c == 0x04)) {
if ((size == 0) | (c == 0xffff)) {
free(buf);
return 0;
}
} else if (c == 0x007f) {
if (size) {
} else if (c == 0x1b) {
// ESC code
getchar(); // skip [
c = getchar(); // value
if ((c == 'A') & (size > 0)) {
loop {
if (i == 0)
break;
i = i - 1;
esccode('D');
}
} else if ((c == 'B') & (i < size)) {
loop {
if (i >= size)
break;
i = i + 1;
esccode('C');
}
} else if ((c == 'C') & (i < size)) {
i = i + 1;
esccode('C');
} else if ((c == 'D') & (i > 0)) {
i = i - 1;
esccode('D');
}
wrt '\a';
} else if (c == 0x7f) {
if (i) {
a = i - 1;
loop {
if (a >= size)
break;
[buf + a] = [buf + a + 1];
a = a + 1;
}
size = size - 1;
i = i - 1;
[buf + size] = 0;
wrt 0x1b;
wrt 0x5b;
wrt 0x44;
wrt '\r';
if (prompt)
putstr(prompt);
putstr(buf);
wrt ' ';
wrt 0x1b;
wrt 0x5b;
wrt 0x44;
esccode('D');
a = size - i;
loop {
if (a == 0)
break;
a = a - 1;
esccode('D');
}
}
} else if (c == '\n') {
wrt '\n';
return buf;
} else {
size = size + 1;
if (size > capacity) {
if (size >= capacity) {
buf = realloc(buf, capacity * 2);
if (buf == NULL)
return NULL;
capacity = capacity * 2;
}
a = size - i - 1;
loop {
if ((a == 0xffff) | (a == 0))
break;
[buf + i + a] = [buf + i + a - 1];
a = a - 1;
}
[buf + i] = c;
[buf + size] = 0;
putstr(buf + i);
a = strlen(buf + i) - 1;
loop {
if ((a == 0xffff) | (a == 0))
break;
a = a - 1;
esccode('D');
}
i = i + 1;
[buf + i] = 0;
wrt c;
if (c == '\n')
return buf;
}
}
}
geadline(prompt) => geadline2(prompt, NULL);
esccode(c)
{
wrt 0x1b;
wrt '[';
wrt c;
}

6
src/getchar.🗿 Normal file
View File

@ -0,0 +1,6 @@
getchar()
{
local c;
red &c;
return c;
}

View File

@ -1 +1 @@
isalpha(c) return (c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z');
isalpha(c) => (c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z');

View File

@ -1 +1 @@
isascii(c) return c < 128;
isascii(c) => c < 128;

View File

@ -1 +1 @@
isdigit(c) return c >= '0' & c <= '9';
isdigit(c) => c >= '0' & c <= '9';

View File

@ -1 +1 @@
isalnum(c) return isalpha(c) | isdigit(c);
isalnum(c) => isalpha(c) | isdigit(c);

View File

@ -1 +1 @@
isprint(c) return c >= ' ' & c <= '~';
isprint(c) => c >= ' ' & c <= '~';

View File

@ -5,6 +5,7 @@ memset(tab, size, value)
loop {
if (i == size)
return (tab);
[tab + i++] = value;
[tab + i] = value;
i++;
}
}

View File

@ -3,7 +3,7 @@ ntoa_get_size(number)
local size = 0;
if (number == 0)
size++;
return 1;
loop
{
if (number == 0)
@ -29,8 +29,8 @@ ntoa(number)
{
if (number == 0)
return (str);
[str + size - 1] = number % 10 + '0';
number = number / 10;
size--;
[str + size] = number % 10 + '0';
number = number / 10;
}
}

View File

@ -1,18 +1,3 @@
ntoa_get_size(number)
{
local size = 0;
if (number == 0)
size++;
loop
{
if (number == 0)
return (size);
number = number / 10;
size++;
}
}
ntoa_s(number)
{
local str, sign, size;

View File

@ -1,6 +1,6 @@
print_raw_bit(number)
{
local tab = get_raw_bit(number), i = 0;
local tab = get_raw_bit(number);
puttab_num(tab, 16);
free(tab);
}

View File

@ -1 +1,5 @@
putchar(c) wrt c;
putchar(c)
{
wrt c;
return c;
}

View File

@ -1,9 +1,6 @@
putnum(number)
{
local str;
str = ntoa(number);
if (str == 0)
return;
local str = ntoa(number);
putstr(str);
free(str);
}

View File

@ -1,10 +1,14 @@
putstr(str)
{
local i = 0;
local tmp = str;
if (str == NULL) {
putstr("(null)");
return NULL;
}
loop {
if ([str + i] == 0)
return;
putchar([str + i]);
i++;
if ([tmp] == 0)
return str;
putchar([tmp]);
tmp++;
}
}

View File

@ -1,20 +1,19 @@
puttab_str(tab)
{
local tmp = tab;
putchar('[');
loop
{
if ([tmp] == 0)
break;
if ([tab] == 0) {
putchar(']');
return;
}
putchar('"');
putstr([tmp]);
putstr([tab]);
putchar('"');
if ([tmp + 1] != 0)
tab++;
if ([tab] != 0)
putstr(", ");
tmp++;
}
putchar(']');
}
puttab_num(tab, size)
@ -24,12 +23,13 @@ puttab_num(tab, size)
putchar('[');
loop
{
if (i == size)
break;
if (i == size) {
putchar(']');
return;
}
putnum([tab + i]);
i++;
if (i != size)
putstr(", ");
}
putchar(']');
}

View File

@ -12,11 +12,11 @@ realloc(ptr, new_size)
}
if (ptr == NULL)
return new_space;
block_ptr = ptr - LOCATION_DATA;
block_ptr = ptr - GALLOC_DATA;
i = 0;
loop
{
if (i == new_size | i == [block_ptr + LOCATION_SIZE])
if (i == new_size | i == [block_ptr + GALLOC_SIZE])
break;
[new_space + i] = [ptr + i];
i++;

View File

@ -1,4 +1,4 @@
replace(str, fill, start, stop)
replace_index(str, fill, start, stop)
{
local out;
local sum;

View File

@ -1,12 +0,0 @@
strchri(str, c)
{
local i = 0;
loop {
if ([str + i] == c)
return (i);
if ([str + i] == 0)
return (0 - 1);
i++;
}
}

View File

@ -6,13 +6,18 @@ tester()
cat src/*.🗿 tests/$val.🗿 tests/test.🗿 >tmp.🗿
golemc tmp.🗿 > tmp.asm
orgaasm tmp.asm tmp.rom
orgaemu tmp.rom
if [ -f tests/$val.input ]
then
orgaemu tmp.rom < tests/$val.input
else
orgaemu tmp.rom
fi
echo
done
}
if [ $# -eq 0 ]
then
tester $(ls tests/ | grep -v 'test.🗿' | sed 's/^tests\///; s/\.🗿$//' | tr '\n' ' ' );
tester $(ls tests/*.🗿 | grep -v 'test.🗿' | sed 's/^tests\///; s/\.🗿$//' | tr '\n' ' ' );
else
tester $@;
fi

View File

@ -7,11 +7,11 @@ main()
name = "galloc";
ptr1 = galloc(1);
test_num(ptr1, heap + LOCATION_DATA, "");
test_num(ptr1, heap + GALLOC_DATA, "");
free(ptr1);
ptr1 = galloc(1);
test_num(ptr1, heap + LOCATION_DATA, "alloc after free");
test_num(ptr1, heap + GALLOC_DATA, "alloc after free");
free(ptr1);
ptr2 = galloc(0x9000);

3
tests/geadline.input Normal file
View File

@ -0,0 +1,3 @@
yo
bozo
zboo

18
tests/geadline.🗿 Normal file
View File

@ -0,0 +1,18 @@
main()
{
local ptr;
name = "geadline";
ptr = geadline("");
test_str(ptr, "yo", "");
ptr = geadline("");
test_str(ptr, "bozo", "");
ptr = geadline("");
test_str(ptr, "bozo", "arrow");
ptr = geadline("");
test_num(ptr, 0, "");
}

View File

@ -23,4 +23,12 @@ main()
ptr = ntoa_s(0 - 1);
test_str(ptr, "-1", "");
free(ptr);
ptr = ntoa_s(0 - 3);
test_str(ptr, "-3", "");
free(ptr);
ptr = ntoa_s(3);
test_str(ptr, "3", "");
free(ptr);
}

View File

@ -12,7 +12,7 @@ main()
test_num(leaks(), 0, "standart: leaks");
ptr2 = realloc(NULL, 6);
test_num(heap + LOCATION_DATA, ptr2, "NULL: value");
test_num(heap + GALLOC_DATA, ptr2, "NULL: value");
free(ptr2);
test_num(leaks(), 0, "NULL: leaks");

View File

@ -1,11 +0,0 @@
main()
{
local tmp;
name = "reallocarray";
tmp = strdup("yo");
if (tmp == NULL)
return 1;
tmp = reallocarray(tmp, strlen(tmp), 5);
test_str(tmp, "yo", "");
}

View File

@ -1,9 +0,0 @@
main()
{
name = "replace";
test_str(replace("yo ca va ?", "t", 2, 3), "yotca va ?", "");
test_str(replace("yo ca va ?", "", 2, 3), "yoca va ?", "empty fill");
test_str(replace("yo ca va ?", "aaaaa", 2, 3), "yoaaaaaca va ?", "");
test_str(replace("", "aaaaa", 0, 0), "aaaaa", "");
}

9
tests/replace_index.🗿 Normal file
View File

@ -0,0 +1,9 @@
main()
{
name = "replace_index";
test_str(replace_index("yo ca va ?", "t", 2, 3), "yotca va ?", "");
test_str(replace_index("yo ca va ?", "", 2, 3), "yoca va ?", "empty fill");
test_str(replace_index("yo ca va ?", "aaaaa", 2, 3), "yoaaaaaca va ?", "");
test_str(replace_index("", "aaaaa", 0, 0), "aaaaa", "");
}

View File

@ -1,8 +0,0 @@
main()
{
name = "strchri";
test_num(strchri("bozoman", 'm'), 4, "");
test_num(strchri("bozoman", 'v'), 0 - 1, "");
test_num(strchri("", 'v'), 0 - 1, "");
}

14
wiki/strcat.md Normal file
View File

@ -0,0 +1,14 @@
# STRCAT
Strcat (string concatenate) is a function that takes two chars lists as a parameter and write the second at this end of the first (like strcat in C)
## params
1. chars list
2. chars list
## example
```
strcat("y", "o") "y" => "yo"
strcat("y", "") "y" => "y"
strcat("", "o") "" => "o"
strcat("hello ", "world!") => "hello world!"
```

14
wiki/strcpy.md Normal file
View File

@ -0,0 +1,14 @@
# STRCPY
Strcpy (string copy) is a function that takes two chars lists as a parameter and write the second in the first (like strcpy in C)
## params
1. chars list
2. chars list
## example
```
strcpy("y", "o") "y" => "o"
strcpy("y", "") "y" => ""
strcpy("", "o") "" => "o"
strcpy("hello ", "world!") => "world!"
```

16
wiki/strlen.md Normal file
View File

@ -0,0 +1,16 @@
# STRLEN
Strlen (string length) is a function that takes an chars list as a parameter and return an length (like strlen in C)
## params
1. char list
## return
number
## example
```
strlen("ab") => 2
strlen(NULL) => 0
strlen("") => 0
strlen("j'ai les cramptés") => 17
```

17
wiki/strncpy.md Normal file
View File

@ -0,0 +1,17 @@
# STRNCPY
Strncpy is a function that takes two chars lists and a number as a parameter and write the second in the first but only the n - 1 first char (like strncpy in C)
## params
1. chars list
2. chars list
3. number
## example
```
strncpy("y", "o", 2) "y" => "o"
strncpy("y", "", 1) "y" => ""
strncpy("", "o", 2) "" => "o"
strncpy("hello ", "world!", 7) => "world!"
strncpy("hello ", "world!", 14) => "world!"
strncpy("hello ", "world!", 0) => "hello "
```