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();
96 bool old_fancy =
false;
100 if (out->
dest != stdout) {
101 out->
dest = freopen(NULL,
"w", out->
dest);
108 old_fancy = priv->fancy;
114 priv->fancy = old_fancy;
119 const char *proc_stdout,
const char *proc_stderr) {
122 if (proc_stdout != NULL) {
123 fprintf(out->
dest,
"%s\n", proc_stdout);
126 if (proc_stderr != NULL) {
127 fprintf(out->
dest,
"%s\n", proc_stderr);
139 fprintf(out->
dest,
"Written by Andrew Beekhof and " 140 "the Pacemaker project contributors\n");
152 va_start(ap, format);
157 len = vfprintf(stderr, format, ap);
162 fprintf(stderr,
"\n");
173 if (out->is_quiet(out)) {
177 va_start(ap, format);
182 len = vfprintf(out->dest, format, ap);
187 fprintf(out->dest,
"\n");
206 text_begin_list(
pcmk__output_t *out, const
char *singular_noun, const
char *plural_noun,
207 const
char *format, ...) {
215 va_start(ap, format);
217 if ((fancy || priv->fancy) && (format != NULL)) {
219 fprintf(out->dest,
":\n");
229 g_queue_push_tail(priv->parent_q, new_list);
234 text_list_item(
pcmk__output_t *out, const
char *
id, const
char *format, ...) {
241 va_start(ap, format);
243 if (fancy || priv->fancy) {
250 vfprintf(out->dest, format, ap);
258 fputc(
'\n', out->dest);
262 out->increment_list(out);
273 tail = g_queue_peek_tail(priv->parent_q);
286 node = g_queue_pop_tail(priv->parent_q);
288 if (node->singular_noun != NULL && node->plural_noun != NULL) {
289 if (node->len == 1) {
296 free_list_data(node);
308 fprintf(out->
dest,
"\n");
315 if (out->
dest == stdout) {
316 fprintf(out->
dest,
".");
319 fprintf(out->
dest,
"\n");
328 if (retval == NULL) {
335 retval->
init = text_init;
337 retval->
finish = text_finish;
338 retval->
reset = text_reset;
344 retval->
version = text_version;
345 retval->
info = text_info;
347 retval->
err = text_err;
356 retval->
spacer = text_spacer;
405 priv->fancy = enabled;
417 len = vfprintf(out->dest, format, args);
428 va_start(ap, format);
443 if (fancy || priv->fancy) {
449 level = g_queue_get_length(priv->parent_q);
451 for (
int i = 0; i < level; i++) {
452 fprintf(out->dest,
" ");
456 fprintf(out->dest,
"* ");
470 va_start(ap, format);
479 struct termios settings;
480 tcflag_t orig_c_lflag = 0;
486 rc = tcgetattr(0, &settings);
488 orig_c_lflag = settings.c_lflag;
489 settings.c_lflag &= ~ECHO;
490 rc = tcsetattr(0, TCSANOW, &settings);
495 fprintf(stderr,
"%s: ", prompt);
503 rc = scanf(
"%ms", dest);
506 rc = scanf(
"%1023s", *dest);
508 fprintf(stderr,
"\n");
516 if (orig_c_lflag != 0) {
517 settings.c_lflag = orig_c_lflag;
518 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.
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)