[hackers] [sbase] Use the UTF8_POINT macro in cols(1) || FRIGN

From: <git_AT_suckless.org>
Date: Thu, 10 Mar 2016 09:48:18 +0100 (CET)

commit 00b579566ac6fec6076548d5af1fb72eb5a879f2
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Mon Mar 7 20:56:15 2016 +0100
Commit: sin <sin_AT_2f30.org>
CommitDate: Thu Mar 10 08:48:09 2016 +0000

    Use the UTF8_POINT macro in cols(1)
    
    No need for libutf any more

diff --git a/README b/README
index b2070e7..8490a9a 100644
--- a/README
+++ b/README
_AT_@ -21,7 +21,7 @@ The following tools are implemented:
 0=*|x chroot .
 0=*|o cksum .
 0=*|o cmp .
- #*|x cols .
+0#*|x cols .
 0=*|o comm .
 0=*|o cp (-i)
 0=*|x cron .
diff --git a/cols.c b/cols.c
index ae7d5b2..428cd79 100644
--- a/cols.c
+++ b/cols.c
_AT_@ -9,7 +9,6 @@
 #include <unistd.h>
 
 #include "text.h"
-#include "utf.h"
 #include "util.h"
 
 static void
_AT_@ -63,9 +62,10 @@ main(int argc, char *argv[])
         }
 
         for (i = 0; i < b.nlines; i++) {
- /* TODO: fix libutf to run utflen on a memory chunk
- * of given size to also handle embedded NULs */
- len = utflen(b.lines[i].data);
+ for (j = 0, len = 0; j < b.lines[i].len; j++) {
+ if (UTF8_POINT(b.lines[i].data[j]))
+ len++;
+ }
                 if (len && b.lines[i].data[b.lines[i].len - 1] == '\n') {
                         b.lines[i].data[--(b.lines[i].len)] = '\0';
                         len--;
_AT_@ -79,9 +79,10 @@ main(int argc, char *argv[])
 
         for (i = 0; i < rows; i++) {
                 for (j = 0; j < cols && i + j * rows < b.nlines; j++) {
- /* TODO: fix libutf to run utflen on a memory chunk
- * of given size to also handle embedded NULs */
- len = utflen(b.lines[i + j * rows].data);
+ for (k = 0, len = 0; k < b.lines[i + j * rows].len; k++) {
+ if (UTF8_POINT(b.lines[i + j * rows].data[k]))
+ len++;
+ }
                         fwrite(b.lines[i + j * rows].data, 1,
                                b.lines[i + j * rows].len, stdout);
                         if (j < cols - 1)
Received on Thu Mar 10 2016 - 09:48:18 CET

This archive was generated by hypermail 2.3.0 : Thu Mar 10 2016 - 10:00:53 CET