GnuCash  5.6-150-g038405b370+
gnc-path.c
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 gchar *gnc_path_get_prefix()
30 {
31  //printf("Returning prefix %s\n", gnc_gbr_find_prefix (PREFIX));
32  return gnc_gbr_find_prefix (PREFIX);
33 }
34 
39 gchar *gnc_path_get_bindir()
40 {
41  //printf("Returning bindir %s\n", gnc_gbr_find_bin_dir (BINDIR));
42  return gnc_gbr_find_bin_dir (BINDIR);
43 }
44 
49 gchar *gnc_path_get_libdir()
50 {
51  //printf("Returning libdir %s\n", gnc_gbr_find_lib_dir (LIBDIR));
52  return gnc_gbr_find_lib_dir (LIBDIR);
53 }
54 
59 gchar *gnc_path_get_datadir()
60 {
61  //printf("Returning libdir %s\n", gnc_gbr_find_lib_dir (LIBDIR));
62  return gnc_gbr_find_data_dir (DATADIR);
63 }
64 
69 gchar *gnc_path_get_pkgdatadir()
70 {
71  gchar *datadir = gnc_gbr_find_data_dir (DATADIR);
72  gchar *result = g_build_filename (datadir, PROJECT_NAME, (char*)NULL);
73  g_free (datadir);
74  //printf("Returning pkgdatadir %s\n", result);
75  return result;
76 }
77 
82 gchar *gnc_path_get_pkgdocdir()
83 {
84  gchar *docdir = gnc_gbr_find_data_dir (DATADIR);
85  gchar *result = g_build_filename (docdir, "doc", PROJECT_NAME, (char*)NULL);
86  g_free (docdir);
87  //printf("Returning pkgdocdir %s\n", result);
88  return result;
89 }
90 
95 gchar *gnc_path_get_pkgsysconfdir()
96 {
97  gchar *sysconfdir = gnc_gbr_find_etc_dir (SYSCONFDIR);
98  gchar *result = g_build_filename (sysconfdir, PROJECT_NAME, (char*)NULL);
99  g_free (sysconfdir);
100  //printf("Returning pkgsysconfdir %s\n", result);
101  return result;
102 }
103 
104 
109 gchar *gnc_path_get_pkglibdir()
110 {
111  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  gchar *result = g_build_filename (libdir, PROJECT_NAME, (char*)NULL);
117 #endif
118  g_free (libdir);
119  //printf("Returning pkglibdir %s\n", result);
120  return result;
121 }
122 
127 gchar *gnc_path_get_gtkbuilderdir()
128 {
129  gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
130  gchar *result = g_build_filename (pkgdatadir, "gtkbuilder", (char*)NULL);
131  g_free (pkgdatadir);
132  //printf("Returning gtkbuilderdir %s\n", result);
133  return result;
134 }
135 
140 gchar *gnc_path_get_localedir()
141 {
142  gchar *prefix = gnc_path_get_prefix();
143  char *locale_subdir = gnc_file_path_relative_part (PREFIX, LOCALEDIR);
144  if (prefix == NULL || g_strcmp0 (locale_subdir, LOCALEDIR) == 0)
145  {
146  g_free (prefix);
147  g_free (locale_subdir);
148  return g_strdup (LOCALEDIR);
149  }
150  else
151  {
152  gchar *result = g_build_filename (prefix, locale_subdir, (char*)NULL);
153  g_free (prefix);
154  g_free (locale_subdir);
155  //printf("Returning localedir %s\n", result);
156  return result;
157  }
158 }
159 
164 gchar *gnc_path_get_accountsdir()
165 {
166  gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
167  gchar *result = g_build_filename (pkgdatadir, "accounts", (char*)NULL);
168  g_free (pkgdatadir);
169  //printf("Returning accountsdir %s\n", result);
170  return result;
171 }
172 
179 gchar *gnc_path_get_scmdir()
180 {
181  gchar *prefix = gnc_path_get_prefix ();
182  gchar *result = g_build_filename (prefix, GUILE_REL_SITEDIR, (char*)NULL);
183  g_free (prefix);
184 
185  return result;
186 }
187 
192 gchar *gnc_path_get_reportdir()
193 {
194  gchar *scmdir = gnc_path_get_scmdir ();
195  gchar *result = g_build_filename (scmdir, PROJECT_NAME, "report", (char*)NULL);
196  g_free (scmdir);
197 
198  return result;
199 }
200 
205 gchar *gnc_path_get_reportsdir()
206 {
207  gchar *scmdir = gnc_path_get_scmdir ();
208  gchar *result = g_build_filename (scmdir, PROJECT_NAME, "reports", NULL);
209  g_free (scmdir);
210  //printf("Returning reportsdir %s\n", result);
211  return result;
212 }
213 
219 gchar *gnc_path_get_stdreportsdir()
220 {
221  gchar *reportdir = gnc_path_get_reportdir ();
222  gchar *result = g_build_filename (reportdir, "reports", "standard", NULL);
223  g_free (reportdir);
224  //printf("Returning stdreportsdir %s\n", result);
225  return result;
226 }
227 
gchar * gnc_file_path_relative_part(const gchar *prefix, const gchar *path)
Given a prefix and a path return the relative portion of the path.
File path resolution utility functions.