int newwire(t_li *li, char *line) { t_wire *elem; char **tab; tab = ft_strsplit(line, '-'); if (!getroombyname(li, tab[0]) || !getroombyname(li, tab[1])) { ft_tabfree(tab); return (0); } elem = (t_wire*)malloc(sizeof(t_wire)); elem->a = getroomptr(li, tab[0], elem, 0); elem->b = getroomptr(li, tab[1], elem, 1); elem->antpass = 0; ft_tabfree(tab); if (!elem->a || !elem->b) { ft_printf("newwire return 0"); return (0); } elem->power = -1; elem->next = NULL; addwire(li, elem); return (1); }
int main(int argc, char **argv, char **envp) { t_ftsh *sh; sh = NULL; sh = intialize_sh(argc, argv, envp); if (!sh) { ft_putendl_fd("Error : could'nt initialize shell", 2); return (1); } while (1) { catch_signals(); if (sh->line) free(sh->line); sh->line = NULL; write(1, sh->prompt, ft_strlen(sh->prompt)); if ((sh->line = get_command_line()) != NULL) { sh->ret = execute_command_line(sh, &(sh->env_dup)); ft_tabfree(sh->path_dir); sh->path_dir = extract_path_directories(sh->env_dup); } else exit(1); } }
int put_client(int sock, char *cmd) { char **tab; int fd; tab = ft_strsplit(cmd, ' '); if (!tab[1]) return (client_error(-2)); fd = open(tab[1], O_RDONLY); if (fd == -1) return (client_error(-3)); send(sock, cmd, ft_strlen(cmd), 0); file_to_sock(sock, fd); printf("SUCCESS: file %s has been sent to server\n", tab[1]); ft_tabfree(&tab); return (0); }
void increment_shlvl(char ***env) { int n; char **str; if (get_in_env(*env, "SHLVL")) { n = ft_atoi(get_in_env(*env, "SHLVL")); str = ft_memalloc(sizeof(char*) * 3); str[0] = ft_strdup("setenv"); str[1] = ft_strnew(20); str[1] = ft_strcat(str[1], "SHLVL="); str[1] = ft_strcat(str[1], ft_itoa(++n)); builtin_setenv(str, env); ft_tabfree(str); } }
char *ft_strrepchrbystr(char *str, char c, char *rep) { char **split; char *out; if (str[0] == c) { if (str[1]) out = ft_strjoin(rep, &str[1]); else out = rep; return (out); } split = ft_strsplit(str, ' '); out = ft_repchrbystrwhile(split, rep, c); ft_tabfree(split); return (out); }
static int add_variable_to_env(char *av, char ***env) { char **new_env; int len; int x; x = 0; len = ft_tablen(*env); if (!(new_env = (char**)ft_memalloc(sizeof(char*) * (len + 2)))) return (-1); while ((*env)[x]) { new_env[x] = ft_strdup((*env)[x]); x++; } new_env[x] = ft_strdup(av); ft_tabfree(*env); *env = new_env; return (0); }
void add_info(t_env *e, t_lex *lex) { t_lex *tmp; char **tab; tmp = lex->next; while (tmp && (tmp->str)[0] != '#') { tab = ft_strsplitspace(tmp->str); if (!ft_strcmp(tab[0], "width")) e->width = ft_atoi(tab[1]); else if (!ft_strcmp(tab[0], "height")) e->height = ft_atoi(tab[1]); else if (!ft_strcmp(tab[0], "focal")) e->focal = ft_atoi(tab[1]); else if (!ft_strcmp(tab[0], "color")) e->color = ft_hextoi(tab[1]); ft_tabfree(&tab); tmp = tmp->next; } }
void split_op_label(t_hero *hero) { char **tmpopts; int op; int line; line = 0; op = 0; tmpopts = (char **)malloc(sizeof(char *) * (ft_tablen(hero->opts) + 1)); hero->label_pos = ft_memalloc(sizeof(int) * (ft_tablen(hero->opts) + 1)); hero->label_name = ft_memalloc(sizeof(char*) * (ft_tablen(hero->opts) + 1)); hero->countlabel = 0; while (hero->opts[line]) { hero->opts[line] = ft_strtrimfree(hero->opts[line]); split_op_label_line(hero, tmpopts, &op, line); line++; } tmpopts[op] = NULL; ft_tabfree(hero->opts); hero->opts = tmpopts; }
int get_client(int sock, char *cmd) { char **tab; int ret; char buf[BUFF_LEN + 1]; tab = ft_strsplit(cmd, ' '); if (!tab[1]) return (client_error(-4)); send(sock, cmd, ft_strlen(cmd), 0); ret = recv(sock, buf, BUFF_LEN, 0); buf[ret] = '\0'; if (!ft_strcmp(GET_FAIL, buf)) { printf("ERROR: You failed to receive the file: %s\n", tab[1]); return (0); } else if (!ft_strcmp(GET_OK, buf)) ft_get_file(tab[1], sock); ft_tabfree(&tab); return (0); }
void ft_launch_exec(char *command, char ***env, int *execve_flag) { char **path; char **cmd_arg; if (ft_strsrch(command, '|') != -1) exec_pipe(env, command, execve_flag); else { cmd_arg = get_clean_arg(command, *env); if (((path = ft_path(env, cmd_arg[0])) == NULL) && ft_strcmp(command, "exit") != 0) ft_putendl("Set a good path or you will take expensive."); if ((ft_rd(command, env, execve_flag) == 1) && (builtin(env, cmd_arg) == 0)) { ft_execute_cmd(path, cmd_arg, *env, execve_flag); if (path) ft_tabfree(path); } } }