graphcurses

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

commit b234be2072c8ac88747ba515a7543325f1d3a388
parent ed0a489a6eabc66c21cefc88ee0c86017471da61
Author: Christos Margiolis <christos@margiolis.net>
Date:   Wed,  2 Sep 2020 15:51:59 +0300

removed private functions from header

Diffstat:
M.gitignore | 0
MMakefile | 6++++--
Msrc/main.c | 14+++++++-------
Msrc/plane.c | 21+++++++++++++--------
Msrc/plane.h | 29+++++++++++++----------------
5 files changed, 37 insertions(+), 33 deletions(-)

diff --git a/.gitignore b/.gitignore diff --git a/Makefile b/Makefile @@ -8,8 +8,10 @@ BIN_DIR = bin SRC = $(wildcard $(SRC_DIR)/*.c) OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) +CP=cp MOVE = mv MKDIR_P = mkdir -p +RM_DIR=rm -rf CC = gcc CPPFLAGS += -Iinclude -pedantic -U__STRICT_ANSI__ @@ -34,7 +36,7 @@ run: ./$(BIN_DIR)/$(TARGET) install: $(TARGET) - cp $(BIN_DIR)/$(TARGET) $(INSTALL_PATH) + $(CP) $(BIN_DIR)/$(TARGET) $(INSTALL_PATH) clean: - $(RM) $(OBJ) $(BIN_DIR)/$(TARGET) + $(RM_DIR) $(OBJ_DIR) $(BIN_DIR) 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(Plane *p, char *buf); -static void expression_validate(Plane *p); +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(Plane *p, int key); +static void keys_handle(struct Plane *p, int key); int main(int argc, char **argv) @@ -18,7 +18,7 @@ main(int argc, char **argv) return EXIT_FAILURE; #endif /* NCURSES_VERSION */ curses_init(); - Plane p; + struct Plane p; plane_init(&p); zoom_restore(&p); expression_validate(&p); @@ -61,7 +61,7 @@ curses_init(void) } void -func_get(Plane *p, char *buf) +func_get(struct Plane *p, char *buf) { move(0, 0); clrtoeol(); @@ -75,7 +75,7 @@ func_get(Plane *p, char *buf) } void -expression_validate(Plane *p) +expression_validate(struct Plane *p) { char *buf = (char *)malloc(BUFFSIZE + sizeof(char)); func_get(p, buf); @@ -95,7 +95,7 @@ expression_evaluate(float x) } void -keys_handle(Plane *p, int key) +keys_handle(struct Plane *p, int key) { switch (key) { diff --git a/src/plane.c b/src/plane.c @@ -1,7 +1,12 @@ #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); + void -plane_init(Plane *p) +plane_init(struct Plane *p) { p->xmin = XMIN_PLANE; p->xmax = XMAX_PLANE; @@ -14,7 +19,7 @@ plane_init(Plane *p) } void -plane_shift(Plane *p, float xshift, float yshift) +plane_shift(struct Plane *p, float xshift, float yshift) { xshift *= (p->xmax - p->xmin) / 16.0f; yshift *= (p->ymax - p->ymin) / 16.0f; @@ -32,7 +37,7 @@ plane_scale(float val, float omin, float omax, float nmin, float nmax) } void -zoom_restore(Plane *p) +zoom_restore(struct Plane *p) { p->xmin = XMIN_PLANE; p->xmax = XMAX_PLANE; @@ -43,7 +48,7 @@ zoom_restore(Plane *p) } void -zoom_handle(Plane *p, float factor) +zoom_handle(struct Plane *p, float factor) { float xctr = (p->xmin + p->ymax) / 2.0f; float yctr = (p->ymin + p->ymax) / 2.0f; @@ -54,14 +59,14 @@ zoom_handle(Plane *p, float factor) } void -get_step(const Plane *p, float *xstep, float *ystep) +get_step(const struct Plane *p, float *xstep, float *ystep) { *xstep = (p->xmax - p->xmin) / (p->xmaxs + 1.0f); *ystep = (p->ymax - p->ymin) / (p->ymaxs + 1.0f); } void -axes_draw(const Plane *p) +axes_draw(const struct Plane *p) { int i; float x0 = plane_scale(0.0f, p->xmin, p->xmax, 0.0f, p->xmaxs); @@ -84,7 +89,7 @@ axes_draw(const Plane *p) } void -graph_draw(const Plane *p) +graph_draw(const struct Plane *p) { float x, xstep, ystep; get_step(p, &xstep, &ystep); @@ -98,7 +103,7 @@ graph_draw(const Plane *p) } void -graph_plot(const Plane *p, float x, float y) +graph_plot(const struct Plane *p, float x, float y) { float xp = plane_scale(x, p->xmin, p->xmax, 0.0f, p->xmaxs); float yp = plane_scale(y, p->ymin, p->ymax, p->ymaxs, 0.0f); diff --git a/src/plane.h b/src/plane.h @@ -17,24 +17,21 @@ #define ZOOM_IN_FACTOR (1.0f / 1.05f) #define ZOOM_OUT_FACTOR 1.05f -typedef struct { +struct Plane { float (*yfunc)(float x); - float ymin, ymax; - float xmin, xmax; - float xscale, yscale; - int ymaxs, xmaxs; -} Plane; + float ymin, ymax; + float xmin, xmax; + float xscale, yscale; + int ymaxs, xmaxs; +}; -extern Plane p; +extern struct Plane p; -extern void plane_init(Plane *p); -extern float plane_scale(float val, float omin, float omax, float nmin, float nmax); -extern void plane_shift(Plane *p, float xshift, float yshift); -extern void zoom_restore(Plane *p); -extern void zoom_handle(Plane *p, float factor); -extern void get_step(const Plane *p, float *xstep, float *ystep); -extern void axes_draw(const Plane *p); -extern void graph_draw(const Plane *p); -extern void graph_plot(const Plane *p, float x, float y); +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); #endif /* PLANE_H */