IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ticket #395: pslib-0.5.0-string_conslidation.patch

File pslib-0.5.0-string_conslidation.patch, 8.9 KB (added by jhoblitt, 21 years ago)

patch to conslidate psString functions into psString.c

  • pslib/src/dataIO/psDB.

    ---------------------
    PatchSet 235 
    Date: 2005/05/06 00:42:24
    Author: jhoblitt
    Branch: HEAD
    Tag: (none) 
    Log:
    move psStringAppend() & psStringPrepend() from psDB.c to psString.c and make them public
    
    Members: 
    	src/dataIO/psDB.c:1.1->1.2 
    	src/sysUtils/psString.c:1.1->1.2 
    	src/sysUtils/psString.h:1.1->1.2 
    
    diff -u pslib/src/dataIO/psDB.c:1.1 pslib/src/dataIO/psDB.c:1.2
    old new  
    1111 *  @author Aaron Culliney
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.1 $ $Name:  $
    15  *  @date $Date: 2005/04/06 01:12:58 $
     14 *  @version $Revision: 1.2 $ $Name:  $
     15 *  @date $Date: 2005/05/06 00:42:24 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
    1818 */
     
    8282
    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
    8987// public functions
     
    16111609    return string;
    16121610}
    16131611
    1614 static ssize_t psStringAppend(char **dest, const char *format, ...)
    1615 {
    1616     va_list         args;
    1617     size_t          length;             // complete string length (sans \0)
    1618     size_t          oldLength;          // original string length (sans \0)
    1619     ssize_t         tailLength;         // length of string to append
    1620 
    1621     if (!*dest) {
    1622         *dest = psStringCopy("");
    1623         oldLength = 0;
    1624     } else {
    1625         // size of existing string
    1626         oldLength = strlen(*dest);
    1627     }
    1628 
    1629     // find the size of the string to append
    1630     va_start(args, format);
    1631     // C99 guarentees vsnprintf() to work as expected with size = 0
    1632     tailLength = vsnprintf(*dest, 0, format, args);
    1633     va_end(args);
    1634 
    1635     // if the new tail is zero length, return the length of the old string.  if
    1636     // it's a format error, return the error code.
    1637     if (tailLength < 1) {
    1638         return tailLength == 0 ? oldLength : tailLength;
    1639     }
    1640 
    1641     // new string length (sans \0)
    1642     length = oldLength + tailLength;
    1643 
    1644     // realloc string to string + tail + \0
    1645     *dest = psRealloc(*dest, length + 1);
    1646 
    1647     // append tail + \0
    1648     va_start(args, format);
    1649     vsnprintf(*dest + oldLength, tailLength + 1, format, args);
    1650     va_end(args);
    1651 
    1652     return length;
    1653 }
    1654 
    1655 static ssize_t psStringPrepend(char **dest, const char *format, ...)
    1656 {
    1657     va_list         args;
    1658     size_t          length;             // complete string length (sans \0)
    1659     ssize_t         headLength;         // length of string to prepend
    1660     char            *oldDest;           // copy of original string
    1661 
    1662     if (!*dest) {
    1663         // makes the string backup and concatination pointless
    1664         *dest = psStringCopy("");
    1665         length = 0;
    1666     } else {
    1667         // size of existing string
    1668         length = strlen(*dest);
    1669     }
    1670 
    1671     // find the size of the string to prepend
    1672     va_start(args, format);
    1673     // C99 guarentees vsnprintf() to work as expected with size = 0
    1674     headLength = vsnprintf(*dest, 0, format, args);
    1675     va_end(args);
    1676 
    1677     // if the new head is zero length, return the length of the old string.  if
    1678     // it's a format error, return the error code.
    1679     if (headLength < 1) {
    1680         return headLength == 0 ? length : headLength;
    1681     }
    1682 
    1683     // backup original string
    1684     oldDest = psStringCopy(*dest);
    1685 
    1686     // new string length (sans \0)
    1687     length += headLength;
    1688 
    1689     // realloc string to head + string + \0
    1690     *dest = psRealloc(*dest, length + 1);
    1691 
    1692     // copy the new head to the beginning of string
    1693     va_start(args, format);
    1694     vsnprintf(*dest, length + 1, format, args);
    1695     va_end(args);
    1696 
    1697     // append the original string
    1698     strncat(*dest, oldDest, length + 1);
    1699 
    1700     psFree(oldDest);
    1701 
    1702     return length;
    1703 }
    1704 
    17051612#endif // BUILD_PSDB
  • pslib/src/sysUtils/psString.

    diff -u pslib/src/sysUtils/psString.c:1.1 pslib/src/sysUtils/psString.c:1.2
    old new  
    88 *
    99 *  @author Eric Van Alst, MHPCC
    1010 *
    11  *  @version $Revision: 1.1 $ $Name:  $
    12  *  @date $Date: 2005/02/17 19:26:24 $
     11 *  @version $Revision: 1.2 $ $Name:  $
     12 *  @date $Date: 2005/05/06 00:42:27 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1515 */
     
    5454    // Return the string pointer
    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}
  • pslib/src/sysUtils/psString.

    diff -u pslib/src/sysUtils/psString.h:1.1 pslib/src/sysUtils/psString.h:1.2
    old new  
    99 *
    1010 *  @author Eric Van Alst, MHPCC
    1111 *
    12  *  @version $Revision: 1.1 $ $Name:  $
    13  *  @date $Date: 2005/02/17 19:26:24 $
     12 *  @version $Revision: 1.2 $ $Name:  $
     13 *  @date $Date: 2005/05/06 00:42:27 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1616 */
     
    1818#ifndef PS_STRING_H
    1919#define PS_STRING_H
    2020
     21#include <sys/types.h>
    2122#include "psType.h"
    2223
    2324/** This macro will convert the argument to a quoted string */
     
    6667    /**< Number of bytes to allocate for string copy */
    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
    71100#endif