diff --git a/csoundbox.c b/csoundbox.c index 6876d2f..1e83057 100644 --- a/csoundbox.c +++ b/csoundbox.c @@ -9,15 +9,16 @@ #include "config.h" #include "sound.h" #include "udpserver.h" - +#include "curseshelper.h" int main(int argc, char *argv[]) { - const char *short_options = "hsi:l"; + const char *short_options = "hsi:lv"; struct option long_options[] = { {"server", no_argument, NULL, 's'}, {"ip", required_argument, NULL, 'i'}, {"help", no_argument, NULL, 'h'}, - {"local", no_argument, NULL, 'l'} + {"local", no_argument, NULL, 'l'}, + {"verbose", no_argument, NULL, 'v'} }; int c; @@ -27,6 +28,8 @@ int main(int argc, char *argv[]) { return 0; } ao_initialize(); + settings csset = {0}; + csset.verbose = 0; //Off by default while ( (c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1 ) { switch (c) { @@ -37,12 +40,16 @@ int main(int argc, char *argv[]) { break; case 'h': //show the help page - showHelp(); + showHelp(&csset); break; case 'i': //connect to a csoundbox server inputNetwork(optarg); break; + case 'v': + //set a verbose flag + csset.verbose = 1; + break; case 'l': default: //start local @@ -110,14 +117,21 @@ void printCursesWelcome(void) { x /= 2; const char *msg = "Press enter to exit."; const char *msg2 = "Press F1 to kill the server + client"; - mvprintw(y, x - (strlen(msg) / 2), msg); - mvprintw(y + 1, x - (strlen(msg2) / 2), msg2); +// mvprintw(y, x - (strlen(msg) / 2), msg); +// mvprintw(y + 1, x - (strlen(msg2) / 2), msg2); + printCenter(msg); + printCenterOffset(msg2, 2); + } -void showHelp(void) { +void showHelp(settings *s) { + if (s->verbose) { + printf("Test\n"); + } printf("-h: Show the help screen and exit\n"); printf("-s: Start the server\n"); printf("-i : connect to a server\n"); printf("-l or without arguments: Start local\n"); + } diff --git a/csoundbox.h b/csoundbox.h index e896561..f5b1ff2 100644 --- a/csoundbox.h +++ b/csoundbox.h @@ -1,5 +1,5 @@ - +#include "structures.h" void inputLocal(void); void printCursesWelcome(void); void inputNetwork(char *server); -void showHelp(void); +void showHelp(settings *s); diff --git a/curseshelper.c b/curseshelper.c new file mode 100644 index 0000000..7890f25 --- /dev/null +++ b/curseshelper.c @@ -0,0 +1,25 @@ +#include +#include +#include "curseshelper.h" + +void printCenter(const char *text) { + int x, y; + getmaxyx(stdscr, y, x); + + int centery = --y / 2; + int centerx = (--x - (strlen(text) / 2)) / 2; + + mvprintw(centery, centerx, text); +} + + + +void printCenterOffset(const char *text, int offsety) { + int x, y; + getmaxyx(stdscr, y, x); + + int centery = (--y + offsety) / 2; + int centerx = (--x - (strlen(text) / 2)) / 2; + + mvprintw(centery, centerx, text); +} diff --git a/curseshelper.h b/curseshelper.h new file mode 100644 index 0000000..ba284f8 --- /dev/null +++ b/curseshelper.h @@ -0,0 +1,3 @@ + +void printCenter(const char *text); +void printCenterOffset(const char *text, int offsety); diff --git a/makefile b/makefile index ad00810..367d5fe 100644 --- a/makefile +++ b/makefile @@ -7,7 +7,7 @@ CFLAGS = -Wall -g -O3 -DVERSION=\"$(VERSION)\" #LDFLAGS = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread LDFLAGS = -lmpg123 -lao -lconfig -lncurses -lpthread -OBJ = csoundbox.o config.o sound.o udpserver.o +OBJ = csoundbox.o config.o sound.o udpserver.o curseshelper.o all: $(OBJ) $(CC) $(CFLAGS) -o csoundbox $(OBJ) $(LDFLAGS) diff --git a/structures.h b/structures.h new file mode 100644 index 0000000..3c2dbe5 --- /dev/null +++ b/structures.h @@ -0,0 +1,4 @@ + +typedef struct { + int verbose; +} settings;