IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3866


Ignore:
Timestamp:
May 6, 2005, 8:15:25 AM (21 years ago)
Author:
desonia
Message:

Bug #395 - consolidated psString functions introduced for psDB to psString.[ch]

Location:
trunk/psLib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/pslib.kdevses

    r3779 r3866  
    22<!DOCTYPE KDevPrjSession>
    33<KDevPrjSession>
    4  <DocsAndViews NumberOfDocuments="0" />
     4 <DocsAndViews NumberOfDocuments="6" >
     5  <Doc0 NumberOfViews="1" URL="file:///home/desonia/panstarrs/psLib/src/dataIO/psFits.c" >
     6   <View0 line="1202" Type="Source" />
     7  </Doc0>
     8  <Doc1 NumberOfViews="1" URL="file:///home/desonia/panstarrs/psLib/test/image/tst_psImage.c" >
     9   <View0 line="35" Type="Source" />
     10  </Doc1>
     11  <Doc2 NumberOfViews="1" URL="file:///home/desonia/panstarrs/psLib/configure.ac" >
     12   <View0 line="26" Type="Source" />
     13  </Doc2>
     14  <Doc3 NumberOfViews="1" URL="file:///home/desonia/panstarrs/psLib/src/sysUtils/psTrace.h" >
     15   <View0 line="87" Type="Source" />
     16  </Doc3>
     17  <Doc4 NumberOfViews="1" URL="file:///home/desonia/panstarrs/psLib/src/sysUtils/psTrace.c" >
     18   <View0 line="522" Type="Source" />
     19  </Doc4>
     20  <Doc5 NumberOfViews="1" URL="file:///home/desonia/panstarrs/psLib/src/collections/psMetadata.h" >
     21   <View0 line="65" Type="Source" />
     22  </Doc5>
     23 </DocsAndViews>
    524 <pluginList>
    625  <kdevdebugger>
  • trunk/psLib/src/dataIO/psDB.c

    r3849 r3866  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-05-05 21:11:39 $
     14 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-05-06 18:15:25 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    8383// string utility functions
    8484static char    *psDBIntToString(psU64 n);
    85 static ssize_t  psStringAppend(char **dest, const char *format, ...);
    86 static ssize_t  psStringPrepend(char **dest, const char *format, ...);
    8785
    8886
     
    15961594}
    15971595
    1598 static ssize_t psStringAppend(char **dest, const char *format, ...)
    1599 {
    1600     va_list         args;
    1601     size_t          length;             // complete string length (sans \0)
    1602     size_t          oldLength;          // original string length (sans \0)
    1603     ssize_t         tailLength;         // length of string to append
    1604 
    1605     if (!*dest) {
    1606         *dest = psStringCopy("");
    1607         oldLength = 0;
    1608     } else {
    1609         // size of existing string
    1610         oldLength = strlen(*dest);
    1611     }
    1612 
    1613     // find the size of the string to append
    1614     va_start(args, format);
    1615     // C99 guarentees vsnprintf() to work as expected with size = 0
    1616     tailLength = vsnprintf(*dest, 0, format, args);
    1617     va_end(args);
    1618 
    1619     // if the new tail is zero length, return the length of the old string.  if
    1620     // it's a format error, return the error code.
    1621     if (tailLength < 1) {
    1622         return tailLength == 0 ? oldLength : tailLength;
    1623     }
    1624 
    1625     // new string length (sans \0)
    1626     length = oldLength + tailLength;
    1627 
    1628     // realloc string to string + tail + \0
    1629     *dest = psRealloc(*dest, length + 1);
    1630 
    1631     // append tail + \0
    1632     va_start(args, format);
    1633     vsnprintf(*dest + oldLength, tailLength + 1, format, args);
    1634     va_end(args);
    1635 
    1636     return length;
    1637 }
    1638 
    1639 static ssize_t psStringPrepend(char **dest, const char *format, ...)
    1640 {
    1641     va_list         args;
    1642     size_t          length;             // complete string length (sans \0)
    1643     ssize_t         headLength;         // length of string to prepend
    1644     char            *oldDest;           // copy of original string
    1645 
    1646     if (!*dest) {
    1647         // makes the string backup and concatination pointless
    1648         *dest = psStringCopy("");
    1649         length = 0;
    1650     } else {
    1651         // size of existing string
    1652         length = strlen(*dest);
    1653     }
    1654 
    1655     // find the size of the string to prepend
    1656     va_start(args, format);
    1657     // C99 guarentees vsnprintf() to work as expected with size = 0
    1658     headLength = vsnprintf(*dest, 0, format, args);
    1659     va_end(args);
    1660 
    1661     // if the new head is zero length, return the length of the old string.  if
    1662     // it's a format error, return the error code.
    1663     if (headLength < 1) {
    1664         return headLength == 0 ? length : headLength;
    1665     }
    1666 
    1667     // backup original string
    1668     oldDest = psStringCopy(*dest);
    1669 
    1670     // new string length (sans \0)
    1671     length += headLength;
    1672 
    1673     // realloc string to head + string + \0
    1674     *dest = psRealloc(*dest, length + 1);
    1675 
    1676     // copy the new head to the beginning of string
    1677     va_start(args, format);
    1678     vsnprintf(*dest, length + 1, format, args);
    1679     va_end(args);
    1680 
    1681     // append the original string
    1682     strncat(*dest, oldDest, length + 1);
    1683 
    1684     psFree(oldDest);
    1685 
    1686     return length;
    1687 }
    1688 
    16891596#endif // BUILD_PSDB
  • trunk/psLib/src/db/psDB.c

    r3849 r3866  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-05-05 21:11:39 $
     14 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-05-06 18:15:25 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    8383// string utility functions
    8484static char    *psDBIntToString(psU64 n);
    85 static ssize_t  psStringAppend(char **dest, const char *format, ...);
    86 static ssize_t  psStringPrepend(char **dest, const char *format, ...);
    8785
    8886
     
    15961594}
    15971595
    1598 static ssize_t psStringAppend(char **dest, const char *format, ...)
    1599 {
    1600     va_list         args;
    1601     size_t          length;             // complete string length (sans \0)
    1602     size_t          oldLength;          // original string length (sans \0)
    1603     ssize_t         tailLength;         // length of string to append
    1604 
    1605     if (!*dest) {
    1606         *dest = psStringCopy("");
    1607         oldLength = 0;
    1608     } else {
    1609         // size of existing string
    1610         oldLength = strlen(*dest);
    1611     }
    1612 
    1613     // find the size of the string to append
    1614     va_start(args, format);
    1615     // C99 guarentees vsnprintf() to work as expected with size = 0
    1616     tailLength = vsnprintf(*dest, 0, format, args);
    1617     va_end(args);
    1618 
    1619     // if the new tail is zero length, return the length of the old string.  if
    1620     // it's a format error, return the error code.
    1621     if (tailLength < 1) {
    1622         return tailLength == 0 ? oldLength : tailLength;
    1623     }
    1624 
    1625     // new string length (sans \0)
    1626     length = oldLength + tailLength;
    1627 
    1628     // realloc string to string + tail + \0
    1629     *dest = psRealloc(*dest, length + 1);
    1630 
    1631     // append tail + \0
    1632     va_start(args, format);
    1633     vsnprintf(*dest + oldLength, tailLength + 1, format, args);
    1634     va_end(args);
    1635 
    1636     return length;
    1637 }
    1638 
    1639 static ssize_t psStringPrepend(char **dest, const char *format, ...)
    1640 {
    1641     va_list         args;
    1642     size_t          length;             // complete string length (sans \0)
    1643     ssize_t         headLength;         // length of string to prepend
    1644     char            *oldDest;           // copy of original string
    1645 
    1646     if (!*dest) {
    1647         // makes the string backup and concatination pointless
    1648         *dest = psStringCopy("");
    1649         length = 0;
    1650     } else {
    1651         // size of existing string
    1652         length = strlen(*dest);
    1653     }
    1654 
    1655     // find the size of the string to prepend
    1656     va_start(args, format);
    1657     // C99 guarentees vsnprintf() to work as expected with size = 0
    1658     headLength = vsnprintf(*dest, 0, format, args);
    1659     va_end(args);
    1660 
    1661     // if the new head is zero length, return the length of the old string.  if
    1662     // it's a format error, return the error code.
    1663     if (headLength < 1) {
    1664         return headLength == 0 ? length : headLength;
    1665     }
    1666 
    1667     // backup original string
    1668     oldDest = psStringCopy(*dest);
    1669 
    1670     // new string length (sans \0)
    1671     length += headLength;
    1672 
    1673     // realloc string to head + string + \0
    1674     *dest = psRealloc(*dest, length + 1);
    1675 
    1676     // copy the new head to the beginning of string
    1677     va_start(args, format);
    1678     vsnprintf(*dest, length + 1, format, args);
    1679     va_end(args);
    1680 
    1681     // append the original string
    1682     strncat(*dest, oldDest, length + 1);
    1683 
    1684     psFree(oldDest);
    1685 
    1686     return length;
    1687 }
    1688 
    16891596#endif // BUILD_PSDB
  • trunk/psLib/src/sys/psString.c

    r3264 r3866  
    99 *  @author Eric Van Alst, MHPCC
    1010 *
    11  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-02-17 19:26:24 $
     11 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-05-06 18:15:25 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5555    return returnValue;
    5656}
     57
     58ssize_t psStringAppend(char **dest, const char *format, ...)
     59{
     60    va_list         args;
     61    size_t          length;             // complete string length (sans \0)
     62    size_t          oldLength;          // original string length (sans \0)
     63    ssize_t         tailLength;         // length of string to append
     64
     65    if (!*dest) {
     66        *dest = psStringCopy("");
     67        oldLength = 0;
     68    } else {
     69        // size of existing string
     70        oldLength = strlen(*dest);
     71    }
     72
     73    // find the size of the string to append
     74    va_start(args, format);
     75    // C99 guarentees vsnprintf() to work as expected with size = 0
     76    tailLength = vsnprintf(*dest, 0, format, args);
     77    va_end(args);
     78
     79    // if the new tail is zero length, return the length of the old string.  if
     80    // it's a format error, return the error code.
     81    if (tailLength < 1) {
     82        return tailLength == 0 ? oldLength : tailLength;
     83    }
     84
     85    // new string length (sans \0)
     86    length = oldLength + tailLength;
     87
     88    // realloc string to string + tail + \0
     89    *dest = psRealloc(*dest, length + 1);
     90
     91    // append tail + \0
     92    va_start(args, format);
     93    vsnprintf(*dest + oldLength, tailLength + 1, format, args);
     94    va_end(args);
     95
     96    return length;
     97}
     98
     99ssize_t psStringPrepend(char **dest, const char *format, ...)
     100{
     101    va_list         args;
     102    size_t          length;             // complete string length (sans \0)
     103    ssize_t         headLength;         // length of string to prepend
     104    char            *oldDest;           // copy of original string
     105
     106    if (!*dest) {
     107        // makes the string backup and concatination pointless
     108        *dest = psStringCopy("");
     109        length = 0;
     110    } else {
     111        // size of existing string
     112        length = strlen(*dest);
     113    }
     114
     115    // find the size of the string to prepend
     116    va_start(args, format);
     117    // C99 guarentees vsnprintf() to work as expected with size = 0
     118    headLength = vsnprintf(*dest, 0, format, args);
     119    va_end(args);
     120
     121    // if the new head is zero length, return the length of the old string.  if
     122    // it's a format error, return the error code.
     123    if (headLength < 1) {
     124        return headLength == 0 ? length : headLength;
     125    }
     126
     127    // backup original string
     128    oldDest = psStringCopy(*dest);
     129
     130    // new string length (sans \0)
     131    length += headLength;
     132
     133    // realloc string to head + string + \0
     134    *dest = psRealloc(*dest, length + 1);
     135
     136    // copy the new head to the beginning of string
     137    va_start(args, format);
     138    vsnprintf(*dest, length + 1, format, args);
     139    va_end(args);
     140
     141    // append the original string
     142    strncat(*dest, oldDest, length + 1);
     143
     144    psFree(oldDest);
     145
     146    return length;
     147}
  • trunk/psLib/src/sys/psString.h

    r3264 r3866  
    1010 *  @author Eric Van Alst, MHPCC
    1111 *
    12  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-02-17 19:26:24 $
     12 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2005-05-06 18:15:25 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1919#define PS_STRING_H
    2020
     21#include <sys/types.h>
    2122#include "psType.h"
    2223
     
    6768);
    6869
     70/** Appends a format onto a string
     71 *
     72 * This function shall allocate a new string if dest is NULL.  dest shall be
     73 * automatically extended to the size of the new string.
     74 *
     75 * @return The length of the new string (excluding '\0')
     76 */
     77
     78ssize_t psStringAppend(
     79    char **dest,                        ///< existing string
     80    const char *format,                 ///< format to append
     81    ...                                 ///< format arguments
     82);
     83
     84/** Prepends a format onto a string
     85 *
     86 * This function shall allocate a new string if dest is NULL.  dest shall be
     87 * automatically extended to the size of the new string.
     88 *
     89 * @return The length of the new string (excluding '\0')
     90 */
     91
     92ssize_t psStringPrepend(
     93    char **dest,                        ///< existing string
     94    const char *format,                 ///< format to append
     95    ...                                 ///< format arguments
     96);
     97
    6998/* @} */// Doxygen - End of SystemGroup Functions
    7099
  • trunk/psLib/src/sysUtils/psString.c

    r3264 r3866  
    99 *  @author Eric Van Alst, MHPCC
    1010 *
    11  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-02-17 19:26:24 $
     11 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-05-06 18:15:25 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5555    return returnValue;
    5656}
     57
     58ssize_t psStringAppend(char **dest, const char *format, ...)
     59{
     60    va_list         args;
     61    size_t          length;             // complete string length (sans \0)
     62    size_t          oldLength;          // original string length (sans \0)
     63    ssize_t         tailLength;         // length of string to append
     64
     65    if (!*dest) {
     66        *dest = psStringCopy("");
     67        oldLength = 0;
     68    } else {
     69        // size of existing string
     70        oldLength = strlen(*dest);
     71    }
     72
     73    // find the size of the string to append
     74    va_start(args, format);
     75    // C99 guarentees vsnprintf() to work as expected with size = 0
     76    tailLength = vsnprintf(*dest, 0, format, args);
     77    va_end(args);
     78
     79    // if the new tail is zero length, return the length of the old string.  if
     80    // it's a format error, return the error code.
     81    if (tailLength < 1) {
     82        return tailLength == 0 ? oldLength : tailLength;
     83    }
     84
     85    // new string length (sans \0)
     86    length = oldLength + tailLength;
     87
     88    // realloc string to string + tail + \0
     89    *dest = psRealloc(*dest, length + 1);
     90
     91    // append tail + \0
     92    va_start(args, format);
     93    vsnprintf(*dest + oldLength, tailLength + 1, format, args);
     94    va_end(args);
     95
     96    return length;
     97}
     98
     99ssize_t psStringPrepend(char **dest, const char *format, ...)
     100{
     101    va_list         args;
     102    size_t          length;             // complete string length (sans \0)
     103    ssize_t         headLength;         // length of string to prepend
     104    char            *oldDest;           // copy of original string
     105
     106    if (!*dest) {
     107        // makes the string backup and concatination pointless
     108        *dest = psStringCopy("");
     109        length = 0;
     110    } else {
     111        // size of existing string
     112        length = strlen(*dest);
     113    }
     114
     115    // find the size of the string to prepend
     116    va_start(args, format);
     117    // C99 guarentees vsnprintf() to work as expected with size = 0
     118    headLength = vsnprintf(*dest, 0, format, args);
     119    va_end(args);
     120
     121    // if the new head is zero length, return the length of the old string.  if
     122    // it's a format error, return the error code.
     123    if (headLength < 1) {
     124        return headLength == 0 ? length : headLength;
     125    }
     126
     127    // backup original string
     128    oldDest = psStringCopy(*dest);
     129
     130    // new string length (sans \0)
     131    length += headLength;
     132
     133    // realloc string to head + string + \0
     134    *dest = psRealloc(*dest, length + 1);
     135
     136    // copy the new head to the beginning of string
     137    va_start(args, format);
     138    vsnprintf(*dest, length + 1, format, args);
     139    va_end(args);
     140
     141    // append the original string
     142    strncat(*dest, oldDest, length + 1);
     143
     144    psFree(oldDest);
     145
     146    return length;
     147}
  • trunk/psLib/src/sysUtils/psString.h

    r3264 r3866  
    1010 *  @author Eric Van Alst, MHPCC
    1111 *
    12  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-02-17 19:26:24 $
     12 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2005-05-06 18:15:25 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1919#define PS_STRING_H
    2020
     21#include <sys/types.h>
    2122#include "psType.h"
    2223
     
    6768);
    6869
     70/** Appends a format onto a string
     71 *
     72 * This function shall allocate a new string if dest is NULL.  dest shall be
     73 * automatically extended to the size of the new string.
     74 *
     75 * @return The length of the new string (excluding '\0')
     76 */
     77
     78ssize_t psStringAppend(
     79    char **dest,                        ///< existing string
     80    const char *format,                 ///< format to append
     81    ...                                 ///< format arguments
     82);
     83
     84/** Prepends a format onto a string
     85 *
     86 * This function shall allocate a new string if dest is NULL.  dest shall be
     87 * automatically extended to the size of the new string.
     88 *
     89 * @return The length of the new string (excluding '\0')
     90 */
     91
     92ssize_t psStringPrepend(
     93    char **dest,                        ///< existing string
     94    const char *format,                 ///< format to append
     95    ...                                 ///< format arguments
     96);
     97
    6998/* @} */// Doxygen - End of SystemGroup Functions
    7099
Note: See TracChangeset for help on using the changeset viewer.