From: Michael D. Lowis Date: Thu, 10 Oct 2019 22:56:55 +0000 (-0400) Subject: fixed some lint X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=8f2f5660f44e687bb2845f23460394c60de10d17;p=projs%2Ftide.git fixed some lint --- diff --git a/Makefile b/Makefile index 4bd11bc..b101fe6 100644 --- a/Makefile +++ b/Makefile @@ -3,19 +3,19 @@ all: build config: - ./rscons configure + ./rscons $(RFLAGS) configure build: - ./rscons build + ./rscons $(RFLAGS) build clean: - ./rscons clean + ./rscons $(RFLAGS) clean distclean: - ./rscons distclean + ./rscons $(RFLAGS) distclean install: - ./rscons install + ./rscons $(RFLAGS) install uninstall: - ./rscons uninstall + ./rscons $(RFLAGS) uninstall diff --git a/Rsconscript b/Rsconscript index 164fa1f..323003f 100644 --- a/Rsconscript +++ b/Rsconscript @@ -14,12 +14,12 @@ build do env["CPPPATH"] += %w[. inc] env["LIBPATH"] += %w[.] -# env["CFLAGS"] << "-DNDEBUG" +# env["CPPFLAGS"] << "-DNDEBUG" # # Enable Sanitizers # env["CFLAGS"] += ["-g", "-fsanitize=undefined,address"] # env["LDFLAGS"] += ["-g", "-fsanitize=undefined,address"] - +# # # Enable Coverage # env["CFLAGS"] += ["-g", "-O0", "--coverage"] # env["LDFLAGS"] += ["-g", "-O0", "--coverage"] diff --git a/alcc b/alcc index 8029d83..92ae831 100755 --- a/alcc +++ b/alcc @@ -69,6 +69,7 @@ declare -a sources declare -a objects declare -a libpaths compile=false +lintonly=false runtime=' #define _POSIX_C_SOURCE 200809L #define _XOPEN_SOURCE 700 @@ -103,8 +104,11 @@ for i do -L*) # Add libpaths to the search list libpaths+=("${i#-L}") ;; - -c|-E) # Mark this as compilation/preprocess only + -c|-E) # Mark this as compilation/preprocess only run compile=true ;; + --lint) # Mark this as lint only run + lintonly=true ;; + esac done @@ -213,14 +217,18 @@ script=$(cat < #include "config.h" -void draw_rect(XConf* x, int color, int posx, int posy, int width, int height) { +void draw_rect(XConf* x, int color, int posx, int posy, int width, int height) +{ x11_draw_rect(x, Palette[color], posx, posy, width, height); } -void draw_statbox(XConf* x, int status) { +void draw_statbox(XConf* x, int status) +{ draw_rect(x, VerBdr, ScrollWidth, 0, 1, x->height/4); switch (status) { case NORMAL: draw_rect(x, TagsBg, 0, 0, ScrollWidth, x->height/4); break; @@ -20,13 +22,15 @@ void draw_statbox(XConf* x, int status) { draw_rect(x, WinBdr, 0, 0, 1, x->height/4); } -int draw_hrule(XConf* x, drawcsr* csr) { +int draw_hrule(XConf* x, drawcsr* csr) +{ draw_rect(x, HorBdr, 0, csr->y + 1, x->width, 1); csr->y += 2; return (csr->y - 2); } -void draw_view(XConf* x, View* view, XftFont* font, size_t nrows, drawcsr* csr, int bg, int fg, int sel, bool csrsync) { +void draw_view(XConf* x, View* view, XftFont* font, size_t nrows, drawcsr* csr, int bg, int fg, int sel, bool csrsync) +{ int nspecs = 0; XftGlyphSpec* specs = NULL; size_t fheight = font->height; @@ -35,10 +39,12 @@ void draw_view(XConf* x, View* view, XftFont* font, size_t nrows, drawcsr* csr, view_resize(view, (csr->w - csr->x), nrows); view_update(view); draw_rect(x, bg, csr->x, csr->y, csr->w, ((nrows + 1) * fheight) + 9); - for (size_t i = 0; i < nrows; i++) { + for (size_t i = 0; i < nrows; i++) + { Row* row = view_getrow(view, i + view->index); size_t posx = (csr->x + 2), y = (csr->y + 2 + (i * fheight)); - for (size_t i = 0; i < row->len; i++) { + for (size_t i = 0; i < row->len; i++) + { int rune = row->cols[i].rune; if (rune == '\r' || rune == '\n' || rune == '\t') rune = ' '; @@ -46,7 +52,8 @@ void draw_view(XConf* x, View* view, XftFont* font, size_t nrows, drawcsr* csr, draw_rect(x, sel, posx, y, row->cols[i].width, fheight); if (row->cols[i].off == view->buffer.selection.end) csr_drawn = draw_csr(x, view, fg, fheight, posx, y, csr_drawn); - if (csrsync && row->cols[i].off == view->buffer.selection.beg) { + if (csrsync && row->cols[i].off == view->buffer.selection.beg) + { XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, posx + row->cols[i].width/2, y + fheight*3/4); csrsync = false; } @@ -62,8 +69,10 @@ void draw_view(XConf* x, View* view, XftFont* font, size_t nrows, drawcsr* csr, free(specs); } -bool draw_csr(XConf* x, View* view, int fg, size_t fheight, int posx, int posy, bool csrdrawn) { - if (!csrdrawn && !view_selsize(view)) { +bool draw_csr(XConf* x, View* view, int fg, size_t fheight, int posx, int posy, bool csrdrawn) +{ + if (!csrdrawn && !view_selsize(view)) + { draw_rect(x, fg, posx-1, posy, 3, 3); draw_rect(x, fg, posx, posy, 1, fheight); draw_rect(x, fg, posx-1, posy+fheight-3, 3, 3); @@ -72,7 +81,8 @@ bool draw_csr(XConf* x, View* view, int fg, size_t fheight, int posx, int posy, return csrdrawn; } -void draw_scroll(XConf* x, drawcsr* csr, View* view, int divider) { +void draw_scroll(XConf* x, drawcsr* csr, View* view, int divider) +{ size_t bend = buf_end(&(view->buffer)); if (bend == 0) bend = 1; if (!view->rows || !view->nrows) return; diff --git a/src/lib/job.c b/src/lib/job.c index 9d082fa..c3b7cd5 100644 --- a/src/lib/job.c +++ b/src/lib/job.c @@ -20,35 +20,42 @@ struct PipeData { static struct pollfd JobFds[MAX_JOBS]; static Job* JobList = NULL; -static void pipe_read(Job* job) { +static void pipe_read(Job* job) +{ struct PipeData* pipedata = job->data; char buffer[16385]; errno = 0; long nread = read(job->fd, buffer, sizeof(buffer)-1); - if (nread <= 0) { + if (nread <= 0) + { job->readfn = NULL; buf_logstop(&pipedata->dest->buffer); if (view_selsize(pipedata->dest)) view_delete(pipedata->dest, RIGHT, false); else view_selprev(pipedata->dest); - } else if (nread > 0) { + } + else if (nread > 0) + { buffer[nread] = '\0'; buf_logstart(&pipedata->dest->buffer); view_putstr(pipedata->dest, buffer); } } -static void pipe_write(Job* job) { +static void pipe_write(Job* job) +{ struct PipeData* pipedata = job->data; char* chunk = pipedata->data + pipedata->nwrite; errno = 0; long nwrite = write(job->fd, chunk, pipedata->ndata); - if (nwrite >= 0) { + if (nwrite >= 0) + { pipedata->ndata -= nwrite; pipedata->nwrite += nwrite; } - if ((nwrite < 0 && errno != EWOULDBLOCK) || pipedata->ndata <= 0) { + if ((nwrite < 0 && errno != EWOULDBLOCK) || pipedata->ndata <= 0) + { free(pipedata->data); pipedata->data = NULL; job->writefn = NULL; @@ -56,23 +63,31 @@ static void pipe_write(Job* job) { } } -static Job* job_remove(Job* list, Job* job) { - if (list == job) { - return job->next; - } else { +static Job* job_remove(Job* list, Job* job) +{ + Job* ret = NULL; + if (list == job) + { + ret = job->next; + } + else + { list->next = job_remove(list->next, job); - return list; + ret = list; } + return ret; } -static void job_finish(Job* job) { +static void job_finish(Job* job) +{ JobList = job_remove(JobList, job); close(job->fd); free(job->data); free(job); } -static void job_process(int fd, int events) { +static void job_process(int fd, int events) +{ Job* job = JobList; // Get job by fd while (job && job->fd != fd) job = job->next; @@ -85,24 +100,31 @@ static void job_process(int fd, int events) { job_finish(job); } -static int job_exec(char** cmd, int* p_pid) { +static int job_exec(char** cmd, int* p_pid) +{ int pid, fds[2]; /* create the sockets */ if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) return -1; /* create the process */ - if ((pid = fork()) < 0) { + if ((pid = fork()) < 0) + { close(fds[0]), close(fds[1]), fds[0] = -1; - } else if (0 == pid) { + } + else if (0 == pid) + { /* redirect child process's io to the pipes */ - if ((dup2(fds[1], 0) < 0) || (dup2(fds[1], 1) < 0) || (dup2(fds[1], 2) < 0)) { + if ((dup2(fds[1], 0) < 0) || (dup2(fds[1], 1) < 0) || (dup2(fds[1], 2) < 0)) + { perror("failed to pipe"); exit(1); } /* execute the process */ close(fds[0]); exit(execvp(cmd[0], cmd)); - } else { + } + else + { close(fds[1]); fcntl(fds[0], F_SETFL, fcntl(fds[0], F_GETFL, 0) | O_NONBLOCK); } @@ -110,19 +132,23 @@ static int job_exec(char** cmd, int* p_pid) { return fds[0]; } -Job* job_list(void) { +Job* job_list(void) +{ return JobList; } -void job_kill(Job* job) { +void job_kill(Job* job) +{ job->readfn = NULL; job->writefn = NULL; } -bool job_poll(int ms) { +bool job_poll(int ms) +{ int njobs = 0; /* Add jobs from the job list */ - for (Job *job = JobList; job && njobs < MAX_JOBS; job = job->next) { + for (Job *job = JobList; job && njobs < MAX_JOBS; job = job->next) + { JobFds[njobs].fd = job->fd; JobFds[njobs].events = 0; JobFds[njobs].revents = 0; @@ -139,7 +165,8 @@ bool job_poll(int ms) { return (ret > 0); } -void job_spawn(int fd, jobfn_t readfn, jobfn_t writefn, void* data) { +void job_spawn(int fd, jobfn_t readfn, jobfn_t writefn, void* data) +{ Job *job = calloc(1, sizeof(Job)); job->fd = fd; job->readfn = readfn; @@ -149,32 +176,40 @@ void job_spawn(int fd, jobfn_t readfn, jobfn_t writefn, void* data) { JobList = job; } -void job_start(char** cmd, char* data, size_t ndata, View* dest) { +void job_start(char** cmd, char* data, size_t ndata, View* dest) +{ int fd = job_exec(cmd, 0); - if (fd >= 0 && (data || dest)) { + if (fd >= 0 && (data || dest)) + { struct PipeData* pipedata = NULL; - if (data) { + if (data) + { pipedata = calloc(1, sizeof(struct PipeData)); pipedata->data = data; pipedata->ndata = ndata; pipedata->dest = dest; } job_spawn(fd, (data ? pipe_read : NULL), (dest ? pipe_write : NULL), pipedata); - } else { + } + else + { close(fd); } } -int job_run(char** cmd) { +int job_run(char** cmd) +{ int pid = -1, status = 0; job_exec(cmd, &pid); - do { + do + { waitpid(pid, &status, WUNTRACED|WCONTINUED); } while (!WIFEXITED(status) && !WIFSIGNALED(status)); return WEXITSTATUS(status); } -void job_readfd(int fd, View* view) { +void job_readfd(int fd, View* view) +{ struct PipeData* pipedata = calloc(1, sizeof(struct PipeData)); pipedata->dest = view; job_spawn(fd, pipe_read, NULL, pipedata); diff --git a/src/lib/mouse.c b/src/lib/mouse.c index 3382573..8bd04ef 100644 --- a/src/lib/mouse.c +++ b/src/lib/mouse.c @@ -2,62 +2,106 @@ #include #include #include +#include #include "config.h" -#define PRESSED(mods, btn) \ - ((mods & (1 << (btn + 7))) == (1 << (btn + 7))) +static inline int PRESSED(int mods, int btn) +{ + return ((mods & (1 << (btn + 7))) == (1 << (btn + 7))); +} static int ExecRequest = 0; -static int mouse_left(bool pressed) { +static int mouse_left(bool pressed) +{ static int count = 0; static Time before = 0; - if (!pressed) return MouseActNone; - count = ((X.now - before) <= (uint64_t)ClickTime ? count+1 : 1); - before = X.now; - if (PRESSED(X.mods, MouseRight)) { - return MouseActNone; - } else if (PRESSED(X.mods, MouseMiddle)) { - ExecRequest = 0; - return MouseActExecArg; - } else if (count == 1) { - return MouseActSel; - } else if (count == 2) { - return MouseActSelCtx; - } else if (count == 3) { - return MouseActSelWord; - } else { - return MouseActNone; + int ret = MouseActNone; + if (pressed) + { + count = ((X.now - before) <= (uint64_t)ClickTime ? count+1 : 1); + before = X.now; + if (PRESSED(X.mods, MouseRight)) + { + ret = MouseActNone; + } + else if (PRESSED(X.mods, MouseMiddle)) + { + ExecRequest = 0; + ret = MouseActExecArg; + } + else if (count == 1) + { + ret = MouseActSel; + } + else if (count == 2) + { + ret = MouseActSelCtx; + } + else if (count == 3) + { + ret = MouseActSelWord; + } + else + { + ret = MouseActNone; + } } + return ret; } -static int mouse_middle(bool pressed) { - if (pressed) { ExecRequest = 1; return MouseActNone; } - if (PRESSED(X.mods, MouseLeft)) { - return MouseActCut; - } else if (ExecRequest) { - return MouseActExec; - } else { - return MouseActNone; +static int mouse_middle(bool pressed) +{ + int ret; + if (pressed) + { + ExecRequest = 1; + ret = MouseActNone; + } + else if (PRESSED(X.mods, MouseLeft)) + { + ret = MouseActCut; + } + else if (ExecRequest) + { + ret = MouseActExec; + } + else + { + ret = MouseActNone; } + return ret; } -static int mouse_right(bool pressed) { - if (pressed) return MouseActNone; - if (PRESSED(X.mods, MouseLeft)) { - return MouseActPaste; - } else { - return MouseActFetch; +static int mouse_right(bool pressed) +{ + int ret; + if (pressed) + { + ret = MouseActNone; } + else if (PRESSED(X.mods, MouseLeft)) + { + ret = MouseActPaste; + } + else + { + ret = MouseActFetch; + } + return ret; } -int process_mouse(int btn, bool pressed) { - switch(btn) { - case MouseLeft: return mouse_left(pressed); - case MouseMiddle: return mouse_middle(pressed); - case MouseRight: return mouse_right(pressed); - case MouseWheelUp: return (pressed ? MouseActScrollUp : MouseActNone); - case MouseWheelDn: return (pressed ? MouseActScrollDn : MouseActNone); - } - return MouseActNone; +int process_mouse(int btn, bool pressed) +{ + require(btn <= MouseWheelDn); + int ret = MouseActNone; + switch(btn) + { + case MouseLeft: ret = mouse_left(pressed); break; + case MouseMiddle: ret = mouse_middle(pressed); break; + case MouseRight: ret = mouse_right(pressed); break; + case MouseWheelUp: ret = (pressed ? MouseActScrollUp : MouseActNone); break; + case MouseWheelDn: ret = (pressed ? MouseActScrollDn : MouseActNone); break; + } + return ret; } diff --git a/src/lib/utf8.c b/src/lib/utf8.c index 19dd5ed..7305ed4 100644 --- a/src/lib/utf8.c +++ b/src/lib/utf8.c @@ -9,34 +9,56 @@ static const uint8_t UTF8_SeqBits[] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC 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) { +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) { +static size_t runelen(Rune rune) +{ + size_t ret; if(!runevalid(rune)) - return 0; + { + ret = 0; + } else if(rune <= 0x7F) - return 1; + { + ret = 1; + } else if(rune <= 0x07FF) - return 2; + { + ret = 2; + } else if(rune <= 0xFFFF) - return 3; + { + ret = 3; + } else - return 4; + { + ret = 4; + } + return ret; } -static uint8_t utfseq(uint8_t byte) { +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]) - return UTF8_SeqLens[i-1]; - return 0; + { + ret = UTF8_SeqLens[i-1]; + break; + } + } + return ret; } -size_t utf8encode(char str[UTF_MAX], Rune rune) { +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)))); @@ -45,7 +67,8 @@ size_t utf8encode(char str[UTF_MAX], Rune rune) { return len; } -bool utf8decode(Rune* rune, size_t* length, int byte) { +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 */ @@ -74,35 +97,48 @@ bool utf8decode(Rune* rune, size_t* length, int byte) { return ((*length == 0) || (*rune == RUNE_ERR)); } -int runewidth(unsigned col, Rune r) { - size_t tabwidth = TabWidth; - if (r == '\t') return (tabwidth - (col % tabwidth)); - int width = wcwidth(r); - if (width < 0) width = 1; +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) { +bool risword(Rune r) +{ return (r < 127 && (isalnum(r) || r == '_' || r == '+' || r == '-')); } -bool rissigil(Rune r) { +bool rissigil(Rune r) +{ return (r == ':' || r == '!' || r == '|' || r == '>' || r == '<'); } -bool risfile(Rune r) { +bool risfile(Rune r) +{ return (risword(r) || r == '/' || r == '.' || r == ':' || r == '-' || r == '~'); } -bool riscmd(Rune r) { +bool riscmd(Rune r) +{ return (risword(r) || rissigil(r)); } -bool risblank(Rune r) { +bool risblank(Rune r) +{ return (r == ' ' || r == '\t' || r == '\n' || r == '\r'); } -bool risbigword(Rune r) { +bool risbigword(Rune r) +{ return !risblank(r); } diff --git a/src/tide.c b/src/tide.c index bf9aec3..5ecb416 100644 --- a/src/tide.c +++ b/src/tide.c @@ -756,6 +756,24 @@ static void usage(void) exit(1); } +static void edit_file(char* file, int line_num) +{ + char* path = realpath(file, NULL); + if (!path) path = strdup(file); /* if file doesnt exist, use the original name */ + if (!strcmp("-", path)) + { + job_readfd(STDIN_FILENO, win_view(EDIT)); + } + else + { + view_init(win_view(EDIT), path); + win_setln(line_num); + win_title(path); + win_prop_set("FILE", "file", path); + } + free(path); +} + int main(int argc, char** argv) { long int line_num = 0; @@ -793,20 +811,7 @@ int main(int argc, char** argv) /* if we still have args left we're going to open it in this instance */ if (*argv) { - char* path = realpath(*argv, NULL); - if (!path) path = strdup(*argv); /* if file doesnt exist, use the original name */ - if (!strcmp("-", path)) - { - job_readfd(STDIN_FILENO, win_view(EDIT)); - } - else - { - view_init(win_view(EDIT), path); - win_setln(line_num); - win_title(path); - win_prop_set("FILE", "file", path); - } - free(path); + edit_file(*argv, line_num); } /* set host name property */ @@ -814,14 +819,6 @@ int main(int argc, char** argv) if (!gethostname(host, sizeof(host))) win_prop_set("HOST", "host", host); - /* check if we should embed in a parent */ - char* winid = getenv("TIDE_PARENT"); - if (winid) - { - XReparentWindow(X.display, X.self, strtoul(winid, 0, 0), 0, 0); - XFlush(X.display); - } - /* now create the window and start the event loop */ #ifndef TEST x11_show(&X); diff --git a/tests/lib/buf.c b/tests/lib/buf.c index b36836f..b33af63 100644 --- a/tests/lib/buf.c +++ b/tests/lib/buf.c @@ -32,7 +32,7 @@ static int selection_equals(char* str) return (!strcmp(str, Output)); } -void setup_buffer(void) +static void setup_buffer(void) { free(Output), Output = NULL; buf_init(&TestBuf); @@ -89,14 +89,14 @@ PROPERTY(edit_operations_are_reversible) return 1; } -void show_codepoint(QCValue* val) +static void show_codepoint(QCValue* val) { char buf[UTF_MAX+1] = {0}; utf8encode(buf, val->data[0]); printf("0x%08x (%s)\n", (int)(val->data[0]), buf); } -QCValue* GenCodepoint(void) +static QCValue* GenCodepoint(void) { long cp = 0; do { cp = qcrandr(32,0x10FFFF); } diff --git a/tests/lib/utf8.c b/tests/lib/utf8.c index c8d7170..1ef63db 100644 --- a/tests/lib/utf8.c +++ b/tests/lib/utf8.c @@ -3,5 +3,6 @@ #include #include -TEST_SUITE(Utf8Tests) { +TEST_SUITE(Utf8Tests) +{ }