int ft_putchar(unsigned int c) { if (c < 128) ft_help(c); else if (c < 2048) { ft_help(192 | (c >> 6)); ft_help(128 | (c & 63)); return (2); }
static int ft_setenv_local(t_env *env, char **var_arg) { if (var_arg[0] != NULL && var_arg[1] != NULL) ft_setenv_list(env, var_arg[0], var_arg[1]); else { ft_help(var_arg[0]); return (-1); } ft_display_lst(env, 0); return (0); }
static int ft_setenv_ignore(t_env *env, char **var_arg) { char *env_var; if (var_arg[0] != NULL && var_arg[1] != NULL) ft_setenv_list(env, var_arg[0], var_arg[1]); else { ft_help(var_arg[0]); return (-1); } env_var = ft_find_element(env, var_arg[0]); ft_printf("%s=%s\n", var_arg[0], env_var); return (0); }
int get_next_line(int const fd, char **line) { static t_list *lst; // t_list *lstnow; int end; int i; // lstnow = (t_list *)malloc(sizeof(t_list)); // lst = &lstnow; // lst->next = (t_list *)malloc(sizeof(t_list)); // // lst = lst->next; end = 1; i = 0; // lstnow = &lst; if(!(lst = ft_help(&lst, fd)) || line == NULL || fd < 0 || fd == 1) return (-1); /* if (lstnow != NULL) { end = 2; while (lstnow != NULL && end == 2) { if (lstnow->content_size != fd) lstnow = lstnow->next; else end = 1; } } if (lstnow == NULL) { if (!(lstnow = (t_list*)malloc(sizeof(t_list)))) return (-1); if (!(listnow->content = (ft_strnew(0)))) return (-1); lstnow->content_size = fd; }*/ while ((((char*)lst->content)[i]) != '\n' && (((char*)lst->content)[i]) != '\0') i++; if ((((char*)lst->content)[i]) == '\0') lst->content = ft_alloc_n_read(fd, lst->content, &end); if (end != -1) line = ft_copy((char**)(&(lst->content)), line, &end, 0); // if ((*line) != NULL) // if ((*line)[0] == '\0') // free(*line); return (end); }
static void execcmd(char *buf, int sock) { if (ft_strcmp("quit", buf) == 0) { close(sock); exit(0); } else if (ft_strncmp(buf, "get ", 4) == 0) ft_get(sock, buf); else if (ft_strncmp(buf, "put ", 4) == 0) ft_put(sock, buf); else if (ft_strncmp(buf, "help", 4) == 0) { ft_bzero(buf, 1024); ft_help(); } else ft_putendl("ERROR"); }
void own_command(t_env *env, char **sa, char *s) { if (ft_memcmp(sa[0], "echo", 4) == 0) ft_echo(sa); else if (ft_memcmp(sa[0], "cd", 2) == 0) ft_cd(env, sa); else if (ft_memcmp(sa[0], "setenv", 6) == 0) ft_setenv(env, sa); else if (ft_memcmp(sa[0], "unsetenv", 8) == 0) ft_unsetenv(env, sa); else if (ft_memcmp(sa[0], "env", 3) == 0) call_env(*env, s); else if (ft_memcmp(sa[0], "help", 4) == 0) ft_help(env, sa); else if (ft_memcmp(sa[0], "easter", 6) == 0) easteregg(env, sa); else if (ft_memcmp(sa[0], "history", 7) == 0) list_history(env, sa); else ft_putstr(E_MESS05); FREE_(s); }
int main(int argc, char **argv) { t_data d; if (argc < 2) { ft_putendl_fd("\033[31;1mGimme scenes ! format: [*.sc]\033[0m", 2); ft_help(); return (0); } if (argc > 50) { ft_putendl_fd("\033[31;1mToo many scenes !\033[0m", 2); return (0); } ft_parse_options(&d, argc, argv); ft_set_data(&d); if ((d.init = mlx_init())) { if ((d.win = mlx_new_window(d.init, WX, WY, TITLE))) ft_main_loop(argv, &d); } return (0); }