doc: added missing adg-rdim.c to POTFILES.in
[adg.git] / demo / demo.c
blob8173c6f7639c49d9a294e29e5945344c6085ed6e
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012,2013 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.
20 #include "demo.h"
21 #include <string.h>
24 /* Whether the program is running installed or uninstalled */
25 gboolean is_installed = TRUE;
27 /* The base directory where all files must be referred,
28 * usually left unset _adg_init() on POSIX systems. */
29 gchar *basedir = NULL;
32 void
33 _demo_init(gint argc, gchar *argv[])
35 gchar *name;
37 if (argc < 1 || argv == NULL || argv[0] == NULL) {
38 g_error(_("Invalid arguments: arg[0] not set"));
39 g_assert_not_reached();
42 name = g_path_get_basename(argv[0]);
43 if (name != NULL) {
44 is_installed = strstr(name, "uninstalled") == NULL;
45 g_free(name);
48 basedir = g_path_get_dirname(argv[0]);
49 if (basedir == NULL)
50 basedir = g_strdup("");
53 gchar *
54 _demo_file(const gchar *file_name)
56 static gchar *pkg_data_dir = NULL;
58 if (! is_installed) {
59 /* Running uninstalled: look up the file in BUILDDIR before and
60 * in SRCDIR after, returning the first match */
61 return adg_find_file(file_name, BUILDDIR, SRCDIR, NULL);
64 /* Otherwise, look up the file only in PKGDATADIR */
65 if (pkg_data_dir == NULL) {
66 #ifdef G_OS_WIN32
67 /* On windows, PKGDATADIR is relative to basedir */
68 pkg_data_dir = g_build_filename(basedir, PKGDATADIR, NULL);
69 #else
70 pkg_data_dir = g_strdup(PKGDATADIR);
71 #endif
74 return adg_find_file(file_name, pkg_data_dir, NULL);