本文整理汇总了C++中PG_TEXTDOMAIN函数的典型用法代码示例。如果您正苦于以下问题:C++ PG_TEXTDOMAIN函数的具体用法?C++ PG_TEXTDOMAIN怎么用?C++ PG_TEXTDOMAIN使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PG_TEXTDOMAIN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: libpq_binddomain
static void
libpq_binddomain()
{
static bool already_bound = false;
if (!already_bound)
{
/* bindtextdomain() does not preserve errno */
#ifdef WIN32
int save_errno = GetLastError();
#else
int save_errno = errno;
#endif
const char *ldir;
already_bound = true;
/* No relocatable lookup here because the binary could be anywhere */
ldir = getenv("PGLOCALEDIR");
if (!ldir)
ldir = LOCALEDIR;
bindtextdomain(PG_TEXTDOMAIN("libpq"), ldir);
#ifdef WIN32
SetLastError(save_errno);
#else
errno = save_errno;
#endif
}
}
示例2: main
int
main(int argc, char **argv)
{
int i;
int j;
int ret;
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_config"));
progname = get_progname(argv[0]);
/* check for --help */
for (i = 1; i < argc; i++)
{
if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0)
{
help();
exit(0);
}
}
ret = find_my_exec(argv[0], mypath);
if (ret)
{
fprintf(stderr, _("%s: could not find own program executable\n"), progname);
exit(1);
}
/* no arguments -> print everything */
if (argc < 2)
{
show_all();
exit(0);
}
for (i = 1; i < argc; i++)
{
for (j = 0; info_items[j].switchname != NULL; j++)
{
if (strcmp(argv[i], info_items[j].switchname) == 0)
{
(*info_items[j].show_func) (false);
break;
}
}
if (info_items[j].switchname == NULL)
{
fprintf(stderr, _("%s: invalid argument: %s\n"),
progname, argv[i]);
advice();
exit(1);
}
}
return 0;
}
示例3: set_pglocale_pgservice
/*
* set_pglocale_pgservice
*
* Set application-specific locale and service directory
*
* This function takes the value of argv[0] rather than a full path.
*
* (You may be wondering why this is in exec.c. It requires this module's
* services and doesn't introduce any new dependencies, so this seems as
* good as anyplace.)
*/
void
set_pglocale_pgservice(const char *argv0, const char *app)
{
char path[MAXPGPATH];
char my_exec_path[MAXPGPATH];
char env_path[MAXPGPATH + sizeof("PGSYSCONFDIR=")]; /* longer than
* PGLOCALEDIR */
char *dup_path;
/* don't set LC_ALL in the backend */
if (strcmp(app, PG_TEXTDOMAIN("postgres")) != 0)
{
setlocale(LC_ALL, "");
/*
* One could make a case for reproducing here PostmasterMain()'s test
* for whether the process is multithreaded. Unlike the postmaster,
* no frontend program calls sigprocmask() or otherwise provides for
* mutual exclusion between signal handlers. While frontends using
* fork(), if multithreaded, are formally exposed to undefined
* behavior, we have not witnessed a concrete bug. Therefore,
* complaining about multithreading here may be mere pedantry.
*/
}
if (find_my_exec(argv0, my_exec_path) < 0)
return;
#ifdef ENABLE_NLS
get_locale_path(my_exec_path, path);
bindtextdomain(app, path);
textdomain(app);
if (getenv("PGLOCALEDIR") == NULL)
{
/* set for libpq to use */
snprintf(env_path, sizeof(env_path), "PGLOCALEDIR=%s", path);
canonicalize_path(env_path + 12);
dup_path = strdup(env_path);
if (dup_path)
putenv(dup_path);
}
#endif
if (getenv("PGSYSCONFDIR") == NULL)
{
get_etc_path(my_exec_path, path);
/* set for libpq to use */
snprintf(env_path, sizeof(env_path), "PGSYSCONFDIR=%s", path);
canonicalize_path(env_path + 13);
dup_path = strdup(env_path);
if (dup_path)
putenv(dup_path);
}
}
示例4: set_pglocale_pgservice
/*
* set_pglocale_pgservice
*
* Set application-specific locale and service directory
*
* This function takes the value of argv[0] rather than a full path.
*
* (You may be wondering why this is in exec.c. It requires this module's
* services and doesn't introduce any new dependencies, so this seems as
* good as anyplace.)
*/
void
set_pglocale_pgservice(const char *argv0, const char *app)
{
char path[MAXPGPATH];
char my_exec_path[MAXPGPATH];
char env_path[MAXPGPATH + sizeof("PGSYSCONFDIR=")]; /* longer than
* PGLOCALEDIR */
/* don't set LC_ALL in the backend */
if (strcmp(app, PG_TEXTDOMAIN("postgres")) != 0)
setlocale(LC_ALL, "");
if (find_my_exec(argv0, my_exec_path) < 0)
return;
#ifdef ENABLE_NLS
get_locale_path(my_exec_path, path);
bindtextdomain(app, path);
textdomain(app);
if (getenv("PGLOCALEDIR") == NULL)
{
/* set for libpq to use */
snprintf(env_path, sizeof(env_path), "PGLOCALEDIR=%s", path);
canonicalize_path(env_path + 12);
putenv(strdup(env_path));
}
#endif
if (getenv("PGSYSCONFDIR") == NULL)
{
get_etc_path(my_exec_path, path);
/* set for libpq to use */
snprintf(env_path, sizeof(env_path), "PGSYSCONFDIR=%s", path);
canonicalize_path(env_path + 13);
putenv(strdup(env_path));
}
}
示例5: main
int
main(int argc, char *argv[])
{
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_test_fsync"));
progname = get_progname(argv[0]);
handle_args(argc, argv);
/* Prevent leaving behind the test file */
pqsignal(SIGINT, signal_cleanup);
pqsignal(SIGTERM, signal_cleanup);
#ifndef WIN32
pqsignal(SIGALRM, process_alarm);
#endif
#ifdef SIGHUP
/* Not defined on win32 */
pqsignal(SIGHUP, signal_cleanup);
#endif
prepare_buf();
test_open();
/* Test using 1 XLOG_BLCKSZ write */
test_sync(1);
/* Test using 2 XLOG_BLCKSZ writes */
test_sync(2);
test_open_syncs();
test_file_descriptor_sync();
test_non_sync();
unlink(filename);
return 0;
}
示例6: main
int
main(int argc, char *argv[])
{
static struct option long_options[] = {
{"list", no_argument, NULL, 'l'},
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"username", required_argument, NULL, 'U'},
{"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
{"dbname", required_argument, NULL, 'd'},
{"echo", no_argument, NULL, 'e'},
{NULL, 0, NULL, 0}
};
const char *progname;
int optindex;
int c;
bool listlangs = false;
const char *dbname = NULL;
char *host = NULL;
char *port = NULL;
char *username = NULL;
enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
char *langname = NULL;
char *p;
Oid lanplcallfoid;
Oid laninline;
Oid lanvalidator;
char *handler;
char *inline_handler;
char *validator;
char *handler_ns;
char *inline_ns;
char *validator_ns;
bool keephandler;
bool keepinline;
bool keepvalidator;
PQExpBufferData sql;
PGconn *conn;
PGresult *result;
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
handle_help_version_opts(argc, argv, "droplang", help);
while ((c = getopt_long(argc, argv, "lh:p:U:wWd:e", long_options, &optindex)) != -1)
{
switch (c)
{
case 'l':
listlangs = true;
break;
case 'h':
host = optarg;
break;
case 'p':
port = optarg;
break;
case 'U':
username = optarg;
break;
case 'w':
prompt_password = TRI_NO;
break;
case 'W':
prompt_password = TRI_YES;
break;
case 'd':
dbname = optarg;
break;
case 'e':
echo = true;
break;
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
}
if (argc - optind > 0)
{
if (listlangs)
dbname = argv[optind++];
else
{
langname = argv[optind++];
if (argc - optind > 0)
dbname = argv[optind++];
}
}
if (argc - optind > 0)
{
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
progname, argv[optind]);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
//.........这里部分代码省略.........
示例7: main
int
main(int argc, char *argv[])
{
ControlFileData ControlFile;
int fd;
char ControlFilePath[MAXPGPATH];
char *DataDir;
pg_crc32 crc;
time_t time_tmp;
char pgctime_str[128];
char ckpttime_str[128];
char sysident_str[32];
const char *strftime_fmt = "%c";
const char *progname;
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_controldata"));
progname = get_progname(argv[0]);
if (argc > 1)
{
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
{
usage(progname);
exit(0);
}
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
{
puts("pg_controldata (PostgreSQL) " PG_VERSION);
exit(0);
}
}
if (argc > 1)
DataDir = argv[1];
else
DataDir = getenv("PGDATA");
if (DataDir == NULL)
{
fprintf(stderr, _("%s: no data directory specified\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
if ((fd = open(ControlFilePath, O_RDONLY | PG_BINARY, 0)) == -1)
{
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
progname, ControlFilePath, strerror(errno));
exit(2);
}
if (read(fd, &ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData))
{
fprintf(stderr, _("%s: could not read file \"%s\": %s\n"),
progname, ControlFilePath, strerror(errno));
exit(2);
}
close(fd);
/* Check the CRC. */
INIT_CRC32(crc);
COMP_CRC32(crc,
(char *) &ControlFile,
offsetof(ControlFileData, crc));
FIN_CRC32(crc);
if (!EQ_CRC32(crc, ControlFile.crc))
printf(_("WARNING: Calculated CRC checksum does not match value stored in file.\n"
"Either the file is corrupt, or it has a different layout than this program\n"
"is expecting. The results below are untrustworthy.\n\n"));
/*
* This slightly-chintzy coding will work as long as the control file
* timestamps are within the range of time_t; that should be the case in
* all foreseeable circumstances, so we don't bother importing the
* backend's timezone library into pg_controldata.
*
* Use variable for format to suppress overly-anal-retentive gcc warning
* about %c
*/
time_tmp = (time_t) ControlFile.time;
strftime(pgctime_str, sizeof(pgctime_str), strftime_fmt,
localtime(&time_tmp));
time_tmp = (time_t) ControlFile.checkPointCopy.time;
strftime(ckpttime_str, sizeof(ckpttime_str), strftime_fmt,
localtime(&time_tmp));
/*
* Format system_identifier separately to keep platform-dependent format
* code out of the translatable message string.
*/
snprintf(sysident_str, sizeof(sysident_str), UINT64_FORMAT,
ControlFile.system_identifier);
printf(_("pg_control version number: %u\n"),
ControlFile.pg_control_version);
if (ControlFile.pg_control_version % 65536 == 0 && ControlFile.pg_control_version / 65536 != 0)
printf(_("WARNING: possible byte ordering mismatch\n"
//.........这里部分代码省略.........
示例8: main
int
main(int argc, char *argv[])
{
static int if_exists = 0;
static struct option long_options[] = {
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"username", required_argument, NULL, 'U'},
{"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
{"echo", no_argument, NULL, 'e'},
{"interactive", no_argument, NULL, 'i'},
{"if-exists", no_argument, &if_exists, 1},
{"maintenance-db", required_argument, NULL, 2},
{NULL, 0, NULL, 0}
};
const char *progname;
int optindex;
int c;
char *dbname = NULL;
char *maintenance_db = NULL;
char *host = NULL;
char *port = NULL;
char *username = NULL;
enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
bool interactive = false;
PQExpBufferData sql;
PGconn *conn;
PGresult *result;
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
handle_help_version_opts(argc, argv, "dropdb", help);
while ((c = getopt_long(argc, argv, "h:p:U:wWei", long_options, &optindex)) != -1)
{
switch (c)
{
case 'h':
host = pg_strdup(optarg);
break;
case 'p':
port = pg_strdup(optarg);
break;
case 'U':
username = pg_strdup(optarg);
break;
case 'w':
prompt_password = TRI_NO;
break;
case 'W':
prompt_password = TRI_YES;
break;
case 'e':
echo = true;
break;
case 'i':
interactive = true;
break;
case 0:
/* this covers the long options */
break;
case 2:
maintenance_db = pg_strdup(optarg);
break;
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
}
switch (argc - optind)
{
case 0:
fprintf(stderr, _("%s: missing required argument database name\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
case 1:
dbname = argv[optind];
break;
default:
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
progname, argv[optind + 1]);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
if (interactive)
{
printf(_("Database \"%s\" will be permanently removed.\n"), dbname);
if (!yesno_prompt("Are you sure?"))
exit(0);
}
//.........这里部分代码省略.........
示例9: main
int
main(int argc, char **argv)
{
ConfigData *configdata;
size_t configdata_len;
char my_exec_path[MAXPGPATH];
int i;
int j;
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_config"));
progname = get_progname(argv[0]);
/* check for --help */
for (i = 1; i < argc; i++)
{
if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0)
{
help();
exit(0);
}
}
if (find_my_exec(argv[0], my_exec_path) < 0)
{
fprintf(stderr, _("%s: could not find own program executable\n"), progname);
exit(1);
}
configdata = get_configdata(my_exec_path, &configdata_len);
/* no arguments -> print everything */
if (argc < 2)
{
for (i = 0; i < configdata_len; i++)
printf("%s = %s\n", configdata[i].name, configdata[i].setting);
exit(0);
}
/* otherwise print requested items */
for (i = 1; i < argc; i++)
{
for (j = 0; info_items[j].switchname != NULL; j++)
{
if (strcmp(argv[i], info_items[j].switchname) == 0)
{
show_item(info_items[j].configname,
configdata, configdata_len);
break;
}
}
if (info_items[j].switchname == NULL)
{
fprintf(stderr, _("%s: invalid argument: %s\n"),
progname, argv[i]);
advice();
exit(1);
}
}
return 0;
}
示例10: main
int
main(int argc, char *argv[])
{
static struct option long_options[] = {
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"username", required_argument, NULL, 'U'},
{"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
{"echo", no_argument, NULL, 'e'},
{"quiet", no_argument, NULL, 'q'},
{"dbname", required_argument, NULL, 'd'},
{"analyze", no_argument, NULL, 'z'},
{"analyze-only", no_argument, NULL, 'Z'},
{"freeze", no_argument, NULL, 'F'},
{"all", no_argument, NULL, 'a'},
{"table", required_argument, NULL, 't'},
{"full", no_argument, NULL, 'f'},
{"verbose", no_argument, NULL, 'v'},
{"jobs", required_argument, NULL, 'j'},
{"maintenance-db", required_argument, NULL, 2},
{"analyze-in-stages", no_argument, NULL, 3},
{NULL, 0, NULL, 0}
};
const char *progname;
int optindex;
int c;
const char *dbname = NULL;
const char *maintenance_db = NULL;
char *host = NULL;
char *port = NULL;
char *username = NULL;
enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
bool quiet = false;
vacuumingOptions vacopts;
bool analyze_in_stages = false;
bool alldb = false;
SimpleStringList tables = {NULL, NULL};
int concurrentCons = 1;
int tbl_count = 0;
/* initialize options to all false */
memset(&vacopts, 0, sizeof(vacopts));
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
handle_help_version_opts(argc, argv, "vacuumdb", help);
while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:zZFat:fvj:", long_options, &optindex)) != -1)
{
switch (c)
{
case 'h':
host = pg_strdup(optarg);
break;
case 'p':
port = pg_strdup(optarg);
break;
case 'U':
username = pg_strdup(optarg);
break;
case 'w':
prompt_password = TRI_NO;
break;
case 'W':
prompt_password = TRI_YES;
break;
case 'e':
echo = true;
break;
case 'q':
quiet = true;
break;
case 'd':
dbname = pg_strdup(optarg);
break;
case 'z':
vacopts.and_analyze = true;
break;
case 'Z':
vacopts.analyze_only = true;
break;
case 'F':
vacopts.freeze = true;
break;
case 'a':
alldb = true;
break;
case 't':
{
simple_string_list_append(&tables, optarg);
tbl_count++;
break;
}
case 'f':
vacopts.full = true;
//.........这里部分代码省略.........
示例11: libpq_ngettext
char *
libpq_ngettext(const char *msgid, const char *msgid_plural, unsigned long n)
{
libpq_binddomain();
return dngettext(PG_TEXTDOMAIN("libpq"), msgid, msgid_plural, n);
}
示例12: main
int
main(int argc, char *argv[])
{
int c;
bool force = false;
bool noupdate = false;
uint32 set_xid_epoch = (uint32) -1;
TransactionId set_xid = 0;
Oid set_oid = 0;
MultiXactId set_mxid = 0;
MultiXactOffset set_mxoff = (MultiXactOffset) -1;
uint32 minXlogTli = 0,
minXlogId = 0,
minXlogSeg = 0;
char *endptr;
char *endptr2;
char *endptr3;
char *DataDir;
int fd;
char path[MAXPGPATH];
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_resetxlog"));
progname = get_progname(argv[0]);
if (argc > 1)
{
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
{
usage();
exit(0);
}
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
{
puts("pg_resetxlog (Greenplum Database) " PG_VERSION);
exit(0);
}
if (strcmp(argv[1], "--gp-version") == 0)
{
puts("pg_resetxlog (Greenplum Database) " GP_VERSION);
exit(0);
}
}
while ((c = getopt(argc, argv, "fl:m:no:O:x:e:")) != -1)
{
switch (c)
{
case 'f':
force = true;
break;
case 'n':
noupdate = true;
break;
case 'e':
set_xid_epoch = strtoul(optarg, &endptr, 0);
if (endptr == optarg || *endptr != '\0')
{
fprintf(stderr, _("%s: invalid argument for option -e\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
if (set_xid_epoch == -1)
{
fprintf(stderr, _("%s: transaction ID epoch (-e) must not be -1\n"), progname);
exit(1);
}
break;
case 'x':
set_xid = strtoul(optarg, &endptr, 0);
if (endptr == optarg || *endptr != '\0')
{
fprintf(stderr, _("%s: invalid argument for option -x\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
if (set_xid == 0)
{
fprintf(stderr, _("%s: transaction ID (-x) must not be 0\n"), progname);
exit(1);
}
break;
case 'o':
set_oid = strtoul(optarg, &endptr, 0);
if (endptr == optarg || *endptr != '\0')
{
fprintf(stderr, _("%s: invalid argument for option -o\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
if (set_oid == 0)
{
fprintf(stderr, _("%s: OID (-o) must not be 0\n"), progname);
exit(1);
}
//.........这里部分代码省略.........
示例13: main
int
main(int argc, char *argv[])
{
static struct option long_options[] = {
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"username", required_argument, NULL, 'U'},
{"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
{"echo", no_argument, NULL, 'e'},
{"quiet", no_argument, NULL, 'q'},
{"dbname", required_argument, NULL, 'd'},
{"analyze", no_argument, NULL, 'z'},
{"analyze-only", no_argument, NULL, 'Z'},
{"freeze", no_argument, NULL, 'F'},
{"all", no_argument, NULL, 'a'},
{"table", required_argument, NULL, 't'},
{"full", no_argument, NULL, 'f'},
{"verbose", no_argument, NULL, 'v'},
{"maintenance-db", required_argument, NULL, 2},
{NULL, 0, NULL, 0}
};
const char *progname;
int optindex;
int c;
const char *dbname = NULL;
const char *maintenance_db = NULL;
char *host = NULL;
char *port = NULL;
char *username = NULL;
enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
bool quiet = false;
bool and_analyze = false;
bool analyze_only = false;
bool freeze = false;
bool alldb = false;
char *table = NULL;
bool full = false;
bool verbose = false;
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
handle_help_version_opts(argc, argv, "vacuumdb", help);
while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:zZFat:fv", long_options, &optindex)) != -1)
{
switch (c)
{
case 'h':
host = pg_strdup(optarg);
break;
case 'p':
port = pg_strdup(optarg);
break;
case 'U':
username = pg_strdup(optarg);
break;
case 'w':
prompt_password = TRI_NO;
break;
case 'W':
prompt_password = TRI_YES;
break;
case 'e':
echo = true;
break;
case 'q':
quiet = true;
break;
case 'd':
dbname = pg_strdup(optarg);
break;
case 'z':
and_analyze = true;
break;
case 'Z':
analyze_only = true;
break;
case 'F':
freeze = true;
break;
case 'a':
alldb = true;
break;
case 't':
table = pg_strdup(optarg);
break;
case 'f':
full = true;
break;
case 'v':
verbose = true;
break;
case 2:
maintenance_db = pg_strdup(optarg);
break;
//.........这里部分代码省略.........
示例14: main
int
main(int argc, char *argv[])
{
int c;
bool force = false;
bool noupdate = false;
MultiXactId set_oldestmxid = 0;
char *endptr;
char *endptr2;
char *DataDir = NULL;
int fd;
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_resetxlog"));
progname = get_progname(argv[0]);
if (argc > 1)
{
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
{
usage();
exit(0);
}
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
{
puts("pg_resetxlog (PostgreSQL) " PG_VERSION);
exit(0);
}
}
while ((c = getopt(argc, argv, "D:fl:m:no:O:x:e:")) != -1)
{
switch (c)
{
case 'D':
DataDir = optarg;
break;
case 'f':
force = true;
break;
case 'n':
noupdate = true;
break;
case 'e':
set_xid_epoch = strtoul(optarg, &endptr, 0);
if (endptr == optarg || *endptr != '\0')
{
fprintf(stderr, _("%s: invalid argument for option -e\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
if (set_xid_epoch == -1)
{
fprintf(stderr, _("%s: transaction ID epoch (-e) must not be -1\n"), progname);
exit(1);
}
break;
case 'x':
set_xid = strtoul(optarg, &endptr, 0);
if (endptr == optarg || *endptr != '\0')
{
fprintf(stderr, _("%s: invalid argument for option -x\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
if (set_xid == 0)
{
fprintf(stderr, _("%s: transaction ID (-x) must not be 0\n"), progname);
exit(1);
}
break;
case 'o':
set_oid = strtoul(optarg, &endptr, 0);
if (endptr == optarg || *endptr != '\0')
{
fprintf(stderr, _("%s: invalid argument for option -o\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
if (set_oid == 0)
{
fprintf(stderr, _("%s: OID (-o) must not be 0\n"), progname);
exit(1);
}
break;
case 'm':
set_mxid = strtoul(optarg, &endptr, 0);
if (endptr == optarg || *endptr != ',')
{
fprintf(stderr, _("%s: invalid argument for option -m\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
//.........这里部分代码省略.........
示例15: main
int
main(int argc, char *argv[])
{
static struct option long_options[] = {
{"list", no_argument, NULL, 'l'},
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"username", required_argument, NULL, 'U'},
{"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
{"dbname", required_argument, NULL, 'd'},
{"echo", no_argument, NULL, 'e'},
{NULL, 0, NULL, 0}
};
const char *progname;
int optindex;
int c;
bool listlangs = false;
const char *dbname = NULL;
char *host = NULL;
char *port = NULL;
char *username = NULL;
enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
char *langname = NULL;
char *p;
PQExpBufferData sql;
PGconn *conn;
PGresult *result;
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
handle_help_version_opts(argc, argv, "createlang", help);
while ((c = getopt_long(argc, argv, "lh:p:U:wWd:e", long_options, &optindex)) != -1)
{
switch (c)
{
case 'l':
listlangs = true;
break;
case 'h':
host = pg_strdup(optarg);
break;
case 'p':
port = pg_strdup(optarg);
break;
case 'U':
username = pg_strdup(optarg);
break;
case 'w':
prompt_password = TRI_NO;
break;
case 'W':
prompt_password = TRI_YES;
break;
case 'd':
dbname = pg_strdup(optarg);
break;
case 'e':
echo = true;
break;
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
}
/*
* We set dbname from positional arguments if it is not already set by
* option arguments -d. If not doing listlangs, positional dbname must
* follow positional langname.
*/
if (argc - optind > 0)
{
if (listlangs)
{
if (dbname == NULL)
dbname = argv[optind++];
}
else
{
langname = argv[optind++];
if (argc - optind > 0 && dbname == NULL)
dbname = argv[optind++];
}
}
if (argc - optind > 0)
{
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
progname, argv[optind]);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
//.........这里部分代码省略.........