Notes On Types And Types

2739 Words Nov 21st, 2014 11 Pages
// Martin Jacobs s4304939 - Assignment 4

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <pthread.h>

#define NOCARD '- '
#define NOPLAYER -1

typedef enum {

EXIT_NORMAL = 0, EXIT_USAGE = 1, EXIT_PLAYNAME = 2, EXIT_INVGAME = 3, EXIT_INVSERVP = 4, EXIT_SERVFAILED = 5, EXIT_INVGAMEINFO = 6, EXIT_BADSERVMSG = 7, EXIT_SERVLOSS = 8, EXIT_INPUTEND = 9, EXIT_SYSFAIL = 20

} CRESULT;

/* Exit codes and messages */ void exit_prog(CRESULT r) {

switch(r) { case EXIT_NORMAL: exit(EXIT_NORMAL); case EXIT_INVGAME: fputs("Invalid game name
", stderr); exit(EXIT_INVGAME); case EXIT_USAGE: fputs("Usage: client name game_name port host
", stderr); exit(EXIT_USAGE); case EXIT_PLAYNAME: fputs("Invalid player name
", stderr); exit(EXIT_PLAYNAME); case EXIT_INVSERVP: fputs("Invalid server port
", stderr); exit(EXIT_INVSERVP); case EXIT_INVGAMEINFO: fputs("Invalid game information received from server
", stderr); exit(EXIT_INVGAMEINFO); case EXIT_SERVFAILED: fputs("Server connection failed
", stderr); exit(EXIT_SERVFAILED); case EXIT_BADSERVMSG: fputs("Bad message from server
", stderr); exit(EXIT_BADSERVMSG); case EXIT_SERVLOSS: fputs("Unexpected loss…
Open Document