void init_fractal(t_mlx *e, t_env *w) { if (!(w->win = mlx_new_window(e->mlx, WIN_W, WIN_H, TITLE))) exit_str("Failed to create new window"); if (!(w->img_ptr = mlx_new_image(e->mlx, WIN_W, WIN_H))) exit_str("Failed to create new image"); w->img_addr = mlx_get_data_addr(w->img_ptr, &w->bpp, &w->linesize, &w->endian); if (IS_GPU && (w->linesize != WIN_W * 4 || w->bpp != 32)) { ft_printf_fd(2, "%sERROR:%; %red;Linesize and bpp are not as ", "\x1b[1;31m"); ft_printf_fd(2, "expected in OpenCL init%;\n"); ft_printf_fd(2, "%yellow;Expected : %d and %d\n", WIN_W * 4, 32); ft_printf_fd(2, "Received : %d and %d\n", w->linesize, w->bpp); exit(1); } set_hooks(w); w->e = e; ft_bzero(w->keys, KEYCODE_MAX); init_fractal_values(w); w->colorft = (w->fractalft != newton) ? DEFAULT_COLORFT : color5; w->colorft_num = (w->fractalft != newton) ? DEFAULT_COLORFT_NUM : 5; w->fractalft_num = get_fractalft_num(w); redraw_fractal(*w); }
static int try_opencl_init_next(t_cl *cl) { char buffer[10000]; size_t len; cl->err = clBuildProgram(cl->program, 0, NULL, "-I.", NULL, NULL); if (cl->err != CL_SUCCESS) { cl->err = clGetProgramBuildInfo(cl->program, cl->device_id, CL_PROGRAM_BUILD_LOG, 10000, buffer, &len); if (cl->err == CL_SUCCESS) ft_printf_fd(2, "%red;Compiler error message :%;\n%s\n", buffer); else { ft_printf_fd(2, "%red;Error while retrieving compiler log%;\n"); ft_printf_fd(2, "%red;Try increasing buffer size to 100 000%;\n"); } return (-5); } cl->kernel = clCreateKernel(cl->program, "iterate", &cl->err); if (!cl->kernel || cl->err != CL_SUCCESS) return (-6); cl->output = clCreateBuffer(cl->context, CL_MEM_WRITE_ONLY, WIN_H * WIN_W * 4, NULL, NULL); if (!cl->output) return (-7); return (0); }
int is_correct_varname(char *name, int err, char *cmd) { int i; if (ft_isalpha(*name) == 0) { ft_printf_fd(err, "%s: Variable name must begin with a letter.\n", cmd); return (0); } i = 0; while (name[i]) { if (ft_isalnum(name[i]) == 0) { ft_printf_fd(err, "%s: %s\n", cmd, ERR1); return (0); } i++; } return (1); }
void sc_clear_screen(t_shprop *shell) { t_term *term; int bak_pos; bak_pos = shell->curs_pos; term = shell->term; T_SETMODE("cl"); ft_printf_fd(shell->term->fd, "%s", shell->prompt); if (shell->input) print_line_on_shell(shell, shell->input); while (shell->curs_pos > bak_pos) key_move_left(shell); }
void set_env_array(t_array **array, char *key, char *value, int flag) { t_array *tmp; if (!(tmp = array_get(*array, key))) { tmp = array_init(*array, ft_strjoin(key, value)); if (!*array) *array = tmp; } else tmp->data = ft_strjoin(key, value); if (flag == 1 || flag == 3) ft_strdel(&value); if (flag == 2 || flag == 3) ft_printf_fd(2, "#env setenv: %s\n", tmp->data); }
static char get_option(char *arg) { char option; int i; i = 0; while (arg[++i]) { if (arg[i] == 'L' || arg[i] == 'P') option = arg[i]; else { ft_printf_fd(2, "cd: invalid option: -%c.\n", arg[i]); return (-1); } } return (option); }
void ft_write_encoding(int fd, char **args, char *opcode) { char c; int len; len = ft_tablen(args); c = 0; if (ft_has_encoding(opcode)) { if (len > 0) ft_encode_args(&c, args[0], 0); if (len > 1) ft_encode_args(&c, args[1], 1); if (len > 2) ft_encode_args(&c, args[2], 2); ft_printf_fd(fd, "%c", c); } }
void reprint_all_line(t_shprop *shell) { t_term *term; int bak_pos; term = shell->term; bak_pos = shell->curs_pos; if (shell->input) { T_SETMODE("cr"); T_SETMODE("cd"); ft_printf_fd(shell->term->fd, "%s", shell->prompt); if (shell->input) print_line_on_shell(shell, shell->input); while (shell->curs_pos > bak_pos) key_move_left(shell); } shell->size_changed = 0; }
static void ft_st_putcirc_infos(int argc, t_choice **choice, int y) { int nbr; char *tty; char *tmp; ft_st_cmdgoto(3, y); nbr = ft_st_putchoice(argc, choice, 0); ft_printf_fd("\033[0m%d selected ", isatty(STDOUT_FILENO), nbr); if ((tmp = ttyname(isatty(STDOUT_FILENO))) != NULL) { tmp = ft_strdup(tmp); tty = !ft_strncmp(tmp, "/dev/", 4) ? tmp + 5 : tmp; ft_st_cmdgoto(ft_st_termsize(0) - ft_strlen(tty) - 3, y); ft_putstr_fd(tty, isatty(STDOUT_FILENO)); free(tmp); } return ; }
int main(int ac, char **av) { t_env *env; env = NULL; if (ac < 2) { ft_printf_fd(2, "%s\n", USAGE); return (EXIT_FAILURE); } if ((env = (t_env *)malloc(sizeof(t_env)))) { ft_bzero(env, sizeof(t_env)); ft_init_main(env, ac, av); rt_scene(av[1], env); ft_set_mlx(env->dt); ft_init_vectors(env->dt, 0.5, 0.5); ft_ray_cast_threads(env); mlx_key_hook(env->dt->win, &ft_loop, &env); mlx_expose_hook(env->dt->win, ft_expose, env); mlx_loop(env->dt->conn); } return (EXIT_SUCCESS); }
char *get_next_command(t_shell *shell) { if (shell->edit->prompt) ft_strdel(&(shell->edit)->prompt); shell->edit->prompt = print_prompt(shell, &shell->edit->prompt_len); ft_printf_fd(shell->edit->term->fd, "%s", shell->edit->prompt); if (get_input(shell->edit, &handle_key) == 0) clean_exit(shell->edit->term, 1, shell); if (shell->edit->term->term_name) { while (!is_closed(shell->edit->input, "\"'`([{") && interrupt(-1) == 0) complete_line(shell->edit); } if (!search_in_hist(shell->edit)) { goto_end_list(shell->edit); ft_strdel(&(shell->edit->hist)->line); return (NULL); } hist_update(shell->edit, 0); if (shell->edit->input && interrupt(-1) != 1) append_hist(shell->edit); return (shell->edit->input); }
void ft_write_header(int fd, t_asm *st_asm) { int i; int len; i = rev_int(COREWAR_EXEC_MAGIC); ft_write_int(fd, i); st_asm->header.name = ft_remove_cor(st_asm->header.name); ft_putstr_fd(st_asm->header.name, fd); len = ft_strlen(st_asm->header.name); len = PROG_NAME_LENGTH - len + 4; if (len < 0) ft_error("Name too big", 0, ASM_EXIT); ft_write_blank(len, fd); i = st_asm->header.prog_size; i = rev_int(i); ft_write_int(fd, i); ft_printf_fd(fd, "%s", st_asm->header.comment); len = ft_strlen(st_asm->header.comment); len = COMMENT_LENGTH - len + 4; if (len < 0) ft_error("Comments too big", 0, ASM_EXIT); ft_write_blank(len, fd); }