OS/2 codes: How to support DBCS #1 Determine if DBCS env
Most of OS/2 users are in SBCS countries. Naturally, many OS/2 programs are developed in their countries. And those programs lack DBCS support. To begin with this article, I'll write a series of articles for DBCS support.
OS/2 is based on a code page. And OS/2 provides many APIs for a code page. Out of these, you can use DosQueryDBCSEnv() to determine if DBCS environment because DBCS code pages provides the ranges of DBCS lead-bytes.
This is a syntax for DosQueryDBCSEnv().
Reference : http://cyberkinetica.homeunix.net/os2tk45/cp1/1126_L2H_DosQueryDBCSEnvSynta.html
Note: You can see the explanation for parameters by clicking them.
As you see, if country of *pcc is set to 0, then a default system country code is used. And if codepage of *pcc is set to 0, then a current process code page is used.
If returned buffer has two bytes of zero, then it means SBCS env, otherwise DBCS env.
Here is a function to determine if DBCS env by using the above.
// ----- 2015/01/12
Note: MB_CUR_MAX is affected by LC_CTYPE category not a process code page. By the way, a program starts with "C" or "POSIX" locale. That is, SBCS. So if you want to set a locale which you want, you should use setlocale(). And if a second parameter is an empty string(""), then a locale is set to a process locale. For example
How to determine if DBCS environment
OS/2 is based on a code page. And OS/2 provides many APIs for a code page. Out of these, you can use DosQueryDBCSEnv() to determine if DBCS environment because DBCS code pages provides the ranges of DBCS lead-bytes.
This is a syntax for DosQueryDBCSEnv().
Obtains a DBCS (double-byte character set) environmental vector that resides in the country file.
#define INCL_DOSNLS #include <os2.h> ULONG cb; /* The length, in bytes, of the data area (pBuf) provided by the caller. */ PCOUNTRYCODE pcc; /* A pointer to the COUNTRYCODE structure in which the country code and code page are identified. */ PCHAR pBuf; /* The data area where the country-dependent information for the DBCS environmental vector is returned. */ APIRET ulrc; /* Return Code. */ ulrc = DosQueryDBCSEnv(cb, pcc, pBuf);
Reference : http://cyberkinetica.homeunix.net/os2tk45/cp1/1126_L2H_DosQueryDBCSEnvSynta.html
Note: You can see the explanation for parameters by clicking them.
As you see, if country of *pcc is set to 0, then a default system country code is used. And if codepage of *pcc is set to 0, then a current process code page is used.
If returned buffer has two bytes of zero, then it means SBCS env, otherwise DBCS env.
Here is a function to determine if DBCS env by using the above.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #define INCL_DOSNLS #include <os2.h> int isDBCSEnv( void ) { COUNTRYCODE cc = { 0, }; UCHAR uchDBCSLead[ 12 ]; return DosQueryDBCSEnv( sizeof( uchDBCSLead ), &cc, uchDBCSLead ) == 0 && ( uchDBCSLead[ 0 ] || uchDBCSLead[ 1 ]); } #include <stdio.h> int main( void ) { printf("Is DBCS env ? %s\n", isDBCSEnv() ? "Yes" : "No"); return 0; } |
// ----- 2015/01/12
Locale version
1 2 3 4 5 6 7 | #include <stdlib.h> int isDBCSEnv( void ) { /* Do not consider unicodes such as UTF-8, UCS-2. */ return MB_CUR_MAX > 1; } |
Note: MB_CUR_MAX is affected by LC_CTYPE category not a process code page. By the way, a program starts with "C" or "POSIX" locale. That is, SBCS. So if you want to set a locale which you want, you should use setlocale(). And if a second parameter is an empty string(""), then a locale is set to a process locale. For example
1 2 3 4 5 6 7 | #include <locale.h> int main( void ) { setlocale( LC_ALL, ""); ... } |
댓글
댓글 쓰기