summaryrefslogtreecommitdiffstats
path: root/lib/output.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/output.c')
-rw-r--r--lib/output.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/lib/output.c b/lib/output.c
index b398c2ad..62e1366d 100644
--- a/lib/output.c
+++ b/lib/output.c
@@ -42,7 +42,7 @@ static inline char *fmt_subcheck_perfdata(mp_subcheck check) {
42 42
43 while (subchecks != NULL) { 43 while (subchecks != NULL) {
44 if (added > 0) { 44 if (added > 0) {
45 added = asprintf(&result, "%s%s", result, fmt_subcheck_perfdata(subchecks->subcheck)); 45 added = asprintf(&result, "%s %s", result, fmt_subcheck_perfdata(subchecks->subcheck));
46 } else { 46 } else {
47 // TODO free previous result here? 47 // TODO free previous result here?
48 added = asprintf(&result, "%s", fmt_subcheck_perfdata(subchecks->subcheck)); 48 added = asprintf(&result, "%s", fmt_subcheck_perfdata(subchecks->subcheck));
@@ -368,7 +368,40 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch
368 mp_subcheck_list *subchecks = NULL; 368 mp_subcheck_list *subchecks = NULL;
369 369
370 switch (output_format) { 370 switch (output_format) {
371 case MP_FORMAT_MULTI_LINE: 371 case MP_FORMAT_MULTI_LINE: {
372 char *tmp_string = NULL;
373 if ((tmp_string = strchr(check.output, '\n')) != NULL) {
374 // This is a multiline string, put the correct indentation in before proceeding
375 char *intermediate_string = "";
376 bool have_residual_chars = false;
377
378 while (tmp_string != NULL) {
379 *tmp_string = '\0';
380 asprintf(&intermediate_string, "%s%s\n%s", intermediate_string, check.output,
381 generate_indentation_string(
382 indentation + 1)); // one more indentation to make it look better
383
384 if (*(tmp_string + 1) != '\0') {
385 check.output = tmp_string + 1;
386 have_residual_chars = true;
387 } else {
388 // Null after the \n, so this is the end
389 have_residual_chars = false;
390 break;
391 }
392
393 tmp_string = strchr(check.output, '\n');
394 }
395
396 // add the rest (if any)
397 if (have_residual_chars) {
398 char *tmp = check.output;
399 xasprintf(&check.output, "%s\n%s%s", intermediate_string,
400 generate_indentation_string(indentation + 1), tmp);
401 } else {
402 check.output = intermediate_string;
403 }
404 }
372 asprintf(&result, "%s\\_[%s] - %s", generate_indentation_string(indentation), 405 asprintf(&result, "%s\\_[%s] - %s", generate_indentation_string(indentation),
373 state_text(mp_compute_subcheck_state(check)), check.output); 406 state_text(mp_compute_subcheck_state(check)), check.output);
374 407
@@ -380,6 +413,7 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch
380 subchecks = subchecks->next; 413 subchecks = subchecks->next;
381 } 414 }
382 return result; 415 return result;
416 }
383 default: 417 default:
384 die(STATE_UNKNOWN, "Invalid format"); 418 die(STATE_UNKNOWN, "Invalid format");
385 } 419 }