char *get_next_line(int const fd) { static char *tmp; char *buf; char *size; int ret; tmp = (tmp ? tmp : ft_strdup("")); if (fd < 0 || BUFF_SIZE < 1) return (ft_exit(&tmp)); buf = ft_strnew(BUFF_SIZE + 1); if (!buf) return (ft_exit(&tmp)); while (!(size = ft_strchr(tmp, '\n')) && (ret = read(fd, buf, BUFF_SIZE))) { buf[ret] = 0; tmp = ft_strcleanjoin(tmp, buf); } ft_free(&buf); if (tmp[0] && (size || (size = ft_strrchr(tmp, 0)))) { buf = ft_strsub(tmp, 0, size - tmp); ft_free(&tmp); tmp = (size[0] ? ft_strdup(size + 1) : ft_strdup("")); return (buf); } return (ft_exit(&tmp)); }
static void ft_handle(int num) { t_select *select; char ch[2]; if (num == SIGINT) ft_exit(); else if (num == SIGTSTP) { signal(SIGTSTP, SIG_DFL); select = ft_save_and_load(NULL, 1); ft_reset_term_behavior(&(select->term)); ch[0] = select->term.c_cc[VSUSP]; ch[1] = '\0'; ioctl(0, TIOCSTI, ch); } else if (num == SIGCONT) { signal(SIGTSTP, ft_handle); select = ft_save_and_load(NULL, 1); ft_change_term_behavior(&(select->term)); ft_print_list(select); } else if (num == SIGWINCH) ft_win_change(); else ft_exit(); }
void check_border(t_map *map) { int i; i = 0; while (i < map->nb_col) { if (map->tab[0][i] == 0) ft_exit(); i++; } i = 0; while (i < map->nb_col) { if (map->tab[map->nb_line - 1][i] == 0) ft_exit(); i++; } i = 0; while (i < map->nb_line) map->tab[i][0] == 0 ? ft_exit() : i++; i = 0; while (i < map->nb_line) map->tab[i][map->nb_col - 1] == 0 ? ft_exit() : i++; }
int main(int ac, char **av) { t_env e; int fd; char *line; char *map; line = NULL; map = ft_strnew(0); if (ac == 2) { e.filename = av[1]; fd = open(av[1], O_RDONLY); if (fd < 1) ft_exit("Bad file descriptor"); while (get_next_line(fd, &line) > 0) { map = ft_strjoin(map, ft_strjoin(line, "\n")); free(line); e.nline++; } close(fd); } else ft_exit("Usage: ./fdf <path to map>"); ft_open_win(&e, map); return (0); }
char *autocomp_word(char *str, char *path) { struct dirent *rd; DIR *rep; int i; char **tb; i = -1; if (!str) return (ft_select(autocomp_all(path))); if ((i = get_tab_size(path, str) == 0)) return (str); if (!(tb = (char**)malloc(sizeof(char*) * i + 1))) ft_exit("Malloc error"); if (!(rep = opendir(path))) ft_exit("Opendir failed"); i = -1; while ((rd = readdir(rep))) if (!(ft_strncmp(str, rd->d_name, ft_strlen(str)))) tb[++i] = ft_strdup(rd->d_name); if (i == -1) { ft_arrfree(&tb); return (str); } tb[i + 1] = NULL; closedir(rep); if (tb[1] && tb[1][0] == '\0') return (tb[0]); return (ft_select(tb)); }
void command_pwd(t_client *client) { char *current; if (!(current = malloc(PATH_MAX + 1))) ft_exit("server: can't malloc", EXIT_FAILURE); ft_bzero(current, PATH_MAX + 1); if (!getcwd(current, PATH_MAX)) ft_exit("server: can't malloc", EXIT_FAILURE); current = current + ft_strlen(client->origin_path); current[ft_strlen(current)] = '/'; write_str(client, current); free(current - ft_strlen(client->origin_path)); }
static char *get_file_name(char *file) { char *tmp; tmp = ft_strrchr(file, '/'); if (!tmp) { if (!(tmp = ft_strdup(file))) ft_exit("client: strdup failed", EXIT_FAILURE); return (tmp); } if (!(tmp = ft_strdup(tmp + 1))) ft_exit("client: strdup failed", EXIT_FAILURE); return (tmp); }
int main(int ac, char **av) { if (ac != 2) (ac > 2) ? (ft_exit("\033[31mToo many parameters\n")) : (ft_exit("\033[31mNot enough parameters\n")); if (av[1][ft_strlen(av[1]) - 3] == '.' && av[1][ft_strlen(av[1]) - 2] == 'r' && av[1][ft_strlen(av[1]) - 1] == 't') { gtk_init(&ac, &av); create_window(av[1]); } else ft_exit("\033[31mFiles must have .rt extension\n"); return (0); }
void check_for_errors(t_corps *corps, char *filename) { if ((corps->next = open(filename, O_RDONLY)) == -1) ft_exit("error"); if ((corps->vread = read(corps->next, corps->buff, BUFF_SIZE)) == -1 || corps->vread == 546) ft_exit("error"); if ((close(corps->next)) == -1) ft_exit("error"); if (((corps->vread + 1) % 21) != 0 || ft_strstr(corps->buff, "\n\n\n") != NULL) ft_exit("error"); if ((corps->tetri_tab = ft_strsplit(corps->buff, '\n')) == NULL) ft_exit("error"); }
void parsing_objects(int fd, char *object, t_env *rt) { char *line; char **tab; int tmp; tmp = 0; init_name(rt, object); while (get_next_line(fd, &line) > 0 && line[0]) { tmp = 1; tab = ft_strsplit(line, ' '); if ((ft_strcmp(tab[0], "radius") && ft_strcmp(tab[0], "pos") && ft_strcmp(tab[0], "color") && ft_strcmp(tab[0], "angle") && ft_strcmp(tab[0], "a") && ft_strcmp(tab[0], "b") && ft_strcmp(tab[0], "c") && ft_strcmp(tab[0], "material") && ft_strcmp(tab[0], "separation")) || !tab[2]) ft_exit("\033[31mMissing parameter for an object\n"); parsing_options(tab, rt, rt->i_obj); parsing_options2(tab, rt, rt->i_obj); tab_free(tab); ft_strdel(&line); } if (tmp) ft_strdel(&line); rt->i_obj++; }
int ft_enter(t_param *p, t_list *list, t_termios *term) { t_list *tmp; int i; i = 0; tmp = list->next; ft_clear_area(); i = 0; ft_putendl("--> [ liste selectionner ] <---\n"); while (i < p->count + 1) { if (tmp->valid) { ft_printf("[%s] ", tmp->data); p->nb_elt += 1; } tmp = tmp->next; i++; } if (p->nb_elt == 0) ft_putstr("Aucun element selectionner"); ft_putendl("\n\n-------------------------------"); ft_exit(p, list, term); }
int main(int argc, char **argv) { char buffer[547]; char **map; char save[16][16]; char tab[27]; int cpt[4]; if (argc != 2) ft_ragequit(); ft_file(argv[1], buffer, tab); map = ft_debut(cpt, save, tab); while (cpt[0] == 1 && cpt[1] >= cpt[2]) { cpt[0] = ft_treatment(map, save, tab, 1); cpt[3] = 0; while (cpt[1] > cpt[2] && !cpt[3] && cpt[0] == 2) { cpt[1]--; map = ft_init(cpt[1]); cpt[3] = ft_test_point(map); cpt[0] = 1; } } ft_exit(save, ft_len_save(save)); return (0); }
void load_obj(t_object *obj, char *filename) { int fd; char *line; ft_exit((fd = open(filename, O_RDONLY)) < 0, "Can't read file"); obj->vertex_buffer_size = obj->index_buffer_size = obj->normal_buffer_size = obj->tex_buffer_size = 0; while (get_next_line(fd, &line) > 0) { if (ft_strlen(line) < 3 || line[0] == '#') ; else if (line[0] == 'o') ft_strcpy((char *)obj->name, line + 2); else if (line[0] == 'v' && line[1] == ' ') load_vertex(obj, line + 1); else if (line[0] == 'v' && line[1] == 'n') load_normal(obj, line + 2); else if (line[0] == 'v' && line[1] == 't') load_tex(obj, line + 2); else if (line[0] == 'f' && line[1] == ' ') load_index(obj, line + 1); ft_memdel((void **)&line); } close(fd); print_obj(obj); }
void ft_parse_input(t_shun **shell) { if (*(*shell)->input) { (*shell)->argv = ft_parse_get_args((*shell)->input); (*shell)->argc = ft_tablen((*shell)->argv); if ((*shell)->argc != 0) { if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "exit") == 0) ft_exit(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "env") == 0) ft_print_environ(*shell); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "setenv") == 0) ft_setenv(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "unsetenv") == 0) ft_unsetenv(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "cd") == 0) ft_cd(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "prompt") == 0) ft_chg_prompt(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "pwd") == 0) ft_putendl(ft_get_pwd()); else ft_exec_bin(&(*shell)); } } }
void exiting (void *args) { ft_thread_cooperate_n (10); fprintf (stdout, "running\n"); ft_exit (); fprintf (stdout, "should not appear!!!!!\n"); }
t_l_a *ft_pushlast(t_control *list, int nb) { t_l_a *node; node = (t_l_a *)malloc(sizeof(*node)); if (list == NULL || !node) ft_exit("Error\n"); node->nb = nb; if (list->lasta == NULL) { list->firsta = node; list->lasta = node; node->prev = node; } else { list->lasta->next = node; list->firsta->prev = node; node->prev = list->lasta; list->lasta = node; } node->next = list->firsta; list->sizea += 1; return (node); }
static void check_cmd2(char **str, t_env *e) { int stat; pid_t fat; char *ret; ret = NULL; if (str[0] && ft_strcmp(str[0], "cd") == 0) ft_cd(str[1], e); else if (str[0] && ft_strcmp(str[0], "env") == 0) print_env(e->env); else if (str[0] && ft_strcmp(str[0], "exit") == 0) ft_exit(str); else if (str[0] && (ret = pathsys(str[0], e)) != NULL) { fat = fork(); if (fat != -1) { if (fat == 0) execve(ret, str, e->env); else waitpid(fat, &stat, 0); } if (WIFSIGNALED(stat)) ft_wrong_exit(e->shell, WTERMSIG(stat), ret); } safe_free(ret); }
int distrib_buttons(int i, char **result, char *buffer, int *v) { if (buffer[0] == 10) return (-2); else if (buffer[0] == 27 && buffer[1] == 91) i = distrib_arrow(i, result, buffer, v); else if (buffer[0] == 127) *result = del_c(*result, &i); else if (buffer[0] == 9 && *result && i == ft_strlen(*result)) i = distrib_tab(i, result); else if (buffer[0] == 12) clear_and_prompt(); else if (buffer[0] == 1) i = ctrl_a(i, result); else if (buffer[0] == 5) i = ctrl_k(i, result); else if (buffer[0] == 21) { clear_line(i + 1, ft_strlen(*result)); *result = NULL; i = 0; } else if (buffer[0] == 4) ft_exit(NULL); else ft_putstr(tgetstr("le", NULL)); return (i); }
void ft_usage(char *name, char *usage) { ft_putstr(name); ft_putstr(" : usage : "); ft_putstr(usage); ft_exit(0); }
int keycode_fun_quit(t_env *env) { debug_stdout("INIT", FILE_LINE_FUN); ft_exit(env, EXIT_SUCCESS, NULL, NULL); debug_stdout("END", FILE_LINE_FUN); return (EXIT_SUCCESS); }
void ft_tmblk(char *file) { t_varf v; v.i = 0; v.nblines = 0; v.contact = 0; v.blk = 0; while (file[v.i]) { if (v.nblines < 4) { if (file[v.i] == '\n') v.nblines++; if (file[v.i] == '#') v.blk++; } if (v.nblines == 4) { if (v.blk != 4) ft_exit(); v.blk = 0; v.nblines = 0; v.i++; } v.i++; } }
void ft_init_incantation(t_env *env) { int i; i = 0; env->incantation = NULL; if (!(env->incantation = (int **)malloc(sizeof(int *) * NB_LEVEL))) ft_exit("incation init fail."); while (i < NB_LEVEL) { if (!(env->incantation[i] = (int *)malloc(sizeof(int) * NB_STUFF))) ft_exit("incation init fail."); i++; } st_init(env); }
int main(int argc, char **argv) { char BUF[547]; char **map; char save[16][16]; char tab[27]; char end; int taille; int cpt; if (argc != 2) ft_ragequit(); ft_bzero(tab, 27); ft_file(argv[1], BUF); ft_erreur(BUF); ft_search(BUF, tab); taille = ft_sqrt(8 * tab[0]); map = ft_init(taille); ft_clean(save, 15); cpt = 1; end = 0; while (end == 0 && taille >= ft_sqrt(4 * tab[0])) { end = ft_treatment(map, save, tab, cpt); if (taille > ft_sqrt(4 * tab[0])) { taille--; map = ft_init(taille); cpt = ft_try_copy(map, save, taille); } } ft_exit(save, ft_len_save(save)); return (0); }
void ft_del_arg(t_dlist *arg, t_dlist_node *node, struct termios term) { int i; i = 0; if (node == node->next) { write(arg->fd, "101\n", 4); arg->head = NULL; arg->tail = NULL; free(node); free(arg); ft_exit(NULL, term); } else { node->prev->next = node->next; node->next->prev = node->prev; } if (arg->tail == node) arg->tail = node->prev; if (arg->head == node) arg->head = node->next; arg->size--; free(node); ft_select(arg, term); }
int main(void) { t_game game; if (!(WIN_VALUE % 2) && initscr()) { glob = &game; init(&game); setwins(&game); score_init(&game); while ((game.size = menu(&game) + 3) > 5) put_score(&game); if (game.size > 3 && game.size < 6) { set_plateau(&game); if (start(&game)) put_msg(game.msgbar, " GAME BEGIN", 2); play(&game); refresh(); } ft_exit("ya", &game); } else ft_putendl("Game_2048: Initialisation failed."); return (0); }
int ft_event_key(int key, t_env *env) { if (key == KEY_ESCAPE) ft_exit(&env->mlx); else if (key == ARROW_UP || key == ARROW_DOWN || key == ARROW_RIGHT || key == ARROW_LEFT) ft_move_mandelbrot(key, env); else if (key == 113) printf(C_GREEN"On lit les donnees : zoom{%d}, iterate{%d} X1{%f} X2{%f} Y1{%f} Y2{%f}"C_NONE"\n", env->fract.zoom, env->fract.iterate, env->fract.area.xy1.x, env->fract.area.xy2.x, env->fract.area.xy1.y, env->fract.area.xy2.y); else if (key == 49) env->fract.cst_zoom = 0.5; else if (key == 50) env->fract.cst_zoom = 0.1; else if (key == 51) env->fract.cst_zoom = 0.01; else if (key == 52) env->fract.cst_zoom = 0.001; else if (key == 48) { ft_bzero(env->mlx.data, env->mlx.sizeline * env->height); ft_bzero(env->mlx.data_tmp, env->mlx.sizeline * env->height); ft_mandelbrot(env->fract, env); } printf(C_GREEN"On lit les donnees : key{%d}\n", key); return (0); }
int main (void) { int i; ft_thread_t thread_array[MAX_THREADS]; in_sched = ft_scheduler_create(); out_sched = ft_scheduler_create(); new_input = ft_event_create(in_sched); new_output = ft_event_create(out_sched); ft_thread_create(in_sched, traceinstants, NULL, (void *)50); for (i=0; i<MAX_THREADS; i++) { thread_array[i] = ft_thread_create(in_sched, process, NULL, (void *) &i); } ft_thread_create(in_sched, produce, NULL, NULL); ft_thread_create(out_sched, consume, NULL, NULL); ft_scheduler_start(in_sched); ft_scheduler_start(out_sched); ft_exit(); return 0; }
int st_wrong_params(void) { ft_putstr_fd("Usage: ./serveur -p <port> -x <width> -y <height> -n ", 2); ft_putendl_fd("<team> [<team>] [<team>] ... -c <nb> -t <t>", 2); ft_exit("Pars Error."); return (ERR); }
int main(int ac, char **av) { if (ac < 3) ft_exit("\033[1;33mUsage : ./client <ip> <port> [nickname]\033[0m\n"); init_client(ac, av); return (0); }
static void init_socks(t_socket sock, fd_set *rdfs) { FD_ZERO(rdfs); FD_SET(STDIN_FILENO, rdfs); FD_SET(sock, rdfs); if (select(sock + 1, rdfs, NULL, NULL, NULL) == -1) ft_exit("Select error\n"); }