graphcurses

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

commit 3b65c51be09231776fc11f7cd1c2cd3a3de56173
parent 3e98a7955dda9f0a1bad746f2b64b427b13d3c85
Author: Christos Margiolis <christos@margiolis.net>
Date:   Wed, 21 Oct 2020 13:42:47 +0300

added config.mk and fixed M_PI undeclared error

Diffstat:
MMakefile | 32+++++++-------------------------
MREADME.md | 14+++++---------
Aconfig.mk | 40++++++++++++++++++++++++++++++++++++++++
Mgraphcurses.c | 36++++++++++++++++++++----------------
4 files changed, 72 insertions(+), 50 deletions(-)

diff --git a/Makefile b/Makefile @@ -2,33 +2,15 @@ # graphcurses - an ncurses 2D graph generator .POSIX: +include config.mk + BIN = graphcurses -VERSION = 0.1 DIST = ${BIN}-${VERSION} -MAN1 = ${BIN}.1 -PREFIX = /usr/local -MAN_DIR = ${PREFIX}/man/man1 -BIN_DIR = ${PREFIX}/bin +#MAN1 = ${BIN}.1 -#EXT = c -#SRC = ${wildcard *.${EXT}} -#OBJ = ${SRC:%.${EXT}=%.o} SRC = graphcurses.c OBJ = graphcurses.o -CC = gcc -INCS = -Iinclude -CPPFLAGS = -U__STRICT_ANSI__ -DVERSION=\"${VERSION}\" -CFLAGS = -Wall -std=c99 -pedantic -O3 ${INCS} ${CPPFLAGS} -LDFLAGS = -Llib -lm -lmatheval -lncurses - -CP = cp -f -RM = rm -f -RM_DIR = rm -rf -MKDIR = mkdir -p -TAR = tar -cf -GZIP = gzip - all: options ${BIN} options: @@ -45,7 +27,7 @@ ${OBJ}: ${SRC} dist: clean ${MKDIR} ${DIST} - ${CP} -R ${SRC} LICENSE Makefile README.md ${DIST} + ${CP} -R config.mk ${SRC} LICENSE Makefile README.md ${DIST} ${TAR} ${DIST}.tar ${DIST} ${GZIP} ${DIST}.tar ${RM_DIR} ${DIST} @@ -57,10 +39,10 @@ install: all #${MKDIR} ${DESTDIR}${BIN_DIR} ${DESTDIR}${MAN_DIR} ${MKDIR} ${DESTDIR}${BIN_DIR} ${CP} ${BIN} ${BIN_DIR} - #${CP} ${MAN1} ${DESTDIR}${MAN_DIR} + ${CP} ${MAN1} ${DESTDIR}${MAN_DIR} #sed "s/VERSION/${VERSION}/g" < ${MAN1} > ${DESTDIR}${MAN_DIR}/${MAN1} - chmod 755 ${DESTDIR}${BIN_DIR}/${BIN} - #chmod 644 ${DESTDIR}${MAN_DIR}/${MAN1} + #chmod 755 ${DESTDIR}${BIN_DIR}/${BIN} + chmod 644 ${DESTDIR}${MAN_DIR}/${MAN1} uninstall: ${RM} ${DESTDIR}${BIN_DIR}/${BIN} diff --git a/README.md b/README.md @@ -7,22 +7,18 @@ A simple ncurses graph generator. ## Dependencies * `ncurses` -* `matheval` +* `libmatheval` ## Usage ```shell $ cd path/to/graphcurses -$ make -$ make run -``` -In order to install do -```shell -$ cd path/to/graphcurses -$ sudo make install +$ make && make run $ make clean # optional ``` -The binary will be installed at `/usr/local/bin/` + +You can install `graphcurses` by running `sudo make install clean`. +The binary will be installed at `/usr/local/bin` ## To Do diff --git a/config.mk b/config.mk @@ -0,0 +1,40 @@ +# See LICENSE file for copyright and license details. +# graphcurses version +VERSION = 0 + +# paths +PREFIX = /usr/local +MAN_DIR = ${PREFIX}/man/man1 +BIN_DIR = ${PREFIX}/bin +# uncomment if you're making a library +#MAN_DIR = ${PREFIX}/man/man3 +#INC_DIR = ${PREFIX}/include +#LIB_DIR = ${PREFIX}/lib + +# includes and libs +INCS = -Iinclude +LIBS = -Llib -lm -lmatheval -lncurses + +# flags +CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L \ + -DVERSION=\"${VERSION}\" -U__STRICT_ANSI__ +CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations \ + -O3 ${INCS} ${CPPFLAGS} +LDFLAGS = ${LIBS} +# uncomment if you're making a library +#ARFLAGS = rs + +# utils +CP = cp -f +RM = rm -f +RM_DIR = rm -rf +MV = mv +MKDIR = mkdir -p +RM_DIR = rm -rf +TAR = tar -cf +GZIP = gzip + +# compiler +CC = gcc +# uncomment if you're making a library +#AR = ar diff --git a/graphcurses.c b/graphcurses.c @@ -7,6 +7,10 @@ #include <matheval.h> #include <ncurses.h> +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif /* M_PI */ + #define XMIN_PLANE (-2.0f * M_PI) #define XMAX_PLANE ( 2.0f * M_PI) #define YMIN_PLANE -M_PI @@ -52,20 +56,20 @@ struct Plane { static void *f = NULL; -static void curses_init(void); -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); -static void plane_init(struct Plane *); -static void plane_shift(struct Plane *, float, float); -static void zoom_restore(struct Plane *); -static void zoom_handle(struct Plane *, float); -static void axes_draw(const struct Plane *); -static void graph_draw(const struct Plane *); -static void graph_plot(const struct Plane *, float, float); -static void menu_options(void); -static void menu_fill(struct _win_st *); +static void curses_init(void); +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); +static void plane_init(struct Plane *); +static void plane_shift(struct Plane *, float, float); +static void zoom_restore(struct Plane *); +static void zoom_handle(struct Plane *, float); +static void axes_draw(const struct Plane *); +static void graph_draw(const struct Plane *); +static void graph_plot(const struct Plane *, float, float); +static void menu_options(void); +static void menu_fill(struct _win_st *); void curses_init(void) @@ -100,7 +104,7 @@ expression_validate(struct Plane *p) { char *buf; - if ((buf = (char *)malloc(BUFFSIZE + sizeof(char))) == NULL) { + if ((buf = malloc(BUFFSIZE + sizeof(char))) == NULL) { fputs("Cannot allocate memory. Exiting. . .\n", stderr); exit(EXIT_FAILURE); } @@ -294,7 +298,7 @@ menu_fill(WINDOW *opts) } int -main(int argc, char **argv) +main(int argc, char *argv[]) { #ifndef NCURSES_VERSION fputs("ncurses is needed in order to run this program.\n", stderr);