/* 3.9.4.1 parse a grouping compound * * The format for grouping commands is a s follows: * * (compound-list) Execute compound-list in a subshell environment; * Variable assignments and built-in commands that * affect the environment shall not remain in effect * after the list finishes. * * { compound-list;} Execute compound-list in the current process * environment. * * ----------------------------------------------------------------------- */ union node *parse_grouping(struct parser *p) { enum tok_flag tok; union node **rptr; union node *grouping; union node *compound_list; /* return NULL on empty compound */ grouping = NULL; if(!(tok = parse_expect(p, P_DEFAULT, T_BEGIN|T_LP, NULL))) return NULL; /* parse compound content and create a compound node if there are commands */ if((compound_list = parse_compound_list(p))) { grouping = tree_newnode(tok == T_BEGIN ? N_CMDLIST : N_SUBSHELL); grouping->ngrp.cmds = compound_list; } /* expect the appropriate ending token */ if(!parse_expect(p, P_DEFAULT, tok << 1, grouping)) return NULL; if(grouping) { tree_init(grouping->ngrp.rdir, rptr); /* now any redirections may follow */ while(parse_gettok(p, P_DEFAULT) & T_REDIR) tree_move(p->tree, rptr); p->pushback++; } return grouping; }
static t_node *argv_wa_tree(int ac, int i, char **av) { int (*s)(void *, void *); t_node *root; t_node *no; t_ls_entry e; root = NULL; s = g_ls_select_argvsort(env()->o); while (i < ac) { e = ls_newentry(av[i], av[i]); errno = 0; if (!(no = tree_newnode((void *)&e, sizeof(t_ls_entry)))) { ft_err(env()->av, av[i]); errno = 0; tree_del(&root, NULL); return (NULL); } maj_env(e); tree_add(&root, no, s); i++; } return (root); }
int entry_tree(t_node **ar, struct dirent *entry, \ quad_t *blocks, int *i) { char absname[PATHSIZE_LS]; t_ls_entry e; t_node *no; ft_strcpy(absname, env()->path); ft_strcat(absname, "/"); ft_strcat(absname, entry->d_name); e = ls_newentry(entry->d_name, absname); if (entry->d_name[0] == '.' && !((env()->o & O_HIDE) == O_HIDE)) e.handle = 0; if (e.handle) { *i += 1; *blocks += e.stat.st_blocks; } if (!ft_strcmp(entry->d_name, ".") || !ft_strcmp(entry->d_name, "..")) e.handle = 0; if (!(no = tree_newnode((void *)&e, sizeof(t_ls_entry)))) return (ft_err(env()->av, absname)); tree_add(ar, no, g_ls_select_sort(env()->o)); maj_env(e); return (1); }
static t_node *argv_woa_tree(void) { t_ls_entry e; e = ls_newentry(".", "."); return (tree_newnode((void *)&e, sizeof(t_ls_entry))); }
/* allocate a tree node and link * ----------------------------------------------------------------------- */ union node *tree_newlink(union node **nptr, enum nod_id nod) { union node *n = tree_newnode(nod); if(*nptr == NULL) *nptr = n; else (*nptr)->list.next = n; return n; }