… | |
… | |
731 | */ |
731 | */ |
732 | static void |
732 | static void |
733 | split_line (int idx, const char *str, unsigned long color) |
733 | split_line (int idx, const char *str, unsigned long color) |
734 | { |
734 | { |
735 | int l = strlen (str); |
735 | int l = strlen (str); |
|
|
736 | int last_wrapped = 0; |
736 | const char *p = str; |
737 | const char *p = str; |
|
|
738 | static int continuation_width = -1; |
|
|
739 | static int continuation_length; |
|
|
740 | |
|
|
741 | /* only calculate the continuation's width once */ |
|
|
742 | if (continuation_width == -1) |
|
|
743 | { |
|
|
744 | continuation_length = strlen(continuation); |
|
|
745 | continuation_width = XmbTextEscapement (fontset, continuation, continuation_length); |
|
|
746 | printf("continuation width is %d and length is %d\n", continuation_width, continuation_length); |
|
|
747 | } |
737 | |
748 | |
738 | do |
749 | do |
739 | { |
750 | { |
740 | const char *beg = p; |
751 | const char *beg = p; |
|
|
752 | int w = last_wrapped ? continuation_width : 0; |
741 | int w = 0, wrapped = 0; |
753 | int wrapped = 0; |
742 | const char *break_p = NULL; |
754 | const char *break_p = NULL; |
743 | |
755 | |
744 | while (*p) |
756 | while (*p) |
745 | { |
757 | { |
746 | /* find the length in bytes of the next multibyte character */ |
758 | /* find the length in bytes of the next multibyte character */ |
… | |
… | |
774 | } |
786 | } |
775 | |
787 | |
776 | { |
788 | { |
777 | /* HACK-4 - consider inserting the 'continuation string' |
789 | /* HACK-4 - consider inserting the 'continuation string' |
778 | * before the rest of the wrapped line */ |
790 | * before the rest of the wrapped line */ |
|
|
791 | int len = p - beg + (last_wrapped ? continuation_length : 0); |
779 | char *s = xmalloc (p - beg + 1); |
792 | char *s = xmalloc (len + 1); |
|
|
793 | if (last_wrapped) |
|
|
794 | { |
|
|
795 | memcpy (s, continuation, continuation_length); |
|
|
796 | memcpy (s + continuation_length, beg, p - beg); |
|
|
797 | } |
|
|
798 | else |
780 | memcpy (s, beg, p - beg); |
799 | memcpy (s, beg, len); |
|
|
800 | |
781 | s[p - beg] = 0; |
801 | s[len] = 0; |
782 | insert_line (idx); |
802 | insert_line (idx); |
783 | lines[idx].line = s; |
803 | lines[idx].line = s; |
784 | lines[idx].len = p - beg; |
804 | lines[idx].len = len; |
785 | lines[idx].color = color; |
805 | lines[idx].color = color; |
786 | } |
806 | } |
787 | |
807 | |
788 | /* if we wrapped at a space, don't display the space */ |
808 | /* if we wrapped at a space, don't display the space */ |
789 | if (opt_wordwrap && wrapped && break_p && break_p != beg) |
809 | if (opt_wordwrap && wrapped && break_p && break_p != beg) |
790 | { |
810 | { |
791 | l--; |
811 | l--; |
792 | p++; |
812 | p++; |
793 | } |
813 | } |
|
|
814 | |
|
|
815 | last_wrapped = wrapped; |
794 | } |
816 | } |
795 | while (l); |
817 | while (l); |
796 | } |
818 | } |
797 | |
819 | |
798 | /* |
820 | /* |