… | |
… | |
57 | off_t last_size; /* file size at the last check */ |
57 | off_t last_size; /* file size at the last check */ |
58 | unsigned long color; /* color to be used for printing */ |
58 | unsigned long color; /* color to be used for printing */ |
59 | int partial; /* true if the last line isn't complete */ |
59 | int partial; /* true if the last line isn't complete */ |
60 | int lastpartial; /* true if the previous output wasn't complete */ |
60 | int lastpartial; /* true if the previous output wasn't complete */ |
61 | int index; /* index into linematrix of a partial line */ |
61 | int index; /* index into linematrix of a partial line */ |
|
|
62 | int modified; /* true if line is modified & needs displaying */ |
62 | }; |
63 | }; |
63 | |
64 | |
64 | struct linematrix |
65 | struct linematrix |
65 | { |
66 | { |
66 | char *line; |
67 | char *line; |
67 | int len; |
68 | int len; |
68 | unsigned long color; |
69 | unsigned long color; |
69 | }; |
70 | }; |
70 | |
71 | |
|
|
72 | struct displaymatrix |
|
|
73 | { |
|
|
74 | char *line; |
|
|
75 | int len; |
|
|
76 | int buffer_size; |
|
|
77 | }; |
|
|
78 | |
71 | /* global variables */ |
79 | /* global variables */ |
72 | struct linematrix *lines; |
80 | struct linematrix *lines; |
|
|
81 | struct displaymatrix *display; |
73 | int width = STD_WIDTH, height = STD_HEIGHT, listlen; |
82 | int width = STD_WIDTH, height = STD_HEIGHT, listlen; |
74 | int win_x = LOC_X, win_y = LOC_Y; |
83 | int win_x = LOC_X, win_y = LOC_Y; |
75 | int font_ascent, font_height; |
84 | int font_ascent, font_height; |
76 | int effect_x_space, effect_y_space; /* how much space does shading / outlining take up */ |
85 | int effect_x_space, effect_y_space; /* how much space does shading / outlining take up */ |
77 | int effect_x_offset, effect_y_offset; /* and how does it offset the usable space */ |
86 | int effect_x_offset, effect_y_offset; /* and how does it offset the usable space */ |
… | |
… | |
112 | void force_refresh (int); |
121 | void force_refresh (int); |
113 | void blank_window (int); |
122 | void blank_window (int); |
114 | |
123 | |
115 | void InitWindow (void); |
124 | void InitWindow (void); |
116 | unsigned long GetColor (const char *); |
125 | unsigned long GetColor (const char *); |
117 | void redraw (void); |
126 | void redraw (int); |
118 | void refresh (int, int, int); |
127 | void refresh (int, int, int, int); |
119 | |
128 | |
120 | void transform_line (char *s); |
129 | void transform_line (char *s); |
121 | int lineinput (struct logfile_entry *); |
130 | int lineinput (struct logfile_entry *); |
122 | void reopen (void); |
131 | void reopen (void); |
123 | void check_open_files (void); |
132 | void check_open_files (void); |
… | |
… | |
127 | void display_version (void); |
136 | void display_version (void); |
128 | void display_help (char *); |
137 | void display_help (char *); |
129 | void install_signal (int, void (*)(int)); |
138 | void install_signal (int, void (*)(int)); |
130 | void *xstrdup (const char *); |
139 | void *xstrdup (const char *); |
131 | void *xmalloc (size_t); |
140 | void *xmalloc (size_t); |
|
|
141 | void *xrealloc (void *, size_t); |
132 | int daemonize (void); |
142 | int daemonize (void); |
133 | |
143 | |
134 | /* signal handlers */ |
144 | /* signal handlers */ |
135 | void |
145 | void |
136 | list_files (int dummy) |
146 | list_files (int dummy) |
… | |
… | |
149 | } |
159 | } |
150 | |
160 | |
151 | void |
161 | void |
152 | force_refresh (int dummy) |
162 | force_refresh (int dummy) |
153 | { |
163 | { |
154 | redraw (); |
164 | redraw (1); |
155 | } |
165 | } |
156 | |
166 | |
157 | void |
167 | void |
158 | blank_window (int dummy) |
168 | blank_window (int dummy) |
159 | { |
169 | { |
… | |
… | |
348 | |
358 | |
349 | XSelectInput (disp, root, ExposureMask | FocusChangeMask); |
359 | XSelectInput (disp, root, ExposureMask | FocusChangeMask); |
350 | } |
360 | } |
351 | |
361 | |
352 | /* |
362 | /* |
353 | * redraw does a complete redraw, rather than an update (i.e. the area |
363 | * if redraw() is passwd a non-zero argument, it does a complete |
354 | * gets cleared first) |
364 | * redraw, rather than an update. if the argument is zero (and |
|
|
365 | * -noflicker is in effect) then only the lines which have changed |
|
|
366 | * since the last draw are redrawn. |
|
|
367 | * |
355 | * the rest is handled by regular refresh()'es |
368 | * the rest is handled by regular refresh()'es |
356 | */ |
369 | */ |
357 | void |
370 | void |
358 | redraw (void) |
371 | redraw (int redraw_all) |
359 | { |
372 | { |
360 | XSetClipMask (disp, WinGC, None); |
373 | XSetClipMask (disp, WinGC, None); |
361 | refresh (0, 32768, 1); |
374 | refresh (0, 32768, 1, redraw_all); |
362 | } |
375 | } |
363 | |
376 | |
364 | /* Just redraw everything without clearing (i.e. after an EXPOSE event) */ |
377 | /* Just redraw everything without clearing (i.e. after an EXPOSE event) */ |
365 | void |
378 | void |
366 | refresh (int miny, int maxy, int clear) |
379 | refresh (int miny, int maxy, int clear, int refresh_all) |
367 | { |
380 | { |
368 | int lin; |
381 | int lin; |
369 | int offset = (listlen + 1) * font_height; |
382 | int offset = (listlen + 1) * font_height; |
370 | unsigned long black_color = GetColor ("black"); |
383 | unsigned long black_color = GetColor ("black"); |
371 | |
384 | |
… | |
… | |
376 | XClearArea (disp, root, win_x, win_y, width, height, False); |
389 | XClearArea (disp, root, win_x, win_y, width, height, False); |
377 | |
390 | |
378 | for (lin = listlen; lin--;) |
391 | for (lin = listlen; lin--;) |
379 | { |
392 | { |
380 | struct linematrix *line = lines + (opt_reverse ? listlen - lin - 1 : lin); |
393 | struct linematrix *line = lines + (opt_reverse ? listlen - lin - 1 : lin); |
|
|
394 | struct displaymatrix *display_line = display + lin; |
381 | |
395 | |
382 | offset -= font_height; |
396 | offset -= font_height; |
383 | |
397 | |
384 | if (offset < miny || offset > maxy) |
398 | if (offset < miny || offset > maxy) |
385 | continue; |
399 | continue; |
386 | |
400 | |
387 | if (clear && opt_noflicker) |
401 | if (opt_noflicker) |
|
|
402 | { |
|
|
403 | /* if this line is a different than it was, then it |
|
|
404 | * needs displaying */ |
|
|
405 | if (refresh_all || |
|
|
406 | display_line->len != line->len || |
|
|
407 | strcmp(display_line->line, line->line)) |
|
|
408 | { |
|
|
409 | /* update the record of what has been displayed; |
|
|
410 | * first make sure the buffer is big enough */ |
|
|
411 | if (display_line->buffer_size <= line->len) |
|
|
412 | { |
|
|
413 | display_line->buffer_size = line->len + 1; |
|
|
414 | display_line->line = xrealloc(display_line->line, display_line->buffer_size); |
|
|
415 | } |
|
|
416 | strcpy(display_line->line, line->line); |
|
|
417 | display_line->len = line->len; |
|
|
418 | |
|
|
419 | if (clear) |
388 | XClearArea (disp, root, win_x, win_y + offset - font_height, |
420 | XClearArea (disp, root, win_x, win_y + offset - font_height, |
389 | width + effect_x_space, font_height + effect_y_space, False); |
421 | width + effect_x_space, font_height + effect_y_space, False); |
390 | |
422 | |
391 | if (opt_outline) |
423 | if (opt_outline) |
392 | { |
424 | { |
393 | int x, y; |
425 | int x, y; |
394 | XSetForeground (disp, WinGC, black_color); |
426 | XSetForeground (disp, WinGC, black_color); |
395 | |
427 | |
396 | for (x = -1; x < 2; x += 2) |
428 | for (x = -1; x < 2; x += 2) |
397 | for (y = -1; y < 2; y += 2) |
429 | for (y = -1; y < 2; y += 2) |
|
|
430 | XmbDrawString (disp, root, fontset, WinGC, |
|
|
431 | win_x + effect_x_offset + x, |
|
|
432 | win_y + effect_y_offset + y + offset - font_height + font_ascent, |
|
|
433 | line->line, line->len); |
|
|
434 | } |
|
|
435 | else if (opt_shade) |
|
|
436 | { |
|
|
437 | XSetForeground (disp, WinGC, black_color); |
|
|
438 | XmbDrawString (disp, root, fontset, WinGC, |
|
|
439 | win_x + effect_x_offset + SHADE_X, |
|
|
440 | win_y + effect_y_offset + offset + SHADE_Y - font_height + font_ascent, |
|
|
441 | line->line, line->len); |
|
|
442 | } |
|
|
443 | |
|
|
444 | XSetForeground (disp, WinGC, line->color); |
398 | XmbDrawString (disp, root, fontset, WinGC, |
445 | XmbDrawString (disp, root, fontset, WinGC, |
399 | win_x + effect_x_offset + x, |
446 | win_x + effect_x_offset, |
400 | win_y + effect_y_offset + y + offset - font_height + font_ascent, |
447 | win_y + effect_y_offset + offset - font_height + font_ascent, |
401 | line->line, line->len); |
448 | line->line, line->len); |
402 | } |
449 | } |
403 | else if (opt_shade) |
450 | } |
404 | { |
451 | else |
|
|
452 | { |
405 | XSetForeground (disp, WinGC, black_color); |
453 | XSetForeground (disp, WinGC, line->color); |
406 | XmbDrawString (disp, root, fontset, WinGC, |
454 | XmbDrawString (disp, root, fontset, WinGC, |
407 | win_x + effect_x_offset + SHADE_X, |
455 | win_x + effect_x_offset, |
408 | win_y + effect_y_offset + offset + SHADE_Y - font_height + font_ascent, |
456 | win_y + effect_y_offset + offset - font_height + font_ascent, |
409 | line->line, line->len); |
457 | line->line, line->len); |
410 | } |
458 | } |
411 | |
|
|
412 | XSetForeground (disp, WinGC, line->color); |
|
|
413 | XmbDrawString (disp, root, fontset, WinGC, |
|
|
414 | win_x + effect_x_offset, |
|
|
415 | win_y + effect_y_offset + offset - font_height + font_ascent, |
|
|
416 | line->line, line->len); |
|
|
417 | } |
459 | } |
418 | |
460 | |
419 | if (opt_frame) |
461 | if (opt_frame) |
420 | { |
462 | { |
421 | XSetForeground (disp, WinGC, GetColor (def_color)); |
463 | XSetForeground (disp, WinGC, GetColor (def_color)); |
… | |
… | |
452 | int old_whole_len = strlen(s); |
494 | int old_whole_len = strlen(s); |
453 | printf("regexp was matched by '%s' - replace with '%s'\n", s, transform_to); |
495 | printf("regexp was matched by '%s' - replace with '%s'\n", s, transform_to); |
454 | printf("match is from %d to %d\n", |
496 | printf("match is from %d to %d\n", |
455 | match_start, match_end); |
497 | match_start, match_end); |
456 | if (new_len > old_len) { |
498 | if (new_len > old_len) { |
457 | s = realloc(s, old_whole_len + new_len - old_len); |
499 | s = xrealloc(s, old_whole_len + new_len - old_len); |
458 | } |
500 | } |
459 | if (new_len != old_len) { |
501 | if (new_len != old_len) { |
460 | memcpy(s + match_end + new_len - old_len, |
502 | memcpy(s + match_end + new_len - old_len, |
461 | s + match_end, |
503 | s + match_end, |
462 | old_whole_len - match_end); |
504 | old_whole_len - match_end); |
… | |
… | |
673 | struct logfile_entry *current; |
715 | struct logfile_entry *current; |
674 | |
716 | |
675 | for (cur_line = idx; cur_line > 0; cur_line--) |
717 | for (cur_line = idx; cur_line > 0; cur_line--) |
676 | lines[cur_line] = lines[cur_line - 1]; |
718 | lines[cur_line] = lines[cur_line - 1]; |
677 | |
719 | |
678 | lines[0].line = strdup ("~"); |
720 | lines[0].line = xstrdup ("~"); |
679 | |
721 | |
680 | for (current = loglist; current; current = current->next) |
722 | for (current = loglist; current; current = current->next) |
681 | if (current->index >= 0 && current->index <= idx) |
723 | if (current->index >= 0 && current->index <= idx) |
682 | current->index++; |
724 | current->index++; |
683 | } |
725 | } |
… | |
… | |
771 | |
813 | |
772 | static void |
814 | static void |
773 | main_loop (void) |
815 | main_loop (void) |
774 | { |
816 | { |
775 | lines = xmalloc (sizeof (struct linematrix) * listlen); |
817 | lines = xmalloc (sizeof (struct linematrix) * listlen); |
|
|
818 | display = xmalloc (sizeof (struct displaymatrix) * listlen); |
776 | int lin; |
819 | int lin; |
777 | time_t lastreload; |
820 | time_t lastreload; |
778 | Region region = XCreateRegion (); |
821 | Region region = XCreateRegion (); |
779 | XEvent xev; |
822 | XEvent xev; |
780 | struct logfile_entry *lastprinted = NULL; |
823 | struct logfile_entry *lastprinted = NULL; |
… | |
… | |
784 | lastreload = time (NULL); |
827 | lastreload = time (NULL); |
785 | |
828 | |
786 | /* Initialize linematrix */ |
829 | /* Initialize linematrix */ |
787 | for (lin = 0; lin < listlen; lin++) |
830 | for (lin = 0; lin < listlen; lin++) |
788 | { |
831 | { |
789 | lines[lin].line = strdup ("~"); |
832 | lines[lin].line = xstrdup ("~"); |
790 | lines[lin].len = 1; |
833 | lines[lin].len = 1; |
|
|
834 | display[lin].line = xstrdup(""); |
|
|
835 | display[lin].len = 0; |
|
|
836 | display[lin].buffer_size = 1; |
791 | lines[lin].color = GetColor (def_color); |
837 | lines[lin].color = GetColor (def_color); |
792 | } |
838 | } |
793 | |
839 | |
794 | for (;;) |
840 | for (;;) |
795 | { |
841 | { |
… | |
… | |
846 | } |
892 | } |
847 | } |
893 | } |
848 | |
894 | |
849 | if (need_update) |
895 | if (need_update) |
850 | { |
896 | { |
851 | redraw (); |
897 | redraw (0); |
852 | need_update = 0; |
898 | need_update = 0; |
853 | } |
899 | } |
854 | else |
900 | else |
855 | { |
901 | { |
856 | XFlush (disp); |
902 | XFlush (disp); |
… | |
… | |
913 | XRectangle r; |
959 | XRectangle r; |
914 | |
960 | |
915 | XSetRegion (disp, WinGC, region); |
961 | XSetRegion (disp, WinGC, region); |
916 | XClipBox (region, &r); |
962 | XClipBox (region, &r); |
917 | |
963 | |
918 | refresh (r.y, r.y + r.height, 0); |
964 | refresh (r.y, r.y + r.height, 0, 1); |
919 | |
965 | |
920 | XDestroyRegion (region); |
966 | XDestroyRegion (region); |
921 | region = XCreateRegion (); |
967 | region = XCreateRegion (); |
922 | } |
968 | } |
923 | } |
969 | } |
… | |
… | |
1190 | } |
1236 | } |
1191 | |
1237 | |
1192 | return p; |
1238 | return p; |
1193 | } |
1239 | } |
1194 | |
1240 | |
|
|
1241 | void * |
|
|
1242 | xrealloc (void *ptr, size_t size) |
|
|
1243 | { |
|
|
1244 | void *p; |
|
|
1245 | |
|
|
1246 | while ((p = realloc (ptr, size)) == NULL) |
|
|
1247 | { |
|
|
1248 | fprintf (stderr, "Memory exausted."); |
|
|
1249 | sleep (10); |
|
|
1250 | } |
|
|
1251 | |
|
|
1252 | return p; |
|
|
1253 | } |
|
|
1254 | |
1195 | void |
1255 | void |
1196 | display_help (char *myname) |
1256 | display_help (char *myname) |
1197 | { |
1257 | { |
1198 | printf ("Usage: %s [options] file1[,color[,desc]] " |
1258 | printf ("Usage: %s [options] file1[,color[,desc]] " |
1199 | "[file2[,color[,desc]] ...]\n", myname); |
1259 | "[file2[,color[,desc]] ...]\n", myname); |