t_pcs *convertlisttoexectab(t_dlist *list, int n) { t_dlist *cpy; t_pcs *tab; int i; t_prs *tmp; i = -1; if ((cpy = list) == NULL || (tab = gbgc_calloc(sizeof(t_pcs) * (n + 1))) == NULL) return (NULL); while (++i < n && cpy != NULL && (tmp = cpy->data) != NULL && tmp->argv != NULL) { if (!convertlisttoexectab2(&(tab[i]), tmp)) return (NULL); if (i > 0 && tmp->piped && tab[i - 1].pipedright != NULL) { tab[i].is_piped = 1; tab[i].pipedleft = tab[i - 1].pipedright; } if (tmp->cond) tab[i].cdt = (tmp->cond == ANDAND) ? SCCDT : FLCDT; cpy = cpy->next; } tab[i].pathn = NULL; return (tab); }
t_uni *build_uni() { t_uni *out; if (get_crtreturn(NULL)) return (NULL); if ((out = gbgc_calloc(sizeof(t_uni))) == NULL) return ((t_uni *)dbgcrt("Error: build_uni: Allocation failed")); out->attack = uni_attack; out->move = uni_move; out->dead = uni_dead; return (out); }
t_dtf *build_dtf() { t_dtf *out; if (get_crtreturn(NULL)) return (NULL); if ((out = gbgc_calloc(sizeof(t_dtf))) == NULL) return ((t_dtf *)dbgcrt("Error: build_dtf: Allocation failed")); out->actplayer = BLUEPL; out->move = dtf_move; out->strategic = dtf_strategic; out->pass = dtf_pass; out->createmap = dtf_createmap; out->createunits = dtf_createunits; return (out); }
char *get_term_name_cpy(char *str) { char *name; int i; i = 5; if (!(name = gbgc_calloc(sizeof(char) * (my_strlen(str) - i + 1)))) { my_perror("malloc failed"); return (NULL); } while (str[i]) { name[i - 5] = str[i]; i++; } name[i - 5] = 0; return (name); }
int init_sh(char **env, t_sh **sh) { set_static_tty(env); my_signals(); gbgc_init(); init_open(); if (((*sh) = gbgc_calloc(sizeof(t_sh))) == NULL) return (false); if (((*sh)->env = convert_envtab(env)) == NULL) return (my_perror("env return null")); (*sh)->rdl.prompt = "Such prompt $> "; if (isatty(STDIN_FILENO) && env[0] != NULL) { (*sh)->tty = false; if ((getent_term(env)) == false) return (false); if (!rawmode()) return (false); (*sh)->tty = true; } else (*sh)->tty = false; return (true); }
int convertlisttoexectab2(t_pcs *tab, t_prs *tmp) { if (tab == NULL || tmp == NULL) return (0); tab->pathn = my_strdup(tmp->argv[0]); tab->args = my_strtabdup(tmp->argv); if (tmp->stdout_path != NULL) { tab->filout = my_strdup(tmp->stdout_path); tab->redright = (tmp->stdout == SP_RIGHT) ? R_RIGHT : R_RRIGHT; } if (tmp->stdin_path != NULL) { tab->filin = my_strdup(tmp->stdin_path); tab->redleft = (tmp->stdin == SP_LEFT) ? R_LEFT : R_LLEFT; } if (tmp->piping) { if ((tab->pipedright = gbgc_calloc(sizeof(int) * 2)) == NULL || pipe(tab->pipedright) < 0) return (1); } return (1); }