forked from starnakin/IronGOLEM
Compare commits
32 Commits
6051375f6a
...
master
Author | SHA1 | Date | |
---|---|---|---|
e9bf776069 | |||
4bd9f50bd4 | |||
cc965024d6 | |||
2421c51116 | |||
78bc62c044 | |||
57de93e799 | |||
9a23536491 | |||
54370e872e | |||
106d2da5a0 | |||
c41ebf6ff5 | |||
a84415a953 | |||
470b97446b | |||
09e0d32c15 | |||
2b97d38b7e | |||
cb41e69bdb | |||
cc53b0cda5 | |||
a432fd32c5 | |||
15d00356e4 | |||
c4ce5b8566 | |||
1452a70b85 | |||
575ed7aa64 | |||
46d7e9c85c | |||
ee80b05d10 | |||
2fab31d822 | |||
a7e050c351 | |||
a39e4a780d | |||
0c782738cc | |||
1a1251b512 | |||
d3e788868a | |||
5dcace0cbe | |||
85aeaebc7a | |||
3443ed76e8 |
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
tmp.rom
|
IronGolem.asm
|
||||||
tmp.asm
|
IronGolem.🗿
|
||||||
tmp.🗿
|
tmp.*
|
||||||
|
4
run.sh
4
run.sh
@ -1,4 +1,4 @@
|
|||||||
cat src/* >tmp.🗿
|
cat src/* > IronGolem.🗿
|
||||||
golemc tmp.🗿 >tmp.asm
|
golemc IronGolem.🗿 > IronGolem.asm
|
||||||
# orgaasm tmp.asm tmp.rom
|
# orgaasm tmp.asm tmp.rom
|
||||||
# orgaemu tmp.rom
|
# orgaemu tmp.rom
|
||||||
|
14
src/aton.🗿
14
src/aton.🗿
@ -1,18 +1,16 @@
|
|||||||
aton(str)
|
aton(str)
|
||||||
{
|
{
|
||||||
local i = 0;
|
|
||||||
local out = 0;
|
local out = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if ([str + i] != '+')
|
if ([str] != '+')
|
||||||
break;
|
break;
|
||||||
i++;
|
str++;
|
||||||
}
|
}
|
||||||
loop {
|
loop {
|
||||||
if ([str + i] == 0 | isdigit([str + i]) == 0)
|
if ([str] == 0 | isdigit([str]) == 0)
|
||||||
break;
|
return out;
|
||||||
out = out * 10 + [str + i] - '0';
|
out = out * 10 + [str] - '0';
|
||||||
i++;
|
str++;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
18
src/aton_s.🗿
18
src/aton_s.🗿
@ -1,23 +1,19 @@
|
|||||||
aton_s(str)
|
aton_s(str)
|
||||||
{
|
{
|
||||||
local i = 0;
|
|
||||||
local sign = 0;
|
local sign = 0;
|
||||||
local out = 0;
|
local out = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if ([str + i] == '-')
|
if ([str] == '-')
|
||||||
sign = sign == 0;
|
sign = sign == 0;
|
||||||
else if ([str + i] != '+')
|
else if ([str] != '+')
|
||||||
break;
|
break;
|
||||||
i++;
|
str++;
|
||||||
}
|
}
|
||||||
loop {
|
loop {
|
||||||
if ([str + i] == 0 | isdigit([str + i]) == 0)
|
if ([str] == 0 | isdigit([str]) == 0)
|
||||||
break;
|
return (sign * (0 - out)) | ((sign == 0) * out);
|
||||||
out = out * 10 + [str + i] - '0';
|
out = out * 10 + [str] - '0';
|
||||||
i++;
|
str++;
|
||||||
}
|
}
|
||||||
if (sign)
|
|
||||||
return (0 - out);
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
bzero(tab, size) memset(tab, size, 0);
|
bzero(tab, size) => memset(tab, size, 0);
|
||||||
|
11
src/contain_only.🗿
Normal file
11
src/contain_only.🗿
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
contain_only(to_big, to_find)
|
||||||
|
{
|
||||||
|
loop
|
||||||
|
{
|
||||||
|
if ([to_big] == 0)
|
||||||
|
return 1;
|
||||||
|
if (strchr(to_find, [to_big]) == 0)
|
||||||
|
return 0;
|
||||||
|
to_big++;
|
||||||
|
}
|
||||||
|
}
|
@ -9,5 +9,5 @@ free_tab(tab)
|
|||||||
free([tmp]);
|
free([tmp]);
|
||||||
tmp++;
|
tmp++;
|
||||||
}
|
}
|
||||||
free(tab);
|
return free(tab);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
define HEAP_SIZE = 0x8000;
|
define HEAP_SIZE = 0x4000;
|
||||||
global heap[HEAP_SIZE] = 0;
|
global heap[HEAP_SIZE] = 0;
|
||||||
|
|
||||||
define PADDING_SIZE = 4;
|
define PADDING_SIZE = 4;
|
||||||
@ -26,11 +26,7 @@ define HEADER_SIZE = 5;
|
|||||||
🗿 Is used to check invalid write
|
🗿 Is used to check invalid write
|
||||||
🗿 If a case doesn't equal to 0 it is an invalid write
|
🗿 If a case doesn't equal to 0 it is an invalid write
|
||||||
|
|
||||||
define LOCATION_INITIALISED = 0;
|
enum LOCATION_INITIALISED, LOCATION_USED, LOCATION_SIZE, LOCATION_PREV, LOCATION_NEXT;
|
||||||
define LOCATION_USED = 1;
|
|
||||||
define LOCATION_SIZE = 2;
|
|
||||||
define LOCATION_PREV = 3;
|
|
||||||
define LOCATION_NEXT = 4;
|
|
||||||
define LOCATION_DATA = HEADER_SIZE + PADDING_SIZE;
|
define LOCATION_DATA = HEADER_SIZE + PADDING_SIZE;
|
||||||
|
|
||||||
galloc_setup_header(ptr, used, size, next_block, prev_block)
|
galloc_setup_header(ptr, used, size, next_block, prev_block)
|
||||||
|
121
src/geadline.🗿
121
src/geadline.🗿
@ -1,49 +1,132 @@
|
|||||||
geadline(prompt) {
|
geadline2(prompt, text)
|
||||||
|
{
|
||||||
local capacity = 64,
|
local capacity = 64,
|
||||||
size = 0,
|
size = 0,
|
||||||
i = 0,
|
i = 0,
|
||||||
c,
|
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)
|
if (prompt)
|
||||||
putstr(prompt);
|
putstr(prompt);
|
||||||
if (buf == NULL)
|
putstr(buf);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
red &c;
|
c = getchar();
|
||||||
if ((c == 0xffff) | (c == 0x04)) {
|
if ((c == 0xffff) | (c == 0x04)) {
|
||||||
if ((size == 0) | (c == 0xffff)) {
|
if ((size == 0) | (c == 0xffff)) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (c == 0x007f) {
|
} else if (c == 0x1b) {
|
||||||
if (size) {
|
// 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;
|
size = size - 1;
|
||||||
i = i - 1;
|
i = i - 1;
|
||||||
[buf + size] = 0;
|
[buf + size] = 0;
|
||||||
|
|
||||||
wrt 0x1b;
|
wrt '\r';
|
||||||
wrt 0x5b;
|
if (prompt)
|
||||||
wrt 0x44;
|
putstr(prompt);
|
||||||
|
putstr(buf);
|
||||||
wrt ' ';
|
wrt ' ';
|
||||||
wrt 0x1b;
|
esccode('D');
|
||||||
wrt 0x5b;
|
a = size - i;
|
||||||
wrt 0x44;
|
loop {
|
||||||
|
if (a == 0)
|
||||||
|
break;
|
||||||
|
a = a - 1;
|
||||||
|
esccode('D');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else if (c == '\n') {
|
||||||
|
wrt '\n';
|
||||||
|
return buf;
|
||||||
} else {
|
} else {
|
||||||
size = size + 1;
|
size = size + 1;
|
||||||
if (size > capacity) {
|
if (size >= capacity) {
|
||||||
buf = reallocarray(buf, capacity, capacity * 2);
|
buf = realloc(buf, capacity * 2);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
capacity = capacity * 2;
|
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 + 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;
|
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;
|
||||||
|
}
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
define GET_LINE_BUFFER=100;
|
|
||||||
|
|
||||||
get_line()
|
|
||||||
{
|
|
||||||
local tmp;
|
|
||||||
local out;
|
|
||||||
local c;
|
|
||||||
local i;
|
|
||||||
|
|
||||||
out = NULL;
|
|
||||||
i = 0;
|
|
||||||
loop
|
|
||||||
{
|
|
||||||
if (i % GET_LINE_BUFFER == 0)
|
|
||||||
{
|
|
||||||
tmp = reallocarray(out, i, i + GET_LINE_BUFFER + 1);
|
|
||||||
if (tmp == NULL)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
red &c;
|
|
||||||
if (c == 0xffff)
|
|
||||||
return NULL;
|
|
||||||
[tmp + i] = c;
|
|
||||||
i++;
|
|
||||||
if (c == '\n')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
[tmp + i] = 0;
|
|
||||||
out = strdup(tmp);
|
|
||||||
free(tmp);
|
|
||||||
return out;
|
|
||||||
}
|
|
6
src/getchar.🗿
Normal file
6
src/getchar.🗿
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
getchar()
|
||||||
|
{
|
||||||
|
local c;
|
||||||
|
red &c;
|
||||||
|
return c;
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
isalpha(c) return (c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z');
|
isalpha(c) => (c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z');
|
||||||
|
@ -1 +1 @@
|
|||||||
isascii(c) return c < 128;
|
isascii(c) => c < 128;
|
||||||
|
@ -1 +1 @@
|
|||||||
isdigit(c) return c >= '0' & c <= '9';
|
isdigit(c) => c >= '0' & c <= '9';
|
||||||
|
@ -1 +1 @@
|
|||||||
isalnum(c) return isalpha(c) | isdigit(c);
|
isalnum(c) => isalpha(c) | isdigit(c);
|
||||||
|
@ -1 +1 @@
|
|||||||
isprint(c) return c >= ' ' & c <= '~';
|
isprint(c) => c >= ' ' & c <= '~';
|
||||||
|
@ -5,6 +5,7 @@ memset(tab, size, value)
|
|||||||
loop {
|
loop {
|
||||||
if (i == size)
|
if (i == size)
|
||||||
return (tab);
|
return (tab);
|
||||||
[tab + i++] = value;
|
[tab + i] = value;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ ntoa_get_size(number)
|
|||||||
local size = 0;
|
local size = 0;
|
||||||
|
|
||||||
if (number == 0)
|
if (number == 0)
|
||||||
size++;
|
return 1;
|
||||||
loop
|
loop
|
||||||
{
|
{
|
||||||
if (number == 0)
|
if (number == 0)
|
||||||
@ -29,8 +29,8 @@ ntoa(number)
|
|||||||
{
|
{
|
||||||
if (number == 0)
|
if (number == 0)
|
||||||
return (str);
|
return (str);
|
||||||
[str + size - 1] = number % 10 + '0';
|
|
||||||
number = number / 10;
|
|
||||||
size--;
|
size--;
|
||||||
|
[str + size] = number % 10 + '0';
|
||||||
|
number = number / 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
src/ntoa_s.🗿
15
src/ntoa_s.🗿
@ -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)
|
ntoa_s(number)
|
||||||
{
|
{
|
||||||
local str, sign, size;
|
local str, sign, size;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
print_raw_bit(number)
|
print_raw_bit(number)
|
||||||
{
|
{
|
||||||
local tab = get_raw_bit(number), i = 0;
|
local tab = get_raw_bit(number);
|
||||||
puttab_num(tab, 16);
|
puttab_num(tab, 16);
|
||||||
free(tab);
|
free(tab);
|
||||||
}
|
}
|
||||||
|
@ -1 +1,5 @@
|
|||||||
putchar(c) wrt c;
|
putchar(c)
|
||||||
|
{
|
||||||
|
wrt c;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
putnum(number)
|
putnum(number)
|
||||||
{
|
{
|
||||||
local str;
|
local str = ntoa(number);
|
||||||
str = ntoa(number);
|
|
||||||
if (str == 0)
|
|
||||||
return;
|
|
||||||
putstr(str);
|
putstr(str);
|
||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
|
14
src/putstr.🗿
14
src/putstr.🗿
@ -1,10 +1,14 @@
|
|||||||
putstr(str)
|
putstr(str)
|
||||||
{
|
{
|
||||||
local i = 0;
|
local tmp = str;
|
||||||
|
if (str == NULL) {
|
||||||
|
putstr("(null)");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
loop {
|
loop {
|
||||||
if ([str + i] == 0)
|
if ([tmp] == 0)
|
||||||
return;
|
return str;
|
||||||
putchar([str + i]);
|
putchar([tmp]);
|
||||||
i++;
|
tmp++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
src/puttab.🗿
22
src/puttab.🗿
@ -1,20 +1,19 @@
|
|||||||
puttab_str(tab)
|
puttab_str(tab)
|
||||||
{
|
{
|
||||||
local tmp = tab;
|
|
||||||
|
|
||||||
putchar('[');
|
putchar('[');
|
||||||
loop
|
loop
|
||||||
{
|
{
|
||||||
if ([tmp] == 0)
|
if ([tab] == 0) {
|
||||||
break;
|
putchar(']');
|
||||||
|
return;
|
||||||
|
}
|
||||||
putchar('"');
|
putchar('"');
|
||||||
putstr([tmp]);
|
putstr([tab]);
|
||||||
putchar('"');
|
putchar('"');
|
||||||
if ([tmp + 1] != 0)
|
tab++;
|
||||||
|
if ([tab] != 0)
|
||||||
putstr(", ");
|
putstr(", ");
|
||||||
tmp++;
|
|
||||||
}
|
}
|
||||||
putchar(']');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
puttab_num(tab, size)
|
puttab_num(tab, size)
|
||||||
@ -24,12 +23,13 @@ puttab_num(tab, size)
|
|||||||
putchar('[');
|
putchar('[');
|
||||||
loop
|
loop
|
||||||
{
|
{
|
||||||
if (i == size)
|
if (i == size) {
|
||||||
break;
|
putchar(']');
|
||||||
|
return;
|
||||||
|
}
|
||||||
putnum([tab + i]);
|
putnum([tab + i]);
|
||||||
i++;
|
i++;
|
||||||
if (i != size)
|
if (i != size)
|
||||||
putstr(", ");
|
putstr(", ");
|
||||||
}
|
}
|
||||||
putchar(']');
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,26 @@
|
|||||||
reallocarray(ptr, nmemb, size)
|
realloc(ptr, new_size)
|
||||||
{
|
{
|
||||||
local tmp;
|
local block_ptr;
|
||||||
local start;
|
local new_space;
|
||||||
|
local i;
|
||||||
|
|
||||||
start = ptr;
|
new_space = galloc(new_size);
|
||||||
tmp = galloc(size);
|
if (new_space == NULL)
|
||||||
if (tmp == NULL)
|
{
|
||||||
return NULL;
|
free(ptr);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
return tmp;
|
return new_space;
|
||||||
|
block_ptr = ptr - LOCATION_DATA;
|
||||||
|
i = 0;
|
||||||
loop
|
loop
|
||||||
{
|
{
|
||||||
if (start - ptr == nmemb)
|
if (i == new_size | i == [block_ptr + LOCATION_SIZE])
|
||||||
break;
|
break;
|
||||||
[tmp + start - ptr] = [start];
|
[new_space + i] = [ptr + i];
|
||||||
start++;
|
i++;
|
||||||
}
|
}
|
||||||
free(ptr);
|
free(ptr);
|
||||||
return tmp;
|
return new_space;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
replace(str, fill, start, stop)
|
replace_index(str, fill, start, stop)
|
||||||
{
|
{
|
||||||
local out;
|
local out;
|
||||||
local sum;
|
local sum;
|
10
src/strchr.🗿
10
src/strchr.🗿
@ -1,12 +1,12 @@
|
|||||||
strchr(str, c)
|
strchr(str, c)
|
||||||
{
|
{
|
||||||
local i = 0;
|
local start = str;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if ([str + i] == c)
|
if ([start] == c)
|
||||||
return (str + i);
|
return (start);
|
||||||
if ([str + i] == 0)
|
if ([start] == 0)
|
||||||
return (0);
|
return (0);
|
||||||
i++;
|
start++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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++;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,8 @@
|
|||||||
strlen(str) {
|
strlen(str) {
|
||||||
local i = 0;
|
local i = 0;
|
||||||
|
|
||||||
|
if (str == NULL)
|
||||||
|
return 0;
|
||||||
loop {
|
loop {
|
||||||
if ([str + i] == 0)
|
if ([str + i] == 0)
|
||||||
return (i);
|
return (i);
|
||||||
|
7
test.sh
7
test.sh
@ -6,7 +6,12 @@ tester()
|
|||||||
cat src/*.🗿 tests/$val.🗿 tests/test.🗿 >tmp.🗿
|
cat src/*.🗿 tests/$val.🗿 tests/test.🗿 >tmp.🗿
|
||||||
golemc tmp.🗿 > tmp.asm
|
golemc tmp.🗿 > tmp.asm
|
||||||
orgaasm tmp.asm tmp.rom
|
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
|
echo
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
7
tests/contain_only.🗿
Normal file
7
tests/contain_only.🗿
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
main()
|
||||||
|
{
|
||||||
|
name = "contain_only";
|
||||||
|
|
||||||
|
test_num(contain_only("17", "0123456789"), 1, "");
|
||||||
|
test_num(contain_only("17a", "0123456789"), 0, "");
|
||||||
|
}
|
3
tests/geadline.input
Normal file
3
tests/geadline.input
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
yo
|
||||||
|
bozo
|
||||||
|
z[Dbo[C[C[Co
|
18
tests/geadline.🗿
Normal file
18
tests/geadline.🗿
Normal 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, "");
|
||||||
|
}
|
@ -1,23 +0,0 @@
|
|||||||
define GET_LINE=0;
|
|
||||||
main()
|
|
||||||
{
|
|
||||||
local ptr;
|
|
||||||
|
|
||||||
name = "get_line";
|
|
||||||
if (GET_LINE == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
putstr("yo\n");
|
|
||||||
ptr = get_line();
|
|
||||||
test_str(ptr, "yo\n", "");
|
|
||||||
free(ptr);
|
|
||||||
|
|
||||||
putstr("ENTER\n");
|
|
||||||
ptr = get_line();
|
|
||||||
test_str(ptr, "\n", "");
|
|
||||||
free(ptr);
|
|
||||||
|
|
||||||
putstr("ctrl + D\n");
|
|
||||||
ptr = get_line();
|
|
||||||
test_num(ptr, NULL, "");
|
|
||||||
}
|
|
24
tests/realloc.🗿
Normal file
24
tests/realloc.🗿
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
main()
|
||||||
|
{
|
||||||
|
local ptr1;
|
||||||
|
local ptr2;
|
||||||
|
|
||||||
|
name = "realloc";
|
||||||
|
|
||||||
|
ptr1 = strdup("yo");
|
||||||
|
ptr2 = realloc(ptr1, 6);
|
||||||
|
test_str("yo", ptr2, "standart: value");
|
||||||
|
free(ptr2);
|
||||||
|
test_num(leaks(), 0, "standart: leaks");
|
||||||
|
|
||||||
|
ptr2 = realloc(NULL, 6);
|
||||||
|
test_num(heap + LOCATION_DATA, ptr2, "NULL: value");
|
||||||
|
free(ptr2);
|
||||||
|
test_num(leaks(), 0, "NULL: leaks");
|
||||||
|
|
||||||
|
ptr1 = strdup("bonjour");
|
||||||
|
ptr2 = realloc(ptr1, 2);
|
||||||
|
test_tab_num(ptr2, "bo", 2, "decrement size: value");
|
||||||
|
free(ptr2);
|
||||||
|
test_num(leaks(), 0, "decrement size: leaks");
|
||||||
|
}
|
@ -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", "");
|
|
||||||
}
|
|
@ -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
9
tests/replace_index.🗿
Normal 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", "");
|
||||||
|
}
|
@ -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
14
wiki/strcat.md
Normal 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
14
wiki/strcpy.md
Normal 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
16
wiki/strlen.md
Normal 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
|
||||||
|
```
|
Reference in New Issue
Block a user