graphcurses

Curses 2D graph generator
git clone git://git.margiolis.net/graphcurses.git
Log | Files | Refs | README | LICENSE

commit 425cfc3d755132f0ae3993db001f4d510555949d
parent 067ba1b4855ea7ba50964d411bfabb87ddbba706
Author: Christos Margiolis <christos@margiolis.net>
Date:   Tue, 22 Mar 2022 16:46:10 +0200

stuff

Diffstat:
MREADME.md | 5++---
Mconfig.mk | 2+-
Mgraphcurses.1 | 4+++-
Mgraphcurses.c | 21+++++++++------------
4 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/README.md b/README.md @@ -11,13 +11,12 @@ A simple curses graph generator. ## Usage -```shell -$ cd path/to/graphcurses +``` $ make && make run $ make clean # optional ``` -You can install `graphcurses` by running `sudo make install clean`. +You can install `graphcurses` by running `make install`. The binary will be installed at `/usr/local/bin` ## To Do diff --git a/config.mk b/config.mk @@ -8,7 +8,7 @@ MANPREFIX = ${PREFIX}/share/man # includes and libs INCS = -Iinclude -I${PREFIX}/include -LIBS = -Llib -L${PREFIX}/lib -lncursesw -lmatheval -lm +LIBS = -Llib -L${PREFIX}/lib -lcursesw -lmatheval -lm # flags CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L \ diff --git a/graphcurses.1 b/graphcurses.1 @@ -10,7 +10,8 @@ .Nm takes a function as an input and draws it using .Xr curses 3 -to draw the TUI. Functions and derivatives are evaluated by +to draw the TUI. +Functions and derivatives are evaluated by .Xr libmatheval 3 and might use .Xr math 3 @@ -39,6 +40,7 @@ reset zooming to default zoom in .It Sy - zoom out +.El .Sh SEE ALSO .Xr curses 3 , .Xr libmatheval 3 , diff --git a/graphcurses.c b/graphcurses.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include <err.h> +#include <locale.h> #include <math.h> #include <signal.h> #include <stdio.h> @@ -16,7 +17,6 @@ #define SIGWINCH 28 #endif /* SIGWINCH */ #define SHIFT_STEP 1.0f -#define BUFSIZE 256 #define YMAX (getmaxy(stdscr)) #define XMAX (getmaxx(stdscr)) @@ -66,7 +66,7 @@ static void cleanup(void); static struct plane *p; static void *f = NULL; static int colors[] = { - [C_FG] = COLOR_BLUE, + [C_FG] = COLOR_WHITE, [C_F] = COLOR_YELLOW, [C_DF] = COLOR_MAGENTA, }; @@ -91,7 +91,6 @@ cursesinit(void) memset(&sa, 0, sizeof(sa)); sa.sa_handler = sighandler; - sa.sa_flags = SA_RESTART; sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); @@ -101,10 +100,8 @@ cursesinit(void) static void exprvalidate(void) { - char *buf; + char buf[BUFSIZ]; - if ((buf = malloc(BUFSIZE)) == NULL) - err(1, "malloc"); attron(COLOR_PAIR(C_FG)); for (;;) { move(0, 0); @@ -112,12 +109,12 @@ exprvalidate(void) printw("f(x) = "); echo(); refresh(); - if (getnstr(buf, BUFSIZE) == ERR) + if (getnstr(buf, sizeof(buf)) == ERR) continue; zoomrestore(); refresh(); noecho(); - if (!(f = evaluator_create(buf))) + if ((f = evaluator_create(buf)) == NULL) printw("Error in expression! Try again"); else break; @@ -125,13 +122,12 @@ exprvalidate(void) } attroff(COLOR_PAIR(C_FG)); p->df = evaluator_derivative_x(f); - free(buf); } static float expreval(float x) { - return evaluator_evaluate_x(f, x); + return (evaluator_evaluate_x(f, x)); } static void @@ -286,7 +282,7 @@ sighandler(int sig) static void cleanup(void) { - endwin(); + (void)endwin(); evaluator_destroy(f); free(p); } @@ -296,6 +292,7 @@ main(int argc, char *argv[]) { int key = 0; + (void)setlocale(LC_ALL, ""); cursesinit(); planeinit(); exprvalidate(); @@ -351,5 +348,5 @@ main(int argc, char *argv[]) } cleanup(); - return 0; + return (0); }