1 #ifndef __MT_H__ 2 #define __MT_H__ 3 4 #define _LARGEFILE64_SOURCE /* required for GLIBC to enable stat64 and friends */ 5 #include <regex.h> 6 #include <stdint.h> 7 #include <stdio.h> 8 #include <arpa/inet.h> 9 #include <sys/socket.h> 10 #include <sys/types.h> 11 12 #define WAIT_FOR_FILE_DELAY (250) /* sleep when waiting for a file to become available */ 13 #define MAX_N_RE_MATCHES (80) /* max. number of regex matches: used for coloring matches */ 14 #define MIN_N_BUFFERLINES (100) /* number of lines to buffer at minimum */ 15 #define MAX_N_SPAWNED_PROCESSES (16) /* max. nr. of processes executed by matching regexps */ 16 #define MAX_N_COLUMNS (15) /* max number of columns */ 17 #define DEFAULT_TAB_WIDTH (4) 18 #define DEFAULT_COLORPAIRS (8) 19 #define MAX_BACKTRACE_LENGTH (256) 20 #define SCRIPT_IO_BUFFER_SIZE (4096) 21 #define CONFIG_READ_BUFFER (4096) 22 #define HISTORY_IO_BUFFER (4096) 23 #define TIMESTAMP_EXTEND_BUFFER (1024) 24 25 #define SL_REGULAR (1) 26 #define SL_NONE (0) 27 #define SL_ATTR (2) 28 29 #define LOADAVG_STR_LEN (20) 30 #define AMOUNT_STR_LEN (3 + 2 + 1) 31 32 #ifndef __GNUC__ 33 #define __PRETTY_FUNCTION__ "(unknown)" 34 #define USE_IF_SET(x, y) ((x)?(x):(y)) 35 #else 36 #define USE_IF_SET(x, y) ((x)?:(y)) 37 #endif 38 39 typedef enum { MY_FALSE = 0, MY_TRUE = 1 } mybool_t; 40 41 typedef enum { VAL_ZERO_POSITIVE = 1, VAL_POSITIVE_NOT_1, VAL_POSITIVE } valcheck_t; 42 43 #define M_KB (1024) 44 #define M_MB (M_KB * 1024) 45 #define M_GB (M_MB * 1024) 46 47 typedef enum { BEEP_FLASH = 1, BEEP_BEEP, BEEP_POPUP, BEEP_NONE } beeb_t; 48 49 typedef enum { LINE_LEFT = 1, LINE_RIGHT, LINE_TOP, LINE_BOTTOM } linepos_t; 50 51 typedef enum { TERM_IGNORE = 0, TERM_XTERM, TERM_ANSI /* or vt100 */} term_t; 52 53 typedef enum { SCHEME_TYPE_EDIT = 0, SCHEME_TYPE_FILTER } filter_edit_scheme_t; 54 55 #ifndef _BSD_SOURCE 56 #define _BSD_SOURCE /* don't worry: it'll still work if you don't have a BSD system */ 57 #endif 58 #ifndef __USE_BSD 59 #define __USE_BSD /* manpage says _BSD_SOURCE, stdlib.h says __USE_BSD */ 60 #endif 61 62 #if defined(UTF8_SUPPORT) && !defined(__APPLE__) 63 #if defined(__FreeBSD__) 64 #include <panel.h> 65 #include <curses.h> 66 #else 67 #include <ncursesw/panel.h> 68 #include <ncursesw/ncurses.h> 69 #endif 70 #else 71 #if defined(__APPLE__) 72 #include <ncurses.h> 73 #include <panel.h> 74 #elif defined(sun) || defined(__sun) || defined(scoos) || defined(_HPUX_SOURCE) || defined(AIX) || defined(__CYGWIN__) 75 #include <ncurses/panel.h> 76 #include <ncurses/ncurses.h> 77 #else 78 #include <panel.h> 79 #include <ncurses.h> 80 #endif 81 #endif 82 83 /* it seems the default HP-UX c-compiler doesn't understand atoll and 84 * strtoll while it does understand 'long long' 85 */ 86 #if defined(_HPUX_SOURCE) || defined(__APPLE__) 87 #ifndef atoll 88 #define atoll(x) atol(x) 89 #endif 90 #endif 91 92 #ifndef strtoll 93 #define strtoll(x, y, z) strtol(x, y, z) 94 #endif 95 #ifndef atoll 96 #define atoll(a) strtoll((a), (char **)NULL, 10) 97 #endif 98 99 /* Tru64 workaround */ 100 #if defined(OSF1) 101 #undef getmaxyx 102 #define getmaxyx(w,y,x) y = w->_maxy; x = w->_maxx 103 #endif 104 105 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__minix) 106 #define off64_t off_t 107 #define stat64 stat 108 #define open64 open 109 #endif 110 111 #define MARKER_REGULAR (NULL) 112 #define MARKER_CHANGE ((proginfo *)-1) 113 #define MARKER_IDLE ((proginfo *)-2) 114 #define MARKER_MSG ((proginfo *)-3) 115 #define IS_MARKERLINE(x) ((x) == MARKER_REGULAR || (x) == MARKER_CHANGE || (x) == MARKER_IDLE || (x) == MARKER_MSG) 116 117 typedef enum { SEL_WIN = 1, SEL_SUBWIN, SEL_FILES, SEL_CSCHEME, SEL_HISTORY } selbox_type_t; 118 119 typedef enum { TT_ATIME = 1, TT_MTIME, TT_CTIME } time_field_t; 120 121 typedef double dtime_t; 122 123 typedef struct 124 { 125 char *history_file; 126 int history_size; 127 128 char **history; 129 } history_t; 130 131 typedef struct 132 { 133 int *elements; 134 int n; 135 int size; 136 } int_array_t; 137 138 typedef struct 139 { 140 char *glob_str; 141 int check_interval; 142 dtime_t last_check; 143 time_field_t new_only; 144 const char *color_scheme; 145 146 char in_one_window; 147 int window_nr; /* if 'in_one_window' is set, merge into the window 'window_nr' */ 148 } check_dir_glob; 149 150 typedef struct 151 { 152 WINDOW *win; 153 PANEL *pwin; 154 155 int x_off, y_off; 156 int width, height; 157 158 } NEWWIN; 159 160 typedef struct 161 { 162 char *regex_str; 163 regex_t regex; 164 char invert_regex; 165 char use_regex; 166 167 int match_count; 168 169 /* command to run if matches */ 170 char *cmd; 171 } re; 172 173 typedef struct 174 { 175 char *fs_name; 176 char *fs_desc; 177 int n_re; 178 re *pre; 179 } filterscheme; 180 181 typedef enum { STRIP_TYPE_REGEXP = 1, STRIP_TYPE_RANGE, STRIP_TYPE_COLUMN, STRIP_KEEP_SUBSTR } striptype_t; 182 183 typedef struct 184 { 185 striptype_t type; 186 187 regex_t regex; 188 char *regex_str; 189 190 int start, end; 191 192 int col_nr; 193 char *del; 194 195 int match_count; 196 } strip_t; 197 198 typedef struct 199 { 200 char *es_name; 201 char *es_desc; 202 203 int n_strips; 204 strip_t *strips; 205 } editscheme; 206 207 #define MAX_COLORS_PER_LINE (80) 208 209 typedef struct 210 { 211 int *fg_color; 212 int *bg_color; 213 int size; /* COLOR_PAIRS */ 214 int n_def; /* n defined, at least 1 as color_pair(0) is the default 215 * terminal colors (white on black mostly) which also 216 * cannot be changed 217 */ 218 } colorpairs; 219 220 typedef struct 221 { 222 int colorpair_index; 223 int attrs; 224 } myattr_t; 225 226 typedef enum { REDIRECTTO_NONE = 0, REDIRECTTO_PIPE_FILTERED = 1, REDIRECTTO_PIPE, REDIRECTTO_FILE_FILTERED, REDIRECTTO_FILE, REDIRECTTO_SOCKET_FILTERED, REDIRECTTO_SOCKET } redirecttype_t; 227 228 typedef struct { 229 char *redirect; 230 redirecttype_t type; 231 int fd; 232 pid_t pid; 233 struct sockaddr_in sai; 234 int prio_fac; 235 } redirect_t; 236 237 typedef struct 238 { 239 dtime_t lastevent; 240 double prev_deltat, total_deltat; 241 double med; 242 double dev; 243 char sccfirst; 244 double scc, sccu0, scclast, scct1, scct2, scct3; 245 int n_events; 246 247 dtime_t start_ts; 248 long long int bytes_processed; 249 } statistics_t; 250 251 typedef struct 252 { 253 char colorize; 254 char field_nr; 255 char *field_del; 256 int_array_t color_schemes; 257 myattr_t attributes; 258 char alt_col; 259 myattr_t alt_col_cdev1, alt_col_cdev2; 260 char syslog_noreverse; 261 262 term_t term_emul; 263 } cdef_t; 264 265 typedef struct 266 { 267 char **bcur, **bprev; 268 int ncur, nprev; 269 } diff_t; 270 271 typedef struct 272 { 273 int restart; 274 char restart_clear; /* clear after each iteration? */ 275 char is_restarted; 276 char first; 277 char do_diff; 278 diff_t diff; 279 } restart_t; 280 281 typedef struct 282 { 283 char suppress_repeating_lines; 284 char *last_line; 285 int n_times_repeated; 286 } repeatinglines_t; 287 288 typedef enum { WT_FILE=1, WT_COMMAND, WT_STDIN, WT_SOCKET } windowtype_t; 289 290 typedef struct _subwindow_ 291 { 292 char *filename; 293 windowtype_t wt; 294 int last_exit_rc; 295 int n_runs; 296 int check_interval; 297 int fd; /* read */ 298 int wfd; /* write */ 299 pid_t pid; 300 301 int n_redirect; 302 redirect_t *predir; 303 304 off64_t last_size; 305 306 char cont; /* "re-connect" lines with \ at the end */ 307 308 char add_timestamp; 309 310 char *label; /* put in front of each line */ 311 312 int_array_t conversions; 313 314 char paused; 315 char closed; 316 317 char *incomplete_line; 318 319 char *win_title; 320 321 char line_wrap; 322 int line_wrap_offset; 323 324 int win_height; 325 326 /* repeatingly start a program */ 327 restart_t restart; 328 329 int initial_n_lines_tail; 330 331 int mark_interval; 332 333 repeatinglines_t repeat; 334 335 cdef_t cdef; 336 337 char hidden; 338 char follow_filename; 339 char retry_open; 340 341 int close_idle; 342 343 statistics_t statistics; 344 345 struct 346 { 347 int beep_interval; 348 int linecounter_for_beep; 349 int did_n_beeps; 350 } beep; 351 352 NEWWIN *status; 353 NEWWIN *data; 354 355 int n_re; 356 re *pre; 357 358 int n_strip; 359 strip_t *pstrip; 360 361 struct _subwindow_ *next; 362 } proginfo; 363 364 typedef struct 365 { 366 char *Bline; 367 proginfo *pi; 368 double ts; 369 } buffered_entry; 370 371 typedef struct 372 { 373 buffered_entry *be; 374 int curpos; 375 char bufferwhat; 376 int maxnlines; 377 int maxbytes, curbytes; 378 379 proginfo *last_win; 380 char marker_of_other_window; 381 } buffer; 382 383 typedef enum { 384 CSREFLAG_SUB = 1, /* substring matching */ 385 CSREFLAG_CMP_VAL_LESS, /* compare with value: value less then what is configured? */ 386 CSREFLAG_CMP_VAL_BIGGER, /* compare with value: value higher then what is configured? */ 387 CSREFLAG_CMP_VAL_EQUAL /* compare with value: value equal to what is configured? */ 388 } csreflag_t; 389 390 typedef struct 391 { 392 char *script; 393 pid_t pid; 394 int fd_r, fd_w; 395 } script; 396 397 typedef struct 398 { 399 myattr_t attrs1; 400 myattr_t attrs2; 401 mybool_t use_alternating_colors; 402 int ac_index; 403 } cse_main; 404 405 typedef struct 406 { 407 cse_main cdef; 408 409 regex_t regex; 410 csreflag_t flags; 411 double cmp_value; 412 413 mybool_t merge_color; 414 415 } color_scheme_entry; 416 417 typedef struct 418 { 419 char *name; 420 char *descr; 421 422 script color_script; 423 424 int n; 425 color_scheme_entry *pentries; 426 } color_scheme; 427 428 typedef enum { CONVTYPE_IP4TOHOST = 1, CONVTYPE_EPOCHTODATE, CONVTYPE_ERRNO, CONVTYPE_HEXTODEC, CONVTYPE_DECTOHEX, CONVTYPE_TAI64NTODATE, CONVTYPE_SCRIPT, CONVTYPE_ABBRTOK, CONVTYPE_SIGNRTOSTRING } conversion_t; 429 typedef struct 430 { 431 conversion_t type; 432 regex_t regex; 433 int match_count; 434 } conversion_bundle_t; 435 typedef struct 436 { 437 char *name; 438 439 int n; 440 conversion_bundle_t *pcb; 441 442 /* conversion script */ 443 script *pcs; 444 } conversion; 445 446 typedef enum { SCHEME_CONVERSION = 1, SCHEME_COLOR } scheme_t; 447 448 typedef struct cv_off 449 { 450 int start, end; 451 char *newstr; 452 } cv_off; 453 454 typedef struct 455 { 456 int n_colorschemes; 457 char **colorschemes; 458 459 int buffer_maxnlines; 460 int buffer_bytes; 461 462 char change_win_marker; 463 464 regex_t regex; 465 char *re_str; 466 467 int_array_t filterschemes; 468 469 int_array_t editschemes; 470 471 int n_conversion_schemes; 472 char **conversion_schemes; 473 } pars_per_file; 474 475 typedef struct 476 { 477 regoff_t start; 478 regoff_t end; 479 480 myattr_t attrs; 481 mybool_t merge_color; 482 } color_offset_in_line; 483 484 typedef struct 485 { 486 char key; 487 char *command; 488 } keybinding; 489 490 void do_exit(void); 491 char * select_file(char *input, int what_help); 492 char check_no_suppress_lines_filter(proginfo *cur); 493 void color_print(int f_index, NEWWIN *win, proginfo *cur, char *string, regmatch_t *matches, int matching_regex, mybool_t force_to_winwidth, int start_at_offset, int end_at_offset, double ts, char show_window_nr); 494 int select_window(int what_help, char *heading); 495 char check_filter(proginfo *cur, char *string, regmatch_t **pmatch, char **error, int *matching_regex, char do_re, char *display); 496 int wait_for_keypress(int what_help, double max_wait, NEWWIN *popup, char shift_cursor); 497 int toggle_colors(void); 498 void regexp_error_popup(int rc, regex_t *pre); 499 void redraw_statuslines(void); 500 void buffer_replace_pi_pointers(int f_index, proginfo *org, proginfo *new); 501 char delete_entry(int f_index, proginfo *sub); 502 char * key_to_keybinding(char what); 503 void do_buffer(int f_index, proginfo *cur, char *string, char filter_match, double now); 504 void do_print(int f_index, proginfo *cur, char *string, regmatch_t *matches, int matching_regex, double ts); 505 void do_set_bufferstart(int f_index, char store_what_lines, int maxnlines); 506 void emit_myattr_t(FILE *fh, myattr_t what); 507 void update_statusline(NEWWIN *status, int win_nr, proginfo *cur); 508 void write_escape_str(FILE *fh, char *string); 509 void check_proc_sigh(int sig); 510 void info(void); 511 void statistics(void); 512 int emit_to_buffer_and_term(int f_index, proginfo *cur, char *line); 513 void add_pars_per_file(char *re, char *colorscheme, int n_buffer_lines, int buffer_bytes, char change_win_marker, int fs, int es, char *conversion_scheme); 514 void version(void); 515 void usage(void); 516 void create_new_win(proginfo **cur, int *nr); 517 void delete_be_in_buffer(buffer *pb); 518 void do_restart_window(proginfo *cur); 519 520 void LOG(char *str, ...); 521 522 #endif 523