继续分析
下面这一段,当 initdb --version 或者 initdb --help 才有意义。
if (argc > )
{ if (strcmp(argv[], "--help") == || strcmp(argv[], "-?") == )
{
usage(progname);
exit();
}
if (strcmp(argv[], "--version") == || strcmp(argv[], "-V") == )
{
puts("initdb (PostgreSQL) " PG_VERSION);
exit();
}
}
再看下一段:
实际上就是 initdb 运行时候,后面可以跟各种参数。我这里只考虑 -D那种就好了
/* process command-line options */
while ((c = getopt_long(argc, argv, "dD:E:L:nU:WA:sT:X:", long_options, &option_index)) != -)
{
switch (c)
{
case 'A':
authmethod = xstrdup(optarg);
break;
case 'D':
pg_data = xstrdup(optarg);
break;
case 'E':
encoding = xstrdup(optarg);
break;
case 'W':
pwprompt = true;
break;
case 'U':
username = xstrdup(optarg);
break;
case 'd':
debug = true;
printf(_("Running in debug mode.\n"));
break;
case 'n':
noclean = true;
printf(_("Running in noclean mode. Mistakes will not be cleaned up.\n"));
break;
case 'L':
share_path = xstrdup(optarg);
break;
case :
locale = xstrdup(optarg);
break;
case :
lc_collate = xstrdup(optarg);
break;
case :
lc_ctype = xstrdup(optarg);
break;
case :
lc_monetary = xstrdup(optarg);
break;
case :
lc_numeric = xstrdup(optarg);
break;
case :
lc_time = xstrdup(optarg);
break;
case :
lc_messages = xstrdup(optarg);
break;
case :
locale = "C";
break;
case :
pwfilename = xstrdup(optarg);
break;
case 's':
show_setting = true;
break;
case 'T':
default_text_search_config = xstrdup(optarg);
break;
case 'X':
xlog_dir = xstrdup(optarg);
break;
default:
/* getopt_long already emitted a complaint */
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit();
}
}
也就是这段:
case 'D':
pg_data = xstrdup(optarg);
break;