PostgreSQL Source Code  git master
pg_config.c File Reference
#include "postgres_fe.h"
#include "common/config_info.h"
#include "port.h"
Include dependency graph for pg_config.c:

Go to the source code of this file.

Data Structures

struct  InfoItem
 

Functions

static void help (void)
 
static void advice (void)
 
static void show_item (const char *configname, ConfigData *configdata, size_t configdata_len)
 
int main (int argc, char **argv)
 

Variables

static const char * progname
 
static const InfoItem info_items []
 

Function Documentation

◆ advice()

static void advice ( void  )
static

Definition at line 110 of file pg_config.c.

111 {
112  fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
113 }
static const char * progname
Definition: pg_config.c:30
#define _(x)
Definition: elog.c:90
#define fprintf
Definition: port.h:242

References _, fprintf, and progname.

Referenced by main().

◆ help()

static void help ( void  )
static

Definition at line 72 of file pg_config.c.

73 {
74  printf(_("\n%s provides information about the installed version of PostgreSQL.\n\n"), progname);
75  printf(_("Usage:\n"));
76  printf(_(" %s [OPTION]...\n\n"), progname);
77  printf(_("Options:\n"));
78  printf(_(" --bindir show location of user executables\n"));
79  printf(_(" --docdir show location of documentation files\n"));
80  printf(_(" --htmldir show location of HTML documentation files\n"));
81  printf(_(" --includedir show location of C header files of the client\n"
82  " interfaces\n"));
83  printf(_(" --pkgincludedir show location of other C header files\n"));
84  printf(_(" --includedir-server show location of C header files for the server\n"));
85  printf(_(" --libdir show location of object code libraries\n"));
86  printf(_(" --pkglibdir show location of dynamically loadable modules\n"));
87  printf(_(" --localedir show location of locale support files\n"));
88  printf(_(" --mandir show location of manual pages\n"));
89  printf(_(" --sharedir show location of architecture-independent support files\n"));
90  printf(_(" --sysconfdir show location of system-wide configuration files\n"));
91  printf(_(" --pgxs show location of extension makefile\n"));
92  printf(_(" --configure show options given to \"configure\" script when\n"
93  " PostgreSQL was built\n"));
94  printf(_(" --cc show CC value used when PostgreSQL was built\n"));
95  printf(_(" --cppflags show CPPFLAGS value used when PostgreSQL was built\n"));
96  printf(_(" --cflags show CFLAGS value used when PostgreSQL was built\n"));
97  printf(_(" --cflags_sl show CFLAGS_SL value used when PostgreSQL was built\n"));
98  printf(_(" --ldflags show LDFLAGS value used when PostgreSQL was built\n"));
99  printf(_(" --ldflags_ex show LDFLAGS_EX value used when PostgreSQL was built\n"));
100  printf(_(" --ldflags_sl show LDFLAGS_SL value used when PostgreSQL was built\n"));
101  printf(_(" --libs show LIBS value used when PostgreSQL was built\n"));
102  printf(_(" --version show the PostgreSQL version\n"));
103  printf(_(" -?, --help show this help, then exit\n"));
104  printf(_("\nWith no arguments, all known items are shown.\n\n"));
105  printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
106  printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
107 }
#define printf(...)
Definition: port.h:244

References _, printf, and progname.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 130 of file pg_config.c.

131 {
132  ConfigData *configdata;
133  size_t configdata_len;
134  char my_exec_path[MAXPGPATH];
135  int i;
136  int j;
137 
138  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_config"));
139 
140  progname = get_progname(argv[0]);
141 
142  /* check for --help */
143  for (i = 1; i < argc; i++)
144  {
145  if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0)
146  {
147  help();
148  exit(0);
149  }
150  }
151 
152  if (find_my_exec(argv[0], my_exec_path) < 0)
153  {
154  fprintf(stderr, _("%s: could not find own program executable\n"), progname);
155  exit(1);
156  }
157 
158  configdata = get_configdata(my_exec_path, &configdata_len);
159  /* no arguments -> print everything */
160  if (argc < 2)
161  {
162  for (i = 0; i < configdata_len; i++)
163  printf("%s = %s\n", configdata[i].name, configdata[i].setting);
164  exit(0);
165  }
166 
167  /* otherwise print requested items */
168  for (i = 1; i < argc; i++)
169  {
170  for (j = 0; info_items[j].switchname != NULL; j++)
171  {
172  if (strcmp(argv[i], info_items[j].switchname) == 0)
173  {
174  show_item(info_items[j].configname,
175  configdata, configdata_len);
176  break;
177  }
178  }
179  if (info_items[j].switchname == NULL)
180  {
181  fprintf(stderr, _("%s: invalid argument: %s\n"),
182  progname, argv[i]);
183  advice();
184  exit(1);
185  }
186  }
187 
188  return 0;
189 }
static void advice(void)
Definition: pg_config.c:110
static const InfoItem info_items[]
Definition: pg_config.c:43
static void help(void)
Definition: pg_config.c:72
static void show_item(const char *configname, ConfigData *configdata, size_t configdata_len)
Definition: pg_config.c:116
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1217
int find_my_exec(const char *argv0, char *retpath)
Definition: exec.c:160
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:429
ConfigData * get_configdata(const char *my_exec_path, size_t *configdata_len)
Definition: config_info.c:33
char my_exec_path[MAXPGPATH]
Definition: globals.c:80
int j
Definition: isn.c:74
int i
Definition: isn.c:73
exit(1)
#define MAXPGPATH
const char * get_progname(const char *argv0)
Definition: path.c:575
const char * switchname
Definition: pg_config.c:39
const char * name

References _, advice(), exit(), find_my_exec(), fprintf, get_configdata(), get_progname(), help(), i, info_items, j, MAXPGPATH, my_exec_path, name, PG_TEXTDOMAIN, printf, progname, set_pglocale_pgservice(), show_item(), and InfoItem::switchname.

◆ show_item()

static void show_item ( const char *  configname,
ConfigData configdata,
size_t  configdata_len 
)
static

Definition at line 116 of file pg_config.c.

119 {
120  int i;
121 
122  for (i = 0; i < configdata_len; i++)
123  {
124  if (strcmp(configname, configdata[i].name) == 0)
125  printf("%s\n", configdata[i].setting);
126  }
127 }

References i, name, and printf.

Referenced by main().

Variable Documentation

◆ info_items

const InfoItem info_items[]
static
Initial value:
= {
{"--bindir", "BINDIR"},
{"--docdir", "DOCDIR"},
{"--htmldir", "HTMLDIR"},
{"--includedir", "INCLUDEDIR"},
{"--pkgincludedir", "PKGINCLUDEDIR"},
{"--includedir-server", "INCLUDEDIR-SERVER"},
{"--libdir", "LIBDIR"},
{"--pkglibdir", "PKGLIBDIR"},
{"--localedir", "LOCALEDIR"},
{"--mandir", "MANDIR"},
{"--sharedir", "SHAREDIR"},
{"--sysconfdir", "SYSCONFDIR"},
{"--pgxs", "PGXS"},
{"--configure", "CONFIGURE"},
{"--cc", "CC"},
{"--cppflags", "CPPFLAGS"},
{"--cflags", "CFLAGS"},
{"--cflags_sl", "CFLAGS_SL"},
{"--ldflags", "LDFLAGS"},
{"--ldflags_ex", "LDFLAGS_EX"},
{"--ldflags_sl", "LDFLAGS_SL"},
{"--libs", "LIBS"},
{"--version", "VERSION"},
{NULL, NULL}
}

Definition at line 43 of file pg_config.c.

Referenced by main().

◆ progname

const char* progname
static

Definition at line 30 of file pg_config.c.

Referenced by advice(), help(), and main().