Ejemplo n.º 1
0
/*:::::*/
FBSTRING *fb_CHR ( int args, ... )
{
	FBSTRING 	*dst;
	va_list 	ap;
	unsigned int num;
	int i;

	if( args <= 0 )
		return &__fb_ctx.null_desc;

	va_start( ap, args );

	/* alloc temp string */
    dst = fb_hStrAllocTemp( NULL, args );
	if( dst != NULL )
	{
		/* convert */
		for( i = 0; i < args; i++ )
		{
			num = va_arg( ap, unsigned int );
			dst->data[i] = (unsigned char)num;
		}
		dst->data[args] = '\0';
	}
	else
Ejemplo n.º 2
0
FBCALL FBSTRING *fb_ExePath ( void )
{
	FBSTRING 	*dst;
	char		*p;
	char		tmp[MAX_PATH+1];
	ssize_t len;

	p = fb_hGetExePath( tmp, MAX_PATH );

	if( p != NULL )
	{
		/* alloc temp string */
        len = strlen( tmp );
        dst = fb_hStrAllocTemp( NULL, len );
		if( dst != NULL )
		{
			fb_hStrCopy( dst->data, tmp, len );
		}
		else
			dst = &__fb_ctx.null_desc;
	}
	else
		dst = &__fb_ctx.null_desc;

	return dst;
}
Ejemplo n.º 3
0
FBSTRING *fb_DrvIntlGetMonthName( int month, int short_names )
{
    const char *pszName;
    FBSTRING *result;
    size_t name_len;
    nl_item index;

    if( month < 1 || month > 12 )
        return NULL;

    if( short_names ) {
        index = (nl_item) (ABMON_1 + month - 1);
    } else {
        index = (nl_item) (MON_1 + month - 1);
    }

    FB_LOCK();

    pszName = nl_langinfo( index );
    if( pszName==NULL ) {
        FB_UNLOCK();
        return NULL;
    }

    name_len = strlen( pszName );

    result = fb_hStrAllocTemp( NULL, name_len );
    if( result!=NULL ) {
        FB_MEMCPY( result->data, pszName, name_len + 1 );
    }

    FB_UNLOCK();

    return result;
}
Ejemplo n.º 4
0
/*:::::*/
static FBSTRING *hHEX ( unsigned int num, int len, int digits )
{
	FBSTRING *dst;
	char *buf;
	int	i, totdigs;

	if( digits > 0 )
	{
		totdigs = (digits < len << 1? digits: len << 1);
		if( digits > len << 1 )
			digits = len << 1;
	}
	else
		totdigs = len << 1;

	/* alloc temp string */
    dst = fb_hStrAllocTemp( NULL, totdigs );
	if( dst == NULL )
		return &__fb_ctx.null_desc;

	/* convert */
	buf = dst->data;

	if( num == 0 )
	{
		if( digits <= 0 )
			digits = 1;

		while( digits-- )
			*buf++ = '0';
    }
	else
	{
		num <<= ((sizeof(int) << 3) - (totdigs << 2));

		for( i = 0; i < totdigs; i++, num <<= 4 )
			if( num > 0x0FFFFFFF )
				break;

		if( digits > 0 )
		{
			digits -= totdigs - i;
			while( digits-- )
				*buf++ = '0';
		}

		for( ; i < totdigs; i++, num <<= 4 )
			*buf++ = hex_table[(num & 0xF0000000) >> 28];
	}

	/* add null-term */
	*buf = '\0';

	fb_hStrSetLength( dst, buf - dst->data );

	return dst;
}
Ejemplo n.º 5
0
FBSTRING *fb_DrvIntlGetWeekdayName( int weekday, int short_names )
{
    char *pszName = NULL;
    size_t name_len;
    LCTYPE lctype;
    FBSTRING *result;

    if( weekday < 1 || weekday > 7 )
        return NULL;

    if( weekday==1 )
        weekday = 8;

    if( short_names ) {
        lctype = (LCTYPE) (LOCALE_SABBREVDAYNAME1 + weekday - 2);
    } else {
        lctype = (LCTYPE) (LOCALE_SDAYNAME1 + weekday - 2);
    }

    pszName = fb_hGetLocaleInfo( LOCALE_USER_DEFAULT, lctype,
                                 NULL, 0 );
    if( pszName==NULL )
        return NULL;

    name_len = strlen(pszName);

    result = fb_hStrAllocTemp( NULL, name_len );
    if( result!=NULL ) {
        /* !!!FIXME!!! GetCodepage() should become a hook function for console and gfx modes */
        int target_cp = /*( FB_GFX_ACTIVE() ? FB_GFX_GET_CODEPAGE() : GetConsoleCP() );*/ GetConsoleCP();
        if( target_cp!=-1 ) {
            FB_MEMCPY( result->data, pszName, name_len + 1 );
            result = fb_hIntlConvertString( result,
                                            CP_ACP,
                                            target_cp );
        }
    }

   free( pszName );

    return result;
}
Ejemplo n.º 6
0
FBCALL FBSTRING *fb_WstrToStr( const FB_WCHAR *src )
{
	FBSTRING *dst;
	ssize_t chars;

    if( src == NULL )
    	return &__fb_ctx.null_desc;

	chars = fb_wstr_Len( src );
    if( chars == 0 )
    	return &__fb_ctx.null_desc;

    dst = fb_hStrAllocTemp( NULL, chars );
	if( dst == NULL )
		return &__fb_ctx.null_desc;

	fb_wstr_ConvToA( dst->data, src, chars );

	return dst;
}
Ejemplo n.º 7
0
/*:::::*/
FBCALL FBSTRING *fb_UIntToStr ( unsigned int num )
{
    FBSTRING 	*dst;

    /* alloc temp string */
    dst = fb_hStrAllocTemp( NULL, sizeof( int ) * 3 );
    if( dst != NULL )
    {
        /* convert */
#ifdef HOST_MINGW
        _ultoa( num, dst->data, 10 );
#else
        sprintf( dst->data, "%u", num );
#endif
        fb_hStrSetLength( dst, strlen( dst->data ) );
    }
    else
        dst = &__fb_ctx.null_desc;

    return dst;
}
Ejemplo n.º 8
0
FBCALL FBSTRING *fb_StrFill1( ssize_t cnt, int fchar )
{
	FBSTRING 	*dst;

	if( cnt > 0 )
	{
		/* alloc temp string */
        dst = fb_hStrAllocTemp( NULL, cnt );
		if( dst != NULL )
		{
			/* fill it */
			memset( dst->data, fchar, cnt );
			/* null char */
			dst->data[cnt] = '\0';
		}
		else
			dst = &__fb_ctx.null_desc;
	}
	else
		dst = &__fb_ctx.null_desc;

	return dst;
}
Ejemplo n.º 9
0
	if( digits <= 0 ) {
		/* Only use the minimum amount of digits needed; need to count
		   the important bits in the number. And if there are none set,
		   use 1 digit for 1 zero. */
		digits = 0;
		num2 = num;
		while( num2 ) {
			digits += 1;
			num2 >>= 1;
		}
		if( digits == 0 )
			digits = 1;
	}

	s = fb_hStrAllocTemp( NULL, digits );
	if( s == NULL )
		return &__fb_ctx.null_desc;

	i = digits - 1;
	while( i >= 0 ) {
		s->data[i] = '0' + (num & 1); /* '0' or '1' */
		num >>= 1;
		i -= 1;
	}

	s->data[digits] = '\0';
	return s;
}

FBCALL FBSTRING *fb_BIN_l ( unsigned long long num )