int load_hole_cube_datas3(t_hole_cube *s, t_bunny_ini *ini, char *scope) { const char *field; if ((field = bunny_ini_get_field(ini, scope, "opacity", 0)) == NULL) return (my_puterr("load_datas: missing hole_cube opacity")); s->opacity = (double)my_getnbr((char *)field) / 100; if ((field = bunny_ini_get_field(ini, scope, "color1", 0)) == NULL) return (my_puterr("load_datas: missing hole_cube color1")); s->color1.full = my_getcolor((char *)field, "0123456789ABCDEF"); if ((field = bunny_ini_get_field(ini, scope, "color2", 0)) == NULL) return (my_puterr("load_datas: missing hole_cube color2")); s->color2.full = my_getcolor((char *)field, "0123456789ABCDEF"); s->tex_name = NULL; s->texture = NULL; if (s->tex_type == IMAGE) { if ((field = bunny_ini_get_field(ini, scope, "texture", 0)) == NULL) return (my_puterr("load_datas: missing hole_cube texture")); s->tex_name = my_strdup((char *)field); if ((s->texture = bunny_load_pixelarray((char *)field)) == NULL) return (my_puterr("load_datas: invalid hole_cube texture1")); } return (0); }
int builtins_fg(int ac, char **av, t_config *conf, int *ret) { change_signal(0); *ret = 0; if (ac == 1 && put_in_foreground(conf->head_job, conf) == -1) { *ret = -1; my_puterr("fg: No current job.\n"); } else if (ac == 2) { if (check_job_and_put_in_foreground(conf->head_job, av[1], conf) == -1) { *ret = -1; my_puterr("fg: No such job.\n"); } } else if (ac != 1) { *ret = -1; my_puterr("fg: No such job.\n"); } change_signal(1); return (MYSH_SIGNAL_NOPE); }
void tcheck_getnbr(t_all *all, int j, int i, int errare) { while (i < j) { if (all->simple_buff[i] < 48 || all->simple_buff[i] > 57) { my_puterr("at the case "); my_put_nbr(i); my_puterr(" there is a wrong char ("); my_putchar_err(all->simple_buff[i]); my_puterr("), please remove-it\n"); errare += 1; } i += 1; } if (errare > 0) { my_puterr("Total of "); my_put_nbr(errare); my_puterr(" error(s) on the first line\n"); free(all->simple_buff); free(all); exit(EXIT_FAILURE); } }
void tcheck_elem_map(t_all *all, int i, int back_n) { while (all->simple_buff[i] != '\n') i += 1; while (all->simple_buff[i] != '\0') { if (all->simple_buff[i] == 10) back_n += 1; if (all->simple_buff[i] != 46 && all->simple_buff[i] != 111 && all->simple_buff[i] != 10) { my_puterr("The map have some wrong chars\n"); free(all->simple_buff); free(all); exit(EXIT_FAILURE); } i += 1; } if ((back_n - 1) != all->lines) { my_puterr("The map have a problem about backslash n\n"); free(all->simple_buff); free(all); exit(EXIT_FAILURE); } }
void my_err_msg_label(labels_t *calls) { my_puterr("Error at line #"); my_put_nbr(calls->line); my_puterr(" -> Label \""); my_puterr(calls->s); my_puterr("\" undefined\n"); }
t_err print_error(t_err error, ...) { char *errors[ERROR_COUNT]; va_list args; if (error == -1) return (error); fill_error_messages(errors); my_puterr("Error: "); va_start(args, error); my_vfprintf(2, errors[error - 1], &args); va_end(args); my_puterr("\n"); return (error); }
char *concatenate(char *str1, char *str2, char separator) { char *result; int i; int a; if (str1 == NULL && str2 == NULL) return (NULL); if (str1 == NULL || str2 == NULL) return ((str1 == NULL) ? strdup(str2) : strdup(str1)); i = 0; a = 0; if ((result = malloc((strlen(str1) + strlen(str2) + 2) * sizeof(char))) == NULL) return (my_puterr("\nMalloc : error\n", NULL)); while (str1[i]) result[a++] = str1[i++]; if (separator != 0) result[a++] = separator; i = 0; while (str2[i]) result[a++] = str2[i++]; result[a] = '\0'; return (result); }
int main(int argc, char **argv, char **env) { t_tetris game; t_list list; bool files; files = true; initialize_struct(&game); initialize_value(&game, argv[0], env); if (argc > 1) options(&game, argc, argv); init_list(&list); files = (!(initialize_files(&list, &game))) ? false : true; if (game.debug == true) mode_debug(&game, list); game.list = list; if (files == true) { if ((game.scene->rows + 2 > (tgetnum("lines"))) || (game.scene->colums + 43 > (tgetnum("cols")))) my_puterr("Terminal too small\n"); else if ((check_one_valid(&list)) == 1) initialize_game(&game); } my_free(&game, &list); endwin(); return (0); }
void tcheck_size_map(t_all *all, int i) { int lines_supposed; int size_supposed; int cols_supposed; int how_back_n; while (all->simple_buff[i] != '\n') { if (all->simple_buff[i] == '\0') no_backslash_n(all); i += 1; } tcheck_getnbr(all, i, 0, 0); lines_supposed = my_getnbr(all->simple_buff, i); cols_supposed = how_cols((i + 1), all->simple_buff); size_supposed = lines_supposed * cols_supposed; how_back_n = (lines_supposed + 1); if (size_supposed != (((int) (all->stati.st_size)) - i) - (how_back_n)) { my_puterr("The map has a problem of size\n"); free(all->simple_buff); free(all); exit(EXIT_FAILURE); } all->lines = lines_supposed; all->cols = cols_supposed; }
void no_backslash_n(t_all *all) { my_puterr("No backslash n\n"); free(all->simple_buff); free(all); exit(EXIT_FAILURE); }
void tcheck_size_map_again(t_all *all) { int i; int z; int start; start = 0; while (all->simple_buff[start] != '\n') start += 1; start += 1; i = 0; z = 0; while (i < all->lines) { if (all->simple_buff[(i * all->cols) + (all->cols + i) + start] == '\n') z += 1; i += 1; } if (z != (all->lines)) { my_puterr("Map invalid\n"); free(all->simple_buff); free(all); exit(EXIT_FAILURE); } }
int help(t_data *data) { pid_t cpid; char *url[3]; url[0] = "firefox"; url[1] = "http://raytracer.strikingly.com/"; url[1] = "http://raytracer.strikingly.com/"; url[2] = NULL; cpid = fork(); if (cpid == 0) { if (execve("/usr/bin/firefox", url, data->itfc.env) == -1) { url[0] = "chromium"; if (execve("/usr/bin/chromium-browser", url, data->itfc.env) == -1) { my_puterr("Could not open firefox nor chormium."); exit (1); } } } return (0); }
static int remind_options_to_user(t_rtc *rtc) { if (rtc->height == 1080) my_putstr("Default height selected : 1080\n"); else { my_putstr("Your selected height : "); my_put_nbr(rtc->height); my_putstr("\n"); } if (rtc->width == 1920) my_putstr("Default width selected : 1920\n"); else { my_putstr("Your selected width : "); my_put_nbr(rtc->width); my_putstr("\n"); } (rtc->fullscreen == 1) ? (my_putstr("Fullscreen : YES\n")) : (my_putstr("Fullscreen : NO\n")); if (rtc->scene_file == NULL) return (my_puterr("Error : No scene file given. Aborting.\n")); else return (parse_obj_file(rtc)); }
int read_file(t_conf *x) { char *s; x->o_list = NULL; x->c_list = NULL; x->list = NULL; x->ptr_beg = NULL; x->ptr_end = NULL; x->b = 0; x->e = 0; x->stack = NULL; if ((x->ants_nb = ret_ants_nb()) <= 0) return (my_puterr(MSG1)); s = nodes_filler(x, 0); rev_list(&x->list); if (links_filler(x, s) == FAIL) return (FAIL); if (chk_begend_links(x) == FAIL) return (FAIL); chk_dblcoord(x->list); chk_dblname(x->list); rev_stack(&x->stack); return (1); }
void *my_malloc(size_t size) { void *ptr; if (!(ptr = bunny_malloc(size))) my_puterr("Malloc Failed !\n"); return (ptr); }
int apply_cylinder(t_data *data) { t_cylinder *cyl; cyl = data->itfc.obj_selected->datas; if (!cyl->texture1 && ((cyl->texture1 = bunny_load_pixelarray ("assets/img/stone3.jpg")) == NULL)) return (my_puterr("load_datas: invalid cylinder texture"), 1); if (!cyl->texture2 && ((cyl->texture2 = bunny_load_pixelarray ("assets/img/stone3.jpg")) == NULL)) return (my_puterr("load_datas: invalid cylinder texture"), 1); cyl->tex_type = IMAGE; data->itfc.past.rad_state = IMG; return (0); }
int init_term(t_core *core, const int ac, char **av) { if (ac >= 1 && (str_cmp(av[1], OPT_TERMCAPS_1) == EQUAL || str_cmp(av[1], OPT_TERMCAPS_2) == EQUAL)) { if (tcgetattr(0, core->term) == ERROR) return (my_puterr(ERR_GTERMC)); if ((core->name_term = get_env(core->env, STR_TERM)) == NULL) { core->is_tcaps = FALSE; return (my_puterr(WAR_NOTERM)); } } else core->is_tcaps = FALSE; return (NO_ERR); }
int load_hole_cube_datas1(t_hole_cube *s, t_bunny_ini *ini, char *scope) { const char *field; if ((field = bunny_ini_get_field(ini, scope, "pos", 0)) == NULL) return (my_puterr("load_datas: missing hole_cube x_pos")); s->pos.x = my_getnbr((char *)field); if ((field = bunny_ini_get_field(ini, scope, "pos", 1)) == NULL) return (my_puterr("load_datas: missing hole_cube y_pos")); s->pos.y = my_getnbr((char *)field); if ((field = bunny_ini_get_field(ini, scope, "pos", 2)) == NULL) return (my_puterr("load_datas: missing hole_cube z_pos")); s->pos.z = my_getnbr((char *)field); if ((field = bunny_ini_get_field(ini, scope, "rot", 0)) == NULL) return (my_puterr("load_datas: missing hole_cube x_rot")); s->rot.x = my_getnbr((char *)field); if ((field = bunny_ini_get_field(ini, scope, "rot", 1)) == NULL) return (my_puterr("load_datas: missing hole_cube y_rot")); s->rot.y = my_getnbr((char *)field); if ((field = bunny_ini_get_field(ini, scope, "rot", 2)) == NULL) return (my_puterr("load_datas: missing hole_cube z_rot")); s->rot.z = my_getnbr((char *)field); if ((field = bunny_ini_get_field(ini, scope, "rad", 0)) == NULL) return (my_puterr("load_datas: missing hole_cube rad")); s->rad = (double)my_getnbr((char *)field); return (load_hole_cube_datas2(s, ini, scope)); }
t_bool print_usage(t_bool err) { if (err) my_puterr(USAGE); else my_putstr(USAGE); return (false); }
void alloc_str(char **str, int size) { *str = malloc(sizeof(*str) * size); if (*str == NULL) { my_puterr("Alloc failed in alloc_str"); exit(1); } }
void alloc_tab(char ***_tab, int size) { *_tab = malloc(sizeof(*_tab) * size); if (*_tab == NULL) { my_puterr("Alloc failed in alloc_str"); exit(1); } }
static void init_core(t_core *core, struct termios *term) { core->shutdown = 0; core->term = term; core->is_tcaps = TRUE; core->cut_tab = NULL; core->packet = NULL; core->name_term = NULL; core->jump = FALSE; core->err_open = NO_ERR; core->buf_caps = NULL; core->jobs = NULL; core->prompt = NULL; core->mods = get_modules(); if (signal(SIGINT, SIG_IGN) == SIG_ERR) my_puterr(ERR_SIGNAL); if (signal(SIGTTOU, SIG_IGN) == SIG_ERR) my_puterr(ERR_SIGNAL); }
static void wait_for_job(t_config *conf, t_job *job) { int status; update_last_use(conf->head_job, job); if (kill(job->pgid, SIGCONT) < 0) my_puterr("Error: kill (SIGCONT)\n"); job->head_process->is_stopped = 0; waitpid(job->pgid, &status, WUNTRACED); if (WIFSTOPPED(status)) job->head_process->is_stopped = 1; else job->head_process->is_finish = 1; signal_display(status); if (tcsetpgrp(STDIN_FILENO, getpgid(getpid())) == -1) my_puterr("Error: tcsetpgrp\n"); if (tcsetattr(STDIN_FILENO, TCSADRAIN, &conf->tmodes) == -1) my_puterr("Error: tcsetattr\n"); }
int check_first_pars(char **src, t_bin *bin, t_pars *pars) { int tmp; if (!src[pars->i] || (tmp = check_wone(src[pars->i], pars->path)) == -1) { my_puterr("Command not Found: "); if (src[pars->i]) my_puterr(src[pars->i]); my_puterr("\n"); while (src[pars->i] && my_strcmp(src[pars->i], "||") != 0) pars->i++; if (!src[pars->i]) return (EXIT_FAILURE); } else if (go_init[tmp].func(src, bin, pars) == -1) return (-1); return (EXIT_SUCCESS); }
int add_redir_next(char **src, t_bin *bin, t_pars *pars, int j) { int tmp; if ((tmp = check_wone(src[pars->i], pars->path)) == 1 || tmp == 3) { my_puterr("Parsing error near '"); my_puterr(src[pars->i]); my_puterr("' \n"); return (-1); } if (add_redir_attribute(src, bin, pars, j) == -1) return (-1); pars->i++; if (src[pars->i]) if (add_redir_checkafter(src, bin, pars) == -1) return (-1); return (EXIT_SUCCESS); }
int wait_game_start() { int cont; t_lemipc *game; cont = 1; printf("Waiting for another team\n"); while (cont) { if ((game = get_game()) == NULL) return (my_puterr("Can't retrieve shared game\n")); if (sem_lock()) return (my_puterr("Can't lock semaphore\n")); cont = should_continue_wait(game); if (sem_unlock()) return (my_puterr("Can't unlock semaphore\n")); release_game(game); } printf("Lets do this !!\n"); return (0); }
int *init_ke(t_map *map, t_paths *path) { int *ke; int i; if ((ke = malloc((map->nb_path + 2) * sizeof(int ))) == NULL) return (my_puterr("Malloc : error\n", NULL)); for (i = 0; i < map->nb_path + 2; i++) ke[i] = 0; ke[0] = path->id; return (ke); }
int load_hole_cube_datas2(t_hole_cube *s, t_bunny_ini *ini, char *scope) { const char *field; if ((field = bunny_ini_get_field(ini, scope, "tex_type", 0)) == NULL) return (my_puterr("load_datas: missing hole_cube type")); s->tex_type = my_getnbr((char *)field); if ((field = bunny_ini_get_field(ini, scope, "ka", 0)) == NULL) return (my_puterr("load_datas: missing hole_cube ambient coef")); s->ka = (double)my_getnbr((char *)field) / 100; if ((field = bunny_ini_get_field(ini, scope, "kd", 0)) == NULL) return (my_puterr("load_datas: missing diffuse coef")); s->kd = (double)my_getnbr((char *)field) / 100; if ((field = bunny_ini_get_field(ini, scope, "ks", 0)) == NULL) return (my_puterr("load_datas: missing hole_cube specular coef")); s->ks = (double)my_getnbr((char *)field) / 100; if ((field = bunny_ini_get_field(ini, scope, "brightness", 0)) == NULL) return (my_puterr("load_datas: missing hole_cube brightness")); s->brightness = (double)my_getnbr((char *)field) / 100; if ((field = bunny_ini_get_field(ini, scope, "reflection", 0)) == NULL) return (my_puterr("load_datas: missing hole_cube reflection")); s->reflection = (double)my_getnbr((char *)field) / 100; return (load_hole_cube_datas3(s, ini, scope)); }
int apply_plan(t_data *data) { t_plan *pla; pla = data->itfc.obj_selected->datas; if (!pla->texture && ((pla->texture = bunny_load_pixelarray ("assets/img/stone3.jpg")) == NULL)) return (my_puterr("load_datas: invalid plane texture"), 1); pla->tex_type = IMAGE; data->itfc.past.rad_state = IMG; return (0); }
int apply_sphere(t_data *data) { t_sphere *sph; sph = data->itfc.obj_selected->datas; if (!sph->texture && ((sph->texture = bunny_load_pixelarray ("assets/img/stone3.jpg")) == NULL)) return (my_puterr("load_datas: invalid sphere texture"), 1); sph->tex_type = IMAGE; data->itfc.past.rad_state = IMG; return (0); }