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); }
static void http_write(const struct http *hp, int lvl, const char *pfx) { int l; vsb_finish(hp->vsb); AZ(vsb_overflowed(hp->vsb)); vtc_dump(hp->vl, lvl, pfx, vsb_data(hp->vsb)); l = write(hp->fd, vsb_data(hp->vsb), vsb_len(hp->vsb)); if (l != vsb_len(hp->vsb)) vtc_log(hp->vl, 0, "Write failed: %s", strerror(errno)); }
static void vtc_log_emit(struct vtclog *vl, unsigned lvl) { if (vtc_stop && lvl == 0) return; AZ(pthread_mutex_lock(&vtclog_mtx)); vsb_cat(vtclog_full, vsb_data(vl->vsb)); AZ(pthread_mutex_unlock(&vtclog_mtx)); if (lvl <= vtc_verbosity) (void)fputs(vsb_data(vl->vsb), stdout); }
int cli_writeres(int fd, const struct cli *cli) { int i, l; struct iovec iov[3]; char nl[2] = "\n"; char res[CLI_LINE0_LEN + 2]; /* * NUL + one more so we can catch * any misformats by snprintf */ assert(cli->result >= 100); assert(cli->result <= 999); /*lint !e650 const out of range */ i = snprintf(res, sizeof res, "%-3d %-8d\n", cli->result, vsb_len(cli->sb)); assert(i == CLI_LINE0_LEN); iov[0].iov_base = res; iov[0].iov_len = CLI_LINE0_LEN; iov[1].iov_base = vsb_data(cli->sb); iov[1].iov_len = vsb_len(cli->sb); iov[2].iov_base = nl; iov[2].iov_len = 1; for (l = i = 0; i < 3; i++) l += iov[i].iov_len; i = writev(fd, iov, 3); return (i != l); }
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++; } }
const char * vtc_logfull(void) { vsb_finish(vtclog_full); AZ(vsb_overflowed(vtclog_full)); return (vsb_data(vtclog_full)); }
static void cli_cb_after(const struct cli *cli) { ASSERT_CLI(); Lck_Unlock(&cli_mtx); VSL(SLT_CLI, 0, "Wr %03u %u %s", cli->result, vsb_len(cli->sb), vsb_data(cli->sb)); }