ref: 44eba0535148291926a0cc4bb926ce32c0d2385f
parent: 8f521e6db49764583e5ba4391c0d798393e2082e
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Feb 5 22:17:51 EST 2025
more bool
--- a/src/print.c
+++ b/src/print.c
@@ -182,18 +182,18 @@
);
}
-static int
+static bool
smallp(value_t v)
{
if(tinyp(v))
- return 1;
+ return true;
if(fl_isnumber(v))
- return 1;
+ return true;
if(iscons(v)){
if(tinyp(car_(v)) &&
(tinyp(cdr_(v)) || (iscons(cdr_(v)) && tinyp(car_(cdr_(v))) && cdr_(cdr_(v)) == FL_nil)))
- return 1;
- return 0;
+ return true;
+ return false;
}
if(isvector(v)){
size_t s = vector_size(v);
@@ -202,7 +202,7 @@
(tinyp(vector_elt(v, 0)) && (s == 1 || (s == 2 && tinyp(vector_elt(v, 1)))))
);
}
- return 0;
+ return false;
}
static int
@@ -257,7 +257,7 @@
return (head == FL_definesym || head == FL_defmacrosym) && !allsmallp(cdr_(v));
}
-static int
+static bool
indentevery(value_t v)
{
// indent before every subform of a special form, unless every
@@ -264,13 +264,13 @@
// subform is "small"
value_t c = car_(v);
if(c == FL_lambda || c == FL_setqsym)
- return 0;
+ return false;
//if(c == FL(IF)) // TODO: others
// return !allsmallp(cdr_(v));
- return 0;
+ return false;
}
-static int
+static bool
blockindent(value_t v)
{
// in this case we switch to block indent mode, where the head
@@ -301,8 +301,9 @@
}
int startpos = FL(hpos);
outc(f, '(');
- int newindent = FL(hpos), blk = blockindent(v);
- int lastv, n = 0, si, ind, est, always = 0, nextsmall, thistiny;
+ int newindent = FL(hpos);
+ int lastv, n = 0, si, ind, est, nextsmall, thistiny;
+ bool always = false, blk = blockindent(v);
if(!blk)
always = indentevery(v);
value_t head = car_(v);
@@ -376,7 +377,7 @@
static void cvalue_print(ios_t *f, value_t v);
-static int
+static bool
print_circle_prefix(ios_t *f, value_t v)
{
value_t label;
@@ -383,13 +384,13 @@
if((label = (value_t)ptrhash_get(&FL(printconses), (void*)v)) != (value_t)HT_NOTFOUND){
if(!ismarked(v)){
FL(hpos) += ios_printf(f, "#%"PRIdPTR"#", (intptr_t)numval(label));
- return 1;
+ return true;
}
FL(hpos) += ios_printf(f, "#%"PRIdPTR"=", (intptr_t)numval(label));
}
if(ismanaged(v))
unmark_cons(v);
- return 0;
+ return false;
}
void
--- a/src/utf8.c
+++ b/src/utf8.c
@@ -220,7 +220,7 @@
length is in bytes, since without knowing whether the string is valid
it's hard to know how many characters there are! */
-int
+bool
u8_isvalid(const char *str, int length)
{
const uint8_t *p, *pend = (const uint8_t*)str + length;
@@ -232,16 +232,16 @@
if(c < 128)
continue;
if((c & 0xc0) != 0xc0)
- return 0;
+ return false;
ab = trailingBytesForUTF8[c];
if(length < ab)
- return 0;
+ return false;
length -= ab;
p++;
/* Check top bits in the second byte */
if((*p & 0xc0) != 0x80)
- return 0;
+ return false;
/* Check for overlong sequences for each different length */
switch(ab){
@@ -248,31 +248,31 @@
/* Check for xx00 000x */
case 1:
if((c & 0x3e) == 0)
- return 0;
+ return false;
continue; /* We know there aren't any more bytes to check */
/* Check for 1110 0000, xx0x xxxx */
case 2:
if(c == 0xe0 && (*p & 0x20) == 0)
- return 0;
+ return false;
break;
/* Check for 1111 0000, xx00 xxxx */
case 3:
if(c == 0xf0 && (*p & 0x30) == 0)
- return 0;
+ return false;
break;
/* Check for 1111 1000, xx00 0xxx */
case 4:
if(c == 0xf8 && (*p & 0x38) == 0)
- return 0;
+ return false;
break;
/* Check for leading 0xfe or 0xff and then for 1111 1100, xx00 00xx */
case 5:
if(c == 0xfe || c == 0xff || (c == 0xfc && (*p & 0x3c) == 0))
- return 0;
+ return false;
break;
}
@@ -279,19 +279,19 @@
/* Check for valid bytes after the 2nd, if any; all must start 10 */
while(--ab > 0)
if((*(++p) & 0xc0) != 0x80)
- return 0;
+ return false;
}
- return 1;
+ return true;
}
-int
+void
u8_reverse(char *dest, char *src, size_t len)
{
size_t si, di;
if(len == 0)
- return 0;
+ return;
dest[di = len] = '\0';
for(si = 0; si < len;){
@@ -321,5 +321,4 @@
break;
}
}
- return 0;
}
--- a/src/utf8.h
+++ b/src/utf8.h
@@ -52,8 +52,8 @@
ssize_t u8_strwidth(const char *s, ssize_t n) fl_purefn;
/* determine whether a sequence of bytes is valid UTF-8. length is in bytes */
-int u8_isvalid(const char *str, int length) fl_purefn;
+bool u8_isvalid(const char *str, int length) fl_purefn;
/* reverse a UTF-8 string. len is length in bytes. dest and src must both
be allocated to at least len+1 bytes. returns 1 for error, 0 otherwise */
-int u8_reverse(char *dest, char *src, size_t len);
+void u8_reverse(char *dest, char *src, size_t len);