comparison src/xs_support.c @ 663:180d7a0250d8

More cosmetic variable name changes.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 03 Apr 2008 00:26:53 +0300
parents b0743dc9165d
children 229fa2d043b9
comparison
equal deleted inserted replaced
662:b37cb1a8a50a 663:180d7a0250d8
87 } 87 }
88 88
89 89
90 /* Copy a string 90 /* Copy a string
91 */ 91 */
92 gchar *xs_strncpy(gchar *pDest, const gchar *pSource, size_t n) 92 gchar *xs_strncpy(gchar *dest, const gchar *src, size_t n)
93 { 93 {
94 const gchar *s; 94 const gchar *s;
95 gchar *d; 95 gchar *d;
96 size_t i; 96 size_t i;
97 97
98 /* Check the string pointers */ 98 /* Check the string pointers */
99 if (!pSource || !pDest) 99 if (!src || !dest)
100 return pDest; 100 return dest;
101 101
102 /* Copy to the destination */ 102 /* Copy to the destination */
103 i = n; 103 i = n;
104 s = pSource; 104 s = src;
105 d = pDest; 105 d = dest;
106 while (*s && (i > 0)) { 106 while (*s && (i > 0)) {
107 *(d++) = *(s++); 107 *(d++) = *(s++);
108 i--; 108 i--;
109 } 109 }
110 110
113 *(d++) = 0; 113 *(d++) = 0;
114 i--; 114 i--;
115 } 115 }
116 116
117 /* Ensure that last is always zero */ 117 /* Ensure that last is always zero */
118 pDest[n - 1] = 0; 118 dest[n - 1] = 0;
119 119
120 return pDest; 120 return dest;
121 } 121 }
122 122
123 123
124 /* Copy a given string over in *ppResult. 124 /* Copy a given string over in *result.
125 */ 125 */
126 gint xs_pstrcpy(gchar **ppResult, const gchar *pStr) 126 gint xs_pstrcpy(gchar **result, const gchar *str)
127 { 127 {
128 /* Check the string pointers */ 128 /* Check the string pointers */
129 if (!ppResult || !pStr) 129 if (!result || !str)
130 return -1; 130 return -1;
131 131
132 /* Allocate memory for destination */ 132 /* Allocate memory for destination */
133 if (*ppResult) 133 if (*result)
134 g_free(*ppResult); 134 g_free(*result);
135 *ppResult = (gchar *) g_malloc(strlen(pStr) + 1); 135 *result = (gchar *) g_malloc(strlen(str) + 1);
136 if (!*ppResult) 136 if (!*result)
137 return -2; 137 return -2;
138 138
139 /* Copy to the destination */ 139 /* Copy to the destination */
140 strcpy(*ppResult, pStr); 140 strcpy(*result, str);
141 141
142 return 0; 142 return 0;
143 } 143 }
144 144
145 145
146 /* Concatenates a given string into string pointed by *ppResult. 146 /* Concatenates a given string into string pointed by *result.
147 */ 147 */
148 gint xs_pstrcat(gchar **ppResult, const gchar *pStr) 148 gint xs_pstrcat(gchar **result, const gchar *str)
149 { 149 {
150 /* Check the string pointers */ 150 /* Check the string pointers */
151 if (!ppResult || !pStr) 151 if (!result || !str)
152 return -1; 152 return -1;
153 153
154 if (*ppResult != NULL) { 154 if (*result != NULL) {
155 *ppResult = (gchar *) g_realloc(*ppResult, strlen(*ppResult) + strlen(pStr) + 1); 155 *result = (gchar *) g_realloc(*result, strlen(*result) + strlen(str) + 1);
156 if (*ppResult == NULL) 156 if (*result == NULL)
157 return -1; 157 return -1;
158 strcat(*ppResult, pStr); 158 strcat(*result, str);
159 } else { 159 } else {
160 *ppResult = (gchar *) g_malloc(strlen(pStr) + 1); 160 *result = (gchar *) g_malloc(strlen(str) + 1);
161 if (*ppResult == NULL) 161 if (*result == NULL)
162 return -1; 162 return -1;
163 strcpy(*ppResult, pStr); 163 strcpy(*result, str);
164 } 164 }
165 165
166 return 0; 166 return 0;
167 } 167 }
168 168
169 169
170 /* Concatenate a given string up to given dest size or \n. 170 /* Concatenate a given string up to given dest size or \n.
171 * If size max is reached, change the end to "..." 171 * If size max is reached, change the end to "..."
172 */ 172 */
173 void xs_pnstrcat(gchar *pDest, size_t iSize, const gchar *pStr) 173 void xs_pnstrcat(gchar *dest, size_t iSize, const gchar *str)
174 { 174 {
175 size_t i, n; 175 size_t i, n;
176 const gchar *s; 176 const gchar *s;
177 gchar *d; 177 gchar *d;
178 178
179 d = pDest; 179 d = dest;
180 i = 0; 180 i = 0;
181 while (*d && (i < iSize)) { 181 while (*d && (i < iSize)) {
182 i++; 182 i++;
183 d++; 183 d++;
184 } 184 }
185 185
186 s = pStr; 186 s = str;
187 while (*s && (*s != '\n') && (i < iSize)) { 187 while (*s && (*s != '\n') && (i < iSize)) {
188 *d = *s; 188 *d = *s;
189 d++; 189 d++;
190 s++; 190 s++;
191 i++; 191 i++;
207 } 207 }
208 208
209 209
210 /* Locate character in string 210 /* Locate character in string
211 */ 211 */
212 gchar *xs_strrchr(gchar *pcStr, const gchar ch) 212 gchar *xs_strrchr(gchar *str, const gchar ch)
213 { 213 {
214 gchar *lastPos = NULL; 214 gchar *lastPos = NULL;
215 215
216 while (*pcStr) { 216 while (*str) {
217 if (*pcStr == ch) 217 if (*str == ch)
218 lastPos = pcStr; 218 lastPos = str;
219 pcStr++; 219 str++;
220 } 220 }
221 221
222 return lastPos; 222 return lastPos;
223 } 223 }
224 224
225 225
226 void xs_findnext(const gchar *pcStr, size_t *piPos) 226 void xs_findnext(const gchar *str, size_t *pos)
227 { 227 {
228 while (pcStr[*piPos] && isspace(pcStr[*piPos])) 228 while (str[*pos] && isspace(str[*pos]))
229 (*piPos)++; 229 (*pos)++;
230 } 230 }
231 231
232 232
233 void xs_findeol(const gchar *pcStr, size_t *piPos) 233 void xs_findeol(const gchar *str, size_t *pos)
234 { 234 {
235 while (pcStr[*piPos] && (pcStr[*piPos] != '\n') && (pcStr[*piPos] != '\r')) 235 while (str[*pos] && (str[*pos] != '\n') && (str[*pos] != '\r'))
236 (*piPos)++; 236 (*pos)++;
237 } 237 }
238 238
239 239
240 void xs_findnum(const gchar *pcStr, size_t *piPos) 240 void xs_findnum(const gchar *str, size_t *pos)
241 { 241 {
242 while (pcStr[*piPos] && isdigit(pcStr[*piPos])) 242 while (str[*pos] && isdigit(str[*pos]))
243 (*piPos)++; 243 (*pos)++;
244 } 244 }
245 245