Mercurial > audlegacy-plugins
annotate src/sid/xs_support.c @ 3076:5b59df43b93f
Update the playback slider at the end of a seek (bug #31)
author | John Lindgren <john.lindgren@tds.net> |
---|---|
date | Sun, 26 Apr 2009 16:11:55 -0400 |
parents | 78b8e3614df7 |
children |
rev | line source |
---|---|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
1 /* |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
3 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
4 Miscellaneous support functions |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
5 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
735
6c3c7b841382
[svn] - sync audacious-sid with latest xmms-sid, from Matti Hamalainen (ccr).
nenolod
parents:
12
diff
changeset
|
7 (C) Copyright 1999-2007 Tecnic Software productions (TNSP) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
8 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
9 This program is free software; you can redistribute it and/or modify |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
10 it under the terms of the GNU General Public License as published by |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
11 the Free Software Foundation; either version 2 of the License, or |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
12 (at your option) any later version. |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
13 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
14 This program is distributed in the hope that it will be useful, |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
15 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
17 GNU General Public License for more details. |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
18 |
735
6c3c7b841382
[svn] - sync audacious-sid with latest xmms-sid, from Matti Hamalainen (ccr).
nenolod
parents:
12
diff
changeset
|
19 You should have received a copy of the GNU General Public License along |
6c3c7b841382
[svn] - sync audacious-sid with latest xmms-sid, from Matti Hamalainen (ccr).
nenolod
parents:
12
diff
changeset
|
20 with this program; if not, write to the Free Software Foundation, Inc., |
6c3c7b841382
[svn] - sync audacious-sid with latest xmms-sid, from Matti Hamalainen (ccr).
nenolod
parents:
12
diff
changeset
|
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
22 */ |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
23 #include "xs_support.h" |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
24 #include <ctype.h> |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
25 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
26 |
2507
251336bee085
Cosmetic cleanups, synchronized from XMMS-SID.
Matti Hamalainen <ccr@tnsp.org>
parents:
2474
diff
changeset
|
27 guint16 xs_fread_be16(xs_file_t *f) |
735
6c3c7b841382
[svn] - sync audacious-sid with latest xmms-sid, from Matti Hamalainen (ccr).
nenolod
parents:
12
diff
changeset
|
28 { |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
29 return (((guint16) xs_fgetc(f)) << 8) | ((guint16) xs_fgetc(f)); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
30 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
31 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
32 |
2507
251336bee085
Cosmetic cleanups, synchronized from XMMS-SID.
Matti Hamalainen <ccr@tnsp.org>
parents:
2474
diff
changeset
|
33 guint32 xs_fread_be32(xs_file_t *f) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
34 { |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
35 return (((guint32) xs_fgetc(f)) << 24) | |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
36 (((guint32) xs_fgetc(f)) << 16) | |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
37 (((guint32) xs_fgetc(f)) << 8) | |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
38 ((guint32) xs_fgetc(f)); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
39 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
40 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
41 |
735
6c3c7b841382
[svn] - sync audacious-sid with latest xmms-sid, from Matti Hamalainen (ccr).
nenolod
parents:
12
diff
changeset
|
42 /* Load a file to a buffer, return 0 on success, negative value on error |
6c3c7b841382
[svn] - sync audacious-sid with latest xmms-sid, from Matti Hamalainen (ccr).
nenolod
parents:
12
diff
changeset
|
43 */ |
2507
251336bee085
Cosmetic cleanups, synchronized from XMMS-SID.
Matti Hamalainen <ccr@tnsp.org>
parents:
2474
diff
changeset
|
44 gint xs_fload_buffer(const gchar *filename, guint8 **buf, size_t *bufSize) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
45 { |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
46 xs_file_t *f; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
47 glong seekPos; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
48 |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
49 /* Open file, get file size */ |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
50 if ((f = xs_fopen(filename, "rb")) == NULL) |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
51 return -1; |
735
6c3c7b841382
[svn] - sync audacious-sid with latest xmms-sid, from Matti Hamalainen (ccr).
nenolod
parents:
12
diff
changeset
|
52 |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
53 xs_fseek(f, 0, SEEK_END); |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
54 seekPos = xs_ftell(f); |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
55 |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
56 if (seekPos > 0) { |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
57 size_t readSize = seekPos; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
58 if (readSize >= *bufSize || *buf == NULL) { |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
59 /* Only re-allocate if the required size > current */ |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
60 if (*buf != NULL) { |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
61 g_free(*buf); |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
62 *buf = NULL; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
63 } |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
64 |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
65 *bufSize = seekPos; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
66 |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
67 *buf = (guint8 *) g_malloc(*bufSize * sizeof(guint8)); |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
68 if (*buf == NULL) { |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
69 xs_fclose(f); |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
70 return -2; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
71 } |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
72 } |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
73 |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
74 /* Read data */ |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
75 xs_fseek(f, 0, SEEK_SET); |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
76 readSize = xs_fread(*buf, sizeof(guint8), *bufSize, f); |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
77 xs_fclose(f); |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
78 |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
79 if (readSize != *bufSize) |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
80 return -3; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
81 else |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
82 return 0; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
83 } else { |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
84 xs_fclose(f); |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
85 return -4; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
86 } |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
87 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
88 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
89 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
90 /* Copy a string |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
91 */ |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
92 gchar *xs_strncpy(gchar *dest, const gchar *src, size_t n) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
93 { |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
94 const gchar *s; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
95 gchar *d; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
96 size_t i; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
97 |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
98 /* Check the string pointers */ |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
99 if (!src || !dest) |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
100 return dest; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
101 |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
102 /* Copy to the destination */ |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
103 i = n; |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
104 s = src; |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
105 d = dest; |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
106 while (*s && (i > 0)) { |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
107 *(d++) = *(s++); |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
108 i--; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
109 } |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
110 |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
111 /* Fill rest of space with zeros */ |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
112 while (i > 0) { |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
113 *(d++) = 0; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
114 i--; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
115 } |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
116 |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
117 /* Ensure that last is always zero */ |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
118 dest[n - 1] = 0; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
119 |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
120 return dest; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
121 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
122 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
123 |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
124 /* Copy a given string over in *result. |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
125 */ |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
126 gint xs_pstrcpy(gchar **result, const gchar *str) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
127 { |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
128 /* Check the string pointers */ |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
129 if (!result || !str) |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
130 return -1; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
131 |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
132 /* Allocate memory for destination */ |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
133 if (*result) |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
134 g_free(*result); |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
135 *result = (gchar *) g_malloc(strlen(str) + 1); |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
136 if (!*result) |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
137 return -2; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
138 |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
139 /* Copy to the destination */ |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
140 strcpy(*result, str); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
141 |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
142 return 0; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
143 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
144 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
145 |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
146 /* Concatenates a given string into string pointed by *result. |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
147 */ |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
148 gint xs_pstrcat(gchar **result, const gchar *str) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
149 { |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
150 /* Check the string pointers */ |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
151 if (!result || !str) |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
152 return -1; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
153 |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
154 if (*result != NULL) { |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
155 *result = (gchar *) g_realloc(*result, strlen(*result) + strlen(str) + 1); |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
156 if (*result == NULL) |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
157 return -1; |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
158 strcat(*result, str); |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
159 } else { |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
160 *result = (gchar *) g_malloc(strlen(str) + 1); |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
161 if (*result == NULL) |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
162 return -1; |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
163 strcpy(*result, str); |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
164 } |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
165 |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
166 return 0; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
167 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
168 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
169 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
170 /* Concatenate a given string up to given dest size or \n. |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
171 * If size max is reached, change the end to "..." |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
172 */ |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
173 void xs_pnstrcat(gchar *dest, size_t iSize, const gchar *str) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
174 { |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
175 size_t i, n; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
176 const gchar *s; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
177 gchar *d; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
178 |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
179 d = dest; |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
180 i = 0; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
181 while (*d && (i < iSize)) { |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
182 i++; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
183 d++; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
184 } |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
185 |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
186 s = str; |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
187 while (*s && (*s != '\n') && (i < iSize)) { |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
188 *d = *s; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
189 d++; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
190 s++; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
191 i++; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
192 } |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
193 |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
194 *d = 0; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
195 |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
196 if (i >= iSize) { |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
197 i--; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
198 d--; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
199 n = 3; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
200 while ((i > 0) && (n > 0)) { |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
201 *d = '.'; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
202 d--; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
203 i--; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
204 n--; |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
205 } |
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
206 } |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
207 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
208 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
209 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
210 /* Locate character in string |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
211 */ |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
212 gchar *xs_strrchr(gchar *str, const gchar ch) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
213 { |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
214 gchar *lastPos = NULL; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
215 |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
216 while (*str) { |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
217 if (*str == ch) |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
218 lastPos = str; |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
219 str++; |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
220 } |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
221 |
2509
1223e8510d8a
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
2507
diff
changeset
|
222 return lastPos; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
223 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
224 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
225 |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
226 void xs_findnext(const gchar *str, size_t *pos) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
227 { |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
228 while (str[*pos] && isspace(str[*pos])) |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
229 (*pos)++; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
230 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
231 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
232 |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
233 void xs_findeol(const gchar *str, size_t *pos) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
234 { |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
235 while (str[*pos] && (str[*pos] != '\n') && (str[*pos] != '\r')) |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
236 (*pos)++; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
237 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
238 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
239 |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
240 void xs_findnum(const gchar *str, size_t *pos) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
241 { |
2510
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
242 while (str[*pos] && isdigit(str[*pos])) |
78b8e3614df7
Cosmetic variable and function argument name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2509
diff
changeset
|
243 (*pos)++; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
244 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
245 |