third_party/inchi/INCHI_BASE/src/ichiprt2.c
int MakeDecNumber( char        *szString,
                   int         nStringLen,
                   const char  *szLeadingDelim,
                   int         nValue )
{
#define DECIMAL_BASE     10
#define DECIMAL_MINUS    '-'
#define DECIMAL_ZERO_VAL '0'
#define DECIMAL_ONE      '1'
#define DECIMAL_ZERO     '0'

    char *p = szString;
    char *q;
    int  nChar;

    if (nStringLen < 2)
    {
        return -1;
    }
    while (szLeadingDelim && *szLeadingDelim && --nStringLen)
    {
        *p++ = *szLeadingDelim++;
    }
    if (nStringLen < 2)
    {
        return -1;
    }
    if (!nValue)
    {
        *p++ = DECIMAL_ZERO_VAL;  /*  zero value (cannot use 0) */
        *p = '\0';
        return (int) ( p - szString );
    }
    if (nValue < 0)
    {
        *p++ = DECIMAL_MINUS;
        nStringLen--;
        nValue = -nValue;
    }
    for (q = p; nValue && --nStringLen; nValue /= DECIMAL_BASE)
    {
        if (nChar = nValue % DECIMAL_BASE)
        {
            nChar = DECIMAL_ONE + nChar - 1;
        }
        else
        {
            nChar = DECIMAL_ZERO;
        }
        *q++ = nChar;
    }
    if (nStringLen <= 0)
    {
        return -1;
    }
    *q = '\0';
    mystrrev( p );

    return (int) ( q - szString );

#undef DECIMAL_BASE
#undef DECIMAL_MINUS
#undef DECIMAL_ZERO_VAL
#undef DECIMAL_ONE
#undef DECIMAL_ZERO
}
/****************************************************************************
  MakeDecNumber( ... )

    Produce a decimal number

    szString length nStringLen includes 1 byte for zero termination
    Return Value: length without zero termination; -1 means not enough room
****************************************************************************/


szString length nStringLen includes 1 byte for zero termination
Return Value: length without zero termination; -1 means not enough room
szString length nStringLen includes 1 byte for zero termination Return Value : length without zero termination ; - 1 means not enough room
int MakeDecNumber( char        *szString,
                   int         nStringLen,
                   const char  *szLeadingDelim,
                   int         nValue )
{
#define DECIMAL_BASE     10
#define DECIMAL_MINUS    '-'
#define DECIMAL_ZERO_VAL '0'
#define DECIMAL_ONE      '1'
#define DECIMAL_ZERO     '0'
    char *p = szString;
    char *q;
    int  nChar;
    if (nStringLen < 2)
    {
        return -1;
    }
    while (szLeadingDelim && *szLeadingDelim && --nStringLen)
    {
        *p++ = *szLeadingDelim++;
    }
    if (nStringLen < 2)
    {
        return -1;
    }
    if (!nValue)
    {
        *p++ = DECIMAL_ZERO_VAL;  
        *p = '\0';
        return (int) ( p - szString );
    }
    if (nValue < 0)
    {
        *p++ = DECIMAL_MINUS;
        nStringLen--;
        nValue = -nValue;
    }
    for (q = p; nValue && --nStringLen; nValue /= DECIMAL_BASE)
    {
        if (nChar = nValue % DECIMAL_BASE)
        {
            nChar = DECIMAL_ONE + nChar - 1;
        }
        else
        {
            nChar = DECIMAL_ZERO;
        }
        *q++ = nChar;
    }
    if (nStringLen <= 0)
    {
        return -1;
    }
    *q = '\0';
    mystrrev( p );
    return (int) ( q - szString );
#undef DECIMAL_BASE
#undef DECIMAL_MINUS
#undef DECIMAL_ZERO_VAL
#undef DECIMAL_ONE
#undef DECIMAL_ZERO
}
int MakeDecNumber ( char * szString , int nStringLen , const char * szLeadingDelim , int nValue ) { #define DECIMAL_BASE      10 #define DECIMAL_MINUS     '-' #define DECIMAL_ZERO_VAL  '0' #define DECIMAL_ONE       '1' #define DECIMAL_ZERO      '0' char * p = szString ; char * q ; int nChar ; if ( nStringLen < 2 ) { return -1 ; } while ( szLeadingDelim && * szLeadingDelim && -- nStringLen ) { * p ++ = * szLeadingDelim ++ ; } if ( nStringLen < 2 ) { return -1 ; } if ( ! nValue ) { * p ++ = DECIMAL_ZERO_VAL ; * p = ' \0 ' ; return ( int ) ( p - szString ) ; } if ( nValue < 0 ) { * p ++ = DECIMAL_MINUS ; nStringLen -- ; nValue = - nValue ; } for ( q = p ; nValue && -- nStringLen ; nValue /= DECIMAL_BASE ) { if ( nChar = nValue % DECIMAL_BASE ) { nChar = DECIMAL_ONE + nChar - 1 ; } else { nChar = DECIMAL_ZERO ; } * q ++ = nChar ; } if ( nStringLen <= 0 ) { return -1 ; } * q = ' \0 ' ; mystrrev ( p ) ; return ( int ) ( q - szString ) ; #undef  DECIMAL_BASE #undef  DECIMAL_MINUS #undef  DECIMAL_ZERO_VAL #undef  DECIMAL_ONE #undef  DECIMAL_ZERO }
MakeDecNumber( ... )
Produce a decimal number
MakeDecNumber ( ... ) Produce a decimal number
/*  zero value (cannot use 0) */