use postfix and variable initialisation #1

Merged
starnakin merged 1 commits from kdx/IronGOLEM:master into master 2023-06-18 10:23:20 -04:00
12 changed files with 34 additions and 44 deletions
Showing only changes of commit 29c3992343 - Show all commits

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,12 +2,12 @@ strncmp(s1, s2, n)
{ {
local i; local i;
if (n == 0) if (n-- == 0)
return (0); return (0);
i = 0; i = 0;
loop 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]); return ([s1 + i] - [s2 + i]);
i++; i++;
} }

View File

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