FreeBASIC  0.91.0
drv_intl_getweekdayname.c
Go to the documentation of this file.
1 /* get localized weekday name */
2 
3 #include "../fb.h"
4 #include "fb_private_intl.h"
5 
6 FBSTRING *fb_DrvIntlGetWeekdayName( int weekday, int short_names )
7 {
8  char *pszName = NULL;
9  size_t name_len;
10  LCTYPE lctype;
11  FBSTRING *result;
12 
13  if( weekday < 1 || weekday > 7 )
14  return NULL;
15 
16  if( weekday==1 )
17  weekday = 8;
18 
19  if( short_names ) {
20  lctype = (LCTYPE) (LOCALE_SABBREVDAYNAME1 + weekday - 2);
21  } else {
22  lctype = (LCTYPE) (LOCALE_SDAYNAME1 + weekday - 2);
23  }
24 
25  pszName = fb_hGetLocaleInfo( LOCALE_USER_DEFAULT, lctype,
26  NULL, 0 );
27  if( pszName==NULL )
28  return NULL;
29 
30  name_len = strlen(pszName);
31 
32  result = fb_hStrAllocTemp( NULL, name_len );
33  if( result!=NULL ) {
34  /* !!!FIXME!!! GetCodepage() should become a hook function for console and gfx modes */
35  int target_cp = /*( FB_GFX_ACTIVE() ? FB_GFX_GET_CODEPAGE() : GetConsoleCP() );*/ GetConsoleCP();
36  if( target_cp!=-1 ) {
37  FB_MEMCPY( result->data, pszName, name_len + 1 );
38  result = fb_hIntlConvertString( result,
39  CP_ACP,
40  target_cp );
41  }
42  }
43 
44  free( pszName );
45 
46  return result;
47 }