forked from scott/threaded_network_chat
refactor done? maybe?
This commit is contained in:
62
main.cc
62
main.cc
@@ -3,6 +3,7 @@
|
|||||||
#include <bits/types/struct_timeval.h>
|
#include <bits/types/struct_timeval.h>
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@@ -25,4 +26,65 @@ main(int argc, char *argv[])
|
|||||||
use_default_colors();
|
use_default_colors();
|
||||||
|
|
||||||
line_position = count_lines(log_path) - LOG_LENGTH + 1;
|
line_position = count_lines(log_path) - LOG_LENGTH + 1;
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case CLIENT_MODE:
|
||||||
|
log_append(log_path, "CLIENT MODE");
|
||||||
|
client_start();
|
||||||
|
break;
|
||||||
|
case SERVER_MODE:
|
||||||
|
log_append(log_path, "SERVER MODE");
|
||||||
|
server_start(listen_port);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto panic_no_mode;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!quit) {
|
||||||
|
file_disp(log_path, line_position, LOG_LENGTH);
|
||||||
|
|
||||||
|
if (count_lines(log_path) > LOG_LENGTH)
|
||||||
|
line_position++;
|
||||||
|
|
||||||
|
/* prompt for input */
|
||||||
|
move(12, 0);
|
||||||
|
printw("> ");
|
||||||
|
|
||||||
|
/* await input */
|
||||||
|
getstr(usr_in);
|
||||||
|
log_append(log_path, usr_in);
|
||||||
|
send(socket_descriptor_client, (char *)usr_in, strlen(usr_in), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Final exit point if everything goes OK */
|
||||||
|
|
||||||
|
endwin();
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case CLIENT_MODE:
|
||||||
|
client_stop();
|
||||||
|
break;
|
||||||
|
case SERVER_MODE:
|
||||||
|
server_stop();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto panic_no_mode;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
panic_no_mode:
|
||||||
|
fprintf(stderr, "-----FATAL ERROR, THIS SHOULD NEVER HAPPEN-----\n");
|
||||||
|
fprintf(stderr, "You may ask yourself... how do I work this?\n");
|
||||||
|
fprintf(stderr, "And you may find yourself... past the point of return 0;!\n");
|
||||||
|
fprintf(stderr, "And you may ask yourself... well, how did I get here?\n");
|
||||||
|
|
||||||
|
if (mode == NO_MODE)
|
||||||
|
fprintf(stderr, "Fatal: Mode was not set!\n");
|
||||||
|
else
|
||||||
|
fprintf(stderr, "Fatal: Mode was set to invalid enum %i\n", mode);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user