void dumpdyn(t_dyn d) { size_t i = 0; ft_fprintf(2, "\t[%zu][%zu][%zu][%zu]\n", d.real, d.used, d.ante, d.post); while (i <= d.real) { ft_fprintf(2, "[%d]", (int)d.str[i]); i++; } ft_fprintf(2, "\n"); }
int ft_fatal(char *str, t_env *e) { ft_fprintf(stderr, "%s: ", e->progname); if (!str) perror(str); else ft_fprintf(stderr, "%s\n", str); if (e->fd > 0) close(e->fd); if (e->file != NULL) munmap(e->file, e->file_size); exit(1); }
void debug_cmd(\ t_cmd cmd) { int i; if (!IS(O_FILEDEBUG, OPT) && !IS(O_DEBUG, OPT)) return ; start_debug("Command"); i = -1; ft_fprintf(FDDEBUG, "Binary: [%s] -> [%s]\n", cmd.arg_v[0], cmd.pathbin); while (cmd.arg_v[++i]) ft_fprintf(FDDEBUG, FMT_ARGV, i, cmd.arg_v[i]); end_debug("Command"); }
unsigned int *buddhabrot(int bailout, int iter) { t_pos *sequence; int n, i, ix, iy; long double x, y; unsigned int *image = (unsigned int *)malloc(BUDDHA_WIN_X * BUDDHA_WIN_Y * sizeof(unsigned int)); sequence = (t_pos *)malloc(sizeof(t_pos) * iter); ft_bzero(sequence, sizeof(t_pos) * iter); ft_bzero(image, sizeof(int) * BUDDHA_WIN_X * BUDDHA_WIN_Y); srand48((unsigned int)time(NULL)); for (int t = 0; t < bailout; t++) { ft_fprintf(2, "Buddhabrot: Processing: %f%%\r", (float)t * 100 / (float)bailout); fflush(stdout); for (int tt = 0; tt < 1000000; tt++) { x = 6 * drand48() - 3; y = 6 * drand48() - 3; if (mandel_iter(iter, x, y, &n, sequence)) { for (i = 0; i < n; i++) { ix = 0.3 * BUDDHA_WIN_X * (sequence[i].x + 0.5) + BUDDHA_WIN_X / 2; iy = 0.3 * BUDDHA_WIN_Y * sequence[i].y + BUDDHA_WIN_Y / 2; if (ix >= 0 && iy >= 0 && ix < BUDDHA_WIN_X && iy < BUDDHA_WIN_Y) image[iy*BUDDHA_WIN_X+ix]++; } } } } return (image); }
static char handle_cwd(\ char **arg_v, char *nwd_path) { char *spec; ft_bzero((void *)nwd_path, sizeof(char) * (FT_SH_CWD_PATH_SIZE + 1)); if (!arg_v[0]) { if (!(spec = intern_getenv("HOME"))) { ft_fprintf(2, (IS(O_COLOR, OPT) ? FMT_COL_NOHOME : FMT_STD_NOHOME)); return (-1); } ft_strcpy(nwd_path, spec); } else if (!ft_strcmp("-", arg_v[0])) { spec = intern_getenv("OLDPWD"); ft_strcpy(nwd_path, (spec ? spec : "")); return (1); } else ft_strcpy(nwd_path, arg_v[0]); if (!isvalid(nwd_path, arg_v)) return (-1); return (0); }
void rl_echo(t_rl *rl) { char buff[2048]; size_t len; if (!rl_checkperf(rl->used, &len)) { if (len) ft_fprintf(1, "%*.*s", len, len, "...[Echo stop here... but line still saving input ;)]"); return ; } if (rl->diff.type == RL_TCURSORONLY) rl_goto(buff, *echo_cursor(), rl->ante_cursor); else { rl_goto(buff, *echo_cursor(), rl->diff.begin); tm_cap("cd"); if (rl->diff.type == RL_TAPPEND) write(1, rl->buffer + rl->diff.begin, rl->diff.offset); if (rl->real != rl->post_cursor) { write(1, rl->buffer + rl->post_cursor, rl->real - rl->post_cursor); rl_last_co(rl->used); } rl_goto(buff, rl->used, rl->ante_cursor); } *echo_cursor() = rl->ante_cursor; }
static void putbinary(\ t_dic *e) { if (!e) return ; ft_fprintf(FDDEBUG, FMT_BINARY_DEBUG, e->id, (char *)e->content); }
static int ft_generate_new_name(void) { static char name[0x10]; size_t i; int fd; i = 0; ft_bzero((void *)name, 0x10); while (i != 10) name[i++] = '0' + rand() % 10; ft_sprintf(name + 10, ".bmp"); if ((fd = open(name, O_WRONLY | O_CREAT, 0777)) <= 0) ft_fprintf(2, "Error while generating new name: %s\n", name); else ft_fprintf(1, "Generating %s... ", name); return (fd); }
static void nofound(\ char *cmd_name) { char *fmt; fmt = (IS(O_COLOR, OPT) ? FMT_CNOFOUND : FMT_NOFOUND); ft_fprintf(2, fmt, AV, MSG_NOFOUND, cmd_name); }
static void display_light_prp(t_light *light, int file) { ft_fprintf("%s :\n", LIGHT); ft_fprintf(file, "\tx : %f \n", light->orig.x); ft_fprintf(file, "\ty : %f \n", light->orig.y); ft_fprintf(file, "\tz : %f \n", light->orig.z); ft_fprintf(file, "\tIntensity : %f \n", light->instens); ft_fprintf(file, "\tRed : %f \n", light->color.red); ft_fprintf(file, "\tGreen : %f \n", light->color.green); ft_fprintf(file, "\tBlue : %f \n", light->color.blue); }
void ft_dicdump(t_dic_entry *dic, int fd) { if (!dic) return ; if (dic->l) ft_dicdump(dic->l, fd); ft_fprintf(fd, "%{%s} : `%s`\n", dic->key, (char *)dic->content); if (dic->r) ft_dicdump(dic->r, fd); }
static bool ft_set_eye(t_env *e) { if (e->scene->cam == 0) { ft_fprintf(2, "There is no eye\n"); return (false); } e->scene->actual_cam = e->scene->cam; return (true); }
int ft_err(char *key, char *msg) { int cp; if (!errno) return (errno); cp = errno; errno = 0; ft_fprintf(2, "%s: %s: %s\n", key, msg, strerror(cp)); return (cp); }
int init_sem(t_env *env) { if ((env->sem_id = semget(env->key, 1, IPC_CREAT | S_IRUSR | S_IWUSR)) <= 0) { ft_fprintf(2, "fail to get semaphore\n"); exit (-1); } if (semctl(env->sem_id, 0, GETPID, 0) == 0) semctl(env->sem_id, 0, SETVAL, 1); return (1); }
void ft_write_arg(t_term *term, t_arg *arg) { ft_move_to(term, arg->position->x, arg->position->y); tputs(tgetstr(TC_CURSOR_INVI, NULL), 0, &ft_write_null); tputs(ft_s_underline(term->cur_arg->content == arg->content), 0, &ft_write_null); tputs(ft_s_inverse(arg->selected), 0, &ft_write_null); ft_fprintf(0, "%s", arg->content); tputs(ft_e_inverse(arg->selected), 0, &ft_write_null); tputs(ft_e_underline(term->cur_arg->content == arg->content), 0, &ft_write_null); }
int ft_err(char *name, char *msg) { char *errno_msg; int errno_cp; if (!(errno_cp = errno)) return (errno_cp); errno = 0; errno_msg = strerror(errno); ft_fprintf(2, "{green}%s{eoc}: {red}%s{eoc}: %s\n", name, msg, errno_msg); return (errno_cp); }
void debug_env(\ void) { int i; if (!IS(O_FILEDEBUG, OPT) && !IS(O_DEBUG, OPT)) return ; start_debug("Environ"); i = 0; while (ENV[i]) ft_fprintf(FDDEBUG, "\t%s\n", ENV[i++]); end_debug("Environ"); }
void debug_builtin(\ void) { int i; if (!IS(O_FILEDEBUG, OPT) && !IS(O_DEBUG, OPT)) return ; start_debug("Builtin"); i = -1; while (++i < FT_SH_BUILTIN_SIZE) ft_fprintf(FDDEBUG, FMT_BUILTIN_DEBUG, BUILTIN[i].id, BUILTIN[i].built); end_debug("Builtin"); }
int hist_save(t_hist *hist) { int fd; if (!(fd = open(".42sh_history", O_WRONLY | O_CREAT, 0755))) return (-1); hist->cursor = hist->list; while (hist->cursor) { ft_fprintf(fd, "%s\n", (char *)hist->cursor->content); hist->cursor = hist->cursor->n; } ft_dlstdel(&hist->list, NULL); close(fd); return (0); }
int evo_key(int key, void *p) { t_env *e; e = (t_env *)p; if (key == QUITKEY) { ft_lstdel(&e->pop, NULL); evo_success(e->av, "evo destroy pop"); mlx_destroy_window(e->mlx, e->win); evo_success(e->av, "mlx destroy window"); evo_success(e->av, "mlx loop"); exit(EXIT_SUCCESS); } ft_fprintf(2, "[%d]\n", key); return (0); }
int exec_stdout_redir(t_tree *root, t_dic_entry *bin) { int fd; if (!root->r) return (1); if (!(fd = open(root->r->content->value.str, O_WRONLY|O_CREAT|O_TRUNC, 0755))) { ft_fprintf(2, "can't open [%s]\n", root->r->content->value.str); return (1); } root->l->cmd.bitset &= ~EX_NOPIPE; root->l->cmd.bitset |= EX_OUTREDIR; root->l->cmd.fd[1][1] = fd; exec_root(root->l, bin); waitpid(-1, NULL, 0); close(fd); return (0); }
static void usage(void) { ft_putendl("fractol help:"); ft_putendl("usage: ./fractol [1-5]"); ft_putendl("1.mandelbrot 2.julia 3.modulo 4.burning_ship 5.multibrot"); ft_putendl("Keys: - - - - - - - - - - - - -"); ft_putendl("B: launch the nebulabrot in a new window"); ft_putendl("C: switch color palette"); ft_putendl("F: switch fractal type"); ft_putendl("P/; increment decrement multibrot roots"); ft_putendl("O/I: increment decrement maximum iterations (2n)"); ft_putendl("X: open current fractal in a new window"); ft_fprintf(1, "%s %s %s %s: move fractal\n", "\u2190", "\u2191", "\u2193", "\u2192"); ft_putendl("LEFT_CLICK MIDDLE_UP: zoom in"); ft_putendl("RIGHT_CLICK MIDDLE_DOWN: zoom out"); ft_putendl("NUMERIC_1: switch render mode"); ft_putendl("ESCAPE: close the current window"); ft_putendl("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); }
int main(void) { t_fract f; t_nebula e; ft_bzero(&f, sizeof(t_fract)); f.mlx = mlx_init(); f.win = mlx_new_window(f.mlx, BUDDHA_WIN_X, BUDDHA_WIN_Y, "buddhabrot"); e.color = &greyscale_color; e.r = buddhabrot(1, 5000); e.g = buddhabrot(500, 500); e.b = buddhabrot(500, 50); e.max_1 = get_max_color(e.r); e.max_2 = get_max_color(e.g); e.max_3 = get_max_color(e.b); convert_int_to_img(&e, &f); ft_fprintf(2, "Buddhabrot: rendering done\nPress [ESCAPE] to quit"); mlx_hook(f.win, KEY_PRESS, KEY_PRESS_MASK, key_hook, &f); mlx_loop(f.mlx); return (0); }
int exec_new_cmd(t_sh *sh, t_tree *root) { char *path; char *key; ft_bzero((void *)root->cmd.bin, 2048); key = root->content->value.str; if ((path = (char *)ft_dicget(sh->bin, key))) { ft_strcpy(root->cmd.bin, path); ft_strcat(root->cmd.bin, "/"); ft_strcat(root->cmd.bin, key); return (0); } if (!ft_strncmp(key, "./", 2)) { ft_strcat(root->cmd.bin, key); return (0); } ft_fprintf(2, "%s: command not found\n", root->content->value.str); return (-1); }
static int cd_usage(void) { ft_fprintf(2, "Illegal option -- P & L\nUsage: cd [-L|P] [rep]\n"); return (-1); }
static void display_cam_prp(t_cam *cam, int file) { ft_fprintf(file, "%s :\n", CAM); ft_fprintf(file, "\tx : %f\n", cam->orig.x); ft_fprintf(file, "\ty : %f\n", cam->orig.y); ft_fprintf(file, "\tz : %f\n", cam->orig.z); ft_fprintf(file, "\tvx -> x : %f \n", cam->vx.x); ft_fprintf(file, "\tvx -> y : %f \n", cam->vx.y); ft_fprintf(file, "\tvx -> z : %f \n", cam->vx.z); ft_fprintf(file, "\tvy -> x : %f \n", cam->vx.x); ft_fprintf(file, "\tvy -> y : %f \n", cam->vx.y); ft_fprintf(file, "\tvy -> z : %f \n", cam->vx.z); ft_fprintf(file, "\tvz -> x : %f \n", cam->vx.x); ft_fprintf(file, "\tvz -> y : %f \n", cam->vx.y); ft_fprintf(file, "\tvz -> z : %f \n", cam->vx.z); }
void ft_write_search(t_term *term) { ft_move_to(term, 0, 0); ft_fprintf(0, FT_SEARCH); }
int main() { /* printf */ printf("%s\n", setlocale(LC_ALL, "")); printf("S**t les zouzous\n"); ft_printf("S**t les zouzous\n"); printf("Hello le nombre est %d\n", 42); ft_printf("Hello le nombre est %d\n", 42); printf("Hello le nombre est %d%d\n", 42, 42); ft_printf("Hello le nombre est %d%d\n", 42, 42); printf("Hello le nombre est decimal %u\n", 42); ft_printf("Hello le nombre est decimal %u\n", 42); printf("Hello le nombre est hexa %x%X\n", 42, 42); ft_printf("Hello le nombre est hexa %x%X\n", 42, 42); printf("Hello le nombre est octal %o\n", 42); ft_printf("Hello le nombre est octal %o\n", 42); printf("Hello la string est %s\n", "Les zouulous !!"); ft_printf("Hello la string est %s\n", "Les zouulous !!"); printf ("中\n"); ft_printf ("中\n"); printf("Hello la string est %s\n", "汉语"); ft_printf("Hello la string est %s\n", "汉语"); printf("Hello la string est %50s\n", "汉语"); ft_printf("Hello la string est %50s\n", "汉语"); printf("Hello la string est %.2s\n", "Allo les terriens"); ft_printf("Hello la string est %.2s\n", "Allo les terriens"); printf("Hello le nombre est %.8d\n", 42); ft_printf("Hello le nombre est %.8d\n", 42); printf("Hello le nombre est field 5 %5d\n", 42); ft_printf("Hello le nombre est field 5 %5d\n", 42); printf("Hello le nombre est space % d\n", 42); ft_printf("Hello le nombre est space % d\n", 42); printf("Hello le nombre est space field 5 % 5d\n", 42); ft_printf("Hello le nombre est space field 5 % 5d\n", 42); printf("Hello le nombre est space 0 field 5 % 05d\n", 42); ft_printf("Hello le nombre est space 0 field 5 % 05d\n", 42); printf("Hello le nombre est space . 105 % .10d\n", 42); ft_printf("Hello le nombre est space . 105 % .10d\n", 42); printf("Hello le nombre est %05d\n", 42); ft_printf("Hello le nombre est %05d\n", 42); printf("Hello le nombre est %+5d\n", 42); ft_printf("Hello le nombre est %+5d\n", 42); printf("Hello le nombre est %+.5d\n", 42); ft_printf("Hello le nombre est %+.5d\n", 42); printf("Hello le nombre est %-5d\n", 42); ft_printf("Hello le nombre est %-5d\n", 42); printf("Hello le nombre est %d\n", -5); ft_printf("Hello le nombre est %d\n", -5); /* fprintf */ fprintf(stderr, "Hello le nombre est %+.5d\n", 42); ft_fprintf(2, "Hello le nombre est %+.5d\n", 42); return (0); }
int ft_err(char *av, char *id, char *msg, int ret) { ft_fprintf(2, "{green|gr}%s{eoc}: {red}%s{eoc}: %s\n", av, id, msg); return (ret); }