annotate src/audacious/util.c @ 4454:a7bf5b979a05

Remove duplicated path separator conversion (backslash to slash).
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 13 Apr 2008 07:15:07 +0300
parents 539f3cb7b1e8
children 6e323e395886
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
1 /* Audacious - Cross-platform multimedia player
4259
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
2 * Copyright (C) 2005-2008 Audacious development team
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
3 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
4 * Based on BMP:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
5 * Copyright (C) 2003-2004 BMP development team.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
6 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
7 * Based on XMMS:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
8 * Copyright (C) 1998-2003 XMMS development team.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
9 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
3121
3b6d316f8b09 GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents: 3103
diff changeset
12 * the Free Software Foundation; under version 3 of the License.
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
13 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
17 * GNU General Public License for more details.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
18 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
3121
3b6d316f8b09 GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents: 3103
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses>.
3123
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 3122
diff changeset
21 *
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 3122
diff changeset
22 * The Audacious team does not consider modular code linking to
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 3122
diff changeset
23 * Audacious or using our public API to be a derived work.
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
24 */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
25
4127
8433739e41b9 oops...
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4124
diff changeset
26 /*#define AUD_DEBUG*/
4070
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
27
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
28 #ifdef HAVE_CONFIG_H
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
29 # include "config.h"
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
30 #endif
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
31
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
32 #include "util.h"
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
33
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
34 #include <glib.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
35 #include <glib/gi18n.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
36 #include <gtk/gtk.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
37 #include <stdlib.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
38 #include <string.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
39 #include <ctype.h>
4267
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
40 #include <math.h>
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
41
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
42 #include "platform/smartinclude.h"
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
43 #include <errno.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
44
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
45 #ifdef HAVE_FTS_H
3033
2c17b008a532 MacOS target: build fixes
nenolod@tiamat.local
parents: 2990
diff changeset
46 # include <sys/types.h>
2c17b008a532 MacOS target: build fixes
nenolod@tiamat.local
parents: 2990
diff changeset
47 # include <sys/stat.h>
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
48 # include <fts.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
49 #endif
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
50
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
51 #include "input.h"
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
52 #include "playback.h"
2373
ad1d7687814c [svn] made strings.h for existing strings.c, cleanups
mf0102
parents: 2365
diff changeset
53 #include "strings.h"
4347
f493c456c77f Still cleaning up stuff
mf0102 <0102@gmx.at>
parents: 4278
diff changeset
54
4259
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
55 #include "libSAD.h"
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
56
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
57 #ifdef USE_CHARDET
3210
5939941ba48b More librcd removal.
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
58 #include "../libguess/libguess.h"
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
59 #ifdef HAVE_UDET
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
60 #include <libudet_c.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
61 #endif
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
62 #endif
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
63
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
64 /*
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
65 * find <file> in directory <dirname> or subdirectories. return
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
66 * pointer to complete filename which has to be freed by calling
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
67 * "g_free()" after use. Returns NULL if file could not be found.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
68 */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
69
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
70 typedef struct {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
71 const gchar *to_match;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
72 gchar *match;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
73 gboolean found;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
74 } FindFileContext;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
75
4259
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
76 static const struct {
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
77 AFormat afmt;
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
78 SAD_sample_format sadfmt;
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
79 } format_table[] = {
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
80 {FMT_U8, SAD_SAMPLE_U8},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
81 {FMT_S8, SAD_SAMPLE_S8},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
82
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
83 {FMT_S16_LE, SAD_SAMPLE_S16_LE},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
84 {FMT_S16_BE, SAD_SAMPLE_S16_BE},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
85 {FMT_S16_NE, SAD_SAMPLE_S16},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
86
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
87 {FMT_U16_LE, SAD_SAMPLE_U16_LE},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
88 {FMT_U16_BE, SAD_SAMPLE_U16_BE},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
89 {FMT_U16_NE, SAD_SAMPLE_U16},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
90
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
91 {FMT_S24_LE, SAD_SAMPLE_S24_LE},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
92 {FMT_S24_BE, SAD_SAMPLE_S24_BE},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
93 {FMT_S24_NE, SAD_SAMPLE_S24},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
94
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
95 {FMT_U24_LE, SAD_SAMPLE_U24_LE},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
96 {FMT_U24_BE, SAD_SAMPLE_U24_BE},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
97 {FMT_U24_NE, SAD_SAMPLE_U24},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
98
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
99 {FMT_S32_LE, SAD_SAMPLE_S32_LE},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
100 {FMT_S32_BE, SAD_SAMPLE_S32_BE},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
101 {FMT_S32_NE, SAD_SAMPLE_S32},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
102
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
103 {FMT_U32_LE, SAD_SAMPLE_U32_LE},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
104 {FMT_U32_BE, SAD_SAMPLE_U32_BE},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
105 {FMT_U32_NE, SAD_SAMPLE_U32},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
106
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
107 {FMT_FLOAT, SAD_SAMPLE_FLOAT},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
108 {FMT_FIXED32, SAD_SAMPLE_FIXED32},
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
109 };
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
110
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
111 SAD_sample_format
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
112 sadfmt_from_afmt(AFormat fmt)
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
113 {
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
114 int i;
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
115 for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++) {
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
116 if (format_table[i].afmt == fmt) return format_table[i].sadfmt;
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
117 }
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
118
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
119 return -1;
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
120 }
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
121
92642f860860 - added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4223
diff changeset
122
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
123 static gboolean
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
124 find_file_func(const gchar * path, const gchar * basename, gpointer data)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
125 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
126 FindFileContext *context = data;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
127
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
128 if (strlen(path) > FILENAME_MAX) {
4124
d217b71e5836 more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4097
diff changeset
129 AUDDBG("Ignoring path: name too long (%s)\n", path);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
130 return TRUE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
131 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
132
2989
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
133 if (vfs_file_test(path, G_FILE_TEST_IS_REGULAR)) {
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
134 if (!strcasecmp(basename, context->to_match)) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
135 context->match = g_strdup(path);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
136 context->found = TRUE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
137 return TRUE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
138 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
139 }
2989
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
140 else if (vfs_file_test(path, G_FILE_TEST_IS_DIR)) {
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
141 dir_foreach(path, find_file_func, context, NULL);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
142 if (context->found)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
143 return TRUE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
144 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
145
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
146 return FALSE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
147 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
148
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
149 gchar *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
150 find_file_recursively(const gchar * path, const gchar * filename)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
151 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
152 FindFileContext context;
2989
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
153 gchar *out = NULL;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
154
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
155 context.to_match = filename;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
156 context.match = NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
157 context.found = FALSE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
158
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
159 dir_foreach(path, find_file_func, &context, NULL);
2989
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
160
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
161 if (context.match)
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
162 {
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
163 out = g_filename_to_uri(context.match, NULL, NULL);
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
164 g_free(context.match);
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
165 }
2988
43a075cb5c81 find_file_recursively(): Return a valid URI instead of a literal path.
William Pitcock <nenolod@atheme-project.org>
parents: 2977
diff changeset
166
43a075cb5c81 find_file_recursively(): Return a valid URI instead of a literal path.
William Pitcock <nenolod@atheme-project.org>
parents: 2977
diff changeset
167 return out;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
168 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
169
2989
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
170 gchar *
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
171 find_path_recursively(const gchar * path, const gchar * filename)
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
172 {
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
173 FindFileContext context;
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
174
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
175 context.to_match = filename;
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
176 context.match = NULL;
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
177 context.found = FALSE;
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
178
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
179 dir_foreach(path, find_file_func, &context, NULL);
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
180
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
181 return context.match;
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
182 }
15f6c9949cde Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents: 2988
diff changeset
183
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
184
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
185 typedef enum {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
186 ARCHIVE_UNKNOWN = 0,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
187 ARCHIVE_DIR,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
188 ARCHIVE_TAR,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
189 ARCHIVE_TGZ,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
190 ARCHIVE_ZIP,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
191 ARCHIVE_TBZ2
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
192 } ArchiveType;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
193
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
194 typedef gchar *(*ArchiveExtractFunc) (const gchar *, const gchar *);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
195
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
196 typedef struct {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
197 ArchiveType type;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
198 const gchar *ext;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
199 } ArchiveExtensionType;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
200
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
201 static ArchiveExtensionType archive_extensions[] = {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
202 {ARCHIVE_TAR, ".tar"},
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
203 {ARCHIVE_ZIP, ".wsz"},
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
204 {ARCHIVE_ZIP, ".zip"},
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
205 {ARCHIVE_TGZ, ".tar.gz"},
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
206 {ARCHIVE_TGZ, ".tgz"},
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
207 {ARCHIVE_TBZ2, ".tar.bz2"},
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
208 {ARCHIVE_TBZ2, ".bz2"},
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
209 {ARCHIVE_UNKNOWN, NULL}
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
210 };
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
211
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
212 static gchar *archive_extract_tar(const gchar * archive, const gchar * dest);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
213 static gchar *archive_extract_zip(const gchar * archive, const gchar * dest);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
214 static gchar *archive_extract_tgz(const gchar * archive, const gchar * dest);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
215 static gchar *archive_extract_tbz2(const gchar * archive, const gchar * dest);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
216
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
217 static ArchiveExtractFunc archive_extract_funcs[] = {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
218 NULL,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
219 NULL,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
220 archive_extract_tar,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
221 archive_extract_tgz,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
222 archive_extract_zip,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
223 archive_extract_tbz2
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
224 };
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
225
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
226
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
227 /* FIXME: these functions can be generalised into a function using a
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
228 * command lookup table */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
229
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
230 static const gchar *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
231 get_tar_command(void)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
232 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
233 static const gchar *command = NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
234
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
235 if (!command) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
236 if (!(command = getenv("TARCMD")))
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
237 command = "tar";
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
238 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
239
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
240 return command;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
241 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
242
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
243 static const gchar *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
244 get_unzip_command(void)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
245 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
246 static const gchar *command = NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
247
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
248 if (!command) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
249 if (!(command = getenv("UNZIPCMD")))
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
250 command = "unzip";
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
251 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
252
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
253 return command;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
254 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
255
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
256
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
257 static gchar *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
258 archive_extract_tar(const gchar * archive, const gchar * dest)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
259 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
260 return g_strdup_printf("%s >/dev/null xf \"%s\" -C %s",
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
261 get_tar_command(), archive, dest);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
262 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
263
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
264 static gchar *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
265 archive_extract_zip(const gchar * archive, const gchar * dest)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
266 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
267 return g_strdup_printf("%s >/dev/null -o -j \"%s\" -d %s",
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
268 get_unzip_command(), archive, dest);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
269 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
270
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
271 static gchar *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
272 archive_extract_tgz(const gchar * archive, const gchar * dest)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
273 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
274 return g_strdup_printf("%s >/dev/null xzf \"%s\" -C %s",
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
275 get_tar_command(), archive, dest);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
276 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
277
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
278 static gchar *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
279 archive_extract_tbz2(const gchar * archive, const gchar * dest)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
280 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
281 return g_strdup_printf("bzip2 -dc \"%s\" | %s >/dev/null xf - -C %s",
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
282 archive, get_tar_command(), dest);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
283 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
284
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
285
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
286 ArchiveType
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
287 archive_get_type(const gchar * filename)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
288 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
289 gint i = 0;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
290
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
291 if (g_file_test(filename, G_FILE_TEST_IS_DIR))
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
292 return ARCHIVE_DIR;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
293
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
294 while (archive_extensions[i].ext) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
295 if (g_str_has_suffix(filename, archive_extensions[i].ext)) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
296 return archive_extensions[i].type;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
297 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
298 i++;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
299 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
300
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
301 return ARCHIVE_UNKNOWN;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
302 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
303
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
304 gboolean
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
305 file_is_archive(const gchar * filename)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
306 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
307 return (archive_get_type(filename) > ARCHIVE_DIR);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
308 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
309
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
310 gchar *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
311 archive_basename(const gchar * str)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
312 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
313 gint i = 0;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
314
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
315 while (archive_extensions[i].ext) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
316 if (str_has_suffix_nocase(str, archive_extensions[i].ext)) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
317 const gchar *end = g_strrstr(str, archive_extensions[i].ext);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
318 if (end) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
319 return g_strndup(str, end - str);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
320 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
321 break;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
322 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
323 i++;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
324 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
325
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
326 return NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
327 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
328
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
329 /*
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
330 decompress_archive
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
331
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
332 Decompresses the archive "filename" to a temporary directory,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
333 returns the path to the temp dir, or NULL if failed,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
334 watch out tho, doesn't actually check if the system command succeeds :-|
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
335 */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
336
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
337 gchar *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
338 archive_decompress(const gchar * filename)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
339 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
340 gchar *tmpdir, *cmd, *escaped_filename;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
341 ArchiveType type;
2328
d88558b0de0a [svn] - Added script for migration to XDG basedir.
js
parents: 2313
diff changeset
342 #ifndef HAVE_MKDTEMP
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
343 mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
2328
d88558b0de0a [svn] - Added script for migration to XDG basedir.
js
parents: 2313
diff changeset
344 #endif
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
345
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
346 if ((type = archive_get_type(filename)) <= ARCHIVE_DIR)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
347 return NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
348
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
349 #ifdef HAVE_MKDTEMP
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
350 tmpdir = g_build_filename(g_get_tmp_dir(), "audacious.XXXXXXXX", NULL);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
351 if (!mkdtemp(tmpdir)) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
352 g_free(tmpdir);
4124
d217b71e5836 more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4097
diff changeset
353 AUDDBG("Unable to load skin: Failed to create temporary "
d217b71e5836 more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4097
diff changeset
354 "directory: %s\n", g_strerror(errno));
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
355 return NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
356 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
357 #else
3637
d0775f9708e8 Typecast to (long)
Matti Hamalainen <ccr@tnsp.org>
parents: 3470
diff changeset
358 tmpdir = g_strdup_printf("%s/audacious.%ld", g_get_tmp_dir(), (long) rand());
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
359 make_directory(tmpdir, mode755);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
360 #endif
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
361
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
362 escaped_filename = escape_shell_chars(filename);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
363 cmd = archive_extract_funcs[type] (escaped_filename, tmpdir);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
364 g_free(escaped_filename);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
365
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
366 if (!cmd) {
4124
d217b71e5836 more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4097
diff changeset
367 AUDDBG("extraction function is NULL!\n");
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
368 g_free(tmpdir);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
369 return NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
370 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
371
4124
d217b71e5836 more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4097
diff changeset
372 AUDDBG("Attempt to execute \"%s\"\n", cmd);
d217b71e5836 more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4097
diff changeset
373
d217b71e5836 more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4097
diff changeset
374 if(system(cmd) != 0)
2361
f24ae4f40e29 [svn] - security and warning fixes from ssommer@suse
nenolod
parents: 2332
diff changeset
375 {
4124
d217b71e5836 more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4097
diff changeset
376 AUDDBG("could not execute cmd %s\n",cmd);
2361
f24ae4f40e29 [svn] - security and warning fixes from ssommer@suse
nenolod
parents: 2332
diff changeset
377 g_free(cmd);
f24ae4f40e29 [svn] - security and warning fixes from ssommer@suse
nenolod
parents: 2332
diff changeset
378 return NULL;
f24ae4f40e29 [svn] - security and warning fixes from ssommer@suse
nenolod
parents: 2332
diff changeset
379 }
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
380 g_free(cmd);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
381
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
382 return tmpdir;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
383 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
384
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
385
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
386 #ifdef HAVE_FTS_H
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
387
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
388 void
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
389 del_directory(const gchar * dirname)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
390 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
391 gchar *const argv[2] = { (gchar *) dirname, NULL };
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
392 FTS *fts;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
393 FTSENT *p;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
394
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
395 fts = fts_open(argv, FTS_PHYSICAL, (gint(*)())NULL);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
396 while ((p = fts_read(fts))) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
397 switch (p->fts_info) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
398 case FTS_D:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
399 break;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
400 case FTS_DNR:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
401 case FTS_ERR:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
402 break;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
403 case FTS_DP:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
404 rmdir(p->fts_accpath);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
405 break;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
406 default:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
407 unlink(p->fts_accpath);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
408 break;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
409 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
410 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
411 fts_close(fts);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
412 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
413
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
414 #else /* !HAVE_FTS */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
415
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
416 gboolean
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
417 del_directory_func(const gchar * path, const gchar * basename,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
418 gpointer params)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
419 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
420 if (!strcmp(basename, ".") || !strcmp(path, ".."))
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
421 return FALSE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
422
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
423 if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
424 dir_foreach(path, del_directory_func, NULL, NULL);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
425 rmdir(path);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
426 return FALSE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
427 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
428
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
429 unlink(path);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
430
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
431 return FALSE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
432 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
433
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
434 void
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
435 del_directory(const gchar * path)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
436 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
437 dir_foreach(path, del_directory_func, NULL, NULL);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
438 rmdir(path);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
439 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
440
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
441 #endif /* ifdef HAVE_FTS */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
442
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
443 static void
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
444 strip_string(GString *string)
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
445 {
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
446 while (string->len > 0 && string->str[0] == ' ')
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
447 g_string_erase(string, 0, 1);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
448
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
449 while (string->len > 0 && string->str[string->len - 1] == ' ')
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
450 g_string_erase(string, string->len - 1, 1);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
451 }
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
452
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
453 static void
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
454 strip_lower_string(GString *string)
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
455 {
2660
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
456 gchar *lower;
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
457 strip_string(string);
2609
fe33bdd3d5ad [svn] Prevent double free() by strdup'ing value.
hansmi
parents: 2607
diff changeset
458
2660
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
459 lower = g_ascii_strdown(string->str, -1);
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
460 g_free(string->str);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
461 string->str = lower;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
462 }
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
463
4157
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
464 static void
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
465 close_ini_file_free_value(gpointer value)
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
466 {
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
467 g_free((gchar*)value);
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
468 }
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
469
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
470 static void
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
471 close_ini_file_free_section(gpointer section)
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
472 {
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
473 g_hash_table_destroy((GHashTable*)section);
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
474 }
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
475
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
476 INIFile *
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
477 open_ini_file(const gchar *filename)
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
478 {
4157
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
479 GHashTable *ini_file = NULL;
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
480 GHashTable *section = NULL;
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
481 GString *section_name, *key_name, *value;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
482 gpointer section_hash, key_hash;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
483 gchar *buffer = NULL;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
484 gsize off = 0;
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
485 gsize filesize = 0;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
486
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
487 unsigned char x[] = { 0xff, 0xfe, 0x00 };
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
488
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
489 g_return_val_if_fail(filename, NULL);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
490 vfs_file_get_contents(filename, &buffer, &filesize);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
491 if (buffer == NULL)
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
492 return NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
493
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
494 /*
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
495 * Convert UTF-16 into something useful. Original implementation
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
496 * by incomp@#audacious. Cleanups \nenolod
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
497 * FIXME: can't we use a GLib function for that? -- 01mf02
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
498 */
2607
65543c999c7e [svn] Check filesize before doing memcmp (potential sigsegv).
hansmi
parents: 2556
diff changeset
499 if (filesize > 2 && !memcmp(&buffer[0],&x,2))
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
500 {
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
501 gchar *outbuf = g_malloc (filesize); /* it's safe to waste memory. */
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
502 guint counter;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
503
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
504 for (counter = 2; counter < filesize; counter += 2)
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
505 {
4157
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
506 if (!memcmp(&buffer[counter+1], &x[2], 1)) {
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
507 outbuf[(counter-2)/2] = buffer[counter];
4157
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
508 } else {
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
509 g_free(buffer);
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
510 g_free(outbuf);
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
511 return NULL;
4157
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
512 }
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
513 }
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
514
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
515 outbuf[(counter-2)/2] = '\0';
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
516
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
517 if ((filesize - 2) / 2 == (counter - 2) / 2)
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
518 {
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
519 g_free(buffer);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
520 buffer = outbuf;
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
521 }
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
522 else
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
523 {
4157
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
524 g_free(buffer);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
525 g_free(outbuf);
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
526 return NULL; /* XXX wrong encoding */
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
527 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
528 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
529
4157
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
530 section_name = g_string_new("");
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
531 key_name = g_string_new(NULL);
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
532 value = g_string_new(NULL);
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
533
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
534 ini_file = g_hash_table_new_full(NULL, NULL, NULL,
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
535 close_ini_file_free_section);
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
536 section = g_hash_table_new_full(NULL, NULL, NULL,
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
537 close_ini_file_free_value);
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
538 /* make a nameless section which should store all entries that are not
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
539 * embedded in a section */
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
540 section_hash = GINT_TO_POINTER(g_string_hash(section_name));
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
541 g_hash_table_insert(ini_file, section_hash, section);
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
542
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
543 while (off < filesize)
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
544 {
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
545 /* ignore the following characters */
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
546 if (buffer[off] == '\r' || buffer[off] == '\n' ||
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
547 buffer[off] == ' ' || buffer[off] == '\t')
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
548 {
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
549 if (buffer[off] == '\n')
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
550 {
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
551 g_string_free(key_name, TRUE);
4095
7e57ace6385a Fix memory leak in open_ini_file() function. (Bugzilla #17)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4073
diff changeset
552 g_string_free(value, TRUE);
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
553 key_name = g_string_new(NULL);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
554 value = g_string_new(NULL);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
555 }
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
556
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
557 off++;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
558 continue;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
559 }
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
560
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
561 /* if we encounter a possible section statement */
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
562 if (buffer[off] == '[')
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
563 {
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
564 g_string_free(section_name, TRUE);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
565 section_name = g_string_new(NULL);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
566 off++;
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
567
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
568 if (off >= filesize)
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
569 goto return_sequence;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
570
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
571 while (buffer[off] != ']')
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
572 {
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
573 /* if the section statement has not been closed before a
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
574 * linebreak */
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
575 if (buffer[off] == '\n')
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
576 break;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
577
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
578 g_string_append_c(section_name, buffer[off]);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
579 off++;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
580 if (off >= filesize)
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
581 goto return_sequence;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
582 }
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
583 if (buffer[off] == '\n')
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
584 continue;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
585 if (buffer[off] == ']')
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
586 {
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
587 off++;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
588 if (off >= filesize)
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
589 goto return_sequence;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
590
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
591 strip_lower_string(section_name);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
592 section_hash = GINT_TO_POINTER(g_string_hash(section_name));
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
593
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
594 /* if this section already exists, we don't make a new one,
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
595 * but reuse the old one */
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
596 if (g_hash_table_lookup(ini_file, section_hash) != NULL)
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
597 section = g_hash_table_lookup(ini_file, section_hash);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
598 else
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
599 {
4157
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
600 section = g_hash_table_new_full(NULL, NULL, NULL,
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
601 close_ini_file_free_value);
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
602 g_hash_table_insert(ini_file, section_hash, section);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
603 }
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
604
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
605 continue;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
606 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
607 }
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
608
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
609 if (buffer[off] == '=')
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
610 {
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
611 off++;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
612 if (off >= filesize)
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
613 goto return_sequence;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
614
2556
a221f10fd105 [svn] - or comparison should be an and comparison
nenolod
parents: 2555
diff changeset
615 while (buffer[off] != '\n' && buffer[off] != '\r')
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
616 {
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
617 g_string_append_c(value, buffer[off]);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
618 off++;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
619 if (off >= filesize)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
620 break;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
621 }
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
622
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
623 strip_lower_string(key_name);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
624 key_hash = GINT_TO_POINTER(g_string_hash(key_name));
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
625 strip_string(value);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
626
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
627 if (key_name->len > 0 && value->len > 0)
2609
fe33bdd3d5ad [svn] Prevent double free() by strdup'ing value.
hansmi
parents: 2607
diff changeset
628 g_hash_table_insert(section, key_hash, g_strdup(value->str));
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
629 }
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
630 else
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
631 {
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
632 g_string_append_c(key_name, buffer[off]);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
633 off++;
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
634 if (off >= filesize)
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
635 goto return_sequence;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
636 }
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
637 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
638
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
639 return_sequence:
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
640 g_string_free(section_name, TRUE);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
641 g_string_free(key_name, TRUE);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
642 g_string_free(value, TRUE);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
643 g_free(buffer);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
644 return ini_file;
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
645 }
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
646
4157
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
647 /**
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
648 * Frees the memory allocated for inifile.
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
649 */
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
650 void
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
651 close_ini_file(INIFile *inifile)
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
652 {
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
653 g_return_if_fail(inifile);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
654 g_hash_table_destroy(inifile);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
655 }
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
656
4157
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
657 /**
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
658 * Returns a string that corresponds to correct section and key in inifile.
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
659 *
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
660 * Returns NULL if value was not found in inifile. Otherwise returns a copy
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
661 * of string pointed by "section" and "key". Returned string should be freed
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
662 * after use.
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
663 */
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
664 gchar *
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
665 read_ini_string(INIFile *inifile, const gchar *section, const gchar *key)
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
666 {
2660
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
667 GString *section_string;
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
668 GString *key_string;
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
669 gchar *value = NULL;
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
670 gpointer section_hash, key_hash;
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
671 GHashTable *section_table;
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
672
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
673 g_return_val_if_fail(inifile, NULL);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
674
2660
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
675 section_string = g_string_new(section);
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
676 key_string = g_string_new(key);
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
677 value = NULL;
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
678
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
679 strip_lower_string(section_string);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
680 strip_lower_string(key_string);
2660
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
681 section_hash = GINT_TO_POINTER(g_string_hash(section_string));
8d0b89db56e5 [svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents: 2635
diff changeset
682 key_hash = GINT_TO_POINTER(g_string_hash(key_string));
4097
96194518173c Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4095
diff changeset
683 section_table = g_hash_table_lookup(inifile, section_hash);
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
684
4097
96194518173c Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4095
diff changeset
685 if (section_table) {
4157
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
686 value = g_strdup(g_hash_table_lookup(section_table,
e474286a4c23 Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4127
diff changeset
687 GINT_TO_POINTER(key_hash)));
4097
96194518173c Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4095
diff changeset
688 }
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
689
4097
96194518173c Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4095
diff changeset
690 g_string_free(section_string, TRUE);
96194518173c Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4095
diff changeset
691 g_string_free(key_string, TRUE);
96194518173c Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4095
diff changeset
692
96194518173c Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4095
diff changeset
693 g_return_val_if_fail(value, NULL);
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
694 return value;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
695 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
696
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
697 GArray *
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
698 read_ini_array(INIFile *inifile, const gchar *section, const gchar *key)
2514
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
699 {
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
700 gchar *temp;
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
701 GArray *a;
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
702
2529
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
703 g_return_val_if_fail((temp = read_ini_string(inifile, section, key)), NULL);
299be5908480 [svn] - made new INI file parser
mf0102
parents: 2514
diff changeset
704
2514
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
705 a = string_to_garray(temp);
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
706 g_free(temp);
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
707 return a;
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
708 }
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
709
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
710 GArray *
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
711 string_to_garray(const gchar * str)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
712 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
713 GArray *array;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
714 gint temp;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
715 const gchar *ptr = str;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
716 gchar *endptr;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
717
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
718 array = g_array_new(FALSE, TRUE, sizeof(gint));
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
719 for (;;) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
720 temp = strtol(ptr, &endptr, 10);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
721 if (ptr == endptr)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
722 break;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
723 g_array_append_val(array, temp);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
724 ptr = endptr;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
725 while (!isdigit((int) *ptr) && (*ptr) != '\0')
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
726 ptr++;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
727 if (*ptr == '\0')
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
728 break;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
729 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
730 return (array);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
731 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
732
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
733 void
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
734 glist_movedown(GList * list)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
735 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
736 gpointer temp;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
737
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
738 if (g_list_next(list)) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
739 temp = list->data;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
740 list->data = list->next->data;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
741 list->next->data = temp;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
742 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
743 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
744
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
745 void
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
746 glist_moveup(GList * list)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
747 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
748 gpointer temp;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
749
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
750 if (g_list_previous(list)) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
751 temp = list->data;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
752 list->data = list->prev->data;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
753 list->prev->data = temp;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
754 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
755 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
756
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
757
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
758 void
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
759 util_menu_position(GtkMenu * menu, gint * x, gint * y,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
760 gboolean * push_in, gpointer data)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
761 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
762 GtkRequisition requisition;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
763 gint screen_width;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
764 gint screen_height;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
765 MenuPos *pos = data;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
766
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
767 gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
768
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
769 screen_width = gdk_screen_width();
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
770 screen_height = gdk_screen_height();
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
771
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
772 *x = CLAMP(pos->x - 2, 0, MAX(0, screen_width - requisition.width));
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
773 *y = CLAMP(pos->y - 2, 0, MAX(0, screen_height - requisition.height));
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
774 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
775
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
776 GdkFont *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
777 util_font_load(const gchar * name)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
778 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
779 GdkFont *font;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
780 PangoFontDescription *desc;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
781
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
782 desc = pango_font_description_from_string(name);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
783 font = gdk_font_from_description(desc);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
784
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
785 return font;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
786 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
787
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
788 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
789 * Mattis et al */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
790 gboolean
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
791 text_get_extents(const gchar * fontname,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
792 const gchar * text,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
793 gint * width, gint * height, gint * ascent, gint * descent)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
794 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
795 PangoFontDescription *font_desc;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
796 PangoLayout *layout;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
797 PangoRectangle rect;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
798
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
799 g_return_val_if_fail(fontname != NULL, FALSE);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
800 g_return_val_if_fail(text != NULL, FALSE);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
801
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
802 /* FIXME: resolution */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
803 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
804
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
805 font_desc = pango_font_description_from_string(fontname);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
806 pango_layout_set_font_description(layout, font_desc);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
807 pango_font_description_free(font_desc);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
808 pango_layout_get_pixel_extents(layout, NULL, &rect);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
809
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
810 if (width)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
811 *width = rect.width;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
812 if (height)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
813 *height = rect.height;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
814
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
815 if (ascent || descent) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
816 PangoLayoutIter *iter;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
817 PangoLayoutLine *line;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
818
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
819 iter = pango_layout_get_iter(layout);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
820 line = pango_layout_iter_get_line(iter);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
821 pango_layout_iter_free(iter);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
822
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
823 pango_layout_line_get_pixel_extents(line, NULL, &rect);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
824
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
825 if (ascent)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
826 *ascent = PANGO_ASCENT(rect);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
827 if (descent)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
828 *descent = -PANGO_DESCENT(rect);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
829 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
830
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
831 g_object_unref(layout);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
832
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
833 return TRUE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
834 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
835
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
836 /* counts number of digits in a gint */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
837 guint
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
838 gint_count_digits(gint n)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
839 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
840 guint count = 0;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
841
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
842 n = ABS(n);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
843 do {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
844 count++;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
845 n /= 10;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
846 } while (n > 0);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
847
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
848 return count;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
849 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
850
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
851 gboolean
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
852 dir_foreach(const gchar * path, DirForeachFunc function,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
853 gpointer user_data, GError ** error)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
854 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
855 GError *error_out = NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
856 GDir *dir;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
857 const gchar *entry;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
858 gchar *entry_fullpath;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
859
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
860 if (!(dir = g_dir_open(path, 0, &error_out))) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
861 g_propagate_error(error, error_out);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
862 return FALSE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
863 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
864
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
865 while ((entry = g_dir_read_name(dir))) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
866 entry_fullpath = g_build_filename(path, entry, NULL);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
867
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
868 if ((*function) (entry_fullpath, entry, user_data)) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
869 g_free(entry_fullpath);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
870 break;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
871 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
872
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
873 g_free(entry_fullpath);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
874 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
875
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
876 g_dir_close(dir);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
877
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
878 return TRUE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
879 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
880
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
881 GtkWidget *
2514
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
882 make_filebrowser(const gchar *title, gboolean save)
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
883 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
884 GtkWidget *dialog;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
885 GtkWidget *button;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
886
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
887 g_return_val_if_fail(title != NULL, NULL);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
888
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
889 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin),
2514
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
890 save ?
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
891 GTK_FILE_CHOOSER_ACTION_SAVE :
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
892 GTK_FILE_CHOOSER_ACTION_OPEN,
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
893 NULL, NULL);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
894
2514
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
895 button = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL,
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
896 GTK_RESPONSE_REJECT);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
897
2514
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
898 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE);
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
899 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
900
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
901 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ?
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
902 GTK_STOCK_SAVE : GTK_STOCK_OPEN,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
903 GTK_RESPONSE_ACCEPT);
2514
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
904
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
905 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE);
2514
7934ac463591 [svn] - removed unused function bmp_menu_translate()
mf0102
parents: 2494
diff changeset
906 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
2635
9b763f1f4e6a [svn] tweak UI behaviors:
yaz
parents: 2609
diff changeset
907 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); /* centering */
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
908
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
909 return dialog;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
910 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
911
4212
47352b34dbdf introduce ui_skinned_widget_draw
Tomasz Mon <desowin@gmail.com>
parents: 4157
diff changeset
912 void ui_skinned_widget_draw(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gboolean scale) {
47352b34dbdf introduce ui_skinned_widget_draw
Tomasz Mon <desowin@gmail.com>
parents: 4157
diff changeset
913 g_return_if_fail(widget != NULL);
47352b34dbdf introduce ui_skinned_widget_draw
Tomasz Mon <desowin@gmail.com>
parents: 4157
diff changeset
914 g_return_if_fail(obj != NULL);
47352b34dbdf introduce ui_skinned_widget_draw
Tomasz Mon <desowin@gmail.com>
parents: 4157
diff changeset
915
47352b34dbdf introduce ui_skinned_widget_draw
Tomasz Mon <desowin@gmail.com>
parents: 4157
diff changeset
916 if (scale) {
4223
2c9c2b5caaee changed the hardcoded scale to 1.2 and set some dither and interpolation
Cristi Magherusan <majeru@atheme.org>
parents: 4218
diff changeset
917 GdkPixbuf *image = gdk_pixbuf_scale_simple(obj, width * cfg.scale_factor, height* cfg.scale_factor, GDK_INTERP_BILINEAR);
2c9c2b5caaee changed the hardcoded scale to 1.2 and set some dither and interpolation
Cristi Magherusan <majeru@atheme.org>
parents: 4218
diff changeset
918 gdk_draw_pixbuf(widget->window, NULL, image, 0, 0, 0, 0, width * cfg.scale_factor , height * cfg.scale_factor, GDK_RGB_DITHER_NORMAL, 0, 0);
4212
47352b34dbdf introduce ui_skinned_widget_draw
Tomasz Mon <desowin@gmail.com>
parents: 4157
diff changeset
919 g_object_unref(image);
47352b34dbdf introduce ui_skinned_widget_draw
Tomasz Mon <desowin@gmail.com>
parents: 4157
diff changeset
920 } else {
47352b34dbdf introduce ui_skinned_widget_draw
Tomasz Mon <desowin@gmail.com>
parents: 4157
diff changeset
921 gdk_draw_pixbuf(widget->window, NULL, obj, 0, 0, 0, 0, width, height, GDK_RGB_DITHER_NONE, 0, 0);
47352b34dbdf introduce ui_skinned_widget_draw
Tomasz Mon <desowin@gmail.com>
parents: 4157
diff changeset
922 }
47352b34dbdf introduce ui_skinned_widget_draw
Tomasz Mon <desowin@gmail.com>
parents: 4157
diff changeset
923 }
47352b34dbdf introduce ui_skinned_widget_draw
Tomasz Mon <desowin@gmail.com>
parents: 4157
diff changeset
924
2421
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
925 /**
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
926 * xmms_show_message:
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
927 * @title: The title of the message to show.
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
928 * @text: The text of the message to show.
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
929 * @button_text: The text of the button which will close the messagebox.
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
930 * @modal: Whether or not the messagebox should be modal.
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
931 * @button_action: Code to execute on when the messagebox is closed, or %NULL.
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
932 * @action_data: Optional opaque data to pass to @button_action.
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
933 *
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
934 * Displays a message box.
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
935 *
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
936 * Return value: A GTK widget handle for the message box.
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
937 **/
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
938 GtkWidget *
3731
0e5da33a32b7 fun util dialog shit -> vtable
William Pitcock <nenolod@atheme.org>
parents: 3730
diff changeset
939 util_info_dialog(const gchar * title, const gchar * text,
0e5da33a32b7 fun util dialog shit -> vtable
William Pitcock <nenolod@atheme.org>
parents: 3730
diff changeset
940 const gchar * button_text, gboolean modal,
0e5da33a32b7 fun util dialog shit -> vtable
William Pitcock <nenolod@atheme.org>
parents: 3730
diff changeset
941 GCallback button_action, gpointer action_data)
2421
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
942 {
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
943 GtkWidget *dialog;
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
944 GtkWidget *dialog_vbox, *dialog_hbox, *dialog_bbox;
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
945 GtkWidget *dialog_bbox_b1;
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
946 GtkWidget *dialog_textlabel;
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
947 GtkWidget *dialog_icon;
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
948
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
949 dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
950 gtk_window_set_type_hint( GTK_WINDOW(dialog) , GDK_WINDOW_TYPE_HINT_DIALOG );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
951 gtk_window_set_modal( GTK_WINDOW(dialog) , modal );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
952 gtk_window_set_title( GTK_WINDOW(dialog) , title );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
953 gtk_container_set_border_width( GTK_CONTAINER(dialog) , 10 );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
954
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
955 dialog_vbox = gtk_vbox_new( FALSE , 0 );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
956 dialog_hbox = gtk_hbox_new( FALSE , 0 );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
957
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
958 /* icon */
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
959 dialog_icon = gtk_image_new_from_stock( GTK_STOCK_DIALOG_INFO , GTK_ICON_SIZE_DIALOG );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
960 gtk_box_pack_start( GTK_BOX(dialog_hbox) , dialog_icon , FALSE , FALSE , 2 );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
961
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
962 /* label */
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
963 dialog_textlabel = gtk_label_new( text );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
964 /* gtk_label_set_selectable( GTK_LABEL(dialog_textlabel) , TRUE ); */
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
965 gtk_box_pack_start( GTK_BOX(dialog_hbox) , dialog_textlabel , TRUE , TRUE , 2 );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
966
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
967 gtk_box_pack_start( GTK_BOX(dialog_vbox) , dialog_hbox , FALSE , FALSE , 2 );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
968 gtk_box_pack_start( GTK_BOX(dialog_vbox) , gtk_hseparator_new() , FALSE , FALSE , 4 );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
969
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
970 dialog_bbox = gtk_hbutton_box_new();
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
971 gtk_button_box_set_layout( GTK_BUTTON_BOX(dialog_bbox) , GTK_BUTTONBOX_END );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
972 dialog_bbox_b1 = gtk_button_new_with_label( button_text );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
973 g_signal_connect_swapped( G_OBJECT(dialog_bbox_b1) , "clicked" ,
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
974 G_CALLBACK(gtk_widget_destroy) , dialog );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
975 if ( button_action )
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
976 g_signal_connect( G_OBJECT(dialog_bbox_b1) , "clicked" ,
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
977 button_action , action_data );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
978
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
979 gtk_container_add( GTK_CONTAINER(dialog_bbox) , dialog_bbox_b1 );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
980 gtk_box_pack_start( GTK_BOX(dialog_vbox) , dialog_bbox , FALSE , FALSE , 0 );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
981
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
982 gtk_container_add( GTK_CONTAINER(dialog) , dialog_vbox );
3120
3262bf0b8831 Moving gtk_widget_grab_default() below gtk_container_add() to avoid this
Christian Birchinger <joker@netswarm.net>
parents: 3103
diff changeset
983
3262bf0b8831 Moving gtk_widget_grab_default() below gtk_container_add() to avoid this
Christian Birchinger <joker@netswarm.net>
parents: 3103
diff changeset
984 GTK_WIDGET_SET_FLAGS( dialog_bbox_b1 , GTK_CAN_DEFAULT);
3262bf0b8831 Moving gtk_widget_grab_default() below gtk_container_add() to avoid this
Christian Birchinger <joker@netswarm.net>
parents: 3103
diff changeset
985 gtk_widget_grab_default( dialog_bbox_b1 );
3262bf0b8831 Moving gtk_widget_grab_default() below gtk_container_add() to avoid this
Christian Birchinger <joker@netswarm.net>
parents: 3103
diff changeset
986
2421
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
987 gtk_widget_show_all(dialog);
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
988
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
989 return dialog;
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
990 }
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
991
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
992
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
993 /**
3757
d24d28e76588 export util_get_localdir().
William Pitcock <nenolod@atheme.org>
parents: 3731
diff changeset
994 * util_get_localdir:
2421
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
995 *
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
996 * Returns a string with the full path of Audacious local datadir (where config files are placed).
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
997 * It's useful in order to put in the right place custom config files for audacious plugins.
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
998 *
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
999 * Return value: a string with full path of Audacious local datadir (should be freed after use)
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1000 **/
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1001 gchar*
3757
d24d28e76588 export util_get_localdir().
William Pitcock <nenolod@atheme.org>
parents: 3731
diff changeset
1002 util_get_localdir(void)
2421
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1003 {
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1004 gchar *datadir;
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1005 gchar *tmp;
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1006
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1007 if ( (tmp = getenv("XDG_CONFIG_HOME")) == NULL )
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1008 datadir = g_build_filename( g_get_home_dir() , ".config" , "audacious" , NULL );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1009 else
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1010 datadir = g_build_filename( tmp , "audacious" , NULL );
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1011
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1012 return datadir;
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1013 }
74ec16ef847b [svn] - fix accidental removal of xmms_show_message
nenolod
parents: 2416
diff changeset
1014
4070
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1015
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1016 gchar *
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1017 construct_uri(gchar *string, const gchar *playlist_name) // uri, path and anything else
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1018 {
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1019 gchar *filename = g_strdup(string);
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1020 gchar *tmp, *path;
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1021 gchar *uri = NULL;
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1022
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1023 /* try to translate dos path */
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1024 convert_dos_path(filename); /* in place replacement */
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1025
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1026 // make full path uri here
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1027 // case 1: filename is raw full path or uri
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1028 if (filename[0] == '/' || strstr(filename, "://")) {
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1029 uri = g_filename_to_uri(filename, NULL, NULL);
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1030 if(!uri) {
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1031 uri = g_strdup(filename);
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1032 }
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1033 g_free(filename);
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1034 }
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1035 // case 2: filename is not raw full path nor uri, playlist path is full path
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1036 // make full path by replacing last part of playlist path with filename. (using g_build_filename)
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1037 else if (playlist_name[0] == '/' || strstr(playlist_name, "://")) {
4451
539f3cb7b1e8 Fix relative paths in construct_uri() function. (Bugzilla #246)
Paul Marks <paul@pmarks.net>
parents: 4352
diff changeset
1038 path = g_filename_from_uri(playlist_name, NULL, NULL);
539f3cb7b1e8 Fix relative paths in construct_uri() function. (Bugzilla #246)
Paul Marks <paul@pmarks.net>
parents: 4352
diff changeset
1039 if (!path) {
539f3cb7b1e8 Fix relative paths in construct_uri() function. (Bugzilla #246)
Paul Marks <paul@pmarks.net>
parents: 4352
diff changeset
1040 path = g_strdup(playlist_name);
539f3cb7b1e8 Fix relative paths in construct_uri() function. (Bugzilla #246)
Paul Marks <paul@pmarks.net>
parents: 4352
diff changeset
1041 }
4070
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1042 tmp = strrchr(path, '/'); *tmp = '\0';
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1043 tmp = g_build_filename(path, filename, NULL);
4073
22a86d4671b5 fix a memory leak.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4070
diff changeset
1044 g_free(path); g_free(filename);
4070
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1045 uri = g_filename_to_uri(tmp, NULL, NULL);
4073
22a86d4671b5 fix a memory leak.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4070
diff changeset
1046 g_free(tmp);
4070
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1047 }
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1048 // case 3: filename is not raw full path nor uri, playlist path is not full path
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1049 // just abort.
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1050 else {
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1051 g_free(filename);
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1052 return NULL;
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1053 }
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1054
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1055 AUDDBG("uri=%s\n", uri);
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1056 return uri;
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3993
diff changeset
1057 }
4267
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1058
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1059 /*
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1060 * minimize number of realloc's:
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1061 * - set N to nearest power of 2 not less then N
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1062 * - double it
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1063 *
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1064 * -- asphyx
4278
0a9e1d9eae7b Fix some warnings.
William Pitcock <nenolod@atheme.org>
parents: 4267
diff changeset
1065 *
0a9e1d9eae7b Fix some warnings.
William Pitcock <nenolod@atheme.org>
parents: 4267
diff changeset
1066 * XXX: what's so smart about this?? seems wasteful and silly. --nenolod
4267
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1067 */
4278
0a9e1d9eae7b Fix some warnings.
William Pitcock <nenolod@atheme.org>
parents: 4267
diff changeset
1068 gpointer
0a9e1d9eae7b Fix some warnings.
William Pitcock <nenolod@atheme.org>
parents: 4267
diff changeset
1069 smart_realloc(gpointer ptr, gsize *size)
0a9e1d9eae7b Fix some warnings.
William Pitcock <nenolod@atheme.org>
parents: 4267
diff changeset
1070 {
4267
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1071 *size = (size_t)pow(2, ceil(log(*size) / log(2)) + 1);
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1072 if (ptr != NULL) free(ptr);
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1073 ptr = malloc(*size);
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1074 return ptr;
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1075 }
a41fb6bc632a - src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4259
diff changeset
1076
4352
ac1f6d211223 Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents: 4347
diff changeset
1077 void
ac1f6d211223 Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents: 4347
diff changeset
1078 make_directory(const gchar * path, mode_t mode)
ac1f6d211223 Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents: 4347
diff changeset
1079 {
ac1f6d211223 Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents: 4347
diff changeset
1080 if (g_mkdir_with_parents(path, mode) == 0)
ac1f6d211223 Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents: 4347
diff changeset
1081 return;
ac1f6d211223 Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents: 4347
diff changeset
1082
ac1f6d211223 Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents: 4347
diff changeset
1083 g_printerr(_("Could not create directory (%s): %s\n"), path,
ac1f6d211223 Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents: 4347
diff changeset
1084 g_strerror(errno));
ac1f6d211223 Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents: 4347
diff changeset
1085 }