# Treat all warnings as errors (poor man's lint?)
ifeq ($(WERROR), 1)
- CFLAGS += -Wall -Wextra -Werror
+ CFLAGS += -Wall -Wextra -Wno-unused-parameter
endif
# GCC Debugging
/* Generic Death Function
*****************************************************************************/
-void die(const char* msgfmt, ...);
+void die(const char* msgfmt, ...) __attribute__((__noreturn__));
/* Option Parsing
*
};
/* Represents a unicode code point */
-typedef uint32_t Rune;
+typedef int32_t Rune;
size_t utf8encode(char str[UTF_MAX], Rune rune);
bool utf8decode(Rune* rune, size_t* length, int byte);
static void log_insert(Buf* buf, Log** list, size_t beg, size_t end);
static void log_delete(Buf* buf, Log** list, size_t off, Rune* r, size_t len);
static void syncgap(Buf* buf, size_t off);
-static void buf_resize(Buf* buf, size_t sz);
static void delete(Buf* buf, size_t off);
static size_t insert(Buf* buf, size_t off, Rune rune);
-static int range_match(Buf* buf, size_t dbeg, size_t dend, size_t mbeg, size_t mend);
static int rune_match(Buf* buf, size_t mbeg, size_t mend, Rune* runes);
static void swaplog(Buf* buf, Log** from, Log** to, Sel* sel);
static size_t next_size(size_t curr);
log_clear(&(buf->redo));
for (size_t i = end-beg; i > 0; i--) {
Rune r = buf_get(buf, beg);
- bool is_eol = (r == '\n' || r == RUNE_CRLF);
log_delete(buf, &(buf->undo), beg, &r, 1);
delete(buf, beg);
}
void buf_getblock(Buf* buf, Rune first, Rune last, Sel* sel) {
int balance = 0, dir;
- size_t beg = sel->end, end = sel->end, off;
+ size_t beg, end = sel->end;
/* figure out which end of the block we're starting at */
if (buf_get(buf, end) == first)
*(copy.gapstart++) = *(curr);
/* free the buffer and commit the changes */
free(buf->bufstart);
- *buf = copy;
+ memcpy(buf, ©, sizeof(Buf));
}
static void delete(Buf* buf, size_t off) {
return rcount;
}
-static int range_match(Buf* buf, size_t dbeg, size_t dend, size_t mbeg, size_t mend) {
- size_t n1 = dend-dbeg, n2 = mend-mbeg;
- if (n1 != n2) return n1-n2;
- for (; n1 > 0; n1--, dbeg++, mbeg++) {
- int cmp = buf_get(buf, dbeg) - buf_get(buf, mbeg);
- if (cmp != 0) return cmp;
- }
- return 0;
-}
-
static int rune_match(Buf* buf, size_t mbeg, size_t mend, Rune* runes) {
for (; *runes; runes++, mbeg++) {
int cmp = *runes - buf_get(buf, mbeg);
job->nwrite += nwrite;
}
if (nwrite < 0 || job->ndata <= 0)
- job_closefd(job, fd);
+ close(fd);
} else {
job_closefd(job, fd);
}
}
} else {
close(fd);
- job_closefd(job, -fd);
}
} else {
job_closefd(job, fd);
#include <wchar.h>
#include <ctype.h>
-const uint8_t UTF8_SeqBits[] = { 0x00u, 0x80u, 0xC0u, 0xE0u, 0xF0u, 0xF8u, 0xFCu, 0xFEu };
-const uint8_t UTF8_SeqMask[] = { 0x00u, 0xFFu, 0x1Fu, 0x0Fu, 0x07u, 0x03u, 0x01u, 0x00u };
-const uint8_t UTF8_SeqLens[] = { 0x01u, 0x00u, 0x02u, 0x03u, 0x04u, 0x05u, 0x06u, 0x00u };
+const uint8_t UTF8_SeqBits[] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
+const uint8_t UTF8_SeqMask[] = { 0x00, 0xFF, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00 };
+const uint8_t UTF8_SeqLens[] = { 0x01, 0x00, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00 };
static bool runevalid(Rune val) {
return (val <= RUNE_MAX)
- && ((val & 0xFFFEu) != 0xFFFEu)
- && ((val < 0xD800u) || (val > 0xDFFFu))
- && ((val < 0xFDD0u) || (val > 0xFDEFu));
+ && ((val & 0xFFFE) != 0xFFFE)
+ && ((val < 0xD800) || (val > 0xDFFF))
+ && ((val < 0xFDD0) || (val > 0xFDEF));
}
static size_t runelen(Rune rune) {
char* dirname(char* path) {
path = stringdup(path);
char* end = strrchr(path, '/');
- if (!end) return NULL;
+ if (!end) return (free(path), NULL);
*end = '\0';
return path;
}
}
void view_resize(View* view, size_t nrows, size_t ncols) {
- size_t line = 1, off = 0;
+ size_t off = 0;
if (view->nrows == nrows && view->ncols == ncols) return;
/* free the old row data */
if (view->nrows) {
- line = view->rows[0]->line;
off = view->rows[0]->off;
for (size_t i = 0; i < view->nrows; i++)
free(view->rows[i]);
if (!curr) { r = -1; break; } // Break both loops if we're done
/* check if we're in the current region */
- if (curr->beg <= off && off <= curr->end) {
- uint32_t attr = row->cols[col].attr;
+ if (curr->beg <= off && off <= curr->end)
row->cols[col].attr = (row->cols[col].attr & 0xFF00) | curr->color;
- }
off++, col++;
while (col < row->len && row->cols[col].rune == '\0')
col++;
}
static void onredraw(int width, int height) {
- static uint64_t maxtime = 0;
- uint64_t start = getmillis();
size_t fheight = x11_font_height(Font);
size_t fwidth = x11_font_width(Font);
size_t y = Regions[Focused].y + (Regions[Focused].csry * fheight) + (fheight/2);
x11_mouse_set(x, y);
}
-
- uint64_t stop = getmillis();
- uint64_t elapsed = stop-start;
- //printf("%llu\n", elapsed);
}
static void oninput(int mods, Rune key) {
static void scroll_actions(int btn, bool pressed, int x, int y) {
size_t row = (y-Regions[SCROLL].y) / x11_font_height(Font);
- size_t col = (x-Regions[SCROLL].x) / x11_font_width(Font);
switch (btn) {
case MouseLeft:
if (pressed)
static void draw_line_num(bool current, size_t x, size_t y, size_t gcols, size_t num) {
int color = config_get_int(ClrGutterNor);
- if (ShowLineNumbers) {
- if (current) {
- color = config_get_int(ClrGutterSel);;
- size_t fheight = x11_font_height(Font);
- x11_draw_rect((color >> 8), x-3, y-fheight, gutter_size(), fheight);
- }
- UGlyph glyphs[gcols];
- for (int i = gcols-1; i >= 0; i--) {
- glyphs[i].attr = color & 0xFF;
- if (num > 0) {
- glyphs[i].rune = ((num % 10) + '0');
- num /= 10;
- } else {
- glyphs[i].rune = ' ';
- }
+ if (!gcols) return;
+ if (current) {
+ color = config_get_int(ClrGutterSel);;
+ size_t fheight = x11_font_height(Font);
+ x11_draw_rect((color >> 8), x-3, y-fheight, gutter_size(), fheight);
+ }
+ UGlyph glyphs[gcols];
+ for (int i = gcols-1; i >= 0; i--) {
+ glyphs[i].attr = color & 0xFF;
+ if (num > 0) {
+ glyphs[i].rune = ((num % 10) + '0');
+ num /= 10;
+ } else {
+ glyphs[i].rune = ' ';
}
- draw_glyphs(x, y, glyphs, gcols, gcols);
}
+ draw_glyphs(x, y, glyphs, gcols, gcols);
}
static void draw_glyphs(size_t x, size_t y, UGlyph* glyphs, size_t rlen, size_t ncols) {
choice.length = strlen(choice_text);
choice.score = 1.0;
vec_push_back(&Choices, &choice);
+ } else {
+ free(choice_text);
}
}
vec_sort(&Choices, by_score);
static void quit(void) {
static uint64_t before = 0;
uint64_t now = getmillis();
- if (!win_buf(EDIT)->modified || (now-before) <= config_get_int(DblClickTime)) {
+ if (!win_buf(EDIT)->modified || (now-before) <= (uint64_t)config_get_int(DblClickTime)) {
#ifndef TEST
x11_deinit();
#else
static uint64_t before = 0;
if (!pressed) return;
uint64_t now = getmillis();
- count = ((now-before) <= config_get_int(DblClickTime) ? count+1 : 1);
+ count = ((now-before) <= (uint64_t)config_get_int(DblClickTime) ? count+1 : 1);
before = now;
if (count == 1) {
void pty_update(int fd, void* data) {
/* Read from command if we have one */
- long n = 0, r = 0, i = 0;
+ long n = 0, i = 0;
static char cmdbuf[8192];
if ((n = read(CmdFD, cmdbuf, sizeof(cmdbuf))) < 0)
CmdFD = -1;