Chinaunix首页 | 论坛 | 博客

分类: LINUX

2011-10-12 20:27:01

  1. 回到main.c函数
  2. 1343       if (!url_parsed)  /*当然如果没有输入错的话,肯定是不为NULL的*/
  3. 1344         {
  4. 1345           char *error = url_error (*t, url_err);
  5. 1346           logprintf (LOG_NOTQUIET, "%s: %s.\n",*t, error);
  6. 1347           xfree (error);
  7. 1348           inform_exit_status (URLERROR);
  8. 1349         }
  9. 1350       else  /*进入这里*/
  10. 1351         {
  11. 1352           if ((opt.recursive || opt.page_requisites)  /*如果递归&&使用代理或者不是FTP协议*/
  12. 1353               && (url_scheme (*t) != SCHEME_FTP || url_uses_proxy (url_parsed)))
  13. 1354             {
  14. 1355               int old_follow_ftp = opt.follow_ftp;
  15. 1356
  16. 1357               /* Turn opt.follow_ftp on in case of recursive FTP retrieval      */
  17. 1358               if (url_scheme (*t) == SCHEME_FTP)
  18. 1359                 opt.follow_ftp = 1;  
  19. 1360
  20. 1361               retrieve_tree (url_parsed, NULL); /*1、_________------------->
  21. 1362
  22. 1363               opt.follow_ftp = old_follow_ftp;
  23. 1364             }
  24. 1365           else
  25. 1366           {
  26. 1367             retrieve_url (url_parsed, *t, &filename, &redirected_URL, NULL,
  27. 1368                           &dt, opt.recursive, iri, true);
  28. 1369           }
复制代码
  1. 1、___________--------->
  2. 190 uerr_t
  3. 191 retrieve_tree (struct url *start_url_parsed, struct iri *pi)
  4. 192 {
  5. 193   uerr_t status = RETROK;
  6. 194
  7. 195   
  8. 196   struct url_queue *queue;  /*因为是递归,所以要使用队列来保证实现====>
  9.              68 struct url_queue {
  10.              69   struct queue_element *head; ======>
  11.              70   struct queue_element *tail;
  12.              71   int count, maxcount;
  13.               72 };
  14.                                             
  15. */
  16. +++++++++++++++++=========>
  17. /*其中为各个的值,url参数*/
  18. 56 struct queue_element {
  19. 57   const char *url;              /* the URL to download */
  20. 58   const char *referer;          /* the referring document */
  21. 59   int depth;                    /* the depth */
  22. 60   bool html_allowed;            /* whether the document is allowed to
  23. 61                                    be treated as HTML. */
  24. 62   struct iri *iri;                /* sXXXav */
  25. 63   bool css_allowed;             /* whether the document is allowed to
  26. 64                                    be treated as CSS. */
  27. 65   struct queue_element *next;   /* next element in queue */
  28. 66 };
  29. */   
  30. 197
  31.           /*url地址,我们不想让它进入队列,因为它们已经在队列中。这里我们还没有下载*/
  32. 200   struct hash_table *blacklist;  /*=======>将已经进入队列的,放入hash表中*/
  33. 202   struct iri *i = iri_new ();
复制代码
  1. 156 struct hash_table {
  2. 157   hashfun_t hash_function;  
  3. 158   testfun_t test_function;
  4. 159   
  5. 160   struct cell *cells;           /* contiguous array of cells. 连续的数组单元*/
  6. 161   int size;                     /* size of the array. 数组的大小*/
  7. 162      
  8. 163   int count;                    /* number of occupied entries. 已经被占的大小*/
  9. 164   int resize_threshold;         /* after size exceeds this number of
  10. 165                                    entries, resize the table.   如果超过,重置大小*/
  11. 166   int prime_offset;             /* the offset of the current prime in
  12. 167                                    the prime table.  在hash表中的偏移地址*/
  13. 168 };
  14. /*单元内存放索引值和数值*/
  15. 148 struct cell {
  16. 149   void *key;
  17. 150   void *value;
  18. 151 };
复制代码
  1. <----------___________
  2. /src/recur.c
  3. 213     set_uri_encoding (i, opt.locale, true); /*设置编码*/

  4. 216   queue = url_queue_new ();  2、__________----------->
  5. 217   blacklist = make_string_hash_table (0); 3、_____________---------->
  6. 218   

  7. 221   url_enqueue (queue, i, xstrdup (start_url_parsed->url), NULL, 0, true,
  8. 222                false);         4、_____________-------------->
  9. 223   string_set_add (blacklist, start_url_parsed->url);
复制代码
  1. 2、____________----------->
  2. 76 static struct url_queue *
  3. 77 url_queue_new (void)
  4. 78 {
  5. 79   struct url_queue *queue = xnew0 (struct url_queue);/*分配前测试堆栈大小,如果正常就返回一个数据结构*/
  6. 80   return queue;
  7. 81 }
复制代码
  1. 3、________________--------------->
  2. 665 struct hash_table *
  3. 666 make_string_hash_table (int items)
  4. 667 {
  5. 668   return hash_table_new (items, hash_string, cmp_string);5、__________-------->
  6. 669 }
复制代码
  1. 5、_____------>
  2. 272 struct hash_table *
  3. 273 hash_table_new (int items,
  4. 274                 unsigned long (*hash_function) (const void *), /*调用hash_string(const void *)函数 6、__________------------->*/
  5. 275                 int (*test_function) (const void *, const void *)) /*调用typedef int (*testfun_t) (const void *, const void *);7、_______---------> */
  6. 276 {
  7. 277   int size;
  8. 278   struct hash_table *ht = xnew (struct hash_table); /*分配一个新的hash_table的值*/
  9. 279
  10. 280   ht->hash_function = hash_function ? hash_function : hash_pointer; /*如果hash_fuction为NULL,那么就用hash_pointer()函数*/
  11. 281   ht->test_function = test_function ? test_function : cmp_pointer;
  12. 282
  13.   
  14. 285   ht->prime_offset = 0;
  15. 286
  16. 289   size = 1 + items / HASH_MAX_FULLNESS;  /*#define HASH_MAX_FULLNESS 0.75。
  17. 290   size = prime_size (size, &ht->prime_offset);  /*返回一个给定的值8、_____----->*/
  18. 291   ht->size = size;                     /*存储在hash_table中的对应位置*/
  19. 292   ht->resize_threshold = size * HASH_MAX_FULLNESS;
  20. 294
  21. 295   ht->cells = xnew_array (struct cell, ht->size); /*分配一个sizeof(struct cell) * ht->size大小.
  22. 296
  23. 299   memset (ht->cells, INVALID_PTR_CHAR, size * sizeof (struct cell));
  24. 300
  25. 301   ht->count = 0;
  26. 302
  27. 303   return ht;
复制代码
  1. 6、____________-------------->
  2. 642 hash_string (const void *key)  /*hash函数,将地址用以下计算方式获得一个unsigned int*/
  3. 643 {
  4. 644   const char *p = key;  /*地址*/
  5. 645   unsigned int h = *p;
  6. 646
  7. 647   if (h)
  8. 648     for (p += 1; *p != '\0'; p++)
  9. 649       h = (h << 5) - h + *p;  /*hash方程计算hash值*/
  10. 650
  11. 651   return h;
  12. 652 }
复制代码
[code]
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 >= size)
233       {
239         *prime_offset = i + 1;
240         return primes; /*返回的是个规定的值*/
241       }
242  abort();
}
阅读(1971) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~