geadline: move cursor #3

Merged
starnakin merged 3 commits from kdx/IronGOLEM:master into master 2023-07-25 00:37:48 -04:00
18 changed files with 58 additions and 61 deletions
Showing only changes of commit 1452a70b85 - Show all commits

View File

@ -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;
out = out * 10 + [str + i] - '0';
i++;
}
return out; return out;
out = out * 10 + [str] - '0';
str++;
}
} }

View File

@ -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;
} }

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) contain_only(to_big, to_find)
{ {
local tmp;
tmp = to_big;
loop loop
{ {
if ([tmp] == 0) if ([to_big] == 0)
return 1; return 1;
if (strchr(to_find, [tmp]) == 0) if (strchr(to_find, [to_big]) == 0)
return 0; return 0;
tmp++; to_big++;
} }
} }

View File

@ -7,7 +7,7 @@ free_tab(tab)
if ([tmp] == 0) if ([tmp] == 0)
return; return;
free([tmp]); free([tmp]);
tmp++; tmp = tmp + 1;
} }
free(tab); return free(tab);
} }

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 { loop {
if (i == size) if (i == size)
return (tab); return (tab);
[tab + i++] = value; [tab + i] = value;
i = i + 1;
} }
} }

View File

@ -3,13 +3,13 @@ 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)
return (size); return (size);
number = number / 10; number = number / 10;
size++; size = size + 1;
} }
} }
@ -29,8 +29,8 @@ ntoa(number)
{ {
if (number == 0) if (number == 0)
return (str); return (str);
[str + size - 1] = number % 10 + '0'; size = size - 1;
[str + size] = number % 10 + '0';
number = number / 10; number = number / 10;
size--;
} }
} }

View File

@ -3,13 +3,13 @@ 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)
return (size); return (size);
number = number / 10; number = number / 10;
size++; size = size + 1;
} }
} }
@ -24,7 +24,7 @@ ntoa_s(number)
} }
size = ntoa_get_size(number); size = ntoa_get_size(number);
if (sign) if (sign)
size++; size = size + 1;
str = galloc(size + 1); str = galloc(size + 1);
if (str == 0) if (str == 0)
return (0); return (0);
@ -39,6 +39,6 @@ ntoa_s(number)
return (str); return (str);
[str + size - 1] = number % 10 + '0'; [str + size - 1] = number % 10 + '0';
number = number / 10; number = number / 10;
size--; size = size - 1;
} }
} }

View File

@ -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);
} }

View File

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

View File

@ -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);
} }

View File

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

View File

@ -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('"');
putstr([tmp]);
putchar('"');
if ([tmp + 1] != 0)
putstr(", ");
tmp++;
}
putchar(']'); putchar(']');
return;
}
putchar('"');
putstr([tab]);
putchar('"');
tab = tab + 1;
if ([tab] != 0)
putstr(", ");
}
} }
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(']');
} }