Curseshelper. structures for settings

This commit is contained in:
2018-03-26 11:50:10 +02:00
parent 6a4b0fd126
commit 6519092f7c
6 changed files with 56 additions and 10 deletions

View File

@@ -9,15 +9,16 @@
#include "config.h" #include "config.h"
#include "sound.h" #include "sound.h"
#include "udpserver.h" #include "udpserver.h"
#include "curseshelper.h"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
const char *short_options = "hsi:l"; const char *short_options = "hsi:lv";
struct option long_options[] = { struct option long_options[] = {
{"server", no_argument, NULL, 's'}, {"server", no_argument, NULL, 's'},
{"ip", required_argument, NULL, 'i'}, {"ip", required_argument, NULL, 'i'},
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
{"local", no_argument, NULL, 'l'} {"local", no_argument, NULL, 'l'},
{"verbose", no_argument, NULL, 'v'}
}; };
int c; int c;
@@ -27,6 +28,8 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
ao_initialize(); ao_initialize();
settings csset = {0};
csset.verbose = 0; //Off by default
while ( (c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1 ) { while ( (c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1 ) {
switch (c) { switch (c) {
@@ -37,12 +40,16 @@ int main(int argc, char *argv[]) {
break; break;
case 'h': case 'h':
//show the help page //show the help page
showHelp(); showHelp(&csset);
break; break;
case 'i': case 'i':
//connect to a csoundbox server //connect to a csoundbox server
inputNetwork(optarg); inputNetwork(optarg);
break; break;
case 'v':
//set a verbose flag
csset.verbose = 1;
break;
case 'l': case 'l':
default: default:
//start local //start local
@@ -110,14 +117,21 @@ void printCursesWelcome(void) {
x /= 2; x /= 2;
const char *msg = "Press enter to exit."; const char *msg = "Press enter to exit.";
const char *msg2 = "Press F1 to kill the server + client"; const char *msg2 = "Press F1 to kill the server + client";
mvprintw(y, x - (strlen(msg) / 2), msg); // mvprintw(y, x - (strlen(msg) / 2), msg);
mvprintw(y + 1, x - (strlen(msg2) / 2), msg2); // 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("-h: Show the help screen and exit\n");
printf("-s: Start the server\n"); printf("-s: Start the server\n");
printf("-i <ip>: connect to a server\n"); printf("-i <ip>: connect to a server\n");
printf("-l or without arguments: Start local\n"); printf("-l or without arguments: Start local\n");
} }

View File

@@ -1,5 +1,5 @@
#include "structures.h"
void inputLocal(void); void inputLocal(void);
void printCursesWelcome(void); void printCursesWelcome(void);
void inputNetwork(char *server); void inputNetwork(char *server);
void showHelp(void); void showHelp(settings *s);

25
curseshelper.c Normal file
View File

@@ -0,0 +1,25 @@
#include <string.h>
#include <ncurses.h>
#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);
}

3
curseshelper.h Normal file
View File

@@ -0,0 +1,3 @@
void printCenter(const char *text);
void printCenterOffset(const char *text, int offsety);

View File

@@ -7,7 +7,7 @@ CFLAGS = -Wall -g -O3 -DVERSION=\"$(VERSION)\"
#LDFLAGS = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread #LDFLAGS = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread
LDFLAGS = -lmpg123 -lao -lconfig -lncurses -lpthread 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) all: $(OBJ)
$(CC) $(CFLAGS) -o csoundbox $(OBJ) $(LDFLAGS) $(CC) $(CFLAGS) -o csoundbox $(OBJ) $(LDFLAGS)

4
structures.h Normal file
View File

@@ -0,0 +1,4 @@
typedef struct {
int verbose;
} settings;