Chinaunix首页 | 论坛 | 博客

分类: LINUX

2011-10-05 09:56:57

下面是i18n_initalize() /*关于字符集的设置*/

107 static void
108 i18n_initialize (void)
109 {
110   /* ENABLE_NLS implies existence of functions invoked here.  */
111 #ifdef ENABLE_NLS
112   /* Set the current locale.  */
113   setlocale (LC_ALL, "");   /*系统调用设定LC_ALL为环境中的字符集*/
114   /* Set the text message domain.  */
115   bindtextdomain ("wget", LOCALEDIR);  /*linux i18n中每个资源文件都是.mo文件,LOCAL_PATH指定寻找.mo文件路径,此处是wget.mo路径在当前目录。因为LOCALEDIR是" "。
116   textdomain ("wget");  /*wget命令使用wget.mo*/
117 #endif /* ENABLE_NLS */
118 }
main( . . .)
{
. . . . . .
[code]
899   /* Construct the name of the executable, without the directory part.  */
900 #ifdef __VMS
901   /* On VMS, lose the "dev:[dir]" prefix and the ".EXE;nnn" suffix. */ 902   exec_name = vms_basename (argv[0]); /*VMS是no-unix路径名.这里是做一些转化*/
903 #else /* def __VMS */
904   exec_name = strrchr (argv[0], PATH_SEPARATOR); /*找到wget的名字。/x/x/wget运行shell命令时,此就是取wget,或者直接取wget因为那是链接文件,没关系,仍然运行了wget 并且取到了名字wget*/
905   if (!exec_name)
906     exec_name = argv[0];
907   else
908     ++exec_name;
909 #endif /* def __VMS [else] */
910
911 #ifdef WINDOWS  /*如果是Windows环境*/
912   /* Drop extension (typically .EXE) from executable filename. */
913   windows_main ((char **) &exec_name); /*可执行文件中有suffix.exe。要去掉1、____________-------->/mswindows.c*/
914 #endif
915
916   /* Load the hard-coded defaults.  */
917   defaults ();  /3、________--------->*src/init.c*/
918
919   init_switches (); /*4________------>main.c这是初始化options wget - x*/
1、_______-------->
77 windows_main (char **exec_name)
78 {  
79   char *p;
80
81   /* Remove .EXE from filename if it has one.  */
82   *exec_name = xstrdup (*exec_name); 2、_______------>这里分配名字空间来处理。lib/ xmalloc.c*/
83   p = strrchr (*exec_name, '.');  /*这里是真正去掉了.exe*/
84   if (p)
85     *p = '\0';   /*此步将字符串去掉了.exe*/
86 }
2、__________------------->
120 char *
121 xstrdup (char const *string)
122 {
123   return xmemdup (string, strlen (string) + 1);
124 }
112 void *
113 xmemdup (void const *p, size_t s)
114 {
115   return memcpy (xmalloc (s), p, s);
116 }
3、_____------------>
/*初始化很多默认的参数*/
296 void
297 defaults (void)
298 {
299   char *tmp;
300   
301   /* Most of the default values are 0 (and 0.0, NULL, and false).
302      Just reset everything, and fill in the non-zero values.  Note
303      that initializing pointers to NULL this way is technically
304      illegal, but porting Wget to a machine where NULL is not all-zero
305      bit pattern will be the least of the implementors' worries.  */
306   xzero (opt);
307   
308   opt.cookies = true;
309   opt.verbose = -1;
310   opt.ntry = 20;
311   opt.reclevel = 5;
312   opt.add_hostdir = true;      
313   opt.netrc = true;
314   opt.ftp_glob = true;
315   opt.htmlify = true;
316   opt.http_keep_alive = true;
317   opt.use_proxy = true;
318   tmp = getenv ("no_proxy");
319   if (tmp)
320     opt.no_proxy = sepstring (tmp);
321   opt.prefer_family = prefer_none;
322   opt.allow_cache = true;
323
324   opt.read_timeout = 900;
325   opt.use_robots = true;
326
327   opt.remove_listing = true;
328
329   opt.dot_bytes = 1024;
330   opt.dot_spacing = 10;
331   opt.dots_in_line = 50;
332
333   opt.dns_cache = true;
334   opt.ftp_pasv = true;
335
336 #ifdef HAVE_SSL
337   opt.check_cert = true;
338 #endif
339
340   /* The default for file name restriction defaults to the OS type. */
341 #if defined(WINDOWS) || defined(MSDOS) || defined(__CYGWIN__)
342   opt.restrict_files_os = restrict_windows;
343 #else
344   opt.restrict_files_os = restrict_unix;
345 #endif
346   opt.restrict_files_ctrl = true;
347   opt.restrict_files_nonascii = false;
348   opt.restrict_files_case = restrict_no_case_restriction;
349
350   opt.max_redirect = 20;
351
352   opt.waitretry = 10;
353
354 #ifdef ENABLE_IRI
355   opt.enable_iri = true;
356 #else
357   opt.enable_iri = false;
358 #endif
359   opt.locale = NULL;
360   opt.encoding_remote = NULL;
361
362   opt.useservertimestamps = true;
363   opt.show_all_dns_entries = false;
364 }
4_________---------->
331 static void
332 init_switches (void)
333 {
334   char *p = short_options;
335   size_t i, o = 0;
336   for (i = 0; i < countof (option_data); i++) /*+++===?*/
337     {
338       struct cmdline_option *opt = &option_data[i];
339       struct option *longopt;
340
341       if (!opt->long_name)
342   
343         continue;
344
345       longopt = &long_options[o++];
346       longopt->name = opt->long_name;
347       longopt->val = i;
348       if (opt->short_name)
349         {
350           *p++ = opt->short_name;
351           optmap[opt->short_name - 32] = longopt - long_options;
352         }
353       switch (opt->type)
354         {
355         case OPT_VALUE:
356           longopt->has_arg = required_argument;
357           if (opt->short_name)
358             *p++ = ':';
359           break;
. .. . . .. .
/*option_data的初始化表*/
157 static struct cmdline_option option_data[] =
158   {
159     { "accept", 'A', OPT_VALUE, "accept", -1 },
160     { "adjust-extension", 'E', OPT_BOOLEAN, "adjustextension", -1 },
161     { "append-output", 'a', OPT__APPEND_OUTPUT, NULL, required_argument },
162     { "ask-password", 0, OPT_BOOLEAN, "askpassword", -1 },
163     { "auth-no-challenge", 0, OPT_BOOLEAN, "authnochallenge", -1 },
164     { "background", 'b', OPT_BOOLEAN, "background", -1 },
165     { "backup-converted", 'K', OPT_BOOLEAN, "backupconverted", -1 },
166     { "backups", 0, OPT_BOOLEAN, "backups", -1 },
167     { "base", 'B', OPT_VALUE, "base", -1 },
168     { "bind-address", 0, OPT_VALUE, "bindaddress", -1 },
169     { IF_SSL ("ca-certificate"), 0, OPT_VALUE, "cacertificate", -1 },
170     { IF_SSL ("ca-directory"), 0, OPT_VALUE, "cadirectory", -1 },
. .. . . . .
}
/*cmdline_option 的格式*/
137 struct cmdline_option {
138   const char *long_name;
139   char short_name;
140   enum {
141     OPT_VALUE,
142     OPT_BOOLEAN,
143     OPT_FUNCALL,
144     /* Non-standard options that have to be handled specially in
145        main().  */
146     OPT__APPEND_OUTPUT,
147     OPT__CLOBBER,
148     OPT__DONT_REMOVE_LISTING,
149     OPT__EXECUTE,
150     OPT__NO,
151     OPT__PARENT
152   } type;
153   const void *data;             /* for standard options */
154   int argtype;                  /* for non-standard options */
155 };
阅读(1069) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~