annotate Plugins/Input/sid/xs_support.c @ 808:7a1a46811a45 trunk

[svn] - fix a FD leak here
author nenolod
date Wed, 08 Mar 2006 10:11:37 -0800
parents 1b82a9932b60
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
269
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
1 /*
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
3
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
4 Miscellaneous support functions
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
5
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
7 (C) Copyright 1999-2005 Tecnic Software productions (TNSP)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
8
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
9 This program is free software; you can redistribute it and/or modify
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
10 it under the terms of the GNU General Public License as published by
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
11 the Free Software Foundation; either version 2 of the License, or
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
12 (at your option) any later version.
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
13
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
14 This program is distributed in the hope that it will be useful,
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
17 GNU General Public License for more details.
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
18
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
20 along with this program; if not, write to the Free Software
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
22 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
23 #include "xmms-sid.h"
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
24 #include "xs_support.h"
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
25 #include <ctype.h>
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
26
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
27
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
28 /* Bigendian file reading functions
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
29 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
30 guint16 xs_rd_be16(FILE * f)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
31 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
32 return (((guint16) fgetc(f)) << 8) | ((guint16) fgetc(f));
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
33 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
34
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
35
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
36 guint32 xs_rd_be32(FILE * f)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
37 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
38 return (((guint32) fgetc(f)) << 24) |
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
39 (((guint32) fgetc(f)) << 16) | (((guint32) fgetc(f)) << 8) | ((guint32) fgetc(f));
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
40 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
41
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
42
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
43 size_t xs_rd_str(FILE * f, gchar * s, size_t l)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
44 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
45 return fread(s, sizeof(gchar), l, f);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
46 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
47
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
48
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
49 /* Copy a string
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
50 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
51 gchar *xs_strncpy(gchar * pDest, gchar * pSource, size_t n)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
52 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
53 gchar *s, *d;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
54 size_t i;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
55
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
56 /* Check the string pointers */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
57 if (!pSource || !pDest)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
58 return pDest;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
59
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
60 /* Copy to the destination */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
61 i = n;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
62 s = pSource;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
63 d = pDest;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
64 while (*s && (i > 0)) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
65 *(d++) = *(s++);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
66 i--;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
67 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
68
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
69 /* Fill rest of space with zeros */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
70 while (i > 0) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
71 *(d++) = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
72 i--;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
73 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
74
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
75 /* Ensure that last is always zero */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
76 pDest[n - 1] = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
77
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
78 return pDest;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
79 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
80
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
81
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
82 /* Copy a given string over in *ppResult.
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
83 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
84 gint xs_pstrcpy(gchar ** ppResult, const gchar * pStr)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
85 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
86 /* Check the string pointers */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
87 if (!ppResult || !pStr)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
88 return -1;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
89
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
90 /* Allocate memory for destination */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
91 if (*ppResult)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
92 g_free(*ppResult);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
93 *ppResult = (gchar *) g_malloc(strlen(pStr) + 1);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
94 if (!*ppResult)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
95 return -2;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
96
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
97 /* Copy to the destination */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
98 strcpy(*ppResult, pStr);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
99
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
100 return 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
101 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
102
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
103
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
104 /* Concatenates a given string into string pointed by *ppResult.
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
105 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
106 gint xs_pstrcat(gchar ** ppResult, const gchar * pStr)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
107 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
108 /* Check the string pointers */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
109 if (!ppResult || !pStr)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
110 return -1;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
111
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
112 if (*ppResult != NULL) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
113 *ppResult = (gchar *) g_realloc(*ppResult, strlen(*ppResult) + strlen(pStr) + 1);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
114 if (*ppResult == NULL)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
115 return -1;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
116 strcat(*ppResult, pStr);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
117 } else {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
118 *ppResult = (gchar *) g_malloc(strlen(pStr) + 1);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
119 if (*ppResult == NULL)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
120 return -1;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
121 strcpy(*ppResult, pStr);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
122 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
123
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
124 return 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
125 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
126
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
127
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
128 /* Concatenate a given string up to given dest size or \n.
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
129 * If size max is reached, change the end to "..."
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
130 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
131 void xs_pnstrcat(gchar * pDest, size_t iSize, gchar * pStr)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
132 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
133 size_t i, n;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
134 gchar *s, *d;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
135
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
136 d = pDest;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
137 i = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
138 while (*d && (i < iSize)) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
139 i++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
140 d++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
141 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
142
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
143 s = pStr;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
144 while (*s && (*s != '\n') && (i < iSize)) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
145 *d = *s;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
146 d++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
147 s++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
148 i++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
149 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
150
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
151 *d = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
152
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
153 if (i >= iSize) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
154 i--;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
155 d--;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
156 n = 3;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
157 while ((i > 0) && (n > 0)) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
158 *d = '.';
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
159 d--;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
160 i--;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
161 n--;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
162 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
163 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
164 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
165
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
166
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
167 /* Locate character in string
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
168 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
169 gchar *xs_strrchr(gchar * pcStr, gchar ch)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
170 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
171 gchar *lastPos = NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
172
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
173 while (*pcStr) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
174 if (*pcStr == ch)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
175 lastPos = pcStr;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
176 pcStr++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
177 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
178
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
179 return lastPos;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
180 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
181
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
182
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
183 void xs_findnext(gchar * pcStr, guint * piPos)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
184 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
185 while (pcStr[*piPos] && isspace(pcStr[*piPos]))
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
186 (*piPos)++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
187 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
188
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
189
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
190 void xs_findeol(gchar * pcStr, guint * piPos)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
191 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
192 while (pcStr[*piPos] && (pcStr[*piPos] != '\n') && (pcStr[*piPos] != '\r'))
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
193 (*piPos)++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
194 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
195
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
196
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
197 void xs_findnum(gchar * pcStr, guint * piPos)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
198 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
199 while (pcStr[*piPos] && isdigit(pcStr[*piPos]))
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
200 (*piPos)++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
201 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
202
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
203
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
204 #ifndef HAVE_MEMSET
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
205 void *xs_memset(void *p, int c, size_t n)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
206 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
207 gchar *dp;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
208
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
209 dp = (gchar *) p;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
210 while (n--) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
211 *dp = (gchar) c;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
212 n--;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
213 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
214
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
215 return p;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
216 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
217 #endif