ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/root-tail/root-tail.c
(Generate patch)

Comparing root-tail/root-tail.c (file contents):
Revision 1.38 by pcg, Wed Mar 31 01:50:24 2004 UTC vs.
Revision 1.42 by chris_moore, Wed Mar 31 16:57:06 2004 UTC

75struct displaymatrix 75struct displaymatrix
76{ 76{
77 char *line; 77 char *line;
78 int len; 78 int len;
79 int buffer_size; 79 int buffer_size;
80 unsigned long color;
80}; 81};
81 82
82/* global variables */ 83/* global variables */
83struct linematrix *lines; 84struct linematrix *lines;
84struct displaymatrix *display; 85struct displaymatrix *display;
404 /* if this line is a different than it was, then it 405 /* if this line is a different than it was, then it
405 * needs displaying */ 406 * needs displaying */
406 if (!opt_noflicker 407 if (!opt_noflicker
407 || refresh_all 408 || refresh_all
408 || display_line->len != line->len 409 || display_line->len != line->len
410 || display_line->color != line->color
409 || memcmp (display_line->line, line->line, line->len)) 411 || memcmp (display_line->line, line->line, line->len))
410 { 412 {
411 /* don't bother updating the record of what has been 413 /* don't bother updating the record of what has been
412 * displayed if -noflicker isn't in effect, since we redraw 414 * displayed if -noflicker isn't in effect, since we redraw
413 * the whole display every time anyway */ 415 * the whole display every time anyway */
415 { 417 {
416 /* update the record of what has been displayed; 418 /* update the record of what has been displayed;
417 * first make sure the buffer is big enough */ 419 * first make sure the buffer is big enough */
418 if (display_line->buffer_size <= line->len) 420 if (display_line->buffer_size <= line->len)
419 { 421 {
420 display_line->buffer_size = line->len + 1; 422 display_line->buffer_size = line->len;
421 display_line->line = xrealloc (display_line->line, display_line->buffer_size); 423 display_line->line = xrealloc (display_line->line, display_line->buffer_size);
422 } 424 }
423 425
424 display_line->len = line->len; 426 display_line->len = line->len;
427 display_line->color = line->color;
425 memcpy (display_line->line, line->line, line->len); 428 memcpy (display_line->line, line->line, line->len);
426 429
427 if (clear) 430 if (clear)
428 XClearArea (disp, root, win_x, win_y + offset - font_ascent, 431 XClearArea (disp, root, win_x, win_y + offset - font_ascent,
429 width + effect_x_space, font_height + effect_y_space, False); 432 width + effect_x_space, font_height + effect_y_space, False);
432 if (opt_outline) 435 if (opt_outline)
433 { 436 {
434 int x, y; 437 int x, y;
435 XSetForeground (disp, WinGC, black_color); 438 XSetForeground (disp, WinGC, black_color);
436 439
437 for (x = -1; x < 2; x += 2) 440 for (x = -1; x <= 1; x += 2)
438 for (y = -1; y < 2; y += 2) 441 for (y = -1; y <= 1; y += 2)
439 XmbDrawString (disp, root, fontset, WinGC, 442 XmbDrawString (disp, root, fontset, WinGC,
440 win_x + effect_x_offset + x, 443 win_x + effect_x_offset + x,
441 win_y + y + offset, 444 win_y + y + offset,
442 line->line, line->len); 445 line->line, line->len);
443 } 446 }
488 if (i == 0) 491 if (i == 0)
489 { /* matched */ 492 { /* matched */
490 int match_start = matched[0].rm_so; 493 int match_start = matched[0].rm_so;
491 int match_end = matched[0].rm_eo; 494 int match_end = matched[0].rm_eo;
492 int old_len = match_end - match_start; 495 int old_len = match_end - match_start;
493 int new_len = strlen(transform_to); 496 int new_len = strlen (transform_to);
494 int old_whole_len = strlen(s); 497 int old_whole_len = strlen (s);
498
495 printf("regexp was matched by '%s' - replace with '%s'\n", s, transform_to); 499 printf ("regexp was matched by '%s' - replace with '%s'\n", s, transform_to);
496 printf("match is from %d to %d\n", 500 printf ("match is from %d to %d\n", match_start, match_end);
497 match_start, match_end);
498 if (new_len > old_len) { 501 if (new_len > old_len)
499 s = xrealloc(s, old_whole_len + new_len - old_len); 502 s = xrealloc(s, old_whole_len + new_len - old_len);
500 } 503
501 if (new_len != old_len) { 504 if (new_len != old_len)
505 {
502 memcpy(s + match_end + new_len - old_len, 506 memcpy(s + match_end + new_len - old_len,
503 s + match_end, 507 s + match_end,
504 old_whole_len - match_end); 508 old_whole_len - match_end);
505 s[old_whole_len + new_len - old_len] = '\0'; 509 s[old_whole_len + new_len - old_len] = '\0';
506 } 510 }
511
507 memcpy(s + match_start, 512 memcpy (s + match_start,
508 transform_to, 513 transform_to,
509 new_len); 514 new_len);
510 printf("transformed to '%s'\n", s); 515 printf ("transformed to '%s'\n", s);
511 } 516 }
512 else 517 else
513 { 518 {
514 printf("regexp was not matched by '%s'\n", s); 519 printf ("regexp was not matched by '%s'\n", s);
515 } 520 }
516 } 521 }
517} 522}
518#endif 523#endif
519 524
530 535
531 return r; 536 return r;
532} 537}
533 538
534/* 539/*
535 * HACK-1: This routine should read a single line, no matter how long. 540 * This routine can read a line of any length if it is called enough times.
536 */ 541 */
537int 542int
538lineinput (struct logfile_entry *logfile) 543lineinput (struct logfile_entry *logfile)
539{ 544{
540 char buff[1024], *p = buff; 545 char buff[1024], *p = buff;
670 { /* file renamed? */ 675 { /* file renamed? */
671 if (e->fp) 676 if (e->fp)
672 fclose (e->fp); 677 fclose (e->fp);
673 if (openlog (e) == NULL) 678 if (openlog (e) == NULL)
674 continue; 679 continue;
680 if (fstat (fileno (e->fp), &stats) < 0)
681 continue;
675 } 682 }
676 683
677 if (stats.st_size < e->last_size) 684 if (stats.st_size < e->last_size)
678 { /* file truncated? */ 685 { /* file truncated? */
679 fseek (e->fp, 0, SEEK_SET); 686 fseek (e->fp, 0, SEEK_SET);
738 static int continuation_length; 745 static int continuation_length;
739 746
740 /* only calculate the continuation's width once */ 747 /* only calculate the continuation's width once */
741 if (continuation_width == -1) 748 if (continuation_width == -1)
742 { 749 {
743 continuation_length = strlen(continuation); 750 continuation_length = strlen (continuation);
744 continuation_width = XmbTextEscapement (fontset, continuation, continuation_length); 751 continuation_width = XmbTextEscapement (fontset, continuation, continuation_length);
745 } 752 }
746 753
747 do 754 do
748 { 755 {
762 int cw = XmbTextEscapement (fontset, p, len); 769 int cw = XmbTextEscapement (fontset, p, len);
763 if (cw + w > width - effect_x_space) 770 if (cw + w > width - effect_x_space)
764 { 771 {
765 if (p == beg) 772 if (p == beg)
766 { 773 {
767 fprintf(stderr, "we can't even fit a single character onto the line\n"); 774 fprintf (stderr, "we can't even fit a single character onto the line\n");
768 if (len == 1) fprintf(stderr, "(the character we couldn't fit was '%c')\n", *p); 775 if (len == 1) fprintf (stderr, "(the character we couldn't fit was '%c')\n", *p);
769 exit(1); 776 exit (1);
770 } 777 }
771 778
772 wrapped = 1; 779 wrapped = 1;
773 break; 780 break;
774 } 781 }
789 l += p - break_p; 796 l += p - break_p;
790 p = break_p; 797 p = break_p;
791 } 798 }
792 799
793 { 800 {
794 /* HACK-4 - consider inserting the 'continuation string'
795 * before the rest of the wrapped line */
796 int len = p - beg + (last_wrapped ? continuation_length : 0); 801 int len = p - beg + (last_wrapped ? continuation_length : 0);
797 char *s = xmalloc (len + 1); 802 char *s = xmalloc (len + 1);
798 if (last_wrapped) 803 if (last_wrapped)
799 { 804 {
800 memcpy (s, continuation, continuation_length); 805 memcpy (s, continuation, continuation_length);
801 memcpy (s + continuation_length, beg, p - beg); 806 memcpy (s + continuation_length, beg, p - beg);
802 } 807 }
803 else 808 else
804 memcpy (s, beg, len); 809 memcpy (s, beg, len);
805 810
806 s[len] = 0; 811 s[len] = 0;
807 insert_line (idx); 812 insert_line (idx);
808 lines[idx].line = s; 813 lines[idx].line = s;
809 lines[idx].len = len; 814 lines[idx].len = len;
860 { 865 {
861 lines[lin].line = xstrdup ("~"); 866 lines[lin].line = xstrdup ("~");
862 lines[lin].len = 1; 867 lines[lin].len = 1;
863 display[lin].line = xstrdup(""); 868 display[lin].line = xstrdup("");
864 display[lin].len = 0; 869 display[lin].len = 0;
865 display[lin].buffer_size = 1; 870 display[lin].buffer_size = 0;
866 lines[lin].color = GetColor (def_color); 871 lines[lin].color = GetColor (def_color);
867 } 872 }
868 873
869 for (;;) 874 for (;;)
870 { 875 {
895 900
896 /* print filename if any, and if last line was from 901 /* print filename if any, and if last line was from
897 * different file */ 902 * different file */
898 if (!opt_nofilename && lastprinted != current && current->desc[0]) 903 if (!opt_nofilename && lastprinted != current && current->desc[0])
899 { 904 {
900 char buf[1024]; /* HACK-5 */
901 snprintf (buf, sizeof (buf), "[%s]", current->desc);
902 split_line (listlen - 1, buf, current->color); 905 split_line (listlen - 1, "[", current->color);
906 append_line (listlen - 1, current->desc);
907 append_line (listlen - 1, "]");
903 } 908 }
904 909
905 /* if we're dealing with partial lines, and the last 910 /* if we're dealing with partial lines, and the last
906 * time we showed the line it wasn't finished ... */ 911 * time we showed the line it wasn't finished ... */
907 if (!opt_whole && current->lastpartial) 912 if (!opt_whole && current->lastpartial)
1133 { 1138 {
1134 if ((e->fp = fdopen (0, "r")) == NULL) 1139 if ((e->fp = fdopen (0, "r")) == NULL)
1135 perror ("fdopen"), exit (1); 1140 perror ("fdopen"), exit (1);
1136 if (fcntl (0, F_SETFL, O_NONBLOCK) < 0) 1141 if (fcntl (0, F_SETFL, O_NONBLOCK) < 0)
1137 perror ("fcntl"), exit (1); 1142 perror ("fcntl"), exit (1);
1143
1138 e->fname = NULL; 1144 e->fname = NULL;
1139 e->inode = 0; 1145 e->inode = 0;
1140 e->desc = xstrdup ("stdin"); 1146 e->desc = xstrdup ("stdin");
1141 } 1147 }
1142 else 1148 else
1143 { 1149 {
1144 int l;
1145
1146 e->fname = xstrdup (fname); 1150 e->fname = xstrdup (fname);
1151
1147 if (openlog (e) == NULL) 1152 if (openlog (e) == NULL)
1148 perror (fname), exit (1); 1153 perror (fname), exit (1);
1149 1154
1150 e->desc = xstrdup (desc); 1155 e->desc = xstrdup (desc);
1151 } 1156 }
1156 1161
1157 if (!loglist) 1162 if (!loglist)
1158 loglist = e; 1163 loglist = e;
1159 if (loglist_tail) 1164 if (loglist_tail)
1160 loglist_tail->next = e; 1165 loglist_tail->next = e;
1166
1161 loglist_tail = e; 1167 loglist_tail = e;
1162 } 1168 }
1163 } 1169 }
1164 1170
1165 if (!loglist) 1171 if (!loglist)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines