LCOV - code coverage report
Current view: top level - libgnucash/core-utils - gnc-path.c (source / functions) Coverage Total Hit
Test: gnucash.info Lines: 56.5 % 69 39
Test Date: 2026-11-24 04:31:04 Functions: 60.0 % 15 9
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /********************************************************************\
       2              :  * gnc-path.c -- Path lookup of gnucash installation locations      *
       3              :  *                                                                  *
       4              :  * This program is free software; you can redistribute it and/or    *
       5              :  * modify it under the terms of the GNU General Public License as   *
       6              :  * published by the Free Software Foundation; either version 2 of   *
       7              :  * the License, or (at your option) any later version.              *
       8              :  *                                                                  *
       9              :  * This program is distributed in the hope that it will be useful,  *
      10              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
      11              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
      12              :  * GNU General Public License for more details.                     *
      13              :  *                                                                  *
      14              :  * You should have received a copy of the GNU General Public License*
      15              :  * along with this program; if not, contact:                        *
      16              :  *                                                                  *
      17              :  * Free Software Foundation           Voice:  +1-617-542-5942       *
      18              :  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
      19              :  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
      20              : \********************************************************************/
      21              : 
      22              : #include <config.h>
      23              : #include "gnc-path.h"
      24              : #include "gncla-dir.h"
      25              : #include <stdio.h>
      26              : #include "binreloc.h"
      27              : #include "gnc-filepath-utils.h"
      28              : 
      29           15 : gchar *gnc_path_get_prefix()
      30              : {
      31              :     //printf("Returning prefix %s\n", gnc_gbr_find_prefix (PREFIX));
      32           15 :     return gnc_gbr_find_prefix (PREFIX);
      33              : }
      34              : 
      35              : /** Returns the bindir path, usually
      36              :  * "$prefix/bin".
      37              :  *
      38              :  * @returns A newly allocated string. */
      39            2 : gchar *gnc_path_get_bindir()
      40              : {
      41              :     //printf("Returning bindir %s\n", gnc_gbr_find_bin_dir (BINDIR));
      42            2 :     return gnc_gbr_find_bin_dir (BINDIR);
      43              : }
      44              : 
      45              : /** Returns the libdir path, usually
      46              :  * "$prefix/lib".
      47              :  *
      48              :  * @returns A newly allocated string. */
      49          126 : gchar *gnc_path_get_libdir()
      50              : {
      51              :     //printf("Returning libdir %s\n", gnc_gbr_find_lib_dir (LIBDIR));
      52          126 :     return gnc_gbr_find_lib_dir (LIBDIR);
      53              : }
      54              : 
      55              : /** Returns the libdir path, usually
      56              :  * "$prefix/lib".
      57              :  *
      58              :  * @returns A newly allocated string. */
      59            0 : gchar *gnc_path_get_datadir()
      60              : {
      61              :     //printf("Returning libdir %s\n", gnc_gbr_find_lib_dir (LIBDIR));
      62            0 :     return gnc_gbr_find_data_dir (DATADIR);
      63              : }
      64              : 
      65              : /** Returns the datadir path, usually
      66              :  * "$prefix/share/gnucash". Needed for gnc_gnome_locate_*().
      67              :  *
      68              :  * @returns A newly allocated string. */
      69          101 : gchar *gnc_path_get_pkgdatadir()
      70              : {
      71          101 :     gchar *datadir = gnc_gbr_find_data_dir (DATADIR);
      72          101 :     gchar *result = g_build_filename (datadir, PROJECT_NAME, (char*)NULL);
      73          101 :     g_free (datadir);
      74              :     //printf("Returning pkgdatadir %s\n", result);
      75          101 :     return result;
      76              : }
      77              : 
      78              : /** Returns the docdir path, usually
      79              :  * "$prefix/share/doc/gnucash".
      80              :  *
      81              :  * @returns A newly allocated string. */
      82            0 : gchar *gnc_path_get_pkgdocdir()
      83              : {
      84            0 :     gchar *docdir = gnc_gbr_find_data_dir (DATADIR);
      85            0 :     gchar *result = g_build_filename (docdir, "doc", PROJECT_NAME, (char*)NULL);
      86            0 :     g_free (docdir);
      87              :     //printf("Returning pkgdocdir %s\n", result);
      88            0 :     return result;
      89              : }
      90              : 
      91              : /** Returns the sysconfdir path, usually
      92              :  * "$prefix/etc/gnucash".
      93              :  *
      94              :  * @returns A newly allocated string. */
      95            2 : gchar *gnc_path_get_pkgsysconfdir()
      96              : {
      97            2 :     gchar *sysconfdir = gnc_gbr_find_etc_dir (SYSCONFDIR);
      98            2 :     gchar *result = g_build_filename (sysconfdir, PROJECT_NAME, (char*)NULL);
      99            2 :     g_free (sysconfdir);
     100              :     //printf("Returning pkgsysconfdir %s\n", result);
     101            2 :     return result;
     102              : }
     103              : 
     104              : 
     105              : /** Returns the pkglibdir path, usually
     106              :  * "$prefix/lib/gnucash".
     107              :  *
     108              :  * @returns A newly allocated string. */
     109          125 : gchar *gnc_path_get_pkglibdir()
     110              : {
     111          125 :     gchar *libdir = gnc_path_get_libdir ();
     112              : #ifdef G_OS_WIN32
     113              :     /* Workaround for Bug 618646, {pkglibdir} will be bin/ on Windows */
     114              :     gchar *result = gnc_gbr_find_bin_dir(libdir);
     115              : #else
     116          125 :     gchar *result = g_build_filename (libdir, PROJECT_NAME, (char*)NULL);
     117              : #endif
     118          125 :     g_free (libdir);
     119              :     //printf("Returning pkglibdir %s\n", result);
     120          125 :     return result;
     121              : }
     122              : 
     123              : /** Returns the gtkbuilder file path, usually
     124              :  * "$prefix/share/gnucash/gtkbuilder".
     125              :  *
     126              :  * @returns A newly allocated string. */
     127            0 : gchar *gnc_path_get_gtkbuilderdir()
     128              : {
     129            0 :     gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
     130            0 :     gchar *result = g_build_filename (pkgdatadir, "gtkbuilder", (char*)NULL);
     131            0 :     g_free (pkgdatadir);
     132              :     //printf("Returning gtkbuilderdir %s\n", result);
     133            0 :     return result;
     134              : }
     135              : 
     136              : /** Returns the localedir path, usually
     137              :  * "$prefix/share/locale".
     138              :  *
     139              :  * @returns A newly allocated string. */
     140            2 : gchar *gnc_path_get_localedir()
     141              : {
     142            2 :     gchar *prefix = gnc_path_get_prefix();
     143            2 :     char *locale_subdir = gnc_file_path_relative_part (PREFIX, LOCALEDIR);
     144            2 :     if (prefix == NULL || g_strcmp0 (locale_subdir, LOCALEDIR) == 0)
     145              :     {
     146            0 :         g_free (prefix);
     147            0 :         g_free (locale_subdir);
     148            0 :         return g_strdup (LOCALEDIR);
     149              :     }
     150              :     else
     151              :     {
     152            2 :         gchar *result = g_build_filename (prefix, locale_subdir, (char*)NULL);
     153            2 :         g_free (prefix);
     154            2 :         g_free (locale_subdir);
     155              :         //printf("Returning localedir %s\n", result);
     156            2 :         return result;
     157              :     }
     158              : }
     159              : 
     160              : /** Returns the accounts file path, usually
     161              :  * "$prefix/share/gnucash/accounts".
     162              :  *
     163              :  * @returns A newly allocated string. */
     164           50 : gchar *gnc_path_get_accountsdir()
     165              : {
     166           50 :     gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
     167           50 :     gchar *result = g_build_filename (pkgdatadir, "accounts", (char*)NULL);
     168           50 :     g_free (pkgdatadir);
     169              :     //printf("Returning accountsdir %s\n", result);
     170           50 :     return result;
     171              : }
     172              : 
     173              : /** Returns the file path to the directory containing all guile scripts, usually
     174              :  * "$prefix/guile/site/x.y".
     175              :  * This path is determined by querying guile for its sitedir and then
     176              :  * rebasing this to be relative to our own installation prefix.
     177              :  *
     178              :  * @returns A newly allocated string. */
     179           12 : gchar *gnc_path_get_scmdir()
     180              : {
     181           12 :     gchar *prefix = gnc_path_get_prefix ();
     182           12 :     gchar *result = g_build_filename (prefix, GUILE_REL_SITEDIR, (char*)NULL);
     183           12 :     g_free (prefix);
     184              : 
     185           12 :     return result;
     186              : }
     187              : 
     188              : /** Returns the file path to the report directory, usually
     189              :  * "$prefix/share/guile/site/x.y/gnucash/report".
     190              :  *
     191              :  * @returns A newly allocated string. */
     192            0 : gchar *gnc_path_get_reportdir()
     193              : {
     194            0 :     gchar *scmdir = gnc_path_get_scmdir ();
     195            0 :     gchar *result = g_build_filename (scmdir, PROJECT_NAME, "report", (char*)NULL);
     196            0 :     g_free (scmdir);
     197              : 
     198            0 :     return result;
     199              : }
     200              : 
     201              : /** Returns the file path to the reports directory, usually
     202              :  * "$prefix/share/guile/site/x.y/gnucash/reports".
     203              :  *
     204              :  * @returns A newly allocated string. */
     205            0 : gchar *gnc_path_get_reportsdir()
     206              : {
     207            0 :     gchar *scmdir = gnc_path_get_scmdir ();
     208            0 :     gchar *result = g_build_filename (scmdir, PROJECT_NAME, "reports", NULL);
     209            0 :     g_free (scmdir);
     210              :     //printf("Returning reportsdir %s\n", result);
     211            0 :     return result;
     212              : }
     213              : 
     214              : /** Returns the file path to the standard
     215              :  * reports, usually
     216              :  * "$prefix/share/guile/site/x.y/gnucash/reports/standard".
     217              :  *
     218              :  * @returns A newly allocated string. */
     219            0 : gchar *gnc_path_get_stdreportsdir()
     220              : {
     221            0 :     gchar *reportdir = gnc_path_get_reportdir ();
     222            0 :     gchar *result = g_build_filename (reportdir, "reports", "standard", NULL);
     223            0 :     g_free (reportdir);
     224              :     //printf("Returning stdreportsdir %s\n", result);
     225            0 :     return result;
     226              : }
     227              : 
        

Generated by: LCOV version 2.0-1