Lines Matching defs:pctl

104 #define	DFLTPRTOP(pctl, type) \
105 ((pctl)->nvprt_dfltops->print_##type.op)
107 #define DFLTPRTOPARG(pctl, type) \
108 ((pctl)->nvprt_dfltops->print_##type.arg)
110 #define CUSTPRTOP(pctl, type) \
111 ((pctl)->nvprt_custops->print_##type.op)
113 #define CUSTPRTOPARG(pctl, type) \
114 ((pctl)->nvprt_custops->print_##type.arg)
116 #define RENDER(pctl, type, nvl, name, val) \
119 if ((pctl)->nvprt_custops && CUSTPRTOP(pctl, type)) { \
120 done = CUSTPRTOP(pctl, type)(pctl, \
121 CUSTPRTOPARG(pctl, type), nvl, name, val); \
124 (void) DFLTPRTOP(pctl, type)(pctl, \
125 DFLTPRTOPARG(pctl, type), nvl, name, val); \
127 (void) fprintf(pctl->nvprt_fp, pctl->nvprt_eomfmt); \
130 #define ARENDER(pctl, type, nvl, name, arrp, count) \
133 if ((pctl)->nvprt_custops && CUSTPRTOP(pctl, type)) { \
134 done = CUSTPRTOP(pctl, type)(pctl, \
135 CUSTPRTOPARG(pctl, type), nvl, name, arrp, count); \
138 (void) DFLTPRTOP(pctl, type)(pctl, \
139 DFLTPRTOPARG(pctl, type), nvl, name, arrp, count); \
141 (void) fprintf(pctl->nvprt_fp, pctl->nvprt_eomfmt); \
155 indent(nvlist_prtctl_t pctl, int onemore)
159 switch (pctl->nvprt_indent_mode) {
161 (void) fprintf(pctl->nvprt_fp, "%*s",
162 pctl->nvprt_indent + onemore * pctl->nvprt_indentinc, "");
166 depth = pctl->nvprt_indent + onemore;
168 (void) fprintf(pctl->nvprt_fp, "\t");
191 nvprint_##type_and_variant(nvlist_prtctl_t pctl, void *private, \
194 FILE *fp = pctl->nvprt_fp; \
197 indent(pctl, 1); \
198 (void) fprintf(fp, pctl->nvprt_nmfmt, name); \
224 nvaprint_##type_and_variant(nvlist_prtctl_t pctl, void *private, \
227 FILE *fp = pctl->nvprt_fp; \
232 if (i == 0 || pctl->nvprt_btwnarrfmt_nl) { \
233 indent(pctl, 1); \
234 (void) fprintf(fp, pctl->nvprt_nmfmt, name); \
235 if (pctl->nvprt_btwnarrfmt_nl) \
239 (void) fprintf(fp, pctl->nvprt_btwnarrfmt); \
259 nvprint_nvlist(nvlist_prtctl_t pctl, void *private,
262 FILE *fp = pctl->nvprt_fp;
264 indent(pctl, 1);
267 pctl->nvprt_indent += pctl->nvprt_indentinc;
268 nvlist_print_with_indent(value, pctl);
269 pctl->nvprt_indent -= pctl->nvprt_indentinc;
271 indent(pctl, 1);
279 nvaprint_nvlist_array(nvlist_prtctl_t pctl, void *private,
282 FILE *fp = pctl->nvprt_fp;
285 indent(pctl, 1);
289 indent(pctl, 1);
292 pctl->nvprt_indent += pctl->nvprt_indentinc;
293 nvlist_print_with_indent(valuep[i], pctl);
294 pctl->nvprt_indent -= pctl->nvprt_indentinc;
296 indent(pctl, 1);
312 nvlist_prtctl_setdest(nvlist_prtctl_t pctl, FILE *fp)
314 pctl->nvprt_fp = fp;
318 nvlist_prtctl_getdest(nvlist_prtctl_t pctl)
320 return (pctl->nvprt_fp);
325 nvlist_prtctl_setindent(nvlist_prtctl_t pctl, enum nvlist_indent_mode mode,
337 pctl->nvprt_indent_mode = mode;
338 pctl->nvprt_indent = start;
339 pctl->nvprt_indentinc = inc;
343 nvlist_prtctl_doindent(nvlist_prtctl_t pctl, int onemore)
345 indent(pctl, onemore);
350 nvlist_prtctl_setfmt(nvlist_prtctl_t pctl, enum nvlist_prtctl_fmt which,
357 pctl->nvprt_nmfmt = fmt;
363 pctl->nvprt_eomfmt = fmt;
368 pctl->nvprt_btwnarrfmt = " ";
369 pctl->nvprt_btwnarrfmt_nl = 0;
371 pctl->nvprt_btwnarrfmt = fmt;
372 pctl->nvprt_btwnarrfmt_nl = (strstr(fmt, "\n") != NULL);
383 nvlist_prtctl_dofmt(nvlist_prtctl_t pctl, enum nvlist_prtctl_fmt which, ...)
385 FILE *fp = pctl->nvprt_fp;
394 (void) fprintf(fp, pctl->nvprt_nmfmt, name);
398 (void) fprintf(fp, pctl->nvprt_eomfmt);
402 (void) fprintf(fp, pctl->nvprt_btwnarrfmt); \
422 nvlist_prtctlop_##type(nvlist_prtctl_t pctl, \
426 CUSTPRTOP(pctl, type) = func; \
427 CUSTPRTOPARG(pctl, type) = private; \
448 nvlist_prtctlop_##type(nvlist_prtctl_t pctl, \
452 CUSTPRTOP(pctl, type) = func; \
453 CUSTPRTOPARG(pctl, type) = private; \
509 prtctl_defaults(FILE *fp, struct nvlist_prtctl *pctl,
512 pctl->nvprt_fp = fp;
513 pctl->nvprt_indent_mode = NVLIST_INDENT_TABBED;
514 pctl->nvprt_indent = 0;
515 pctl->nvprt_indentinc = 1;
516 pctl->nvprt_nmfmt = "%s = ";
517 pctl->nvprt_eomfmt = "\n";
518 pctl->nvprt_btwnarrfmt = " ";
519 pctl->nvprt_btwnarrfmt_nl = 0;
521 pctl->nvprt_dfltops = (struct nvlist_printops *)&defprtops;
522 pctl->nvprt_custops = ops;
528 struct nvlist_prtctl *pctl;
531 if ((pctl = malloc(sizeof (*pctl))) == NULL)
535 free(pctl);
539 prtctl_defaults(stdout, pctl, ops);
541 return (pctl);
545 nvlist_prtctl_free(nvlist_prtctl_t pctl)
547 if (pctl != NULL) {
548 free(pctl->nvprt_custops);
549 free(pctl);
565 nvlist_print_with_indent(nvlist_t *nvl, nvlist_prtctl_t pctl)
567 FILE *fp = pctl->nvprt_fp;
575 indent(pctl, 0);
588 RENDER(pctl, boolean, nvl, name, 1);
594 RENDER(pctl, boolean_value, nvl, name, val);
600 RENDER(pctl, byte, nvl, name, val);
606 RENDER(pctl, int8, nvl, name, val);
612 RENDER(pctl, uint8, nvl, name, val);
618 RENDER(pctl, int16, nvl, name, val);
624 RENDER(pctl, uint16, nvl, name, val);
630 RENDER(pctl, int32, nvl, name, val);
636 RENDER(pctl, uint32, nvl, name, val);
642 RENDER(pctl, int64, nvl, name, val);
648 RENDER(pctl, uint64, nvl, name, val);
654 RENDER(pctl, double, nvl, name, val);
660 RENDER(pctl, string, nvl, name, val);
666 ARENDER(pctl, boolean_array, nvl, name, val, nelem);
672 ARENDER(pctl, byte_array, nvl, name, val, nelem);
678 ARENDER(pctl, int8_array, nvl, name, val, nelem);
684 ARENDER(pctl, uint8_array, nvl, name, val, nelem);
690 ARENDER(pctl, int16_array, nvl, name, val, nelem);
696 ARENDER(pctl, uint16_array, nvl, name, val, nelem);
702 ARENDER(pctl, int32_array, nvl, name, val, nelem);
708 ARENDER(pctl, uint32_array, nvl, name, val, nelem);
714 ARENDER(pctl, int64_array, nvl, name, val, nelem);
720 ARENDER(pctl, uint64_array, nvl, name, val, nelem);
726 ARENDER(pctl, string_array, nvl, name, val, nelem);
732 RENDER(pctl, hrtime, nvl, name, val);
738 RENDER(pctl, nvlist, nvl, name, val);
744 ARENDER(pctl, nvlist_array, nvl, name, val, nelem);
765 nvlist_prt(nvlist_t *nvl, nvlist_prtctl_t pctl)
767 nvlist_print_with_indent(nvl, pctl);