18 static gboolean fancy = FALSE;
21 {
"text-fancy", 0, 0, G_OPTION_ARG_NONE, &fancy,
22 "Use more highly formatted output (requires --output-as=text)",
28 typedef struct text_list_data_s {
34 typedef struct private_data_s {
42 if (out == NULL || out->
priv == NULL) {
48 g_queue_free(priv->parent_q);
60 if (out->
priv != NULL) {
64 if (out->
priv == NULL) {
71 priv->parent_q = g_queue_new();
85 if (out->
dest != stdout) {
86 out->
dest = freopen(NULL,
"w", out->
dest);
97 const char *proc_stdout,
const char *proc_stderr) {
100 if (proc_stdout != NULL) {
101 fprintf(out->
dest,
"%s\n", proc_stdout);
104 if (proc_stderr != NULL) {
105 fprintf(out->
dest,
"%s\n", proc_stderr);
117 fprintf(out->
dest,
"Written by Andrew Beekhof and " 118 "the Pacemaker project contributors\n");
130 va_start(ap, format);
135 len = vfprintf(stderr, format, ap);
140 fprintf(stderr,
"\n");
151 if (out->is_quiet(out)) {
155 va_start(ap, format);
160 len = vfprintf(out->dest, format, ap);
165 fprintf(out->dest,
"\n");
184 text_begin_list(
pcmk__output_t *out, const
char *singular_noun, const
char *plural_noun,
185 const
char *format, ...) {
193 va_start(ap, format);
195 if (fancy && format) {
197 fprintf(out->dest,
":\n");
207 g_queue_push_tail(priv->parent_q, new_list);
212 text_list_item(
pcmk__output_t *out, const
char *
id, const
char *format, ...) {
217 va_start(ap, format);
226 vfprintf(out->dest, format, ap);
234 fputc(
'\n', out->dest);
238 out->increment_list(out);
249 tail = g_queue_peek_tail(priv->parent_q);
262 node = g_queue_pop_tail(priv->parent_q);
264 if (node->singular_noun != NULL && node->plural_noun != NULL) {
265 if (node->len == 1) {
284 fprintf(out->
dest,
"\n");
291 if (out->
dest == stdout) {
292 fprintf(out->
dest,
".");
295 fprintf(out->
dest,
"\n");
304 if (retval == NULL) {
311 retval->
init = text_init;
313 retval->
finish = text_finish;
314 retval->
reset = text_reset;
320 retval->
version = text_version;
321 retval->
info = text_info;
323 retval->
err = text_err;
332 retval->
spacer = text_spacer;
347 len = vfprintf(out->dest, format, args);
358 va_start(ap, format);
375 level = g_queue_get_length(priv->parent_q);
377 for (
int i = 0; i < level; i++) {
378 fprintf(out->dest,
" ");
382 fprintf(out->dest,
"* ");
396 va_start(ap, format);
405 struct termios settings;
406 tcflag_t orig_c_lflag = 0;
412 rc = tcgetattr(0, &settings);
414 orig_c_lflag = settings.c_lflag;
415 settings.c_lflag &= ~ECHO;
416 rc = tcsetattr(0, TCSANOW, &settings);
421 fprintf(stderr,
"%s: ", prompt);
429 rc = scanf(
"%ms", dest);
431 *dest = calloc(1, 1024);
432 rc = scanf(
"%1023s", *dest);
434 fprintf(stderr,
"\n");
442 if (orig_c_lflag != 0) {
443 settings.c_lflag = orig_c_lflag;
444 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
#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 pcmk__str_update(char **str, const char *value)
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,...)
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)
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)