21 static gboolean fancy = FALSE;
25 {
"text-fancy", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &fancy,
26 "Use more highly formatted output (requires --output-as=text)",
32 typedef struct text_list_data_s {
38 typedef struct private_data_s {
44 free_list_data(gpointer
data) {
47 free(list_data->singular_noun);
48 free(list_data->plural_noun);
55 if (out == NULL || out->
priv == NULL) {
61 g_queue_free_full(priv->parent_q, free_list_data);
73 if (out->
priv != NULL) {
78 if (out->
priv == NULL) {
83 priv->parent_q = g_queue_new();
97 bool old_fancy =
false;
101 if (out->
dest != stdout) {
102 out->
dest = freopen(NULL,
"w", out->
dest);
109 old_fancy = priv->fancy;
115 priv->fancy = old_fancy;
120 const char *proc_stdout,
const char *proc_stderr) {
123 if (proc_stdout != NULL) {
124 fprintf(out->
dest,
"%s\n", proc_stdout);
127 if (proc_stderr != NULL) {
128 fprintf(out->
dest,
"%s\n", proc_stderr);
141 fprintf(out->
dest,
"Written by Andrew Beekhof and " 142 "the Pacemaker project contributors\n");
153 va_start(ap, format);
158 vfprintf(stderr, format, ap);
162 fprintf(stderr,
"\n");
172 if (out->is_quiet(out)) {
176 va_start(ap, format);
181 vfprintf(out->dest, format, ap);
185 fprintf(out->dest,
"\n");
204 text_begin_list(
pcmk__output_t *out, const
char *singular_noun, const
char *plural_noun,
205 const
char *format, ...) {
213 va_start(ap, format);
215 if ((fancy || priv->fancy) && (format != NULL)) {
217 fprintf(out->dest,
":\n");
227 g_queue_push_tail(priv->parent_q, new_list);
232 text_list_item(
pcmk__output_t *out, const
char *
id, const
char *format, ...) {
239 va_start(ap, format);
241 if (fancy || priv->fancy) {
248 vfprintf(out->dest, format, ap);
256 fputc(
'\n', out->dest);
260 out->increment_list(out);
271 tail = g_queue_peek_tail(priv->parent_q);
284 node = g_queue_pop_tail(priv->parent_q);
286 if (node->singular_noun != NULL && node->plural_noun != NULL) {
287 if (node->len == 1) {
294 free_list_data(node);
306 fprintf(out->
dest,
"\n");
313 if (out->
dest == stdout) {
314 fprintf(out->
dest,
".");
317 fprintf(out->
dest,
"\n");
326 if (retval == NULL) {
333 retval->
init = text_init;
335 retval->
finish = text_finish;
336 retval->
reset = text_reset;
342 retval->
version = text_version;
343 retval->
info = text_info;
345 retval->
err = text_err;
354 retval->
spacer = text_spacer;
403 priv->fancy = enabled;
412 vfprintf(out->dest, format, args);
422 va_start(ap, format);
437 if (fancy || priv->fancy) {
443 level = g_queue_get_length(priv->parent_q);
445 for (
int i = 0; i < level; i++) {
446 fprintf(out->dest,
" ");
450 fprintf(out->dest,
"* ");
464 va_start(ap, format);
473 struct termios settings;
474 tcflag_t orig_c_lflag = 0;
479 rc = tcgetattr(0, &settings);
481 orig_c_lflag = settings.c_lflag;
482 settings.c_lflag &= ~ECHO;
483 rc = tcsetattr(0, TCSANOW, &settings);
488 fprintf(stderr,
"%s: ", prompt);
496 rc = scanf(
"%ms", dest);
499 rc = scanf(
"%1023s", *dest);
501 fprintf(stderr,
"\n");
509 if (orig_c_lflag != 0) {
510 settings.c_lflag = orig_c_lflag;
511 tcsetattr(0, TCSANOW, &settings);
void(* end_list)(pcmk__output_t *out)
#define CRM_CHECK(expr, failure_action)
void pcmk__indented_vprintf(pcmk__output_t *out, const char *format, va_list args)
int(* message)(pcmk__output_t *out, const char *message_id,...)
const char * fmt_name
The name of this output formatter.
bool(* is_quiet)(pcmk__output_t *out)
void pcmk__text_prompt(const char *prompt, bool echo, char **dest)
void(* spacer)(pcmk__output_t *out)
void pcmk__register_message(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
enum crm_exit_e crm_exit_t
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void pcmk__output_text_set_fancy(pcmk__output_t *out, bool enabled)
#define PACEMAKER_VERSION
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
void pcmk__formatted_vprintf(pcmk__output_t *out, const char *format, va_list args)
void(* prompt)(const char *prompt, bool echo, char **dest)
void * priv
Implementation-specific private data.
void(* register_message)(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
bool quiet
Should this formatter supress most output?
struct private_data_s private_data_t
void(* free_priv)(pcmk__output_t *out)
bool(* init)(pcmk__output_t *out)
int(*) int(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
int(*) int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
int(*) int(* transient)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
pcmk__output_t * pcmk__mk_text_output(char **argv)
void pcmk__indented_printf(pcmk__output_t *out, const char *format,...)
#define pcmk__str_copy(str)
bool pcmk__output_text_get_fancy(pcmk__output_t *out)
struct private_data_s private_data_t
FILE * dest
Where output should be written.
#define pcmk__assert(expr)
void(*) void(* list_item)(pcmk__output_t *out, const char *name, const char *format,...) G_GNUC_PRINTF(3
gchar * request
A copy of the request that generated this output.
This structure contains everything that makes up a single output formatter.
void(* version)(pcmk__output_t *out, bool extended)
GOptionEntry pcmk__text_output_entries[]
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
struct text_list_data_s text_list_data_t
void(* reset)(pcmk__output_t *out)
void(* progress)(pcmk__output_t *out, bool end)
#define pcmk__assert_alloc(nmemb, size)
gchar * pcmk__quote_cmdline(gchar **argv)
void pcmk__formatted_printf(pcmk__output_t *out, const char *format,...)
void(*) void(*) void(* increment_list)(pcmk__output_t *out)
void(* subprocess_output)(pcmk__output_t *out, int exit_status, const char *proc_stdout, const char *proc_stderr)