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\n");
123 va_start(ap, format);
128 len = vfprintf(stderr, format, ap);
133 fprintf(stderr,
"\n");
144 if (out->is_quiet(out)) {
148 va_start(ap, format);
153 len = vfprintf(out->dest, format, ap);
158 fprintf(out->dest,
"\n");
170 text_begin_list(
pcmk__output_t *out, const
char *singular_noun, const
char *plural_noun,
171 const
char *format, ...) {
179 va_start(ap, format);
181 if (fancy && format) {
183 fprintf(out->dest,
":\n");
190 new_list->singular_noun = singular_noun == NULL ? NULL : strdup(singular_noun);
191 new_list->plural_noun = plural_noun == NULL ? NULL : strdup(plural_noun);
193 g_queue_push_tail(priv->parent_q, new_list);
198 text_list_item(
pcmk__output_t *out, const
char *
id, const
char *format, ...) {
203 va_start(ap, format);
212 vfprintf(out->dest, format, ap);
220 fputc(
'\n', out->dest);
224 out->increment_list(out);
235 tail = g_queue_peek_tail(priv->parent_q);
248 node = g_queue_pop_tail(priv->parent_q);
250 if (node->singular_noun != NULL && node->plural_noun != NULL) {
251 if (node->len == 1) {
270 fprintf(out->
dest,
"\n");
277 if (out->
dest == stdout) {
278 fprintf(out->
dest,
".");
281 fprintf(out->
dest,
"\n");
290 if (retval == NULL) {
295 retval->
request = argv == NULL ? NULL : g_strjoinv(
" ", argv);
297 retval->
init = text_init;
299 retval->
finish = text_finish;
300 retval->
reset = text_reset;
306 retval->
version = text_version;
307 retval->
info = text_info;
308 retval->
err = text_err;
317 retval->
spacer = text_spacer;
331 len = vfprintf(out->dest, format, args);
342 va_start(ap, format);
362 level = g_queue_get_length(priv->parent_q);
364 for (
int i = 0; i < level; i++) {
365 fprintf(out->dest,
" ");
369 fprintf(out->dest,
"* ");
383 va_start(ap, format);
392 struct termios settings;
393 tcflag_t orig_c_lflag = 0;
399 rc = tcgetattr(0, &settings);
401 orig_c_lflag = settings.c_lflag;
402 settings.c_lflag &= ~ECHO;
403 rc = tcsetattr(0, TCSANOW, &settings);
408 fprintf(stderr,
"%s: ", prompt);
416 rc = scanf(
"%ms", dest);
418 *dest = calloc(1, 1024);
419 rc = scanf(
"%1023s", *dest);
421 fprintf(stderr,
"\n");
429 if (orig_c_lflag != 0) {
430 settings.c_lflag = orig_c_lflag;
431 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(* 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)