3 * Copyright (C) 2008 - 2009 The Geeqie Team
5 * Authors: Vladimir Nadvornik / Laurent Monin
7 * This software is released under the GNU General Public License (GNU GPL).
8 * Please read the included file COPYING for more information.
9 * This software comes with no warranty of any kind, use at your own risk!
15 gdouble get_zoom_increment(void)
17 return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0);
20 gchar *utf8_validate_or_convert(const gchar *text)
24 if (!text) return NULL;
27 if (!g_utf8_validate(text, len, NULL))
28 return g_convert(text, len, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
30 return g_strdup(text);
33 gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive)
35 gchar *s1_key, *s2_key;
39 g_assert(g_utf8_validate(s1, -1, NULL));
40 g_assert(g_utf8_validate(s2, -1, NULL));
44 s1_t = g_utf8_casefold(s1, -1);
45 s2_t = g_utf8_casefold(s2, -1);
53 s1_key = g_utf8_collate_key(s1_t, -1);
54 s2_key = g_utf8_collate_key(s2_t, -1);
56 ret = strcmp(s1_key, s2_key);
70 /* Borrowed from gtkfilesystemunix.c */
71 gchar *expand_tilde(const gchar *filename)
74 return g_strdup(filename);
80 if (filename[0] != '~')
81 return g_strdup(filename);
83 notilde = filename + 1;
84 slash = strchr(notilde, G_DIR_SEPARATOR);
85 if (slash == notilde || !*notilde)
87 home = g_get_home_dir();
89 return g_strdup(filename);
94 struct passwd *passwd;
97 username = g_strndup(notilde, slash - notilde);
99 username = g_strdup(notilde);
101 passwd = getpwnam(username);
105 return g_strdup(filename);
107 home = passwd->pw_dir;
111 return g_build_filename(home, G_DIR_SEPARATOR_S, slash + 1, NULL);
113 return g_build_filename(home, G_DIR_SEPARATOR_S, NULL);
118 returns text without quotes or NULL for empty or broken string
119 any text up to first '"' is skipped
120 tail is set to point at the char after the second '"'
125 gchar *quoted_value(const gchar *text, const gchar **tail)
129 gint l = strlen(text);
130 gchar *retval = NULL;
132 if (tail) *tail = text;
134 if (l == 0) return retval;
136 while (c < l && text[c] != '"') c++;
145 if (text[e-1] != '\\' && text[e] == '"') break;
152 gchar *substring = g_strndup(ptr, e - c);
156 retval = g_strcompress(substring);
161 if (tail) *tail = text + e + 1;
164 /* for compatibility with older formats (<0.3.7)
165 * read a line without quotes too */
168 while (c < l && text[c] != '\n' && !g_ascii_isspace(text[c])) c++;
171 retval = g_strndup(text, c);
173 if (tail) *tail = text + c;
179 gchar *escquote_value(const gchar *text)
183 if (!text) return g_strdup("\"\"");
185 e = g_strescape(text, "");
188 gchar *retval = g_strdup_printf("\"%s\"", e);
192 return g_strdup("\"\"");
195 /* Run a command like system() but may output debug messages. */
196 int runcmd(gchar *cmd)
202 /* For debugging purposes */
206 DEBUG_1("Running command: %s", cmd);
208 in = popen(cmd, "r");
215 while (fgets(buf, sizeof(buf), in) != NULL )
217 DEBUG_1("Output: %s", buf);
222 if (WIFEXITED(status))
224 msg = "Command terminated with exit code";
225 retval = WEXITSTATUS(status);
227 else if (WIFSIGNALED(status))
229 msg = "Command was killed by signal";
230 retval = WTERMSIG(status);
234 msg = "pclose() returned";
238 DEBUG_1("%s : %d\n", msg, retval);
246 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */