graphcurses

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

commit 6e548fdc14c3c8445212bd90ed7543af26c65b51
parent b234be2072c8ac88747ba515a7543325f1d3a388
Author: Christos Margiolis <christos@margiolis.net>
Date:   Wed,  2 Sep 2020 18:11:05 +0300

changed brace convention

Diffstat:
Msrc/main.c | 19+++++++------------
Msrc/plane.c | 16++++++----------
Msrc/plane.h | 14+++++++-------
3 files changed, 20 insertions(+), 29 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -5,10 +5,10 @@ static void *f = NULL; static void curses_init(void); -static void func_get(struct Plane *p, char *buf); -static void expression_validate(struct Plane *p); -static float expression_evaluate(float x); -static void keys_handle(struct Plane *p, int key); +static void func_get(struct Plane *, char *); +static void expression_validate(struct Plane *); +static float expression_evaluate(float); +static void keys_handle(struct Plane *, int); int main(int argc, char **argv) @@ -24,9 +24,7 @@ main(int argc, char **argv) expression_validate(&p); p.yfunc = expression_evaluate; - int key = 0; - while (key != 'q') - { + for (key = 0; key != 'q'; key = getch()) { attron(COLOR_PAIR(1)); keys_handle(&p, key); erase(); @@ -39,7 +37,6 @@ main(int argc, char **argv) attroff(COLOR_PAIR(1)); graph_draw(&p); refresh(); - key = getch(); } endwin(); @@ -79,8 +76,7 @@ expression_validate(struct Plane *p) { char *buf = (char *)malloc(BUFFSIZE + sizeof(char)); func_get(p, buf); - while (!(f = evaluator_create(buf))) - { + while (!(f = evaluator_create(buf))) { printw("Error in expression! Try again"); func_get(p, buf); refresh(); @@ -97,8 +93,7 @@ expression_evaluate(float x) void keys_handle(struct Plane *p, int key) { - switch (key) - { + switch (key) { case 'k': case KEY_UP: plane_shift(p, 0.0f, SHIFT_STEP); break; case 'j': case KEY_DOWN: plane_shift(p, 0.0f, -SHIFT_STEP); break; case 'h': case KEY_LEFT: plane_shift(p, -SHIFT_STEP, 0.0f); break; diff --git a/src/plane.c b/src/plane.c @@ -1,9 +1,8 @@ #include "plane.h" -static float plane_scale(float val, float omin, float omax, - float nmin, float nmax); -static void get_step(const struct Plane *p, float *xstep, float *ystep); -static void graph_plot(const struct Plane *p, float x, float y); +static float plane_scale(float, float, float, float, float); +static void get_step(const struct Plane *, float *, float *); +static void graph_plot(const struct Plane *, float, float); void plane_init(struct Plane *p) @@ -73,14 +72,12 @@ axes_draw(const struct Plane *p) float y0 = plane_scale(0.0f, p->ymin, p->ymax, p->ymaxs, 0.0f); float xstep, ystep; get_step(p, &xstep, &ystep); - for (i = 0; i < p->xmaxs; i++) - { + for (i = 0; i < p->xmaxs; i++) { float plotx = p->xmin + xstep * i; int tick = fabs(fmod(plotx, p->xscale)) < xstep; mvaddch(y0, i, tick ? ACS_PLUS : ACS_HLINE); } - for (i = 0; i < p->ymaxs; i++) - { + for (i = 0; i < p->ymaxs; i++) { float ploty = p->ymin + ystep * i; int tick = fabs(fmod(ploty, p->yscale)) < ystep; mvaddch(i, x0, tick ? ACS_PLUS : ACS_VLINE); @@ -94,8 +91,7 @@ graph_draw(const struct Plane *p) float x, xstep, ystep; get_step(p, &xstep, &ystep); attron(COLOR_PAIR(2)); - for (x = p->xmin; x <= p->xmax; x += xstep) - { + for (x = p->xmin; x <= p->xmax; x += xstep) { float y = p->yfunc(x); graph_plot(p, x, y); } diff --git a/src/plane.h b/src/plane.h @@ -18,7 +18,7 @@ #define ZOOM_OUT_FACTOR 1.05f struct Plane { - float (*yfunc)(float x); + float (*yfunc)(float); float ymin, ymax; float xmin, xmax; float xscale, yscale; @@ -27,11 +27,11 @@ struct Plane { extern struct Plane p; -extern void plane_init(struct Plane *p); -extern void plane_shift(struct Plane *p, float xshift, float yshift); -extern void zoom_restore(struct Plane *p); -extern void zoom_handle(struct Plane *p, float factor); -extern void axes_draw(const struct Plane *p); -extern void graph_draw(const struct Plane *p); +extern void plane_init(struct Plane *); +extern void plane_shift(struct Plane *, float, float); +extern void zoom_restore(struct Plane *); +extern void zoom_handle(struct Plane *, float); +extern void axes_draw(const struct Plane *); +extern void graph_draw(const struct Plane *); #endif /* PLANE_H */