LCOV - code coverage report
Current view: top level - src/bin/pg_config - pg_config.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 64 66 97.0 %
Date: 2019-09-19 17:07:13 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * pg_config.c
       4             :  *
       5             :  * This program reports various pieces of information about the
       6             :  * installed version of PostgreSQL.  Packages that interface to
       7             :  * PostgreSQL can use it to configure their build.
       8             :  *
       9             :  * This is a C implementation of the previous shell script written by
      10             :  * Peter Eisentraut <peter_e@gmx.net>, with adjustments made to
      11             :  * accommodate the possibility that the installation has been relocated from
      12             :  * the place originally configured.
      13             :  *
      14             :  * author of C translation: Andrew Dunstan     mailto:andrew@dunslane.net
      15             :  *
      16             :  * This code is released under the terms of the PostgreSQL License.
      17             :  *
      18             :  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
      19             :  *
      20             :  * src/bin/pg_config/pg_config.c
      21             :  *
      22             :  *-------------------------------------------------------------------------
      23             :  */
      24             : 
      25             : #include "postgres_fe.h"
      26             : 
      27             : #include "port.h"
      28             : #include "common/config_info.h"
      29             : 
      30             : static const char *progname;
      31             : 
      32             : /*
      33             :  * Table of known information items
      34             :  *
      35             :  * Be careful to keep this in sync with the help() display.
      36             :  */
      37             : typedef struct
      38             : {
      39             :     const char *switchname;
      40             :     const char *configname;
      41             : } InfoItem;
      42             : 
      43             : static const InfoItem info_items[] = {
      44             :     {"--bindir", "BINDIR"},
      45             :     {"--docdir", "DOCDIR"},
      46             :     {"--htmldir", "HTMLDIR"},
      47             :     {"--includedir", "INCLUDEDIR"},
      48             :     {"--pkgincludedir", "PKGINCLUDEDIR"},
      49             :     {"--includedir-server", "INCLUDEDIR-SERVER"},
      50             :     {"--libdir", "LIBDIR"},
      51             :     {"--pkglibdir", "PKGLIBDIR"},
      52             :     {"--localedir", "LOCALEDIR"},
      53             :     {"--mandir", "MANDIR"},
      54             :     {"--sharedir", "SHAREDIR"},
      55             :     {"--sysconfdir", "SYSCONFDIR"},
      56             :     {"--pgxs", "PGXS"},
      57             :     {"--configure", "CONFIGURE"},
      58             :     {"--cc", "CC"},
      59             :     {"--cppflags", "CPPFLAGS"},
      60             :     {"--cflags", "CFLAGS"},
      61             :     {"--cflags_sl", "CFLAGS_SL"},
      62             :     {"--ldflags", "LDFLAGS"},
      63             :     {"--ldflags_ex", "LDFLAGS_EX"},
      64             :     {"--ldflags_sl", "LDFLAGS_SL"},
      65             :     {"--libs", "LIBS"},
      66             :     {"--version", "VERSION"},
      67             :     {NULL, NULL}
      68             : };
      69             : 
      70             : 
      71             : static void
      72           2 : help(void)
      73             : {
      74           2 :     printf(_("\n%s provides information about the installed version of PostgreSQL.\n\n"), progname);
      75           2 :     printf(_("Usage:\n"));
      76           2 :     printf(_("  %s [OPTION]...\n\n"), progname);
      77           2 :     printf(_("Options:\n"));
      78           2 :     printf(_("  --bindir              show location of user executables\n"));
      79           2 :     printf(_("  --docdir              show location of documentation files\n"));
      80           2 :     printf(_("  --htmldir             show location of HTML documentation files\n"));
      81           2 :     printf(_("  --includedir          show location of C header files of the client\n"
      82             :              "                        interfaces\n"));
      83           2 :     printf(_("  --pkgincludedir       show location of other C header files\n"));
      84           2 :     printf(_("  --includedir-server   show location of C header files for the server\n"));
      85           2 :     printf(_("  --libdir              show location of object code libraries\n"));
      86           2 :     printf(_("  --pkglibdir           show location of dynamically loadable modules\n"));
      87           2 :     printf(_("  --localedir           show location of locale support files\n"));
      88           2 :     printf(_("  --mandir              show location of manual pages\n"));
      89           2 :     printf(_("  --sharedir            show location of architecture-independent support files\n"));
      90           2 :     printf(_("  --sysconfdir          show location of system-wide configuration files\n"));
      91           2 :     printf(_("  --pgxs                show location of extension makefile\n"));
      92           2 :     printf(_("  --configure           show options given to \"configure\" script when\n"
      93             :              "                        PostgreSQL was built\n"));
      94           2 :     printf(_("  --cc                  show CC value used when PostgreSQL was built\n"));
      95           2 :     printf(_("  --cppflags            show CPPFLAGS value used when PostgreSQL was built\n"));
      96           2 :     printf(_("  --cflags              show CFLAGS value used when PostgreSQL was built\n"));
      97           2 :     printf(_("  --cflags_sl           show CFLAGS_SL value used when PostgreSQL was built\n"));
      98           2 :     printf(_("  --ldflags             show LDFLAGS value used when PostgreSQL was built\n"));
      99           2 :     printf(_("  --ldflags_ex          show LDFLAGS_EX value used when PostgreSQL was built\n"));
     100           2 :     printf(_("  --ldflags_sl          show LDFLAGS_SL value used when PostgreSQL was built\n"));
     101           2 :     printf(_("  --libs                show LIBS value used when PostgreSQL was built\n"));
     102           2 :     printf(_("  --version             show the PostgreSQL version\n"));
     103           2 :     printf(_("  -?, --help            show this help, then exit\n"));
     104           2 :     printf(_("\nWith no arguments, all known items are shown.\n\n"));
     105           2 :     printf(_("Report bugs to <pgsql-bugs@lists.postgresql.org>.\n"));
     106           2 : }
     107             : 
     108             : static void
     109           2 : advice(void)
     110             : {
     111           2 :     fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
     112           2 : }
     113             : 
     114             : static void
     115          12 : show_item(const char *configname,
     116             :           ConfigData *configdata,
     117             :           size_t configdata_len)
     118             : {
     119             :     int         i;
     120             : 
     121         288 :     for (i = 0; i < configdata_len; i++)
     122             :     {
     123         276 :         if (strcmp(configname, configdata[i].name) == 0)
     124          12 :             printf("%s\n", configdata[i].setting);
     125             :     }
     126          12 : }
     127             : 
     128             : int
     129          14 : main(int argc, char **argv)
     130             : {
     131             :     ConfigData *configdata;
     132             :     size_t      configdata_len;
     133             :     char        my_exec_path[MAXPGPATH];
     134             :     int         i;
     135             :     int         j;
     136             : 
     137          14 :     set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_config"));
     138             : 
     139          14 :     progname = get_progname(argv[0]);
     140             : 
     141             :     /* check for --help */
     142          28 :     for (i = 1; i < argc; i++)
     143             :     {
     144          16 :         if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0)
     145             :         {
     146           2 :             help();
     147           2 :             exit(0);
     148             :         }
     149             :     }
     150             : 
     151          12 :     if (find_my_exec(argv[0], my_exec_path) < 0)
     152             :     {
     153           0 :         fprintf(stderr, _("%s: could not find own program executable\n"), progname);
     154           0 :         exit(1);
     155             :     }
     156             : 
     157          12 :     configdata = get_configdata(my_exec_path, &configdata_len);
     158             :     /* no arguments -> print everything */
     159          12 :     if (argc < 2)
     160             :     {
     161          48 :         for (i = 0; i < configdata_len; i++)
     162          46 :             printf("%s = %s\n", configdata[i].name, configdata[i].setting);
     163           2 :         exit(0);
     164             :     }
     165             : 
     166             :     /* otherwise print requested items */
     167          22 :     for (i = 1; i < argc; i++)
     168             :     {
     169         128 :         for (j = 0; info_items[j].switchname != NULL; j++)
     170             :         {
     171         126 :             if (strcmp(argv[i], info_items[j].switchname) == 0)
     172             :             {
     173          12 :                 show_item(info_items[j].configname,
     174             :                           configdata, configdata_len);
     175          12 :                 break;
     176             :             }
     177             :         }
     178          14 :         if (info_items[j].switchname == NULL)
     179             :         {
     180           2 :             fprintf(stderr, _("%s: invalid argument: %s\n"),
     181           2 :                     progname, argv[i]);
     182           2 :             advice();
     183           2 :             exit(1);
     184             :         }
     185             :     }
     186             : 
     187           8 :     return 0;
     188             : }

Generated by: LCOV version 1.13