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
|
|
23 #include "xmms-sid.h"
|
|
24 #include <stdlib.h>
|
|
25 #include <string.h>
|
|
26 #include <ctype.h>
|
|
27
|
|
28 /*
|
|
29 * Utility routines
|
|
30 */
|
|
31 int xs_strcalloc(gchar **result, const gchar *str)
|
|
32 {
|
|
33 /* Check the string pointers */
|
|
34 if ((result == NULL) || (str == NULL))
|
|
35 return -1;
|
|
36
|
|
37 /* Allocate memory for destination */
|
|
38 *result = (gchar *) g_realloc(*result, strlen(str) + 1);
|
|
39
|
|
40 if (*result == NULL) return -2;
|
|
41
|
|
42 /* Copy to the destination */
|
|
43 strcpy(*result, str);
|
|
44
|
|
45 return 0;
|
|
46 }
|
|
47
|
|
48
|
|
49 int xs_strcat(gchar **ppcResult, const gchar *pcStr)
|
|
50 {
|
|
51 int ilen;
|
|
52
|
|
53 /* Check the pcString pointers */
|
|
54 if ((ppcResult == NULL) || (pcStr == NULL))
|
|
55 return -1;
|
|
56
|
|
57 /* Get length of the pcString to be catted */
|
|
58 ilen = strlen(pcStr);
|
|
59
|
|
60 /* Re-allocate memory for destination */
|
|
61 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(*ppcResult) + ilen + 1);
|
|
62
|
|
63 if (*ppcResult == NULL) return -2;
|
|
64
|
|
65 /* Cat to the destination */
|
|
66 strcat(*ppcResult, pcStr);
|
|
67
|
|
68 return 0;
|
|
69 }
|
|
70
|
|
71
|
|
72 int xs_strcpy(gchar **ppcResult, gint *j, const gchar *pcStr)
|
|
73 {
|
|
74 int ilen;
|
|
75
|
|
76 /* Check the pcString pointers */
|
|
77 if ((ppcResult == NULL) || (pcStr == NULL) || (j == NULL))
|
|
78 return -1;
|
|
79
|
|
80 /* Get length of the pcString to be catted */
|
|
81 (*j) += ilen = strlen(pcStr);
|
|
82
|
|
83 /* Re-allocate memory for destination */
|
|
84 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(*ppcResult) + ilen + 1);
|
|
85
|
|
86 if (*ppcResult == NULL) return -2;
|
|
87
|
|
88 /* Cat to the destination */
|
|
89 strcat(*ppcResult, pcStr);
|
|
90
|
|
91 return 0;
|
|
92 }
|
|
93
|
|
94
|
|
95 inline void xs_findnext(gchar *pcStr, gint *piPos)
|
|
96 {
|
|
97 /* Terminating NULL-character is not whitespace! */
|
|
98 while (isspace(pcStr[*piPos])) (*piPos)++;
|
|
99 }
|
|
100
|
|
101
|
|
102 inline void xs_findnum(gchar *pcStr, gint *piPos)
|
|
103 {
|
|
104 /* Terminating NULL-character is not digit! */
|
|
105 while (isdigit(pcStr[*piPos])) (*piPos)++;
|
|
106 }
|
|
107
|
|
108
|