Annotation of parser3/src/lib/sdbm/pa_strings.C, revision 1.1

1.1     ! moko        1: /** @file
        !             2:        Parser: implementation of apr functions.
        !             3: 
        !             4:        Copyright(c) 2003 ArtLebedev Group (http://www.artlebedev.com)
        !             5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
        !             6: */
        !             7: 
        !             8: static const char * const IDENT="$Date: 2008-01-25 18:57:52 $";
        !             9: 
        !            10: #include "pa_strings.h"
        !            11: #include "pa_memory.h"
        !            12: 
        !            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: 

E-mail: