void parsor(char *line, t_list **ret) { char **des_ints; char *to_free; if (('a' != line[0]) && ('b' != line[0]) && ('c' != line[0]) && ('d' != line[0]) && ('l' != line[0])) { ft_putendl("invalid file"); exit(0); } else { (*ret)->type = line[0]; to_free = ft_strdup(line); line = ft_strsub(to_free, 2, ft_strlen(to_free) - 1); des_ints = ft_strsplit(line, ' '); free(line); free(to_free); fill_with_tab(des_ints, ret); } }
int client_side_command(char *command) { char **args; int i; if (command[0] != '/') return (0); i = 0; args = ft_strsplit(command, '\t', ' '); while (g_func[i].name != NULL) { if (!ft_strcmp(args[0] + 1, g_func[i].name)) { g_func[i].func(args + 1); ft_freetab(args); return (1); } i++; } ft_freetab(args); return (0); }
void ft_pid2(int fd2, int *piped, char *cmd2) { char **command2; wait (NULL); command2 = ft_strsplit(cmd2, ' '); dup2(piped[0], 0); dup2(fd2, 1); close(piped[0]); close(piped[1]); close(fd2); if (command2[0][0] == '/') { if (execve(command2[0], command2, environ) == -1) ft_error_handling("No such command, try removing the /\n"); } else ft_exec(command2); close(fd2); close(piped[0]); close(piped[1]); }
void cmd_who(char *cmd, t_env *e, int cs) { char *trim; char **spl; char *tmp; trim = ft_strtrim(cmd); spl = ft_strsplit(trim, ' '); ft_strdel(&trim); if (ft_strlistlen(spl) == 1) { s_who(e, cs); } else { tmp = ft_strijoin(e->fds[cs].buf_write, CLEAR_LINE, "usage: /who\n", 0); ft_strcpy(e->fds[cs].buf_write, tmp); ft_strdel(&tmp); } ft_strlistdel(spl); }
int deal_with_env(t_lst *node, char *line) { char **save; char **arg; arg = ft_strsplit(line, ' '); arg++; if (*arg) { if (*arg[0] == '-') save = deal_with_opt(node, arg); else save = deal_with_arg(node, arg); if (!save || !*save) return (-1); restore_env(node, save); free(save); } else print_env(node); return (-1); }
void init_map_parser2(t_map *map, char *line, int j, double y) { char **buf; double x; int i; i = 0; x = -0.90; buf = ft_strsplit(line, ' '); while (buf[i]) { map->map[j][i].state = ft_atoi(buf[i]); map->map[j][i].pos.x = x; map->map[j][i].pos.y = y; map->map[j][i].height = BRICK_H; map->map[j][i].width = BRICK_W; x += BRICK_OFFSET_X; free(buf[i]); i++; } free(buf); }
void get_player(t_env *env) { char *line; char **tab; if (get_next_line(0, &line) != 1) error("ERROR"); tab = ft_strsplit(line, ' '); ft_strdel(&line); line = NULL; if (ft_strcmp(tab[2], "p1") == 0) { env->player = 'O'; env->adv = 'X'; } else { env->adv = 'O'; env->player = 'X'; } ft_free_tab(tab); }
char *perm_display(struct stat filestat) { char **rwx; char *bits; bits = (char *)malloc(sizeof(char) * 12); rwx = ft_strsplit("---,--x,-w-,-wx,r--,r-x,rw-,rwx", ','); bits[0] = file_type(filestat.st_mode); ft_strcpy(&bits[1], rwx[(filestat.st_mode >> 6) & 7]); ft_strcpy(&bits[4], rwx[(filestat.st_mode >> 3) & 7]); ft_strcpy(&bits[7], rwx[(filestat.st_mode & 7)]); if (filestat.st_mode & S_ISUID) bits[3] = (filestat.st_mode & 0100) ? 's' : 'S'; if (filestat.st_mode & S_ISGID) bits[6] = (filestat.st_mode & 0010) ? 's' : 'S'; if (filestat.st_mode & S_ISVTX) bits[9] = (filestat.st_mode & 0100) ? 't' : 'T'; bits[10] = ' '; bits[11] = '\0'; // FREETAB (rwx); return (bits); }
int session_start(char *dir_root, t_sess *sess) { t_request req; int index; char *input; memmove(req.dir_cur, dir_root, ft_strlen(dir_root)); memmove(req.dir_root, dir_root, ft_strlen(dir_root)); while (get_next_line(sess->client.sock, &input) != 0) { req.args = ft_strsplit(input, ' '); index = get_index_handler(sess, req.args[0]); if (index != -1) sess->handlers[index].f(&req, sess->client.sock); else printf("[%s] : Cmd not found.\n", input); ft_2dchardel(&req.args); free(input); } display_hour(); printf("\nDeconnection from : %s\n", sess->client.ip); }
void launch_process_from_asked_dir(char *path, char *args, char **env) { char **argv; argv = NULL; if (args && args[0] && ft_strlen(args)) { args = ft_strtrim(args); argv = ft_strsplit(args, ' '); argv = add_path(argv, path); } else argv = set_argv(argv, path); /*int i = 0; while (argv[i]) { ft_putstr(argv[i]); ft_putstr("\n"); i++; }*/ launch_process_ext(path, argv, env); }
t_data *get_adress(t_glob *g, char *name) { t_temp_list *node; char **stuff; if (g->tmp == NULL) node = g->data; else node = g->tmp; while (node->next != NULL) { if (ft_strchr(node->str, '-') != NULL) { g->tmp = node->next; stuff = ft_strsplit(node->str, '-'); if (ft_strcmp(stuff[0], name) == 0) return (g->rooms[get_num(stuff[1], g)]); } node = node->next; } return (NULL); }
void ft_cd(t_list **list, char *line) { char *pwd; char **argum; char *cwd; pwd = search(*list, "PWD="); argum = ft_strsplit(line, ' '); if (char_array_size(argum) == 1) ft_oldpwd(list, "HOME=", "PWD="); else if (char_array_size(argum) == 2) { if (ft_strcmp(argum[1], "-") == 0) { ft_putendl(search(*list, "OLDPWD=") + 7); ft_oldpwd(list, "OLDPWD=", "PWD="); } else reduc_cd(list, argum[1], pwd, cwd); } free_char_array(argum); }
void delete_channel(char *buff, t_client *client) { int i; char **tmp; tmp = ft_strsplit(buff, ' '); i = 0; while (i < MAX_CHANNEL) { if (client->channel[i] && tmp[1]) { if (ft_strcmp(client->channel[i], tmp[1]) == 0) { client->channel[i] = NULL; client->n_channel--; write_to_client(client->sock, "leave with success !"); return ; } } i++; } }
void start(char *line, char ***env) { int i; t_line *tree; char **split; if (line && line[0]) { i = 0; split = ft_strsplit(line, ';'); while (split[i]) { tree = new_link(0, NULL); manage_line(split[i], tree, env); free_postfix(tree); i++; } free_tab_2d(&split); } if (line) free(line); }
void cmd_msg(char *cmd, t_env *e, int cs) { char *trim; char **spl; char *tmp; trim = ft_strtrim(cmd); spl = ft_strsplit(trim, ' '); ft_strdel(&trim); if (ft_strlistlen(spl) == 3) { s_msg(e, cs, spl[1], spl[2]); } else { tmp = ft_strijoin(e->fds[cs].buf_write, CLEAR_LINE, "usage: /msg [name] [message]\n", 0); ft_strcpy(e->fds[cs].buf_write, tmp); ft_strdel(&tmp); } ft_strlistdel(spl); }
void display(GLFWwindow *win, t_env *e) { char *line; float eom; char **got; while (!glfwWindowShouldClose(win) && !glfwGetKey(win, 256)) { glfwPollEvents(); if (get_next_line(0, &line) > 0) { glClear(GL_COLOR_BUFFER_BIT); if (ft_strstr(line, "<got")) got = ft_strsplit(line, ' '); else if (ft_strstr(line, "Plateau")) { e->map_size = get_size_bonus(line, e); if (e->map_size && !e->sz) e->sz = get_square_size(e->map_size); get_next_line(0, &line); e->map = get_map(e, line); eom = disp_grid(e->map_size, -0.95, 0.95, e->sz); if (e->piece_size[0] > 0) disp_piece(e, eom); put_map_square(e); if (got != NULL) get_play(eom, got, e); glfwSwapBuffers(win); } } else { put_winner(e, eom); glfwSwapBuffers(win); glfwWaitEvents(); //TODO BETTER HOLD } } }
void ft_join(char *buff, t_client *client, t_server *server) { int i; char **tmp; (void)server; tmp = ft_strsplit(buff, ' '); i = 0; while (i < MAX_CHANNEL) { if (client->channel[i] && tmp[1]) { if (ft_strcmp(client->channel[i], tmp[1]) == 0) { write_to_client(client->sock, "/join => channel already joined !"); return ; } } i++; } add_channel(tmp[1], client); }
static char *get_prog_path(t_env *tenv, char *pname) { char **paths; char *pval; char *fpath; int cnt; fpath = NULL; cnt = 0; if ((pval = get_env_val(tenv, "PATH")) == NULL) return (NULL); if ((paths = ft_strsplit(pval, ':')) == NULL) return (NULL); while (paths[cnt] != NULL) { if ((fpath = get_fpath(paths[cnt], pname)) != NULL) break ; cnt++; } ft_strdel(&pval); ft_starfree(paths); return (fpath); }
void check_map(char **line) { int i; char **tmp; i = 0; while(line[i]) { if (line[i][0] == 'L') exit_error("start name room with 'L' forbidden.", 2); if (line[i][0] != '#' && ft_strstr(line[i], " ")) { tmp = ft_strsplit(line[i], ' '); if (ft_double_tablen(tmp) != 3) exit_error("an extra element in a room.", 2); if (!ft_strdigit(tmp[1]) || !ft_strdigit(tmp[2])) exit_error("coord_x or coord_y is not a number.", 2); free_tab(tmp); } i++; } ft_putendl("check_map OK"); }
void array_atoi(char *file, t_map *m) { char **line; char **tmp; m->y = 0; line = read_file(file); m->map = (int **)malloc(sizeof(int *) * ft_double_tablen(line)); while (line[m->y]) { tmp = ft_strsplit(line[m->y], ' '); m->map[m->y] = (int *)malloc(sizeof(int) * ft_double_tablen(tmp)); m->x = 0; while (tmp[m->x]) { m->map[m->y][m->x] = ft_atoi(tmp[m->x]); m->x++; } m->y++; } free(line); free(tmp); }
t_date *ft_date_convert(char *str) { char **ret; t_date *date; ret = ft_strsplit(str, ' '); if (count_char(str, ' ') != 1) return (NULL); if (count_char(str, '/') != 2) return (NULL); if (count_char(str, ':') != 2) return (NULL); if (ret != NULL && ret[1] != NULL && !ret[2]) { if (!(date = date_create())) return (NULL); date_convert_time(ret[0], date); date_convert_date(ret[1], date); ft_tabstrdel(ret); return (date); } return (NULL); }
int ft_consline(t_env *env, char *line, int nb_line) { char **tab; int nb_col; tab = ft_strsplit(line, ' '); nb_col = 0; while (tab[nb_col]) nb_col++; env->map[nb_line] = (int*)malloc(sizeof(int) * (nb_col + 1)); env->map[nb_line][nb_col] = 100; nb_col = 0; while (tab[nb_col]) { env->map[nb_line][nb_col] = ft_atoi(tab[nb_col]); nb_col++; } nb_col = 0; while (tab[nb_col]) free(tab[nb_col++]); free(tab); return (1); }
void change_nick(t_env *e, char *line) { char **split; char *nick; int i; i = 0; split = ft_strsplit(line, ' '); if (!split[1]) { printf(">> enter a 9 characters nickname\n"); return ; } split[1] = ft_strtrim(split[1]); if (ft_strlen(split[1]) > 9) nick = ft_strsub(split[1], 0, 9); else nick = ft_strdup(split[1]); e->nickname = nick; printf(">> your nickname has been changed to : %s\n", e->nickname); while (split[i]) free(split[i++]); }
static void parse_request(char *r, t_http_head *h) { char **spli; spli = ft_strsplit(r, ' '); if (spli) { if (hmatch(r, GET_)) h->type = GET; else if (hmatch(r, POST_)) h->type = POST; else if (hmatch(r, PUT_)) h->type = PUT; else if (hmatch(r, DELETE_)) h->type = DELETE; else h->type = UNKNOWN; if (spli[1]) h->target = ft_strjoin(".", spli[1]); if (spli[2]) h->protocol = spli[2]; } }
int li_get_start_end(char *line, t_lem *lst, int start) { int i; char **tab; i = 0; get_next_line(0, &line); ft_printf("%s\n", line); if (line[0] == 'L' || line[0] == '#') return (0); tab = ft_strsplit(line, ' '); free(line); if (tab && tab[1] == NULL) return (li_free_tab(tab)); if (start == 1) lst->name_start = ft_strdup(tab[0]); else if (start == 2) lst->name_end = ft_strdup(tab[0]); if (li_check_coord(tab, lst) == 0 || tab[3] != NULL) return (li_free_tab(tab)); li_free_tab(tab); return (1); }
static void ft_checkcmd(char *cmdline, t_conf *config) { char **cmdline_split; static void (*tabf[5])(t_conf *, char **) = {&ft_cd, &ft_exit, &ft_unsetenv, &ft_env, &ft_setenv}; int builtin; t_bin *cmd; cmd = NULL; if (!cmdline || !*cmdline || !(cmdline_split = ft_strsplit(cmdline, ' '))) return ; if ((builtin = ft_findbuiltin(*cmdline_split)) != -1) (tabf[builtin])(config, cmdline_split); else if (*cmdline_split[0] == '/' || *cmdline_split[0] == '.' || (cmd = ft_findcmd(*cmdline_split, ft_hashsearch(config, *cmdline_split)))) ft_execcmd(cmd, cmdline_split, config); else ft_error(*cmdline_split, CMD_NOTFOUND, KEEP); ft_free_split(cmdline_split); free(cmdline_split); }
int *convert(char *line) { char **tab; int *intline; int lenght; int i; i = 1; lenght = 0; tab = ft_strsplit(line, ' '); while (tab[lenght]) lenght++; intline = (int *)malloc(sizeof(int *) * (lenght + 1)); intline[0] = lenght; while (i <= lenght) { intline[i] = ft_atoi(tab[i - 1]); free(tab[i - 1]); i++; } free(tab); return (intline); }
void show_prompt(t_list *list) { char *pwd; char **path_components; char *prompt; int component_count; pwd = search(list, "PWD=") + 4; path_components = ft_strsplit(pwd, '/'); write(1, "[POKEMON] ", 10); component_count = char_array_size(path_components); if (component_count < 2) ft_putstr(pwd); else { prompt = join(path_components[component_count - 2], "/", path_components[component_count - 1]); ft_putstr(prompt); free(prompt); } write(1, " > ", 3); free_char_array(path_components); }
void ft_relative_path(t_sh *sh, char *path, int i) { char **pathes; int j; int k; j = -1; k = ft_getenv_id(sh->env, "HOME", 4); pathes = ft_strsplit(path, '/'); if (path[0] == '~') sh->env[i] = ft_strjoin("PWD=", sh->env[k]); else { while (pathes[++j]) { if (!ft_strcmp(pathes[j], "..")) sh->env[i] = ft_strsub_rchr(sh->env[i], '/'); else sh->env[i] = ft_strjoin(ft_strjoin(sh->env[i], "/"), pathes[j]); } } sh->pwd = sh->env[i]; }
void ft_findwh(int fd, t_map *list) { char *line; char **coord; int y; y = 0; if (ft_get_next_line(fd, &line)) { y++; coord = ft_strsplit(line, ' '); list->w = ft_findw(coord); free(coord); free(line); } while (ft_get_next_line(fd, &line)) { y++; free(line); } list->h = y; close(fd); }