~ubuntu-branches/ubuntu/wily/weechat/wily-proposed

« back to all changes in this revision

Viewing changes to src/gui/gui-chat.c

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bouthenot
  • Date: 2014-09-28 17:41:10 UTC
  • mfrom: (1.1.28)
  • Revision ID: package-import@ubuntu.com-20140928174110-o73fmp020gwuz1ht
Tags: 1.0.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
639
639
                           const char *tags, const char *message, ...)
640
640
{
641
641
    time_t date_printed;
642
 
    int display_time, length, at_least_one_message_printed;
 
642
    int display_time, length, at_least_one_message_printed, msg_discarded;
643
643
    char *pos, *pos_prefix, *pos_tab, *pos_end, *pos_lines;
644
644
    char *modifier_data, *new_msg, *ptr_msg, *lines_waiting;
645
645
    struct t_gui_line *ptr_line;
693
693
 
694
694
        /* call modifier for message printed ("weechat_print") */
695
695
        new_msg = NULL;
 
696
        msg_discarded = 0;
696
697
        if (buffer)
697
698
        {
698
699
            length = strlen (gui_buffer_get_plugin_name (buffer)) + 1 +
718
719
                         * print anything
719
720
                         */
720
721
                        free (new_msg);
721
 
                        goto end;
 
722
                        new_msg = NULL;
 
723
                        msg_discarded = 1;
722
724
                    }
723
 
                    if (strcmp (message, new_msg) == 0)
 
725
                    else if (strcmp (message, new_msg) == 0)
724
726
                    {
725
727
                        /* no changes in new message */
726
728
                        free (new_msg);
730
732
            }
731
733
        }
732
734
 
733
 
        pos_prefix = NULL;
734
 
        display_time = 1;
735
 
        ptr_msg = (new_msg) ? new_msg : pos;
 
735
        if (!msg_discarded)
 
736
        {
 
737
            pos_prefix = NULL;
 
738
            display_time = 1;
 
739
            ptr_msg = (new_msg) ? new_msg : pos;
736
740
 
737
 
        /* space followed by tab => prefix ignored */
738
 
        if ((ptr_msg[0] == ' ') && (ptr_msg[1] == '\t'))
739
 
        {
740
 
            ptr_msg += 2;
741
 
        }
742
 
        else
743
 
        {
744
 
            /* if two first chars are tab, then do not display time */
745
 
            if ((ptr_msg[0] == '\t') && (ptr_msg[1] == '\t'))
 
741
            /* space followed by tab => prefix ignored */
 
742
            if ((ptr_msg[0] == ' ') && (ptr_msg[1] == '\t'))
746
743
            {
747
 
                display_time = 0;
748
744
                ptr_msg += 2;
749
745
            }
750
746
            else
751
747
            {
752
 
                /* if tab found, use prefix (before tab) */
753
 
                pos_tab = strchr (ptr_msg, '\t');
754
 
                if (pos_tab)
755
 
                {
756
 
                    pos_tab[0] = '\0';
757
 
                    pos_prefix = ptr_msg;
758
 
                    ptr_msg = pos_tab + 1;
 
748
                /* if two first chars are tab, then do not display time */
 
749
                if ((ptr_msg[0] == '\t') && (ptr_msg[1] == '\t'))
 
750
                {
 
751
                    display_time = 0;
 
752
                    ptr_msg += 2;
 
753
                }
 
754
                else
 
755
                {
 
756
                    /* if tab found, use prefix (before tab) */
 
757
                    pos_tab = strchr (ptr_msg, '\t');
 
758
                    if (pos_tab)
 
759
                    {
 
760
                        pos_tab[0] = '\0';
 
761
                        pos_prefix = ptr_msg;
 
762
                        ptr_msg = pos_tab + 1;
 
763
                    }
759
764
                }
760
765
            }
761
 
        }
762
766
 
763
 
        if (gui_init_ok)
764
 
        {
765
 
            ptr_line = gui_line_add (buffer, (display_time) ? date : 0,
766
 
                                     date_printed, tags, pos_prefix, ptr_msg);
767
 
            if (ptr_line)
768
 
            {
769
 
                if (buffer && buffer->print_hooks_enabled)
770
 
                    hook_print_exec (buffer, ptr_line);
771
 
                if (ptr_line->data->displayed)
772
 
                    at_least_one_message_printed = 1;
773
 
            }
774
 
        }
775
 
        else
776
 
        {
777
 
            length = ((pos_prefix) ? strlen (pos_prefix) + 1 : 0) +
778
 
                strlen (ptr_msg) + 1;
779
 
            if (gui_chat_lines_waiting_buffer)
780
 
            {
781
 
                length += strlen (gui_chat_lines_waiting_buffer) + 1;
782
 
                lines_waiting = realloc (gui_chat_lines_waiting_buffer, length);
783
 
                if (lines_waiting)
784
 
                {
785
 
                    gui_chat_lines_waiting_buffer = lines_waiting;
786
 
                }
787
 
                else
788
 
                {
789
 
                    free (gui_chat_lines_waiting_buffer);
790
 
                    gui_chat_lines_waiting_buffer = NULL;
 
767
            if (gui_init_ok)
 
768
            {
 
769
                ptr_line = gui_line_add (buffer, (display_time) ? date : 0,
 
770
                                         date_printed, tags, pos_prefix, ptr_msg);
 
771
                if (ptr_line)
 
772
                {
 
773
                    if (buffer && buffer->print_hooks_enabled)
 
774
                        hook_print_exec (buffer, ptr_line);
 
775
                    if (ptr_line->data->displayed)
 
776
                        at_least_one_message_printed = 1;
791
777
                }
792
778
            }
793
779
            else
794
780
            {
795
 
                gui_chat_lines_waiting_buffer = malloc (length);
796
 
                if (gui_chat_lines_waiting_buffer)
797
 
                    gui_chat_lines_waiting_buffer[0] = '\0';
798
 
            }
799
 
            if (gui_chat_lines_waiting_buffer)
800
 
            {
801
 
                pos_lines = gui_chat_lines_waiting_buffer +
802
 
                    strlen (gui_chat_lines_waiting_buffer);
803
 
                if (pos_lines > gui_chat_lines_waiting_buffer)
804
 
                {
805
 
                    pos_lines[0] = '\n';
806
 
                    pos_lines++;
807
 
                }
808
 
                if (pos_prefix)
809
 
                {
810
 
                    memcpy (pos_lines, pos_prefix, strlen (pos_prefix));
811
 
                    pos_lines += strlen (pos_prefix);
812
 
                    pos_lines[0] = '\t';
813
 
                    pos_lines++;
814
 
                }
815
 
                memcpy (pos_lines, ptr_msg, strlen (ptr_msg) + 1);
 
781
                length = ((pos_prefix) ? strlen (pos_prefix) + 1 : 0) +
 
782
                    strlen (ptr_msg) + 1;
 
783
                if (gui_chat_lines_waiting_buffer)
 
784
                {
 
785
                    length += strlen (gui_chat_lines_waiting_buffer) + 1;
 
786
                    lines_waiting = realloc (gui_chat_lines_waiting_buffer, length);
 
787
                    if (lines_waiting)
 
788
                    {
 
789
                        gui_chat_lines_waiting_buffer = lines_waiting;
 
790
                    }
 
791
                    else
 
792
                    {
 
793
                        free (gui_chat_lines_waiting_buffer);
 
794
                        gui_chat_lines_waiting_buffer = NULL;
 
795
                    }
 
796
                }
 
797
                else
 
798
                {
 
799
                    gui_chat_lines_waiting_buffer = malloc (length);
 
800
                    if (gui_chat_lines_waiting_buffer)
 
801
                        gui_chat_lines_waiting_buffer[0] = '\0';
 
802
                }
 
803
                if (gui_chat_lines_waiting_buffer)
 
804
                {
 
805
                    pos_lines = gui_chat_lines_waiting_buffer +
 
806
                        strlen (gui_chat_lines_waiting_buffer);
 
807
                    if (pos_lines > gui_chat_lines_waiting_buffer)
 
808
                    {
 
809
                        pos_lines[0] = '\n';
 
810
                        pos_lines++;
 
811
                    }
 
812
                    if (pos_prefix)
 
813
                    {
 
814
                        memcpy (pos_lines, pos_prefix, strlen (pos_prefix));
 
815
                        pos_lines += strlen (pos_prefix);
 
816
                        pos_lines[0] = '\t';
 
817
                        pos_lines++;
 
818
                    }
 
819
                    memcpy (pos_lines, ptr_msg, strlen (ptr_msg) + 1);
 
820
                }
816
821
            }
817
822
        }
818
823
 
825
830
    if (gui_init_ok && at_least_one_message_printed)
826
831
        gui_buffer_ask_chat_refresh (buffer, 1);
827
832
 
828
 
end:
829
833
    free (vbuffer);
830
834
}
831
835