int main(int ac, char **av) { char **tab; if (ac != 4){ my_putstr("wrong parameter number\n"); my_putstr("usage : lenght hight cell number\n"); return (0); } if ((my_getnbr(av[1]) * my_getnbr(av[2])) < my_getnbr(av[3])){ my_putstr("please enter a correct amount of cell (too big)\n"); return (0); } my_pars_args(av, 0); if ((tab = my_tab_remp(av, 0)) == NULL) return (0); tab[my_getnbr(av[2]) + 2] = NULL; tab = my_rand_star(my_getnbr(av[3]), tab, av); print_tab(tab); algo(tab, av); return (0); }
int main(int ac, char **av) { t_ints *ints; t_line line; t_vd vd; t_eq eq; if ((ints = malloc(sizeof(t_ints))) == NULL) return (1); if (ac > 9) arg_sup(ac); if (ac < 9) arg_low(); if (my_getnbr(av[5]) == 0 && my_getnbr(av[6]) == 0 && my_getnbr(av[7]) == 0) check_vec(); if (my_getnbr(av[8]) <= 0) my_check(); check_my_arguments(av); my_intersection(ac, av, ints); free(ints); return (0); }
void get_sizemap() { extern t_client t; char *tmp; int a; send(t.s, "msz\n", 4, 0); t.size = recv(t.s, t.buf, 256, 0); t.buf[t.size] = '\0'; tmp = malloc((my_strlen(t.buf) + 1) * sizeof(*tmp)); for (t.i = 3;t.buf[t.i] != ' ';t.i++); for (a = 0, t.i = t.i++; t.buf[t.i] != ' ';t.i++, a++) tmp[a] = t.buf[t.i]; tmp[a] = '\0'; t.x_map = my_getnbr(tmp); t.x_cam = t.x_map; for (a = 0, t.i = t.i++;t.buf[t.i] != '\0' && t.buf[t.i] != '\n';t.i++, a++) tmp[a] = t.buf[t.i]; tmp[a] = '\0'; t.y_map = my_getnbr(tmp); t.y_cam = t.y_map; }
int depile_all(t_list *op, t_list *nb) { char *operator; char *nb1; char *nb2; char *newval; int inew_val; if (my_list_size(op) > 0) { my_rev_list(&op); my_rev_list(&nb); } while (my_list_size(op) > 0) { nb1 = nb->data; depile(&nb); if (my_list_size(nb)== 0) { my_put_in_list(&nb, "0"); nb2=nb->data; my_string_swap(&nb1,&nb2); } else { nb2=nb->data; } depile(&nb); operator = op->data; depile(&op); inew_val = eval(my_getnbr(nb1), *operator, my_getnbr(nb2)); newval = malloc(sizeof(*newval) * (digit_len(inew_val) + 1)); my_itoa(inew_val, newval); my_put_in_list(&nb, newval); free(newval); } return (my_getnbr(nb->data)); }
int my_matches(int line) { char *buff; int nb; my_putstr("How many do you want to take ? : \n"); if (line == -1) return (-1); buff = get_next_line(0); nb = my_getnbr(buff); if (nb <= 0) /**/ return (-1); return (nb); }
void add_flag(struct grid *grid,char **tmp) { int x; int y; x = my_getnbr(tmp[2]) - 1; y = my_getnbr(tmp[1]) - 1; if (x < 0 || x > grid->x || y < 0 || y > grid->y) my_putstr("Wrong coord.\n"); else { if (grid->cell[x][y].flagged == false) { grid->cell[x][y].flagged = 1; grid->flags++; } else if (grid->cell[x][y].flagged == true) { grid->cell[x][y].flagged = 0; grid->flags--; } } }
int server_client_core(t_client *client) { int rtrn; char buffer[1024]; if ((rtrn = recv(client->sock, buffer, 1024, 0)) <= 0) return (EXIT_FAILURE); buffer[rtrn] = '\0'; client->core = my_getnbr(buffer); printf("[*] Raytracer: Clustering: CORE Receive [%d] from %s:%d.\n", \ client->core, inet_ntoa(client->csin->sin_addr), \ htons(client->csin->sin_port)); return (EXIT_SUCCESS); }
int live(char *param, int fdwrite, char code) { int nb; if (write(fdwrite, &code, 1) == -1) return (-1); nb = my_getnbr(¶m[1]); nb = swap_nbr(nb); if (write(fdwrite, &nb, 4) == -1) return (-1); return (5); }
int parser(t_box *tab, char *str, int it) { int i; if (it == 1) i = 0; else if (it == 2) i = 1; tab->nb[0] = my_getnbr(str); str = str + my_int_len(tab->nb[0]); tab->sign[0] = str[0]; str = str + 2; while (str[0] != ')') { tab->nb[i] = my_getnbr(str); str = str + my_int_len(tab->nb[i]); tab->sign[i] = str[0]; i = i + 1; str = str + 1; } exec(tab, it); return (0); }
int get_args(t_arg *arg, char *nb, int *i, char *tmp) { if ((arg->size = agregate(nb, i, tmp)) != 2) tmp++; arg->value = my_getnbr(tmp); if (arg->size == 4) arg->value = swap_nbr(arg->value); else if (arg->size == 2) arg->value = swap_shnbr(arg->value); return (arg->size); }
void get_precision(char *format, int *i, int *chars_written) { if (format[*i] == '.') { *chars_written += 1; *i += 1; g_precision = my_getnbr(&format[*i]); while (format[*i] >= '0' && format[*i] <= '9') { *i += 1; *chars_written += 1; } } }
void write2_conf(t_struct *st, char *str) { char *file; char *tmp; int nb; file = str_nb(st->map_sel); tmp = get_file_content(str); nb = my_getnbr(tmp); free(tmp); if (st->map_sel > nb) write_in(str, file); free(file); }
int parseSize(const char *str, t_game *game) { int i; int j; int row; int col; char *tmp; str += 11; i = 0; j = 0; while (str[i] && str[i] != ',' && ++i); if (!(tmp = malloc(sizeof(char) * (i + 1)))) return (1); while (j < i && (tmp[j] = str[j]) && ++j); tmp[i] = '\0'; str += ++i; if (!BETWEEN((row = my_getnbr(tmp)), MIN_ROW, MAX_ROW) || !BETWEEN((col = my_getnbr(str)), MIN_COL, MAX_COL)) return (free(tmp), write(2, "Incorrect size\n", 15), 1); game->height = row; game->width = col; return (free(tmp), 0); }
int init_game(t_player *player, int argc, char **argv) { if (argc < 1 || argc > 2) return (exit_prog("USAGE: ./allum1 [matches]\n")); if (argv[1]) { if ((player->nb_matches = my_getnbr(argv[1])) == 0) return (exit_prog("Error : tu dois au moins mettre une allumette(s)\n")); if (player->nb_matches > 100) return (exit_prog("Matches must be <= 100\n")); } else player->nb_matches = 4; return (0); }
int my_get_keys(char **str, int *keys, int flag) { if (!flag) { keys[0] = my_getnbr(str[2]); keys[1] = my_getnbr(str[3]); keys[2] = my_getnbr(str[4]); keys[3] = my_getnbr(str[5]); } else { keys[0] = my_getnbr(str[5]); keys[1] = -my_getnbr(str[4]); keys[2] = -my_getnbr(str[3]); keys[3] = my_getnbr(str[2]); } }
void my_write_ld(char *args, t_size *p, int fd, t_lab *lab) { char reg; char **args_tab; args_tab = my_str_to_wordtab(args, ","); p->len += write(fd, &op_tab[1].code, 1); reg = encode_octet(args); p->len += write(fd, ®, 1); write_ld_first(args_tab[0], p, fd, lab); if (args_tab[1][0] == 'r') args_tab[1]++; reg = my_getnbr(args_tab[1]); p->len += write(fd, ®, 1); }
int get_number(void) { int nbr; char buffer[11]; int len; echo_mode(SET); raw_mode(UNSET); my_printf("\ngive number : "); if ((len = read(0, buffer, 10)) < 0) return (ERROR); buffer[len] = 0; nbr = my_getnbr(buffer); return (nbr); }
void resolv(int *i, char **tabstring, t_list **op, t_list **nb) { char *save; int new_val; char *str; my_putstr("O_o"); my_put_in_list(op, tabstring[*i]); *i =*i + 1; if (is_operator(tabstring[*i]) == 0) my_put_in_list(nb, tabstring[*i]); if (is_operator(tabstring[*i]) == 3) my_put_in_list(nb, parenthesis_mode(i, tabstring)); save =(*nb)->data; depile(nb); my_putstr("O_o"); if (my_list_size(*(nb)) == 0) my_put_in_list(nb, "0"); new_val = eval(my_getnbr((*nb)->data), *(*op)->data, my_getnbr(save)); depile(op); depile(nb); str = malloc(sizeof(*str) * (digit_len(new_val) + 1)); my_itoa(new_val, str); my_put_in_list(nb, str); }
int step_one(int *remove_line, int *tab, int tab_size, char *buff) { if (my_str_isnum(buff) == -1) { my_putstr("Error: You must have to enter positive numbers only !\n"); my_putstr("On which line would you want to remove matches ? "); return (0); } if (my_getnbr(buff) > 0 && my_getnbr(buff) <= tab_size) { if (tab[my_getnbr(buff) - 1] == 0) { my_putstr("Error: there is no matches in this line !\n"); my_putstr("On which line would you want to remove matches ? "); return (0); } *remove_line = my_getnbr(buff) - 1; my_putstr("How many matches do you want to remove ? "); return (1); } my_putstr("Error: The line specified does not exist !\n"); my_putstr("On which line would you want to remove matches ? "); return (0); }
t_scene *parsing_ground_setting(t_scene *scene, t_bunny_ini *ini, char *name) { char *str; if ((str = (char *)bunny_ini_get_field(ini, name, "scene_nb_x_case", 0)) == NULL) return (my_puterror_scene("Error: ", name, ":scene_nb_x_case field ", 1, " not found\n")); if ((scene->size.x = my_getnbr(str)) < 0) return (my_puterror_scene("Error ", name, ":scene_nb_x_case field ", 1, " should not be negative\n")); if ((str = (char *)bunny_ini_get_field(ini, name, "scene_nb_y_case", 0)) == NULL) return (my_puterror_scene("Error: ", name, ":scene_nb_y_case field ", 1, " not found\n")); if ((scene->size.y = my_getnbr(str)) < 0) return (my_puterror_scene("Error ", name, ":scene_nb_y_case field ", 1, " should not be negative\n")); return (scene); }
int my_line(int line) { char *buff; int nb; my_putstr("Enter a number of line : "); buff = get_next_line(0); nb = my_getnbr(buff); if (nb <= 0 || nb > line) { my_putstr("Line error\n"); return (-1); } return (nb); }
int add_registre_and(int *args, char *arg, int c) { char *number; int c2; int c3; c2 = 1; c3 = 0; number = xmalloc(sizeof(char) * (my_strlen(arg) + 1)); while (arg[c2]) number[c3++] = arg[c2++]; number[c3] = '\0'; args[c++] = my_getnbr(number); return (c); }
int complete_lim_max(FILE *fd, t_coordonne *lim) { char *tmp; char **tab; int size_tab; if ((tmp = get_line(fd)) == NULL) return (error("Sorry, obj[lim][undeclared] error\n")); tab = my_str_to_word_tab(&size_tab, tmp, ' '); if (size_tab != 4) return (error_parsing(tmp, "Sorry, lim[nb_arg] error at this line : ")); if (my_strcmp(tab[0], "lim_max") != 0) { my_putstr("Sorry, function call[lim]"); return (error_parsing(tmp, "error at this line : ")); } lim->x = my_getnbr(tab[1]); lim->y = my_getnbr(tab[2]); lim->z = my_getnbr(tab[3]); free_tab(tab, size_tab); free(tmp); return (SUCCES); }
char *check_and_or_xor_param(char *file_cor, char *cmd, t_cmd *cmd_oct, t_list **call_label) { int i; i = cmd_oct->i; while (cmd[++i] && cmd[i] != ','); if (cmd[++i] != 'r' && cmd[i] != '%') file_cor = my_write_octets(file_cor, 2, my_getnbr(&cmd[i]), cmd_oct->k); if (cmd[i] == 'r') file_cor = my_write_octets(file_cor, 1, my_getnbr(&cmd[i + 1]), cmd_oct->k); if (cmd[i] == DIRECT_CHAR) { if (cmd[i + 1] == LABEL_CHAR) fill_call_label(call_label, &cmd[i + 2], *cmd_oct->k - cmd_oct->size_cmd, *cmd_oct->k); file_cor = my_write_octets(file_cor, DIR_SIZE, my_getnbr(&cmd[i + 1]), cmd_oct->k); } while (cmd[++i] && cmd[i] != ','); file_cor = my_write_octets(file_cor, 1, my_getnbr(&cmd[i + 2]), cmd_oct->k); return (file_cor); }
int my_str_isnum(char *str) { int i; i = 0; while (str[i] != '\0') { if (str[i] < '0' || str[i] > '9') { my_putstr("Error: invalid input (positive number expected)\n"); return (-1); } i += 1; } return (my_getnbr(str)); }
int recup_nb_history(char *str) { char buff[10]; int indice; indice = 0; while (indice < 8 && str[indice] != '\0') { if (str[indice] < '0' || str[indice] > '9') return (-1); buff[indice] = str[indice]; indice = indice + 1; } buff[indice] = '\0'; return (my_getnbr(buff)); }
int main(int argc, char **argv) { int i; t_list list; if (argc < 2) return (0); i = 1; init_list(&list); while (i <= argc - 1) { add_nb(&list, my_getnbr(argv[i])); i++; } print_list(&list); return (0); }
int parse_thread(t_info *inf, char **tab, int *i) { static int present; if (tab[*i] && !my_strcmp("-t", tab[*i])) { if (present) return (-1); inf->nbr_thread = (tab[(*i) + 1]) ? my_getnbr(tab[++(*i)]) : \ (sysconf(_SC_NPROCESSORS_CONF)); inf->nbr_thread = (inf->nbr_thread <= 0) ? 1 : inf->nbr_thread; (*i) += 1; present++; return (1); } return (0); }
static int check_n(t_program *prgm, int i, int argc, const char **argv) { if (my_match(argv[i], "-n")) { if (prgm->player_id != -1) return (error_int(RET_FAILURE, ERR_N_REPEAT)); if (i + 1 < argc) { if (!my_str_isnum(argv[i + 1]) || (prgm->player_id = my_getnbr(argv[i + 1])) < 0) return (error_int(RET_ERROR, ERR_N_INVALID_VAL)); } else return (error_int(RET_FAILURE, ERR_N_NO_VAL)); } return (RET_SUCCESS); }
int option(char **av, int *indice, int *option) { int i; i = -1; *indice = *indice + 1; if (av[*indice] != NULL) { while (av[*indice][++i]) if (isnum(av[*indice][i]) && av[*indice][i] != '-') return (1); *option= my_getnbr(av[*indice]); *indice = *indice + 1; return (0); } return (1); }