comparison libnnchat.c @ 78:745f670068dc

Add functions to simplify code.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 18 Dec 2008 14:34:44 +0200
parents fe5fc76c0806
children e36df57c5b0f
comparison
equal deleted inserted replaced
77:e8c9d7d13866 78:745f670068dc
95 #define PUSHSTR(x) bufPushStr(&result, &resSize, &resPos, x) 95 #define PUSHSTR(x) bufPushStr(&result, &resSize, &resPos, x)
96 BOOL bufPushStr(char **buf, size_t *size, size_t *pos, char *str) 96 BOOL bufPushStr(char **buf, size_t *size, size_t *pos, char *str)
97 { 97 {
98 size_t tmpLen; 98 size_t tmpLen;
99 99
100 if (!str) return FALSE; 100 if (str == NULL) return FALSE;
101 tmpLen = strlen(str); 101 tmpLen = strlen(str);
102 102
103 if ((*pos + tmpLen) >= *size && !bufRealloc(buf, size, tmpLen + SET_ALLOC_SIZE)) 103 if ((*pos + tmpLen) >= *size && !bufRealloc(buf, size, tmpLen + SET_ALLOC_SIZE))
104 return FALSE; 104 return FALSE;
105 105
113 { 113 {
114 const char *s = str; 114 const char *s = str;
115 char *result; 115 char *result;
116 size_t resSize, resPos = 0; 116 size_t resSize, resPos = 0;
117 117
118 if (!str) return NULL; 118 if (str == NULL) return NULL;
119 119
120 resSize = strlen(str) + SET_ALLOC_SIZE; 120 resSize = strlen(str) + SET_ALLOC_SIZE;
121 if ((result = th_malloc(resSize)) == NULL) 121 if ((result = th_malloc(resSize)) == NULL)
122 return NULL; 122 return NULL;
123 123
168 const char *s = str; 168 const char *s = str;
169 char *result; 169 char *result;
170 size_t resSize, resPos = 0; 170 size_t resSize, resPos = 0;
171 int c; 171 int c;
172 172
173 if (!str) return NULL; 173 if (str == NULL) return NULL;
174 174
175 resSize = strlen(str) + SET_ALLOC_SIZE; 175 resSize = strlen(str) + SET_ALLOC_SIZE;
176 if ((result = th_malloc(resSize)) == NULL) 176 if ((result = th_malloc(resSize)) == NULL)
177 return NULL; 177 return NULL;
178 178
229 { 229 {
230 const char *s = str; 230 const char *s = str;
231 char *result; 231 char *result;
232 size_t resSize, resPos = 0; 232 size_t resSize, resPos = 0;
233 233
234 if (!str) return NULL; 234 if (str == NULL) return NULL;
235 235
236 resSize = strlen(str) + SET_ALLOC_SIZE; 236 resSize = strlen(str) + SET_ALLOC_SIZE;
237 if ((result = th_malloc(resSize)) == NULL) 237 if ((result = th_malloc(resSize)) == NULL)
238 return NULL; 238 return NULL;
239 239
254 { 254 {
255 const char *s = str; 255 const char *s = str;
256 char *result; 256 char *result;
257 size_t resSize, resPos = 0; 257 size_t resSize, resPos = 0;
258 258
259 if (!str) return NULL; 259 if (str == NULL) return NULL;
260 260
261 resSize = strlen(str) + SET_ALLOC_SIZE; 261 resSize = strlen(str) + SET_ALLOC_SIZE;
262 if ((result = th_malloc(resSize)) == NULL) 262 if ((result = th_malloc(resSize)) == NULL)
263 return NULL; 263 return NULL;
264 264
285 { 285 {
286 const char *s = str; 286 const char *s = str;
287 char *result; 287 char *result;
288 size_t resSize, resPos = 0; 288 size_t resSize, resPos = 0;
289 289
290 if (!str) return NULL; 290 if (str == NULL) return NULL;
291 291
292 resSize = strlen(str); 292 resSize = strlen(str);
293 if ((result = th_malloc(resSize)) == NULL) 293 if ((result = th_malloc(resSize)) == NULL)
294 return NULL; 294 return NULL;
295 295
315 315
316 return result; 316 return result;
317 } 317 }
318 318
319 319
320 char *doubleDecodeStr(const char *str)
321 {
322 char *res, *tmp;
323
324 if ((tmp = decodeStr1(str)) == NULL)
325 return NULL;
326
327 res = decodeStr2(tmp);
328 th_free(tmp);
329
330 return res;
331 }
332
333
334 char *doubleEncodeStr(const char *str)
335 {
336 char *res, *tmp;
337
338 if ((tmp = encodeStr2(str)) == NULL)
339 return NULL;
340
341 res = encodeStr1(tmp);
342 th_free(tmp);
343
344 return res;
345 }
346
347
320 BOOL sendUserMsg(const int sock, const char *user, const char *fmt, ...) 348 BOOL sendUserMsg(const int sock, const char *user, const char *fmt, ...)
321 { 349 {
322 char tmpBuf[SET_BUFSIZE], tmpBuf2[SET_BUFSIZE + 256]; 350 char tmpBuf[SET_BUFSIZE], tmpBuf2[SET_BUFSIZE + 256];
323 int n; 351 int n;
324 va_list ap; 352 va_list ap;