17 static gboolean fancy = FALSE;
20 {
"text-fancy", 0, 0, G_OPTION_ARG_NONE, &fancy,
21 "Use more highly formatted output (requires --output-as=text)",
27 typedef struct text_list_data_s {
33 typedef struct private_data_s {
45 g_queue_free(priv->parent_q);
55 if (out->
priv != NULL) {
59 if (out->
priv == NULL) {
66 priv->parent_q = g_queue_new();
79 if (out->
dest != stdout) {
80 out->
dest = freopen(NULL,
"w", out->
dest);
91 const char *proc_stdout,
const char *proc_stderr) {
94 if (proc_stdout != NULL) {
95 fprintf(out->
dest,
"%s\n", proc_stdout);
98 if (proc_stderr != NULL) {
99 fprintf(out->
dest,
"%s\n", proc_stderr);
111 fprintf(out->
dest,
"Written by Andrew Beekhof and " 112 "the Pacemaker project contributors\n");
124 va_start(ap, format);
129 len = vfprintf(stderr, format, ap);
134 fprintf(stderr,
"\n");
145 if (out->is_quiet(out)) {
149 va_start(ap, format);
154 len = vfprintf(out->dest, format, ap);
159 fprintf(out->dest,
"\n");
171 text_begin_list(
pcmk__output_t *out, const
char *singular_noun, const
char *plural_noun,
172 const
char *format, ...) {
180 va_start(ap, format);
182 if (fancy && format) {
184 fprintf(out->dest,
":\n");
194 g_queue_push_tail(priv->parent_q, new_list);
199 text_list_item(
pcmk__output_t *out, const
char *
id, const
char *format, ...) {
204 va_start(ap, format);
213 vfprintf(out->dest, format, ap);
221 fputc(
'\n', out->dest);
225 out->increment_list(out);
236 tail = g_queue_peek_tail(priv->parent_q);
249 node = g_queue_pop_tail(priv->parent_q);
251 if (node->singular_noun != NULL && node->plural_noun != NULL) {
252 if (node->len == 1) {
271 fprintf(out->
dest,
"\n");
278 if (out->
dest == stdout) {
279 fprintf(out->
dest,
".");
282 fprintf(out->
dest,
"\n");
291 if (retval == NULL) {
296 retval->
request = argv == NULL ? NULL : g_strjoinv(
" ", argv);
298 retval->
init = text_init;
300 retval->
finish = text_finish;
301 retval->
reset = text_reset;
307 retval->
version = text_version;
308 retval->
info = text_info;
309 retval->
err = text_err;
318 retval->
spacer = text_spacer;
332 len = vfprintf(out->dest, format, args);
343 va_start(ap, format);
363 level = g_queue_get_length(priv->parent_q);
365 for (
int i = 0; i < level; i++) {
366 fprintf(out->dest,
" ");
370 fprintf(out->dest,
"* ");
384 va_start(ap, format);
393 struct termios settings;
394 tcflag_t orig_c_lflag = 0;
400 rc = tcgetattr(0, &settings);
402 orig_c_lflag = settings.c_lflag;
403 settings.c_lflag &= ~ECHO;
404 rc = tcsetattr(0, TCSANOW, &settings);
409 fprintf(stderr,
"%s: ", prompt);
417 rc = scanf(
"%ms", dest);
419 *dest = calloc(1, 1024);
420 rc = scanf(
"%1023s", *dest);
422 fprintf(stderr,
"\n");
430 if (orig_c_lflag != 0) {
431 settings.c_lflag = orig_c_lflag;
432 tcsetattr(0, TCSANOW, &settings);
void(* end_list)(pcmk__output_t *out)
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)
int(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
enum crm_exit_e crm_exit_t
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
#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(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void pcmk__str_update(char **str, const char *value)
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
pcmk__output_t * pcmk__mk_text_output(char **argv)
void pcmk__indented_printf(pcmk__output_t *out, const char *format,...)
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)
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)