uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

extern.h (828B)


      1 #ifndef _EXTERN_H_
      2 #define _EXTERN_H_
      3 
      4 #define CMD_LEN		32
      5 #define NAME_LEN	32
      6 #define CLIENTS_MAX	64
      7 #define MOVE_TIMEOUT	10
      8 #define BUF_LEN		(BUFSIZ << 2)
      9 #define ARRLEN(x)	(sizeof(x) / sizeof(x[0]))
     10 
     11 enum {
     12 	MOVE_ROCK,
     13 	MOVE_PAPER,
     14 	MOVE_SCISSOR,
     15 };
     16 
     17 static inline int str2move(const char *);
     18 static inline const char *move2str(int);
     19 
     20 static inline int
     21 str2move(const char *str)
     22 {
     23 	if (strcmp(str, "rock") == 0)
     24 		return (MOVE_ROCK);
     25 	else if (strcmp(str, "paper") == 0)
     26 		return (MOVE_PAPER);
     27 	else if (strcmp(str, "scissor") == 0)
     28 		return (MOVE_SCISSOR);
     29 	else
     30 		return (-1);
     31 }
     32 
     33 static inline const char *
     34 move2str(int move)
     35 {
     36 	switch (move) {
     37 	case MOVE_ROCK:
     38 		return ("rock");
     39 	case MOVE_PAPER:
     40 		return ("paper");
     41 	case MOVE_SCISSOR:
     42 		return ("scissor");
     43 	default:
     44 		return ("unknown");
     45 	}
     46 }
     47 
     48 #endif /* _EXTERN_H_ */