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.40 by chris_moore, Wed Mar 31 16:27:04 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
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 }
799 { 806 {
800 memcpy (s, continuation, continuation_length); 807 memcpy (s, continuation, continuation_length);
801 memcpy (s + continuation_length, beg, p - beg); 808 memcpy (s + continuation_length, beg, p - beg);
802 } 809 }
803 else 810 else
804 memcpy (s, beg, len); 811 memcpy (s, beg, len);
805 812
806 s[len] = 0; 813 s[len] = 0;
807 insert_line (idx); 814 insert_line (idx);
808 lines[idx].line = s; 815 lines[idx].line = s;
809 lines[idx].len = len; 816 lines[idx].len = len;
860 { 867 {
861 lines[lin].line = xstrdup ("~"); 868 lines[lin].line = xstrdup ("~");
862 lines[lin].len = 1; 869 lines[lin].len = 1;
863 display[lin].line = xstrdup(""); 870 display[lin].line = xstrdup("");
864 display[lin].len = 0; 871 display[lin].len = 0;
865 display[lin].buffer_size = 1; 872 display[lin].buffer_size = 0;
866 lines[lin].color = GetColor (def_color); 873 lines[lin].color = GetColor (def_color);
867 } 874 }
868 875
869 for (;;) 876 for (;;)
870 { 877 {
1133 { 1140 {
1134 if ((e->fp = fdopen (0, "r")) == NULL) 1141 if ((e->fp = fdopen (0, "r")) == NULL)
1135 perror ("fdopen"), exit (1); 1142 perror ("fdopen"), exit (1);
1136 if (fcntl (0, F_SETFL, O_NONBLOCK) < 0) 1143 if (fcntl (0, F_SETFL, O_NONBLOCK) < 0)
1137 perror ("fcntl"), exit (1); 1144 perror ("fcntl"), exit (1);
1145
1138 e->fname = NULL; 1146 e->fname = NULL;
1139 e->inode = 0; 1147 e->inode = 0;
1140 e->desc = xstrdup ("stdin"); 1148 e->desc = xstrdup ("stdin");
1141 } 1149 }
1142 else 1150 else
1143 { 1151 {
1144 int l;
1145
1146 e->fname = xstrdup (fname); 1152 e->fname = xstrdup (fname);
1153
1147 if (openlog (e) == NULL) 1154 if (openlog (e) == NULL)
1148 perror (fname), exit (1); 1155 perror (fname), exit (1);
1149 1156
1150 e->desc = xstrdup (desc); 1157 e->desc = xstrdup (desc);
1151 } 1158 }
1156 1163
1157 if (!loglist) 1164 if (!loglist)
1158 loglist = e; 1165 loglist = e;
1159 if (loglist_tail) 1166 if (loglist_tail)
1160 loglist_tail->next = e; 1167 loglist_tail->next = e;
1168
1161 loglist_tail = e; 1169 loglist_tail = e;
1162 } 1170 }
1163 } 1171 }
1164 1172
1165 if (!loglist) 1173 if (!loglist)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines