Annotation of parser3/src/lib/sdbm/pa_strings.C, revision 1.3
1.1 moko 1: /** @file
2: Parser: implementation of apr functions.
3:
1.3 ! moko 4: Copyright (c) 2000-2012 Art. Lebedev Studio (http://www.artlebedev.com)
1.1 moko 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
6: */
7:
8: #include "pa_strings.h"
9: #include "pa_memory.h"
10:
1.3 ! moko 11: volatile const char * IDENT_PA_STRINGS_C="$Id: 2010-11-28 14:39:33 $";
! 12:
1.1 moko 13: /** this is used to cache lengths in pa_pstrcat */
14: #define MAX_SAVED_LENGTHS 6
15:
16: char *pa_pstrcat(pa_pool_t *p, ...)
17: {
18: char *cp, *argp, *res;
19: pa_size_t saved_lengths[MAX_SAVED_LENGTHS];
20: int nargs = 0;
21:
22: /* Pass one --- find length of required string */
23:
24: pa_size_t len = 0;
25: va_list adummy;
26:
27: va_start(adummy, p);
28:
29: while ((cp = va_arg(adummy, char *)) != NULL) {
30: pa_size_t cplen = strlen(cp);
31: if (nargs < MAX_SAVED_LENGTHS) {
32: saved_lengths[nargs++] = cplen;
33: }
34: len += cplen;
35: }
36:
37: va_end(adummy);
38:
39: /* Allocate the required string */
40:
41: res = (char *) pa_malloc_atomic(len + 1);
42: cp = res;
43:
44: /* Pass two --- copy the argument strings into the result space */
45:
46: va_start(adummy, p);
47:
48: nargs = 0;
49: while ((argp = va_arg(adummy, char *)) != NULL) {
50: if (nargs < MAX_SAVED_LENGTHS) {
51: len = saved_lengths[nargs++];
52: }
53: else {
54: len = strlen(argp);
55: }
56:
57: memcpy(cp, argp, len);
58: cp += len;
59: }
60:
61: va_end(adummy);
62:
63: /* Return the result string */
64:
65: *cp = '\0';
66:
67: return res;
68: }
69:
1.2 moko 70: void* pa_sdbm_malloc(unsigned int size){
71: return pa_malloc(size);
72: }
E-mail: