commit 822895e0be32336e97b8afb42efe81de4ed905ea
parent ad15460f1bcc0cf807e79f19de8b19b3801d66db
Author: Christos Margiolis <christos@margiolis.net>
Date: Fri, 16 Oct 2020 19:48:43 +0300
defined menu opts as constants
Diffstat:
3 files changed, 54 insertions(+), 31 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,20 +1,22 @@
+# See LICENSE file for copyright and license details.
+
BIN = graphcurses
VERSION = 0.1
DIST = ${BIN}-${VERSION}
MAN1 = ${BIN}.1
PREFIX = /usr/local
MAN_DIR = ${PREFIX}/man/man1
-BIN_DIR = ${PREFIX}bin
+BIN_DIR = ${PREFIX}/bin
EXT = c
SRC = ${wildcard *.${EXT}}
OBJ = ${SRC:%.${EXT}=%.o}
CC = gcc
-CPPFLAGS += -Iinclude -U__STRICT_ANSI__ -DVERSION=\"${VERSION}\"
-CFLAGS += -Wall -std=c99 -pedantic -O3
-LDFLAGS += -Llib
-LDLIBS += -lm -lmatheval -lncurses
+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
@@ -23,13 +25,19 @@ MKDIR = mkdir -p
TAR = tar -cf
GZIP = gzip
-all: ${BIN}
+all: options ${BIN}
+
+options:
+ @echo ${BIN} build options:
+ @echo "CFLAGS = ${CFLAGS}"
+ @echo "LDFLAGS = ${LDFLAGS}"
+ @echo "CC = ${CC}"
${BIN}: ${OBJ}
- ${CC} ${LDFLAGS} $^ ${LDLIBS} -o $@
+ ${CC} ${LDFLAGS} $^ -o $@
%.o: %.${EXT}
- ${CC} ${CPPFLAGS} ${CFLAGS} -c $< -o $@
+ ${CC} ${CFLAGS} -c $< -o $@
dist: clean
${MKDIR} ${DIST}
@@ -42,18 +50,19 @@ run:
./${BIN}
install: all
- ${MKDIR} ${DESTDIR}${BIN_DIR} ${DESTDIR}${MAN_DIR}
+ #${MKDIR} ${DESTDIR}${BIN_DIR} ${DESTDIR}${MAN_DIR}
+ ${MKDIR} ${DESTDIR}${BIN_DIR}
${CP} ${BIN} ${BIN_DIR}
- ${CP} ${MAN1} ${DESTDIR}${MAN_DIR}
- sed "s/VERSION/${VERSION}/g" < ${MAN1} > ${DESTDIR}${MAN_DIR}/${MAN1}
- chmod 644 ${DESTDIR}${BIN_DIR}/${BIN}
- chmod 644 ${DESTDIR}${MAN_DIR}/${MAN1}
+ #${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}
-uninstall: all
+uninstall:
${RM} ${DESTDIR}${BIN_DIR}/${BIN}
- ${RM} ${DESTDIR}${MAN_DIR}/${MAN1}
+ #${RM} ${DESTDIR}${MAN_DIR}/${MAN1}
clean:
- ${RM} ${OBJ} ${BIN}
+ ${RM} ${BIN} ${OBJ} ${DIST}.tar.gz
-.PHONY: all clean dist install uninstall run
+.PHONY: all options clean dist install uninstall run
diff --git a/README.md b/README.md
@@ -19,7 +19,6 @@ $ make run
In order to install do
```shell
$ cd path/to/graphcurses
-$ make
$ sudo make install
$ make clean # optional
```
diff --git a/graphcurses.c b/graphcurses.c
@@ -1,9 +1,12 @@
+/* See LICENSE file for copyright and license details. */
+
#include <math.h>
-#include <matheval.h>
-#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
+#include <matheval.h>
+#include <ncurses.h>
+
#define XMIN_PLANE (-2.0f * M_PI)
#define XMAX_PLANE ( 2.0f * M_PI)
#define YMIN_PLANE -M_PI
@@ -25,6 +28,18 @@
#define PLANE_YSTEP(p, ystep) \
ystep = (p->xmax - p->ymin) / (p->ymaxs + 1.0f);
+#define OPT_QUIT "q Quit"
+#define OPT_MOVE_UP "Up/k Move up"
+#define OPT_MOVE_DOWN "Down/j Move down"
+#define OPT_MOVE_LEFT "Left/h Move left"
+#define OPT_MOVE_RIGHT "Right/l Move right"
+#define OPT_SHOW_DERIVATIVE "d Show derivative"
+#define OPT_NEW_FUNCTION "f New function"
+#define OPT_RESTORE_ZOOM "r Restore zoom"
+#define OPT_ZOOM_IN "+ Zoom in"
+#define OPT_ZOOM_OUT "- Zoom out"
+#define MSG_QUIT_MENU "Press any key to quit the menu"
+
struct Plane {
float (*f)(float);
void *df;
@@ -231,17 +246,17 @@ menu_options(void)
void
menu_fill(WINDOW *opts)
{
- mvwprintw(opts, 1, 1, "q Quit");
- mvwprintw(opts, 2, 1, "Up/k Move up");
- mvwprintw(opts, 3, 1, "Down/j Move down");
- mvwprintw(opts, 4, 1, "Left/h Move left");
- mvwprintw(opts, 5, 1, "Right/l Move right");
- mvwprintw(opts, 6, 1, "d Show derivative");
- mvwprintw(opts, 7, 1, "f New function");
- mvwprintw(opts, 8, 1, "r Restore zoom");
- mvwprintw(opts, 9, 1, "+ Zoom in");
- mvwprintw(opts, 10, 1, "- Zoom out");
- mvwprintw(opts, 12, 1, "Press any key to quit the menu");
+ mvwprintw(opts, 1, 1, OPT_QUIT);
+ mvwprintw(opts, 2, 1, OPT_MOVE_UP);
+ mvwprintw(opts, 3, 1, OPT_MOVE_DOWN);
+ mvwprintw(opts, 4, 1, OPT_MOVE_LEFT);
+ mvwprintw(opts, 5, 1, OPT_MOVE_RIGHT);
+ mvwprintw(opts, 6, 1, OPT_SHOW_DERIVATIVE);
+ mvwprintw(opts, 7, 1, OPT_NEW_FUNCTION);
+ mvwprintw(opts, 8, 1, OPT_RESTORE_ZOOM);
+ mvwprintw(opts, 9, 1, OPT_ZOOM_IN);
+ mvwprintw(opts, 10, 1, OPT_ZOOM_OUT);
+ mvwprintw(opts, 12, 1, MSG_QUIT_MENU);
}
int