Chinaunix首页 | 论坛 | 博客

分类: LINUX

2011-10-11 21:46:45

  选项部分终于要结束了
分析initialize();
  1. {
  2. 591 {
  3. 592   char *file, *env_sysrc;
  4. 593   bool ok = true;
  5. 601 #ifdef SYSTEM_WGETRC
  6. 602   else if (file_exists_p (SYSTEM_WGETRC)) /*  1、________------>判断文件是否存在,如果存在,就去读取里面内容作判断*/
  7. 603     ok &= run_wgetrc (SYSTEM_WGETRC);
  8. 604 #endif
  9. 607   if (! ok)
  10. 608     {
  11. 609       fprintf (stderr, _()); /*打印出错误*/
  12. 615    file = wgetrc_file_name ();  /*这里是如果存在,就从新写2、________---------->*/

  13. 629     ok &= run_wgetrc (file);
复制代码
  1. 1、________------------->
  2. 538 file_exists_p (const char *filename)
  3. 539 {     
  4. 540 #ifdef HAVE_ACCESS
  5. 541   return access (filename, F_OK) >= 0; /*如果已经访问过了,就判断是否还在这个是系统调用
  6. */
  7. 542 #else
  8. 543   struct_stat buf;
  9. 544   return stat (filename, &buf) >= 0;  /*这个是读取文件状态*/
  10. 545 #endif
  11. 546 }
复制代码

  1. 2、___________--------->
  2. 478 char *
  3. 479 wgetrc_file_name (void)
  4. 480 {
  5. 481   char *file = wgetrc_env_file_name (); 3、_____----->/*根据环境变量WGETRC获得文件*/
  6. 482   if (file && *file)
  7. 483     return file;
  8. 484
  9. 485   file = wgetrc_user_file_name (); /*4、_____----->这里是检查~home/.wgetrc文件,如果有就返回此路径*/
复制代码
  1. 3、_________________------>
  2. 428 char *
  3. 429 wgetrc_env_file_name (void)
  4. 430 {
  5. 431   char *env = getenv ("WGETRC"); /*   env是指向此环境变量的指针 ,我理解的就是目录*/
  6. 432   if (env && *env)
  7. 433     {
  8. 434       if (!file_exists_p (env)) /*如果有WGETRC存在,但是文件却不存在,那么就直接退出*/
  9. 435         {
  10. 436           fprintf (stderr, _("%s: WGETRC points to %s, which does't exist.\n"),
  11. 437                    exec_name, env);
  12. 438           exit (1);
  13. 439         }
  14. 440       return xstrdup (env);  /*如果文件存在,就在此env地址从写环境变量的值*/
  15. 441     }
  16. 442   return NULL;  /*如果没有此环境变量,或者指向的字符串是NULL。那么返回NULL。
  17. 443 }
复制代码
4、______________----------->
  1. 447 char *
  2. 448 wgetrc_user_file_name (void)
  3. 449 {
  4. 450   char *home;
  5. 451   char *file = NULL;
  6. 452   /* If that failed, try $HOME/.wgetrc (or equivalent).  */
  7. 453
  8. 454 #ifdef __VMS         /*vms格式下的路径名*/
  9. 455   file = "SYS$LOGIN:.wgetrc";
  10. 456 #else /* def __VMS */
  11. 457   home = home_dir ();  /*这是获得home的环境变量值*/
  12. 458   if (home)
  13. 459     file = aprintf ("%s/.wgetrc", home); /*一种打印方式。*/
  14. 460   xfree_null (home);  
  15. 461 #endif /* def __VMS [else] */
  16. 462
  17. 463   if (!file)
  18. 464     return NULL;
  19. 465   if (!file_exists_p (file))
  20. 466     {
  21. 467       xfree (file);
  22. 468       return NULL;
  23. 469     }
  24. 470   return file; /*返回文件名*/
  25. 471 }
  26. 472
复制代码
<-----------________________
  1. 从initialize()返回,又是刚才的根据用户输入进行初始化*/
  2. while ((ret = getopt_long (argc, argv,  short_options, long_options, &longindex)) != -1)
  3. 965       if (longindex == -1)  /*如果此值没有变只有找到一个相匹配的长选项才会改变此longindex的值。如果返回?这个字符说明说明长选项或者 没有参数 短选项不为:*/
  4. 966         {
  5. 967           if (ret == '?')  /*此时返回为?那么就--help*/
  6. 968             {
  7. 969               print_usage (0);
  8. 970               printf ("\n");
  9. 971               printf (_("Try `%s --help' for more options.\n"), exec_name     );
  10. 972               exit (2);
  11. 973             }
  12. 974           /* Find the short option character in the mapping.  */
  13. 975           longindex = optmap[ret - 32]; /*找到 /*找到相应的长选项*/
  14. 976         }
  15. 977       val = long_options[longindex].val; /*根据检索到longindex来获得val的值*/
  16. 982       opt = &option_data[val & ~BOOLEAN_NEG_MARKER]; /*获得那个option_data数组中对应元素*/  
  17. 983       switch (opt->type) /*根据cmdline_option类型,用optarg来设置相应修改opt->data*/
  18. 984         {
  19. 985         case OPT_VALUE:
  20. 986          setoptval (opt->data, optarg, opt->long_name); 5、________------->
  21. 987           break;
  22. 988         case OPT_BOOLEAN:
  23. 989           if (optarg)
  24. . . . . .
  25. }
复制代码
  1. 5、____________------------->
  2. 781 void
  3. 782 setoptval (const char *com, const char *val, const char *optname)
  4. 783 {     
  5. 784   /* Prepend "--" to OPTNAME. */  
  6. 785   char *dd_optname = (char *) alloca (2 + strlen (optname) + 1); /*设置成--optname*/
  7. 786   dd_optname[0] = '-';
  8. 787   dd_optname[1] = '-';
  9. 788   strcpy (dd_optname + 2, optname);
  10. 789
  11. 790   assert (val != NULL);
  12. 791   if (!setval_internal (command_by_name (com), dd_optname, val)) 检查是否有命令错误,或者参数,并且最后一步是运行此命令*/
  13. 792     exit (2);
  14. 793 }
  15. 7、______------------->
  16. 733 setval_internal (int comind, const char *com, const char *val)
  17. 734 {
  18. 735   assert (0 <= comind && ((size_t) comind) < countof (commands));
  19. 736   DEBUGP (("Setting %s (%s) to %s\n", com, commands[comind].name, val));
  20. 737   return commands[comind].action (com, val, commands[comind].place); /*最后一步是运行命令*/
  21. 738 }
  22. 例如:这里是com是 accept,commands[comind].place 这里是  &opt.accepts, val是参数*/
复制代码
  1. 调用的是rpl
  2. 29 #undef accept

  3. 32 rpl_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
  4. 33 {
  5. 34   SOCKET fh = accept (FD_TO_SOCKET (fd), addr, addrlen); /*这是接受网络请求的函数系统调用来了!*/
  6. 35   if (fh == INVALID_SOCKET)  /*在linux下是不可能失败的*/
  7. 36     {
  8. 37       set_winsock_errno (); /*如果是无效的sock文件,那么就返回-1。*/
  9. 38       return -1;
  10. 39     }
  11. 40   else
  12. 41     return SOCKET_TO_FD (fh); /*否则就将改变文件的属性,*/
  13. 42 }  
  14. 29 #define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINAR    Y))
  15. /*这里是windows系统调用函数*/
阅读(1413) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~