下面就是运行修改default的设置了。
- 983 switch (opt->type)
- 984 {
- 985 case OPT_VALUE: /*如果得到的是含有参数的选项*/
- 986 setoptval (opt->data, optarg, opt->long_name); /*1、______--------->
- 987 break;
复制代码- 781 void
- 782 setoptval (const char *com, const char *val, const char *optname)/*com就是命令了,val是选项参数,optname就是长选项的名字*/
- 783 {
- 784 /* Prepend "--" to OPTNAME. */
- 785 char *dd_optname = (char *) alloca (2 + strlen (optname) + 1);
- 786 dd_optname[0] = '-';
- 787 dd_optname[1] = '-';
- 788 strcpy (dd_optname + 2, optname); /*前面几个是在optname前面加上 "--"符号*/
- 789
- 790 assert (val != NULL);
- 791 if (!setval_internal (command_by_name (com), dd_optname, val))/*2、_______----->重要的函数在这里*/
- 792 exit (2);
- 793 }
复制代码- /*这是折半法查找对应项的索引值。就是commands[]中的数组下标,找到返回此下标,如果没有就返回 -1 。*/
- 274 static int
- 275 command_by_name (const char *cmdname)
- 276 {
- 277 /* Use binary search for speed. Wget has ~100 commands, which
- 278 guarantees a worst case performance of 7 string comparisons. */
- 279 int lo = 0, hi = countof (commands) - 1;
- 280
- 281 while (lo <= hi)
- 282 {
- 283 int mid = (lo + hi) >> 1;
- 284 int cmp = strcasecmp (cmdname, commands[mid].name);
- 285 if (cmp < 0)
- 286 hi = mid - 1;
- 287 else if (cmp > 0)
- 288 lo = mid + 1;
- 289 else
- 290 return mid;
- 291 }
- 292 return -1;
- }
- [code]
- 732 static bool
- 733 setval_internal (int comind, const char *com, const char *val) /*
- 734 {
- 735 assert (0 <= comind && ((size_t) comind) < countof (commands));
- 736 DEBUGP (("Setting %s (%s) to %s\n", com, commands[comind].name, val));
- 737 return commands[comind].action (com, val, commands[comind].place);/*这里就又一步处理解析过程3、________---------->*/
- 738 }
复制代码- commands[comind].action() ,其中有这几中类型:
- 117 { "accept", &opt.accepts, cmd_vector },
- 118 { "addhostdir", &opt.add_hostdir, cmd_boolean },
- 126 { "backups", &opt.backups, cmd_number },
- 127 { "base", &opt.base_href, cmd_string },
- 130 { "cacertificate", &opt.ca_cert, cmd_file },
- 134 { "cadirectory", &opt.ca_directory, cmd_directory },
- 135 { "certificate", &opt.cert_file, cmd_file },
- 136 { "certificatetype", &opt.cert_type, cmd_cert_type },
- etc*/
- 这些都是去改变command[]数组中的place的值*/
- 因为类似这里只说一个*/
复制代码- 957 static bool
- 958 cmd_vector (const char *com, const char *val, void *place) /*place是指
- 959 {
- 960 char ***pvec = (char ***)place;
- 961
- 962 if (*val)
- 963 *pvec = merge_vecs (*pvec, sepstring (val));/sepstring()将参数再次解析成以数粗形式存储的变量4、___------------->*/
复制代码- 1310 char **
- 1311 merge_vecs (char **v1, char **v2)
- 1312 {
- 1313 int i, j;
- 1314
- 1315 if (!v1)
- 1316 return v2;
- 1317 if (!v2)
- 1318 return v1;
- 1319 if (!*v2)
- 1320 {
- 1321 /* To avoid j == 0 */
- 1322 xfree (v2);
- 1323 return v1; /*如果参数是0的话,那么就采用默认值*/
- 1324 }
- 1325 /* Count v1. */
- 1326 for (i = 0; v1[i]; i++)
- 1327 ;
- 1328 /* Count v2. */
- 1329 for (j = 0; v2[j]; j++)
- 1330 ;
- 1331 /* Reallocate v1. */
- 1332 v1 = xrealloc (v1, (i + j + 1) * sizeof (char **));
- 1333 memcpy (v1 + i, v2, (j + 1) * sizeof (char *));
- 1334 xfree (v2);
- 1335 return v1;
- 1336 }
复制代码/*这里是改变commands[]数组中 *place的内容,就是改变的当初defaults[]的内容*/
- 下面就是一系列的判断,如果出错就打印出来*/
- 比如
- if(!opt.locale)
- opt.locale = find_locale(); /*最终为系统调用*/
- 1202 if (opt.ask_passwd)
- 1203 {
- 1204 opt.passwd = prompt_for_password (); /*接受密码6、________----->*/
- 1205
- 1206 if (opt.passwd == NULL || opt.passwd[0] == '\0')
- 1207 exit (1);
- 1208 }
复制代码- 6、________---------->
- static char *prompt_for_password(void)
- {
- . . .
- return getpass(""); /*接受函数*/
- }
复制代码- 86 char *
- 87 getpass (const char *prompt)
- 88 {
- 89 FILE *tty;
- 90 FILE *in, *out;
- 91 struct termios s, t;
- 92 bool tty_changed = false;
- 93 static char *buf;
- 94 static size_t bufsize;
- 95 ssize_t nread;
- 96
- 97 /* Try to write to and read from the terminal if we can.
- 98 If we can't open the terminal, use stderr and stdin. */
- 99
- 100 tty = fopen ("/dev/tty", "w+");
- 101 if (tty == NULL) /*如果可以从终端输入打开终端设备文件,进行输入*/
- 102 {
- 103 in = stdin; /*如果没有,那么用标准输入进行输出*/
- 104 out = stderr; /*输出文件为stderr*/
- 105 }
- 106 else
- 107 {
- 108 /* We do the locking ourselves. */
- 109 __fsetlocking (tty, FSETLOCKING_BYCALLER);
- 110
- 111 out = in = tty;
- 112 }
- 113
- 114 flockfile (out);
- . . . . . . /*省略的是对文件进行加锁*/
- 133 nread = getline (&buf, &bufsize, in);
阅读(993) | 评论(0) | 转发(0) |