如何阅读源代码(7)

2020-12-22 08:27

如何阅读源代码

这几个函数,我们回到main程序。接下来是,
/* setup our internal variables */
init_counters(); /* initalize main counters */
我们所阅读的这个软件是用来分析日志并且做出统计的,那么这个函数的名字已经告诉了我们,这是一个初始化计数器的函数。简略的看看吧!
$ grep init_counters *.h
webalizer.h:extern void init_counters();
在webalizer.c中找到:
void init_counters()
{
int i;
for (i=0;i<TOTAL_RC;i++) response[i].count = 0;
for (i=0;i<31;i++) /* monthly totals */
{
tm_xfer[i]=0.0;
tm_hit[i]=tm_file[i]=tm_site[i]=tm_page[i]=tm_visit[i]=0;
}
for (i=0;i<24;i++) /* hourly totals */
{
th_hit[i]=th_file[i]=th_page[i]=0;
th_xfer[i]=0.0;
}
......
}略过去一大串代码,不用看了,肯定是计数器清0。在主程序中,接下来是:
if (page_type==NULL) /* check if page types present */
{
if ((log_type == LOG_CLF) || (log_type == LOG_SQUID))
{
add_nlist("htm*" ,&page_type); /* if no page types specified, we */
add_nlist("cgi" ,&page_type); /* use the default ones here... */
if (!isinlist(page_type,html_ext)) add_nlist(html_ext,&page_type);
}
else add_nlist("txt" ,&page_type); /* FTP logs default to .txt */
}
page_type这个变量在前面见过,
case 'P': add_nlist(optarg,&page_type); break; /* page view types
根据在最开始读过的README文件,这个page_type是用来定义处理的页面的类型的。在README文件中,
-P name Page type. This is the extension of files you consider to
be pages for Pages calculations (sometimes called 'pageviews').
The default is 'htm*' and 'cgi' (plus whatever HTMLExtension
you specified if it is different). Don't use a period!
我们在程序中也可以看到,如果没有在命令行中或者config文件中指定,则根据处理的日志文件的类型来添加缺省的文件类型。比如对于CLF文件(WWW日志),处理html, htm, cgi文件
if (log_type == LOG_FTP)
{
/* disable stuff for ftp logs */
ntop_entry=ntop_exit=0;
ntop_search=0;
}
else
.....

这一段是对于FTP的日志格式,设置搜索列表。
for (i=0;i<MAXHASH;i++)
{
sm_htab[i]=sd_htab[i]=NULL; /* initalize hash tables */
um_htab[i]=NULL;
rm_htab[i]=NULL;
am_htab[i]=NULL;
sr_htab[i]=NULL;
}
清空哈西表,为下面即将进行的排序工作做好准备。关于哈西表,这是数据结构中常用的一种用来快速排序的结构,如果不清楚,可以参考相关书籍,比如清华的<<数据结构>>教材或者<<数据结构的C++实现>>等书。
if (verbose>1)
{
u
name(&system_info);
printf("Webalizer V%s-%s (%s %s) %s ",
version,editlvl,system_info.sysname,
system_info.release,language);


如何阅读源代码(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:口服液灌装机再验证方案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: