2 * Copyright (C) 2008 - 2016 The Geeqie Team
4 * Authors: Vladimir Nadvornik, Laurent Monin
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 gdouble get_zoom_increment(void)
26 return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 100.0 : 1.0);
29 gchar *utf8_validate_or_convert(const gchar *text)
33 if (!text) return NULL;
36 if (!g_utf8_validate(text, len, NULL))
37 return g_convert(text, len, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
39 return g_strdup(text);
42 gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive)
44 gchar *s1_key, *s2_key;
48 g_assert(g_utf8_validate(s1, -1, NULL));
49 g_assert(g_utf8_validate(s2, -1, NULL));
53 s1_t = g_utf8_casefold(s1, -1);
54 s2_t = g_utf8_casefold(s2, -1);
62 s1_key = g_utf8_collate_key(s1_t, -1);
63 s2_key = g_utf8_collate_key(s2_t, -1);
65 ret = strcmp(s1_key, s2_key);
79 /* Borrowed from gtkfilesystemunix.c */
80 gchar *expand_tilde(const gchar *filename)
83 return g_strdup(filename);
89 if (filename[0] != '~')
90 return g_strdup(filename);
92 notilde = filename + 1;
93 slash = strchr(notilde, G_DIR_SEPARATOR);
94 if (slash == notilde || !*notilde)
96 home = g_get_home_dir();
98 return g_strdup(filename);
103 struct passwd *passwd;
106 username = g_strndup(notilde, slash - notilde);
108 username = g_strdup(notilde);
110 passwd = getpwnam(username);
114 return g_strdup(filename);
116 home = passwd->pw_dir;
120 return g_build_filename(home, G_DIR_SEPARATOR_S, slash + 1, NULL);
122 return g_build_filename(home, G_DIR_SEPARATOR_S, NULL);
127 /* Run a command like system() but may output debug messages. */
128 int runcmd(gchar *cmd)
134 /* For debugging purposes */
138 DEBUG_1("Running command: %s", cmd);
140 in = popen(cmd, "r");
147 while (fgets(buf, sizeof(buf), in) != NULL )
149 DEBUG_1("Output: %s", buf);
154 if (WIFEXITED(status))
156 msg = "Command terminated with exit code";
157 retval = WEXITSTATUS(status);
159 else if (WIFSIGNALED(status))
161 msg = "Command was killed by signal";
162 retval = WTERMSIG(status);
166 msg = "pclose() returned";
170 DEBUG_1("%s : %d\n", msg, retval);
178 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */