IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11711 for trunk/psLib


Ignore:
Timestamp:
Feb 8, 2007, 12:27:30 PM (19 years ago)
Author:
jhoblitt
Message:

change selected psString*() functions into wrappers so file/lineo/func can be recorded in the memBlock
whitespace cleanup

Location:
trunk/psLib/src/sys
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psString.c

    r11686 r11711  
    1313 *  @author David Robbins, MHPCC
    1414 *
    15  *  @version $Revision: 1.51 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2007-02-07 23:52:54 $
     15 *  @version $Revision: 1.52 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2007-02-08 22:27:30 $
    1717 *
    1818 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3333#include "psMemory.h"
    3434
    35 
    3635static void stringFree(psString string)
    3736{
    38     // There is non dynamic allocated item
    39 }
    40 
    41 psString psStringAlloc(long nChar)
     37    // this function is only nessicary so psMemCheckString has a function
     38    // pointer address to test against
     39}
     40
     41
     42psString p_psStringAlloc(const char *file,
     43                         unsigned int lineno,
     44                         const char *func,
     45                         long nChar)
    4246{
    4347    if (nChar < 1) {
    4448        return NULL;
    4549    }
    46     psString string = psAlloc(nChar + 1);
     50
     51    psString string = p_psAlloc(file, lineno, func, nChar + 1);
    4752    psMemSetDeallocator(string, (psFreeFunc)stringFree);
     53
    4854    return string;
    4955}
    5056
     57
    5158bool psMemCheckString(psPtr ptr)
    5259{
    5360    PS_ASSERT_PTR(ptr, false);
    54     return ( psMemGetDeallocator(ptr) == (psFreeFunc)stringFree );
    55 }
    56 
    57 psString psStringCopy(const char *string)
     61    return (psMemGetDeallocator(ptr) == (psFreeFunc)stringFree);
     62}
     63
     64
     65psString p_psStringCopy(const char *file,
     66                        unsigned int lineno,
     67                        const char *func,
     68                        const char *string)
    5869{
    5970    // Pass through NULL values!
     
    6172        return NULL;
    6273    }
    63     psString output = psStringAlloc(strlen(string) + 1); // Output string
     74
     75    // Output string
     76    psString output = p_psStringAlloc(file, lineno, func, strlen(string) + 1);
     77
    6478    // Copy input string to memory just allocated
    6579    return strcpy(output, string);
    6680}
    6781
    68 psString psStringNCopy(const char *string,
    69                        unsigned int nChar)
     82
     83psString p_psStringNCopy(const char *file,
     84                         unsigned int lineno,
     85                         const char *func,
     86                         const char *string,
     87                         unsigned int nChar)
    7088{
    7189    PS_ASSERT_PTR_NON_NULL(string, NULL);
     
    86104
    87105    // Copy input string to memory allocated up to nChar characters
    88     psString output = psStringAlloc((size_t) nChar + 1);
     106    psString output = p_psStringAlloc(file, lineno, func, (size_t) nChar + 1);
    89107    output = strncpy(output, string, (size_t) nChar);
    90108
     
    96114}
    97115
    98 ssize_t psStringAppend(char **dest,
    99                        const char *format,
    100                        ...)
     116
     117ssize_t p_psStringAppend(const char *file,
     118                         unsigned int lineno,
     119                         const char *func,
     120                         char **dest,
     121                         const char *format,
     122                         ...)
    101123{
    102124    PS_ASSERT_PTR_NON_NULL(dest, 0);
     
    105127    va_list ap;
    106128    va_start(ap, format);
    107     ssize_t length = psStringAppendV(dest, format, ap);
     129    ssize_t length = p_psStringAppendV(file, lineno, func, dest, format, ap);
    108130    va_end(ap);
    109131
     
    111133}
    112134
    113 ssize_t psStringAppendV(char **dest,
    114                         const char *format,
    115                         va_list ap)
     135ssize_t p_psStringAppendV(const char *file,
     136                          unsigned int lineno,
     137                          const char *func,
     138                          char **dest,
     139                          const char *format,
     140                          va_list ap)
    116141{
    117142    PS_ASSERT_PTR_NON_NULL(dest, 0);
     
    144169    // realloc string to string + tail + \0
    145170    if (*dest) {
    146         *dest = psRealloc(*dest, oldLength + tailLength + 1);
     171        *dest = p_psRealloc(file, lineno, func, *dest, oldLength + tailLength + 1);
    147172    } else {
    148         *dest = psStringAlloc(oldLength + tailLength + 1);
     173        *dest = p_psStringAlloc(file, lineno, func, oldLength + tailLength + 1);
    149174    }
    150175
     
    160185}
    161186
    162 ssize_t psStringPrepend(char **dest,
    163                         const char *format,
    164                         ...)
     187
     188ssize_t p_psStringPrepend(const char *file,
     189                          unsigned int lineno,
     190                          const char *func,
     191                          char **dest,
     192                          const char *format,
     193                          ...)
    165194{
    166195    PS_ASSERT_PTR_NON_NULL(dest, 0);
     
    169198    va_list ap;
    170199    va_start(ap, format);
    171     ssize_t length = psStringPrependV(dest, format, ap);
     200    ssize_t length = p_psStringPrependV(file, lineno, func, dest, format, ap);
    172201    va_end(ap);
    173202
     
    175204}
    176205
    177 ssize_t psStringPrependV(char **dest,
    178                          const char *format,
    179                          va_list ap)
     206
     207ssize_t p_psStringPrependV(const char *file,
     208                           unsigned int lineno,
     209                           const char *func,
     210                           char **dest,
     211                           const char *format,
     212                           va_list ap)
    180213{
    181214    PS_ASSERT_PTR_NON_NULL(dest, 0);
     
    188221    if (!*dest) {
    189222        // makes the string backup and concatination pointless
    190         *dest = psStringCopy("");
     223        *dest = p_psStringCopy(file, lineno, func, "");
    191224        length = 0;
    192225    } else {
     
    210243
    211244    // backup original string
    212     oldDest = psStringCopy(*dest);
     245    oldDest = p_psStringCopy(file, lineno, func, *dest);
    213246
    214247    // new string length (sans \0)
     
    216249
    217250    // realloc string to head + string + \0
    218     *dest = psRealloc(*dest, length + 1);
     251    *dest = p_psRealloc(file, lineno, func, *dest, length + 1);
    219252
    220253    // copy the new head to the beginning of string
     
    234267}
    235268
     269
    236270// split the string by the given splitters
    237271// NULL input string returns empty (not NULL) list
     
    276310    return values;
    277311}
     312
    278313
    279314// given the input string, search for all copies of the key, and replace with the replacement value
     
    343378}
    344379
     380
    345381psArray *psStringSplitArray(const char *string, const char *splitters, bool multi)
    346382{
     
    352388}
    353389
     390
    354391#ifndef whitespace
    355392#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
     
    376413    return i;
    377414}
     415
     416
    378417/*
    379418 * Used by PS_FILE_LINE
  • trunk/psLib/src/sys/psString.h

    r11694 r11711  
    1111 * @author Joshua Hoblitt, University of Hawaii
    1212 *
    13  * @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
    14  * @date $Date: 2007-02-08 01:59:28 $
     13 * @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
     14 * @date $Date: 2007-02-08 22:27:30 $
    1515 *
    1616 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3939#define PS_FILE_LINE p_psFileLine(__FILE__,__LINE__)
    4040
     41
    4142/** Allocates a new psString.
    4243 *
    4344 *  @return psString:       Newly allocated string of length n.
    4445 */
     46#ifdef DOXYGEN
    4547psString psStringAlloc(
    4648    long nChar                         ///< Size of psString to allocate.
    4749);
     50#else // ifdef DOXYGEN
     51psString p_psStringAlloc(
     52    const char *file,                   ///< File of caller
     53    unsigned int lineno,                ///< Line number of caller
     54    const char *func,                   ///< Function name of caller
     55    long nChar                         ///< Size of psString to allocate.
     56);
     57#define psStringAlloc(nChar) \
     58      p_psStringAlloc(__FILE__, __LINE__, __func__, nChar)
     59#endif // ifdef DOXYGEN
    4860
    4961
     
    6880 *  @return psString:      Copy of input string
    6981 */
     82#ifdef DOXYGEN
    7083psString psStringCopy(
    71     const char *string                 ///< Input string of characters to copy
    72 );
     84    const char *string                  ///< Input string of characters to copy
     85);
     86#else // ifdef DOXYGEN
     87psString p_psStringCopy(
     88    const char *file,                   ///< File of caller
     89    unsigned int lineno,                ///< Line number of caller
     90    const char *func,                   ///< Function name of caller
     91    const char *string                  ///< Input string of characters to copy
     92);
     93#define psStringCopy(string) \
     94      p_psStringCopy(__FILE__, __LINE__, __func__, string)
     95#endif // ifdef DOXYGEN
    7396
    7497
     
    85108 *  @return  psString:   Copy of input string
    86109 */
     110#ifdef DOXYGEN
    87111psString psStringNCopy(
    88112    const char *string,                ///< Input string of characters to copy
    89113    unsigned int nChar                 ///< Number of bytes to allocate for string copy
    90114);
     115#else // ifdef DOXYGEN
     116psString p_psStringNCopy(
     117    const char *file,                   ///< File of caller
     118    unsigned int lineno,                ///< Line number of caller
     119    const char *func,                   ///< Function name of caller
     120    const char *string,                 ///< Input string of characters to copy
     121    unsigned int nChar                  ///< Number of bytes to allocate for string copy
     122);
     123#define psStringNCopy(string, nChar) \
     124      p_psStringNCopy(__FILE__, __LINE__, __func__, string, nChar)
     125#endif // ifdef DOXYGEN
    91126
    92127
     
    98133 * @return ssize_t:     The length of the new string (excluding '\0')
    99134 */
     135#ifdef DOXYGEN
    100136ssize_t psStringAppend(
     137    char **dest,                        ///< existing string
     138    const char *format,                 ///< format to append
     139    ...                                 ///< format arguments
     140);
     141#else // ifdef DOXYGEN
     142ssize_t p_psStringAppend(
     143    const char *file,                   ///< File of caller
     144    unsigned int lineno,                ///< Line number of caller
     145    const char *func,                   ///< Function name of caller
    101146    char **dest,                        ///< existing string
    102147    const char *format,                 ///< format to append
    103148    ...                                 ///< format arguments
    104149#ifdef __GNUC__
    105 ) __attribute__((format(printf, 2, 3)));
    106 #else // __GNUC__
    107 );
    108 #endif // __GNUC__
     150) __attribute__((format(printf, 5, 6)));
     151#else // ifdef __GNUC__
     152);
     153#endif // ifdef __GNUC__
     154#define psStringAppend(dest, ...) \
     155      p_psStringAppend(__FILE__, __LINE__, __func__, dest, __VA_ARGS__)
     156#endif // ifdef DOXYGEN
    109157
    110158
     
    116164 * @return ssize_t:     The length of the new string (excluding '\0')
    117165 */
     166#ifdef DOXYGEN
    118167ssize_t psStringAppendV(
    119168    char **dest,                        ///< existing string
     
    121170    va_list ap                          ///< va_list of format arguments
    122171);
     172#else // ifdef DOXYGEN
     173ssize_t p_psStringAppendV(
     174    const char *file,                   ///< File of caller
     175    unsigned int lineno,                ///< Line number of caller
     176    const char *func,                   ///< Function name of caller
     177    char **dest,                        ///< existing string
     178    const char *format,                 ///< format to append
     179    va_list ap                          ///< va_list of format arguments
     180);
     181#define psStringAppendV(dest, format, ap) \
     182      p_psStringAppendV(__FILE__, __LINE__, __func__, dest, format, ap)
     183#endif // ifdef DOXYGEN
    123184
    124185
     
    130191 * @return ssize_t:     The length of the new string (excluding '\0')
    131192 */
     193#ifdef DOXYGEN
    132194ssize_t psStringPrepend(
     195    char **dest,                        ///< existing string
     196    const char *format,                 ///< format to append
     197    ...                                 ///< format arguments
     198);
     199#else // ifdef DOXYGEN
     200ssize_t p_psStringPrepend(
     201    const char *file,                   ///< File of caller
     202    unsigned int lineno,                ///< Line number of caller
     203    const char *func,                   ///< Function name of caller
    133204    char **dest,                        ///< existing string
    134205    const char *format,                 ///< format to append
    135206    ...                                 ///< format arguments
    136207#ifdef __GNUC__
    137 ) __attribute__((format(printf, 2, 3)));
    138 # else // __GNUC__
    139 );
    140 #endif // __GNUC__
     208) __attribute__((format(printf, 5, 6)));
     209# else // ifdef __GNUC__
     210);
     211#endif // ifdef __GNUC__
     212#define psStringPrepend(dest, ...) \
     213      p_psStringPrepend(__FILE__, __LINE__, __func__, dest, __VA_ARGS__)
     214#endif // ifdef DOXYGEN
    141215
    142216
     
    148222 * @return ssize_t:     The length of the new string (excluding '\0')
    149223 */
     224#ifdef DOXYGEN
    150225ssize_t psStringPrependV(
    151226    char **dest,                        ///< existing string
     
    153228    va_list ap                          ///< va_list of format arguments
    154229);
     230#else // ifdef DOXYGEN
     231ssize_t p_psStringPrependV(
     232    const char *file,                   ///< File of caller
     233    unsigned int lineno,                ///< Line number of caller
     234    const char *func,                   ///< Function name of caller
     235    char **dest,                        ///< existing string
     236    const char *format,                 ///< format to append
     237    va_list ap                          ///< va_list of format arguments
     238);
     239#define psStringPrependV(dest, format, ap) \
     240      p_psStringPrependV(__FILE__, __LINE__, __func__, dest, format, ap)
     241#endif // ifdef DOXYGEN
    155242
    156243
Note: See TracChangeset for help on using the changeset viewer.