Mercurial > hg > xmms-sid
annotate src/xs_support.c @ 87:94497283affa
Various fixes and improvements
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 05 Oct 2003 10:38:03 +0000 |
parents | 85811bcd049e |
children | 578b71b62eeb |
rev | line source |
---|---|
4 | 1 /* |
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) | |
3 | |
4 Miscellaneous support functions | |
5 | |
6 Written by Matti "ccr" Hamalainen <ccr@tnsp.org> | |
7 | |
8 This program is free software; you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation; either version 2 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program; if not, write to the Free Software | |
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
21 */ | |
22 | |
49
3518ca5c8b0f
Support for compile-time big/little-endian optimizations in audio output
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
23 #include "xs_support.h" |
4 | 24 #include <stdlib.h> |
25 #include <string.h> | |
26 #include <ctype.h> | |
27 | |
28 /* | |
29 * Utility routines | |
30 */ | |
38 | 31 gint xs_strcalloc(gchar **ppcResult, const gchar *pcStr) |
4 | 32 { |
38 | 33 assert(ppcResult); |
34 assert(pcStr); | |
35 | |
36 /* Allocate memory for destination */ | |
37 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(pcStr) + 1); | |
40
1788f4ce6a44
Numerous changes towards 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
38 if (*ppcResult == NULL) return -1; |
4 | 39 |
38 | 40 /* Copy to the destination */ |
41 strcpy(*ppcResult, pcStr); | |
4 | 42 |
38 | 43 return 0; |
4 | 44 } |
45 | |
46 | |
47 int xs_strcat(gchar **ppcResult, const gchar *pcStr) | |
48 { | |
38 | 49 assert(ppcResult); |
50 assert(pcStr); | |
51 | |
52 /* Re-allocate memory for destination */ | |
53 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(*ppcResult) + strlen(pcStr) + 1); | |
54 if (*ppcResult == NULL) return -1; | |
4 | 55 |
38 | 56 /* Cat to the destination */ |
57 strcat(*ppcResult, pcStr); | |
4 | 58 |
38 | 59 return 0; |
4 | 60 } |
61 | |
62 | |
56
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
63 gchar *xs_strrchr(gchar *pcStr, gchar ch) |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
64 { |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
65 gchar *lastPos = NULL; |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
66 |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
67 while (*pcStr) |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
68 { |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
69 if (*pcStr == ch) lastPos = pcStr; |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
70 pcStr++; |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
71 } |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
72 |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
73 return lastPos; |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
74 } |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
75 |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
76 |
4 | 77 inline void xs_findnext(gchar *pcStr, gint *piPos) |
78 { | |
79 /* Terminating NULL-character is not whitespace! */ | |
80 while (isspace(pcStr[*piPos])) (*piPos)++; | |
81 } | |
82 | |
83 | |
84 inline void xs_findnum(gchar *pcStr, gint *piPos) | |
85 { | |
86 /* Terminating NULL-character is not digit! */ | |
87 while (isdigit(pcStr[*piPos])) (*piPos)++; | |
88 } | |
89 | |
90 |