dazibao/parser.c

31 lines
833 B
C

#include "parser.h"
// retourne le type de commande à exécuter
cmd_token parse_cmd() {
char buf[198], cmd[5], arg[193];
cmd_token token;
token.type = ERROR;
memset(token.arg, 0, 193);
if(fgets(buf, 198, stdin) == NULL)
return token;
// cmd sera le premier mot rencontré et arg la suite de mots après celui ci, si les deux variables ne sont pas remplies alors il y a une erreur
if(sscanf(buf, "%s %[^\t\n]", cmd, arg) != 2)
return token;
if(strcmp("req", cmd) == 0) {
if(strcmp("neighbour", arg) == 0)
token.type = NEIGHBOUR_REQ;
else if(strcmp("network state", arg) == 0)
token.type = NETWORK_STATE_REQ;
else if(strcmp("node state", arg) == 0)
token.type = NODE_STATE_REQ;
} else if(strcmp("send", cmd) == 0) {
token.type = SEND;
//arg[192] = 0;
strcpy(token.arg, arg);
}
return token;
}