
/******************************************************/
/*Title:  sccpfun.c                                   */
/*Descr:  Common Function                             */
/*Author: Liang Hanxi                                 */
/*Create: 2002-2-19                                   */
/*Modify: 2003-5-9                                    */

/******************************************************/
//All the funtions base on following assuming:
//BCD:          0x123456
//Digits:       0x214356
//Str:          "123456"
//Ull:          123456
//Array:    {0x01,0x02,0x03,0x04,0x05,0x06};
#include "./include/sccp.h"

int ParseLine ( char *str, char ( *row )[128], int maxrow )
{
    char *pstr = str;
    int len, index = 0, i;
    BOOL black = 0;

    len = strlen ( str );
    for ( i = 0; i < len && index < maxrow; i++ )
    {
        if( isspace ( str[i] ) )
        {
            if( black == 0 )
                pstr = str + i + 1;
            else
            {
                str[i] = '\0';
                if( strlen ( pstr ) > 128 )
                    pstr[127] = 0;
                sprintf ( row[index++], "%s", pstr );
                pstr = str + i + 1;
            }
            black = 0;
        }
        else
            black = 1;
    }
    if( black == 1 )
    {
        if( strlen ( pstr ) > 128 )
            pstr[127] = 0;
        sprintf ( row[index++], "%s", pstr );
    }
    return index;
}

int GetEnt ( FILE * fp, char *key, char *str )
{
    char *pval, *pkey, *pchr;
    int i = 1, len;

    fseek ( fp, 0, SEEK_SET );
    pval = NULL;
    while ( fgets ( str, 200, fp ) != NULL )
    {
        if( ( pchr = strchr ( str, '#' ) ) != NULL )
            pchr[0] = '\0';
        if( ( pkey = strstr ( str, key ) ) != NULL )
        {
            if( ( pval = strchr ( str, '=' ) ) == NULL || pkey >= pval )
                continue;
            else
                break;
        }
    }
    if( pval == NULL )
        return -1;
    pval++;
    len = strlen ( pval );

    while ( isspace ( pval[len - i] ) && i <= len )
    {
        pval[len - i] = '\n';
        pval[len - i + 1] = '\0';
        i++;
    }

    i = 0;
    while ( isspace ( pval[i++] ) && i < len );
    sprintf ( str, "%s", pval + i - 1 );
    return 1;
}

BOOL isco ( Intra_Msg * intramsg )
{
    if( intramsg->msgtype == 9 || intramsg->msgtype == 10 || intramsg->msgtype == 17 || intramsg->msgtype == 18 || intramsg->msgtype == 19 || intramsg->msgtype == 20 )
        return 0;
    else if( intramsg->msgtype > 0 && intramsg->msgtype <= 20 )
        return 1;
    return 0;
}

BOOL iscl ( Intra_Msg * intramsg )
{
    if( intramsg->msgtype == 9 || intramsg->msgtype == 10 || intramsg->msgtype == 17 || intramsg->msgtype == 18 || intramsg->msgtype == 19 || intramsg->msgtype == 20 )
        return 1;
    else
        return 0;
}

BOOL iscr ( Intra_Msg * intramsg )
{
    if( intramsg->msgtype == 1 || intramsg->msgtype == 2 )
        return 1;
    else
        return 0;
}
