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.
23 #include "ui_fileops.h"
25 gdouble get_zoom_increment(void)
27 return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 100.0 : 1.0);
30 gchar *utf8_validate_or_convert(const gchar *text)
34 if (!text) return NULL;
37 if (!g_utf8_validate(text, len, NULL))
38 return g_convert(text, len, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
40 return g_strdup(text);
43 gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive)
45 gchar *s1_key, *s2_key;
49 g_assert(g_utf8_validate(s1, -1, NULL));
50 g_assert(g_utf8_validate(s2, -1, NULL));
54 s1_t = g_utf8_casefold(s1, -1);
55 s2_t = g_utf8_casefold(s2, -1);
63 s1_key = g_utf8_collate_key(s1_t, -1);
64 s2_key = g_utf8_collate_key(s2_t, -1);
66 ret = strcmp(s1_key, s2_key);
80 /* Borrowed from gtkfilesystemunix.c */
81 gchar *expand_tilde(const gchar *filename)
84 return g_strdup(filename);
90 if (filename[0] != '~')
91 return g_strdup(filename);
93 notilde = filename + 1;
94 slash = strchr(notilde, G_DIR_SEPARATOR);
95 if (slash == notilde || !*notilde)
97 home = g_get_home_dir();
99 return g_strdup(filename);
104 struct passwd *passwd;
107 username = g_strndup(notilde, slash - notilde);
109 username = g_strdup(notilde);
111 passwd = getpwnam(username);
115 return g_strdup(filename);
117 home = passwd->pw_dir;
121 return g_build_filename(home, G_DIR_SEPARATOR_S, slash + 1, NULL);
123 return g_build_filename(home, G_DIR_SEPARATOR_S, NULL);
127 /* Search for latitude/longitude parameters in a string
130 #define GEOCODE_NAME "geocode-parameters.awk"
133 gchar *decode_geo_parameters(const gchar *input_text)
136 gchar *path = g_build_filename(get_rc_dir(), GEOCODE_NAME, NULL);
137 gchar *cmd = g_strconcat("echo \'", input_text, "\' | awk -f ", path, NULL);
139 if (g_file_test(path, G_FILE_TEST_EXISTS))
144 if ((fp = popen(cmd, "r")) == NULL)
146 message = g_strconcat("Error: opening pipe\n", input_text, NULL);
150 while (fgets(buf, BUFSIZE, fp))
152 DEBUG_1("Output: %s", buf);
155 message = g_strconcat(buf, NULL);
159 message = g_strconcat("Error: Command not found or exited with error status\n", input_text, NULL);
165 message = g_strconcat(input_text, NULL);
173 /* Run a command like system() but may output debug messages. */
174 int runcmd(gchar *cmd)
180 /* For debugging purposes */
184 DEBUG_1("Running command: %s", cmd);
186 in = popen(cmd, "r");
193 while (fgets(buf, sizeof(buf), in) != NULL )
195 DEBUG_1("Output: %s", buf);
200 if (WIFEXITED(status))
202 msg = "Command terminated with exit code";
203 retval = WEXITSTATUS(status);
205 else if (WIFSIGNALED(status))
207 msg = "Command was killed by signal";
208 retval = WTERMSIG(status);
212 msg = "pclose() returned";
216 DEBUG_1("%s : %d\n", msg, retval);
224 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */