commit e0aed95b7b61fee379c286678ffb956099cef451 Author: structix Date: Mon Nov 27 09:54:08 2017 +0000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d6ff91a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +*.o diff --git a/makefile b/makefile new file mode 100644 index 0000000..0b7fcf4 --- /dev/null +++ b/makefile @@ -0,0 +1,20 @@ +#Infos: http://www.ijon.de/comp/tutorials/makefile.html + + +VERSION = 1.0 +CC = cc +CFLAGS = -Wall -O3 -D_REENTRANT -DVERSION=\"$(VERSION)\" +#LDFLAGS = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread +LDFLAGS = -lncurses + +OBJ = nclock.o + +all: $(OBJ) + $(CC) $(CFLAGS) -o nclock $(OBJ) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -c $< + +.PHONY: clean +clean: + rm -r *.o diff --git a/nclock b/nclock new file mode 100755 index 0000000..53ac569 Binary files /dev/null and b/nclock differ diff --git a/nclock.c b/nclock.c new file mode 100644 index 0000000..f915e64 --- /dev/null +++ b/nclock.c @@ -0,0 +1,44 @@ +#include //ncurses windows +#include //atexit +#include +#include +#include "nclock.h" +#include "numbers.h" +#include + +int main(int argc, char **argv) { + /* enable ncurses standard screen */ + initscr(); + atexit(quitProgram); //cleanup at exit + + state s = {0}; + + initState(&s); + //mvprintw(s.centery, s.centerx, number[5][0]); + //mvprintw(20, 30, number[0][3]); + drawNumber(10,10,4); + getch(); + drawNumber(10,16,2); + getch(); +} + +void quitProgram(void) { + endwin(); +} + +void initState(state *s) { + getmaxyx(stdscr, s->maxy, s->maxx); + s->centery = --s->maxy / 2; + s->centerx = --s->maxx / 2; +} + +void drawNumber(int starty, int startx, int num) { + int i; + for (i = 0; i < 5; i++) { + mvprintw(starty + i, startx, number[num][i]); + } +} + + + + diff --git a/nclock.h b/nclock.h new file mode 100644 index 0000000..d145150 --- /dev/null +++ b/nclock.h @@ -0,0 +1,15 @@ +typedef struct { + int centerx; + int centery; + int maxy; + int maxx; +} state; + + + + +/* Function prototypes */ +void quitProgram(void); +void initState(state *s); +void drawNumber(int starty, int startx, int num); +void drawTime(state *s); diff --git a/numbers.h b/numbers.h new file mode 100644 index 0000000..1bd7447 --- /dev/null +++ b/numbers.h @@ -0,0 +1,83 @@ +const char number[10][5][6] = \ + {\ + { \ + "#####", \ + "# #", \ + "# #", \ + "# #", \ + "#####", \ + }, \ + { \ + " #", \ + " #", \ + " #", \ + " #", \ + " #", + }, \ + { \ + "#####",\ + " #",\ + "#####",\ + "# ",\ + "#####"\ + }, \ + {\ + "#####",\ + " #",\ + " ####",\ + " #",\ + "#####"\ + }, \ + {\ + "# #",\ + "# #", \ + "#####",\ + " #",\ + " #"\ + },\ + {\ + "#####",\ + "# ",\ + "#####",\ + " #",\ + "#####"\ + },\ + {\ + "#####",\ + "# ",\ + "#####",\ + "# #",\ + "#####"\ + },\ + {\ + "#####",\ + " #",\ + " #",\ + " #",\ + " #"\ + }, \ + {\ + "#####",\ + "# #",\ + "#####",\ + "# #",\ + "#####"\ + },\ + {\ + "#####",\ + "# #",\ + "#####",\ + " #",\ + "#####"\ + }\ + }; + + +const char *colon[5] = \ + {\ + " ",\ + " # ",\ + " ",\ + " # ",\ + " "\ + };