annotate src/xs_support.c @ 40:1788f4ce6a44

Numerous changes towards 0.8
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 19 Jun 2003 22:38:01 +0000
parents dec37e16136e
children 3518ca5c8b0f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 Miscellaneous support functions
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 Written by Matti "ccr" Hamalainen <ccr@tnsp.org>
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 This program is free software; you can redistribute it and/or modify
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 the Free Software Foundation; either version 2 of the License, or
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 (at your option) any later version.
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 GNU General Public License for more details.
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 along with this program; if not, write to the Free Software
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 */
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 #include "xmms-sid.h"
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 #include <stdlib.h>
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 #include <string.h>
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 #include <ctype.h>
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 /*
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 * Utility routines
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 */
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
31 gint xs_strcalloc(gchar **ppcResult, const gchar *pcStr)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 {
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
33 assert(ppcResult);
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
34 assert(pcStr);
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
35
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
36 /* Allocate memory for destination */
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
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
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
40 /* Copy to the destination */
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
41 strcpy(*ppcResult, pcStr);
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
43 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 int xs_strcat(gchar **ppcResult, const gchar *pcStr)
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 {
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
49 assert(ppcResult);
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
50 assert(pcStr);
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
51
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
52 /* Re-allocate memory for destination */
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
53 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(*ppcResult) + strlen(pcStr) + 1);
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
54 if (*ppcResult == NULL) return -1;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
56 /* Cat to the destination */
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
57 strcat(*ppcResult, pcStr);
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
59 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
63 int xs_strpcat(gchar **ppcResult, gint *j, const gchar *pcStr)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 {
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
65 int iLen;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
67 assert(ppcResult);
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
68 assert(pcStr);
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
69 assert(j);
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
70
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
71 /* Get length of the pcString to be catted */
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
72 iLen = strlen(pcStr);
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
73 (*j) += iLen;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
75 /* Re-allocate memory for destination */
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
76 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(*ppcResult) + iLen + 1);
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
77 if (*ppcResult == NULL) return -1;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
79 /* Cat to the destination */
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
80 strcat(*ppcResult, pcStr);
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
82 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 inline void xs_findnext(gchar *pcStr, gint *piPos)
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 {
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 /* Terminating NULL-character is not whitespace! */
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 while (isspace(pcStr[*piPos])) (*piPos)++;
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 inline void xs_findnum(gchar *pcStr, gint *piPos)
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 {
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 /* Terminating NULL-character is not digit! */
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 while (isdigit(pcStr[*piPos])) (*piPos)++;
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99