char *replace_variable(char *line, t_shell *sh) { char *name; char *value; char **tmp; int i; int len; line = is_tild(line, sh); if (ft_strchr(line, '$') == NULL) return (line); i = 0; tmp = sort_split(add_split(sh->env, sh->local)); while (tmp[i]) { len = 0; while (tmp[i][len] != '=') len++; name = ft_strf("$%.*s", len, tmp[i]); value = &tmp[i][len + 1]; line = replace_out(line, name, value, "'"); ft_strdel(&name); i++; } ft_memdel((void**)&tmp); return (line); }
char *ft_get_first_line(int fd, t_map *map_info) { t_list *root; t_list *node; int deep; root = NULL; deep = 0; ft_list_push_back(&root); node = root; while (read(fd, &(node->c), 1) > 0) { deep++; if (node->c == '\n') return ((deep == 1) ? NULL : ft_list_to_tab(root, deep)); if (map_info) if (ft_strf(node->c, map_info->charset)) { ft_destroy(root); return (NULL); } ft_list_push_back(&node); node = node->next; } return (NULL); }
char *protect_all(char *line) { static char *syntax = SYNTAX; char protect[2]; char *tmp; int i; if (!has_syntax_in(line)) return (line); protect[1] = '\0'; i = 0; while (syntax[i]) { if (ft_strchr(line, syntax[i])) { protect[0] = syntax[i]; tmp = ft_strf("\033@%d", (int)protect[0]); line = ft_replace(line, protect, tmp); ft_strdel(&tmp); } i++; } return (line); }