Lines Matching refs:pl

621 int run_pipeline(struct sh_pipeline **pl, int *rd)
628 if (!(pp = run_command((*pl)->arg, &rd))) rc = 0;
636 if ((*pl)->next && !(*pl)->next->type) *pl = (*pl)->next;
657 struct sh_pipeline *pl = pipeline;
660 if (pl) for (j=0; j<=pl->count; j++) {
661 for (i = 0; i<=pl->arg->c; i++) free(pl->arg[j].v[i]);
662 free(pl->arg[j].v);
664 free(pl);
668 struct sh_pipeline *block_end(struct sh_pipeline *pl)
672 while (pl) {
673 if (pl->type == 1 || pl->type == 'f') i++;
674 else if (pl->type == 3) if (--i<1) break;
675 pl = pl->next;
689 struct sh_pipeline *add_function(char *name, struct sh_pipeline *pl)
693 return block_end(pl->next);
701 struct sh_pipeline *pl = sp->pipeline ? sp->pipeline->prev : 0;
706 if (pl) {
707 arg = pl->arg;
716 } else if (pl->count != pl->here) {
717 arg += 1+pl->here;
727 pl->here++;
732 } else pl = 0;
740 if (pl && pl->count == -1) {
741 pl->count = 0;
742 arg = pl->arg;
753 pl = xrealloc(pl, sizeof(*pl) + ++pl->count*sizeof(struct sh_arg));
754 dlist_add_nomalloc((void *)&sp->pipeline, (void *)pl);
757 arg[pl->count].v = xzalloc(2*sizeof(void *));
758 *arg[pl->count].v = arg->v[++i];
759 arg[pl->count].c = -(s[2] == '<'); // note <<< as c = -1
761 pl = 0;
778 if (!pl) {
779 pl = xzalloc(sizeof(struct sh_pipeline));
780 arg = pl->arg;
781 dlist_add_nomalloc((void *)&sp->pipeline, (void *)pl);
799 if (end == start || (arg->c && *start == ')' && pl->type!='f')) {
802 if (pl->type == 'f' && arg->c<3) {
818 pl->count = -1;
839 pl->count = -1;
845 if (arg->c>1 && !strcmp(s, "(")) pl->type = 'f';
846 if (pl->type=='f') {
852 pl->count = -1;
866 pl->count = -1;
889 if (!pl->prev->type) goto flush;
890 if (!strncmp(pl->prev->arg->v[1], "((", 2)) goto flush;
902 if (!pl->type) pl->type = 1;
924 pl->type = 1;
938 pl->type = anystr(s, (char *[]){"fi", "done", "esac", "}", "]]", ")", 0})
963 if (!pl->type) pl->type = 2;
966 pl->count = -1;
971 if (!pl->type && anystr(s, (char *[]){"then", "do", "esac", "}", "]]", ")",
977 pl = sp->pipeline->prev;
978 while (pl->count<pl->here && pl->arg[pl->count].c<0)
979 pl->arg[pl->count++].c = 0;
983 if (sp->pipeline && pl->count != pl->here) return 1;
999 struct sh_pipeline *pl;
1013 for (pl = sp->pipeline; pl ; pl = (pl->next == sp->pipeline) ? 0 : pl->next) {
1014 for (i = 0; i<pl->arg->c; i++)
1015 printf("arg[%d][%ld]=%s\n", q, i, pl->arg->v[i]);
1016 printf("type=%d term[%d]=%s\n", pl->type, q++, pl->arg->v[pl->arg->c]);
1031 struct sh_pipeline *pl = sp->pipeline, *end;
1044 while (pl) {
1045 char *s = *pl->arg->v, *ss = pl->arg->v[1];
1046 //dprintf(2, "s=%s %s %d %s %d\n", s, ss, pl->type, blk ? blk->start->arg->v[0] : "X", blk ? blk->run : 0);
1048 if (!pl->type) {
1056 if (!blk || pl->arg->c>2 || ss[strspn(ss, "0123456789")]) {
1064 pl = blk->start;
1067 pl = blk->end;
1071 pl = pl->next;
1078 if (!blk) toys.exitval = run_pipeline(&pl, 0);
1079 else if (blk->run) toys.exitval = run_pipeline(&pl, blk->redir);
1080 else while (pl->next && !pl->next->type) pl = pl->next;
1083 } else if (pl->type == 1) {
1086 if (!blk || blk->start != pl) {
1089 end = block_end(pl->next);
1091 pl = end;
1092 if (pl) pl = pl->next;
1100 blk->start = pl;
1119 if (!pl->next->type) {
1120 for (i = 1; i<pl->next->arg->c; i++)
1121 expand_arg(&blk->farg, pl->next->arg->v[i], 0, &blk->fdelete);
1124 pl = pl->next;
1137 } else if (pl->type == 2) {
1148 pl = block_end(pl);
1157 } else if (pl->type == 3) {
1161 pl = blk->start;
1171 } else if (pl->type == 'f') pl = add_function(s, pl);
1173 pl = pl->next;