Example #1
0
File: deparse.c Project: att/ast
static_fn void p_comarg(const struct comnod *com) {
    int flag = end_line;

    if (com->comtyp & FAMP) sfwrite(outfile, "& ", 2);
    if (com->comarg || com->comio) flag = ' ';
    if (com->comset) p_arg(com->comset, flag, POST);
    if (com->comarg) {
        if (!com->comio) flag = end_line;
        if (com->comtyp & COMSCAN) {
            p_arg(com->comarg, flag, POST);
        } else {
            p_comlist((struct dolnod *)com->comarg, flag);
        }
    }
    if (com->comio) p_redirect(com->comio);
}
Example #2
0
File: deparse.c Project: att/ast
static_fn void p_arg(const struct argnod *arg, int endchar, int opts) {
    int flag = -1;

    do {
        if (!arg->argnxt.ap) {
            flag = endchar;
        } else if (opts & PRE) {  // case alternation lists in reverse order
            p_arg(arg->argnxt.ap, '|', opts);
            flag = endchar;
        } else if (opts) {
            flag = ' ';
        }
        const char *cp = arg->argval;
        if (*cp == 0 && (arg->argflag & ARG_EXP) && arg->argchn.ap) {
            int c = (arg->argflag & ARG_RAW) ? '>' : '<';
            sfputc(outfile, c);
            sfputc(outfile, '(');
            p_tree((Shnode_t *)arg->argchn.ap, 0);
            sfputc(outfile, ')');
        } else if (*cp == 0 && opts == POST && arg->argchn.ap) {  // compound assignment
            struct fornod *fp = (struct fornod *)arg->argchn.ap;
            sfprintf(outfile, "%s=(\n", fp->fornam);
            sfnputc(outfile, '\t', ++level);
            p_tree(fp->fortre, 0);
            if (--level) sfnputc(outfile, '\t', level);
            sfputc(outfile, ')');
        } else if ((arg->argflag & ARG_RAW) && (cp[1] || (*cp != '[' && *cp != ']'))) {
            cp = sh_fmtq(cp);
        }
        sfputr(outfile, cp, flag);
        if (flag == '\n') begin_line = 1;
        arg = arg->argnxt.ap;
    } while ((opts & POST) && arg);
}
UStatus
ua_sensors_haptic_vibrate_with_pattern(
    UASensorsHaptic* sensor,
    uint32_t pattern[MAX_PATTERN_SIZE],
    uint32_t repeat)
{
    if (sensor == nullptr)
        return U_STATUS_ERROR;

    auto s = static_cast<Holder<UbuntuApplicationSensorsHaptic*>*>(sensor);

    if (s->value->enabled == false)
        return U_STATUS_ERROR;

    std::vector<uint32_t> p_arg (pattern, pattern + MAX_PATTERN_SIZE);

    try
    {
        s->value->session->invoke_method_synchronously<uas::USensorD::Haptic::VibratePattern, void>(p_arg, repeat);
    }
    catch (const std::runtime_error& e)
    {
        std::cout << e.what() << std::endl;
        return U_STATUS_ERROR;
    }
    
    return U_STATUS_SUCCESS;
}
Example #4
0
static void p_comarg(register const struct comnod *com)
{
	register int flag = end_line;
	if(com->comarg || com->comio)
		flag = ' ';
	if(com->comset)
		p_arg(com->comset,flag,POST);
	if(com->comarg)
	{
		if(!com->comio)
			flag = end_line;
		if(com->comtyp&COMSCAN)
			p_arg(com->comarg,flag,POST);
		else
			p_comlist((struct dolnod*)com->comarg,flag);
	}
	if(com->comio)
		p_redirect(com->comio);
	return;
}
Example #5
0
File: deparse.c Project: att/ast
static_fn void p_switch(const struct regnod *reg) {
    if (level > 1) sfnputc(outfile, '\t', level - 1);
    p_arg(reg->regptr, ')', PRE);
    begin_line = 0;
    sfputc(outfile, '\t');
    if (reg->regcom) p_tree(reg->regcom, 0);
    level++;
    if (reg->regflag) {
        p_keyword(";&", END);
    } else {
        p_keyword(";;", END);
    }
    if (reg->regnxt) p_switch(reg->regnxt);
}
Example #6
0
static void p_arg(register const struct argnod *arg,register int endchar,int opts)
{
	register const char *cp;
	register int flag;
	do
	{
		if(!arg->argnxt.ap)
			flag = endchar;
		else if(opts&PRE)
		{
			/* case alternation lists in reverse order */
			p_arg(arg->argnxt.ap,'|',opts);
			flag = endchar;
		}
		else if(opts)
			flag = ' ';
		cp = arg->argval;
		if(*cp==0 && opts==POST && arg->argchn.ap)
		{
			/* compound assignment */
			struct fornod *fp=(struct fornod*)arg->argchn.ap;
			sfprintf(outfile,"%s=(\n",fp->fornam);
			sfnputc(outfile,'\t',++level);
			p_tree(fp->fortre,0);
			if(--level)
				sfnputc(outfile,'\t',level);
			sfputc(outfile,')');
		}
		else if((arg->argflag&ARG_RAW) && (cp[1] || (*cp!='[' && *cp!=']')))
			cp = sh_fmtq(cp);
		sfputr(outfile,cp,flag);
		if(flag=='\n')
			begin_line = 1;
		arg = arg->argnxt.ap;
	}
	while((opts&POST) && arg);
	return;
}
Example #7
0
File: deparse.c Project: att/ast
// Print script corresponding to shell tree <t>.
static_fn void p_tree(const Shnode_t *t, int tflags) {
    char *cp = NULL;
    int save = end_line;
    int needbrace = (tflags & NEED_BRACE);
    int bracket = 0;

    tflags &= ~NEED_BRACE;
    if (tflags & NO_NEWLINE) {
        end_line = ' ';
    } else {
        end_line = '\n';
    }
    int cmd_type = t->tre.tretyp & COMMSK;
    switch (cmd_type) {
        case TTIME: {
            if (t->tre.tretyp & COMSCAN) {
                p_keyword("!", BEGIN);
            } else {
                p_keyword("time", BEGIN);
            }
            if (t->par.partre) p_tree(t->par.partre, tflags);
            level--;
            break;
        }
        case TCOM: {
            if (begin_line && level > 0) sfnputc(outfile, '\t', level);
            begin_line = 0;
            p_comarg((struct comnod *)t);
            break;
        }
        case TSETIO: {
            if (t->tre.tretyp & FPCL) {
                tflags |= NEED_BRACE;
            } else {
                tflags = NO_NEWLINE | NEED_BRACE;
            }
            p_tree(t->fork.forktre, tflags);
            p_redirect(t->fork.forkio);
            break;
        }
        case TFORK: {
            if (needbrace) tflags |= NEED_BRACE;
            if (t->tre.tretyp & (FAMP | FCOOP)) {
                tflags = NEED_BRACE | NO_NEWLINE;
                end_line = ' ';
            } else if (t->fork.forkio) {
                tflags = NO_NEWLINE;
            }
            p_tree(t->fork.forktre, tflags);
            if (t->fork.forkio) p_redirect(t->fork.forkio);
            if (t->tre.tretyp & FCOOP) {
                sfputr(outfile, "|&", '\n');
                begin_line = 1;
            } else if (t->tre.tretyp & FAMP) {
                sfputr(outfile, "&", '\n');
                begin_line = 1;
            }
            break;
        }
        case TIF: {
            p_keyword("if", BEGIN);
            p_tree(t->if_.iftre, 0);
            p_keyword("then", MIDDLE);
            p_tree(t->if_.thtre, 0);
            if (t->if_.eltre) {
                p_keyword("else", MIDDLE);
                p_tree(t->if_.eltre, 0);
            }
            p_keyword("fi", END);
            break;
        }
        case TWH: {
            if (t->wh.whinc) {
                cp = "for";
            } else if (t->tre.tretyp & COMSCAN) {
                cp = "until";
            } else {
                cp = "while";
            }
            p_keyword(cp, BEGIN);
            if (t->wh.whinc) {
                struct argnod *arg = (t->wh.whtre)->ar.arexpr;
                sfprintf(outfile, "(( %s; ", forinit);
                forinit = "";
                sfputr(outfile, arg->argval, ';');
                arg = (t->wh.whinc)->arexpr;
                sfprintf(outfile, " %s))\n", arg->argval);
            } else {
                p_tree(t->wh.whtre, 0);
            }
            t = t->wh.dotre;
            p_keyword("do", MIDDLE);
            p_tree(t, 0);
            p_keyword("done", END);
            break;
        }
        case TLST: {
            Shnode_t *tr = t->lst.lstrit;
            if (tr->tre.tretyp == TWH && tr->wh.whinc && t->lst.lstlef->tre.tretyp == TARITH) {
                // Arithmetic for statement.
                struct argnod *init = (t->lst.lstlef)->ar.arexpr;
                forinit = init->argval;
                p_tree(t->lst.lstrit, tflags);
                break;
            }
            if (needbrace) p_keyword("{", BEGIN);
            p_tree(t->lst.lstlef, 0);
            if (needbrace) tflags = 0;
            p_tree(t->lst.lstrit, tflags);
            if (needbrace) p_keyword("}", END);
            break;
        }
        case TAND:
        case TORF:
        case TFIL: {
            if (cmd_type == TAND) {
                cp = "&&";
            } else if (cmd_type == TORF) {
                cp = "||";
            } else {
                cp = "|";
            }
            if (t->tre.tretyp & TTEST) {
                tflags |= NO_NEWLINE;
                if (!(tflags & NO_BRACKET)) {
                    p_keyword("[[", BEGIN);
                    tflags |= NO_BRACKET;
                    bracket = 1;
                }
            }
            p_tree(t->lst.lstlef, NEED_BRACE | NO_NEWLINE | (tflags & NO_BRACKET));
            if (tflags & FALTPIPE) {
                Shnode_t *tt = t->lst.lstrit;
                if (tt->tre.tretyp != TFIL || !(tt->lst.lstlef->tre.tretyp & FALTPIPE)) {
                    sfputc(outfile, '\n');
                    return;
                }
            }
            sfputr(outfile, cp, here_doc ? '\n' : ' ');
            if (here_doc) {
                here_body(here_doc);
                here_doc = 0;
            }
            level++;
            p_tree(t->lst.lstrit, tflags | NEED_BRACE);
            if (bracket) p_keyword("]]", END);
            level--;
            break;
        }
        case TPAR: {
            p_keyword("(", BEGIN);
            p_tree(t->par.partre, 0);
            p_keyword(")", END);
            break;
        }
        case TARITH: {
            struct argnod *ap = t->ar.arexpr;
            if (begin_line && level) sfnputc(outfile, '\t', level);
            sfprintf(outfile, "(( %s ))%c", ap->argval, end_line);
            if (!(tflags & NO_NEWLINE)) begin_line = 1;
            break;
        }
        case TFOR: {
            cp = ((t->tre.tretyp & COMSCAN) ? "select" : "for");
            p_keyword(cp, BEGIN);
            sfputr(outfile, t->for_.fornam, ' ');
            if (t->for_.forlst) {
                sfputr(outfile, "in", ' ');
                tflags = end_line;
                end_line = '\n';
                p_comarg(t->for_.forlst);
                end_line = tflags;
            } else {
                sfputc(outfile, '\n');
            }
            begin_line = 1;
            t = t->for_.fortre;
            p_keyword("do", MIDDLE);
            p_tree(t, 0);
            p_keyword("done", END);
            break;
        }
        case TSW: {
            p_keyword("case", BEGIN);
            p_arg(t->sw.swarg, ' ', 0);
            if (t->sw.swlst) {
                begin_line = 1;
                sfputr(outfile, "in", '\n');
                tflags = end_line;
                end_line = '\n';
                p_switch(t->sw.swlst);
                end_line = tflags;
            }
            p_keyword("esac", END);
            break;
        }
        case TFUN: {
            if (t->tre.tretyp & FPOSIX) {
                sfprintf(outfile, "%s", t->funct.functnam);
                p_keyword("()\n", BEGIN);
            } else {
                p_keyword("function", BEGIN);
                tflags = (t->funct.functargs ? ' ' : '\n');
                sfputr(outfile, t->funct.functnam, tflags);
                if (t->funct.functargs) {
                    tflags = end_line;
                    end_line = '\n';
                    p_comarg(t->funct.functargs);
                    end_line = tflags;
                }
            }
            begin_line = 1;
            p_keyword("{\n", MIDDLE);
            begin_line = 1;
            p_tree(t->funct.functtre, 0);
            p_keyword("}", END);
            break;
        }
        case TTST: {  // new test compound command
            if (!(tflags & NO_BRACKET)) p_keyword("[[", BEGIN);
            if ((t->tre.tretyp & TPAREN) == TPAREN) {
                p_keyword("(", BEGIN);
                p_tree(t->lst.lstlef, NO_BRACKET | NO_NEWLINE);
                p_keyword(")", END);
            } else {
                int flags = (t->tre.tretyp) >> TSHIFT;
                if (t->tre.tretyp & TNEGATE) sfputr(outfile, "!", ' ');
                if (t->tre.tretyp & TUNARY) {
                    un_op[1] = flags;
                    sfputr(outfile, un_op, ' ');
                } else {
                    cp = ((char *)(shtab_testops + (flags & 037) - 1)->sh_name);
                }
                p_arg(&(t->lst.lstlef->arg), ' ', 0);
                if (t->tre.tretyp & TBINARY) {
                    assert(cp);
                    sfputr(outfile, cp, ' ');
                    p_arg(&(t->lst.lstrit->arg), ' ', 0);
                }
            }
            if (!(tflags & NO_BRACKET)) p_keyword("]]", END);
        }
        default: { break; }
    }

    while (begin_line && here_doc) {
        here_body(here_doc);
        here_doc = 0;
    }
    end_line = save;
}