- 论坛徽章:
- 0
|
本帖最后由 wangzhen11aaa 于 2011-10-12 20:37 编辑
- 回到main.c函数
- 1343 if (!url_parsed) /*当然如果没有输入错的话,肯定是不为NULL的*/
- 1344 {
- 1345 char *error = url_error (*t, url_err);
- 1346 logprintf (LOG_NOTQUIET, "%s: %s.\n",*t, error);
- 1347 xfree (error);
- 1348 inform_exit_status (URLERROR);
- 1349 }
- 1350 else /*进入这里*/
- 1351 {
- 1352 if ((opt.recursive || opt.page_requisites) /*如果递归&&使用代理或者不是FTP协议*/
- 1353 && (url_scheme (*t) != SCHEME_FTP || url_uses_proxy (url_parsed)))
- 1354 {
- 1355 int old_follow_ftp = opt.follow_ftp;
- 1356
- 1357 /* Turn opt.follow_ftp on in case of recursive FTP retrieval */
- 1358 if (url_scheme (*t) == SCHEME_FTP) /*如果协议是SCHEME_FTP*/
- 1359 opt.follow_ftp = 1; /* 开启递归fpt*/
- 1360
- 1361 retrieve_tree (url_parsed, NULL); /*1、_________------------->
- 1362
- 1363 opt.follow_ftp = old_follow_ftp; /*将其初始化为可以递归*/
- 1364 }
- 1365 else
- 1366 {
- 1367 retrieve_url (url_parsed, *t, &filename, &redirected_URL, NULL,
- 1368 &dt, opt.recursive, iri, true); /*如果不递归*/
- 1369 }
复制代码
- 1、___________--------->
- 190 uerr_t
- 191 retrieve_tree (struct url *start_url_parsed, struct iri *pi)
- 192 {
- 193 uerr_t status = RETROK;
- 194
- 195
- 196 struct url_queue *queue; /*因为是递归,所以要使用队列来保证实现====>
- 68 struct url_queue {
- 69 struct queue_element *head; ======>
- 70 struct queue_element *tail;
- 71 int count, maxcount;
- 72 };
-
- */
- +++++++++++++++++=========>
- /*其中为各个的值,url参数*/
- 56 struct queue_element {
- 57 const char *url; /* the URL to download */
- 58 const char *referer; /* the referring document */
- 59 int depth; /* the depth */
- 60 bool html_allowed; /* whether the document is allowed to
- 61 be treated as HTML. */
- 62 struct iri *iri; /* sXXXav */
- 63 bool css_allowed; /* whether the document is allowed to
- 64 be treated as CSS. */
- 65 struct queue_element *next; /* next element in queue */
- 66 };
- */
- 197
- /*url地址,我们不想让它进入队列,因为它们已经在队列中。这里我们还没有下载*/
- 200 struct hash_table *blacklist; /*=======>将已经进入队列的,放入hash表中*/
- 202 struct iri *i = iri_new ();
复制代码
- 156 struct hash_table {
- 157 hashfun_t hash_function;
- 158 testfun_t test_function;
- 159
- 160 struct cell *cells; /* contiguous array of cells. 连续的数组单元*/
- 161 int size; /* size of the array. 数组的大小*/
- 162
- 163 int count; /* number of occupied entries. 已经被占的大小*/
- 164 int resize_threshold; /* after size exceeds this number of
- 165 entries, resize the table. 如果超过,重置大小*/
- 166 int prime_offset; /* the offset of the current prime in
- 167 the prime table. 在hash表中的偏移地址*/
- 168 };
- /*单元内存放索引值和数值*/
- 148 struct cell {
- 149 void *key;
- 150 void *value;
- 151 };
复制代码
- <----------___________
- /src/recur.c
- 213 set_uri_encoding (i, opt.locale, true); /*设置编码*/
- 216 queue = url_queue_new (); 2、__________----------->
- 217 blacklist = make_string_hash_table (0); 3、_____________---------->
- 218
- 221 url_enqueue (queue, i, xstrdup (start_url_parsed->url), NULL, 0, true,
- 222 false); 4、_____________-------------->
- 223 string_set_add (blacklist, start_url_parsed->url);
复制代码
- 2、____________----------->
- 76 static struct url_queue *
- 77 url_queue_new (void)
- 78 {
- 79 struct url_queue *queue = xnew0 (struct url_queue);/*分配前测试堆栈大小,如果正常就返回一个数据结构*/
- 80 return queue;
- 81 }
复制代码
- 3、________________--------------->
- 665 struct hash_table *
- 666 make_string_hash_table (int items)
- 667 {
- 668 return hash_table_new (items, hash_string, cmp_string);5、__________-------->
- 669 }
复制代码
- 5、_____------>
- 272 struct hash_table *
- 273 hash_table_new (int items,
- 274 unsigned long (*hash_function) (const void *), /*调用hash_string(const void *)函数 6、__________------------->*/
- 275 int (*test_function) (const void *, const void *)) /*调用typedef int (*testfun_t) (const void *, const void *);7、_______---------> */
- 276 {
- 277 int size;
- 278 struct hash_table *ht = xnew (struct hash_table); /*分配一个新的hash_table的值*/
- 279
- 280 ht->hash_function = hash_function ? hash_function : hash_pointer; /*如果hash_fuction为NULL,那么就用hash_pointer()函数*/
- 281 ht->test_function = test_function ? test_function : cmp_pointer;
- 282
-
- 285 ht->prime_offset = 0;
- 286
- 289 size = 1 + items / HASH_MAX_FULLNESS; /*#define HASH_MAX_FULLNESS 0.75。
- 290 size = prime_size (size, &ht->prime_offset); /*返回一个给定的值,一开始是0,还是指针是指向0的。8、_____----->*/
- 291 ht->size = size; /*存储在hash_table中的对应位置*/
- 292 ht->resize_threshold = size * HASH_MAX_FULLNESS;
- 294
- 295 ht->cells = xnew_array (struct cell, ht->size); /*分配一个sizeof(struct cell) * ht->size大小.
- 296 /*将ht->cell设置成 0xffffffff最大值*/
- 299 memset (ht->cells, INVALID_PTR_CHAR, size * sizeof (struct cell));
- 300
- 301 ht->count = 0; /*ht->count 没有被其他占用*/
- 302
- 303 return ht;
复制代码
- 6、____________-------------->
- 642 hash_string (const void *key) /*hash函数,将地址用以下计算方式获得一个unsigned int*/
- 643 {
- 644 const char *p = key; /*地址*/
- 645 unsigned int h = *p;
- 646
- 647 if (h)
- 648 for (p += 1; *p != '\0'; p++)
- 649 h = (h << 5) - h + *p; /*hash方程计算hash值*/
- 650
- 651 return h;
- 652 }
复制代码
- 8、______________------------->
- 215 static int
- 216 prime_size (int size, int *prime_offset)
- 217 {
- 218 static const int primes[] = { /*hash 表*/
- 219 13, 19, 29, 41, 59, 79, 107, 149, 197, 263, 347, 457, 599, 787, 1031,
- 220 1361, 1777, 2333, 3037, 3967, 5167, 6719, 8737, 11369, 14783,
- 221 19219, 24989, 32491, 42257, 54941, 71429, 92861, 120721, 156941,
- 222 204047, 265271, 344857, 448321, 582821, 757693, 985003, 1280519,
- 223 1664681, 2164111, 2813353, 3657361, 4754591, 6180989, 8035301,
- 224 10445899, 13579681, 17653589, 22949669, 29834603, 38784989,
- 225 50420551, 65546729, 85210757, 110774011, 144006217, 187208107,
- 226 243370577, 316381771, 411296309, 534685237, 695090819, 903618083,
- 227 1174703521, 1527114613, 1837299131, 2147483647
- 228 };
- 229 size_t i;
- 230
- 231 for (i = *prime_offset; i < countof (primes); i++)
- 232 if (primes[i] >= size)
- 233 {
- 239 *prime_offset = i + 1;
- 240 return primes[i]; /*返回的是个规定的值*/
- 241 }
- 242 abort();
- }
复制代码 |
|