… | |
… | |
73 | struct timeval interval = { 2, 400000 }; |
73 | struct timeval interval = { 2, 400000 }; |
74 | XFontSet fontset; |
74 | XFontSet fontset; |
75 | |
75 | |
76 | /* command line options */ |
76 | /* command line options */ |
77 | int opt_noinitial, opt_shade, opt_frame, opt_reverse, opt_nofilename, |
77 | int opt_noinitial, opt_shade, opt_frame, opt_reverse, opt_nofilename, |
78 | opt_outline, opt_noflicker, opt_whole, opt_update, geom_mask, reload = 0; |
78 | opt_outline, opt_noflicker, opt_whole, opt_update, opt_wordwrap, |
|
|
79 | geom_mask, reload = 0; |
79 | const char *command = NULL, |
80 | const char *command = NULL, |
80 | *fontname = USE_FONT, *dispname = NULL, *def_color = DEF_COLOR, |
81 | *fontname = USE_FONT, *dispname = NULL, *def_color = DEF_COLOR, |
81 | *continuation = "[+]"; |
82 | *continuation = "[+]"; |
82 | |
83 | |
83 | struct logfile_entry *loglist = NULL, *loglist_tail = NULL; |
84 | struct logfile_entry *loglist = NULL, *loglist_tail = NULL; |
… | |
… | |
607 | if (current->index >= 0 && current->index <= idx) |
608 | if (current->index >= 0 && current->index <= idx) |
608 | current->index++; |
609 | current->index++; |
609 | } |
610 | } |
610 | |
611 | |
611 | /* |
612 | /* |
612 | * takes a logical log file line and split it into multiple physical |
613 | * takes a logical log file line and splits it into multiple physical |
613 | * screen lines by splitting it whenever a part becomes too long. |
614 | * screen lines by splitting it whenever a part becomes too long. |
614 | * lal lines will be inserted at position "idx". |
615 | * lal lines will be inserted at position "idx". |
615 | */ |
616 | */ |
616 | static void |
617 | static void |
617 | split_line (int idx, const char *str, unsigned long color) |
618 | split_line (int idx, const char *str, unsigned long color) |
… | |
… | |
620 | const char *p = str; |
621 | const char *p = str; |
621 | |
622 | |
622 | do |
623 | do |
623 | { |
624 | { |
624 | const char *beg = p; |
625 | const char *beg = p; |
625 | int w = 0; |
626 | int w = 0, wrapped = 0; |
|
|
627 | const char *break_p = NULL; |
626 | |
628 | |
627 | while (*p) |
629 | while (*p) |
628 | { |
630 | { |
|
|
631 | /* find the length in bytes of the next multibyte character */ |
629 | int len = mblen (p, l); |
632 | int len = mblen (p, l); |
630 | if (len <= 0) |
633 | if (len <= 0) |
631 | len = 1; /* ignore (don't skip) ilegal character sequences */ |
634 | len = 1; /* ignore (don't skip) illegal character sequences */ |
632 | |
635 | |
|
|
636 | /* find the width in pixels of the next character */ |
633 | int cw = XmbTextEscapement (fontset, p, len); |
637 | int cw = XmbTextEscapement (fontset, p, len); |
634 | if (cw + w >= width) |
638 | if (cw + w >= width) |
|
|
639 | { |
|
|
640 | wrapped = 1; |
635 | break; |
641 | break; |
|
|
642 | } |
|
|
643 | |
|
|
644 | if (opt_wordwrap && len == 1 && p[0] == ' ') |
|
|
645 | break_p = p; |
636 | |
646 | |
637 | w += cw; |
647 | w += cw; |
638 | p += len; |
648 | p += len; |
639 | l -= len; |
649 | l -= len; |
640 | } |
650 | } |
|
|
651 | |
|
|
652 | /* if we're wrapping at spaces, and the line is long enough to |
|
|
653 | * wrap, and we've seen a space already, and the space wasn't |
|
|
654 | * the first character on the line, then wrap at the space */ |
|
|
655 | if (opt_wordwrap && wrapped && break_p && break_p != beg) |
|
|
656 | { |
|
|
657 | l += p - break_p; |
|
|
658 | p = break_p; |
|
|
659 | } |
641 | |
660 | |
642 | { |
661 | { |
643 | char *s = xmalloc (p - beg + 1); |
662 | char *s = xmalloc (p - beg + 1); |
644 | memcpy (s, beg, p - beg); |
663 | memcpy (s, beg, p - beg); |
645 | s[p - beg] = 0; |
664 | s[p - beg] = 0; |
646 | insert_line (idx); |
665 | insert_line (idx); |
647 | lines[idx].line = s; |
666 | lines[idx].line = s; |
648 | lines[idx].len = p - beg; |
667 | lines[idx].len = p - beg; |
649 | lines[idx].color = color; |
668 | lines[idx].color = color; |
650 | } |
669 | } |
|
|
670 | |
|
|
671 | /* if we wrapped at a space, don't display the space */ |
|
|
672 | if (opt_wordwrap && wrapped && break_p && break_p != beg) |
|
|
673 | { |
|
|
674 | l--; |
|
|
675 | p++; |
|
|
676 | } |
651 | } |
677 | } |
652 | while (l); |
678 | while (l); |
653 | } |
679 | } |
654 | |
680 | |
655 | /* |
681 | /* |
… | |
… | |
892 | opt_whole = 1; |
918 | opt_whole = 1; |
893 | else if (!strcmp (arg, "-partial")) |
919 | else if (!strcmp (arg, "-partial")) |
894 | opt_partial = 1; |
920 | opt_partial = 1; |
895 | else if (!strcmp (arg, "-update")) |
921 | else if (!strcmp (arg, "-update")) |
896 | opt_update = opt_partial = 1; |
922 | opt_update = opt_partial = 1; |
|
|
923 | else if (!strcmp (arg, "-wordwrap")) |
|
|
924 | opt_wordwrap = 1; |
897 | else if (!strcmp (arg, "-color")) |
925 | else if (!strcmp (arg, "-color")) |
898 | def_color = argv[++i]; |
926 | def_color = argv[++i]; |
899 | else if (!strcmp (arg, "-noinitial")) |
927 | else if (!strcmp (arg, "-noinitial")) |
900 | opt_noinitial = 1; |
928 | opt_noinitial = 1; |
901 | else if (!strcmp (arg, "-id")) |
929 | else if (!strcmp (arg, "-id")) |
… | |
… | |
1088 | " -reverse print new lines at the top\n" |
1116 | " -reverse print new lines at the top\n" |
1089 | " -whole wait for \\n before showing a line\n" |
1117 | " -whole wait for \\n before showing a line\n" |
1090 | " -partial show lines even if they don't end with a \\n\n" |
1118 | " -partial show lines even if they don't end with a \\n\n" |
1091 | " -update allow updates to old partial lines\n" |
1119 | " -update allow updates to old partial lines\n" |
1092 | " -cont string to prefix continued partial lines with\n" |
1120 | " -cont string to prefix continued partial lines with\n" |
|
|
1121 | " -wordwrap wrap long lines at spaces to avoid breaking words\n" |
1093 | " defaults to \"[+]\"\n" |
1122 | " defaults to \"[+]\"\n" |
1094 | " -shade add shading to font\n" |
1123 | " -shade add shading to font\n" |
1095 | " -noinitial don't display the last file lines on\n" |
1124 | " -noinitial don't display the last file lines on\n" |
1096 | " startup\n" |
1125 | " startup\n" |
1097 | " -i | -interval seconds interval between checks (fractional\n" |
1126 | " -i | -interval seconds interval between checks (fractional\n" |