예제 #1
0
파일: color.c 프로젝트: hrsalles/kohonen
LSTList rgbGetBasicColors () {
    int i;
    static RGBColor_ST basic_colors_vc[] = {
        { 000, 000, 000 }, { 255, 255, 255 },
        { 255, 000, 000 }, { 000, 255, 000 },
        { 000, 000, 255 }, { 255, 000, 255 },
        { 000, 255, 255 }, { 255, 255, 000 }
    };
    RGBColor_ST* curr_color_p;
    LSTList basic_colors = lstNew();

    if (basic_colors)
        for (i = 0; i < 8; i ++) {
            curr_color_p = rgbAlloc(basic_colors_vc[i]);

            if (curr_color_p) lstAppend(basic_colors, curr_color_p);
            else {
                rgb_current_error = RGB_NOT_ENOUGH_SPACE;
                lstDestroy(&basic_colors);

                return NULL;
            }
        }
    else rgb_current_error = RGB_NOT_ENOUGH_SPACE;

    return basic_colors;
}
예제 #2
0
void sqpStoreColumn( HLST *ph, char *pszColumn, int nColumn )
{
	HSQPCOLUMN	pColumn	= (HSQPCOLUMN)malloc( sizeof(SQPCOLUMN) );
    char        szName[200];

#ifdef SQPDEBUG
	printf( "[SQP][%s][%d] BEGIN: %s %d\n", __FILE__, __LINE__, pszColumn, nColumn );
#endif

	pColumn->pszTable	= NULL;
    if ( pszColumn )
    	pColumn->pszColumn	= (char*)strdup( pszColumn );
    else
    {
        sprintf( szName, "%d", nColumn );
    	pColumn->pszColumn	= (char*)strdup( szName );
    }

	if ( !(*ph) )
		*ph = lstOpen();

	lstAppend( *ph, pColumn );
	
#ifdef SQPDEBUG
	printf( "[SQP][%s][%d] END:\n", __FILE__, __LINE__ );
#endif

}
예제 #3
0
int logPushMsg( HLOG hLog, char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessage )
{
    HLOGMSG     hMsg;
    FILE        *hFile;

    if ( !hLog ) return LOG_ERROR;
    if ( !hLog->hMessages ) return LOG_ERROR;
    if ( !hLog->bOn ) return LOG_SUCCESS;

    if ( !pszModule ) return LOG_ERROR;
    if ( !pszFunctionName ) return LOG_ERROR;
    if ( !pszMessage ) return LOG_ERROR;


    /* check for, and handle, max msg */
    if ( hLog->nMaxMsgs && hLog->hMessages->nItems >= hLog->nMaxMsgs )
        logPopMsg( hLog );

    hMsg                    = malloc( sizeof(LOGMSG) );
    if (!hMsg) goto error_abort0;

    hMsg->pszModuleName     = (char *)strdup( pszModule );
    if (!hMsg->pszModuleName) goto error_abort1;

    hMsg->pszFunctionName   = (char *)strdup( pszFunctionName );
    if (!hMsg->pszFunctionName) goto error_abort2;

    hMsg->pszMessage        = (char *)strdup( pszMessage );
    if (!hMsg->pszMessage) goto error_abort3;

    hMsg->nLine             = nLine;
    hMsg->nSeverity         = nSeverity;
    hMsg->nCode             = nCode;

    /* append to  list */
    lstAppend( hLog->hMessages, hMsg );

    /* append to file */
    if ( hLog->pszLogFile )
    {
        hFile = uo_fopen( hLog->pszLogFile, "a" );
        if ( !hFile ) return LOG_ERROR;

        uo_fprintf( hFile, "[%s][%s][%s][%d]%s\n", hLog->pszProgramName, pszModule, pszFunctionName, nLine, pszMessage );

        uo_fclose( hFile );
    }

    return LOG_SUCCESS;

    error_abort3:
    free(hMsg->pszFunctionName);
    error_abort2:
    free(hMsg->pszModuleName);
    error_abort1:
    free(hMsg);
    error_abort0:
    return LOG_ERROR;
}
예제 #4
0
int lstInsert( HLST hLst, void *pData )
{
	HLSTITEM	hItem;
	
	if ( !hLst )
		return LST_ERROR;

	if ( !hLst->hCurrent )
		return lstAppend( hLst, pData );

	/**********************
	 * CREATE AN ITEM
	 **********************/
	hItem = malloc( sizeof(LSTITEM) );
	if ( !hItem )
		return LST_ERROR;

	hItem->bDelete		= false;
	hItem->bHide		= false;
	hItem->hLst			= hLst;
	hItem->nRefs		= 0;
	hItem->pData		= NULL;
	hItem->pNext		= NULL;
	hItem->pPrev		= NULL;

	if ( hLst->hLstBase )
	{
		/**********************
		 * WE ARE A CURSOR LIST SO...
		 * 1. ADD TO BASE LIST
		 * 2. inc BASE LIST ITEM REF COUNT
		 * 3. ADD TO THIS LIST (ref to base list)
		 **********************/
		lstInsert( hLst->hLstBase, pData );				/* !!! INSERT POS IN BASE LIST IS UNPREDICTABLE !!! */
														/*     BECAUSE hCurrent MAY HAVE CHANGED AND WE 	*/
														/*     ARE NOT TRYING TO PUT IT BACK				*/
		hItem->pData = hLst->hLstBase->hCurrent;		
        hLst->hLstBase->hCurrent->nRefs++;
		_lstInsert( hLst, hItem );
	}
	else
	{
		/**********************
		 * WE ARE THE ROOT SO...
		 * 1. ADD TO THIS LIST
		 **********************/
		hItem->pData = pData;
		_lstInsert( hLst, hItem );
	}


	return LST_SUCCESS;
}
예제 #5
0
int logvPushMsgf( HLOG hLog, char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessageFormat, va_list args )
{
    HLOGMSG     hMsg=NULL;
    FILE        *hFile;
    int             mlen=0;

    if ( !hLog ) return LOG_ERROR;
    if ( !hLog->hMessages ) return LOG_ERROR;
    if ( !hLog->bOn ) return LOG_SUCCESS;

    if ( !pszModule ) return LOG_ERROR;
    if ( !pszFunctionName ) return LOG_ERROR;
    if ( !pszMessageFormat ) return LOG_ERROR;

    /* check for, and handle, max msg */
    if ( hLog->nMaxMsgs && hLog->hMessages->nItems == hLog->nMaxMsgs )
        logPopMsg( hLog );

    hMsg                    = malloc( sizeof(LOGMSG) );
    if (!hMsg) goto error_abort0;

    hMsg->pszModuleName     = (char *)strdup( pszModule );
    if (!hMsg->pszModuleName) goto error_abort1;

    hMsg->pszFunctionName   = (char *)strdup( pszFunctionName );
    if (!hMsg->pszFunctionName) goto error_abort2;

#if defined( HAVE_VSNPRINTF )
    mlen=vsnprintf(NULL,0,pszMessageFormat,args);
#else
    mlen=uodbc_vsnprintf(NULL,0,pszMessageFormat,args);
#endif
    mlen++;
    hMsg->pszMessage        = malloc(mlen);
    if (!hMsg->pszMessage) goto error_abort3;

#if defined( HAVE_VSNPRINTF )
    vsnprintf(hMsg->pszMessage,mlen,pszMessageFormat,args);
#else
    uodbc_vsnprintf(hMsg->pszMessage,mlen,pszMessageFormat,args);
#endif

    hMsg->nLine             = nLine;
    hMsg->nSeverity         = nSeverity;
    hMsg->nCode             = nCode;

    /* append to  list */
    lstAppend( hLog->hMessages, hMsg );

    /* append to file */
    if ( hLog->pszLogFile )
    {
        hFile = uo_fopen( hLog->pszLogFile, "a" );
        if ( !hFile ) return LOG_ERROR;

        if (hMsg)
        {
            uo_fprintf( hFile, "[%s][%s][%s][%d]%s\n", hLog->pszProgramName, pszModule, pszFunctionName, nLine, hMsg->pszMessage );
        }
        else
        {
            uo_fprintf( hFile, "[%s][%s][%s][%d]", hLog->pszProgramName, pszModule, pszFunctionName, nLine );
            uo_vfprintf( hFile, pszMessageFormat, args );
            uo_fprintf( hFile, "\n" );
        }

        uo_fclose( hFile );
    }

    return LOG_SUCCESS;

    error_abort3:
    free(hMsg->pszFunctionName);
    error_abort2:
    free(hMsg->pszModuleName);
    error_abort1:
    free(hMsg);
    error_abort0:
    return LOG_ERROR;
}