Esempio n. 1
0
static void
vcc_expr_fmt(struct vsb *d, int ind, const struct expr *e1)
{
	char *p;
	int i;

	for (i = 0; i < ind; i++)
		vsb_cat(d, " ");
	p = vsb_data(e1->vsb);
	while (*p != '\0') {
		if (*p == '\n') {
			vsb_putc(d, '\n');
			if (p[1] != '\0') {
				for (i = 0; i < ind; i++)
					vsb_cat(d, " ");
			}
			p++;
			continue;
		}
		if (*p != '\v') {
			vsb_putc(d, *p);
			p++;
			continue;
		}
		p++;
		switch(*p) {
		case '+': ind += 2; break;
		case '-': ind -= 2; break;
		default:
			assert(__LINE__ == 0);
		}
		p++;
	}
}
Esempio n. 2
0
static struct expr *
vcc_expr_edit(enum var_type fmt, const char *p, struct expr *e1,
    struct expr *e2)
{
	struct expr *e;
	int nl = 1;

	e = vcc_new_expr();
	while (*p != '\0') {
		if (*p == '\n') {
			if (!nl)
				vsb_putc(e->vsb, *p);
			nl = 1;
			p++;
			continue;
		}
		nl = 0;
		if (*p != '\v') {
			vsb_putc(e->vsb, *p);
			p++;
			continue;
		}
		assert(*p == '\v');
		p++;
		switch(*p) {
		case '+': vsb_cat(e->vsb, "\v+"); break;
		case '-': vsb_cat(e->vsb, "\v-"); break;
		case '1':
		case '2':
			if (*p == '1')
				vsb_cat(e->vsb, vsb_data(e1->vsb));
			else {
				AN(e2);
				vsb_cat(e->vsb, vsb_data(e2->vsb));
			}
			break;
		default:
			assert(__LINE__ == 0);
		}
		p++;
	}
	AZ(vsb_finish(e->vsb));
	if (e1 != NULL)
		e->t1 = e1->t1;
	else if (e2 != NULL)
		e->t1 = e2->t1;
	if (e2 != NULL)
		e->t2 = e2->t1;
	else if (e1 != NULL)
		e->t1 = e1->t1;
	if ((e1 == NULL || e1->constant) && (e2 == NULL || e2->constant))
		e->constant = 1;
	vcc_delete_expr(e1);
	vcc_delete_expr(e2);
	e->fmt = fmt;
	return (e);
}
Esempio n. 3
0
//lint -e{818}
void
vtc_log(struct vtclog *vl, unsigned lvl, const char *fmt, ...)
{

	CHECK_OBJ_NOTNULL(vl, VTCLOG_MAGIC);
	AZ(pthread_mutex_lock(&vl->mtx));
	assert(lvl < NLEAD);
	vsb_clear(vl->vsb);
	vsb_printf(vl->vsb, "%s %-4s ", lead[lvl], vl->id);
	va_list ap;
	va_start(ap, fmt);
	(void)vsb_vprintf(vl->vsb, fmt, ap);
	va_end(ap);
	vsb_putc(vl->vsb, '\n');
	vsb_finish(vl->vsb);
	AZ(vsb_overflowed(vl->vsb));

	vtc_log_emit(vl, lvl);

	vsb_clear(vl->vsb);
	AZ(pthread_mutex_unlock(&vl->mtx));
	if (lvl == 0) {
		vtc_error = 1;
		if (pthread_self() != vtc_thread)
			pthread_exit(NULL);
	}
}
Esempio n. 4
0
void
vcc_Expr(struct vcc *tl, enum var_type fmt)
{
	struct expr *e;
	struct token *t1;

	assert(fmt != VOID);

	t1 = tl->t;
	vcc_expr0(tl, &e, fmt);
	ERRCHK(tl);
	if (fmt == STRING || fmt == STRING_LIST)
		vcc_expr_tostring(&e, fmt);
	if (!tl->err && fmt != e->fmt)  {
		vsb_printf(tl->sb, "Expression has type %s, expected %s\n",
		    vcc_Type(e->fmt), vcc_Type(fmt));
		tl->err = 1;
	}
	if (!tl->err) {
		if (e->fmt == STRING_LIST) {
			e = vcc_expr_edit(STRING_LIST,
			    "\v+\n\v1,\nvrt_magic_string_end\v-", e, NULL);
		}
		vcc_expr_fmt(tl->fb, tl->indent, e);
		vsb_putc(tl->fb, '\n');
	} else {
		if (t1 != tl->t)
			vcc_ErrWhere2(tl, t1, tl->t);
	}
	vcc_delete_expr(e);
}
Esempio n. 5
0
/*
 * Quote a string
 */
void
vsb_quote(struct vsb *s, const char *p, int len, int how)
{
    const char *q;
    int quote = 0;

    (void)how;	/* For future enhancements */
    if (len == -1)
        len = strlen(p);

    for (q = p; q < p + len; q++) {
        if (!isgraph(*q) || *q == '"' || *q == '\\') {
            quote++;
            break;
        }
    }
    if (!quote) {
        (void)vsb_bcat(s, p, len);
        return;
    }
    (void)vsb_putc(s, '"');
    for (q = p; q < p + len; q++) {
        switch (*q) {
        case ' ':
            (void)vsb_putc(s, *q);
            break;
        case '\\':
        case '"':
            (void)vsb_putc(s, '\\');
            (void)vsb_putc(s, *q);
            break;
        case '\n':
            (void)vsb_cat(s, "\\n");
            break;
        case '\r':
            (void)vsb_cat(s, "\\r");
            break;
        case '\t':
            (void)vsb_cat(s, "\\t");
            break;
        default:
            if (isgraph(*q))
                (void)vsb_putc(s, *q);
            else
                (void)vsb_printf(s, "\\%o", *q & 0xff);
            break;
        }
    }
    (void)vsb_putc(s, '"');
}