1 /*
2 * Buffered Character Stream
3 *
4 * (c) 2018, Ronny Lorenz, ViennaRNA Package
5 */
6
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <unistd.h>
15 #include <stdint.h>
16
17 #include "ViennaRNA/utils/basic.h"
18 #include "ViennaRNA/datastructures/char_stream.h"
19 #include "ViennaRNA/color_output.inc"
20
21 #define CSTR_OVERHEAD 4096
22
23 struct vrna_cstr_s {
24 char *string;
25 size_t size;
26 FILE *output;
27 unsigned char istty;
28 };
29
30
31 /*
32 #################################
33 # PRIVATE FUNCTION DECLARATIONS #
34 #################################
35 */
36
37 /*
38 #################################
39 # BEGIN OF FUNCTION DEFINITIONS #
40 #################################
41 */
42 struct vrna_cstr_s *
vrna_cstr(size_t size,FILE * output)43 vrna_cstr(size_t size,
44 FILE *output)
45 {
46 struct vrna_cstr_s *buf = NULL;
47
48 if (size == 0)
49 size = CSTR_OVERHEAD;
50
51 buf = (struct vrna_cstr_s *)vrna_alloc(sizeof(struct vrna_cstr_s));
52 buf->string = (char *)vrna_alloc(sizeof(char) * size);
53 buf->size = size;
54 buf->output = (output) ? output : stdout;
55 buf->istty = isatty(fileno(buf->output));
56
57 if (buf->string == NULL) {
58 free(buf);
59 return NULL;
60 }
61
62 buf->string[0] = '\0'; /* just in case */
63
64 return buf;
65 }
66
67
68 void
vrna_cstr_free(struct vrna_cstr_s * buf)69 vrna_cstr_free(struct vrna_cstr_s *buf)
70 {
71 if (buf) {
72 vrna_cstr_fflush(buf);
73 free(buf->string);
74 free(buf);
75 }
76 }
77
78
79 void
vrna_cstr_close(struct vrna_cstr_s * buf)80 vrna_cstr_close(struct vrna_cstr_s *buf)
81 {
82 if (buf) {
83 vrna_cstr_fflush(buf);
84
85 free(buf->string);
86
87 if ((buf->output != stdout) && (buf->output != stderr))
88 fclose(buf->output);
89
90 free(buf);
91 }
92 }
93
94
95 const char *
vrna_cstr_string(struct vrna_cstr_s * buf)96 vrna_cstr_string(struct vrna_cstr_s *buf)
97 {
98 if (buf)
99 return (const char *)buf->string;
100
101 return NULL;
102 }
103
104
105 void
vrna_cstr_fflush(struct vrna_cstr_s * buf)106 vrna_cstr_fflush(struct vrna_cstr_s *buf)
107 {
108 if (buf) {
109 if (buf->output) {
110 fprintf(buf->output, "%s", buf->string);
111 (void)fflush(buf->output);
112 }
113
114 buf->size = CSTR_OVERHEAD;
115 buf->string = (char *)vrna_realloc(buf->string, sizeof(char) * buf->size);
116 buf->string[0] = '\0';
117 }
118 }
119
120
121 int
vrna_cstr_printf(struct vrna_cstr_s * buf,const char * format,...)122 vrna_cstr_printf(struct vrna_cstr_s *buf,
123 const char *format,
124 ...)
125 {
126 int r;
127 va_list argp;
128
129 if ((!buf) || (!format))
130 return -1;
131
132 va_start(argp, format);
133 r = vrna_cstr_vprintf(buf, format, argp);
134 va_end(argp); /* Each va_start() or va_copy() needs a va_end() */
135
136 return r;
137 }
138
139
140 int
vrna_cstr_vprintf(struct vrna_cstr_s * buf,const char * format,va_list args)141 vrna_cstr_vprintf(struct vrna_cstr_s *buf,
142 const char *format,
143 va_list args)
144 {
145 char *ptr;
146 int r, l1, l2;
147 size_t size_avail, size_old, size_new;
148
149 if ((!buf) && (!format))
150 return -1;
151
152 va_list copy;
153 va_copy(copy, args);
154
155 r = -1;
156 ptr = buf->string;
157 size_avail = buf->size;
158 size_old = (ptr) ? strlen(ptr) : 0;
159
160 /* retrieve the number of characters that the string requires */
161 #ifdef _WIN32
162 /*
163 * vsnprintf() in Windows is not ANSI compliant, although it's
164 * "...included for compliance to the ANSI standard"
165 * Thus, we use _vscprintf() that explicitly counts characters
166 */
167 size_new = _vscprintf(format, args);
168 #else
169 size_new = vsnprintf(NULL, 0, format, args);
170 #endif
171
172 /* determine longer and shorter part of new string for size_t overflow protection */
173 if (size_old > size_new) {
174 l1 = size_old;
175 l2 = size_new;
176 } else {
177 l1 = size_new;
178 l2 = size_old;
179 }
180
181 if ((size_new > 0) && (l1 < SIZE_MAX) && ((SIZE_MAX - l1) > l2)) {
182 /* increase string memory if necessary */
183 if ((size_old + size_new + 1) > size_avail) {
184 size_avail = size_old + size_new + 1;
185 if (size_avail < SIZE_MAX - CSTR_OVERHEAD)
186 size_avail += CSTR_OVERHEAD;
187
188 ptr = (char *)vrna_realloc(ptr, sizeof(char) * (size_avail));
189 }
190
191 if (ptr == NULL) {
192 r = -1;
193 } else if ((r = vsnprintf(ptr + size_old, size_new + 1, format, copy)) < 0) {
194 free(ptr);
195 } else {
196 buf->string = ptr;
197 buf->size = size_avail;
198 r = size_old + size_new;
199 }
200 } else if (size_new == 0) {
201 /* we do not treat empty format string as error */
202 r = (int)size_old;
203 }
204
205 va_end(copy); /* Each va_start() or va_copy() needs a va_end() */
206
207 return r;
208 }
209
210
211 PUBLIC void
vrna_cstr_message_info(struct vrna_cstr_s * buf,const char * format,...)212 vrna_cstr_message_info(struct vrna_cstr_s *buf,
213 const char *format,
214 ...)
215 {
216 va_list args;
217
218 if ((!buf) || (!format))
219 return;
220
221 va_start(args, format);
222 vrna_cstr_message_vinfo(buf, format, args);
223 va_end(args); /* Each va_start() or va_copy() needs a va_end() */
224 }
225
226
227 PUBLIC void
vrna_cstr_message_vinfo(struct vrna_cstr_s * buf,const char * format,va_list args)228 vrna_cstr_message_vinfo(struct vrna_cstr_s *buf,
229 const char *format,
230 va_list args)
231 {
232 if ((!buf) || (!format))
233 return;
234
235 #ifndef VRNA_WITHOUT_TTY_COLORS
236 if (buf->istty) {
237 vrna_cstr_printf(buf, ANSI_COLOR_BLUE_B);
238 vrna_cstr_vprintf(buf, format, args);
239 vrna_cstr_printf(buf, ANSI_COLOR_RESET "\n");
240 } else {
241 #endif
242 vrna_cstr_vprintf(buf, format, args);
243 vrna_cstr_printf(buf, "\n");
244 #ifndef VRNA_WITHOUT_TTY_COLORS
245 }
246
247
248 #endif
249 }
250
251 PUBLIC void
vrna_cstr_message_warning(struct vrna_cstr_s * buf,const char * format,...)252 vrna_cstr_message_warning(struct vrna_cstr_s *buf,
253 const char *format,
254 ...)
255 {
256 va_list args;
257
258 if ((!buf) || (!format))
259 return;
260
261 va_start(args, format);
262 vrna_cstr_message_vwarning(buf, format, args);
263 va_end(args); /* Each va_start() or va_copy() needs a va_end() */
264 }
265
266
267 PUBLIC void
vrna_cstr_message_vwarning(struct vrna_cstr_s * buf,const char * format,va_list args)268 vrna_cstr_message_vwarning(struct vrna_cstr_s *buf,
269 const char *format,
270 va_list args)
271 {
272 if ((!buf) || (!format))
273 return;
274
275 #ifndef VRNA_WITHOUT_TTY_COLORS
276 if (buf->istty) {
277 vrna_cstr_printf(buf, ANSI_COLOR_MAGENTA_B "WARNING: " ANSI_COLOR_RESET ANSI_COLOR_BRIGHT);
278 vrna_cstr_vprintf(buf, format, args);
279 vrna_cstr_printf(buf, ANSI_COLOR_RESET "\n");
280 } else {
281 #endif
282 vrna_cstr_printf(buf, "WARNING: ");
283 vrna_cstr_vprintf(buf, format, args);
284 vrna_cstr_printf(buf, "\n");
285 #ifndef VRNA_WITHOUT_TTY_COLORS
286 }
287
288
289 #endif
290 }
291
292 PUBLIC void
vrna_cstr_print_fasta_header(struct vrna_cstr_s * buf,const char * head)293 vrna_cstr_print_fasta_header(struct vrna_cstr_s *buf,
294 const char *head)
295 {
296 if (head) {
297 #ifndef VRNA_WITHOUT_TTY_COLORS
298 if (buf->istty)
299 vrna_cstr_printf(buf, ANSI_COLOR_YELLOW ">%s" ANSI_COLOR_RESET "\n", head);
300 else
301 #endif
302 vrna_cstr_printf(buf, ">%s\n", head);
303 }
304 }
305
306
307 PUBLIC void
vrna_cstr_printf_structure(struct vrna_cstr_s * buf,const char * structure,const char * format,...)308 vrna_cstr_printf_structure(struct vrna_cstr_s *buf,
309 const char *structure,
310 const char *format,
311 ...)
312
313 {
314 va_list args;
315
316 if (!buf)
317 return;
318
319 va_start(args, format);
320 vrna_cstr_vprintf_structure(buf, structure, format, args);
321 va_end(args); /* Each va_start() or va_copy() needs a va_end() */
322 }
323
324
325 PUBLIC void
vrna_cstr_vprintf_structure(struct vrna_cstr_s * buf,const char * structure,const char * format,va_list args)326 vrna_cstr_vprintf_structure(struct vrna_cstr_s *buf,
327 const char *structure,
328 const char *format,
329 va_list args)
330 {
331 if (!buf)
332 return;
333
334 if (structure)
335 vrna_cstr_printf(buf, structure);
336
337 if ((format) && (*format != '\0')) {
338 #ifndef VRNA_WITHOUT_TTY_COLORS
339 if (buf->istty) {
340 vrna_cstr_printf(buf, ANSI_COLOR_GREEN);
341 vrna_cstr_vprintf(buf, format, args);
342 vrna_cstr_printf(buf, ANSI_COLOR_RESET);
343 } else {
344 #endif
345 vrna_cstr_vprintf(buf, format, args);
346 #ifndef VRNA_WITHOUT_TTY_COLORS
347 }
348
349 #endif
350 }
351
352 if ((structure) || ((format) && (*format != '\0')))
353 vrna_cstr_printf(buf, "\n");
354 }
355
356
357 PUBLIC void
vrna_cstr_printf_comment(struct vrna_cstr_s * buf,const char * format,...)358 vrna_cstr_printf_comment(struct vrna_cstr_s *buf,
359 const char *format,
360 ...)
361
362 {
363 va_list args;
364
365 if (!buf)
366 return;
367
368 va_start(args, format);
369 vrna_cstr_vprintf_comment(buf, format, args);
370 va_end(args); /* Each va_start() or va_copy() needs a va_end() */
371 }
372
373
374 PUBLIC void
vrna_cstr_vprintf_comment(struct vrna_cstr_s * buf,const char * format,va_list args)375 vrna_cstr_vprintf_comment(struct vrna_cstr_s *buf,
376 const char *format,
377 va_list args)
378 {
379 if (!buf)
380 return;
381
382 if ((format) && (*format != '\0')) {
383 #ifndef VRNA_WITHOUT_TTY_COLORS
384 if (buf->istty) {
385 vrna_cstr_printf(buf, ANSI_COLOR_CYAN);
386 vrna_cstr_vprintf(buf, format, args);
387 vrna_cstr_printf(buf, ANSI_COLOR_RESET);
388 } else {
389 #endif
390 vrna_cstr_vprintf(buf, format, args);
391 #ifndef VRNA_WITHOUT_TTY_COLORS
392 }
393
394 #endif
395 }
396
397 if ((format) && (*format != '\0'))
398 vrna_cstr_printf(buf, "\n");
399 }
400
401
402 PUBLIC void
vrna_cstr_printf_thead(struct vrna_cstr_s * buf,const char * format,...)403 vrna_cstr_printf_thead(struct vrna_cstr_s *buf,
404 const char *format,
405 ...)
406
407 {
408 va_list args;
409
410 if (!buf)
411 return;
412
413 va_start(args, format);
414 vrna_cstr_vprintf_thead(buf, format, args);
415 va_end(args); /* Each va_start() or va_copy() needs a va_end() */
416 }
417
418
419 PUBLIC void
vrna_cstr_vprintf_thead(struct vrna_cstr_s * buf,const char * format,va_list args)420 vrna_cstr_vprintf_thead(struct vrna_cstr_s *buf,
421 const char *format,
422 va_list args)
423 {
424 if (!buf)
425 return;
426
427 if ((format) && (*format != '\0')) {
428 #ifndef VRNA_WITHOUT_TTY_COLORS
429 if (buf->istty) {
430 vrna_cstr_printf(buf, ANSI_COLOR_UNDERLINE ANSI_COLOR_BRIGHT);
431 vrna_cstr_vprintf(buf, format, args);
432 vrna_cstr_printf(buf, ANSI_COLOR_RESET);
433 } else {
434 #endif
435 vrna_cstr_vprintf(buf, format, args);
436 #ifndef VRNA_WITHOUT_TTY_COLORS
437 }
438
439 #endif
440 }
441
442 if ((format) && (*format != '\0'))
443 vrna_cstr_printf(buf, "\n");
444 }
445
446
447 PUBLIC void
vrna_cstr_printf_tbody(struct vrna_cstr_s * buf,const char * format,...)448 vrna_cstr_printf_tbody(struct vrna_cstr_s *buf,
449 const char *format,
450 ...)
451
452 {
453 va_list args;
454
455 if (!buf)
456 return;
457
458 va_start(args, format);
459 vrna_cstr_vprintf_tbody(buf, format, args);
460 va_end(args); /* Each va_start() or va_copy() needs a va_end() */
461 }
462
463
464 PUBLIC void
vrna_cstr_vprintf_tbody(struct vrna_cstr_s * buf,const char * format,va_list args)465 vrna_cstr_vprintf_tbody(struct vrna_cstr_s *buf,
466 const char *format,
467 va_list args)
468 {
469 if (!buf)
470 return;
471
472 if ((format) && (*format != '\0')) {
473 #ifndef VRNA_WITHOUT_TTY_COLORS
474 if (buf->istty) {
475 vrna_cstr_printf(buf, ANSI_COLOR_GREEN);
476 vrna_cstr_vprintf(buf, format, args);
477 vrna_cstr_printf(buf, ANSI_COLOR_RESET);
478 } else {
479 #endif
480 vrna_cstr_vprintf(buf, format, args);
481 #ifndef VRNA_WITHOUT_TTY_COLORS
482 }
483
484 #endif
485 }
486
487 if ((format) && (*format != '\0'))
488 vrna_cstr_printf(buf, "\n");
489 }
490
491
492 PUBLIC void
vrna_cstr_print_eval_sd_corr(struct vrna_cstr_s * buf)493 vrna_cstr_print_eval_sd_corr(struct vrna_cstr_s *buf)
494 {
495 if (!buf)
496 return;
497
498 #ifndef VRNA_WITHOUT_TTY_COLORS
499 if (buf->istty) {
500 vrna_cstr_printf(buf,
501 ANSI_COLOR_BRIGHT "Correcting for presence of structured domains" ANSI_COLOR_RESET "\n");
502 } else {
503 #endif
504 vrna_cstr_printf(buf, "Correcting for presence of structured domains\n");
505 #ifndef VRNA_WITHOUT_TTY_COLORS
506 }
507
508
509 #endif
510 }
511
512 PUBLIC void
vrna_cstr_print_eval_ext_loop(struct vrna_cstr_s * buf,int energy)513 vrna_cstr_print_eval_ext_loop(struct vrna_cstr_s *buf,
514 int energy)
515 {
516 if (!buf)
517 return;
518
519 #ifndef VRNA_WITHOUT_TTY_COLORS
520 if (buf->istty) {
521 vrna_cstr_printf(buf,
522 ANSI_COLOR_CYAN "External loop" ANSI_COLOR_RESET
523 " : "
524 ANSI_COLOR_GREEN "%5d" ANSI_COLOR_RESET "\n",
525 energy);
526 } else {
527 #endif
528 vrna_cstr_printf(buf,
529 "External loop"
530 " : "
531 "%5d\n",
532 energy);
533 #ifndef VRNA_WITHOUT_TTY_COLORS
534 }
535
536
537 #endif
538 }
539
540
541 PUBLIC void
vrna_cstr_print_eval_hp_loop(struct vrna_cstr_s * buf,int i,int j,char si,char sj,int energy)542 vrna_cstr_print_eval_hp_loop(struct vrna_cstr_s *buf,
543 int i,
544 int j,
545 char si,
546 char sj,
547 int energy)
548 {
549 if (!buf)
550 return;
551
552 #ifndef VRNA_WITHOUT_TTY_COLORS
553 if (buf->istty) {
554 vrna_cstr_printf(buf,
555 ANSI_COLOR_CYAN "Hairpin loop" ANSI_COLOR_RESET
556 " (%3d,%3d) "
557 ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
558 " : "
559 ANSI_COLOR_GREEN "%5d" ANSI_COLOR_RESET "\n",
560 i, j,
561 si, sj,
562 energy);
563 } else {
564 #endif
565 vrna_cstr_printf(buf,
566 "Hairpin loop"
567 " (%3d,%3d) %c%c : "
568 "%5d\n",
569 i, j,
570 si, sj,
571 energy);
572 #ifndef VRNA_WITHOUT_TTY_COLORS
573 }
574
575
576 #endif
577 }
578
579
580 PUBLIC void
vrna_cstr_print_eval_hp_loop_revert(struct vrna_cstr_s * buf,int i,int j,char si,char sj,int energy)581 vrna_cstr_print_eval_hp_loop_revert(struct vrna_cstr_s *buf,
582 int i,
583 int j,
584 char si,
585 char sj,
586 int energy)
587 {
588 if (!buf)
589 return;
590
591 #ifndef VRNA_WITHOUT_TTY_COLORS
592 if (buf->istty) {
593 vrna_cstr_printf(buf,
594 ANSI_COLOR_MAGENTA "Hairpin loop" ANSI_COLOR_RESET
595 " (%3d,%3d) "
596 ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
597 " : "
598 ANSI_COLOR_RED "%5d" ANSI_COLOR_RESET "\n",
599 i, j,
600 si, sj,
601 -energy);
602 } else {
603 #endif
604 vrna_cstr_printf(buf,
605 "Hairpin loop"
606 " (%3d,%3d) %c%c : "
607 "%5d\n",
608 i, j,
609 si, sj,
610 -energy);
611 #ifndef VRNA_WITHOUT_TTY_COLORS
612 }
613
614
615 #endif
616 }
617
618
619 PUBLIC void
vrna_cstr_print_eval_int_loop(struct vrna_cstr_s * buf,int i,int j,char si,char sj,int k,int l,char sk,char sl,int energy)620 vrna_cstr_print_eval_int_loop(struct vrna_cstr_s *buf,
621 int i,
622 int j,
623 char si,
624 char sj,
625 int k,
626 int l,
627 char sk,
628 char sl,
629 int energy)
630 {
631 if (!buf)
632 return;
633
634 #ifndef VRNA_WITHOUT_TTY_COLORS
635 if (buf->istty) {
636 vrna_cstr_printf(buf,
637 ANSI_COLOR_CYAN "Interior loop" ANSI_COLOR_RESET
638 " (%3d,%3d) "
639 ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
640 "; (%3d,%3d) "
641 ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
642 ": "
643 ANSI_COLOR_GREEN "%5d" ANSI_COLOR_RESET "\n",
644 i, j,
645 si, sj,
646 k, l,
647 sk, sl,
648 energy);
649 } else {
650 #endif
651 vrna_cstr_printf(buf,
652 "Interior loop"
653 " (%3d,%3d) "
654 "%c%c"
655 "; (%3d,%3d) "
656 "%c%c"
657 ": "
658 "%5d\n",
659 i, j,
660 si, sj,
661 k, l,
662 sk, sl,
663 energy);
664 #ifndef VRNA_WITHOUT_TTY_COLORS
665 }
666
667
668 #endif
669 }
670
671
672 PUBLIC void
vrna_cstr_print_eval_int_loop_revert(struct vrna_cstr_s * buf,int i,int j,char si,char sj,int k,int l,char sk,char sl,int energy)673 vrna_cstr_print_eval_int_loop_revert(struct vrna_cstr_s *buf,
674 int i,
675 int j,
676 char si,
677 char sj,
678 int k,
679 int l,
680 char sk,
681 char sl,
682 int energy)
683 {
684 if (!buf)
685 return;
686
687 #ifndef VRNA_WITHOUT_TTY_COLORS
688 if (buf->istty) {
689 vrna_cstr_printf(buf,
690 ANSI_COLOR_MAGENTA "Interior loop" ANSI_COLOR_RESET
691 " (%3d,%3d) "
692 ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
693 "; (%3d,%3d) "
694 ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
695 ": "
696 ANSI_COLOR_RED "%5d" ANSI_COLOR_RESET "\n",
697 i, j,
698 si, sj,
699 k, l,
700 sk, sl,
701 -energy);
702 } else {
703 #endif
704 vrna_cstr_printf(buf,
705 "Interior loop"
706 " (%3d,%3d) "
707 "%c%c"
708 "; (%3d,%3d) "
709 "%c%c"
710 ": "
711 "%5d\n",
712 i, j,
713 si, sj,
714 k, l,
715 sk, sl,
716 -energy);
717 #ifndef VRNA_WITHOUT_TTY_COLORS
718 }
719
720
721 #endif
722 }
723
724
725 PUBLIC void
vrna_cstr_print_eval_mb_loop(struct vrna_cstr_s * buf,int i,int j,char si,char sj,int energy)726 vrna_cstr_print_eval_mb_loop(struct vrna_cstr_s *buf,
727 int i,
728 int j,
729 char si,
730 char sj,
731 int energy)
732 {
733 if (!buf)
734 return;
735
736 #ifndef VRNA_WITHOUT_TTY_COLORS
737 if (buf->istty) {
738 vrna_cstr_printf(buf,
739 ANSI_COLOR_CYAN "Multi loop" ANSI_COLOR_RESET
740 " (%3d,%3d) "
741 ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
742 " : "
743 ANSI_COLOR_GREEN "%5d" ANSI_COLOR_RESET "\n",
744 i, j,
745 si, sj,
746 energy);
747 } else {
748 #endif
749 vrna_cstr_printf(buf,
750 "Multi loop"
751 " (%3d,%3d) %c%c : "
752 "%5d\n",
753 i, j,
754 si, sj,
755 energy);
756 #ifndef VRNA_WITHOUT_TTY_COLORS
757 }
758
759
760 #endif
761 }
762
763
764 PUBLIC void
vrna_cstr_print_eval_mb_loop_revert(struct vrna_cstr_s * buf,int i,int j,char si,char sj,int energy)765 vrna_cstr_print_eval_mb_loop_revert(struct vrna_cstr_s *buf,
766 int i,
767 int j,
768 char si,
769 char sj,
770 int energy)
771 {
772 if (!buf)
773 return;
774
775 #ifndef VRNA_WITHOUT_TTY_COLORS
776 if (buf->istty) {
777 vrna_cstr_printf(buf,
778 ANSI_COLOR_MAGENTA "Multi loop" ANSI_COLOR_RESET
779 " (%3d,%3d) "
780 ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
781 " : "
782 ANSI_COLOR_RED "%5d" ANSI_COLOR_RESET "\n",
783 i, j,
784 si, sj,
785 -energy);
786 } else {
787 #endif
788 vrna_cstr_printf(buf,
789 "Multi loop"
790 " (%3d,%3d) %c%c : "
791 "%5d\n",
792 i, j,
793 si, sj,
794 -energy);
795 #ifndef VRNA_WITHOUT_TTY_COLORS
796 }
797
798
799 #endif
800 }
801
802
803 PUBLIC void
vrna_cstr_print_eval_gquad(struct vrna_cstr_s * buf,int i,int L,int l[3],int energy)804 vrna_cstr_print_eval_gquad(struct vrna_cstr_s *buf,
805 int i,
806 int L,
807 int l[3],
808 int energy)
809 {
810 if (!buf)
811 return;
812
813 #ifndef VRNA_WITHOUT_TTY_COLORS
814 if (buf->istty) {
815 vrna_cstr_printf(buf,
816 ANSI_COLOR_CYAN "G-Quadruplex " ANSI_COLOR_RESET
817 " (%3d,%3d) "
818 ANSI_COLOR_BRIGHT "L%d " ANSI_COLOR_RESET
819 "(%2d,%2d,%2d) : "
820 ANSI_COLOR_GREEN "%5d" ANSI_COLOR_RESET "\n",
821 i, i + 4 * L + l[0] + l[1] + l[2] - 1,
822 L, l[0], l[1], l[2],
823 energy);
824 } else {
825 #endif
826 vrna_cstr_printf(buf,
827 "G-Quadruplex "
828 " (%3d,%3d) "
829 "L%d "
830 "(%2d,%2d,%2d) : "
831 "%5d\n",
832 i, i + 4 * L + l[0] + l[1] + l[2] - 1,
833 L, l[0], l[1], l[2],
834 energy);
835 #ifndef VRNA_WITHOUT_TTY_COLORS
836 }
837
838
839 #endif
840 }
841