diff --git a/cmp11sht.c b/cmp11sht.c index fd502bd..33fa415 100644 --- a/cmp11sht.c +++ b/cmp11sht.c @@ -1,6 +1,6 @@ /* ************************************************************************ * * cmp11sht.c, v20251221.085434 * - * Fuzzy comparison CLI — thin shell over lib11sht * + * Fuzzy comparison CLI -- thin shell over lib11sht * * * * Copyright (C) 2025 by Ruben Carlo Benante * * GNU GPL version 2 or later. * @@ -92,11 +92,11 @@ cmp11sht v20251221.0718 (C) 2025 by Ruben C. Benante (MIT Lic)\n\n" res = sequal_full(argv[1], argv[2], delta, &ratio, s1, LEVN_SBUFF, s2, LEVN_SBUFF); if(errno == EINVAL) - res = 3; /* error → CLI exit 3 */ + res = 3; /* error -> CLI exit 3 */ else if(res > 0) - res = 1; /* a > b → CLI exit 1 */ + res = 1; /* a > b -> CLI exit 1 */ else if(res < 0) - res = 2; /* a < b → CLI exit 2 */ + res = 2; /* a < b -> CLI exit 2 */ /* res == 0 stays 0 (equal) */ if(opt==3) printf("result: "); if(opt) printf("%d\n", res); @@ -109,9 +109,9 @@ cmp11sht v20251221.0718 (C) 2025 by Ruben C. Benante (MIT Lic)\n\n" if(opt==3) printf("cmp11sht: float\n"); res = fequal(a, b, delta); if(res > 0) - res = 1; /* a > b → CLI exit 1 */ + res = 1; /* a > b -> CLI exit 1 */ else if(res < 0) - res = 2; /* a < b → CLI exit 2 */ + res = 2; /* a < b -> CLI exit 2 */ /* res == 0 stays 0 (equal) */ if(opt==3) printf("result: "); if(opt) printf("%d\n", res); diff --git a/lib11sht.c b/lib11sht.c index e98693c..d7caadc 100644 --- a/lib11sht.c +++ b/lib11sht.c @@ -14,7 +14,7 @@ #include "lib11sht.h" -/* Internal helpers — kept private to this translation unit. */ +/* Internal helpers -- kept private to this translation unit. */ static int uselesschar(int c); /* trim is public (declared in lib11sht.h) */ static void asciify(const char *src, char *dest, size_t dest_size); @@ -111,7 +111,7 @@ static float shit11(char *s1, char *s2) return 0.0; /* one empty == no similarity */ /* Defensive cap: refuse to allocate too-large VLA. Bounds the stack - * matrix at LEVN_SBUFF × LEVN_SBUFF × sizeof(int) = ~256 KB worst case. */ + * matrix at LEVN_SBUFF * LEVN_SBUFF * sizeof(int) = ~256 KB worst case. */ if(len1 >= LEVN_SBUFF || len2 >= LEVN_SBUFF) return 0.0; /* treat as "completely dissimilar" */ @@ -218,7 +218,7 @@ static void asciify(const char *src, char *dest, size_t dest_size) "AEIOUAEIOUAEIOUAEIOUAEIOU" "aeiouaeiouaeiouaeiouaeiou" "aoCcNn123" - " "; /* NBSP → space */ + " "; /* NBSP -> space */ const char *translit[] = { "Á","É","Í","Ó","Ú", "À","È","Ì","Ò","Ù", "Ã","Ẽ","Ĩ","Õ","Ũ", "Â","Ê","Î","Ô","Û", diff --git a/lib11sht.h b/lib11sht.h index 45c87f8..16afe90 100644 --- a/lib11sht.h +++ b/lib11sht.h @@ -42,7 +42,7 @@ * 0 if equal or similar above the shold threshold * -1 if a < b alphabetically (after normalization) * +1 if a > b alphabetically (after normalization) - * On error: sets errno = EINVAL and returns 0 — see ERROR CONVENTION above. + * On error: sets errno = EINVAL and returns 0 -- see ERROR CONVENTION above. * * Parameters: * a, b input strings (NUL-terminated, may contain UTF-8 accented Latin chars). @@ -68,17 +68,17 @@ int sequal(char *a, char *b, float shold); * comparison. The Levenshtein ratio in *ratio is computed on the * normalized contents of s1 / s2 (i.e. on the possibly-truncated buffer * data), NOT on the original a / b strings. To compare without truncation, - * pass buffers at least as large as the longest input — LEVN_SBUFF (256) + * pass buffers at least as large as the longest input -- LEVN_SBUFF (256) * is the recommended floor. * - * On error: same convention as sequal — sets errno = EINVAL and returns 0; + * On error: same convention as sequal -- sets errno = EINVAL and returns 0; * *ratio, s1, s2 are not modified in that case. See ERROR CONVENTION above. */ int sequal_full(char *a, char *b, float shold, float *ratio, char *s1, size_t s1_size, char *s2, size_t s2_size); -/* Compare two floats within ±delta. +/* Compare two floats within +/-delta. * Returns: * 0 if |a - b| <= delta * -1 if a < b - delta diff --git a/makefile b/makefile index 4ede044..0af047e 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ # Copyright (C) 2026 by Prof. Dr. Ruben Carlo Benante -# levenshtein library — makefile +# levenshtein library -- makefile # # Usage: # make build both: cmp11sht (CLI) and test_lib11sht diff --git a/test_lib11sht.c b/test_lib11sht.c index 15ee99b..57880e1 100644 --- a/test_lib11sht.c +++ b/test_lib11sht.c @@ -1,4 +1,4 @@ -/* Stress tests for lib11sht — aim to break upper / lower bounds. +/* Stress tests for lib11sht -- aim to break upper / lower bounds. * Compile: gcc -Wall -Wextra -O2 test_lib11sht.c lib11sht.c -lm -o test_lib11sht * Run: ./test_lib11sht * Exit 0 if all tests pass, non-zero on first failure. @@ -64,7 +64,7 @@ int main(void) CHECK(errno == 0 && r == 0, "no errno, returns 0 (equal at boundary)"); } - /* Test 4: long input WITH accents — UTF-8 multi-byte at offset 250. + /* Test 4: long input WITH accents -- UTF-8 multi-byte at offset 250. * Should asciify each accent to ASCII, total visible chars < 256. */ { char a[400] = "", b[400] = ""; @@ -72,15 +72,15 @@ int main(void) /* Fill with 240 'a' then put "ÃÃÃÃÃÃ" (UTF-8: 0xC3 0x83 each, 12 bytes) */ for(i = 0; i < 240; i++) { a[i] = 'a'; b[i] = 'a'; } a[240] = b[240] = '\0'; - strcat(a, "ÃÃÃÃÃÃ"); /* +12 bytes UTF-8, 6 chars visible → asciify to 'AAAAAA' */ + strcat(a, "ÃÃÃÃÃÃ"); /* +12 bytes UTF-8, 6 chars visible -> asciify to 'AAAAAA' */ strcat(b, "ÃÃÃÃÃÃ"); - printf("Test 4: 240 'a' + 6×à (multi-byte near boundary)\n"); + printf("Test 4: 240 'a' + 6x A-tilde (multi-byte near boundary)\n"); errno = 0; r = sequal(a, b, 0.85); CHECK(errno == 0 && r == 0, "no errno, returns 0 (equal)"); } - /* Test 5: full-detail call with undersized buffers — this is the actual + /* Test 5: full-detail call with undersized buffers -- this is the actual * realistic break path. Pass 64-byte buffers to sequal_full. */ { char small1[64], small2[64]; @@ -99,7 +99,7 @@ int main(void) /* ----- LOWER bound tests ----- */ - /* Test 6: NULL inputs — should set errno=EINVAL and return 0 */ + /* Test 6: NULL inputs -- should set errno=EINVAL and return 0 */ { printf("Test 6: NULL inputs via sequal_full\n"); errno = 0; @@ -123,7 +123,7 @@ int main(void) CHECK(errno == EINVAL && r == 0, "NULL s2: errno=EINVAL, returns 0"); } - /* Test 7: zero-size buffers — should set errno=EINVAL */ + /* Test 7: zero-size buffers -- should set errno=EINVAL */ { printf("Test 7: zero-size buffers\n"); errno = 0; @@ -142,23 +142,23 @@ int main(void) /* single char equal */ errno = 0; r = sequal("a", "a", 0.85); - CHECK(r == 0 && errno == 0, "'a' vs 'a' → 0 (equal)"); + CHECK(r == 0 && errno == 0, "'a' vs 'a' -> 0 (equal)"); /* single char different */ errno = 0; r = sequal("a", "b", 0.85); - CHECK(r != 0 && errno == 0, "'a' vs 'b' → non-zero (different)"); + CHECK(r != 0 && errno == 0, "'a' vs 'b' -> non-zero (different)"); - /* threshold = 0.0: any non-zero similarity matches → 0 even when different */ + /* threshold = 0.0: any non-zero similarity matches -> 0 even when different */ r = sequal("hello", "world", 0.0); CHECK(r == 0, "shold=0.0 makes any non-empty pair 'match'"); - /* threshold = 1.0: only exact-after-normalize → strict strcmp */ + /* threshold = 1.0: only exact-after-normalize -> strict strcmp */ r = sequal("hello", "Hello", 1.0); CHECK(r == 0, "shold=1.0 + case-only diff still matches (normalized exact)"); r = sequal("hello", "world", 1.0); - CHECK(r != 0, "shold=1.0 + completely different → non-zero"); + CHECK(r != 0, "shold=1.0 + completely different -> non-zero"); /* whitespace-only strings */ r = sequal(" ", " ", 0.85);