MCPcopy Create free account
hub / github.com/F-Stack/f-stack / xo_init_handle

Function xo_init_handle

tools/libxo/libxo/libxo.c:608–657  ·  view source on GitHub ↗

* Initialize an xo_handle_t, using both static defaults and * the global settings from the LIBXO_OPTIONS environment * variable. */

Source from the content-addressed store, hash-verified

606 * variable.
607 */
608static void
609xo_init_handle (xo_handle_t *xop)
610{
611 xop->xo_opaque = stdout;
612 xop->xo_write = xo_write_to_file;
613 xop->xo_flush = xo_flush_file;
614
615 if (xo_is_line_buffered(stdout))
616 XOF_SET(xop, XOF_FLUSH_LINE);
617
618 /*
619 * We need to initialize the locale, which isn't really pretty.
620 * Libraries should depend on their caller to set up the
621 * environment. But we really can't count on the caller to do
622 * this, because well, they won't. Trust me.
623 */
624 if (!xo_locale_inited) {
625 xo_locale_inited = 1; /* Only do this once */
626
627#ifdef __FreeBSD__ /* Who does The Right Thing */
628 const char *cp = "";
629#else /* __FreeBSD__ */
630 const char *cp = getenv("LC_ALL");
631 if (cp == NULL)
632 cp = getenv("LC_CTYPE");
633 if (cp == NULL)
634 cp = getenv("LANG");
635 if (cp == NULL)
636 cp = "C"; /* Default for C programs */
637#endif /* __FreeBSD__ */
638
639 (void) setlocale(LC_CTYPE, cp);
640 }
641
642 /*
643 * Initialize only the xo_buffers we know we'll need; the others
644 * can be allocated as needed.
645 */
646 xo_buf_init(&xop->xo_data);
647 xo_buf_init(&xop->xo_fmt);
648
649 if (XOIF_ISSET(xop, XOIF_INIT_IN_PROGRESS))
650 return;
651 XOIF_SET(xop, XOIF_INIT_IN_PROGRESS);
652
653 xop->xo_indent_by = XO_INDENT_BY;
654 xo_depth_check(xop, XO_DEPTH);
655
656 XOIF_CLEAR(xop, XOIF_INIT_IN_PROGRESS);
657}
658
659/*
660 * Initialize the default handle.

Callers 2

xo_default_initFunction · 0.85
xo_createFunction · 0.85

Calls 3

xo_is_line_bufferedFunction · 0.85
xo_buf_initFunction · 0.85
xo_depth_checkFunction · 0.85

Tested by

no test coverage detected