print.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include <stdlib.h>
  2. #include "doc_stream.h"
  3. #include "print_ctxt.h"
  4. #include "print.h"
  5. static const char *start_mark = ">>>>>>> ";
  6. static const char *middle_mark = "======= ";
  7. static const char *end_mark = "<<<<<<< ";
  8. void
  9. enter_structural_conflict (print_ctxt *ctxt, conflict_state state,
  10. char* msg, doc_stream *out)
  11. {
  12. /* wrap up the conflicts, print a message on the last conflict
  13. * marker, if there is one */
  14. if ( ctxt->structure_conflict != state )
  15. {
  16. enter_content_conflict (ctxt, no_conflict, NULL, out);
  17. }
  18. else
  19. return;
  20. if (state != no_conflict)
  21. ctxt->conflict_occurred = true;
  22. while (ctxt->structure_conflict != state )
  23. {
  24. /*conflict wrap up */
  25. switch (ctxt->structure_conflict)
  26. {
  27. case no_conflict:
  28. doc_stream_puts (start_mark, out);
  29. break;
  30. case local_side:
  31. doc_stream_puts (middle_mark, out);
  32. break;
  33. case remote_side:
  34. doc_stream_puts (end_mark, out);
  35. break;
  36. }
  37. ctxt->structure_conflict ++;
  38. if (ctxt->structure_conflict == 3)
  39. ctxt->structure_conflict = 0;
  40. if (ctxt->structure_conflict != state)
  41. doc_stream_putc ('\n', out);
  42. }
  43. if (msg != NULL)
  44. {
  45. doc_stream_puts (msg, out);
  46. }
  47. else
  48. {
  49. doc_stream_putc ('\n', out);
  50. }
  51. return;
  52. }
  53. void
  54. enter_content_conflict (print_ctxt *ctxt, conflict_state state,
  55. char* msg, doc_stream *out)
  56. {
  57. if (ctxt->content_conflict == state)
  58. return;
  59. if (state != no_conflict)
  60. ctxt->conflict_occurred = true;
  61. while ( ctxt->content_conflict != state )
  62. {
  63. /*conflict wrap up */
  64. switch (ctxt->content_conflict)
  65. {
  66. case no_conflict:
  67. doc_stream_puts (start_mark, out);
  68. break;
  69. case local_side:
  70. doc_stream_puts (middle_mark, out);
  71. break;
  72. case remote_side:
  73. doc_stream_puts (end_mark, out);
  74. break;
  75. }
  76. ctxt->content_conflict ++;
  77. if (ctxt->content_conflict == 3)
  78. ctxt->content_conflict = 0;
  79. if (ctxt->content_conflict != state)
  80. doc_stream_putc ('\n', out);
  81. }
  82. if (msg != NULL)
  83. {
  84. doc_stream_puts (msg, out);
  85. }
  86. else
  87. {
  88. doc_stream_putc ('\n', out);
  89. }
  90. return;
  91. }