tt

A terminal-based typing game
git clone git://pcardenasb.com/tt
Log | Files | Refs | README | LICENSE

commit aae695b7e274c999ca1da85e181df7db7638cb3e
parent b3d6da5c2f700d7a3e563dfd6b2c5e15ae8c0cb5
Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe>
Date:   Mon, 24 Jun 2024 16:24:39 -0500

Added proper Makefile

Diffstat:
MMakefile | 36+++++++++++++++++++++++++++++-------
Aconfig.mk | 21+++++++++++++++++++++
Mtt.h | 2--
Mttcli.c | 14+++++---------
Mttsrv.c | 2+-
5 files changed, 56 insertions(+), 19 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,13 +1,35 @@ -CFLAGS = -g -Wall -Wextra -Werror -Wpedantic -LDFLAGS = `pkg-config --libs ncurses` `pkg-config --libs json-c` +.POSIX: -all: ttcli ttsrv +include config.mk -ttcli.o: tt.h +SRC = ttcli.c ttsrv.c +OBJ = $(SRC:.c=.o) +BIN = $(SRC:.c=) -ttsrv.o: tt.h +all: $(BIN) + +$(OBJ): tt.h config.mk + +.c.o: + $(CC) $(TTCFLAGS) -c $< + +.o: + $(CC) -o $@ $< $(TTLDFLAGS) clean: - rm -f ttcli.o ttcli ttsrv.o ttsrv + rm -f $(OBJ) $(BIN) tt-$(VERSION).tar.gz + +dist: clean + mkdir -p tt-$(VERSION) + cp -R README.md config.mk Makefile tt.h $(SRC) tt-$(VERSION) + tar -czf tt-$(VERSION).tar.gz tt-$(VERSION) + rm -rf tt-$(VERSION) + +install: + mkdir -p $(DESTDIR)$(PREFIX)/bin + install -m 755 $(BIN) $(DESTDIR)$(PREFIX)/bin + +uninstall: + cd $(DESTDIR)$(PREFIX)/bin; rm -f $(BIN) -.PHONY: all clean +.PHONY: all clean dist install uninstall diff --git a/config.mk b/config.mk @@ -0,0 +1,21 @@ +# tt version +VERSION = 0.1.0 + +# Customize below to fit your system + +# paths +PREFIX = /usr/local +MANPREFIX = $(PREFIX)/share/man + +PKG_CONFIG = pkg-config + +# includes and libs +INCS = `$(PKG_CONFIG) --cflags ncurses` \ + `$(PKG_CONFIG) --cflags json-c` +LIBS = `$(PKG_CONFIG) --libs ncurses` \ + `$(PKG_CONFIG) --libs json-c` + +# flags +TTCPPFLAGS = -DVERSION=\"$(VERSION)\" $(CPPFLAGS) +TTCFLAGS = $(INCS) $(CPPFLAGS) $(CFLAGS) +TTLDFLAGS = $(LIBS) $(LDFLAGS) diff --git a/tt.h b/tt.h @@ -1,7 +1,5 @@ #pragma once -#define NAME_LENGHT 14 - struct state { unsigned short pos; }; diff --git a/ttcli.c b/ttcli.c @@ -62,7 +62,6 @@ void print_text( mvwprintw(win, 9, 24, " WPM: %.0f", (pos / 5.0) / (elapsed / 60.0)); mvwprintw(win, 10, 24, "Errors: %d", count_errors); mvwprintw(win, 11, 24, " Slows: %d", count_slows); - wrefresh(win); struct timespec current; clock_gettime(CLOCK_REALTIME, &current); @@ -259,7 +258,7 @@ int main(int argc, const char *argv[]) FD_SET(sockfd, &writefds); } - struct timeval select_timeout = {1, 500000}; + struct timeval select_timeout = {1, 200000}; select(FD_SETSIZE, &readfds, &writefds, NULL, &select_timeout); if (FD_ISSET(0, &readfds)) { @@ -327,7 +326,7 @@ int main(int argc, const char *argv[]) void *buffer; switch (recv_step) { case 0: - // HEADER + // TYPE buffer_length = 1; buffer = &header_type; break; @@ -359,9 +358,11 @@ int main(int argc, const char *argv[]) switch (recv_step) { case 0: + // MESSAGE recv_step = 1; break; case 1: + // LENGTH if (header_length == 0) { recv_step = 0; } else { @@ -370,6 +371,7 @@ int main(int argc, const char *argv[]) break; case 2: + // MESSAGE recv_step = 0; if (header_type == 0) { length = recv_length; @@ -405,11 +407,6 @@ int main(int argc, const char *argv[]) } else if (header_type == 1) { num_players = header_length / (sizeof(struct state)); - mvprintw( - 20, - 0, - "num_players = %d", - num_players); } break; } @@ -421,7 +418,6 @@ int main(int argc, const char *argv[]) }; send(sockfd, &state, sizeof state, 0); outdated = 0; - mvprintw(19, 0, "sent %d", pos); } print_text( diff --git a/ttsrv.c b/ttsrv.c @@ -1,5 +1,5 @@ #include "tt.h" -#include <json-c/json.h> +#include <json.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h>