int main(int ac, char **av) { t_list *list1; t_list *list2; char **tab1; char **tab2; if (ac == 3) { tab1 = ft_split_whitespaces(av[1]); tab2 = ft_split_whitespaces(av[2]); list1 = ft_list_push_params(tab_len(tab1), tab1); list2 = ft_list_push_params(tab_len(tab2), tab2); ft_list_sort(&list1, &ft_strcmp); ft_list_sort(&list2, &ft_strcmp); ft_putstr("List1:\n"); ft_print_list(list1); ft_putstr("List2:\n"); ft_print_list(list2); ft_putstr("List1 + List2:\n"); ft_sorted_list_merge(&list1, list2, &ft_strcmp); ft_print_list(list1); } return (0); }
void init_coord(char *file_name, t_co *c) { char *line; int i; int fd; int x_len; char **split; i = 0; c->coord = (t_coord *)malloc(sizeof(t_coord)); fd = open(file_name, O_RDONLY); while (get_next_line(fd, &line) > 0) { split = ft_strsplit(line, ' '); if (i++ == 0) x_len = tab_len(split); c->coord->x_point = tab_len(split); tab_free(split); check_len_map(x_len, c->coord); free(line); } check_ret_gnl(&fd, line); c->coord->to_pts = x_len * i; c->coord->y_point = i; close(fd); }
int my_setenv(char **tab, t_shell *sh) { int i; i = -1; sh->bol = 0; if (!exit_setenv(tab)) return (-1); if (!tab[1]) return (my_env(sh)); while (sh->env[++i]) { if (!strncmp(sh->env[i], tab[1], strlen(tab[1])) && sh->env[i][strlen(tab[1])] == '=') { free(sh->env[i]); sh->env[i] = concat_str(tab[1], tab[2], '='); sh->bol = 1; } } if (!sh->bol) { sh->env = my_realloc(sh->env, ((tab_len(sh->env) + 2) * sizeof(char *))); sh->env[i] = concat_str(tab[1], tab[2], '='); sh->env[i + 1] = NULL; } return (0); }
int main(int ac, char **av) { char **tab = malloc(sizeof(char *) * ac); int i = 1; int j = 0; if (ac < 2) { my_putstr("\n"); return 0; } if (av[1] == NULL) { my_putstr("\n"); return 0; } while (i < ac) { if (av[i] != NULL) tab[j] = strdup(av[i]); j++; ++i; } tab[i] = NULL; qsort(&tab[0], tab_len(tab), sizeof(char *), cmpstringp); tab = sort_tab(tab); aff_tab(tab); my_putstr("\n"); return 0; }
int check_spaces(char **map) { int x; int y; y = 0; while (map[y]) { x = 0; while (map[y][x]) { if (map[y][x] == ' ') { if (map[y][x + 1] == ' ') return ((my_puterr_int ("More than one space between two elements\n", 0))); } x++; } y++; } if (my_strlen(map[0]) < 8 || tab_len(map) < 4) return ((my_puterr_int("Map muste be at least 4 x 4 on the SDL\n", 0))); return (check_space_integrity(map)); }
void command_ls(t_env *env, char **splitted) { long i; char c; write_long(env, COMMAND_LS); write_long(env, tab_len(splitted)); i = 1; while (splitted[i]) write_str(env, splitted[i++]); while ((c = read_byte(env))) ft_putchar(c); ft_putendl("SUCCESS"); (void)splitted; }
static int exit_setenv(char **tab) { if (tab_len(tab) > 3) { fprintf(stderr, "setenv: Too many arguments.\n"); return (0); } if ((tab[1] && !is_alphanum(tab[1]))) { fprintf(stderr, "setenv: Variable name must" " contain alphanumeric characters.\n"); return (0); } return (1); }
int init_draw_board(char **map, SDL_Surface **bg, t_assets *assets) { int i; i = 0; while (map[0][i] != -1) i++; assets->width = i / 3 - 2; assets->length = tab_len(map) - 2; *bg = SDL_CreateRGBSurface(SDL_HWSURFACE, WIN_X, WIN_Y, BPP, 0, 0, 0, 0); fill_bg(*bg, assets); draw_grille(*bg, assets); draw_walls(*bg, assets); return (1); }
static void insert_alias(t_alias *t1, int pos, t_alias *t2) { char **stock; char *save; int i; int k; i = -1; if (!(stock = calloc(tab_len(t1->cmd) + tab_len(t2->cmd) + 2, 8))) return ; while (++i < pos) stock[i] = t1->cmd[i]; save = t1->cmd[i]; k = i + 1; while (t2->cmd[pos]) if (!(stock[i++] = my_strdup(t2->cmd[pos++]))) return ; while (t1->cmd[k]) stock[i++] = t1->cmd[k++]; XFREE(save); XFREE(t1->cmd); t1->cmd = stock; }
int join(int fd, t_user *users, t_channel *channels, char **arg) { if (tab_len(arg) < 2) return (send_response(fd, "461", "JOIN :Not enough parameters")); if (arg[1][0] != '#') { send_403(fd, arg[1]); return (0); } if (add_in_channel(arg[1], fd, &channels) == -1) send_443(fd, arg[1], users); else return (send_response(fd, "332", arg[1])); return (0); }
void do_the_thing(t_shell *sh, char ***cmd, int flag) { int ret_check; int ret_exclam; if (flag) { *cmd = insert_str_in_tab(*cmd, "\"", 0, 0); *cmd = insert_str_in_tab(*cmd, "\"", tab_len(*cmd), 0); } if (!(ret_check = check_command(*cmd)) && (ret_exclam = replace_exclam_dot(cmd, sh)) == 1 && !man_couver(*cmd, sh)) { backquote(cmd, sh); the_execution(*cmd, sh); del_quote(*cmd); } else if (ret_check || !ret_exclam) sh->ret = 1; }
void swap_tab(int **ways, int len) { static int i; int j; int *swap; j = i; while (ways[j] != NULL) { if (tab_len(ways[j]) == len) { swap = ways[i]; ways[i] = ways[j]; ways[j] = swap; i += 1; return ; } j += 1; } }
int check_borders(char **map) { int x; int y; y = 0; while (map[y]) { x = 0; if (y == 0 || y == tab_len(map) - 1) { while (map[y][x] && (map[y][x] == '1' || map[y][x] == ' ')) x++; if (map[y][x] != '\0' && map[y][x] != '1') return (my_puterr_int("Bad borders\n", 0)); } else if (map[y][0] != '1' || map[y][my_strlen(map[y]) - 1] != '1') return (my_puterr_int("Bad borders\n", 0)); y++; } return (1); }