PostgreSQL Source Code  git master
option_utils.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * Command line option processing facilities for frontend code
4  *
5  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
6  * Portions Copyright (c) 1994, Regents of the University of California
7  *
8  * src/fe_utils/option_utils.c
9  *
10  *-------------------------------------------------------------------------
11  */
12 
13 #include "postgres_fe.h"
14 
15 #include "fe_utils/option_utils.h"
16 
17 /*
18  * Provide strictly harmonized handling of --help and --version
19  * options.
20  */
21 void
22 handle_help_version_opts(int argc, char *argv[],
23  const char *fixed_progname, help_handler hlp)
24 {
25  if (argc > 1)
26  {
27  if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
28  {
29  hlp(get_progname(argv[0]));
30  exit(0);
31  }
32  if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
33  {
34  printf("%s (PostgreSQL) " PG_VERSION "\n", fixed_progname);
35  exit(0);
36  }
37  }
38 }
const char * get_progname(const char *argv0)
Definition: path.c:453
#define printf(...)
Definition: port.h:222
void handle_help_version_opts(int argc, char *argv[], const char *fixed_progname, help_handler hlp)
Definition: option_utils.c:22
void(* help_handler)(const char *progname)
Definition: option_utils.h:17