Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15345706
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类:

2010-02-06 23:04:07

apps/openssl.c
int main
==> prog=prog_init();
就在apps/openssl.c文件中有如下定义:
static LHASH_OF(FUNCTION) *prog_init(void)
    {
    LHASH_OF(FUNCTION) *ret;
    FUNCTION *f;
    size_t i;

    /* Purely so it looks nice when the user hits ? */
    for(i=0,f=functions ; f->name != NULL ; ++f,++i)
        ; // 统计一共实现了多少个function.[luther.gliethttp]
    qsort(functions,i,sizeof *functions,SortFnByName); // 使用SortFnByName函数判断数组中数据大小,
    // 这里就是根据函数名字符串来排序[luther.gliethttp]
    // qsort为库函数,用来排序functions[]数组, 这和busybox中实现类似

    if ((ret=lh_FUNCTION_new()) == NULL) // 创建一个hash列表
        return(NULL);

    for (f=functions; f->name != NULL; f++)
        (void)lh_FUNCTION_insert(ret,f); // 将每个function逐个添加到hash列表上,这里使用到了hash算法
                                        // 这种方法比直接使用字母的
    return(ret);                        // 第1个字节来判断hash键值要好很难多,因为这样随机性更大
    }                                   // 于是冲突就会更加平均到hash[]的各个项中[luther.gliethttp]

static int SortFnByName(const void *_f1,const void *_f2)
    {
    const FUNCTION *f1=_f1;
    const FUNCTION *f2=_f2;

    if(f1->type != f2->type)
    return f1->type-f2->type;
    return strcmp(f1->name,f2->name);
    }

阅读(1419) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~