1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2021 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
24 #if GLIB_CHECK_VERSION(2, 58, 0)
27 _demo_absolutepath(const gchar
*path
)
29 return g_canonicalize_filename(path
, NULL
);
38 _demo_absolutepath(const gchar
*path
)
40 char abspath
[PATH_MAX
];
41 return g_strdup(realpath(path
, abspath
));
47 /* Base folder all installed files should be referred to. */
48 static gchar
*pkg_data_dir
= NULL
;
52 _demo_basedir(const gchar
*program
)
56 dir
= g_path_get_dirname(program
);
61 absdir
= _demo_absolutepath(dir
);
67 _demo_init(gint argc
, gchar
*argv
[])
71 if (argc
< 1 || argv
== NULL
|| argv
[0] == NULL
) {
72 g_error(_("Invalid arguments: arg[0] not set"));
73 g_assert_not_reached();
76 basedir
= _demo_basedir(argv
[0]);
77 if (basedir
== NULL
) {
78 /* This should never happen but... just in case */
83 g_print("basedir = '%s'\nbuilddir= '%s'\n", basedir
, BUILDDIR
);
84 if (! g_str_has_prefix(basedir
, BUILDDIR
)) {
85 /* Installed program: set pkg_data_dir */
87 gchar
*parent
= g_path_get_dirname(dirname
);
88 /* XXX: `pkg_data_dir` will be leaked... who cares? */
89 pkg_data_dir
= g_build_filename(parent
, PKGDATADIR
, NULL
);
92 pkg_data_dir
= PKGDATADIR
;
99 _demo_file(const gchar
*file_name
)
101 if (pkg_data_dir
== NULL
) {
102 /* Running uninstalled: look up the file in BUILDDIR first and
103 * SRCDIR later, returning the first match */
104 return adg_find_file(file_name
, BUILDDIR
, SRCDIR
, NULL
);
107 /* Running installed: look up the file only in `pkg_data_dir` */
108 return adg_find_file(file_name
, pkg_data_dir
, NULL
);