static char *pastie(char *str) { char **tab; char *ret; char *tmp; char *tempo; int curs; curs = -1; tab = str_to_wordtab(str); while (tab[++curs]); if (curs == 3) tmp = tab[2]; ret = concate(tab[0], tab[1]); free(tab[0]); free(tab[1]); free(tab); if (curs == 3) { tempo = ret; ret = concate(tempo, tmp); free(tempo); free(tmp); } return (ret); }
t_bool do_put(t_server *s, t_user *user, char *buff) { int pos; int i; char **tab; if ((tab = str_to_wordtab(buff, " \n")) == NULL) return (false); i = 0; pos = user->y * s->option->width + user->x; while (i < 7) { if (tab[1] && strcmp(s->map[pos].stone_list[i].name, tab[1]) == 0) { update_box_content(s, -1, pos); s->map[pos].stone_list[i].nb++; if (remove_stone_to_user(s, user, tab[1]) == false) return (false); send_ok(user->fd); gc_do_put(s, user, i); free_wordtab(tab); return (true); } ++i; } free_wordtab(tab); return (false); }
t_grp *create_n_process_group(t_sh *shell, char *lign) { char **cmd_line; t_grp *res; t_cmd *tmp_cmd; int i; i = 0; if ((res = malloc(1 * sizeof(t_grp))) == NULL) return (NULL); res->line = lign; init_stdfd_t_def_val(&(res->fd), 0, 1, 2); res->pid.sid = shell->pid.sid; res->pid.pgid = -1; res->cmds = NULL; res->flags = 0; parse_redirection(res, lign); if ((cmd_line = str_to_wordtab(res->line, "|", 1)) != NULL) while (cmd_line[i] != NULL) { tmp_cmd = create_n_cmd(shell, cmd_line[i]); res->cmds = (t_cmd**)add_ptr_t_tab((void**)res->cmds, (void*)tmp_cmd); i++; } free(cmd_line); return (res); }
int fill_vertex(t_ply *ply, t_ply_info *info, int fd) { int i; char *str; char **tab; i = -1; while (++i < info->nb_vertex && (str = get_next_line(fd))) { if (!(tab = str_to_wordtab(str, ' ')) || count_tab(tab) < count_prop(info->vertex_prop, NB_V_VAR)) return (1); ply->list_vertex[i].vec.x = (info->vertex_prop[V_X] == -1) ? 0 : my_getdouble(tab[info->vertex_prop[V_X]]); ply->list_vertex[i].vec.y = (info->vertex_prop[V_Y] == -1) ? 0 : my_getdouble(tab[info->vertex_prop[V_Y]]); ply->list_vertex[i].vec.z = (info->vertex_prop[V_Z] == -1) ? 0 : my_getdouble(tab[info->vertex_prop[V_Z]]); if (parse_color_vertex (&ply->list_vertex[i].color, tab, info->vertex_prop, &ply->list_vertex[i].get_color)) return (1); my_free(tab); my_free(str); } return (0); }
void prend(char *str, t_env *e, int fd) { t_player *tmp; char **tab; tmp = e->player; tab = str_to_wordtab(str, ' '); while (tmp->nxt) { if ((strcmp(tab[0], "food") == 0) && tmp->player == fd && e->mapp[tmp->posX][tmp->posY].food >= atoi(tab[2])) { e->mapp[tmp->posX][tmp->posY].food = e->mapp[tmp->posX][tmp->posY].food - atoi(tab[2]); tmp->inventory->food += atoi(tab[2]); } else if ((strcmp(tab[0], "deraumere") == 0) && tmp->player == fd && e->mapp[tmp->posX][tmp->posY].deraumere >= atoi(tab[2])) { e->mapp[tmp->posX][tmp->posY].deraumere = e->mapp[tmp->posX][tmp->posY].deraumere - atoi(tab[2]); tmp->inventory->deraumere += atoi(tab[2]); } prend3(e, fd, tmp, tab); } }
int show_occurence(char *str) { int i; char *str_cpy; char **tab_char; char *tmp; char occ[30 + 1]; i = 0; str_cpy = strdup(str); tab_char = str_to_wordtab(str_cpy); printf("What is the world ? "); scanf("%30s", occ); while (tab_char[i]) { if (!strcmp(occ, tab_char[i])) { tmp = malloc(strlen("\033[36m") + strlen(tab_char[i]) + strlen("\033[00m") + 1); strcpy(tmp, "\033[36m"); strcat(tmp, tab_char[i]); strcat(tmp, "\033[00m"); tab_char[i] = strdup(tmp); } i++; } print_text(tab_char); free(str_cpy); free(tmp); free_tabchar(tab_char); return (0); }
int fill_face(t_ply *ply, t_ply_info *info, int fd) { int i; int j; int count; int size; char *str; char **tab; i = -1; count = count_prop(info->face_prop, NB_F_VAR); while (++i < info->nb_face && (str = get_next_line(fd))) { j = 0; if (!(tab = str_to_wordtab(str, ' ')) || (size = count_tab(tab)) < count) return (1); ply->list_face[i].face = (info->face_prop[F_VERTICES_INDICES] == -1) ? NULL : add_list_face(tab, &j, &ply->list_face[i].nb_face, size); ply->list_face[i].texcoord = (info->face_prop[F_TEXCOORD] == -1) ? NULL : add_list_texcoord(tab, &j, &ply->list_face[i].nb_tex, size); ply->list_face[i].texnumber = (info->face_prop[F_TEXNUMBER] == -1) ? 0 : (F_TEXNUMBER + j >= size) ? 0 : my_getnbr(tab[info->face_prop[F_TEXNUMBER] + j]); my_free(tab); my_free(str); } return (0); }
static int _loop(int s) { char *cmd; char **arr; my_printf(1, "ftp> "); cmd = get_next_line(0); my_printf(s, "%s\n", cmd); while (cmd && strncmp(cmd, "quit", 4) && strcmp(cmd, "(null)")) { arr = str_to_wordtab(cmd); if (arr && arr[0] && arr[1] && (!strcmp(arr[0], "get"))) (void)my_get(arr, s, 0, NULL); else if (arr && arr[0] && !strcmp(arr[0], "user")) (void)user(s, arr, NULL, NULL); else _getlines(s); free(cmd); my_printf(1, "ftp> "); cmd = get_next_line(0); my_printf(s, "%s\n", cmd); } free_wordtab(arr); my_printf(1, "%s221 Goodbye.\n", cmd ? "" : "\n"); return (0); }
int find_occurence(char *str) { int i; int count; char *str_cpy; char **tab_char; char occ[30 + 1]; i = 0; count = 0; str_cpy = strdup(str); tab_char = str_to_wordtab(str_cpy); printf("What is the word ? "); scanf("%30s", occ); while (tab_char[i]) { if (!strcmp(occ, tab_char[i])) count++; i++; } printf("Occurences: %d\n", count); free(str_cpy); free_tabchar(tab_char); return (count); }
char *get_last_cmd_history(t_history *history, char *cmd, int nb) { t_history *pcurrent; char **tab; int indice; if (history == NULL) return (NULL); pcurrent = history; indice = 0; while (pcurrent != NULL) { if ((tab = str_to_wordtab(pcurrent->cmd, " ", 0)) == NULL || tab[0] == NULL) return (NULL); if (str_cmp(tab[0], cmd) == 1) { if (indice == nb) return (pcurrent->cmd); indice += 1; } free_ptr_tab((void *)tab, free); pcurrent = pcurrent->next; } return (NULL); }
int main(int ac, char **av) { t_main c; int res; c.connect = FALSE; c.m = init_gtk(&ac, &av); c.start = 0; c.end = 0; while (1) { if (c.connect == TRUE) do_select(&c); gtk_main_iteration(); if (!c.m->buffer) continue; c.tab = str_to_wordtab((char *)c.m->buffer); if ((res = gere_cmd(&c)) == -1) aff_msg(c.m, "Usage: /server host[:port]\n"); else if (!res) send_serv(c.m, c.m->buffer, c.sfd); gtk_widget_show_all(c.m->main_win); free_tab(c.tab); c.m->buffer = xfree(c.m->buffer); } return (EXIT_SUCCESS); }
int load_obj_file_open(t_prog *prog, char *str) { char **file; t_vtx_list *vtx_list; load_obj_file_open_init(prog); if ((file = str_to_wordtab(str, "\n")) == NULL) return (-1); prog->light_list = NULL; if (((prog->light_list = add_empty_light(prog->light_list)) == NULL) || ((prog->light_list = add_empty_light2(prog->light_list)) == NULL) || ((prog->light_list = add_empty_light3(prog->light_list)) == NULL) || ((prog->light_list = add_empty_light4(prog->light_list)) == NULL) || ((prog->background = create_text_uni(prog->win_size.x, prog->win_size.x, 0xff000000)) == NULL)) return (-1); prog->anti_alias = 1; prog->mat_list = NULL; if (((prog->mat_list = add_empty_mat(prog->mat_list)) == NULL) || ((vtx_list = get_vertex(file)) == NULL) || ((prog->obj_list = parse_obj_formes(file, vtx_list)) == NULL)) return (-1); free_tab(file); return (0); }
int load_scene_open(t_prog *prog, char *str) { char **file; t_coord dir; if (((file = str_to_wordtab(str, "\n")) == NULL) || (load_scene_open_beg(prog, file))) return (-1); prog->cam_fov.y = prog->cam_fov.x * ((prog->win_size.x / prog->win_size.y) / 1.5); if (get_cam_pos(file, prog) == 1 || get_cam_look_at(file, prog) == 1 || load_mat(prog, file) == -1 || load_light(prog, file) == -1 || load_obj(prog, file) == -1) return (-1); if (prog->look_at.x == prog->cam_pos.x && prog->look_at.y == prog->cam_pos.y && prog->look_at.z == prog->cam_pos.z) return (my_printf(2, "Wrong camera placement\n") - 1); dir = normalize(minus_point(prog->look_at, prog->cam_pos)); prog->cam_rot.x = RTD(acos(-(dir.z / sqrt(pow(dir.x, 2) + pow(dir.z, 2))))) - 90; prog->cam_rot.y = RTD((M_PI / 2 - acos(dir.y))); prog->cam_dir = normalize(minus_point(prog->look_at, prog->cam_pos)); free_tab(file); return (0); }
int check_command(char *str, int client_s, char *ignored, t_log *log) { char **arr; int i; static t_cmd cmds[NB_CMD + 1] = { {"ls", my_ls}, {"cd", my_cd}, {"pwd", my_pwd}, {"user", my_user}, {"get", my_get}, {"quit", my_quit}, {"(null)", my_quit}, {NULL, my_invalid} }; arr = str_to_wordtab(str); write_log(log, str, 0); if (arr == NULL || arr[0] == NULL) { my_printf(client_s, "%s\n", END_READ); return (arr == NULL ? 1 : 0); } i = _check_function(cmds, arr[0]); return (cmds[i].fnc(arr, client_s, ignored)); }
void export_set(char *str, t_sh *shell) { char **field; if ((field = str_to_wordtab(str, "=", 2)) == NULL) return ; if ((field[0] != NULL) && (field[1] != NULL)) { shell->env = add_change_env(shell->env, field[0], field[1]); } free_ptr_tab((void**)field, &free); }
void mult_wt_fill_all_tab(char ***tab, char *line, char **sepa, int opt) { int i; i = 0; while (sepa[i] != NULL) { tab[i] = str_to_wordtab(line, sepa[i], opt); i++; } tab[i] = NULL; }
char *rempl_str_inib(char *str, char *ref, char *rempl, int inib) { char **tab; char *s; if ((tab = str_to_wordtab(str, ref, inib)) == NULL || (s = strtab_to_str(tab, rempl)) == NULL) { free_ptr_tab((void**)tab, &free); return (NULL); } free_ptr_tab((void**)tab, &free); return (s); }
void init_envvars(char **envp) { char **wordtab; int i; i = 0; while (envp[i]) { wordtab = str_to_wordtab(envp[i], '='); if (!wordtab) return ; my_setenv(wordtab[0], wordtab[1]); free_wordtab(wordtab); ++i; } }
void getmap(char *fichier) { int fd; int taille; char *str; extern char **map; struct stat s; fd = open(fichier, O_RDONLY); fstat(fd, &s); str = malloc(sizeof(*str) * s.st_size); taille = read(fd, str, s.st_size); str[taille - 1] = '\0'; map = malloc(sizeof(*map) * get_height(str)); map = str_to_wordtab(str); close(fd); aff_map(map); }
int pipe_parsing(char *str) { char **tab_pipe; int ret; int tab_len; if (!valid_str(str) || !last_verif(str)) return (0); if (in_str(str, token_val("|")) && (tab_pipe = str_to_wordtab(str, token_val("|")))) { tab_len = count_tab(tab_pipe); ret = exec_pipe(tab_pipe, tab_len); free(tab_pipe); } else ret = parse_command_redir(str); return (ret); }
int init_parsing(char **buf) { int i; int ret; char **tab; i = 0; ret = first_parsing(buf, 0); if (ret < 0) return (0); if (!check_parenth(*buf)) return (0); tab = str_to_wordtab(*buf, token_val(SEMICOLON)); if (!tab) return (0); ret = 0; while (tab[i]) ret = logic_parse(tab[i++]); free(tab); return (ret); }
int main() { str_to_wordtab("coucouc coucu"); }
#include <arpa/inet.h> #include <stdio.h> #include <netdb.h> #include <string.h> #include <strings.h> #include <gtk/gtk.h> #include "client.h" #include "window.h" extern t_Window Wdata; int res_who(__attribute__((unused)) int s, char *cmd) { char **arg; arg = str_to_wordtab(cmd, ' '); if (tablen(arg) == 3) write_on_contacts(Wdata.begin, arg[1], arg[2]); return (0); } int who_chan(int s, char *cmd) { write(s, cmd, strlen(cmd)); return (0); } int nick(int s, char *cmd) { write(s, cmd, strlen(cmd)); return (0);