int check_redir_left(t_vars *redir, t_redir *r) { if (!my_strlen(r->the_file)) return (redir_error(redir, r, 1)); else if (my_xopen(r->the_file) == -1) return (redir_error(redir, r, 6)); else if (!my_tablen(r->before_tab) && !my_tablen(r->after_tab)) return (redir_error(redir, r, 2)); else if (my_tablen(r->before_tab)) { redir->argv = r->before_tab; redir->argc = my_tablen(redir->argv); if (which_it_is(redir) == 7) return (redir_error(redir, r, 3)); if (which_it_is(redir) == SMTH_ELSE) return (redir_error(redir, r, 4)); } else { redir->argv = r->after_tab; redir->argc = my_tablen(redir->argv); if (which_it_is(redir) == SMTH_ELSE) return (redir_error(redir, r, 4)); } return (OK); }
int epur_duplicates(char **pathv) { int i; int j; char **dup; int len; j = 0; i = 0; len = my_tablen(pathv); dup = NULL; if ((dup = malloc(sizeof(char*) * (len + 1))) == NULL) return (-1); clear_all_pattern(pathv); if (dup) dup = memset(dup, 0, sizeof(char*) * (len + 1)); while (pathv && pathv[i]) { if (already_in(dup, pathv[i]) == 0) dup[j++] = pathv[i]; ++i; } pathv = dup; i = my_tablen(dup) + 1; return (i); }
int sudoki_bi() { char ***tab; t_list *list; t_present *present; int i; if ((tab = get_all_tab()) == NULL) return (-1); i = -1; while (++i < my_tablen(tab)) { if ((present = get_present(tab[i])) == NULL || (list = get_list(tab[i])) == NULL) return (-1); filler(tab[i], list, present); if (check_valid(tab[i]) == 1) error_aff_tab(); else aff_table(tab[i]); if (i < (my_tablen(tab) - 1)) write(1, "####################\n", 21); free_function_bis(list, present); } free_function(tab); return (0); }
void move(t_event *event, float i) { t_data *data; float x; float y; float c_x; float c_y; float angle; data = event->data; angle = data->a / 180 * PI; x = data->x_p + (Y_SENSITIVE * cos(angle) * i); c_x = data->x_p + ((Y_SENSITIVE * 4) * cos(angle) * i); y = data->y_p + (Y_SENSITIVE * sin(angle) * i); c_y = data->y_p + ((Y_SENSITIVE * 4) * sin(angle) * i); if (x < 0 || y < 0 || (int)y >= my_tablen(data->map) || (int)x >= my_strlen(data->map[(int)y])) return; if (c_y >= 0 && c_y < my_tablen(data->map) && c_x >= 0 && c_x < my_strlen(data->map[(int)c_y]) && data->map[(int)c_y][(int)c_x] == '3') get_new_map(event); else hitbox('0', data, x, y); }
int config_alias(char *str, t_config *config) { char **tab; char **spec; char *base; base = DELIM_ALIAS_STRING; if ((tab = my_strtok(str, base, TOK_DELIM)) == NULL || my_tablen(tab) != ALIAS_STRING_NUMBER) { (tab) ? my_free_tab(tab) : (tab = NULL); return (EXIT_FAILURE); } base = DELIM_SPACE_STRING; if ((spec = my_strtok(tab[0], base, TOK_DELIM)) == NULL || my_tablen(spec) != ALIAS_STRING_NUMBER) { (tab) ? my_free_tab(tab) : (tab = NULL); (spec) ? my_free_tab(spec) : (spec = NULL); return (EXIT_FAILURE); } my_putalias(&config->alias, spec[1], tab[1]); (tab) ? my_free_tab(tab) : (tab = NULL); (spec) ? my_free_tab(spec) : (spec = NULL); return (EXIT_SUCCESS); }
int check_db_redir_left(t_vars *redir, t_redir *r) { if (my_strlen(r->the_file) < 1) return (redir_error(redir, r, 1)); else if (!my_tablen(r->before_tab) && !my_tablen(r->after_tab)) return (redir_error(redir, r, 2)); else if (!my_tablen(r->before_tab) && !my_tablen(r->after_tab)) return (redir_error(redir, r, 5)); return (OK); }
int load_faces(t_triangle *tri, char **tab) { t_face *tmp; unsigned int i; i = 0; if ((tmp = bunny_malloc(sizeof(t_face) * (tri->nb_face + 1))) == NULL) return (my_perror(MALLOC_F)); while (i != tri->nb_face) { tmp[i] = tri->face[i]; i = i + 1; } if (((tmp[i].f = my_getnbr(tab[1])) == 0) || ((tmp[i].s = my_getnbr(tab[2])) == 0) || ((tmp[i].t = my_getnbr(tab[3])) == 0)) return (-1); if (tmp[i].f > tri->nb_vertices || tmp[i].s > tri->nb_vertices || tmp[i].t > tri->nb_vertices) return (my_perror(W_VERTC)); tri->face = tmp; tri->nb_face += 1; if (my_tablen(tab) == 5) if (load_second_face(tri, tab) == -1) return (-1); return (0); }
static t_line *edit_autocomplete(char *str, char *path, t_global *global, t_line *line) { t_line *complete; char **tab; int len; complete = NULL; if ((tab = my_strtok(str, " \t", TOK_DELIM)) == NULL) return (NULL); len = my_tablen(tab); if (len == 1) { if (tab[0][my_strlen(tab[0]) - 1] == '*') complete = NULL; else complete = edit_convertstr(&tab[0][my_strlen(path) - 1]); } else { complete = edit_recurrence(tab, my_strlen(path) - 1); aff_rch(tab, global, line); } my_free_tab(tab); return (complete); }
static void aff_rch(char **tab, t_global *global, t_line *line) { char **tmp; int i; i = -1; termcap_action(1, CURSER_OFF, NULL, 0); termcap_action((edit_listlen(line) - edit_cp(line)), RIGHT_MOVE_STRING, global, 1); termcap_action(1, DOWN_MOVE_STRING, NULL, 0); termcap_action(global->dom[X], LEFT_MOVE_STRING, NULL, 0); while (tab && tab[++i]) { termcap_action(1, UNDERLINE_ON, NULL, 0); if ((tmp = my_strtok(tab[i], "/", TOK_DELIM)) != NULL) { printf("%s\n", tmp[my_tablen(tmp) - 1]); my_free_tab(tmp); } termcap_action(1, UNDERLINE_OFF, NULL, 0); } my_putstr(global->prompt); edit_global(global, 1); termcap_action(edit_cp(line), RIGHT_MOVE_STRING, global, 1); termcap_action(1, CURSER_ON, NULL, 0); }
char *my_tabjoin(char **tab, char *glue) { char *str; int extra; int length; int flength; length = my_tablen(tab); flength = my_tabflen(tab); extra = my_strlen(glue) * my_max(length - 1, 0); if ((str = malloc((extra + flength + 1) * sizeof(str))) == NULL) { return (NULL); } str[extra + flength] = '\0'; flength = extra = 0; while (tab[extra]) { my_strncpyz(str, tab[extra], flength, -1); flength += my_strlen(tab[extra]); if (extra + 1 != length) my_strncpyz(str, glue, flength, -1); flength += my_strlen(glue); extra++; } return (str); }
int my_unsetenv(char **args) { t_env *parse; t_env *begin; int count; begin = gl_st.st_env; count = 1; if (my_tablen(args) < 2) { fprintf(stderr, "unsetenv: Too few arguments.\n"); return (EXIT_FAILURE); } else if (begin) while ((begin) && (args[count])) { parse = begin; while ((parse) && my_strcmp(parse->var, args[count]) != '=') parse = parse->next; if (parse) _unset_elem(&begin, parse); count++; } gl_st.st_env = begin; return (EXIT_SUCCESS); }
int config_prompt(char *str, t_config *config) { char **tab; char *base; char *prompt; base = DELIM_PROMPT_STRING; if (str == NULL || config == NULL) return (EXIT_FAILURE); prompt = NULL; if ((tab = my_strtok(str, base, TOK_DELIM)) == NULL || my_tablen(tab) != PROMPT_STRING_NUMBER || (prompt = xmalloc(sizeof(*prompt) * (my_strlen(tab[1]) + 1))) == NULL || fill_prompt(prompt, tab[1]) == EXIT_FAILURE) { (tab) ? my_free_tab(tab) : (tab = NULL); (prompt) ? free(prompt) : (prompt = NULL); return (EXIT_FAILURE); } if (config->prompt != NULL) free(config->prompt); my_free_tab(tab); config->prompt = prompt; return (EXIT_SUCCESS); }
static void add_champ_to_tab(t_glob *glob, t_champ *champ) { int size; size = my_tablen((char **) glob->champ); if (size < 4 && glob->champ[size] == NULL) glob->champ[size] = champ; else my_errex("vm-error: Too many champions.\n"); }
void init_redir_simp(t_vars *v, t_redir *r, char redir) { r->is = which_it_is(v); r->prompt = my_strdup(v->prompt); r->before_str = my_strdup2(r->prompt, redir); r->after_str = my_strdup3(r->prompt, redir); r->before_tab = get_argv(r->before_str); r->after_tab = get_argv(r->after_str); r->the_file = rebuild_name(v, r->after_tab[0]); if (my_tablen(r->after_tab)) r->after_tab = delete_first_elem_in_tab(r->after_tab); }
int hitbox(char c, t_data *data, float x, float y) { char **map; map = data->map; if (y - HIT >= 0 && y + HIT < my_tablen(map) && x - HIT >= 0 && x + HIT < my_strlen(map[(int)y]) && hit(map, c, y, x) == 0) { data->y_p = y; data->x_p = x; } return (0); }
int mysh_chdir(char **tokens, t_env *env) { int ret; char *home; ret = 1; if (my_tablen(tokens) > 1) ret = chdir(tokens[1]); else { if ((home = get_env(env, "HOME")) == NULL) return (-1); ret = chdir(home); } mysh_chdir_checkerr(tokens, ret); return (ret); }
int builtin_unalias(t_global *global, char **cmd) { int len; int i; i = 0; len = my_tablen(cmd); if (len == 1) { fprintf(stderr, "Unalias: Too few arguments.\n"); return (EXIT_FAILURE); } else if (global->config != NULL) { while (cmd[++i]) my_subalias(&global->config->alias, cmd[i]); } else return (EXIT_FAILURE); return (EXIT_SUCCESS); }
int builtin_alias(t_global *global, char **cmd) { int len; char *alias; alias = NULL; len = my_tablen(cmd); if (len == 1 && global->config != NULL) show_alias(global->config->alias, NULL); else if (len >= 3 && global->config != NULL) { alias = alias_concat(&cmd[2]); my_putalias(&global->config->alias, cmd[1], alias); (alias) ? free(alias) : (alias = NULL); } else if (len == 2 && global->config != NULL) show_alias(global->config->alias, cmd[1]); else return (EXIT_FAILURE); return (EXIT_SUCCESS); }
int dup_and_exec(t_vars *redir, char **array) { pid_t shell; int exe; int status; int fd; redir->argv = array; redir->argc = my_tablen(redir->argv); redir->prompt = concat_tab_elems(redir->argv, " "); fd = my_xopen(".tmp"); if ((shell = my_xfork()) == 0) { fd = my_xdup2(fd, 0); lexer(redir); exe = global_exec(redir); fd = my_xclose(fd); exit(exe); } else waitpid(shell, &status, 0); return (status); }
/* ** compil a single instruction (lexed_line): ** check the params and write the einstruction ** if an error is encountered, return -1 ** else return how many byte has been writed */ int my_compil(char **lexed_line, op_t *optodo, int fd_binary) { int i; int ret; int writed; writed = 0; i = my_tablen(lexed_line); if (my_check_params(i, optodo, lexed_line) == -1) return (-1); if ((ret = write(fd_binary, &(optodo->code), 1)) == -1) { my_fprintf(2, "write() error. (opcode)\n"); return (-1); } writed += ret; if ((ret = my_write_args(lexed_line, optodo, fd_binary)) == -1) { my_fprintf(2, "write() error. (arg)\n"); return (-1); } writed += ret; return (writed); }