int client(int ac, char **av) { int port; int sock; fd_set fd_read; if (ac == 1) s_wait_server(&port, &sock); else if (ac == 3 && ft_isnumber(av[2])) { port = ft_atoi(av[2]); sock = ft_connect(av[1], port); } else return (ft_putendl(USAGE), 1); if (sock == -1) return (1); while (1) { if (ft_get_fd(&fd_read, sock) <= 0) break ; } close(sock); return (0); }
int ft_is_printf(char c) { if (c == '%' || c == 'd' || c == 'D' || c == 'i' || c == 'x' || c == 'X' || c == 's' || c == 'S' || c == 'p' || c == 'c' || c == 'C' || c == 'o' || c == 'O' || c == 'u' || c == 'U' || c == 'f' || c == 'F' || c == 'b' || c == 'B') return (1); if (c == '.' || ft_isnumber(c) || c == '#' || c == '-' || c == '+' || c == ' ' || c == 'l' || c == 'h' || c == 'j' || c == 'z' || c == '!' || c == '*') return (0); return (2); }
int lexer_isnumber(char *str, t_token *token) { int i; if (ft_isdigit(str[0]) != 1) return (0); i = 0; while (str[i] != '\0' && ft_isnumber(str[i]) == 1) i++; token->typetoken = Number; token->str = str; token->size = i; return (1); }
int ft_check_of(t_lpr *stc) { const char *nb; int i; i = 0; nb = ft_itoa((int)stc->of_int); while (nb[i]) { if (!ft_isnumber(nb[i])) return (0); i++; } return (1); }
void normal_execution(t_list *map, t_room *room, t_chain *network) { t_list *begin; begin = map; network = ft_find_way(room); if (network) { while (!ft_isnumber(begin->data)) begin = begin->next; ft_putlist(map); ft_putchar('\n'); ft_resolver(&network, ft_atoi(begin->data), room); } }
void s_wait_server(int *port, int *sock) { char *line; char **spl; line = NULL; ft_putstr("Please choose a server [addr] [port] > "); while (ft_get_next_line(0, &line) > 0) { spl = ft_strsplit(line, ' '); if (ft_strlistlen(spl) == 2 && ft_isnumber(spl[1])) { *port = ft_atoi(spl[1]); *sock = ft_connect(spl[0], *port); if (*sock != -1) { ft_strlistdel(spl); return ; } } ft_putstr("Please choose a server [addr] [port] > "); ft_strlistdel(spl); } }
static int check_command(char *line, int *sock) { char **spl; int port; spl = ft_strsplit(line, ' '); if (ft_strlistlen(spl) > 0 && ft_strcmp(spl[0], "/connect") == '\0') { if (ft_strlistlen(spl) == 3 && ft_isnumber(spl[2])) { close(*sock); *sock = -1; port = ft_atoi(spl[2]); if ((*sock = ft_connect(spl[1], port)) != -1) { ft_strlistdel(spl); return (0); } s_wait_server(&port, sock); } } ft_strlistdel(spl); return (1); }