Determining DBCS Environment Vector

There are many APIs provided by OS/2 to obtain the runtime environment. This chapter describes some of these APIs used to determine environment information that are unique to each country.

┌──────────────────────────────────────────────────────────────────────┐
│DosQueryDBCSEnv is to:                                                │
│                                                                      │
│ check whether the runtime code page is an SBCS one or a combined    │
│one.                                                                  │
│                                                                      │
│ find the valid code range for the first byte of DBCS at the current │
│code page setting.                                                    │
└──────────────────────────────────────────────────────────────────────┘

The first step toward the DBCS enabling is to determine whether your program should expect DBCS data or not. If the program is running at a combined code page, you should expect DBCS data to come in and should start activating DBCS-support capability of the program before it processes the first datum.

The DosQueryDBCSEnv (changed from DosGetDBCSEv) serves for the determination to obtain the DBCS environment vector. The syntax of the API is as follows:

Set 0 to are members of COUNTRYCODE, to obtain the DBCS environment vector of the runtime code page.

Check the obtained environment vector until it terminates with two bytes of binary 0. One of the following DBCS environment vectors, which tells you a valid code range of the first byte of DBCS at the runtime code page, is retuned from the operating system. If the value of the vector is 0000H, it means the program is running at a SBCS code page:

┌────────────────────┬────────────────────┬────────────────────┐
│Code page           │Env. vector         │The 1st byte of DBCS│
├────────────────────┼────────────────────┼────────────────────┤
│Japanese (932 and   │819FE0FC0000H       │81H-9FH, E0-FCH     │
│942)                │                    │                    │
├────────────────────┼────────────────────┼────────────────────┤
│Korean (949)        │8FFE0000H           │8FH-FEH             │
├────────────────────┼────────────────────┼────────────────────┤
│Simplified Chinese  │8CFE0000H           │8CH-FEH             │
│(1381)              │                    │                    │
├────────────────────┼────────────────────┼────────────────────┤
│Traditional Chinese │81FE0000H           │81H-FEH             │
│(950)               │                    │                    │
├────────────────────┼────────────────────┼────────────────────┤
│Traditional Chinese │81FC0000H           │81H-FCH             │
│(938 and 948)       │                    │                    │
├────────────────────┼────────────────────┼────────────────────┤
│Others              │0000H               │None                │
└────────────────────┴────────────────────┴────────────────────┘

The valid code range of the first byte of DBCS should be stored in a table. The table is used afterwards to determine whether a byte in process is a SBCS character or a part of a DBCS character.

The following example shows how to obtain and store the valid code range.

...
#define    INCL_DOSNLS

#include   <os2.h>
#include   <stdlib.h>
#include   <stdio.h>
#include   <string.h>              // STRING.H now includes MemXXX
#include   <time.h>
#include   "ordent.h"
#include   "dbcs.h"

COUNTRYINFO   ctryInfo;
USHORT flDbcsCp;

/*--------------------------------------------------------------------*/
/*  Table to identify if one byte data is in the range of             */
/*  DBCS 1st byte of the current environment.                         */
/*    If c is in the 1st byte range dbcsTable[c] == DBCS_1ST (== 1)   */
/*    else                          dbcsTable[c] == SBCS     (== 0)   */
/*--------------------------------------------------------------------*/
static USHORT dbcsTable[256];

USHORT InitDBCSTable( void );
USHORT isDBCS1st( UCHAR );
USHORT getCharType( UCHAR *, USHORT );
USHORT dbcsStrValidate( UCHAR *, USHORT *, USHORT );


/**********************************************************************/
/*    Set up a DBCS table with the DBCS environmental vector.         */
/**********************************************************************/
USHORT InitDBCSTable()
{
  UCHAR  dbcsEv[12];
  USHORT i, j;
  COUNTRYCODE ctryCode;

  /*--- Initialization of variables --------------------------*/
  ctryCode.country = 0;
  ctryCode.codepage = 0;
  for (i = 0; i < 256; i++) dbcsTable[i] = SBCS;

  /*--- System call to obtain the DBCS environmental vector --*/
  DosQueryDBCSEnv(12, &ctryCode, dbcsEv);

  for (j = 0; dbcsEv[j] | dbcsEv[j + 1]; j += 2)
    for (i = dbcsEv[j]; i <= dbcsEv[j + 1]; i++)
      dbcsTable[i] = DBCS_1ST;
  /*----------------------------------------------------------*/
  /*   Returns DBCS_CP if the DBCS 1st byte range is defined, */
  /*   else returns NON_DBCS_CP.                              */
  /*----------------------------------------------------------*/
  return flDbcsCp = (dbcsEv[0] | dbcsEv[1] ? DBCS_CP : NON_DBCS_CP);
}
...

Obtaining DBCS environment vector (source: NLSSUB.C)


[Back: Recognizing DBCS OS/2 from your program]
[Next: Determining runtime code page and country code]