Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. #include "server.h"
  2.  
  3. static char     (*g_cmd[13]) = {
  4.         "FORWARD",
  5.         "RIGHT",
  6.         "LEFT",
  7.         "LOOK",
  8.         "INVENTORY",
  9.         "BROADCAST TEXT",
  10.         "CONNECT_NBR",
  11.         "FORK",
  12.         "EJECT",
  13.         "TAKE OBJECT",
  14.         "SET OBJECT",
  15.         "INCANTATION",
  16.         NULL
  17. };
  18.  
  19. static void     (*g_func[13])(t_env *, int, s_server *) = {
  20.         &c_forward,
  21.         &c_right,
  22.         &c_left,
  23.         &c_look,
  24.         &c_inventory,
  25.         &c_broadcast,
  26.         &c_connect,
  27.         &c_fork,
  28.         &c_eject,
  29.         &c_take,
  30.         &c_set,
  31.         &c_incantation,
  32.         NULL
  33. };
  34.  
  35. void    c_set(t_env *e, int fd, s_server *s)
  36. {
  37.         (void)e;
  38.         (void)fd;
  39.         (void)s;
  40.         printf("set\n");
  41. }
  42.  
  43. void    c_incantation(t_env *e, int fd, s_server *s)
  44. {
  45.         (void)e;
  46.         (void)fd;
  47.         (void)s;
  48.         printf("incantation\n");
  49. }
  50.  
  51. bool    interpreter(t_env *e, char *str, int fd, s_server *s)
  52. {
  53.         char    *cmd = strdup(str);
  54.         int     i = 0;
  55.  
  56.         for (i = 0; g_cmd[i] != NULL; i++) {
  57.                 if (equal(cmd, g_cmd[i])) {
  58.                         g_func[i](e, fd, s);
  59.             return true;
  60.                 }
  61.         }
  62.         return false;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement