Mercurial > hg > nnchat
comparison util.c @ 431:a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Also re-added util.h, that was missing. Oops.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 24 May 2012 20:57:06 +0300 |
parents | d015ecbd231d |
children | 3396acd40147 |
comparison
equal
deleted
inserted
replaced
430:aaadf6cea6be | 431:a9b20b31cae1 |
---|---|
107 else if ((c = nn_get_hexdigit(*s, 4)) >= 0) | 107 else if ((c = nn_get_hexdigit(*s, 4)) >= 0) |
108 { | 108 { |
109 int i = nn_get_hexdigit(*(++s), 0); | 109 int i = nn_get_hexdigit(*(++s), 0); |
110 if (i >= 0) | 110 if (i >= 0) |
111 { | 111 { |
112 PUSHCHAR(c | i); | 112 PUSHCHAR((char) (c | i)); |
113 } | 113 } |
114 else | 114 else |
115 { | 115 { |
116 PUSHCHAR('§'); | 116 PUSHCHAR('§'); |
117 PUSHCHAR(*s); | 117 PUSHCHAR(*s); |
232 int i; | 232 int i; |
233 BOOL found = FALSE; | 233 BOOL found = FALSE; |
234 for (i = 0; i < numHTMLEntities; i++) | 234 for (i = 0; i < numHTMLEntities; i++) |
235 { | 235 { |
236 const html_entity_t *ent = &HTMLEntities[i]; | 236 const html_entity_t *ent = &HTMLEntities[i]; |
237 int len = strlen(ent->ent); | 237 size_t len = strlen(ent->ent); |
238 if (!strncmp(s, ent->ent, len)) | 238 if (!strncmp(s, ent->ent, len)) |
239 { | 239 { |
240 PUSHCHAR(ent->c); | 240 PUSHCHAR(ent->c); |
241 s += len; | 241 s += len; |
242 found = TRUE; | 242 found = TRUE; |
280 | 280 |
281 return res; | 281 return res; |
282 } | 282 } |
283 | 283 |
284 | 284 |
285 int nn_editbuf_write(nn_editbuf_t *buf, ssize_t pos, int ch) | 285 int nn_editbuf_write(nn_editbuf_t *buf, size_t pos, char ch) |
286 { | 286 { |
287 if (buf->len+1 >= buf->size) return -3; | 287 if (buf->len+1 >= buf->size) return -3; |
288 | 288 |
289 if (pos < 0) | 289 if (pos >= buf->len) |
290 return -1; | |
291 else if (pos >= buf->len) | |
292 buf->data[buf->len++] = ch; | 290 buf->data[buf->len++] = ch; |
293 else | 291 else |
294 buf->data[pos] = ch; | 292 buf->data[pos] = ch; |
295 | 293 |
296 return 0; | 294 return 0; |
297 } | 295 } |
298 | 296 |
299 | 297 |
300 int nn_editbuf_insert(nn_editbuf_t *buf, ssize_t pos, int ch) | 298 int nn_editbuf_insert(nn_editbuf_t *buf, size_t pos, char ch) |
301 { | 299 { |
302 if (buf->len+1 >= buf->size) return -3; | 300 if (buf->len+1 >= buf->size) return -3; |
303 | 301 |
304 if (pos < 0) | 302 if (pos >= buf->len) |
305 return -1; | |
306 else if (pos >= buf->len) | |
307 { | 303 { |
308 buf->data[buf->len] = ch; | 304 buf->data[buf->len] = ch; |
309 } | 305 } |
310 else | 306 else |
311 { | 307 { |
315 buf->len++; | 311 buf->len++; |
316 return 0; | 312 return 0; |
317 } | 313 } |
318 | 314 |
319 | 315 |
320 int nn_editbuf_delete(nn_editbuf_t *buf, ssize_t pos) | 316 int nn_editbuf_delete(nn_editbuf_t *buf, size_t pos) |
321 { | 317 { |
322 if (pos < 0) | 318 if (pos < buf->len) |
323 return -1; | |
324 else if (pos < buf->len) | |
325 { | 319 { |
326 memmove(&(buf->data[pos]), &(buf->data[pos+1]), buf->len - pos); | 320 memmove(&(buf->data[pos]), &(buf->data[pos+1]), buf->len - pos); |
327 buf->len--; | 321 buf->len--; |
328 return 0; | 322 return 0; |
329 } | 323 } |
337 buf->len = 0; | 331 buf->len = 0; |
338 buf->pos = 0; | 332 buf->pos = 0; |
339 } | 333 } |
340 | 334 |
341 | 335 |
342 nn_editbuf_t * nn_editbuf_new(ssize_t n) | 336 nn_editbuf_t * nn_editbuf_new(size_t n) |
343 { | 337 { |
344 nn_editbuf_t *res = th_calloc(1, sizeof(nn_editbuf_t)); | 338 nn_editbuf_t *res = th_calloc(1, sizeof(nn_editbuf_t)); |
345 | 339 |
346 res->data = (char *) th_malloc(n); | 340 res->data = (char *) th_malloc(n); |
347 res->size = n; | 341 res->size = n; |
376 | 370 |
377 return res; | 371 return res; |
378 } | 372 } |
379 | 373 |
380 | 374 |
381 char * nn_editbuf_get_string(nn_editbuf_t *buf, ssize_t start, ssize_t end) | 375 char * nn_editbuf_get_string(nn_editbuf_t *buf, size_t start, size_t end) |
382 { | 376 { |
383 char *str; | 377 char *str; |
384 ssize_t siz; | 378 size_t siz; |
385 | 379 |
386 if (buf == NULL) | 380 if (buf == NULL) |
387 return NULL; | 381 return NULL; |
388 | 382 |
389 if (start < 0 || end > buf->len || start >= buf->len) | 383 if (end > buf->len || start >= buf->len) |
390 return NULL; | 384 return NULL; |
391 | 385 |
392 if (end < 0) | 386 if (start <= end) |
393 { | |
394 siz = buf->len - start + 1; | |
395 } | |
396 else if (start <= end) | |
397 { | |
398 siz = end - start + 1; | 387 siz = end - start + 1; |
399 } | |
400 else | 388 else |
401 return NULL; | 389 return NULL; |
402 | 390 |
403 if ((str = th_malloc(siz + 1)) == NULL) | 391 if ((str = th_malloc(siz + 1)) == NULL) |
404 return NULL; | 392 return NULL; |
408 | 396 |
409 return str; | 397 return str; |
410 } | 398 } |
411 | 399 |
412 | 400 |
413 void nn_editbuf_setpos(nn_editbuf_t *buf, ssize_t pos) | 401 void nn_editbuf_setpos(nn_editbuf_t *buf, size_t pos) |
414 { | 402 { |
415 assert(buf != NULL); | 403 assert(buf != NULL); |
416 | 404 |
417 if (pos < 0) | 405 if (pos >= buf->len) |
418 buf->pos = 0; | |
419 else if (pos >= buf->len) | |
420 buf->pos = buf->len; | 406 buf->pos = buf->len; |
421 else | 407 else |
422 buf->pos = pos; | 408 buf->pos = pos; |
423 } | 409 } |
424 | 410 |
436 c++; n++; | 422 c++; n++; |
437 } | 423 } |
438 | 424 |
439 return (hash & 0xff); | 425 return (hash & 0xff); |
440 */ | 426 */ |
441 return tolower(name[0]); | 427 return (uint8_t) tolower(name[0]); |
442 } | 428 } |
443 | 429 |
444 | 430 |
445 static void nn_user_insert(nn_user_t **list, nn_user_t *node) | 431 static void nn_user_insert(nn_user_t **list, nn_user_t *node) |
446 { | 432 { |