From 12ccec7c4e1551d3716a315fd2859c372dee5ea8 Mon Sep 17 00:00:00 2001 From: Lennart Buhl Date: Sat, 2 Nov 2013 19:46:24 +0100 Subject: [PATCH 1/5] XD --- src/main.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.h b/src/main.h index 462af4a..c169102 100644 --- a/src/main.h +++ b/src/main.h @@ -8,7 +8,7 @@ // _,-' \%/|% // / / ) __,-- /%\ // \__/_,-'%(% ; %)% -// %\%, %\ -// '--%' -// +// / %\%, %\ +// / '--%' +// / // From 38f2f8d15fb37fe115d77a5ea58d83091e95ea5f Mon Sep 17 00:00:00 2001 From: Lennart Buhl Date: Sat, 2 Nov 2013 19:46:34 +0100 Subject: [PATCH 2/5] fix descriptions --- src/msg.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/msg.h b/src/msg.h index 636d466..ce1a858 100644 --- a/src/msg.h +++ b/src/msg.h @@ -8,8 +8,8 @@ struct message { uint32_t timestamp; - uint32_t width; // varies - uint32_t height; // normally 80 + uint32_t width; // normally 80 + uint32_t height; // normally 25, may vary //char **image; // dimension is width x height char *image; // dimension is width x height From ea6213442046bdba1dd0fb89db3d4cda4951073d Mon Sep 17 00:00:00 2001 From: Lennart Buhl Date: Sat, 2 Nov 2013 19:47:37 +0100 Subject: [PATCH 3/5] model for printing --- src/display.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/display.h | 7 +++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/display.c b/src/display.c index 593c2a1..f93c8b9 100644 --- a/src/display.c +++ b/src/display.c @@ -1,6 +1,47 @@ +#include +#include +#include +#include #include "display.h" + +void setup_display() { + initscr(); // ncurses initialization + curs_set(0); // invisible cursor +} + +void cleanup_display() { + endwin(); // clean ncurses shutdown +} + +/* + image[row][col] >>> image[row*width+col]; + + uint32_t width; // normally 80 + uint32_t height; // normally 25, may vary + char *image; // dimension is width x height +*/ +void print_current_image(message* msg, int start, int end) { + + move(0,0); + char *pic = msg->img; + + for (int row=0; row < 25; row++) { + + char *line = (char*) malloc(81); + strcpy(line, strtok(pic, '\n')); + line[81] = '\0'; + printw("%s", line); + + } + + refresh(); // refresh the screen + +} + + void callback(long tst) { printf("in callback, tst=%ld\n", tst); } + diff --git a/src/display.h b/src/display.h index c671667..736cfe7 100644 --- a/src/display.h +++ b/src/display.h @@ -1,8 +1,11 @@ #ifndef __DISPLAY #define __DISPLAY -#include - +void setup_display(); +void cleanup_display(); void callback(long tst); +void + #endif + From 70da4ca56f671e0e48233b5b429c401520b6ba31 Mon Sep 17 00:00:00 2001 From: Lennart Buhl Date: Sat, 2 Nov 2013 19:51:41 +0100 Subject: [PATCH 4/5] fix bugs and add comments in print_current_image --- src/display.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/display.c b/src/display.c index ed63b7f..b2430b9 100644 --- a/src/display.c +++ b/src/display.c @@ -24,17 +24,16 @@ void cleanup_display() { char *image; // dimension is width x height */ void print_current_image(message* msg, int start, int end) { + // end is ignored and 80 is used, should be considered later - move(0,0); - char *pic = msg->img; + move(0,0); // start in the upper left corner + char *pic = msg->img; // get a ptr to the actual image - for (int row=0; row < 25; row++) { - + for (int row=0; row < 25; row++) { // iterate rows char *line = (char*) malloc(81); - strcpy(line, strtok(pic, '\n')); - line[81] = '\0'; - printw("%s", line); - + strcpy(line, strtok(pic, '\n')); // get a line + line[80] = '\0'; // terminate + printw("%s", line+start); } refresh(); // refresh the screen From fd84b083b10a2e4f4d21acd97a535f1540bca31a Mon Sep 17 00:00:00 2001 From: Lennart Buhl Date: Sat, 2 Nov 2013 19:53:53 +0100 Subject: [PATCH 5/5] shorter constant names in makefile --- Makefile | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 183c8c9..a60e1f5 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,23 @@ CFLAGS=-g -Wall -Wextra -std=gnu99 -BIN_DIR=bin -SRC_DIR=src -TARGET=$(BIN_DIR)/netsl -OBJECTS=$(BIN_DIR)/main.o $(BIN_DIR)/msg.o $(BIN_DIR)/net.o $(BIN_DIR)/display.o +BIN=bin +SRC=src +TARGET=$(BIN)/netsl +OBJECTS=$(BIN)/main.o $(BIN)/msg.o $(BIN)/net.o $(BIN)/display.o -all: $(BIN_DIR) $(TARGET) +all: $(BIN) $(TARGET) -$(BIN_DIR): - mkdir -pv $(BIN_DIR) +$(BIN): + mkdir -pv $(BIN) $(TARGET): $(OBJECTS) gcc $^ -o $(TARGET) -# mkdir -pv $(BIN_DIR) +# mkdir -pv $(BIN) -$(BIN_DIR)/%.o: $(SRC_DIR)/%.c $(SRC_DIR)/%.h +$(BIN)/%.o: $(SRC)/%.c $(SRC)/%.h $(CC) $(CFLAGS) -o $@ -c $< - clean: - rm -rf $(BIN_DIR) - + rm -rf $(BIN)