Mercurial > geeqie
annotate src/misc.c @ 1190:a4ea0c74a6e2
File filters cleanup: add .pef .dng and .arw extensions to default sidecar extensions list, add .k25 in Kodak raw extensions, simplify and optimize sidecar_ext_parse().
author | zas_ |
---|---|
date | Sun, 30 Nov 2008 11:46:34 +0000 |
parents | 5fe3b8b3a612 |
children | 3a0bb56adf8e |
rev | line source |
---|---|
1022
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
1 /* |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
2 * Geeqie |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
3 * Copyright (C) 2008 The Geeqie Team |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
4 * |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
5 * Authors: Vladimir Nadvornik / Laurent Monin |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
6 * |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
7 * This software is released under the GNU General Public License (GNU GPL). |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
8 * Please read the included file COPYING for more information. |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
9 * This software comes with no warranty of any kind, use at your own risk! |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
10 */ |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
11 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
12 #include "main.h" |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
13 #include "misc.h" |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
14 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
15 gdouble get_zoom_increment(void) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
16 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
17 return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
18 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
19 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
20 gchar *utf8_validate_or_convert(const gchar *text) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
21 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
22 gint len; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
23 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
24 if (!text) return NULL; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
25 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
26 len = strlen(text); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
27 if (!g_utf8_validate(text, len, NULL)) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
28 return g_convert(text, len, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
29 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
30 return g_strdup(text); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
31 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
32 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
33 gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
34 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
35 gchar *s1_key, *s2_key; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
36 gchar *s1_t, *s2_t; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
37 gint ret; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
38 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
39 g_assert(g_utf8_validate(s1, -1, NULL)); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
40 g_assert(g_utf8_validate(s2, -1, NULL)); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
41 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
42 if (!case_sensitive) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
43 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
44 s1_t = g_utf8_casefold(s1, -1); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
45 s2_t = g_utf8_casefold(s2, -1); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
46 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
47 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
48 s1_key = g_utf8_collate_key(s1_t, -1); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
49 s2_key = g_utf8_collate_key(s2_t, -1); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
50 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
51 ret = strcmp(s1_key, s2_key); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
52 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
53 g_free(s1_key); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
54 g_free(s2_key); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
55 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
56 if (!case_sensitive) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
57 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
58 g_free(s1_t); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
59 g_free(s2_t); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
60 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
61 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
62 return ret; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
63 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
64 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
65 /* Borrowed from gtkfilesystemunix.c */ |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
66 gchar *expand_tilde(const gchar *filename) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
67 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
68 #ifndef G_OS_UNIX |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
69 return g_strdup(filename); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
70 #else |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
71 const gchar *notilde; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
72 const gchar *slash; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
73 const gchar *home; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
74 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
75 if (filename[0] != '~') |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
76 return g_strdup(filename); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
77 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
78 notilde = filename + 1; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
79 slash = strchr(notilde, G_DIR_SEPARATOR); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
80 if (slash == notilde || !*notilde) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
81 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
82 home = g_get_home_dir(); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
83 if (!home) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
84 return g_strdup(filename); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
85 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
86 else |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
87 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
88 gchar *username; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
89 struct passwd *passwd; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
90 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
91 if (slash) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
92 username = g_strndup(notilde, slash - notilde); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
93 else |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
94 username = g_strdup(notilde); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
95 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
96 passwd = getpwnam(username); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
97 g_free(username); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
98 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
99 if (!passwd) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
100 return g_strdup(filename); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
101 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
102 home = passwd->pw_dir; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
103 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
104 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
105 if (slash) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
106 return g_build_filename(home, G_DIR_SEPARATOR_S, slash + 1, NULL); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
107 else |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
108 return g_build_filename(home, G_DIR_SEPARATOR_S, NULL); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
109 #endif |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
110 } |
1023
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
111 |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
112 /* |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
113 returns text without quotes or NULL for empty or broken string |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
114 any text up to first '"' is skipped |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
115 tail is set to point at the char after the second '"' |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
116 or at the ending \0 |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
117 |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
118 */ |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
119 |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
120 gchar *quoted_value(const gchar *text, const gchar **tail) |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
121 { |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
122 const gchar *ptr; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
123 gint c = 0; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
124 gint l = strlen(text); |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
125 gchar *retval = NULL; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
126 |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
127 if (tail) *tail = text; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
128 |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
129 if (l == 0) return retval; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
130 |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
131 while (c < l && text[c] != '"') c++; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
132 if (text[c] == '"') |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
133 { |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
134 gint e; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
135 c++; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
136 ptr = text + c; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
137 e = c; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
138 while (e < l) |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
139 { |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
140 if (text[e-1] != '\\' && text[e] == '"') break; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
141 e++; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
142 } |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
143 if (text[e] == '"') |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
144 { |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
145 if (e - c > 0) |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
146 { |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
147 gchar *substring = g_strndup(ptr, e - c); |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
148 |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
149 if (substring) |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
150 { |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
151 retval = g_strcompress(substring); |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
152 g_free(substring); |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
153 } |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
154 } |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
155 } |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
156 if (tail) *tail = text + e + 1; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
157 } |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
158 else |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
159 /* for compatibility with older formats (<0.3.7) |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
160 * read a line without quotes too */ |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
161 { |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
162 c = 0; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
163 while (c < l && text[c] != '\n' && !g_ascii_isspace(text[c])) c++; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
164 if (c != 0) |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
165 { |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
166 retval = g_strndup(text, c); |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
167 } |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
168 if (tail) *tail = text + c; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
169 } |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
170 |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
171 return retval; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
172 } |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
173 |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
174 gchar *escquote_value(const gchar *text) |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
175 { |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
176 gchar *e; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
177 |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
178 if (!text) return g_strdup("\"\""); |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
179 |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
180 e = g_strescape(text, ""); |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
181 if (e) |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
182 { |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
183 gchar *retval = g_strdup_printf("\"%s\"", e); |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
184 g_free(e); |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
185 return retval; |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
186 } |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
187 return g_strdup("\"\""); |
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1022
diff
changeset
|
188 } |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
189 |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
190 /* Run a command like system() but may output debug messages. */ |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
191 int runcmd(gchar *cmd) |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
192 { |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
193 #if 1 |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
194 return system(cmd); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
195 return 0; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
196 #else |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
197 /* For debugging purposes */ |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
198 int retval = -1; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
199 FILE *in; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
200 |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
201 DEBUG_1("Running command: %s", cmd); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
202 |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
203 in = popen(cmd, "r"); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
204 if (in) |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
205 { |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
206 int status; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
207 const gchar *msg; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
208 gchar buf[2048]; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
209 |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
210 while (fgets(buf, sizeof(buf), in) != NULL ) |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
211 { |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
212 DEBUG_1("Output: %s", buf); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
213 } |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
214 |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
215 status = pclose(in); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
216 |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
217 if (WIFEXITED(status)) |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
218 { |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
219 msg = "Command terminated with exit code"; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
220 retval = WEXITSTATUS(status); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
221 } |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
222 else if (WIFSIGNALED(status)) |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
223 { |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
224 msg = "Command was killed by signal"; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
225 retval = WTERMSIG(status); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
226 } |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
227 else |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
228 { |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
229 msg = "pclose() returned"; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
230 retval = status; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
231 } |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
232 |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
233 DEBUG_1("%s : %d\n", msg, retval); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
234 } |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
235 |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
236 return retval; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
237 #endif |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
238 } |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
239 |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
240 |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1023
diff
changeset
|
241 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |