From: Michael D. Lowis Date: Tue, 2 May 2023 02:58:26 +0000 (-0400) Subject: extract utf8, file toutines, and telemetry X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=942168b10dab0dfff644d6247d91019f2e821796;p=proto%2Faos.git extract utf8, file toutines, and telemetry --- diff --git a/bin/editor/buf.c b/bin/editor/buf.c index 45b3403..3447e8b 100644 --- a/bin/editor/buf.c +++ b/bin/editor/buf.c @@ -1,6 +1,7 @@ +#define _XOPEN_SOURCE 700 +#include #include #include "dbc.h" -#include "utf.h" #include #include #include @@ -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)); } diff --git a/bin/editor/dbc.c b/bin/editor/dbc.c index fec4af5..e772611 100644 --- a/bin/editor/dbc.c +++ b/bin/editor/dbc.c @@ -1,8 +1,8 @@ +#include #include #include "dbc.h" #include #include -#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) diff --git a/bin/editor/draw.c b/bin/editor/draw.c index 11b79d5..b90560c 100644 --- a/bin/editor/draw.c +++ b/bin/editor/draw.c @@ -1,5 +1,5 @@ +#include #include -#include "utf.h" #include "tide.h" #include "config.h" diff --git a/bin/editor/editlog.c b/bin/editor/editlog.c index d016fc9..f83dfad 100644 --- a/bin/editor/editlog.c +++ b/bin/editor/editlog.c @@ -1,6 +1,6 @@ +#include #include #include "dbc.h" -#include "utf.h" #include "tide.h" #include "config.h" diff --git a/bin/editor/exec.c b/bin/editor/exec.c index 1d5ebac..e06ec70 100644 --- a/bin/editor/exec.c +++ b/bin/editor/exec.c @@ -1,5 +1,6 @@ +#define _XOPEN_SOURCE 700 +#include #include -#include "utf.h" #include "dbc.h" #include "tide.h" diff --git a/bin/editor/gapbuf.c b/bin/editor/gapbuf.c index 86df698..3851751 100644 --- a/bin/editor/gapbuf.c +++ b/bin/editor/gapbuf.c @@ -3,11 +3,7 @@ #include #include "dbc.h" -//#include "utf.h" -//#include #include -//#include -//#include #include #include @@ -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 index 860b7bb..0000000 --- a/bin/editor/io.h +++ /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); diff --git a/bin/editor/job.c b/bin/editor/job.c index 84fc6dd..ba81ffa 100644 --- a/bin/editor/job.c +++ b/bin/editor/job.c @@ -1,8 +1,6 @@ #define _XOPEN_SOURCE 700 #include - #include -#include "io.h" #include #include #include @@ -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 */ diff --git a/bin/editor/leap.c b/bin/editor/leap.c index 6105580..0de287c 100644 --- a/bin/editor/leap.c +++ b/bin/editor/leap.c @@ -1,5 +1,5 @@ +#include #include -#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]; diff --git a/bin/editor/main.c b/bin/editor/main.c index fe8629e..dbccfae 100644 --- a/bin/editor/main.c +++ b/bin/editor/main.c @@ -1,7 +1,7 @@ +#define _XOPEN_SOURCE 700 +#include #include #include "dbc.h" -#include "utf.h" -#include "io.h" #include #include @@ -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)); diff --git a/bin/editor/mouse.c b/bin/editor/mouse.c index a59bb99..ee9f126 100644 --- a/bin/editor/mouse.c +++ b/bin/editor/mouse.c @@ -1,5 +1,5 @@ +#include #include -#include "utf.h" #include "dbc.h" #include "tide.h" diff --git a/bin/editor/range.c b/bin/editor/range.c index fbd96e5..4206d29 100644 --- a/bin/editor/range.c +++ b/bin/editor/range.c @@ -1,5 +1,5 @@ +#include #include -#include "utf.h" #include "tide.h" diff --git a/bin/editor/shortcuts.c b/bin/editor/shortcuts.c index c0cb8bc..c7583da 100644 --- a/bin/editor/shortcuts.c +++ b/bin/editor/shortcuts.c @@ -1,5 +1,5 @@ +#include #include -#include "utf.h" #include "tide.h" diff --git a/bin/editor/utf.h b/bin/editor/utf.h deleted file mode 100644 index 906f2f1..0000000 --- a/bin/editor/utf.h +++ /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 index 078c5a3..0000000 --- a/bin/editor/utf8.c +++ /dev/null @@ -1,144 +0,0 @@ -#include -#include "utf.h" -#include -#include - -#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); -} - diff --git a/bin/editor/view.c b/bin/editor/view.c index a5afaab..4314fe7 100644 --- a/bin/editor/view.c +++ b/bin/editor/view.c @@ -1,6 +1,6 @@ +#include #include #include "dbc.h" -#include "utf.h" #include #include "tide.h" diff --git a/bin/editor/x11.c b/bin/editor/x11.c index c1172a5..4af3baf 100644 --- a/bin/editor/x11.c +++ b/bin/editor/x11.c @@ -1,7 +1,6 @@ +#include #include #include "x11.h" -#include "utf.h" -#include "io.h" #include #include #include @@ -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; } diff --git a/bin/editor/x11_gc.c b/bin/editor/x11_gc.c index d7d7a7d..c0cd469 100644 --- a/bin/editor/x11_gc.c +++ b/bin/editor/x11_gc.c @@ -1,11 +1,11 @@ +#include #include #include "x11.h" -#include "io.h" #include 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); } diff --git a/bin/editor/xpty.c b/bin/editor/xpty.c index 9c146da..b74e79a 100644 --- a/bin/editor/xpty.c +++ b/bin/editor/xpty.c @@ -1,7 +1,6 @@ #define _XOPEN_SOURCE 700 #include #include -#include "io.h" #include #ifdef __linux__ #include diff --git a/bin/pick/utf.h b/bin/pick/utf.h deleted file mode 100644 index 906f2f1..0000000 --- a/bin/pick/utf.h +++ /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 index 078c5a3..0000000 --- a/bin/pick/utf8.c +++ /dev/null @@ -1,144 +0,0 @@ -#include -#include "utf.h" -#include -#include - -#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); -} - diff --git a/bin/pick/x11.c b/bin/pick/x11.c index 320a84b..8612a27 100644 --- a/bin/pick/x11.c +++ b/bin/pick/x11.c @@ -1,6 +1,6 @@ +#include #include #include "x11.h" -#include "utf.h" #include "io.h" #include #include diff --git a/inc/liba.h b/inc/liba.h index 597d5d0..3e101a4 100644 --- a/inc/liba.h +++ b/inc/liba.h @@ -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 diff --git a/lib/a/File.c b/lib/a/File.c index 9fb4836..d420f2f 100644 --- a/lib/a/File.c +++ b/lib/a/File.c @@ -4,6 +4,7 @@ #include #include #include +#include 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; +} diff --git a/bin/editor/telem.c b/lib/a/Telemetry.c similarity index 98% rename from bin/editor/telem.c rename to lib/a/Telemetry.c index 36c82e2..8a45eb1 100644 --- a/bin/editor/telem.c +++ b/lib/a/Telemetry.c @@ -1,12 +1,10 @@ #include - #include #include #include #include #include - 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); diff --git a/lib/a/UTF8.c b/lib/a/UTF8.c index 852a3ed..f3191c0 100644 --- a/lib/a/UTF8.c +++ b/lib/a/UTF8.c @@ -1,4 +1,9 @@ +#define _XOPEN_SOURCE 700 #include +#include +#include + +#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); +}