2023-05-14 17:07:34 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2023-05-14 18:44:47 +02:00
|
|
|
#include <ctype.h>
|
2023-05-14 18:10:44 +02:00
|
|
|
#include <server.h>
|
2023-05-14 22:19:52 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/sem.h>
|
|
|
|
#include <sys/stat.h>
|
2023-05-14 21:44:03 +02:00
|
|
|
|
2023-05-14 18:10:44 +02:00
|
|
|
#include <errExit.h>
|
2023-05-14 17:07:34 +02:00
|
|
|
|
2023-05-14 18:08:10 +02:00
|
|
|
input_server_t check_input(int argc, char *argv[]){
|
2023-05-14 17:07:34 +02:00
|
|
|
if (argc < 5) {
|
2023-05-14 18:44:47 +02:00
|
|
|
printf("\033[92m<Help>\033[39m ./F4Server ROW COL PLAYER1 PLAYER2\n"
|
|
|
|
"\t- ROW \t\tnumber of rows\n"
|
|
|
|
"\t- COL \t\tnumber of rows\n"
|
|
|
|
"\t- PLAYER1 \tplayer one token\n"
|
|
|
|
"\t- PLAYER2 \tplayer two token\n"
|
|
|
|
);
|
2023-05-14 17:31:00 +02:00
|
|
|
exit(EXIT_SUCCESS);
|
2023-05-14 17:07:34 +02:00
|
|
|
} else if (argc > 5) {
|
2023-05-14 17:31:00 +02:00
|
|
|
errExitMsg("To many arguments");
|
2023-05-14 17:07:34 +02:00
|
|
|
}
|
|
|
|
|
2023-05-14 18:08:10 +02:00
|
|
|
input_server_t input = {
|
2023-05-14 17:53:38 +02:00
|
|
|
.collums = atoi(argv[1]),
|
|
|
|
.rows = atoi(argv[2]),
|
2023-05-14 18:03:12 +02:00
|
|
|
.player1Token = argv[3][0],
|
2023-05-14 18:44:47 +02:00
|
|
|
.player2Token = argv[4][0]
|
2023-05-14 17:53:38 +02:00
|
|
|
};
|
2023-05-14 17:07:34 +02:00
|
|
|
|
2023-05-14 17:53:38 +02:00
|
|
|
if (input.collums<5 || input.rows<5) {
|
2023-05-14 17:07:34 +02:00
|
|
|
errExitMsg("To few rows or collums");
|
|
|
|
}
|
|
|
|
|
2023-05-14 18:44:47 +02:00
|
|
|
if (!isprint(input.player1Token) || !isprint(input.player2Token)) {
|
|
|
|
errExitMsg("Invalid player token");
|
2023-05-14 17:07:34 +02:00
|
|
|
}
|
2023-05-14 17:53:38 +02:00
|
|
|
|
|
|
|
return input;
|
2023-05-14 17:07:34 +02:00
|
|
|
}
|