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.41 by chris_moore, Wed Mar 31 16:42:22 2004 UTC vs.
Revision 1.65 by root, Sun Jun 16 01:24:29 2019 UTC

1/* 1/*
2 * Copyright 2001 by Marco d'Itri <md@linux.it> 2 * Copyright 2001 by Marco d'Itri <md@linux.it>
3 * Copyright 2000,2001,2002,2003,2004 3 * Copyright 2000,2001,2002,2003,2004
4 * Marc Lehmann <pcg@goof.com>, 4 * Marc Lehmann <pcg@goof.com>,
5 * Chris Moore <chris.moore@mail.com>,
5 * and many others, see README 6 * and many others, see README
6 * 7 *
7 * Original version by Mike Baker. 8 * Original version by Mike Baker.
8 * 9 *
9 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
20 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22 */ 23 */
23 24
24#include "config.h" 25#include "config.h"
26#include <assert.h>
25#include <stdlib.h> 27#include <stdlib.h>
26#include <stdio.h> 28#include <stdio.h>
27#include <unistd.h> 29#include <unistd.h>
28#include <string.h> 30#include <string.h>
29#include <signal.h> 31#include <signal.h>
37#include <ctype.h> 39#include <ctype.h>
38#include <stdarg.h> 40#include <stdarg.h>
39#include <X11/Xlib.h> 41#include <X11/Xlib.h>
40#include <X11/Xatom.h> 42#include <X11/Xatom.h>
41#include <X11/Xutil.h> 43#include <X11/Xutil.h>
44#include <X11/extensions/shape.h>
45#include <X11/extensions/Xfixes.h>
42 46
43#if HAS_REGEX 47#if HAS_REGEX
44#include <regex.h> 48#include <regex.h>
45#endif 49#endif
46 50
47#define SHADE_X 2 51#define SHADE_X 2
48#define SHADE_Y 2 52#define SHADE_Y 2
49 53
54/* some italic fonts still go over the margin - this margin of error cleans up the mess */
55#define MARGIN_OF_ERROR 2
56
50/* data structures */ 57/* data structures */
51struct logfile_entry 58struct logfile_entry
52{ 59{
53 struct logfile_entry *next; 60 struct logfile_entry *next;
54 61
55 char *fname; /* name of file */ 62 char *fname; /* name of file */
56 char *desc; /* alternative description */ 63 char *desc; /* alternative description */
57 char *buf; /* text read but not yet displayed */ 64 char *buf; /* text read but not yet displayed */
65 const char *fontname;
66 XFontSet fontset;
67 int font_height;
68 int font_ascent;
58 FILE *fp; /* FILE struct associated with file */ 69 FILE *fp; /* FILE struct associated with file */
59 ino_t inode; /* inode of the file opened */ 70 ino_t inode; /* inode of the file opened */
60 off_t last_size; /* file size at the last check */ 71 off_t last_size; /* file size at the last check */
61 unsigned long color; /* color to be used for printing */ 72 unsigned long color; /* color to be used for printing */
73 const char *colorname; /* color name/string */
62 int partial; /* true if the last line isn't complete */ 74 int partial; /* true if the last line isn't complete */
63 int lastpartial; /* true if the previous output wasn't complete */ 75 int lastpartial; /* true if the previous output wasn't complete */
64 int index; /* index into linematrix of a partial line */ 76 struct line_node *last; /* last line we output */
65 int modified; /* true if line is modified & needs displaying */ 77 int modified; /* true if line is modified & needs displaying */
66}; 78};
67 79
80struct line_node
81{
82 struct line_node *next;
83 struct line_node *prev;
84 struct logfile_entry *logfile;
85
86 char *line; /* the text of the line (so far) */
87 int len; /* the length of the line (in bytes) so far */
88 int wrapped_left; /* true if wrapped from the previous line */
89 int wrapped_right; /* true if wrapped to the next line */
90 struct breakinfo *breaks; /* array of indicies to spaces if wrapped_right */
91 int num_words; /* the number of words in the line */
92 int free_pixels; /* the number of free pixels to spread out */
93};
94
95struct breakinfo
96{
97 int index; /* index into string of start of substring */
98 int width; /* width in pixels of start of substring */
99 int len; /* length of substring */
100};
101
68struct linematrix 102struct displaymatrix
69{ 103{
70 char *line; 104 char *line;
71 int len; 105 int len;
72 unsigned long color; 106 int offset;
73};
74
75struct displaymatrix
76{
77 char *line;
78 int len;
79 int buffer_size; 107 int buffer_size;
80 unsigned long color; 108 unsigned long color;
81}; 109};
82 110
83/* global variables */ 111/* global variables */
84struct linematrix *lines; 112static struct line_node *linelist = NULL, *linelist_tail = NULL;
85struct displaymatrix *display; 113static struct displaymatrix *display;
114static int continuation_width = -1;
115static int continuation_color;
116static int continuation_length;
117
118/* HACK - ideally listlen will start at however many '~'s will fit on
119 * the screen */
86int width = STD_WIDTH, height = STD_HEIGHT, listlen; 120static unsigned int width = STD_WIDTH, height = STD_HEIGHT;
121static int listlen = 50;
87int win_x = LOC_X, win_y = LOC_Y; 122static int win_x = LOC_X, win_y = LOC_Y;
88int font_ascent, font_height;
89int effect_x_space, effect_y_space; /* how much space does shading / outlining take up */ 123static int effect_x_space, effect_y_space; /* how much space does shading / outlining take up */
90int effect_x_offset, effect_y_offset; /* and how does it offset the usable space */ 124static int effect_x_offset, effect_y_offset; /* and how does it offset the usable space */
91int do_reopen; 125static int do_reopen;
92struct timeval interval = { 2, 400000 }; 126static struct timeval interval = { 2, 400000 };
93XFontSet fontset;
94 127
95/* command line options */ 128/* command line options */
96int opt_noinitial, opt_shade, opt_frame, opt_reverse, opt_nofilename, 129static int opt_noinitial, opt_shade, opt_frame, opt_reverse, opt_nofilename,
97 opt_outline, opt_noflicker, opt_whole, opt_update, opt_wordwrap, 130 opt_outline, opt_noflicker, opt_whole, opt_update, opt_wordwrap,
98 geom_mask, reload = 0; 131 opt_justify, geom_mask, opt_minspace, opt_windowed, reload;
99const char *command = NULL, 132static const char *command = NULL,
100 *fontname = USE_FONT, *dispname = NULL, *def_color = DEF_COLOR, 133 *fontname = USE_FONT, *dispname = NULL, *def_color = DEF_COLOR,
101 *continuation = "[+]"; 134 *continuation = "|| ", *cont_color = DEF_CONT_COLOR;
102 135
103struct logfile_entry *loglist = NULL, *loglist_tail = NULL; 136struct logfile_entry *loglist = NULL, *loglist_tail = NULL;
104 137
105Display *disp; 138static Display *disp;
106Window root; 139static Window root;
107GC WinGC; 140static GC WinGC;
108 141
109#if HAS_REGEX 142#if HAS_REGEX
110struct re_list 143struct re_list
111{ 144{
112 regex_t from; 145 regex_t from;
113 const char *to; 146 const char *to;
114 struct re_list *next; 147 struct re_list *next;
115}; 148};
116struct re_list *re_head, *re_tail; 149static struct re_list *re_head, *re_tail;
117char *transform_to = NULL; 150static char *transform_to = NULL;
118regex_t *transformre; 151static regex_t *transformre;
119#endif 152#endif
120 153
121 154
122/* prototypes */ 155/* prototypes */
123void list_files (int); 156static void list_files (int);
124void force_reopen (int); 157static void force_reopen (int);
125void force_refresh (int); 158static void force_refresh (int);
126void blank_window (int); 159static void blank_window (int);
160#ifdef USE_TOON_GET_ROOT_WINDOW
161static Window ToonGetRootWindow(Display *, int, Window *);
162#endif /* USE_TOON_GET_ROOT_WINDOW */
127 163
128void InitWindow (void); 164static void InitWindow (void);
129unsigned long GetColor (const char *); 165static unsigned long GetColor (const char *);
130void redraw (int); 166static void redraw (int);
131void refresh (int, int, int, int); 167static void refresh (int, int, int, int);
132 168
133void transform_line (char *s);
134int lineinput (struct logfile_entry *); 169static int lineinput (struct logfile_entry *);
135void reopen (void); 170static void reopen (void);
136void check_open_files (void); 171static void check_open_files (void);
137FILE *openlog (struct logfile_entry *); 172static FILE *openlog (struct logfile_entry *);
138static void main_loop (void); 173static void main_loop (void);
139 174
140void display_version (void); 175static void display_version (void);
141void display_help (char *); 176static void display_help (char *);
142void install_signal (int, void (*)(int)); 177static void install_signal (int, void (*)(int));
143void *xstrdup (const char *); 178static void *xstrdup (const char *);
144void *xmalloc (size_t); 179static void *xmalloc (size_t);
145void *xrealloc (void *, size_t); 180static void *xrealloc (void *, size_t);
146int daemonize (void); 181static int daemonize (void);
147 182
148/* signal handlers */ 183/* signal handlers */
149void 184static void
150list_files (int dummy) 185list_files (int dummy)
151{ 186{
152 struct logfile_entry *e; 187 struct logfile_entry *e;
153 188
154 fprintf (stderr, "Files opened:\n"); 189 fprintf (stderr, "Files opened:\n");
155 for (e = loglist; e; e = e->next) 190 for (e = loglist; e; e = e->next)
156 fprintf (stderr, "\t%s (%s)\n", e->fname, e->desc); 191 fprintf (stderr, "\t%s (%s)\n", e->fname, e->desc);
157} 192}
158 193
159void 194static void
160force_reopen (int dummy) 195force_reopen (int dummy)
161{ 196{
162 do_reopen = 1; 197 do_reopen = 1;
163} 198}
164 199
165void 200static void
166force_refresh (int dummy) 201force_refresh (int dummy)
167{ 202{
168 redraw (1); 203 redraw (1);
169} 204}
170 205
171void 206static void
172blank_window (int dummy) 207blank_window (int dummy)
173{ 208{
174 XClearArea (disp, root, win_x - 2, win_y - 2, width + 5, height + 5, False); 209 XClearArea (disp, root, win_x, win_y, width + MARGIN_OF_ERROR, height, False);
175 XFlush (disp); 210 XFlush (disp);
176 exit (0); 211 exit (0);
177} 212}
178 213
179/* X related functions */ 214/* X related functions */
180unsigned long 215static unsigned long
181GetColor (const char *ColorName) 216GetColor (const char *ColorName)
182{ 217{
183 XColor Color; 218 XColor Color;
184 XWindowAttributes Attributes; 219 XWindowAttributes Attributes;
185 220
192 fprintf (stderr, "can't allocate %s\n", ColorName); 227 fprintf (stderr, "can't allocate %s\n", ColorName);
193 228
194 return Color.pixel; 229 return Color.pixel;
195} 230}
196 231
232#ifndef USE_TOON_GET_ROOT_WINDOW
197static Window 233static void
198root_window (Display * display, int screen_number) 234find_root_window (Display *display, int screen_number)
199{ 235{
236 if (!root)
237 {
200 Atom SWM_VROOT = XInternAtom (display, "__SWM_VROOT", False); 238 Atom SWM_VROOT = XInternAtom (display, "__SWM_VROOT", False);
201 Window real_root_window = RootWindow (display, screen_number); 239 Atom NAUTILUS_DESKTOP_WINDOW_ID = XInternAtom (display, "NAUTILUS_DESKTOP_WINDOW_ID", False);
202 240
203 if (root) /* root window set via option */
204 return root;
205
206 if (SWM_VROOT != None)
207 {
208 Window unused, *windows; 241 Window unused, *windows = 0;
209 unsigned int count; 242 unsigned int count;
210 243
244 Atom type;
245 int format;
246 unsigned long nitems, bytes_after_return;
247 unsigned char *virtual_root_window;
248
249 root = RootWindow (display, screen_number);
250
251 if (XGetWindowProperty (display, root, NAUTILUS_DESKTOP_WINDOW_ID,
252 0, 1, False, XA_WINDOW, &type, &format,
253 &nitems, &bytes_after_return,
254 &virtual_root_window) == Success
255 && type == XA_WINDOW)
256 {
211 if (XQueryTree (display, real_root_window, &unused, &unused, &windows, 257 if (XQueryTree (display, *(Window *)virtual_root_window, &unused, &unused, &windows, &count))
212 &count)) 258 root = windows[count - 1];
259
260 XFree (virtual_root_window);
261 }
262 else if (XQueryTree (display, root, &unused, &unused, &windows, &count))
213 { 263 {
214 int i; 264 int i;
215 265
216 for (i = 0; i < count; i++) 266 for (i = 0; i < count; i++)
217 { 267 {
218 Atom type;
219 int format;
220 unsigned long nitems, bytes_after_return;
221 unsigned char *virtual_root_window;
222
223 if (XGetWindowProperty (display, windows[i], SWM_VROOT, 268 if (XGetWindowProperty (display, windows[i], SWM_VROOT,
224 0, 1, False, XA_WINDOW, &type, &format, 269 0, 1, False, XA_WINDOW, &type, &format,
225 &nitems, &bytes_after_return, 270 &nitems, &bytes_after_return,
226 &virtual_root_window) == Success) 271 &virtual_root_window) == Success
272 && type == XA_WINDOW)
227 { 273 {
228 if (type != None)
229 {
230 if (type == XA_WINDOW)
231 {
232 XFree (windows);
233 return (Window) virtual_root_window; 274 root = *(Window *)virtual_root_window;
234 } 275 XFree (virtual_root_window);
235 else
236 fprintf (stderr,
237 "__SWM_VROOT property type mismatch");
238 } 276 break;
239 } 277 }
240 else 278 }
241 fprintf (stderr,
242 "failed to get __SWM_VROOT property on window 0x%lx",
243 windows[i]);
244 }
245 279
246 if (count)
247 XFree (windows); 280 XFree (windows);
248 } 281 }
249 else 282 else
250 fprintf (stderr, "Can't query tree on root window 0x%lx", 283 fprintf (stderr, "Can't query tree on root window 0x%lx", root);
251 real_root_window);
252 } 284 }
253 else
254 /* This shouldn't happen. The Xlib documentation is wrong BTW. */
255 fprintf (stderr, "Can't intern atom __SWM_VROOT");
256
257 return real_root_window;
258} 285}
286#endif /* USE_TOON_GET_ROOT_WINDOW */
259 287
260void 288static void
261InitWindow (void) 289InitWindow (void)
262{ 290{
263 XGCValues gcv; 291 XGCValues gcv;
264 unsigned long gcm; 292 unsigned long gcm;
265 int screen, ScreenWidth, ScreenHeight; 293 int screen, ScreenWidth, ScreenHeight;
294 struct logfile_entry *e;
266 295
267 if (!(disp = XOpenDisplay (dispname))) 296 if (!(disp = XOpenDisplay (dispname)))
268 { 297 {
269 fprintf (stderr, "Can't open display %s.\n", dispname); 298 fprintf (stderr, "Can't open display %s.\n", dispname);
270 exit (1); 299 exit (1);
272 301
273 screen = DefaultScreen (disp); 302 screen = DefaultScreen (disp);
274 ScreenHeight = DisplayHeight (disp, screen); 303 ScreenHeight = DisplayHeight (disp, screen);
275 ScreenWidth = DisplayWidth (disp, screen); 304 ScreenWidth = DisplayWidth (disp, screen);
276 305
306 if (opt_windowed)
307 {
308 XRectangle rect = { };
309 XSetWindowAttributes attr;
310
311 attr.background_pixmap = ParentRelative;
312 attr.override_redirect = True;
313
314 root = XCreateWindow (
315 disp, DefaultRootWindow (disp), 0, 0, DisplayWidth (disp, screen), DisplayHeight (disp, screen),
316 0, CopyFromParent, InputOutput, CopyFromParent,
317 CWOverrideRedirect | CWBackPixmap, &attr);
318
319 XMapWindow (disp, root);
320 XLowerWindow (disp, root);
321
322 XserverRegion region = XFixesCreateRegion (disp, &rect, 1);
323 XFixesSetWindowShapeRegion (disp, root, ShapeInput, 0, 0, region);
324 XFixesDestroyRegion (disp, region);
325 }
326 else
277 root = root_window (disp, screen); 327 find_root_window (disp, screen);
278 328
279 gcm = GCBackground; 329 gcm = GCBackground;
280 gcv.graphics_exposures = True; 330 gcv.graphics_exposures = True;
281 WinGC = XCreateGC (disp, root, gcm, &gcv); 331 WinGC = XCreateGC (disp, root, gcm, &gcv);
282 XMapWindow (disp, root); 332 XMapWindow (disp, root);
333
283 XSetForeground (disp, WinGC, GetColor (DEF_COLOR)); 334 XSetForeground (disp, WinGC, GetColor (DEF_COLOR));
284 335
336 for (e = loglist; e; e = e->next)
285 { 337 {
286 char **missing_charset_list; 338 char **missing_charset_list;
287 int missing_charset_count; 339 int missing_charset_count;
288 char *def_string; 340 char *def_string;
289 341
290 fontset = XCreateFontSet (disp, fontname, 342 e->fontset = XCreateFontSet (disp, e->fontname,
291 &missing_charset_list, &missing_charset_count, 343 &missing_charset_list, &missing_charset_count,
292 &def_string); 344 &def_string);
293
294 if (missing_charset_count) 345 if (missing_charset_count)
346 {
347#if 0
348 fprintf (stderr,
349 "Missing charsets in String to FontSet conversion (%s)\n",
350 missing_charset_list[0]);
351#endif
352 XFreeStringList (missing_charset_list);
353 }
354
355 if (!e->fontset)
356 {
357 fprintf (stderr, "unable to create fontset for font '%s', exiting.\n", e->fontname);
358 exit (1);
359 }
360
295 { 361 {
296 fprintf (stderr, 362 XFontSetExtents *xfe = XExtentsOfFontSet (e->fontset);
297 "Missing charsets in String to FontSet conversion (%s)\n", 363
298 missing_charset_list[0]); 364 e->font_height = xfe->max_logical_extent.height;
299 XFreeStringList (missing_charset_list); 365 e->font_ascent = -xfe->max_logical_extent.y;
300 } 366 }
301 }
302 367
303 if (!fontset) 368 if (e->font_height > height - effect_y_space)
369 {
370 fprintf(stderr, "\n the display isn't tall enough to display a single line in font '%s'\n",
371 e->fontname);
372 fprintf(stderr, "\n the geometry in use is %d pixels tall\n", height);
373 fprintf(stderr, "\n font '%s' is %d pixels tall\n", e->fontname, e->font_height);
374 if (effect_y_space)
375 fprintf(stderr, "\n the shade or outline options need an extra %d pixel%s of vertical space\n",
376 effect_y_space, effect_y_space == 1 ? "" : "s");
377 fprintf(stderr, "\n");
378 exit(1);
379 }
304 { 380 }
305 fprintf (stderr, "unable to create fontset, exiting.\n");
306 exit (1);
307 }
308
309 {
310 XFontSetExtents *xfe = XExtentsOfFontSet (fontset);
311
312 font_height = xfe->max_logical_extent.height;
313 font_ascent = -xfe->max_logical_extent.y;
314 }
315 381
316 if (geom_mask & XNegative) 382 if (geom_mask & XNegative)
317 win_x = win_x + ScreenWidth - width; 383 win_x = win_x + ScreenWidth - width;
318 if (geom_mask & YNegative) 384 if (geom_mask & YNegative)
319 win_y = win_y + ScreenHeight - height; 385 win_y = win_y + ScreenHeight - height;
320 386
321 if (opt_outline)
322 {
323 /* adding outline increases the total width and height by 2
324 pixels each, and offsets the text one pixel right and one
325 pixel down */
326 effect_x_space = effect_y_space = 2;
327 effect_x_offset = effect_y_offset = 1;
328 }
329 else if (opt_shade)
330 {
331 /* adding a shadow increases the space used */
332 effect_x_space = abs(SHADE_X);
333 effect_y_space = abs(SHADE_Y);
334 /* if the shadow is to the right and below then we don't need
335 * to move the text to make space for it, but shadows to the left
336 * and above need accomodating */
337 effect_x_offset = SHADE_X > 0 ? 0 : -SHADE_X;
338 effect_y_offset = SHADE_Y > 0 ? 0 : -SHADE_Y;
339 }
340 else
341 {
342 effect_x_space = effect_y_space = 0;
343 effect_x_offset = effect_y_offset = 0;
344 }
345
346 /* if we are using -shade or -outline, there will be less usable
347 * space for output */
348 listlen = (height - effect_y_space) / font_height;
349
350 if (!listlen)
351 {
352 fprintf (stderr, "height too small for a single line, setting to %d\n",
353 font_height);
354 listlen = 1;
355 }
356
357 /* leave the height how the user requested it. it might not all be
358 * used, but this will allow the geometry to be tuned more accurately
359 * (with the -frame option)
360 * the old code did this:
361 * height = listlen * font_height + effect_y_space; */
362 387 {
388 struct logfile_entry *e;
389
390 for (e = loglist; e; e = e->next)
391 e->color = GetColor (e->colorname);
392 }
393
363 XSelectInput (disp, root, ExposureMask | FocusChangeMask); 394 XSelectInput (disp, root, ExposureMask | FocusChangeMask);
364} 395}
365 396
366/* 397/*
367 * if redraw() is passwd a non-zero argument, it does a complete 398 * if redraw () is passwd a non-zero argument, it does a complete
368 * redraw, rather than an update. if the argument is zero (and 399 * redraw, rather than an update. if the argument is zero (and
369 * -noflicker is in effect) then only the lines which have changed 400 * -noflicker is in effect) then only the lines which have changed
370 * since the last draw are redrawn. 401 * since the last draw are redrawn.
371 * 402 *
372 * the rest is handled by regular refresh()'es 403 * the rest is handled by regular refresh ()'es
373 */ 404 */
374void 405static void
375redraw (int redraw_all) 406redraw (int redraw_all)
376{ 407{
377 XSetClipMask (disp, WinGC, None); 408 XSetClipMask (disp, WinGC, None);
378 refresh (0, 32768, 1, redraw_all); 409 refresh (0, 32768, 1, redraw_all);
379} 410}
380 411
412static void
413draw_text (Display *disp, Window root, GC WinGC, int x, int y, struct line_node *line, int foreground)
414{
415 if (line->wrapped_right && opt_justify && line->breaks)
416 {
417 int i;
418 for (i = 0; i < line->num_words; i++)
419 XmbDrawString (disp, root, line->logfile->fontset, WinGC,
420 x + line->breaks[i].width + ((i * line->free_pixels) / (line->num_words - 1))
421 + continuation_width * line->wrapped_left, y,
422 line->line + line->breaks[i].index,
423 line->breaks[i].len);
424
425 if (line->wrapped_left)
426 {
427 if (foreground) XSetForeground (disp, WinGC, continuation_color);
428 XmbDrawString (disp, root, line->logfile->fontset, WinGC, x, y, continuation, continuation_length);
429 }
430 }
431 else
432 {
433 XmbDrawString (disp, root, line->logfile->fontset, WinGC, x + continuation_width * line->wrapped_left,
434 y, line->line, line->len);
435
436 if (line->wrapped_left)
437 {
438 if (foreground) XSetForeground (disp, WinGC, continuation_color);
439 XmbDrawString (disp, root, line->logfile->fontset, WinGC, x, y, continuation, continuation_length);
440 }
441 }
442}
443
381/* Just redraw everything without clearing (i.e. after an EXPOSE event) */ 444/* Just redraw everything without clearing (i.e. after an EXPOSE event) */
382void 445static void
383refresh (int miny, int maxy, int clear, int refresh_all) 446refresh (int miny, int maxy, int clear, int refresh_all)
384{ 447{
385 int lin; 448 int lin = 0;
386 int offset = listlen * font_height + font_ascent + effect_y_offset; 449 int space = height;
450 int offset;
387 unsigned long black_color = GetColor ("black"); 451 unsigned long black_color = GetColor ("black");
452 struct line_node *line;
453 int step_per_line;
454 int foreground = 0;
388 455
389 miny -= win_y + font_height; 456 if (opt_reverse)
390 maxy -= win_y - font_height; 457 offset = effect_y_offset;
458 else
459 offset = height + effect_y_offset;
460
461 miny -= win_y;
462 maxy -= win_y;
391 463
392 if (clear && !opt_noflicker) 464 if (clear && !opt_noflicker)
393 XClearArea (disp, root, win_x, win_y, width, height, False); 465 XClearArea (disp, root, win_x, win_y, width + MARGIN_OF_ERROR, height, False);
394 466
395 for (lin = listlen; lin--;) 467 for (line = linelist; line; line = line->next, lin++)
396 { 468 {
397 struct linematrix *line = lines + (opt_reverse ? listlen - lin - 1 : lin);
398 struct displaymatrix *display_line = display + lin; 469 struct displaymatrix *display_line;
399 470
400 offset -= font_height; 471 if (opt_noflicker && lin >= listlen)
472 {
473 int i = listlen;
474 listlen *= 1.5;
475 display = xrealloc(display, listlen * sizeof(struct displaymatrix));
476 for (; i < listlen; i++)
477 {
478 display[i].line = xstrdup ("");
479 display[i].len = 0;
480 display[i].offset = 0;
481 display[i].buffer_size = 0;
482 }
483 }
401 484
485 display_line = display + lin;
486
487 step_per_line = line->logfile->font_height + effect_y_space;
488 if (step_per_line > space)
489 break;
490
491 if (!opt_reverse)
492 offset -= step_per_line;
493
494 offset += line->logfile->font_ascent;
495
496 miny -= line->logfile->font_height;
497 maxy += line->logfile->font_height;
498
402 if (offset < miny || offset > maxy) 499 if (offset >= miny && offset <= maxy)
403 continue; 500 {
404
405 /* if this line is a different than it was, then it 501 /* if this line is a different than it was, then it
406 * needs displaying */ 502 * needs displaying */
407 if (!opt_noflicker 503 if (!opt_noflicker
408 || refresh_all 504 || refresh_all
409 || display_line->len != line->len 505 || display_line->len != line->len
410 || display_line->color != line->color 506 || display_line->color != line->logfile->color
507 || display_line->offset != offset
411 || memcmp (display_line->line, line->line, line->len)) 508 || memcmp (display_line->line, line->line, line->len))
412 { 509 {
413 /* don't bother updating the record of what has been 510 /* don't bother updating the record of what has been
414 * displayed if -noflicker isn't in effect, since we redraw 511 * displayed if -noflicker isn't in effect, since we redraw
415 * the whole display every time anyway */ 512 * the whole display every time anyway */
416 if (opt_noflicker) 513 if (opt_noflicker)
417 { 514 {
418 /* update the record of what has been displayed; 515 /* update the record of what has been displayed;
419 * first make sure the buffer is big enough */ 516 * first make sure the buffer is big enough */
420 if (display_line->buffer_size <= line->len) 517 if (display_line->buffer_size < line->len)
421 { 518 {
422 display_line->buffer_size = line->len; 519 display_line->buffer_size = line->len;
423 display_line->line = xrealloc (display_line->line, display_line->buffer_size); 520 display_line->line = xrealloc (display_line->line, display_line->buffer_size);
424 } 521 }
425 522
426 display_line->len = line->len; 523 display_line->len = line->len;
427 display_line->color = line->color; 524 display_line->color = line->logfile->color;
525 display_line->offset = offset;
428 memcpy (display_line->line, line->line, line->len); 526 memcpy (display_line->line, line->line, line->len);
429 527
430 if (clear) 528 if (clear)
529 {
530#ifdef DEBUG
531 static int toggle;
532 toggle = 1 - toggle;
533 XSetForeground (disp, WinGC, toggle ? GetColor ("cyan") : GetColor ("yellow"));
534 XFillRectangle (disp, root, WinGC, win_x, win_y + offset - line->logfile->font_ascent,
535 width, step_per_line);
536#else /* DEBUG */
431 XClearArea (disp, root, win_x, win_y + offset - font_ascent, 537 XClearArea (disp, root, win_x, win_y + offset - line->logfile->font_ascent,
432 width + effect_x_space, font_height + effect_y_space, False); 538 width + MARGIN_OF_ERROR, step_per_line, False);
433 } 539#endif /* DEBUG */
540 }
541 }
434 542
435 if (opt_outline) 543 if (opt_outline)
436 { 544 {
437 int x, y; 545 int x, y;
438 XSetForeground (disp, WinGC, black_color); 546 XSetForeground (disp, WinGC, black_color);
439 547
440 for (x = -1; x <= 1; x += 2) 548 for (x = -1; x <= 1; x += 2)
441 for (y = -1; y <= 1; y += 2) 549 for (y = -1; y <= 1; y += 2)
442 XmbDrawString (disp, root, fontset, WinGC, 550 draw_text (disp, root, WinGC,
443 win_x + effect_x_offset + x, 551 win_x + effect_x_offset + x,
444 win_y + y + offset, 552 win_y + y + offset, line, foreground = 0);
445 line->line, line->len);
446 } 553 }
447 else if (opt_shade) 554 else if (opt_shade)
448 { 555 {
449 XSetForeground (disp, WinGC, black_color); 556 XSetForeground (disp, WinGC, black_color);
450 XmbDrawString (disp, root, fontset, WinGC, 557 draw_text (disp, root, WinGC,
451 win_x + effect_x_offset + SHADE_X, 558 win_x + effect_x_offset + SHADE_X,
452 win_y + offset + SHADE_Y, 559 win_y + offset + SHADE_Y, line, foreground = 0);
453 line->line, line->len);
454 } 560 }
455 561
456 XSetForeground (disp, WinGC, line->color); 562 XSetForeground (disp, WinGC, line->logfile->color);
457 XmbDrawString (disp, root, fontset, WinGC, 563 draw_text (disp, root, WinGC,
458 win_x + effect_x_offset, 564 win_x + effect_x_offset,
459 win_y + offset, 565 win_y + offset, line, foreground = 1);
460 line->line, line->len); 566 }
461 } 567 }
568
569 if (opt_reverse)
570 offset += step_per_line;
571 offset -= line->logfile->font_ascent;
572
573 miny += line->logfile->font_height;
574 maxy -= line->logfile->font_height;
575
576 space -= step_per_line;
577 }
578
579 if (space > 0 && clear)
580 {
581#ifdef DEBUG
582 XSetForeground (disp, WinGC, GetColor ("orange"));
583 XFillRectangle (disp, root, WinGC, win_x, win_y + offset - (opt_reverse ? 0 : space),
584 width, space);
585#else /* DEBUG */
586 XClearArea (disp, root, win_x, win_y + offset - (opt_reverse ? 0 : space),
587 width + MARGIN_OF_ERROR, space, False);
588#endif
589 }
590
591 /* at least one of the lines must fit in the allocated area. we've
592 * already checked at initialisation time that all the fonts are small
593 * enough to fit at least one line in the display area, but assert it
594 * again here to be sure */
595 assert(line != linelist);
596
597 /* any lines that didn't just get looked at are never going to be, so break the chain */
598 if (line) line->prev->next = 0;
599
600 /* and throw them all away */
601 while (line)
602 {
603 struct line_node *this = line;
604 line = line->next;
605 if (this->logfile && this->logfile->last == this)
606 this->logfile->last = NULL;
607 free (this->line);
608 free (this->breaks);
609 free (this);
462 } 610 }
463 611
464 if (opt_frame) 612 if (opt_frame)
465 { 613 {
466 XSetForeground (disp, WinGC, GetColor (def_color)); 614 XSetForeground (disp, WinGC, GetColor (def_color));
615 /* note that XDrawRectangle() draws a rectangle one pixel bigger
616 * in both dimensions than you ask for, hence the subtractions.
617 * XFillRectangle() doesn't suffer from this problem */
467 XDrawRectangle (disp, root, WinGC, win_x - 0, win_y - 0, width - 1, height - 1); 618 XDrawRectangle (disp, root, WinGC, win_x - 0, win_y - 0, width - 1, height - 1);
468 } 619 }
469} 620}
470 621
471#if HAS_REGEX 622#if HAS_REGEX
472void 623void void
473transform_line (char *s) 624transform_line (char *s)
474{ 625{
475#ifdef I_AM_Md 626#ifdef I_AM_Md
476 int i; 627 int i;
477 if (1) 628 if (1)
488 regmatch_t matched[16]; 639 regmatch_t matched[16];
489 640
490 i = regexec (transformre, s, 16, matched, 0); 641 i = regexec (transformre, s, 16, matched, 0);
491 if (i == 0) 642 if (i == 0)
492 { /* matched */ 643 { /* matched */
493 int match_start = matched[0].rm_so; 644 int match_start = matched[0].rm_so;
494 int match_end = matched[0].rm_eo; 645 int match_end = matched[0].rm_eo;
495 int old_len = match_end - match_start; 646 int old_len = match_end - match_start;
496 int new_len = strlen (transform_to); 647 int new_len = strlen (transform_to);
497 int old_whole_len = strlen (s); 648 int old_whole_len = strlen (s);
498 649
499 printf ("regexp was matched by '%s' - replace with '%s'\n", s, transform_to); 650 printf ("regexp was matched by '%s' - replace with '%s'\n", s, transform_to);
500 printf ("match is from %d to %d\n", match_start, match_end); 651 printf ("match is from %d to %d\n", match_start, match_end);
501 if (new_len > old_len) 652 if (new_len > old_len)
502 s = xrealloc(s, old_whole_len + new_len - old_len); 653 s = xrealloc (s, old_whole_len + new_len - old_len);
503 654
504 if (new_len != old_len) 655 if (new_len != old_len)
505 { 656 {
506 memcpy(s + match_end + new_len - old_len, 657 memcpy (s + match_end + new_len - old_len,
507 s + match_end, 658 s + match_end,
508 old_whole_len - match_end); 659 old_whole_len - match_end);
509 s[old_whole_len + new_len - old_len] = '\0'; 660 s[old_whole_len + new_len - old_len] = '\0';
510 } 661 }
511 662
512 memcpy (s + match_start, 663 memcpy (s + match_start,
513 transform_to, 664 transform_to,
514 new_len); 665 new_len);
515 printf ("transformed to '%s'\n", s); 666 printf ("transformed to '%s'\n", s);
516 } 667 }
517 else 668 else
518 {
519 printf ("regexp was not matched by '%s'\n", s); 669 printf ("regexp was not matched by '%s'\n", s);
520 }
521 } 670 }
522} 671}
523#endif 672#endif
524 673
525char * 674/*
526concat_line (const char *p1, const char *p2) 675 * appends p2 to the end of p1, if p1 is not null
676 * otherwise allocates a new string and copies p2 to it
677 */
678static char *
679concat_line (char *p1, const char *p2)
527{ 680{
528 int l1 = p1 ? strlen (p1) : 0; 681 int l1 = p1 ? strlen (p1) : 0;
529 int l2 = strlen (p2); 682 int l2 = strlen (p2);
530 char *r = xmalloc (l1 + l2 + 1); 683 char *r;
531 684
532 memcpy (r, p1, l1); 685 assert (p2);
686
687 if (p1)
688 r = xrealloc(p1, l1 + l2 + 1);
689 else
690 r = xmalloc (l2 + 1);
691
533 memcpy (r + l1, p2, l2); 692 memcpy (r + l1, p2, l2);
534 r[l1 + l2] = 0; 693 r[l1 + l2] = 0;
535 694
536 return r; 695 return r;
537} 696}
538 697
539/* 698/*
540 * This routine can read a line of any length if it is called enough times. 699 * This routine can read a line of any length if it is called enough times.
541 */ 700 */
542int 701static int
543lineinput (struct logfile_entry *logfile) 702lineinput (struct logfile_entry *logfile)
544{ 703{
545 char buff[1024], *p = buff; 704 char buff[1024], *p;
546 int ch; 705 int ch;
547 /* HACK-2: add on the length of any partial line which we will be appending to */ 706 /* HACK-2: add on the length of any partial line which we will be appending to */
548 int ofs = logfile->buf ? strlen (logfile->buf) : 0; 707 int ofs = logfile->buf ? strlen (logfile->buf) : 0;
549 708
709 /* this loop ensures that the whole line is read, even if it's
710 * longer than the buffer. we need to do this because when --whole
711 * is in effect we don't know whether to display the line or not
712 * until we've seen how (ie. whether) it ends */
550 do 713 do
551 { 714 {
715 p = buff;
716 do
717 {
552 ch = fgetc (logfile->fp); 718 ch = fgetc (logfile->fp);
553 719
554 if (ch == '\n' || ch == EOF) 720 if (ch == '\n' || ch == EOF)
555 break; 721 break;
556 else if (ch == '\r') 722 else if (ch == '\r')
557 continue; /* skip */ 723 continue; /* skip */
558 else if (ch == '\t') 724 else if (ch == '\t')
559 { 725 {
560 do 726 do
561 { 727 {
562 *p++ = ' '; 728 *p++ = ' ';
729 ofs++;
730 }
731 while (ofs & 7);
732 }
733 else
734 {
735 *p++ = ch;
563 ofs++; 736 ofs++;
564 } 737 }
565 while (ofs & 7);
566 }
567 else
568 { 738 }
569 *p++ = ch;
570 ofs++;
571 }
572 }
573 while (p < buff + (sizeof buff) - 8 - 1); 739 while (p < buff + (sizeof buff) - 8 - 1);
574 740
575 if (p == buff && ch == EOF) 741 if (p == buff && ch == EOF)
576 return 0; 742 return 0;
577 743
578 *p = 0; 744 *p = 0;
579 745
580 p = concat_line (logfile->buf, buff); 746 p = logfile->buf = concat_line (logfile->buf, buff);
581 free (logfile->buf); logfile->buf = p; 747 }
748 while (ch != '\n' && ch != EOF);
582 749
583 logfile->lastpartial = logfile->partial; 750 logfile->lastpartial = logfile->partial;
584 /* there are 3 ways we could have exited the loop: reading '\n', 751 /* there are 3 ways we could have exited the loop: reading '\n',
585 * reaching EOF, or filling the buffer; the 2nd and 3rd of these 752 * reaching EOF, or filling the buffer; the 2nd and 3rd of these
586 * both result in a partial line */ 753 * both result in a partial line */
587 logfile->partial = ch != '\n'; 754 logfile->partial = ch != '\n';
588 755
589 if (logfile->partial && opt_whole) 756 if (logfile->partial && opt_whole)
590 return 0; 757 return 0;
591 758
592#if HAS_REGEX 759#if HAS_REGEX
593 transform_line (logfile->buf); 760 transform_line (logfile->buf);
598/* input: reads file->fname 765/* input: reads file->fname
599 * output: fills file->fp, file->inode 766 * output: fills file->fp, file->inode
600 * returns file->fp 767 * returns file->fp
601 * in case of error, file->fp is NULL 768 * in case of error, file->fp is NULL
602 */ 769 */
603FILE * 770static FILE *
604openlog (struct logfile_entry * file) 771openlog (struct logfile_entry *file)
605{ 772{
606 struct stat stats; 773 struct stat stats;
607 774
608 if ((file->fp = fopen (file->fname, "r")) == NULL) 775 if ((file->fp = fopen (file->fname, "r")) == NULL)
609 { 776 {
621 else 788 else
622 file->inode = stats.st_ino; 789 file->inode = stats.st_ino;
623 790
624 if (opt_noinitial) 791 if (opt_noinitial)
625 fseek (file->fp, 0, SEEK_END); 792 fseek (file->fp, 0, SEEK_END);
626 else if (stats.st_size > (listlen + 1) * width) 793 else /* if (stats.st_size > (listlen + 1) * width)
794 * HACK - 'width' is in pixels - how are we to know how much text will fit?
627 fseek (file->fp, -((listlen + 2) * width), SEEK_END); 795 * fseek (file->fp, -((listlen + 2) * width/10), SEEK_END); */
796 fseek (file->fp, -5000, SEEK_END);
628 797
629 file->last_size = stats.st_size; 798 file->last_size = stats.st_size;
630 return file->fp; 799 return file->fp;
631} 800}
632 801
633void 802static void
634reopen (void) 803reopen (void)
635{ 804{
636 struct logfile_entry *e; 805 struct logfile_entry *e;
637 806
638 for (e = loglist; e; e = e->next) 807 for (e = loglist; e; e = e->next)
647 } 816 }
648 817
649 do_reopen = 0; 818 do_reopen = 0;
650} 819}
651 820
652void 821static void
653check_open_files (void) 822check_open_files (void)
654{ 823{
655 struct logfile_entry *e; 824 struct logfile_entry *e;
656 struct stat stats; 825 struct stat stats;
657 826
688 } 857 }
689 } 858 }
690} 859}
691 860
692/* 861/*
693 * insert a single physical line (that must be short enough to fit) 862 * insert a single node in the list of screen lines and return a
694 * at position "idx" by pushing up lines above it. the caller 863 * pointer to the new node.
695 * MUST then fill in lines[idx] with valid data. 864 * the caller MUST then fill in ret->line and ret->len with valid
865 * data.
696 */ 866 */
697static void 867static struct line_node *
698insert_line (int idx) 868new_line_node (struct logfile_entry *log)
699{ 869{
700 int cur_line; 870 struct line_node *new = xmalloc (sizeof (struct line_node));
701 struct logfile_entry *current;
702 871
703 free (lines[0].line); 872 new->logfile = log;
873 new->wrapped_left = 0;
874 new->wrapped_right = 0;
875 new->breaks = 0;
704 876
705 for (cur_line = 0; cur_line < idx; cur_line++) 877 assert(log);
706 lines[cur_line] = lines[cur_line + 1];
707 878
708 for (current = loglist; current; current = current->next) 879 if (!log || !log->last)
709 if (current->index <= idx) 880 {
710 current->index--; 881 new->next = linelist;
882 new->next->prev = new;
883
884 new->prev = NULL;
885 linelist = new;
886 }
887 else
888 {
889 /* 2 pointers from the new node */
890 new->next = log->last;
891 new->prev = log->last->prev;
892
893 /* 2 pointers back to the new node */
894 if (new->next) new->next->prev = new;
895 if (new->prev) new->prev->next = new;
896
897 /* if this is a new first entry in the list then update
898 * 'linelist' */
899 if (log->last == linelist)
900 linelist = new;
901 }
902
903 /* update the logfile record */
904 if (log)
905 log->last = new;
906
907 return new;
711} 908}
712 909
713/* 910/*
714 * remove a single physical line at position "idx" by moving the lines above it 911 * this is called after either adding a new line or appending to an
715 * down and inserting a "~" line at the top. 912 * old one. in both cases it's possible that the line no longer fits,
913 * and needs wrapping. this function checks the last line associated
914 * with the supplied logfile.
716 */ 915 */
717static void 916static void
718delete_line (int idx) 917possibly_split_long_line (struct logfile_entry *log)
719{ 918{
720 int cur_line; 919 char *str = log->last->line;
721 struct logfile_entry *current;
722
723 for (cur_line = idx; cur_line > 0; cur_line--)
724 lines[cur_line] = lines[cur_line - 1];
725
726 lines[0].line = xstrdup ("~");
727
728 for (current = loglist; current; current = current->next)
729 if (current->index >= 0 && current->index <= idx)
730 current->index++;
731}
732
733/*
734 * takes a logical log file line and splits it into multiple physical
735 * screen lines by splitting it whenever a part becomes too long.
736 * lal lines will be inserted at position "idx".
737 */
738static void
739split_line (int idx, const char *str, unsigned long color)
740{
741 int l = strlen (str); 920 int l = strlen (str);
742 int last_wrapped = 0;
743 const char *p = str; 921 char *p = str;
744 static int continuation_width = -1; 922 struct line_node *line;
745 static int continuation_length; 923 int spaces;
924 static struct breakinfo *breaks;
925 static int break_buffer_size;
746 926
747 /* only calculate the continuation's width once */ 927 /* only calculate the continuation's width once */
748 if (continuation_width == -1) 928 if (continuation_width == -1)
749 { 929 {
750 continuation_length = strlen (continuation); 930 continuation_length = strlen (continuation);
751 continuation_width = XmbTextEscapement (fontset, continuation, continuation_length); 931 continuation_width = XmbTextEscapement (log->fontset, continuation, continuation_length);
932 continuation_color = GetColor (cont_color);
933
934 /* make an array to store information about the location of
935 * spaces in the line */
936 if (opt_justify)
937 {
938 break_buffer_size = 32;
939 breaks = xmalloc (break_buffer_size * sizeof (struct breakinfo));
940 }
752 } 941 }
753 942
754 do 943 do
755 { 944 {
756 const char *beg = p; 945 const char *beg = p;
757 int w = last_wrapped ? continuation_width : 0; 946 int start_w = log->last->wrapped_left ? continuation_width : 0;
947 int w = start_w;
758 int wrapped = 0; 948 int wrapped = 0;
759 const char *break_p = NULL; 949 char *break_p = NULL;
950 int width_at_break_p = 0;
951 int prefix_len;
952
953 spaces = 0;
954
955 if (opt_justify)
956 breaks[spaces].index = breaks[spaces].width = 0;
760 957
761 while (*p) 958 while (*p)
762 { 959 {
960 int cw, len;
961
763 /* find the length in bytes of the next multibyte character */ 962 /* find the length in bytes of the next multibyte character */
764 int len = mblen (p, l); 963 len = mblen (p, l);
765 if (len <= 0) 964 if (len <= 0)
766 len = 1; /* ignore (don't skip) illegal character sequences */ 965 len = 1; /* ignore (don't skip) illegal character sequences */
767 966
768 /* find the width in pixels of the next character */ 967 /* find the width in pixels of the next character */
769 int cw = XmbTextEscapement (fontset, p, len); 968 cw = XmbTextEscapement (log->fontset, p, len);
969 if (opt_wordwrap && len == 1 && p[0] == ' ' && p != break_p + 1)
970 {
971 break_p = p;
972 width_at_break_p = w;
973 spaces++;
974
975 if (opt_justify)
976 {
977 /* increase the size of the 'breaks' array when
978 * necessary */
979 if (spaces >= break_buffer_size)
980 {
981 break_buffer_size *= 1.5;
982 breaks = xrealloc (breaks, break_buffer_size * sizeof (struct breakinfo));
983 }
984
985 /* store information about (a) the location of each
986 * space */
987 breaks[spaces].index = p + 1 - beg;
988 /* (b) the width (in pixels) of the string up to
989 * this space */
990 breaks[spaces].width = cw + w - start_w;
991 /* (c) the length of each 'word' */
992 breaks[spaces-1].len = breaks[spaces].index - breaks[spaces-1].index;
993 }
994 }
995
770 if (cw + w > width - effect_x_space) 996 if (cw + w > width - effect_x_space)
771 { 997 {
772 if (p == beg) 998 if (p == beg)
773 { 999 {
774 fprintf (stderr, "we can't even fit a single character onto the line\n"); 1000 fprintf (stderr, "we can't even fit a single character onto the line\n");
775 if (len == 1) fprintf (stderr, "(the character we couldn't fit was '%c')\n", *p); 1001 if (len == 1) fprintf (stderr, "(the character we couldn't fit was '%c')\n", *p);
776 exit (1); 1002 exit (1);
777 } 1003 }
778 1004
779 wrapped = 1; 1005 wrapped = 1;
780 break; 1006 break;
781 } 1007 }
782
783 if (opt_wordwrap && len == 1 && p[0] == ' ')
784 break_p = p;
785 1008
786 w += cw; 1009 w += cw;
787 p += len; 1010 p += len;
788 l -= len; 1011 l -= len;
789 } 1012 }
790 1013
791 /* if we're wrapping at spaces, and the line is long enough to 1014 /* if we're wrapping at spaces, and the line is long enough to
792 * wrap, and we've seen a space already, and the space wasn't 1015 * wrap, and we've seen a space already, and the space wasn't
793 * the first character on the line, then wrap at the space */ 1016 * the first character on the line, then wrap at the space */
1017 if (!wrapped)
1018 break;
1019
1020 /* choose where to break the line */
794 if (opt_wordwrap && wrapped && break_p && break_p != beg) 1021 if (opt_wordwrap && break_p && break_p != beg)
795 {
796 l += p - break_p;
797 p = break_p;
798 }
799
800 { 1022 {
801 /* HACK-4 - consider inserting the 'continuation string' 1023 prefix_len = break_p - beg;
802 * before the rest of the wrapped line */ 1024 p = break_p;
803 int len = p - beg + (last_wrapped ? continuation_length : 0); 1025 w = width_at_break_p;
804 char *s = xmalloc (len + 1);
805 if (last_wrapped)
806 {
807 memcpy (s, continuation, continuation_length);
808 memcpy (s + continuation_length, beg, p - beg);
809 }
810 else
811 memcpy (s, beg, len);
812 1026
813 s[len] = 0; 1027 /* if breaking at a space, skip all adjacent spaces */
814 insert_line (idx); 1028 while (*p == ' ')
815 lines[idx].line = s; 1029 {
816 lines[idx].len = len; 1030 int len = mblen (p, l);
817 lines[idx].color = color; 1031 if (len != 1) break;
1032 p++;
1033 }
1034
1035 if (opt_justify)
1036 {
1037 spaces--;
1038 breaks[spaces].len--;
1039 }
818 } 1040 }
1041 else
1042 prefix_len = p - beg;
819 1043
820 /* if we wrapped at a space, don't display the space */ 1044 /* make a copy of the tail end of the string */
821 if (opt_wordwrap && wrapped && break_p && break_p != beg) 1045 p = xstrdup (p);
822 {
823 l--;
824 p++;
825 }
826 1046
827 last_wrapped = wrapped; 1047 /* and reduce the size of the head of the string */
1048 log->last->line = xrealloc (log->last->line, prefix_len + 1);
1049 log->last->len = prefix_len;
1050 log->last->line[prefix_len] = '\0';
1051
1052 /* note that the head was wrapped on it's right */
1053 log->last->wrapped_right = 1;
1054
1055 /* 'spaces' includes any space we broke on; we can only justify
1056 * if there's at least one other space */
1057 if (opt_justify && spaces &&
1058 width - effect_x_space - width_at_break_p < spaces * log->font_height)
1059 {
1060 int i;
1061 log->last->free_pixels = width - effect_x_space - w;
1062 log->last->num_words = spaces + 1;
1063 log->last->breaks = malloc (log->last->num_words * sizeof (struct breakinfo));
1064 for (i = 0; i < log->last->num_words; i++)
1065 log->last->breaks[i] = breaks[i];
1066 }
1067
1068 line = new_line_node (log);
1069 line->line = p;
1070 l = line->len = strlen (p);
1071
1072 /* note that the tail end of the string is wrapped at its left */
1073 line->wrapped_left = 1;
828 } 1074 }
829 while (l); 1075 while (l);
1076}
1077
1078static void
1079insert_new_line (char *str, struct logfile_entry *log)
1080{
1081 struct line_node *new;
1082 new = new_line_node (log);
1083 new->line = str;
1084 new->len = strlen (str);
1085
1086 possibly_split_long_line (log);
830} 1087}
831 1088
832/* 1089/*
833 * append something to an existing physical line. this is done 1090 * append something to an existing physical line. this is done
834 * by deleting the file on-screen, concatenating the new data to it 1091 * by deleting the file on-screen, concatenating the new data to it
835 * and splitting it again. 1092 * and splitting it again.
836 */ 1093 */
837static void 1094static void
838append_line (int idx, const char *str) 1095append_to_existing_line (char *str, struct logfile_entry *log)
839{ 1096{
840 unsigned long color = lines[idx].color; 1097 char *old, *new;
841 char *old = lines[idx].line; 1098
1099 assert(log);
1100 assert(log->last);
1101
1102 old = log->last->line;
1103 assert(old);
1104
842 char *new = concat_line (old, str); 1105 new = concat_line (old, str);
843
844 free (old); 1106 free (str);
845 1107 log->last->line = new;
846 delete_line (idx); 1108 log->last->len = strlen (new);
847 split_line (idx, new, color); 1109 possibly_split_long_line (log);
848} 1110}
849 1111
850static void 1112static void
851main_loop (void) 1113main_loop (void)
852{ 1114{
853 lines = xmalloc (sizeof (struct linematrix) * listlen);
854 display = xmalloc (sizeof (struct displaymatrix) * listlen);
855 int lin; 1115 int lin;
856 time_t lastreload; 1116 time_t lastreload;
857 Region region = XCreateRegion (); 1117 Region region = XCreateRegion ();
858 XEvent xev; 1118 XEvent xev;
859 struct logfile_entry *lastprinted = NULL; 1119 struct logfile_entry *lastprinted = NULL;
860 struct logfile_entry *current; 1120 struct logfile_entry *current;
861 int need_update = 1; 1121 int need_update = 1;
862 1122
1123 display = xmalloc (sizeof (struct displaymatrix) * listlen);
1124
863 lastreload = time (NULL); 1125 lastreload = time (NULL);
864 1126
865 /* Initialize linematrix */ 1127 /* Initialize line_node */
866 for (lin = 0; lin < listlen; lin++) 1128 for (lin = 0; lin < listlen; lin++)
867 { 1129 {
1130 struct line_node *e = xmalloc (sizeof (struct line_node));
868 lines[lin].line = xstrdup ("~"); 1131 e->line = xstrdup ("~");
869 lines[lin].len = 1; 1132 e->len = 1;
1133 e->logfile = loglist; /* this is only needed to get a color for the '~' */
1134 e->wrapped_left = 0;
1135 e->wrapped_right = 0;
1136 e->breaks = 0;
1137 e->next = NULL;
1138 e->prev = linelist_tail;
1139
1140 if (!linelist)
1141 linelist = e;
1142 if (linelist_tail)
1143 linelist_tail->next = e;
1144 linelist_tail = e;
1145
870 display[lin].line = xstrdup(""); 1146 display[lin].line = xstrdup ("");
871 display[lin].len = 0; 1147 display[lin].len = 0;
1148 display[lin].offset = 0;
872 display[lin].buffer_size = 0; 1149 display[lin].buffer_size = 0;
873 lines[lin].color = GetColor (def_color);
874 } 1150 }
875 1151
876 for (;;) 1152 for (;;)
877 { 1153 {
878 /* read logs */ 1154 /* read logs */
889 /* if we're trying to update old partial lines in 1165 /* if we're trying to update old partial lines in
890 * place, and the last time this file was updated the 1166 * place, and the last time this file was updated the
891 * output was partial, and that partial line is not 1167 * output was partial, and that partial line is not
892 * too close to the top of the screen, then update 1168 * too close to the top of the screen, then update
893 * that partial line */ 1169 * that partial line */
894 if (opt_update && current->lastpartial && current->index >= 0) 1170 if (opt_update && current->lastpartial && current->last)
895 { 1171 {
896 int idx = current->index;
897 append_line (idx, current->buf); 1172 append_to_existing_line (current->buf, current);
898 current->index = idx; 1173 current->buf = 0;
899 free (current->buf), current->buf = 0;
900 continue; 1174 continue;
901 } 1175 }
902 1176
1177 /* if all we just read was a newline ending a line that we've already displayed, skip it */
1178 if (current->buf[0] == '\0' && current->lastpartial)
1179 {
1180 free(current->buf);
1181 current->buf = 0;
1182 continue;
1183 }
1184
903 /* print filename if any, and if last line was from 1185 /* print filename if any, and if last line was from
904 * different file */ 1186 * different file */
905 if (!opt_nofilename && lastprinted != current && current->desc[0]) 1187 if (lastprinted != current)
906 { 1188 {
907 char buf[1024]; /* HACK-5 */ 1189 current->last = 0;
908 snprintf (buf, sizeof (buf), "[%s]", current->desc); 1190 if (!opt_nofilename && current->desc[0])
909 split_line (listlen - 1, buf, current->color); 1191 {
910 } 1192 insert_new_line (xstrdup ("["), current);
1193 append_to_existing_line (xstrdup (current->desc), current);
1194 append_to_existing_line (xstrdup ("]"), current);
1195 }
1196 }
911 1197
912 /* if we're dealing with partial lines, and the last 1198 /* if we're dealing with partial lines, and the last
913 * time we showed the line it wasn't finished ... */ 1199 * time we showed the line it wasn't finished ... */
914 if (!opt_whole && current->lastpartial) 1200 if (!opt_whole && current->lastpartial)
915 { 1201 {
916 /* if this is the same file we showed last then 1202 /* if this is the same file we showed last then
917 append to the last line shown */ 1203 append to the last line shown */
918 if (lastprinted == current) 1204 if (lastprinted == current)
919 append_line (listlen - 1, current->buf); 1205 append_to_existing_line (current->buf, current);
920 else 1206 else
921 { 1207 {
922 /* but if a different file has been shown in the 1208 /* but if a different file has been shown in the
923 * mean time, make a new line, starting with the 1209 * mean time, make a new line, starting with the
924 * continuation string */ 1210 * continuation string */
925 split_line (listlen - 1, continuation, current->color); 1211 insert_new_line (current->buf, current);
926 append_line (listlen - 1, current->buf); 1212 current->last->wrapped_left = 1;
927 } 1213 }
928 } 1214 }
929 else 1215 else
930 /* otherwise just make a plain and simple new line */ 1216 /* otherwise just make a plain and simple new line */
931 split_line (listlen - 1, current->buf, current->color); 1217 insert_new_line (current->buf, current);
932 1218
933 free (current->buf), current->buf = 0; 1219 current->buf = 0;
934 current->index = listlen - 1;
935 lastprinted = current; 1220 lastprinted = current;
936 } 1221 }
937 } 1222 }
938 1223
939 if (need_update) 1224 if (need_update)
1011 region = XCreateRegion (); 1296 region = XCreateRegion ();
1012 } 1297 }
1013 } 1298 }
1014} 1299}
1015 1300
1016
1017int 1301int
1018main (int argc, char *argv[]) 1302main (int argc, char *argv[])
1019{ 1303{
1020 int i; 1304 int i;
1021 int opt_daemonize = 0; 1305 int opt_daemonize = 0;
1023#if HAS_REGEX 1307#if HAS_REGEX
1024 char *transform = NULL; 1308 char *transform = NULL;
1025#endif 1309#endif
1026 1310
1027 setlocale (LC_CTYPE, ""); /* try to initialize the locale. */ 1311 setlocale (LC_CTYPE, ""); /* try to initialize the locale. */
1028
1029 /* window needs to be initialized before colorlookups can be done */
1030 /* just a dummy to get the color lookups right */
1031 geom_mask = NoValue;
1032 InitWindow ();
1033 1312
1034 for (i = 1; i < argc; i++) 1313 for (i = 1; i < argc; i++)
1035 { 1314 {
1036 const char *arg = argv[i]; 1315 const char *arg = argv[i];
1037 1316
1050 XParseGeometry (argv[++i], &win_x, &win_y, &width, &height); 1329 XParseGeometry (argv[++i], &win_x, &win_y, &width, &height);
1051 else if (!strcmp (arg, "-display")) 1330 else if (!strcmp (arg, "-display"))
1052 dispname = argv[++i]; 1331 dispname = argv[++i];
1053 else if (!strcmp (arg, "-cont")) 1332 else if (!strcmp (arg, "-cont"))
1054 continuation = argv[++i]; 1333 continuation = argv[++i];
1334 else if (!strcmp (arg, "-cont-color"))
1335 cont_color = argv[++i];
1055 else if (!strcmp (arg, "-font") || !strcmp (arg, "-fn")) 1336 else if (!strcmp (arg, "-font") || !strcmp (arg, "-fn"))
1056 fontname = argv[++i]; 1337 fontname = argv[++i];
1057#if HAS_REGEX 1338#if HAS_REGEX
1058 else if (!strcmp (arg, "-t")) 1339 else if (!strcmp (arg, "-t"))
1059 { 1340 {
1060 transform = argv[++i]; 1341 transform = argv[++i];
1061 transform_to = argv[++i]; 1342 transform_to = argv[++i];
1062 printf("transform: '%s' to '%s'\n", transform, transform_to); 1343 printf ("transform: '%s' to '%s'\n", transform, transform_to);
1063 } 1344 }
1064#endif 1345#endif
1065 else if (!strcmp (arg, "-fork") || !strcmp (arg, "-f")) 1346 else if (!strcmp (arg, "-fork") || !strcmp (arg, "-f"))
1066 opt_daemonize = 1; 1347 opt_daemonize = 1;
1067 else if (!strcmp (arg, "-reload")) 1348 else if (!strcmp (arg, "-reload"))
1068 { 1349 {
1069 reload = atoi (argv[++i]); 1350 reload = atoi (argv[++i]);
1070 command = argv[++i]; 1351 command = argv[++i];
1071 } 1352 }
1353 else if (!strcmp (arg, "-windowed"))
1354 opt_windowed = 1;
1072 else if (!strcmp (arg, "-shade")) 1355 else if (!strcmp (arg, "-shade"))
1073 opt_shade = 1; 1356 opt_shade = 1;
1074 else if (!strcmp (arg, "-outline")) 1357 else if (!strcmp (arg, "-outline"))
1075 opt_outline = 1; 1358 opt_outline = 1;
1359 else if (!strcmp (arg, "-minspace"))
1360 opt_minspace = 1;
1076 else if (!strcmp (arg, "-noflicker")) 1361 else if (!strcmp (arg, "-noflicker"))
1077 opt_noflicker = 1; 1362 opt_noflicker = 1;
1078 else if (!strcmp (arg, "-frame")) 1363 else if (!strcmp (arg, "-frame"))
1079 opt_frame = 1; 1364 opt_frame = 1;
1080 else if (!strcmp (arg, "-no-filename")) 1365 else if (!strcmp (arg, "-no-filename"))
1087 opt_partial = 1; 1372 opt_partial = 1;
1088 else if (!strcmp (arg, "-update")) 1373 else if (!strcmp (arg, "-update"))
1089 opt_update = opt_partial = 1; 1374 opt_update = opt_partial = 1;
1090 else if (!strcmp (arg, "-wordwrap")) 1375 else if (!strcmp (arg, "-wordwrap"))
1091 opt_wordwrap = 1; 1376 opt_wordwrap = 1;
1377 else if (!strcmp (arg, "-justify"))
1378 opt_justify = 1;
1092 else if (!strcmp (arg, "-color")) 1379 else if (!strcmp (arg, "-color"))
1093 def_color = argv[++i]; 1380 def_color = argv[++i];
1094 else if (!strcmp (arg, "-noinitial")) 1381 else if (!strcmp (arg, "-noinitial"))
1095 opt_noinitial = 1; 1382 opt_noinitial = 1;
1096 else if (!strcmp (arg, "-id")) 1383 else if (!strcmp (arg, "-id"))
1097 root = atoi (argv[++i]); 1384 {
1385 unsigned long id;
1386
1387 if (sscanf (argv[++i], "%li", &id) == 1 && id)
1388 root = id;
1389 }
1098 else if (!strcmp (arg, "-interval") || !strcmp (arg, "-i")) 1390 else if (!strcmp (arg, "-interval") || !strcmp (arg, "-i"))
1099 { 1391 {
1100 double iv = atof (argv[++i]); 1392 double iv = atof (argv[++i]);
1101 1393
1102 interval.tv_sec = (int) iv; 1394 interval.tv_sec = (int) iv;
1132 } 1424 }
1133 1425
1134 e = xmalloc (sizeof (struct logfile_entry)); 1426 e = xmalloc (sizeof (struct logfile_entry));
1135 e->partial = 0; 1427 e->partial = 0;
1136 e->buf = 0; 1428 e->buf = 0;
1137 e->index = -1;
1138 1429
1139 if (arg[0] == '-' && arg[1] == '\0') 1430 if (arg[0] == '-' && arg[1] == '\0')
1140 { 1431 {
1141 if ((e->fp = fdopen (0, "r")) == NULL) 1432 if ((e->fp = fdopen (0, "r")) == NULL)
1142 perror ("fdopen"), exit (1); 1433 perror ("fdopen"), exit (1);
1143 if (fcntl (0, F_SETFL, O_NONBLOCK) < 0) 1434 if (fcntl (0, F_SETFL, O_NONBLOCK) < 0)
1144 perror ("fcntl"), exit (1); 1435 perror ("fcntl"), exit (1);
1145 1436
1146 e->fname = NULL; 1437 e->fname = NULL;
1147 e->inode = 0; 1438 e->inode = 0;
1439 if (desc == arg)
1148 e->desc = xstrdup ("stdin"); 1440 e->desc = xstrdup ("stdin");
1441 else
1442 e->desc = xstrdup (desc);
1149 } 1443 }
1150 else 1444 else
1151 { 1445 {
1152 e->fname = xstrdup (fname); 1446 e->fname = xstrdup (fname);
1153 1447
1155 perror (fname), exit (1); 1449 perror (fname), exit (1);
1156 1450
1157 e->desc = xstrdup (desc); 1451 e->desc = xstrdup (desc);
1158 } 1452 }
1159 1453
1160 e->color = GetColor (fcolor); 1454 e->colorname = fcolor;
1161 e->partial = 0; 1455 e->partial = 0;
1456 e->fontname = fontname;
1457 e->last = NULL;
1162 e->next = NULL; 1458 e->next = NULL;
1163 1459
1164 if (!loglist) 1460 if (!loglist)
1165 loglist = e; 1461 loglist = e;
1166 if (loglist_tail) 1462 if (loglist_tail)
1175 fprintf (stderr, "You did not specify any files to tail\n" 1471 fprintf (stderr, "You did not specify any files to tail\n"
1176 "use %s --help for help\n", argv[0]); 1472 "use %s --help for help\n", argv[0]);
1177 exit (1); 1473 exit (1);
1178 } 1474 }
1179 1475
1476 if (opt_update && opt_whole)
1477 {
1478 fprintf (stderr, "Specify at most one of -update and -whole\n");
1479 exit (1);
1480 }
1180 if (opt_partial && opt_whole) 1481 else if (opt_partial && opt_whole)
1181 { 1482 {
1182 fprintf (stderr, "Specify at most one of -partial and -whole\n"); 1483 fprintf (stderr, "Specify at most one of -partial and -whole\n");
1183 exit (1); 1484 exit (1);
1184 } 1485 }
1486
1487 /* it doesn't make sense to justify if word wrap isn't on */
1488 if (opt_justify)
1489 opt_wordwrap = 1;
1185 1490
1186 /* HACK-7: do we want to allow both -shade and -outline? */ 1491 /* HACK-7: do we want to allow both -shade and -outline? */
1187 if (opt_shade && opt_outline) 1492 if (opt_shade && opt_outline)
1188 { 1493 {
1189 fprintf (stderr, "Specify at most one of -shade and -outline\n"); 1494 fprintf (stderr, "Specify at most one of -shade and -outline\n");
1200#if HAS_REGEX 1505#if HAS_REGEX
1201 if (transform) 1506 if (transform)
1202 { 1507 {
1203 int i; 1508 int i;
1204 1509
1205 printf("compiling regexp '%s'\n", transform); 1510 printf ("compiling regexp '%s'\n", transform);
1206 transformre = xmalloc (sizeof (regex_t)); 1511 transformre = xmalloc (sizeof (regex_t));
1207 i = regcomp (transformre, transform, REG_EXTENDED); 1512 i = regcomp (transformre, transform, REG_EXTENDED);
1208 if (i != 0) 1513 if (i != 0)
1209 { 1514 {
1210 char buf[512]; 1515 char buf[512];
1211 1516
1212 regerror (i, transformre, buf, sizeof (buf)); 1517 regerror (i, transformre, buf, sizeof (buf));
1213 fprintf (stderr, "Cannot compile regular expression: %s\n", buf); 1518 fprintf (stderr, "Cannot compile regular expression: %s\n", buf);
1214 } 1519 }
1215 else 1520 else
1216 {
1217 printf("compiled '%s' OK to %x\n", transform, (int)transformre); 1521 printf ("compiled '%s' OK to %x\n", transform, (int)transformre);
1218 }
1219 } 1522 }
1220#endif 1523#endif
1524
1525 if (opt_outline && !opt_minspace)
1526 {
1527 /* adding outline increases the total width and height by 2
1528 pixels each, and offsets the text one pixel right and one
1529 pixel down */
1530 effect_x_space = effect_y_space = 2;
1531 effect_x_offset = effect_y_offset = 1;
1532 }
1533 else if (opt_shade && !opt_minspace)
1534 {
1535 /* adding a shadow increases the space used */
1536 effect_x_space = abs (SHADE_X);
1537 effect_y_space = abs (SHADE_Y);
1538
1539 /* if the shadow is to the right and below then we don't need
1540 * to move the text to make space for it, but shadows to the left
1541 * and above need accomodating */
1542 effect_x_offset = SHADE_X > 0 ? 0 : -SHADE_X;
1543 effect_y_offset = SHADE_Y > 0 ? 0 : -SHADE_Y;
1544 }
1545 else
1546 {
1547 effect_x_space = effect_y_space = 0;
1548 effect_x_offset = effect_y_offset = 0;
1549 }
1221 1550
1222 InitWindow (); 1551 InitWindow ();
1223 1552
1224 install_signal (SIGINT, blank_window); 1553 install_signal (SIGINT, blank_window);
1225 install_signal (SIGQUIT, blank_window); 1554 install_signal (SIGQUIT, blank_window);
1234 main_loop (); 1563 main_loop ();
1235 1564
1236 exit (1); /* to make gcc -Wall stop complaining */ 1565 exit (1); /* to make gcc -Wall stop complaining */
1237} 1566}
1238 1567
1239void 1568static void
1240install_signal (int sig, void (*handler) (int)) 1569install_signal (int sig, void (*handler) (int))
1241{ 1570{
1242 struct sigaction action; 1571 struct sigaction action;
1243 1572
1244 action.sa_handler = handler; 1573 action.sa_handler = handler;
1245 sigemptyset (&action.sa_mask); 1574 sigemptyset (&action.sa_mask);
1246 action.sa_flags = SA_RESTART; 1575 action.sa_flags = SA_RESTART;
1247 1576
1248 if (sigaction (sig, &action, NULL) < 0) 1577 if (sigaction (sig, &action, NULL) < 0)
1249 fprintf (stderr, "sigaction(%d): %s\n", sig, strerror (errno)), exit (1); 1578 fprintf (stderr, "sigaction (%d): %s\n", sig, strerror (errno)), exit (1);
1250} 1579}
1251 1580
1252void * 1581static void *
1253xstrdup (const char *string) 1582xstrdup (const char *string)
1254{ 1583{
1255 void *p; 1584 void *p;
1256 1585
1257 while ((p = strdup (string)) == NULL) 1586 while ((p = strdup (string)) == NULL)
1258 { 1587 {
1259 fprintf (stderr, "Memory exausted."); 1588 fprintf (stderr, "Memory exhausted in xstrdup ().\n");
1260 sleep (10); 1589 sleep (10);
1261 } 1590 }
1262 1591
1263 return p; 1592 return p;
1264} 1593}
1265 1594
1266void * 1595static void *
1267xmalloc (size_t size) 1596xmalloc (size_t size)
1268{ 1597{
1269 void *p; 1598 void *p;
1270 1599
1271 while ((p = malloc (size)) == NULL) 1600 while ((p = malloc (size)) == NULL)
1272 { 1601 {
1273 fprintf (stderr, "Memory exausted."); 1602 fprintf (stderr, "Memory exhausted in xmalloc ().\n");
1274 sleep (10); 1603 sleep (10);
1275 } 1604 }
1276 1605
1277 return p; 1606 return p;
1278} 1607}
1279 1608
1280void * 1609static void *
1281xrealloc (void *ptr, size_t size) 1610xrealloc (void *ptr, size_t size)
1282{ 1611{
1283 void *p; 1612 void *p;
1284 1613
1285 while ((p = realloc (ptr, size)) == NULL) 1614 while ((p = realloc (ptr, size)) == NULL)
1286 { 1615 {
1287 fprintf (stderr, "Memory exausted."); 1616 fprintf (stderr, "Memory exhausted in xrealloc ().\n");
1288 sleep (10); 1617 sleep (10);
1289 } 1618 }
1290 1619
1291 return p; 1620 return p;
1292} 1621}
1293 1622
1294void 1623static void
1295display_help (char *myname) 1624display_help (char *myname)
1296{ 1625{
1297 printf ("Usage: %s [options] file1[,color[,desc]] " 1626 printf ("Usage: %s [options] file1[,color[,desc]]"
1298 "[file2[,color[,desc]] ...]\n", myname); 1627 "[options] [file2[,color[,desc]] ...]\n", myname);
1299 printf (" -g | -geometry geometry -g WIDTHxHEIGHT+X+Y\n" 1628 printf (" -g | -geometry geometry -g WIDTHxHEIGHT+X+Y\n"
1300 " -color color use color $color as default\n" 1629 " -color color use color $color as default\n"
1301 " -reload sec command reload after $sec and run command\n" 1630 " -reload sec command reload after $sec and run command\n"
1302 " -id id window id to use instead of the root window\n" 1631 " -id id window id to use instead of the root window\n"
1632 " -windowed create a window instead of writing to the root\n"
1303 " -font FONTSPEC (-fn) font to use\n" 1633 " -font FONTSPEC (-fn) font to use\n"
1304 " -f | -fork fork into background\n" 1634 " -f | -fork fork into background\n"
1305 " -reverse print new lines at the top\n" 1635 " -reverse print new lines at the top\n"
1306 " -whole wait for \\n before showing a line\n" 1636 " -whole wait for \\n before showing a line\n"
1307 " -partial show lines even if they don't end with a \\n\n" 1637 " -partial show lines even if they don't end with a \\n\n"
1308 " -update allow updates to old partial lines\n" 1638 " -update allow updates to old partial lines\n"
1309 " -cont string to prefix continued partial lines with\n" 1639 " -cont string to prefix continued partial lines with\n"
1640 " defaults to \"|| \"\n"
1310 " -wordwrap wrap long lines at spaces to avoid breaking words\n" 1641 " -wordwrap wrap long lines at spaces to avoid breaking words\n"
1311 " defaults to \"[+]\"\n"
1312 " -shade add shading to font\n" 1642 " -shade add shading to font\n"
1643 " -outline add black outline to font\n"
1644 " -minspace force minimum line spacing\n"
1313 " -noinitial don't display the last file lines on\n" 1645 " -noinitial don't display the last file lines on\n"
1314 " startup\n" 1646 " startup\n"
1315 " -i | -interval seconds interval between checks (fractional\n" 1647 " -i | -interval seconds interval between checks (fractional\n"
1316 " values o.k.). Default 2.4 seconds\n" 1648 " values o.k.). Default 2.4 seconds\n"
1317 " -V display version information and exit\n" 1649 " -V display version information and exit\n"
1318 "\n"); 1650 "\n");
1319 printf ("Example:\n%s -g 80x25+100+50 -font fixed /var/log/messages,green " 1651 printf ("Example:\n%s -g 800x250+100+50 -font fixed /var/log/messages,green "
1320 "/var/log/secure,red,'ALERT'\n", myname); 1652 "/var/log/secure,red,'ALERT'\n", myname);
1321 exit (0); 1653 exit (0);
1322} 1654}
1323 1655
1324void 1656static void
1325display_version (void) 1657display_version (void)
1326{ 1658{
1327 printf ("root-tail version " VERSION "\n"); 1659 printf ("root-tail version " VERSION "\n");
1328 exit (0); 1660 exit (0);
1329} 1661}
1330 1662
1331int 1663static int
1332daemonize (void) 1664daemonize (void)
1333{ 1665{
1334 pid_t pid; 1666 pid_t pid;
1335 1667
1336 switch (pid = fork ()) 1668 switch (pid = fork ())
1338 case -1: 1670 case -1:
1339 return -1; 1671 return -1;
1340 case 0: 1672 case 0:
1341 break; 1673 break;
1342 default: 1674 default:
1343 /*printf("%d\n", pid);*/ 1675 /*printf ("%d\n", pid);*/
1344 exit (0); 1676 exit (0);
1345 } 1677 }
1346 1678
1347 if (setsid () == -1) 1679 if (setsid () == -1)
1348 return -1; 1680 return -1;
1349 1681
1350 return 0; 1682 return 0;
1351} 1683}
1684

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines