]> git.mdlowis.com Git - proto/aos.git/commitdiff
extract utf8, file toutines, and telemetry
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 2 May 2023 02:58:26 +0000 (22:58 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 2 May 2023 02:58:26 +0000 (22:58 -0400)
26 files changed:
bin/editor/buf.c
bin/editor/dbc.c
bin/editor/draw.c
bin/editor/editlog.c
bin/editor/exec.c
bin/editor/gapbuf.c
bin/editor/io.h [deleted file]
bin/editor/job.c
bin/editor/leap.c
bin/editor/main.c
bin/editor/mouse.c
bin/editor/range.c
bin/editor/shortcuts.c
bin/editor/utf.h [deleted file]
bin/editor/utf8.c [deleted file]
bin/editor/view.c
bin/editor/x11.c
bin/editor/x11_gc.c
bin/editor/xpty.c
bin/pick/utf.h [deleted file]
bin/pick/utf8.c [deleted file]
bin/pick/x11.c
inc/liba.h
lib/a/File.c
lib/a/Telemetry.c [moved from bin/editor/telem.c with 98% similarity]
lib/a/UTF8.c

index 45b3403305079f2bc72a7b50d8188def9c5c89db..3447e8b0f79adf8b508c0dd3146389f9c0142857 100644 (file)
@@ -1,6 +1,7 @@
+#define _XOPEN_SOURCE 700
+#include <liba.h>
 #include <stdc.h>
 #include "dbc.h"
-#include "utf.h"
 #include <ctype.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -274,7 +275,7 @@ size_t buf_end(Buf* buf)
 int buf_getrat(Buf* buf, size_t off)
 {
     require(buf != NULL);
-    size_t rlen = 0;
+    Int rlen = 0;
     Rune rune = 0;
     if (gapbuf_getb(&buf->contents, off) == '\r' && gapbuf_getb(&buf->contents, off+1) == '\n')
     {
@@ -282,7 +283,7 @@ int buf_getrat(Buf* buf, size_t off)
     }
     else
     {
-        while ( !utf8decode(&rune, &rlen, gapbuf_getb(&buf->contents, off++)) )
+        while ( !UTF8_Decode(&rune, &rlen, gapbuf_getb(&buf->contents, off++)) )
         {
         }
     }
@@ -292,9 +293,9 @@ int buf_getrat(Buf* buf, size_t off)
 void buf_putc(Buf* buf, int c)
 {
     require(buf != NULL);
-    char utf8buf[UTF_MAX+1] = {0};
-    (void)utf8encode(utf8buf, c);
-    buf_puts(buf, utf8buf);
+    Byte utf8buf[UTF_MAX+1] = {0};
+    (void)UTF8_Encode(utf8buf, c);
+    buf_puts(buf, (char*)utf8buf);
     ensure(buf_valid(buf));
 }
 
index fec4af5e91a99a68d12b3d26d26c086f05b53910..e7726115bb32b852c6da8cbcac8d47cae1198f7c 100644 (file)
@@ -1,8 +1,8 @@
+#include <liba.h>
 #include <stdc.h>
 #include "dbc.h"
 #include <stdio.h>
 #include <signal.h>
-#include "io.h"
 
 #ifndef NDEBUG
 
@@ -12,7 +12,7 @@ static void (*DumpFn)(FILE*) = NULL;
 
 static void dump_and_abort(char* msg)
 {
-    telem_send("%s", msg);
+    Telemetry_Send("%s", msg);
     FILE* f = (DumpPath ? fopen(DumpPath, "w") : stderr);
     fprintf(f, "%s\n\n", msg);
     if (DumpFn)
index 11b79d5ec112e321f8ff57562eee463eb57ad60b..b90560c6b6073d86a9067b46d10ef8ec703e9e39 100644 (file)
@@ -1,5 +1,5 @@
+#include <liba.h>
 #include <stdc.h>
-#include "utf.h"
 
 #include "tide.h"
 #include "config.h"
index d016fc9073602676038d751b5b5998d1e62a3b22..f83dfad2b74685aea14f3284f937863275433985 100644 (file)
@@ -1,6 +1,6 @@
+#include <liba.h>
 #include <stdc.h>
 #include "dbc.h"
-#include "utf.h"
 
 #include "tide.h"
 #include "config.h"
index 1d5ebac82516d36a8e1ca46d5457c687a37c0b10..e06ec70f324b74c19911196210f4b4fd458b14d5 100644 (file)
@@ -1,5 +1,6 @@
+#define _XOPEN_SOURCE 700
+#include <liba.h>
 #include <stdc.h>
-#include "utf.h"
 #include "dbc.h"
 
 #include "tide.h"
index 86df69801f82c94ce2167b41d3dc80d16283d154..3851751e3069ddb48617da00ae196fca8a1d2092 100644 (file)
@@ -3,11 +3,7 @@
 
 #include <stdc.h>
 #include "dbc.h"
-//#include "utf.h"
-//#include <ctype.h>
 #include <unistd.h>
-//#include <fcntl.h>
-//#include <sys/stat.h>
 #include <dirent.h>
 #include <vec.h>
 
@@ -139,7 +135,6 @@ long gapbuf_save(GapBuf* buf, char* path)
     require(buf != NULL);
     File fd;
     long nwrite = 0;
-//    if (path && (fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644)) >= 0)
     if (path && (fd = File_OpenForWrite(path)) >= 0)
     {
         nwrite = File_Write(fd, buf->bufstart, (buf->gapstart - buf->bufstart));
diff --git a/bin/editor/io.h b/bin/editor/io.h
deleted file mode 100644 (file)
index 860b7bb..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
-    @file
-    Helper functions for reading and writing file descriptors as well as outputting telemetry data.
-*/
-void telem_send(char* fmt, ...);
-
-//long writefd(int fd, char* data, long towrite);
-//long readfd(int fd, char* data, long toread);
-//char* readfile(char* path);
-
-char* abspath(char* path);
index 84fc6dddae083917d736ce302f31228a8e9cb123..ba81ffadf09e39cb5a88784a0281d0417fb6ba63 100644 (file)
@@ -1,8 +1,6 @@
 #define _XOPEN_SOURCE 700
 #include <liba.h>
-
 #include <stdc.h>
-#include "io.h"
 #include <unistd.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
@@ -29,7 +27,7 @@ static void pipe_read(Job* job)
     char buffer[32769];
     errno = 0;
     long nread = read(job->fd, buffer, sizeof(buffer)-1);
-    telem_send("PIPE_READ(fd : %d, ret: %ld)\n", job->fd, nread);
+    Telemetry_Send("PIPE_READ(fd : %d, ret: %ld)\n", job->fd, nread);
     if (nread <= 0)
     {
         job->readfn = NULL;
@@ -96,20 +94,20 @@ static void job_process(int fd, int events)
     while (job && job->fd != fd)
         job = job->next;
     if (!job || !events) return;
-    telem_send("JOB(fd: %d, events: 0x%x)\n", fd, events);
+    Telemetry_Send("JOB(fd: %d, events: 0x%x)\n", fd, events);
     if (job->readfn && (events & (POLLIN|POLLHUP)))
     {
-        telem_send("JOB_READ(fd: %d)\n", job->fd);
+        Telemetry_Send("JOB_READ(fd: %d)\n", job->fd);
         job->readfn(job);
     }
     if (job->writefn && (events & POLLOUT))
     {
-        telem_send("JOB_WRITE(fd: %d)\n", job->fd);
+        Telemetry_Send("JOB_WRITE(fd: %d)\n", job->fd);
         job->writefn(job);
     }
     if ((events & POLLERR) || (!job->readfn && !job->writefn))
     {
-        telem_send("JOB_FINISH(fd: %d)\n", job->fd);
+        Telemetry_Send("JOB_FINISH(fd: %d)\n", job->fd);
         job_finish(job);
     }
 }
@@ -176,7 +174,7 @@ bool job_poll(int ms)
     long ret = poll(JobFds, njobs, ms);
     if (ret != 0)
     {
-        telem_send("POLL(njobs: %d, ms: %d, ret: %d)\n", njobs, ms, ret);
+        Telemetry_Send("POLL(njobs: %d, ms: %d, ret: %d)\n", njobs, ms, ret);
     }
 
     /* process all jobs with events reported */
index 6105580ed6ad7da602ca0102befedffb12051319..0de287c6ac1c944a8600fc6720191783bf111963 100644 (file)
@@ -1,5 +1,5 @@
+#include <liba.h>
 #include <stdc.h>
-#include "utf.h"
 #include "tide.h"
 
 static void leap_process_keysym(LeapState_T* state, unsigned long keysym)
@@ -7,8 +7,8 @@ static void leap_process_keysym(LeapState_T* state, unsigned long keysym)
     uint32_t key = x11_getkey(keysym);
     if (key != RUNE_ERR)
     {
-        char utf8buf[UTF_MAX+1] = {0};
-        size_t sz = utf8encode(utf8buf, key);
+        Byte utf8buf[UTF_MAX+1] = {0};
+        size_t sz = UTF8_Encode(utf8buf, key);
         for (size_t i = 0; i < sz; i++)
         {
             state->buf[state->nbuf++] = utf8buf[i];
index fe8629ea033da06ccb54b7d5bedb768e8d420a19..dbccfaeec6a1b3654606275ce054b4e6170c8ce0 100644 (file)
@@ -1,7 +1,7 @@
+#define _XOPEN_SOURCE 700
+#include <liba.h>
 #include <stdc.h>
 #include "dbc.h"
-#include "utf.h"
-#include "io.h"
 #include <locale.h>
 #include <sys/wait.h>
 
@@ -134,7 +134,7 @@ static void xkeydn(XConf* x, XEvent* e)
     {
         Focused = (e->xkey.y <= Divider ? TAGS : EDIT);
         uint32_t key = x11_process_key(x, e, Bindings);
-        telem_send("KEY(reg: %d, key: 0x%x)\n", Focused, key);
+        Telemetry_Send("KEY(reg: %d, key: 0x%x)\n", Focused, key);
         if (key != RUNE_ERR)
         {
             view_insert(win_view(FOCUSED), key);
@@ -155,7 +155,7 @@ static void xmousebtn(XConf* x, XEvent* e)
     Focused = (e->xbutton.y <= Divider ? TAGS : EDIT);
     get_position(Focused, e->xbutton.x,  e->xbutton.y, &row, &col);
     int action = process_mouse(e->xbutton.button, (e->type == ButtonPress));
-    telem_send("BTNPRESS(reg: %d, btn: %d, press: %d, act: %d)\n",
+    Telemetry_Send("BTNPRESS(reg: %d, btn: %d, press: %d, act: %d)\n",
         Focused, e->xbutton.button, (e->type == ButtonPress), action);
     switch (action)
     {
@@ -225,7 +225,7 @@ static void xbtnmotion(XConf* x, XEvent* e)
     size_t row, col;
     int xpos = ev->x, ypos = ev->y;
     get_position(Focused, xpos, ypos, &row, &col);
-    telem_send("BTNMOVE(reg: %d, btn: 0x%x, x: %d, y: %d, r: %d, c: %d)\n",
+    Telemetry_Send("BTNMOVE(reg: %d, btn: 0x%x, x: %d, y: %d, r: %d, c: %d)\n",
         Focused, ev->state, xpos, ypos, row, col);
     if (PRESSED(ev->state, MouseLeft))
         view_setcursor(win_view(Focused), row, col, true);
@@ -267,7 +267,7 @@ static void xredraw(XConf* x)
     size_t tagrows = view_limitrows(win_view(TAGS), maxtagrows);
     size_t tagregsz = (tagrows * x->tagfont->height) + 7;
     size_t editrows = (height - tagregsz) / x->font->height ;
-    telem_send("REDRAW(tagrows: %d, editrows: %d)\n", tagrows, editrows);
+    Telemetry_Send("REDRAW(tagrows: %d, editrows: %d)\n", tagrows, editrows);
 
     /* draw the regions to the window */
     int olddiv = Divider;
@@ -445,7 +445,7 @@ static void put(char* arg)
     if (buf_save(buf, arg) == NORMAL)
     {
         /* convert saved path to absolute path */
-        char* path = abspath(buf->path);
+        char* path = File_AbsolutePath(buf->path);
         buf_setpath(buf, path);
         free(path);
     }
@@ -720,7 +720,7 @@ static void usage(void)
 
 static void edit_file(char* file, int line_num)
 {
-    file = abspath(file);
+    file = File_AbsolutePath(file);
     if (!strcmp("-", file))
     {
         job_readfd(STDIN_FILENO, win_view(EDIT));
index a59bb996cc0e08b4717354cddaf0dcdc9b8cb608..ee9f1264e1918d31776fdc994aaabc228a003c6e 100644 (file)
@@ -1,5 +1,5 @@
+#include <liba.h>
 #include <stdc.h>
-#include "utf.h"
 #include "dbc.h"
 
 #include "tide.h"
index fbd96e508748604612b19640b154d008de4fca13..4206d29582e0a7b3091a9484c260d60dedfaa26d 100644 (file)
@@ -1,5 +1,5 @@
+#include <liba.h>
 #include <stdc.h>
-#include "utf.h"
 
 #include "tide.h"
 
index c0cb8bcb5b184895ffa6d734a55cd1525f171884..c7583daa34031aba70b8a44bb54561fe83f3227a 100644 (file)
@@ -1,5 +1,5 @@
+#include <liba.h>
 #include <stdc.h>
-#include "utf.h"
 
 #include "tide.h"
 
diff --git a/bin/editor/utf.h b/bin/editor/utf.h
deleted file mode 100644 (file)
index 906f2f1..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/** @file */
-enum {
-    UTF_MAX   = 6u,       /* maximum number of bytes that make up a rune */
-    RUNE_SELF = 0x80,     /* byte values larger than this are *not* ascii */
-    RUNE_ERR  = 0xFFFD,   /* rune value representing an error */
-    RUNE_MAX  = 0x10FFFF, /* Maximum decodable rune value */
-    RUNE_EOF  = -1,       /* rune value representing end of file */
-};
-
-/* Represents a unicode code point */
-typedef int32_t Rune;
-
-size_t utf8encode(char str[UTF_MAX], Rune rune);
-bool utf8decode(Rune* rune, size_t* length, int byte);
-int runewidth(unsigned col, Rune r);
-bool risword(Rune r);
-bool rissigil(Rune r);
-bool risfile(Rune r);
-bool riscmd(Rune r);
-bool risblank(Rune r);
-bool risbigword(Rune r);
diff --git a/bin/editor/utf8.c b/bin/editor/utf8.c
deleted file mode 100644 (file)
index 078c5a3..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-#include <stdc.h>
-#include "utf.h"
-#include <wchar.h>
-#include <ctype.h>
-
-#include "config.h"
-
-static const uint8_t UTF8_SeqBits[] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
-static const uint8_t UTF8_SeqMask[] = { 0x00, 0xFF, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00 };
-static const uint8_t UTF8_SeqLens[] = { 0x01, 0x00, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00 };
-
-static bool runevalid(Rune val)
-{
-    return (val <= RUNE_MAX)
-        && ((val & 0xFFFE) != 0xFFFE)
-        && ((val < 0xD800) || (val > 0xDFFF))
-        && ((val < 0xFDD0) || (val > 0xFDEF));
-}
-
-static size_t runelen(Rune rune)
-{
-    size_t ret;
-    if(!runevalid(rune))
-    {
-        ret = 0;
-    }
-    else if(rune <= 0x7F)
-    {
-        ret = 1;
-    }
-    else if(rune <= 0x07FF)
-    {
-        ret = 2;
-    }
-    else if(rune <= 0xFFFF)
-    {
-        ret = 3;
-    }
-    else
-    {
-        ret = 4;
-    }
-    return ret;
-}
-
-static uint8_t utfseq(uint8_t byte)
-{
-    uint8_t ret = 0;
-    for (int i = 1; i < 8; i++)
-    {
-        if ((byte & UTF8_SeqBits[i]) == UTF8_SeqBits[i-1])
-        {
-            ret = UTF8_SeqLens[i-1];
-            break;
-        }
-    }
-    return ret;
-}
-
-size_t utf8encode(char str[UTF_MAX], Rune rune)
-{
-    size_t len = runelen(rune);
-    str[0] = (len == 1 ? 0x00 : UTF8_SeqBits[len])
-           | (UTF8_SeqMask[len] & (rune >> (6 * (len-1))));
-    for (size_t i = 1; i < len; i++)
-        str[i] = 0x80u | (0x3Fu & (rune >> (6 * (len-i-1))));
-    return len;
-}
-
-bool utf8decode(Rune* rune, size_t* length, int byte)
-{
-    /* Handle the start of a new rune */
-    if (*length == 0) {
-        /* If we were fed in an EOF as a start byte, handle it here */
-        if (byte == EOF) {
-            *rune = RUNE_EOF;
-        } else {
-            /* Otherwise, decode the first byte of the rune */
-            *length = utfseq(byte);
-            *rune   = (*length == 0) ? RUNE_ERR : (byte & UTF8_SeqMask[*length]);
-            (*length)--;
-        }
-    /* Handle continuation bytes */
-    } else if ((byte & 0xC0) == 0x80) {
-        /* add bits from continuation byte to rune value
-         * cannot overflow: 6 byte sequences contain 31 bits */
-        *rune = (*rune << 6) | (byte & 0x3F); /* 10xxxxxx */
-        (*length)--;
-        /* Sanity check the final rune value before finishing */
-        if ((*length == 0) && !runevalid(*rune))
-            *rune = RUNE_ERR;
-    /* Didn't get the continuation byte we expected */
-    } else {
-        *rune = RUNE_ERR;
-    }
-    /* Tell the caller whether we finished or not */
-    return ((*length == 0) || (*rune == RUNE_ERR));
-}
-
-int runewidth(unsigned col, Rune r)
-{
-    int width;
-    if (r == '\t')
-    {
-        width = (TabWidth - (col % TabWidth));
-    }
-    else
-    {
-        width = wcwidth(r);
-        if (width < 0) width = 1;
-    }
-    return width;
-}
-
-bool risword(Rune r)
-{
-    return (r < 127 && (isalnum(r) || r == '_' || r == '+' || r == '-'));
-}
-
-bool rissigil(Rune r)
-{
-    return (r == ':' || r == '!' || r == '&' || r == '|' || r == '>' || r == '<');
-}
-
-bool risfile(Rune r)
-{
-    return (risword(r) || r == '/' || r == '.' || r == ':' ||  r == '-' || r == '~');
-}
-
-bool riscmd(Rune r)
-{
-    return (risword(r) || rissigil(r));
-}
-
-bool risblank(Rune r)
-{
-    return (r == ' ' || r == '\t' || r == '\n' || r == '\r');
-}
-
-bool risbigword(Rune r)
-{
-    return !risblank(r);
-}
-
index a5afaab35fd1cda3e802f976084cfea4995b5448..4314fe7f609771e83abf9b609e1427e63240df89 100644 (file)
@@ -1,6 +1,6 @@
+#include <liba.h>
 #include <stdc.h>
 #include "dbc.h"
-#include "utf.h"
 #include <ctype.h>
 
 #include "tide.h"
index c1172a5b244d8042004478d3ce3cf5203c84dfcd..4af3baf269dd816a5d16fbd75848e234809253a4 100644 (file)
@@ -1,7 +1,6 @@
+#include <liba.h>
 #include <stdc.h>
 #include "x11.h"
-#include "utf.h"
-#include "io.h"
 #include <locale.h>
 #include <signal.h>
 #include <sys/types.h>
@@ -103,7 +102,7 @@ void x11_process_events(XConf* x)
     /* process the entire event queue */
     while (XEventsQueued(x->display, QueuedAfterReading))
     {
-        telem_send("EV_READ_QUEUE(pending: %d)\n", XPending(x->display));
+        Telemetry_Send("EV_READ_QUEUE(pending: %d)\n", XPending(x->display));
         XGetMotionEvents(x->display, x->self, CurrentTime, CurrentTime, &nevents);
 
         for (XEvent e; XPending(x->display);)
@@ -112,12 +111,12 @@ void x11_process_events(XConf* x)
             update_state(x, &e);
             if (!XFilterEvent(&e, None) && x->eventfns[e.type])
             {
-                telem_send("EV_HANDLE(type: %d)\n", e.type);
+                Telemetry_Send("EV_HANDLE(type: %d)\n", e.type);
                 (x->eventfns[e.type])(x, &e);
             }
             else
             {
-                telem_send("EV_IGNORE(type: %d)\n", e.type);
+                Telemetry_Send("EV_IGNORE(type: %d)\n", e.type);
             }
 
             /* log error here */
@@ -126,7 +125,7 @@ void x11_process_events(XConf* x)
             {
                 char msg[8192];
                 XGetErrorText(x->display, err->error_code, msg, sizeof(msg));
-                telem_send("XERROR(%s)\n", msg);
+                Telemetry_Send("XERROR(%s)\n", msg);
                 x11_error_clear();
             }
         }
@@ -247,6 +246,6 @@ int x11_seturgent(XConf* x, int urgent)
         hints.flags &= ~XUrgencyHint;
     }
     status = XSetWMHints(x->display, x->self, &hints);
-    telem_send("URGENT(%d %d)\n", urgent, status);
+    Telemetry_Send("URGENT(%d %d)\n", urgent, status);
     return status;
 }
index d7d7a7d835549240527ed2fa305865215d3addff..c0cd4697c1b7d014dbbdb34c3dc266148d7365b3 100644 (file)
@@ -1,11 +1,11 @@
+#include <liba.h>
 #include <stdc.h>
 #include "x11.h"
-#include "io.h"
 #include <X11/extensions/Xinerama.h>
 
 void x11_resize(XConf* x, XEvent* e)
 {
-    telem_send("XRESIZE(w: %d, h: %d)\n", e->xconfigure.width, e->xconfigure.height);
+    Telemetry_Send("XRESIZE(w: %d, h: %d)\n", e->xconfigure.width, e->xconfigure.height);
     if (e->xconfigure.width != x->width || e->xconfigure.height != x->height)
     {
         x->width  = e->xconfigure.width;
@@ -19,12 +19,12 @@ void x11_resize(XConf* x, XEvent* e)
 void x11_mapnotify(XConf* x, XEvent* e)
 {
     (void)x;
-    telem_send("XMAPNOTIFY(0x%x)\n", e->xmap.window);
+    Telemetry_Send("XMAPNOTIFY(0x%x)\n", e->xmap.window);
 }
 
 void x11_enternotify(XConf* x, XEvent* e)
 {
-    telem_send("XENTERNOTIFY(0x%x)\n", e->xmap.window);
+    Telemetry_Send("XENTERNOTIFY(0x%x)\n", e->xmap.window);
     x11_seturgent(x, 0);
 }
 
index 9c146da9ed1843473747da067d7a10b2ef920617..b74e79ad9c7378517ed95935666e28224569ed4e 100644 (file)
@@ -1,7 +1,6 @@
 #define _XOPEN_SOURCE 700
 #include <liba.h>
 #include <stdc.h>
-#include "io.h"
 #include <sys/socket.h>
 #ifdef __linux__
     #include <pty.h>
diff --git a/bin/pick/utf.h b/bin/pick/utf.h
deleted file mode 100644 (file)
index 906f2f1..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/** @file */
-enum {
-    UTF_MAX   = 6u,       /* maximum number of bytes that make up a rune */
-    RUNE_SELF = 0x80,     /* byte values larger than this are *not* ascii */
-    RUNE_ERR  = 0xFFFD,   /* rune value representing an error */
-    RUNE_MAX  = 0x10FFFF, /* Maximum decodable rune value */
-    RUNE_EOF  = -1,       /* rune value representing end of file */
-};
-
-/* Represents a unicode code point */
-typedef int32_t Rune;
-
-size_t utf8encode(char str[UTF_MAX], Rune rune);
-bool utf8decode(Rune* rune, size_t* length, int byte);
-int runewidth(unsigned col, Rune r);
-bool risword(Rune r);
-bool rissigil(Rune r);
-bool risfile(Rune r);
-bool riscmd(Rune r);
-bool risblank(Rune r);
-bool risbigword(Rune r);
diff --git a/bin/pick/utf8.c b/bin/pick/utf8.c
deleted file mode 100644 (file)
index 078c5a3..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-#include <stdc.h>
-#include "utf.h"
-#include <wchar.h>
-#include <ctype.h>
-
-#include "config.h"
-
-static const uint8_t UTF8_SeqBits[] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
-static const uint8_t UTF8_SeqMask[] = { 0x00, 0xFF, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00 };
-static const uint8_t UTF8_SeqLens[] = { 0x01, 0x00, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00 };
-
-static bool runevalid(Rune val)
-{
-    return (val <= RUNE_MAX)
-        && ((val & 0xFFFE) != 0xFFFE)
-        && ((val < 0xD800) || (val > 0xDFFF))
-        && ((val < 0xFDD0) || (val > 0xFDEF));
-}
-
-static size_t runelen(Rune rune)
-{
-    size_t ret;
-    if(!runevalid(rune))
-    {
-        ret = 0;
-    }
-    else if(rune <= 0x7F)
-    {
-        ret = 1;
-    }
-    else if(rune <= 0x07FF)
-    {
-        ret = 2;
-    }
-    else if(rune <= 0xFFFF)
-    {
-        ret = 3;
-    }
-    else
-    {
-        ret = 4;
-    }
-    return ret;
-}
-
-static uint8_t utfseq(uint8_t byte)
-{
-    uint8_t ret = 0;
-    for (int i = 1; i < 8; i++)
-    {
-        if ((byte & UTF8_SeqBits[i]) == UTF8_SeqBits[i-1])
-        {
-            ret = UTF8_SeqLens[i-1];
-            break;
-        }
-    }
-    return ret;
-}
-
-size_t utf8encode(char str[UTF_MAX], Rune rune)
-{
-    size_t len = runelen(rune);
-    str[0] = (len == 1 ? 0x00 : UTF8_SeqBits[len])
-           | (UTF8_SeqMask[len] & (rune >> (6 * (len-1))));
-    for (size_t i = 1; i < len; i++)
-        str[i] = 0x80u | (0x3Fu & (rune >> (6 * (len-i-1))));
-    return len;
-}
-
-bool utf8decode(Rune* rune, size_t* length, int byte)
-{
-    /* Handle the start of a new rune */
-    if (*length == 0) {
-        /* If we were fed in an EOF as a start byte, handle it here */
-        if (byte == EOF) {
-            *rune = RUNE_EOF;
-        } else {
-            /* Otherwise, decode the first byte of the rune */
-            *length = utfseq(byte);
-            *rune   = (*length == 0) ? RUNE_ERR : (byte & UTF8_SeqMask[*length]);
-            (*length)--;
-        }
-    /* Handle continuation bytes */
-    } else if ((byte & 0xC0) == 0x80) {
-        /* add bits from continuation byte to rune value
-         * cannot overflow: 6 byte sequences contain 31 bits */
-        *rune = (*rune << 6) | (byte & 0x3F); /* 10xxxxxx */
-        (*length)--;
-        /* Sanity check the final rune value before finishing */
-        if ((*length == 0) && !runevalid(*rune))
-            *rune = RUNE_ERR;
-    /* Didn't get the continuation byte we expected */
-    } else {
-        *rune = RUNE_ERR;
-    }
-    /* Tell the caller whether we finished or not */
-    return ((*length == 0) || (*rune == RUNE_ERR));
-}
-
-int runewidth(unsigned col, Rune r)
-{
-    int width;
-    if (r == '\t')
-    {
-        width = (TabWidth - (col % TabWidth));
-    }
-    else
-    {
-        width = wcwidth(r);
-        if (width < 0) width = 1;
-    }
-    return width;
-}
-
-bool risword(Rune r)
-{
-    return (r < 127 && (isalnum(r) || r == '_' || r == '+' || r == '-'));
-}
-
-bool rissigil(Rune r)
-{
-    return (r == ':' || r == '!' || r == '&' || r == '|' || r == '>' || r == '<');
-}
-
-bool risfile(Rune r)
-{
-    return (risword(r) || r == '/' || r == '.' || r == ':' ||  r == '-' || r == '~');
-}
-
-bool riscmd(Rune r)
-{
-    return (risword(r) || rissigil(r));
-}
-
-bool risblank(Rune r)
-{
-    return (r == ' ' || r == '\t' || r == '\n' || r == '\r');
-}
-
-bool risbigword(Rune r)
-{
-    return !risblank(r);
-}
-
index 320a84b4bf6d87a2a7e164df6567dfde1319599c..8612a27dd5b138d3b3741300c3c17624f6b5ec05 100644 (file)
@@ -1,6 +1,6 @@
+#include <liba.h>
 #include <stdc.h>
 #include "x11.h"
-#include "utf.h"
 #include "io.h"
 #include <locale.h>
 #include <signal.h>
index 597d5d0c0922b77f3675c977b9b7b4f6478bca38..3e101a41257ca8247ab4348da4e8b185fd024411 100644 (file)
@@ -71,6 +71,14 @@ void Options_PrintHelp(void);
 Int UTF8_Encode(Byte str[UTF_MAX], Rune rune);
 Bool UTF8_Decode(Rune* rune, Int* length, Int byte);
 
+Int runewidth(unsigned col, Rune r);
+Bool risword(Rune r);
+Bool rissigil(Rune r);
+Bool risfile(Rune r);
+Bool riscmd(Rune r);
+Bool risblank(Rune r);
+Bool risbigword(Rune r);
+
 /*
     File I/O
 */
@@ -84,7 +92,12 @@ Int File_Close(File f);
 Int File_Read(File f, char* buf, Uint bufsz);
 Int File_Write(File f, char* buf, Uint bufsz);
 char* File_ReadAll(char* path);
+char* File_AbsolutePath(char* path);
 
+/*
+    Telemetry Output
+*/
+void Telemetry_Send(char* fmt, ...);
 
 /*
     Message Bus Interface
index 9fb4836fcd380e7781aa1475be04303c2de6c498..d420f2fded7327bee1f0b69bfb703506768326d0 100644 (file)
@@ -4,6 +4,7 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <stdlib.h>
+#include <string.h>
 
 File File_OpenForRead(char* path)
 {
@@ -75,3 +76,12 @@ char* File_ReadAll(char* path)
     return data;
 }
 
+char* File_AbsolutePath(char* path)
+{
+    char* ap = realpath(path, NULL);
+    if (!ap)
+    {
+        ap = strdup(path);
+    }
+    return ap;
+}
similarity index 98%
rename from bin/editor/telem.c
rename to lib/a/Telemetry.c
index 36c82e29fc93542fcf2c9409e45b0962b68826c4..8a45eb1dcac9408c3cb345125da2b0622efb8619 100644 (file)
@@ -1,12 +1,10 @@
 #include <liba.h>
-
 #include <stdc.h>
 #include <time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <pwd.h>
 
-
 static int TelemFd = -1;
 static char TelemBuf[16384];
 
@@ -73,7 +71,7 @@ static char* get_fifo_path(void)
     return path;
 }
 
-void telem_send(char* fmt, ...)
+void Telemetry_Send(char* fmt, ...)
 {
     char* str = TelemBuf;
     size_t nleft = sizeof(TelemBuf);
index 852a3ed43fd58321379270fc077d783998a8c5f7..f3191c083bae7d992ae6feb5f9a2c557fb28b52b 100644 (file)
@@ -1,4 +1,9 @@
+#define _XOPEN_SOURCE 700
 #include <liba.h>
+#include <ctype.h>
+#include <wchar.h>
+
+#define TabWidth 4
 
 static const Byte UTF8_SeqBits[] = { 0x00u, 0x80u, 0xC0u, 0xE0u, 0xF0u, 0xF8u, 0xFCu, 0xFEu };
 static const Byte UTF8_SeqMask[] = { 0x00u, 0xFFu, 0x1Fu, 0x0Fu, 0x07u, 0x03u, 0x01u, 0x00u };
@@ -82,3 +87,48 @@ Bool UTF8_Decode(Rune* rune, Int* length, Int byte)
     /* Tell the caller whether we finished or not */
     return ((*length == 0) || (*rune == RUNE_ERR));
 }
+
+Int runewidth(unsigned col, Rune r)
+{
+    Int width;
+    if (r == '\t')
+    {
+        width = (TabWidth - (col % TabWidth));
+    }
+    else
+    {
+        width = wcwidth(r);
+        if (width < 0) width = 1;
+    }
+    return width;
+}
+
+Bool risword(Rune r)
+{
+    return (r < 127 && (isalnum(r) || r == '_' || r == '+' || r == '-'));
+}
+
+Bool rissigil(Rune r)
+{
+    return (r == ':' || r == '!' || r == '&' || r == '|' || r == '>' || r == '<');
+}
+
+Bool risfile(Rune r)
+{
+    return (risword(r) || r == '/' || r == '.' || r == ':' ||  r == '-' || r == '~');
+}
+
+Bool riscmd(Rune r)
+{
+    return (risword(r) || rissigil(r));
+}
+
+Bool risblank(Rune r)
+{
+    return (r == ' ' || r == '\t' || r == '\n' || r == '\r');
+}
+
+Bool risbigword(Rune r)
+{
+    return !risblank(r);
+}