print.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @file print.c
  3. */
  4. /*
  5. * This program is free software: you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation, either vers* ion 3 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see
  17. * <http://www.gnu.org/licenses/>.
  18. */
  19. #include <stdlib.h>
  20. #include "doc_stream.h"
  21. #include "print_ctxt.h"
  22. #include "print.h"
  23. static const char *start_mark = ">>>>>>> ";
  24. static const char *middle_mark = "======= ";
  25. static const char *end_mark = "<<<<<<< ";
  26. /*
  27. * Print the conflict markers
  28. */
  29. static void
  30. print_conflict_markers (conflict_state *current_state, conflict_state state,
  31. char* msg, doc_stream *out);
  32. void
  33. enter_structural_conflict (print_ctxt *ctxt, conflict_state state,
  34. char* msg, doc_stream *out)
  35. {
  36. /* wrap up the conflicts, print a message on the last conflict
  37. * marker, if there is one */
  38. if ( ctxt->structure_conflict != state )
  39. {
  40. enter_movement_conflict (ctxt, no_conflict, NULL, out);
  41. }
  42. else
  43. return;
  44. if (state != no_conflict)
  45. ctxt->conflict_occurred = true;
  46. print_conflict_markers (&ctxt->structure_conflict, state, msg, out);
  47. return;
  48. }
  49. void
  50. enter_movement_conflict (print_ctxt *ctxt, conflict_state state,
  51. char* msg, doc_stream *out)
  52. {
  53. /* wrap up the conflicts, print a message on the last conflict
  54. * marker, if there is one */
  55. if ( ctxt->movement_conflict != state )
  56. {
  57. enter_content_conflict (ctxt, no_conflict, NULL, out);
  58. }
  59. else
  60. return;
  61. if (state != no_conflict)
  62. ctxt->conflict_occurred = true;
  63. print_conflict_markers (&ctxt->movement_conflict, state, msg, out);
  64. return;
  65. }
  66. void
  67. enter_content_conflict (print_ctxt *ctxt, conflict_state state,
  68. char* msg, doc_stream *out)
  69. {
  70. if (ctxt->content_conflict == state)
  71. return;
  72. if (state != no_conflict)
  73. ctxt->conflict_occurred = true;
  74. print_conflict_markers (&ctxt->content_conflict, state, msg, out);
  75. return;
  76. }
  77. static void
  78. print_conflict_markers (conflict_state *current_state, conflict_state state,
  79. char* msg, doc_stream *out)
  80. {
  81. while (*current_state != state )
  82. {
  83. /*conflict wrap up */
  84. switch (*current_state)
  85. {
  86. case no_conflict:
  87. doc_stream_puts (start_mark, out);
  88. break;
  89. case local_side:
  90. doc_stream_puts (middle_mark, out);
  91. break;
  92. case remote_side:
  93. doc_stream_puts (end_mark, out);
  94. break;
  95. }
  96. (*current_state) ++;
  97. if (*current_state == 3)
  98. *current_state = 0;
  99. if (*current_state != state)
  100. doc_stream_putc ('\n', out);
  101. }
  102. if (msg != NULL)
  103. {
  104. doc_stream_puts (msg, out);
  105. }
  106. else
  107. {
  108. doc_stream_putc ('\n', out);
  109. }
  110. return;
  111. }