?? monitor.c
字號:
/*
**通用監控程序:
**其它程序只需把監控信息'O_APPEND|O_SYNC'寫入日志文件即可
**program by gwq on 2001.10.29
*/
#include <curses.h>
#include <stdio.h>
#include <time.h>
main(int argv,char * argc[])
{
FILE * fp;
char buff[100],time[20];
WINDOW *win,*win1;
int y,x;
void get_systime1(char *buff);
if( argv!=4){
printf("Usage: monitor <日志文件全路徑名> <頭信息> <行標題>\n");
exit(1);
}
if( (fp=fopen(argc[1],"r"))==NULL ){
printf("Open log file [%s] fail!!!\n",argc[1]);
exit(1);
}
initscr();
curs_set(0);
standout();
mvprintw(0,(80-strlen(argc[2]))/2, "%s",argc[2]);
standend();
mvprintw(2,0,"%s", "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
mvprintw(3,0,"%s",argc[3]);
mvprintw(4,0,"%s", "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
mvprintw(22,0,"%s","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
refresh();
win=newwin(17,80,5,0);
win1=newwin(1,80,1,0);
scrollok(win,TRUE);
//start_color();
//init_pair(3,COLOR_YELLOW,COLOR_BLACK);
//wattron(win1,COLOR_PAIR(3));
//移動指針到文件尾
while( fgets(buff,100,fp)!=NULL );
while(1)
{
get_systime1(time);
mvwprintw(win1,0,65,"%s",time);
touchwin(win1);
wrefresh(win1);
if( fgets(buff,100,fp)!=NULL )
{
wprintw(win,"%s",buff);
touchwin(win);
wrefresh(win);
}
else
sleep(1);
}
curs_set(1);
delwin(win);
delwin(win1);
endwin();
}
/*************************************************************
* 取系統時間b (6位字符串:小時+分鐘+秒鐘)
*************************************************************/
void get_systime1(char *buff)
{
long t;
struct tm *t1;
time(&t);
t1=localtime(&t);
sprintf(buff,"%02d時%02d分%02d秒",t1->tm_hour,t1->tm_min,t1->tm_sec);
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -