/* * Dump column header to @xd. * @ca[] describes fields. * Does nothing unless @xd is human-readable. */ void xdcolhdr(struct xdstr *xd, struct castr ca[]) { int i, j, n; char *sep = ""; if (!xd->human) return; for (i = 0; ca[i].ca_name; ++i) { if (ca[i].ca_flags & NSC_DEITY && !xd->divine) continue; if (ca[i].ca_dump == CA_DUMP_NONE) continue; n = CA_ARRAY_LEN(&ca[i]); if (n) { for (j = 0; j < n; j++) { xd->pr("%s%s(%d)", sep, ca[i].ca_name, j); sep = " "; } } else { xd->pr("%s%s", sep, ca[i].ca_name); sep = " "; } } xd->pr("\n"); }
/* * Dump field values of a context object to @xd. * @ca[] describes fields. * @ptr points to context object. */ void xdflds(struct xdstr *xd, struct castr ca[], void *ptr) { int i, j, n; struct valstr val; char *sep = ""; for (i = 0; ca[i].ca_name; ++i) { if (ca[i].ca_flags & NSC_DEITY && !xd->divine) continue; if (ca[i].ca_dump == CA_DUMP_NONE) continue; if (ca[i].ca_dump == CA_DUMP_ONLY && xd->cnum == NATID_BAD) continue; n = CA_ARRAY_LEN(&ca[i]); j = 0; do { xdeval(&val, xd, &ca[i], ptr, j); sep = xdprval_sym(xd, &val, &ca[i], sep); } while (++j < n); } }
static int verify_row(int type, int row) { struct castr *ca = ef_cadef(type); struct empobj *row_ref; int i, j, n; struct valstr val; int ret_val = 0; int flags = ef_flags(type); if (flags & EFF_MEM) row_ref = ef_ptr(type, row); else { row_ref = malloc(empfile[type].size); ef_read(type, row, row_ref); } if ((flags & EFF_TYPED) && !EF_IS_VIEW(type)) { if (row_ref->ef_type != type || row_ref->uid != row) { verify_fail(type, row, NULL, 0, "header corrupt"); ret_val = -1; } } if (!empobj_in_use(type, row_ref)) goto out; for (i = 0; ca[i].ca_name; ++i) { if (ca[i].ca_get) continue; /* virtual */ n = CA_ARRAY_LEN(&ca[i]); j = 0; do { if (ca[i].ca_table == EF_BAD) continue; nstr_mksymval(&val, &ca[i], j); nstr_eval(&val, 0, row_ref, NSC_NOTYPE); if (CANT_HAPPEN(val.val_type != NSC_LONG)) { ret_val = -1; continue; } if (ca[i].ca_table == type && i == 0) { /* uid */ if (val.val_as.lng != row) { verify_fail(type, row, &ca[i], j, "value is %ld instead of %d", val.val_as.lng, row); ret_val = -1; } } else { if (verify_tabref(type, row, &ca[i], j, val.val_as.lng) < 0) ret_val = -1; } } while (++j < n); } out: if (!(flags & EFF_MEM)) free(row_ref); return ret_val; }