1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
|
#define _LARGEFILE64_SOURCE /* required for GLIBC to enable stat64 and friends */
#include <sys/types.h>
#include <regex.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <limits.h>
#include <errno.h>
#include "mt.h"
#include "mem.h"
#include "error.h"
#include "color.h"
#include "term.h"
#include "utils.h"
#include "config.h"
#include "globals.h"
void usage(void)
{
printf("%s", version_str);
printf("\n\nmultitail [-cs|-Cs|-c-] [-i] inputfile [-i anotherinputfile] [...]\n");
printf("-l parameter is a command to be executed\n");
printf("-L see -l but add to the previous window\n");
printf("-j read from stdin (can be used (of course) only once)\n");
printf("-r interval restart the command when it exited after `interval' seconds\n");
printf("-R interval same as -r, only with this one only the difference is displayed\n");
printf("-Rc/-rc interval like -r/-R but clean the window before each iteration\n");
printf("-i the following parameter is a filename (in case it starts with a dash)\n");
printf("--cont reconnect lines with a '\' at the end\n");
printf("--mergeall merge all of the following files into the same window\n");
printf("--no-mergeall stop merging all files into one window\n");
printf("--no-repeat suppress repeating lines and replace them with a \"last message repeated x times\"\n");
printf("--mark-interval x\n");
printf(" when nothing comes in, print a '---mark---' line every 'x' seconds\n");
printf("--mark-change\n");
printf(" when multiple files are merged an multitail switches between two windows, print a markerline with the filename\n");
printf("--no-mark-change\n");
printf(" do NOT print the markerline when the file changes (overrides the configfile)\n");
printf("-n x initial number of lines to tail\n");
printf("-m x set scrollback buffer size (# lines)\n");
printf("-mb x set scrollback buffer size (in bytes, use xKB/MB/GB)\n");
printf("-bw a/f what to buffer: 'a'll or what went through the 'f'ilter\n");
printf("-I see -i but add to the previous window\n");
printf("-a x like 'tee': write (filtered) input to file 'x'\n");
printf("-A x see -a: but write the unfiltered(!) input to file 'x'\n");
printf("-g x redirect the input also (filtered) to command/process 'x'\n");
printf("-G x redirect the unfiltered input also to command/process 'x'\n");
printf("-q i path path for new files with interval 'i', all in new windows\n");
printf("-Q i path path for new files with interval 'i', all in the same (sub-)window\n");
printf("--closeidle x close windows when more then 'x' seconds no new data was processed\n");
printf("--new-only (for -q/-Q) only create windows for files created after multitail was started\n");
printf("-s x vertical split screen (in 'x' columns)\n");
printf("-sw x,x,... at what columns to split the screen, use '0' for automatic size\n");
printf("-sn x,x,... number of windows per column\n");
printf("-wh x height of window\n");
printf("-S prepend merged output with subwindow-number\n");
printf("-f follow the following filename, not the descriptor\n");
printf("--retry keep trying to open the following file if it is inaccessible\n");
printf("--retry-all like --retry but for all following files\n");
printf("-fr scheme use the predefined filter from the configfile\n");
printf("-e[m] print only when matching with this regexp\n");
printf("-ev print only when NOT matching with this regexp\n");
printf("-ec use regular expression but display the matches inverted on following file\n");
printf("-eC use regexp, display everything but matches inverted on following file\n");
printf("-ex execute command ('-ex regexp command') when matches\n");
printf("-E use regular expression on following files\n");
printf("-Ec use regular expression but display the matches inverted on following files\n");
printf("-EC use regexp, display everything but matches inverted on following files\n");
printf("-ke x strip parts of the input using regular expression 'x'\n");
printf("-kr x y strip parts of the input starting at offset x and ending (not including!) offset y\n");
printf("-kc x y strip parts of the input: strip column 'y' with delimiter 'x'\n");
printf("-v invert next regular expression (do not use with -ev/em)\n");
printf("-cv x use conversion scheme 'x' (see multitail.conf)\n");
printf("-c colorize current\n");
printf("-cS scheme\n");
printf(" use colorscheme 'scheme' (as defined in multitail.conf)\n");
printf("-csn extra switch for the following switches; do not use reverse (inverted) colors\n");
printf("-Cs colorize all following files with syslog-scheme\n");
printf("-C colorize all following files\n");
printf("-Cf/-cf field delimiter\n");
printf(" colorize next/all file(s) depending on the given field number. fields\n");
printf(" are delimited with the given field-delimiter\n");
printf("-ci color use 'color' (red, green, etc), usefull when merging multiple inputs\n");
printf("-c- do NOT colorize the following file\n");
printf("-C- do NOT colorize the following files\n");
printf("-cT term");
printf(" interpret terminal-codes from file/command (for terminal type 'term')\n");
printf("-Z color set color for markerline\n");
printf("-ts add a timestamp (format configurable in multitail.conf) before each line\n");
printf("-T put a timestamp in markerlines\n");
printf("-d do NOT update the status-line\n");
printf("-D do not display a status-line at all\n");
printf("-du put the statusline above the data window\n");
printf("-z do not \"window closed\" windows\n");
printf("-w do not use colors\n");
printf("-u set update interval (for slow links)\n");
printf("-p x [y]\n");
printf(" set linewrap (l=left/a=all/r=right/s=syslog,S=syslog w/o procname, o=offset -> 'y')\n");
printf("-P like -p but for all following files\n");
printf("-b n set TAB-width\n");
printf("--basename only display the filename (and not the path) in the statusline\n");
printf("-x str switch on the xtermtitlebar stuff\n");
printf("-F file use 'file' as configfile (instead of " CONFIG_FILE ")\n");
printf("--no-load-global-config do not read " CONFIG_FILE "\n");
printf("-o configfileparameter do a setting which would normally be set in the configfile\n");
printf("-H x show heartbeat (to keep your sessions alive)\n");
printf("-h this help\n");
printf("\n");
printf("You can have multiple regular expressions per file/command. Be warned: if\n");
printf("you define multiple and one of them is specified with '-E' (=for every\n");
printf("following file), _all_ of the current regular expressions are for all\n");
printf("following files!\n");
printf("\n");
printf("%s\n", F1);
}
int get_value_arg(char *par, char *string, valcheck_t check)
{
long int result;
int len, loop;
int multiplier = 1;
if (!string)
error_exit("%s needs a parameter\n", par);
len = strlen(string);
for(loop=0; loop<len; loop++)
{
if (!isdigit(string[loop]))
{
char dummy = toupper(string[loop]);
if (toupper(string[loop + 1]) == 'B' && (dummy == 'K' || dummy == 'M' || dummy == 'G'))
{
if (dummy == 'K')
multiplier = 1024;
else if (dummy == 'M')
multiplier = 1024 * 1024;
else if (dummy == 'G')
multiplier = 1024 * 1024 * 1024;
break;
}
else
error_exit("%s needs a value as parameter\n", par);
}
}
result = strtol(string, NULL, 10);
if (result > INT_MAX || result == LONG_MIN || result == LONG_MAX)
error_exit("value %s for parameter %s is too large\n", string, par);
result *= multiplier;
if (check == VAL_ZERO_POSITIVE)
{
if (result < 0)
error_exit("value for %s must be >= 0\n", par);
}
else if (check == VAL_POSITIVE_NOT_1)
{
if (result < 0 || result == 1)
error_exit("value for %s must be >= 0 and not 1\n", par);
}
else if (check == VAL_POSITIVE)
{
if (result <= 0)
error_exit("value for %s must be > 0\n", par);
}
else
error_exit("get_value_arg: internal error (%d)\n", check);
return (int)result;
}
int find_conversion_scheme(char *name)
{
int loop;
for(loop=0; loop<n_conversions; loop++)
{
if (strcmp(conversions[loop].name, name) == 0)
return loop;
}
return -1;
}
void add_redir_to_file(char mode, char *file, redirect_t **predir, int *n_redirect)
{
int cur_index = (*n_redirect)++;
*predir = (redirect_t *)myrealloc(*predir, (*n_redirect) * sizeof(redirect_t), "main: redirect_t-list");
if (mode == 'a')
(*predir)[cur_index].type = REDIRECTTO_FILE_FILTERED;
else
(*predir)[cur_index].type = REDIRECTTO_FILE;
(*predir)[cur_index].redirect = mystrdup(file, "main: redirect destination");
(*predir)[cur_index].fd = open((*predir)[cur_index].redirect, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
if ((*predir)[cur_index].fd == -1)
error_exit("%s: cannot open file %s for write access\n", file, (*predir)[cur_index].redirect);
}
void add_redir_to_proc(char mode, char *proc, redirect_t **predir, int *n_redirect)
{
int fds[2];
int cur_index = (*n_redirect)++;
*predir = (redirect_t *)myrealloc(*predir, (*n_redirect) * sizeof(redirect_t), "main: redirect_t-list");
if ((*predir)[cur_index].type) error_exit("one can only set one redirection-type per (sub-)window\n");
if (mode == 'g')
(*predir)[cur_index].type = REDIRECTTO_PIPE_FILTERED;
else
(*predir)[cur_index].type = REDIRECTTO_PIPE;
(*predir)[cur_index].redirect = mystrdup(proc, "main: command to redirect to");
if (pipe(fds) == -1)
error_exit("main: error creating pipe\n");
if (((*predir)[cur_index].pid = fork()) == -1)
error_exit("main: fork() failed\n");
if ((*predir)[cur_index].pid == 0)
{
int dummy_fd = open_null();
close(0);
if (dup(fds[0]) == -1) error_exit("add_redir_to_proc: dup() failed\n");
close(1);
close(2);
if (dup(dummy_fd) == -1) error_exit("add_redir_to_proc: dup() failed\n");
if (dup(dummy_fd) == -1) error_exit("add_redir_to_proc: dup() failed\n");
close(fds[1]);
/* start process */
if (-1 == execlp(shell, shell, "-c", (*predir)[cur_index].redirect, (void *)NULL)) error_exit("main: execlp of %s failed\n", (*predir)[cur_index].redirect);
/* if execlp returns, an error occured */
error_exit("main: error while starting process '%s'!\n", (*predir)[cur_index].redirect);
}
close(fds[0]);
(*predir)[cur_index].fd = fds[1];
}
void argv_set_window_widths(char *widths)
{
if (split != 0)
error_exit("-s and -sw are mutual exclusive\n");
split = 0;
for(;;)
{
int cur_width;
char *pnt;
pnt = strtok(widths, ",");
if (!pnt) break;
split++;
vertical_split = (int *)myrealloc(vertical_split, split * sizeof(int), "main: vertical split widths");
cur_width = get_value_arg("-sw", pnt, VAL_POSITIVE);
widths = NULL;
if (cur_width < 4)
{
if (cur_width == 0)
cur_width = -1;
else
error_exit("width of a column must be 4 or greater (or '0' for automatic size)\n");
}
vertical_split[split - 1] = cur_width;
}
if (split == 1)
error_exit("you have to give the width for each window! or set it to 0 (=auto width)\n");
}
void argv_set_n_windows_per_column(char *pars)
{
int index = 0;
if (split == 0)
error_exit("first use -s or -sw to define the number of columns\n");
for(;;)
{
int cur_n;
char *pnt;
pnt = strtok(pars, ",");
if (!pnt) break;
index++;
n_win_per_col = (int *)myrealloc(n_win_per_col, index * sizeof(int), "main: vertical split n_win_per_col");
cur_n = get_value_arg("-sn", pnt, VAL_POSITIVE);
pars = NULL;
if (cur_n < 0)
error_exit("number of windows must be either 0 (=auto) or >= 1\n");
n_win_per_col[index - 1] = cur_n;
}
}
int argv_add_re(char *mode, char *pars[], char invert_regex, re **pre, int *n_re, char *exprall)
{
char *cmd = NULL, *expr = NULL;
char regex_mode = 0;
int n_pars_used = 0;
/* -e => only for this file, -E => for all following files */
if (mode[1] == 'E')
*exprall = 1;
/* c/C/m define colors, x says: execute */
if (toupper(mode[2]) == 'C')
regex_mode = mode[2];
else if (toupper(mode[2]) == 'B')
regex_mode = mode[2];
else if (mode[2] == 'm' || mode[2] == 0x00)
regex_mode = 'm'; /* m = match, only print when matches */
else if (mode[2] == 'v')
regex_mode = 'v'; /* v = !match, only print when not matching */
else if (mode[2] == 'x')
regex_mode = 'x'; /* x = execute */
else
error_exit("%s is an unknown switch\n", mode);
/* get expression */
expr = pars[n_pars_used++];
/* and if there's anything to execute, get commandline */
if (regex_mode == 'x')
{
cmd = pars[n_pars_used++];
}
/* compile & set expression */
/* allocate new structure */
*pre = (re *)myrealloc(*pre, sizeof(re) * (*n_re + 1), "main: list of regular expressions");
/* initialize structure */
memset(&(*pre)[*n_re], 0x00, sizeof(re));
/* compile */
compile_re(&(*pre)[*n_re].regex, expr);
/* remember string for later edit */
(*pre)[*n_re].regex_str = mystrdup(expr, "main: -e regexp");
/* set flag on current file */
(*pre)[*n_re].use_regex = regex_mode;
if (exprall == 0)
regex_mode = 0;
/* wether to invert the reg exp or not */
if ((regex_mode == 'v' || regex_mode == 'm') && invert_regex)
{
error_exit("-e[m] / -ev cannot be used together with -v\n");
}
(*pre)[*n_re].invert_regex = invert_regex;
if (exprall == 0)
invert_regex = 0;
/* what to execute (if...) */
if (cmd)
(*pre)[*n_re].cmd = mystrdup(cmd, "main: -e cmd");
else
(*pre)[*n_re].cmd = NULL;
(*n_re)++;
return n_pars_used;
}
int argv_color_settings(char *mode, char *pars[], char *allcolor, char *curcolor, int *field_index, char **field_delimiter, myattr_t *cdef, term_t *cur_term_emul, int **cur_color_schemes, int *cur_n_color_schemes, myattr_t *alt_col_cdev1, myattr_t *alt_col_cdev2)
{
int n_pars_used = 0;
char cur_mode = mode[2], doall = 0;
if (mode[1] == 'C')
doall = 1;
if (cur_mode == 's') /* syslog-file coloring? */
{
}
else if (cur_mode == 'a') /* alternating colors */
{
*alt_col_cdev1 = parse_attributes(pars[n_pars_used++]);
*alt_col_cdev2 = parse_attributes(pars[n_pars_used++]);
}
else if (cur_mode == 'i') /* use one specific color */
{
*cdef = parse_attributes(pars[n_pars_used++]);
}
else if (cur_mode == 'T') /* terminal mode */
{
if (pars[n_pars_used] != NULL && (strcasecmp(pars[n_pars_used], "ANSI") == 0 || strcasecmp(pars[n_pars_used], "vt100") == 0))
*cur_term_emul = TERM_ANSI;
else
error_exit("Terminal emulation '%s' is not known\n", pars[n_pars_used]);
n_pars_used++;
}
else if (cur_mode == 'S') /* use colorscheme */
{
int cur_scheme_index;
char *cur_cscheme = pars[n_pars_used++];
if (!cur_cscheme)
error_exit("%s requires a colorscheme-name\n", mode);
if ((cur_scheme_index = find_colorscheme(cur_cscheme)) == -1)
{
if (use_colors)
error_exit("Colorscheme %s not found! Check your configfile.\n", cur_cscheme);
else
error_exit("Colorschemes are not supported on monochrome terminals\n");
}
add_color_scheme(cur_color_schemes, cur_n_color_schemes, cur_scheme_index);
}
else if (cur_mode == '-') /* do not color current */
{
cur_mode = 'n';
}
else if (cur_mode == 'f') /* select field for coloring */
{
*field_index = get_value_arg(mode, pars[n_pars_used++], VAL_ZERO_POSITIVE);
*field_delimiter = pars[n_pars_used++];
}
else if (cur_mode == 0x00) /* use complete line for coloring */
{
cur_mode = 'm';
}
else
{
error_exit("invalid -c mode: '%c'\n", cur_mode);
}
if (doall)
{
*allcolor = cur_mode;
*curcolor = 'n';
}
else
{
*curcolor = cur_mode;
*allcolor = 'n';
}
return n_pars_used;
}
int argv_add_stripper(char *mode, char *pars[], strip_t **pstrip, int *n_strip)
{
int n_pars_used = 0;
*pstrip = myrealloc(*pstrip, (*n_strip + 1) * sizeof(strip_t), "smain: trip_t");
if (mode[2] == 'e')
{
char *re = pars[n_pars_used++];
(*pstrip)[*n_strip].type = STRIP_TYPE_REGEXP;
(*pstrip)[*n_strip].regex_str = mystrdup(re, "smain: trip regexp string");
compile_re(&(*pstrip)[*n_strip].regex, re);
}
else if (mode[2] == 'r')
{
(*pstrip)[*n_strip].type = STRIP_TYPE_RANGE;
(*pstrip)[*n_strip].start = get_value_arg(mode, pars[n_pars_used++], VAL_ZERO_POSITIVE);
(*pstrip)[*n_strip].end = get_value_arg(mode, pars[n_pars_used++], VAL_ZERO_POSITIVE);
if ((*pstrip)[*n_strip].end <= (*pstrip)[*n_strip].start)
error_exit("'-kr start end': end must be bigger then start\n");
}
else if (mode[2] == 'c')
{
(*pstrip)[*n_strip].type = STRIP_TYPE_COLUMN;
(*pstrip)[*n_strip].del = mystrdup(pars[n_pars_used++], "smain: trip column delimiter");
(*pstrip)[*n_strip].col_nr = get_value_arg(mode, pars[n_pars_used++], VAL_ZERO_POSITIVE);
}
else
error_exit("'%s' is not recognized\n", mode);
(*n_strip)++;
return n_pars_used;
}
void add_glob_check(char *check_glob, int check_interval, char merge, char new_only)
{
cdg = (check_dir_glob *)myrealloc(cdg, sizeof(check_dir_glob) * (n_cdg + 1), "add_glob_check: check_dir_glob");
cdg[n_cdg].glob_str = mystrdup(check_glob, "add_glob_check: glob_str");
cdg[n_cdg].check_interval = check_interval;
cdg[n_cdg].in_one_window = merge;
cdg[n_cdg].new_only = new_only;
cdg[n_cdg].window_nr = -1;
cdg[n_cdg].last_check = (time_t)0;
n_cdg++;
}
void do_commandline(int argc, char *argv[])
{
int loop;
char curcolor = 'n', allcolor = 'n';
int field_index = 0;
char *field_delimiter = NULL;
char follow_filename = -1, retry = 0, invert_regex = 0;
char retry_all = 0;
char exprall = 0;
int maxlines = -1;
char setallmaxlines = 0;
int restart = -1;
char restart_clear = 0;
char do_diff = 0;
char cur_line_wrap = -1;
int cur_line_wrap_offset = -1;
char all_line_wrap = 0;
re *pre = NULL;
int n_re = 0;
int *cur_color_schemes = NULL;
int cur_n_color_schemes = 0;
myattr_t cdef = { -1, -1 };
int window_height = -1;
int initial_n_lines_tail = -1;
char *win_title = NULL;
term_t cur_term_emul = TERM_IGNORE;
strip_t *pstrip = NULL;
int n_strip = 0;
int n_redirect = 0;
redirect_t *predir = NULL;
mybool_t used_stdin = MY_FALSE;
char merge_all = 0;
int close_idle = 0;
char setallmaxbytes = 0;
int maxbytes = -1;
myattr_t alt_col_cdev1 = { -1, -1 }, alt_col_cdev2 = { -1, -1 };
time_field_t new_only = 0;
char no_repeat = 0;
int mark_interval = 0;
char syslog_noreverse = 0;
char cont = 0;
char marker_of_other_window = 0;
char no_marker_of_other_window = 0;
char bufferwhat = -1;
char do_add_timestamp = 0;
int *conversions = NULL;
int n_conversions = 0;
/* first, before we load the main configfile, see if we should load the global
* file or not
*/
for(loop=1; loop<argc; loop++)
{
if (strcmp(argv[loop], "--no-load-global-config") == 0)
{
load_global_config = 0;
break;
}
}
if (load_global_config)
(void)load_configfile(NULL);
/* set defaults from configfile */
bufferwhat = default_bufferwhat;
cur_line_wrap = default_linewrap;
cur_line_wrap_offset = default_line_wrap_offset;
follow_filename = default_follow_filename;
/* parse commandline */
for(loop=1; loop<argc; loop++)
{
if (strcmp(argv[loop], "-V") == 0)
{
version();
exit(0);
}
else if (strcmp(argv[loop], "--no-load-global-config") == 0)
{
/* ignore */
}
else if (strcmp(argv[loop], "-bw") == 0)
{
char *what = argv[++loop];
if (what)
{
if (what[0] == 'a' || what[0] == 'f')
bufferwhat = what[0];
else
error_exit("-bw expects either 'a' or 'f' as parameter (got: '%c')\n", what[0]);
}
else
error_exit("-bw expects a parameter ('a' or 'f')\n");
}
else if (strcmp(argv[loop], "--no-repeat") == 0)
{
no_repeat = 1;
}
else if (strcmp(argv[loop], "--cont") == 0)
{
cont = 1;
}
else if (strcmp(argv[loop], "--mark-interval") ==0)
{
mark_interval = get_value_arg("--mark-interval", argv[++loop], VAL_ZERO_POSITIVE);
}
else if (strcmp(argv[loop], "-ts") == 0)
{
do_add_timestamp = 1;
}
else if (strcmp(argv[loop], "--basename") == 0)
{
filename_only = 1;
}
else if (strcmp(argv[loop], "--mergeall") == 0)
{
merge_all = 1;
}
else if (strcmp(argv[loop], "--no-mergeall") == 0)
{
merge_all = 0;
}
else if (strcmp(argv[loop], "--closeidle") == 0)
{
close_idle = get_value_arg("--closeidle", argv[++loop], VAL_ZERO_POSITIVE);
}
else if (strcmp(argv[loop], "-H") == 0)
{
++loop;
if (argv[loop])
{
heartbeat_interval = atof(argv[loop]);
if (heartbeat_interval < 0.0) error_exit("value for %s must be >= 0\n", "-H");
}
else
error_exit("-H requires a parameter\n");
}
else if (strcasecmp(argv[loop], "-a") == 0)
{
char mode = argv[loop][1];
add_redir_to_file(mode, argv[++loop], &predir, &n_redirect);
}
else if (strcasecmp(argv[loop], "-g") == 0)
{
char mode = argv[loop][1];
add_redir_to_proc(mode, argv[++loop], &predir, &n_redirect);
}
else if (strcmp(argv[loop], "-F") == 0 || strcmp(argv[loop], "--config") == 0)
{
config_file = argv[++loop];
if (file_exist(config_file) == -1)
error_exit("Config-file %s does not exist\n", config_file);
(void)load_configfile(config_file);
}
else if (strcmp(argv[loop], "-Z") == 0)
{
markerline_attrs = parse_attributes(argv[++loop]);
}
else if (strcmp(argv[loop], "-T") == 0)
{
timestamp_in_markerline = 1;
}
else if (strcmp(argv[loop], "-S") == 0)
{
show_subwindow_id = 1;
}
else if (strcmp(argv[loop], "-t") == 0)
{
++loop;
if (!argv[loop])
error_exit("-t requires a parameter\n");
win_title = mystrdup(argv[loop], "-t");
}
else if (strcmp(argv[loop], "-x") == 0)
{
++loop;
if (!argv[loop])
error_exit("-x requires a parameter\n");
set_title = mystrdup(argv[loop], "-x");
}
else if (argv[loop][0] == '-' && toupper(argv[loop][1]) == 'P')
{
char *lw = argv[++loop];
if (lw)
{
if (argv[loop - 1][1] == 'P')
all_line_wrap = 1;
else
all_line_wrap = 0;
cur_line_wrap = lw[0];
if (cur_line_wrap == 'o')
cur_line_wrap_offset = get_value_arg("-p", argv[++loop], VAL_ZERO_POSITIVE);
else if (cur_line_wrap != 'a' && cur_line_wrap != 'l' && cur_line_wrap != 'r' && toupper(cur_line_wrap) != 'S')
error_exit("Invalid mode fore -p\n");
}
else
error_exit("-p requires a parameter\n");
}
else if (strcmp(argv[loop], "--retry") == 0)
{
retry = 1;
}
else if (strcmp(argv[loop], "--retry-all") == 0)
{
retry_all = 1;
retry = 1;
}
else if (strcmp(argv[loop], "-n") == 0)
{
initial_n_lines_tail = get_value_arg("-n", argv[++loop], VAL_ZERO_POSITIVE);
}
else if (strcmp(argv[loop], "-b") == 0)
{
tab_width = get_value_arg("-b", argv[++loop], VAL_ZERO_POSITIVE);
}
else if (strcmp(argv[loop], "-u") == 0)
{
update_interval = get_value_arg("-u", argv[++loop], VAL_ZERO_POSITIVE);
}
else if (argv[loop][0] == '-' && toupper(argv[loop][1]) == 'R')
{
if (argv[loop][1] == 'R')
do_diff = 1;
if (argv[loop][2] == 'c')
restart_clear = 1;
restart = get_value_arg("-r/R", argv[++loop], VAL_ZERO_POSITIVE);
}
else if (strcmp(argv[loop], "-s") == 0)
{
split = get_value_arg("-s", argv[++loop], VAL_POSITIVE_NOT_1);
}
else if (strcmp(argv[loop], "-sw") == 0)
{
argv_set_window_widths(argv[++loop]);
}
else if (strcmp(argv[loop], "-sn") == 0)
{
argv_set_n_windows_per_column(argv[++loop]);
}
else if (strcmp(argv[loop], "-wh") == 0)
{
window_height = get_value_arg("-wh", argv[++loop], VAL_POSITIVE);
}
else if (strcmp(argv[loop], "-fr") == 0)
{
char *par = argv[++loop];
for(;;)
{
int filter;
char *komma = strchr(par, ',');
if (komma)
*komma = 0x00;
filter = find_filterscheme(par);
if (filter == -1)
error_exit("'%s' is an unknown filter scheme\n", par);
duplicate_re_array(pfs[filter].pre, pfs[filter].n_re, &pre, &n_re);
if (komma)
par = komma + 1;
else
break;
}
}
else if (strcmp(argv[loop], "-cv") == 0)
{
char *par = argv[++loop];
for(;;)
{
int conversion;
char *komma = strchr(par, ',');
if (komma)
*komma = 0x00;
conversion = find_conversion_scheme(par);
if (conversion == -1)
error_exit("'%s' is an unknown conversionscheme\n", par);
conversions = (int *)myrealloc(conversions, (n_conversions + 1) * sizeof(int), "list of conversions");
conversions[n_conversions++] = conversion;
if (komma)
par = komma + 1;
else
break;
}
}
else if (argv[loop][0] == '-' && toupper(argv[loop][1]) == 'E')
{
loop += argv_add_re(argv[loop], &argv[loop + 1], invert_regex, &pre, &n_re, &exprall);
}
else if (strcmp(argv[loop], "-v") == 0)
{
invert_regex = 1;
}
else if (strcmp(argv[loop], "-csn") == 0)
{
syslog_noreverse = 1;
}
else if (argv[loop][0] == '-' && toupper(argv[loop][1]) == 'C')
{
loop += argv_color_settings(argv[loop], &argv[loop + 1], &allcolor, &curcolor, &field_index, &field_delimiter, &cdef, &cur_term_emul, &cur_color_schemes, &cur_n_color_schemes, &alt_col_cdev1, &alt_col_cdev2);
}
else if (strcmp(argv[loop], "-f") == 0)
{
follow_filename = 1;
}
else if (strcmp(argv[loop], "-w") == 0)
{
use_colors = 0;
}
else if (argv[loop][0] == '-' && argv[loop][1] == 'k')
{
loop += argv_add_stripper(argv[loop], &argv[loop + 1], &pstrip, &n_strip);
}
else if (strcasecmp(argv[loop], "-m") == 0)
{
if (argv[loop][1] == 'M')
setallmaxlines = 1;
maxlines = get_value_arg("-m/M", argv[++loop], VAL_ZERO_POSITIVE);
}
else if (strcasecmp(argv[loop], "-mb") == 0)
{
if (argv[loop][1] == 'M')
setallmaxbytes = 1;
maxbytes = get_value_arg("-m/M", argv[++loop], VAL_ZERO_POSITIVE);
}
else if (strcasecmp(argv[loop], "-i") == 0 || argv[loop][0] != '-' ||
strcasecmp(argv[loop], "-l") == 0 ||
strcasecmp(argv[loop], "-j") == 0 ||
strcasecmp(argv[loop], "-iw") == 0)
{
struct stat64 buf;
char *dummy;
char is_cmd = 0;
char is_sub = 0;
char is_giw = 0;
mybool_t is_stdin = MY_FALSE;
int check_interval = 0;
proginfo *cur;
if (strcasecmp(argv[loop], "-l") == 0)
{
is_cmd = 1;
}
if (strcasecmp(argv[loop], "-j") == 0)
{
if (used_stdin == MY_TRUE) error_exit("One can use -j only once!\n");
is_stdin = used_stdin = MY_TRUE;
}
if (strcasecmp(argv[loop], "-iw") == 0)
{
if (argv[loop + 2])
{
if ((argc - loop) > 2 && isdigit(argv[loop+2][0]))
{
is_giw = 1;
check_interval = atoi(argv[loop + 2]);
}
else
{
check_interval = 5;
}
}
else
error_exit("-iw requires 2 parameters\n");
}
if (strcmp(argv[loop], "-L") == 0 ||
strcmp(argv[loop], "-I") == 0 ||
strcmp(argv[loop], "-Iw") == 0 ||
strcmp(argv[loop], "-J") == 0 ||
merge_all)
{
is_sub = 1;
}
if (argv[loop][0] == '-' && toupper(argv[loop][1]) != 'J')
{
loop++;
}
dummy = argv[loop];
if (is_sub == 1 && nfd > 0)
{
cur = &pi[nfd - 1];
while(cur -> next)
{
cur = cur -> next;
}
cur -> next = (proginfo *)mymalloc(sizeof(proginfo), "main: proginfo");
cur = cur -> next;
nsubwindows[nfd-1]++;
}
else
{
pi = (proginfo *)myrealloc(pi, (nfd + 1) * sizeof(proginfo), "pmain: roginfo");
lb = (buffer *)myrealloc(lb, (nfd + 1) * sizeof(buffer), "bmain: uffers");
nsubwindows = (char *)myrealloc(nsubwindows, (nfd + 1) * sizeof(char), "main: subwindows");
nsubwindows[nfd] = 1;
memset(&lb[nfd], 0x00, sizeof(buffer));
lb[nfd].maxnlines = maxlines;
if (!setallmaxlines)
maxlines = -1;
lb[nfd].bufferwhat = bufferwhat;
bufferwhat = default_bufferwhat;
lb[nfd].maxbytes = maxbytes;
if (!setallmaxbytes)
maxbytes = -1;
if (marker_of_other_window || lb[nfd].marker_of_other_window)
lb[nfd].marker_of_other_window = 1;
else if (no_marker_of_other_window == 1)
lb[nfd].marker_of_other_window = -1; /* override global configfile setting */
no_marker_of_other_window = marker_of_other_window = 0;
cur = &pi[nfd];
nfd++;
}
memset(cur, 0x00, sizeof(proginfo));
/* see if file exists */
if (check_interval == 0 && is_cmd == 0 && is_stdin == MY_FALSE && retry == 0 && stat64(dummy, &buf) == -1)
{
error_exit("error opening %s (%d)\n", dummy, errno);
}
/* init. struct. for this file */
if (is_stdin == MY_FALSE)
{
if (!dummy) error_exit("No filename given!\n");
cur -> filename = mystrdup(dummy, "main: cur -> filename");
}
else
{
cur -> filename = mystrdup("STDIN", "main: read from stdin");
}
cur -> is_command = is_cmd;
cur -> check_interval = check_interval;
cur -> is_stdin = is_stdin;
cur -> win_title = win_title;
win_title = NULL;
cur -> close_idle = close_idle;
close_idle = 0;
/* initial number of lines to tail */
cur -> initial_n_lines_tail = initial_n_lines_tail;
initial_n_lines_tail = -1;
/* default window height */
cur -> win_height = window_height;
window_height = -1;
/* store regular expression(s) */
cur -> pre = NULL;
cur -> n_re = 0;
duplicate_re_array(pre, n_re, &cur -> pre, &cur -> n_re);
if (exprall == 0)
{
n_re = 0;
pre = NULL;
}
/* hide this window? */
cur -> hidden = 0;
/* add timestamp in front of each line? */
cur -> add_timestamp = do_add_timestamp;
do_add_timestamp = 0;
/* strip */
cur -> pstrip = pstrip;
cur -> n_strip = n_strip;
pstrip = NULL;
n_strip = 0;
cur -> conversions = conversions;
cur -> n_conversions = n_conversions;
conversions = NULL;
n_conversions = 0;
/* line wrap */
cur -> line_wrap = cur_line_wrap;
cur -> line_wrap_offset = cur_line_wrap_offset;
if (!all_line_wrap)
{
cur_line_wrap = default_linewrap;
cur_line_wrap_offset = default_line_wrap_offset;
}
cur -> retry_open = retry;
cur -> follow_filename = follow_filename;
follow_filename = default_follow_filename;
cur -> cont = cont;
cont = 0;
/* 'watch' functionality configuration (more or less) */
cur -> restart = restart;
cur -> restart_clear = restart_clear;
restart = -1; /* invalidate for next parameter */
restart_clear = 0;
cur -> first = 1;
cur -> do_diff = do_diff;
do_diff = 0;
cur -> suppress_repeating_lines = no_repeat;
cur -> mark_interval = mark_interval;
/* colors */
cur -> attributes = cdef;
cur -> alt_col_cdev1 = alt_col_cdev1;
cur -> alt_col_cdev2 = alt_col_cdev2;
cur -> syslog_noreverse = syslog_noreverse;
if (curcolor != 'n' && curcolor != 0)
{
cur -> colorize = curcolor;
cur -> color_schemes = cur_color_schemes;
cur -> n_color_schemes = cur_n_color_schemes;
cur_color_schemes = NULL;
cur_n_color_schemes = 0;
}
else
{
if (allcolor == 'n' && default_color_scheme != -1)
{
cur -> colorize = 'S';
add_color_scheme(&cur -> color_schemes, &cur -> n_color_schemes, default_color_scheme);
}
else if (allcolor == 'n')
{
cur -> colorize = 0;
}
else if (allcolor == 'S')
{
int n_bytes = sizeof(int) * cur_n_color_schemes;
cur -> colorize = 'S';
cur -> n_color_schemes = cur_n_color_schemes;
cur -> color_schemes = mymalloc(n_bytes, "allcolor: cur -> color_schemes");
memcpy(cur -> color_schemes, cur_color_schemes, n_bytes);
}
else
{
cur -> colorize = allcolor;
}
}
cur -> field_nr = field_index;
cur -> field_del = field_delimiter ? mystrdup(field_delimiter, "main: cur -> field_del") : NULL;
cur -> sccfirst = 1;
curcolor = 'n';
if (!retry_all)
retry = 0;
if (is_giw) /* skip over the checkinterval */
loop++;
cur -> term_emul = cur_term_emul;
cur_term_emul = TERM_IGNORE;
/* redirect input also to a file or pipe */
cur -> n_redirect = n_redirect;
n_redirect = 0;
cur -> predir = predir;
predir = NULL;
}
else if (strcmp(argv[loop], "-du") == 0)
{
statusline_above_data = 1;
}
else if (strcmp(argv[loop], "-d") == 0)
{
mode_statusline = 0;
}
else if (strcmp(argv[loop], "-D") == 0)
{
mode_statusline = -1;
}
else if (strcmp(argv[loop], "-z") == 0)
{
warn_closed = 0;
}
else if (strcmp(argv[loop], "--new-only") == 0)
{
char *type = argv[++loop];
if (type)
{
if (strcasecmp(type, "atime") == 0)
new_only = TT_ATIME;
else if (strcasecmp(type, "mtime") == 0)
new_only = TT_MTIME;
else if (strcasecmp(type, "ctime") == 0)
new_only = TT_CTIME;
else
error_exit("--new-only requires either atime, mtime or ctime as parameter, not '%s'\n", type);
}
else
error_exit("--new-only requires a parameter\n");
}
else if (strcasecmp(argv[loop], "-q") == 0)
{
int merge = argv[loop][1] == 'Q';
int check_interval = get_value_arg("-q/-Q", argv[++loop], VAL_ZERO_POSITIVE);
char *check_glob = argv[++loop];
add_glob_check(check_glob, check_interval, merge, new_only);
}
else if (strcmp(argv[loop], "--mark-change") == 0)
{
marker_of_other_window = 1;
}
else if (strcmp(argv[loop], "--no-mark-change") == 0)
{
no_marker_of_other_window = 1;
}
else if (strcmp(argv[loop], "-o") == 0)
{
loop++;
if (!argv[loop])
error_exit("-o requires a parameter\n");
else
config_file_entry(argv[loop]);
}
else
{
if (strcmp(argv[loop], "-h") != 0)
{
fprintf(stderr, "unknown parameter '%s'\n", argv[loop]);
}
usage();
exit(1);
}
}
}
|