use postfix and variable initialisation (#1)

This commit is contained in:
starnakin 2023-06-18 14:23:20 +00:00
commit 4f0d18ee68
12 changed files with 34 additions and 44 deletions

View File

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

View File

@ -1,8 +1,7 @@
itoa_get_size(number)
{
local size;
local size = 0;
size = 0;
if (number == 0)
size++;
loop

View File

@ -1,11 +1,10 @@
memset(tab, size, value)
{
local i;
i = 0;
local i = 0;
loop {
if (i == size)
return (tab);
[tab + i] = value;
i = i + 1;
[tab + i++] = value;
}
}

View File

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

View File

@ -1,11 +1,10 @@
putstr(str)
{
local i;
i = 0;
local i = 0;
loop {
if ([str + i] == 0)
return;
putchar([str + i]);
i = i + 1;
i++;
}
}

View File

@ -1,18 +1,17 @@
strcat(dst, src)
{
local i;
local j;
i = 0;
local i = 0;
local j = 0;
loop {
if ([dst + i] == 0)
break;
i = i + 1;
i++;
}
j = 0;
loop {
if ([src + j] == 0)
return (dst);
[dst + i + j] = [src + j];
j = j + 1;
j++;
}
}

View File

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

View File

@ -1,10 +1,8 @@
strcmp(s1, s2)
{
local i;
local i = 0;
i = 0;
loop
{
loop {
if ([s1 + i] != [s2 + i] | [s1 + i] == 0 | [s2 + i] == 0)
return ([s1 + i] - [s2 + i]);
i++;

View File

@ -1,11 +1,11 @@
strcpy(dst, src)
{
local i;
i = 0;
local i = 0;
loop {
if ([src + i] == 0)
return (dst);
[dst + i] = [src + i];
i = i + 1;
i++;
}
}

View File

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

View File

@ -2,12 +2,12 @@ strncmp(s1, s2, n)
{
local i;
if (n == 0)
if (n-- == 0)
return (0);
i = 0;
loop
{
if (i == n - 1 | [s1 + i] != [s2 + i] | [s1 + i] == 0 | [s2 + i] == 0)
if (i == n | [s1 + i] != [s2 + i] | [s1 + i] == 0 | [s2 + i] == 0)
return ([s1 + i] - [s2 + i]);
i++;
}

View File

@ -1,11 +1,11 @@
strncpy(dst, src, size)
{
local i;
i = 0;
local i = 0;
loop {
if ([src + i] == 0 | i == size)
return (dst);
[dst + i] = [src + i];
i = i + 1;
i++;
}
}