[lwatch-cvs] files/src lwatch.conf,1.4,1.5 strpcre.c,1.5,1.6 strpcre.h,1.4,1.5
Brought to you by:
arturcz
|
From: <ar...@us...> - 2002-07-01 15:53:51
|
Update of /cvsroot/lwatch/files/src
In directory usw-pr-cvs1:/tmp/cvs-serv20427
Modified Files:
lwatch.conf strpcre.c strpcre.h
Log Message:
highlight keyword supported
Index: lwatch.conf
===================================================================
RCS file: /cvsroot/lwatch/files/src/lwatch.conf,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** lwatch.conf 30 Jun 2002 00:23:53 -0000 1.4
--- lwatch.conf 1 Jul 2002 15:53:31 -0000 1.5
***************
*** 13,17 ****
# Default color for displaing message body
# mesg_color=white
- serv_color=green
# Where is source for reading data?
--- 13,16 ----
***************
*** 38,45 ****
# Below is configuration which works for me
! /root/ color=yellow # all messages with root string are yellow
/^fw-reject:/ { # all rejectd from fw are red
color=red
}
--- 37,47 ----
# Below is configuration which works for me
! /root/ highlight=yellow # all messages with root string are yellow
!
! /failed/ color=red # attention, operation failed
/^fw-reject:/ { # all rejectd from fw are red
color=red
+ serv_color=yellow
}
***************
*** 54,57 ****
/disconnect/ highlight=red # highlight only disconnect on red
! //USR/SBIN/CRON/ color=blue # cron's messages are not important
! # display it in blue
--- 56,61 ----
/disconnect/ highlight=red # highlight only disconnect on red
! //USR/SBIN/CRON/ { # cron's messages are not important
! color=blue # display it in blue
! match_service
! }
Index: strpcre.c
===================================================================
RCS file: /cvsroot/lwatch/files/src/strpcre.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** strpcre.c 1 Jul 2002 15:38:17 -0000 1.5
--- strpcre.c 1 Jul 2002 15:53:31 -0000 1.6
***************
*** 42,45 ****
--- 42,46 ----
#define SERV_COLOR colmode[serv_c]
#define MESG_COLOR colmode[mesg_c]
+ #define HL_COLOR colmode[hl_c]
struct {
***************
*** 52,55 ****
--- 53,57 ----
} re_matches[RE_NMATCHES];
+ int date_c,host_c,serv_c,mesg_c,hl_c;
int compile_re(char *re, pcre **pre, pcre_extra **prh) {
***************
*** 95,99 ****
}
! char *newstr(char *str) {
char *ptmp;
ptmp=(char *)malloc(strlen(str)+1);
--- 97,101 ----
}
! char *newstr(const char *str) {
char *ptmp;
ptmp=(char *)malloc(strlen(str)+1);
***************
*** 116,124 ****
}
void showline(char *input) {
int i,n,ignore;
- int date_c,host_c,serv_c,mesg_c;
const char **re_str;
! const char *match;
//memcpy((void*)&date_c,(void*)&lw_conf.def_date_color,4*sizeof(int));
--- 118,156 ----
}
+ char *hl_str(struct s_action *act,char *str) {
+ char *pmatch,*pres;
+ int i,j;
+ int start_match;
+ pmatch=newstr(str);
+ start_match=0;
+ while(pcre_exec(act->re,act->rh,pmatch,strlen(pmatch),start_match,0,(int*)&re_matches,RE_NMATCHES)>0) {
+ pres=(char*)malloc(strlen(pmatch)+strlen(HL_COLOR)+strlen(MESG_COLOR)+1);
+ i=j=0;
+ while(j<re_matches->start)
+ pres[i++]=pmatch[j++];
+ j=0;
+ while(pres[i++]=HL_COLOR[j++]);
+ i--;
+ j=re_matches->start;
+ while(j<re_matches->stop)
+ pres[i++]=pmatch[j++];
+ pres[i]='\0';
+ j=0;
+ while(pres[i++]=MESG_COLOR[j++]);
+ i--;
+ j=re_matches->stop;
+ while(pres[i++]=pmatch[j++]);
+ free(pmatch);
+ pmatch=pres;
+ start_match=re_matches->stop+strlen(MESG_COLOR);
+ }
+ return(pres);
+ }
+
void showline(char *input) {
int i,n,ignore;
const char **re_str;
! char *match;
! char *date_s,*host_s,*serv_s,*mesg_s;
//memcpy((void*)&date_c,(void*)&lw_conf.def_date_color,4*sizeof(int));
***************
*** 127,130 ****
--- 159,163 ----
serv_c=lw_conf.def_serv_color;
mesg_c=lw_conf.def_mesg_color;
+ hl_c=0;
ignore=0;
n=pcre_exec(parser.pre,parser.prh,input,strlen(input),0,0,
***************
*** 135,143 ****
}
pcre_get_substring_list(input,(int*)&re_matches,n,&re_str);
for(i=0;i<no_actions;i++) {
if(lw_actions[i].match_service) {
! match=re_str[3]; /* match service */
} else {
! match=re_str[4]; /* match message body */
}
n=pcre_exec(lw_actions[i].re,lw_actions[i].rh,
--- 168,181 ----
}
pcre_get_substring_list(input,(int*)&re_matches,n,&re_str);
+ date_s=newstr(re_str[1]);
+ host_s=newstr(re_str[2]);
+ serv_s=newstr(re_str[3]);
+ mesg_s=newstr(re_str[4]);
+ pcre_free_substring_list(re_str);
for(i=0;i<no_actions;i++) {
if(lw_actions[i].match_service) {
! match=serv_s; /* match service */
} else {
! match=mesg_s; /* match message body */
}
n=pcre_exec(lw_actions[i].re,lw_actions[i].rh,
***************
*** 150,153 ****
--- 188,198 ----
if(lw_actions[i].serv_color) serv_c=lw_actions[i].serv_color;
if(lw_actions[i].mesg_color) mesg_c=lw_actions[i].mesg_color;
+ if(lw_actions[i].highlight_color) {
+ hl_c=lw_actions[i].highlight_color;
+ match=hl_str(&lw_actions[i],mesg_s);
+ free(mesg_s);
+ mesg_s=match;
+ }
+
break;
}
***************
*** 158,165 ****
if(!ignore) {
printf("%s%s%s%s%s%s%s%s"_S_RESET"\n",
! DATE_COLOR,re_str[1],
! HOST_COLOR,re_str[2],
! SERV_COLOR,re_str[3],
! MESG_COLOR,re_str[4]);
}
#ifdef DEBUG
--- 203,210 ----
if(!ignore) {
printf("%s%s%s%s%s%s%s%s"_S_RESET"\n",
! DATE_COLOR,date_s,
! HOST_COLOR,host_s,
! SERV_COLOR,serv_s,
! MESG_COLOR,mesg_s);
}
#ifdef DEBUG
***************
*** 168,171 ****
}
#endif
! pcre_free_substring_list(re_str);
}
--- 213,219 ----
}
#endif
! free(date_s);
! free(host_s);
! free(serv_s);
! free(mesg_s);
}
Index: strpcre.h
===================================================================
RCS file: /cvsroot/lwatch/files/src/strpcre.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** strpcre.h 30 Jun 2002 00:23:53 -0000 1.4
--- strpcre.h 1 Jul 2002 15:53:31 -0000 1.5
***************
*** 40,44 ****
void init_parser(void);
int compile_re(char *re, pcre **pre, pcre_extra **prh);
! char *newstr(char *str);
char *addstr(char *s1, const char *s2);
void showline(char *str);
--- 40,44 ----
void init_parser(void);
int compile_re(char *re, pcre **pre, pcre_extra **prh);
! char *newstr(const char *str);
char *addstr(char *s1, const char *s2);
void showline(char *str);
|