From 29c3992343db30013f20f409346b901ac6d8d846 Mon Sep 17 00:00:00 2001 From: kdx Date: Sun, 18 Jun 2023 16:15:44 +0200 Subject: [PATCH] use postfix and variable initialisation --- src/atoi.🗿 | 14 ++++++-------- src/itoa.🗿 | 3 +-- src/memset.🗿 | 7 +++---- src/putchar.🗿 | 4 +--- src/putstr.🗿 | 5 ++--- src/strcat.🗿 | 11 +++++------ src/strchr.🗿 | 6 +++--- src/strcmp.🗿 | 6 ++---- src/strcpy.🗿 | 6 +++--- src/strlen.🗿 | 6 +++--- src/strncmp.🗿 | 4 ++-- src/strncpy.🗿 | 6 +++--- 12 files changed, 34 insertions(+), 44 deletions(-) diff --git a/src/atoi.🗿 b/src/atoi.🗿 index 9d37aa5..207c6ca 100644 --- a/src/atoi.🗿 +++ b/src/atoi.🗿 @@ -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); diff --git a/src/itoa.🗿 b/src/itoa.🗿 index 81a562e..8a4f92d 100644 --- a/src/itoa.🗿 +++ b/src/itoa.🗿 @@ -1,8 +1,7 @@ itoa_get_size(number) { - local size; + local size = 0; - size = 0; if (number == 0) size++; loop diff --git a/src/memset.🗿 b/src/memset.🗿 index 4d57e7b..a654035 100644 --- a/src/memset.🗿 +++ b/src/memset.🗿 @@ -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; } } diff --git a/src/putchar.🗿 b/src/putchar.🗿 index 7514988..ef07773 100644 --- a/src/putchar.🗿 +++ b/src/putchar.🗿 @@ -1,3 +1 @@ -putchar(c){ - wrt c; -} +putchar(c) wrt c; diff --git a/src/putstr.🗿 b/src/putstr.🗿 index b0d64ae..3fd0f4a 100644 --- a/src/putstr.🗿 +++ b/src/putstr.🗿 @@ -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++; } } diff --git a/src/strcat.🗿 b/src/strcat.🗿 index 26c97f9..bba521c 100644 --- a/src/strcat.🗿 +++ b/src/strcat.🗿 @@ -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++; } } diff --git a/src/strchr.🗿 b/src/strchr.🗿 index c778d15..0bc990e 100644 --- a/src/strchr.🗿 +++ b/src/strchr.🗿 @@ -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++; } } diff --git a/src/strcmp.🗿 b/src/strcmp.🗿 index f5635a1..e59643a 100644 --- a/src/strcmp.🗿 +++ b/src/strcmp.🗿 @@ -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++; diff --git a/src/strcpy.🗿 b/src/strcpy.🗿 index 84b80f1..b6da2b2 100644 --- a/src/strcpy.🗿 +++ b/src/strcpy.🗿 @@ -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++; } } diff --git a/src/strlen.🗿 b/src/strlen.🗿 index f7d9911..5d72e92 100644 --- a/src/strlen.🗿 +++ b/src/strlen.🗿 @@ -1,9 +1,9 @@ strlen(str) { - local i; - i = 0; + local i = 0; + loop { if ([str + i] == 0) return (i); - i = i + 1; + i++; } } diff --git a/src/strncmp.🗿 b/src/strncmp.🗿 index fdadccb..72aec94 100644 --- a/src/strncmp.🗿 +++ b/src/strncmp.🗿 @@ -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++; } diff --git a/src/strncpy.🗿 b/src/strncpy.🗿 index 7c13477..28c477a 100644 --- a/src/strncpy.🗿 +++ b/src/strncpy.🗿 @@ -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++; } }