~ubuntu-branches/ubuntu/quantal/gnumeric/quantal

« back to all changes in this revision

Viewing changes to src/gutils.c

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2009-06-07 11:10:47 UTC
  • mfrom: (1.1.19 upstream) (2.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090607111047-l3rtbzfjxvmi1kx0
Tags: 1.9.8-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Promoted gnumeric-doc to Recommends in gnumeric package for help to be
    installed automatically
  - gnumeric-gtk is a transitional package
  - gnumeric conflicts with gnumeric-gtk << 1.8.3-3ubuntu1
  - call initltool-update in po*
  - remove psiconv support (psiconv is in universe):
    o debian/control: remove B-D on libpsiconv-dev
    o debian/rules: don't pass --with-psiconv to ./configure

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include <goffice/utils/go-format.h>
21
21
#include <goffice/utils/go-locale.h>
 
22
#include <goffice/utils/go-file.h>
22
23
 
23
24
#include <stdlib.h>
24
25
#include <math.h>
31
32
#include <locale.h>
32
33
#include <gsf/gsf-impl-utils.h>
33
34
 
34
 
#ifndef G_OS_WIN32
35
 
static char const *gnumeric_lib_dir     = GNUMERIC_LIBDIR;
36
 
static char const *gnumeric_data_dir    = GNUMERIC_DATADIR;
37
 
static char const *gnumeric_icon_dir    = GNUMERIC_ICONDIR;
38
 
static char const *gnumeric_locale_dir  = GNUMERIC_LOCALEDIR;
39
 
#else
40
35
static char *gnumeric_lib_dir;
41
36
static char *gnumeric_data_dir;
42
 
static char *priv_lib_dir;
43
 
static char *priv_data_dir;
44
37
static char *gnumeric_icon_dir;
45
38
static char *gnumeric_locale_dir;
46
 
#endif
47
 
 
48
 
static char const *gnumeric_usr_dir;
 
39
static char *gnumeric_usr_dir;
 
40
 
 
41
static gboolean
 
42
running_in_tree (void)
 
43
{
 
44
        const char *argv0 = g_get_prgname ();
 
45
 
 
46
        if (!argv0)
 
47
                return FALSE;
 
48
 
 
49
        /* Sometime we see, e.g., "lt-gnumeric" as basename.  */
 
50
        {
 
51
                char *base = g_path_get_basename (argv0);
 
52
                gboolean has_lt_prefix = (strncmp (base, "lt-", 3) == 0);
 
53
                g_free (base);
 
54
                if (has_lt_prefix)
 
55
                        return TRUE;
 
56
        }
 
57
 
 
58
        /* Look for ".libs" as final path element.  */
 
59
        {
 
60
                const char *dotlibs = strstr (argv0, ".libs/");
 
61
                if (dotlibs &&
 
62
                    (dotlibs == argv0 || G_IS_DIR_SEPARATOR (dotlibs[-1])) &&
 
63
                    strchr (dotlibs + 6, G_DIR_SEPARATOR) == NULL)
 
64
                        return TRUE;
 
65
        }
 
66
 
 
67
        return FALSE;
 
68
}
49
69
 
50
70
void
51
71
gutils_init (void)
52
72
{
53
73
        char const *home_dir;
54
74
#ifdef G_OS_WIN32
55
 
        gchar *dir = g_win32_get_package_installation_directory (NULL, NULL);
56
 
        priv_lib_dir = gnumeric_lib_dir = g_build_filename (dir,
57
 
                "lib", "gnumeric", GNM_VERSION_FULL, NULL);
58
 
        priv_data_dir = gnumeric_data_dir = g_build_filename (dir,
59
 
                "share", "gnumeric", GNM_VERSION_FULL, NULL);
60
 
        gnumeric_icon_dir = g_build_filename (dir,
61
 
                "share", "pixmaps", "gnumeric", NULL);
62
 
        gnumeric_locale_dir = g_build_filename (dir,
63
 
                "share", "locale", NULL);
 
75
        gchar *dir = g_win32_get_package_installation_directory_of_module (NULL);
 
76
        gnumeric_lib_dir = g_build_filename (dir, "lib",
 
77
                                             "gnumeric", GNM_VERSION_FULL,
 
78
                                             NULL);
 
79
        gnumeric_data_dir = g_build_filename (dir, "share",
 
80
                                              "gnumeric", GNM_VERSION_FULL,
 
81
                                              NULL);
 
82
        gnumeric_icon_dir = g_build_filename (dir, "share", "pixmaps",
 
83
                                              "gnumeric", NULL);
 
84
        gnumeric_locale_dir = g_build_filename (dir, "share", "locale", NULL);
64
85
        g_free (dir);
 
86
#else
 
87
        if (running_in_tree ()) {
 
88
                const char *argv0 = g_get_prgname ();
 
89
                char *dotlibs = g_path_get_dirname (argv0);
 
90
                char *top = g_build_filename (dotlibs, "..", "../", NULL);
 
91
                char *plugins = g_build_filename (top, PLUGIN_SUBDIR, NULL);
 
92
                if (g_file_test (plugins, G_FILE_TEST_IS_DIR))
 
93
                        gnumeric_lib_dir =
 
94
                                go_filename_simplify (top, GO_DOTDOT_SYNTACTIC,
 
95
                                                      FALSE);
 
96
                g_free (top);
 
97
                g_free (plugins);
 
98
                g_free (dotlibs);
 
99
                if (0) g_printerr ("Running in-tree\n");
 
100
        }
 
101
 
 
102
        if (!gnumeric_lib_dir)
 
103
                gnumeric_lib_dir = g_strdup (GNUMERIC_LIBDIR);
 
104
        gnumeric_data_dir = g_strdup (GNUMERIC_DATADIR);
 
105
        gnumeric_icon_dir = g_strdup (GNUMERIC_ICONDIR);
 
106
        gnumeric_locale_dir = g_strdup (GNUMERIC_LOCALEDIR);
65
107
#endif
66
108
        home_dir = g_get_home_dir ();
67
109
        gnumeric_usr_dir = (home_dir == NULL ? NULL :
71
113
void
72
114
gutils_shutdown (void)
73
115
{
74
 
#ifdef G_OS_WIN32
75
 
        g_free (priv_lib_dir);
76
 
        g_free (priv_data_dir);
 
116
        g_free (gnumeric_lib_dir);
 
117
        gnumeric_lib_dir = NULL;
 
118
        g_free (gnumeric_data_dir);
 
119
        gnumeric_data_dir = NULL;
77
120
        g_free (gnumeric_icon_dir);
 
121
        gnumeric_icon_dir = NULL;
78
122
        g_free (gnumeric_locale_dir);
 
123
        gnumeric_locale_dir = NULL;
79
124
        g_free (gnumeric_usr_dir);
80
 
#endif
 
125
        gnumeric_usr_dir = NULL;
81
126
}
82
127
 
83
128
char const *
111
156
}
112
157
 
113
158
int
114
 
gnm_regcomp_XL (GORegexp *preg, char const *pattern, int cflags)
 
159
gnm_regcomp_XL (GORegexp *preg, char const *pattern, int cflags,
 
160
                gboolean full)
115
161
{
116
162
        GString *res = g_string_new (NULL);
117
163
        int retval;
118
164
 
 
165
        if (full)
 
166
                g_string_append_c (res, '^');
 
167
 
119
168
        while (*pattern) {
120
169
                switch (*pattern) {
121
 
                case '~':
122
 
                        pattern++;
123
 
                        if (*pattern == '*')
124
 
                                g_string_append (res, "\\*");
125
 
                        else
126
 
                                g_string_append_c (res, *pattern);
127
 
                        if (*pattern) pattern++;
128
 
                        break;
129
 
 
130
170
                case '*':
131
171
                        g_string_append (res, ".*");
132
172
                        pattern++;
137
177
                        pattern++;
138
178
                        break;
139
179
 
 
180
                case '~':
 
181
                        pattern++;
 
182
                        /* Fall through */
140
183
                default:
141
184
                        pattern = go_regexp_quote1 (res, pattern);
142
185
                }
143
186
        }
144
187
 
 
188
        if (full)
 
189
                g_string_append_c (res, '$');
 
190
 
145
191
        retval = go_regcomp (preg, res->str, cflags);
146
192
        g_string_free (res, TRUE);
147
193
        return retval;
303
349
        g_free (locale->num_locale);
304
350
        g_free (locale);
305
351
}
 
352
 
 
353
 
 
354
gboolean
 
355
gnm_debug_flag (const char *flag)
 
356
{
 
357
        GDebugKey key;
 
358
        key.key = (char *)flag;
 
359
        key.value = 1;
 
360
 
 
361
        return g_parse_debug_string (g_getenv ("GNM_DEBUG"), &key, 1) != 0;
 
362
}