20 typedef struct text_list_data_s {
26 typedef struct private_data_s {
32 free_list_data(gpointer
data) {
35 free(list_data->singular_noun);
36 free(list_data->plural_noun);
43 if (out == NULL || out->
priv == NULL) {
49 g_queue_free_full(priv->parent_q, free_list_data);
61 if (out->
priv != NULL) {
66 if (out->
priv == NULL) {
71 priv->parent_q = g_queue_new();
85 bool old_fancy =
false;
89 if (out->
dest != stdout) {
90 out->
dest = freopen(NULL,
"w", out->
dest);
97 old_fancy = priv->fancy;
103 priv->fancy = old_fancy;
108 const char *proc_stdout,
const char *proc_stderr) {
111 if (proc_stdout != NULL) {
112 fprintf(out->
dest,
"%s\n", proc_stdout);
115 if (proc_stderr != NULL) {
116 fprintf(out->
dest,
"%s\n", proc_stderr);
129 fprintf(out->
dest,
"Written by Andrew Beekhof and " 130 "the Pacemaker project contributors\n");
141 va_start(ap, format);
146 vfprintf(stderr, format, ap);
150 fprintf(stderr,
"\n");
160 if (out->is_quiet(out)) {
164 va_start(ap, format);
169 vfprintf(out->dest, format, ap);
173 fprintf(out->dest,
"\n");
192 text_begin_list(
pcmk__output_t *out, const
char *singular_noun, const
char *plural_noun,
193 const
char *format, ...) {
201 va_start(ap, format);
203 if (priv->fancy && (format != NULL)) {
205 fprintf(out->dest,
":\n");
215 g_queue_push_tail(priv->parent_q, new_list);
220 text_list_item(
pcmk__output_t *out, const
char *
id, const
char *format, ...) {
227 va_start(ap, format);
236 vfprintf(out->dest, format, ap);
244 fputc(
'\n', out->dest);
248 out->increment_list(out);
259 tail = g_queue_peek_tail(priv->parent_q);
272 node = g_queue_pop_tail(priv->parent_q);
274 if (node->singular_noun != NULL && node->plural_noun != NULL) {
275 if (node->len == 1) {
282 free_list_data(node);
294 fprintf(out->
dest,
"\n");
301 if (out->
dest == stdout) {
302 fprintf(out->
dest,
".");
305 fprintf(out->
dest,
"\n");
314 if (retval == NULL) {
321 retval->
init = text_init;
323 retval->
finish = text_finish;
324 retval->
reset = text_reset;
330 retval->
version = text_version;
331 retval->
info = text_info;
333 retval->
err = text_err;
342 retval->
spacer = text_spacer;
391 priv->fancy = enabled;
400 vfprintf(out->dest, format, args);
410 va_start(ap, format);
431 level = g_queue_get_length(priv->parent_q);
433 for (
int i = 0; i < level; i++) {
434 fprintf(out->dest,
" ");
438 fprintf(out->dest,
"* ");
452 va_start(ap, format);
461 struct termios settings;
462 tcflag_t orig_c_lflag = 0;
467 rc = tcgetattr(0, &settings);
469 orig_c_lflag = settings.c_lflag;
470 settings.c_lflag &= ~ECHO;
471 rc = tcsetattr(0, TCSANOW, &settings);
476 fprintf(stderr,
"%s: ", prompt);
484 rc = scanf(
"%ms", dest);
487 rc = scanf(
"%1023s", *dest);
489 fprintf(stderr,
"\n");
497 if (orig_c_lflag != 0) {
498 settings.c_lflag = orig_c_lflag;
499 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)
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)