┌──────────────────────────────────────────────────────────────────────┐ │OS/2 PrfQueryProfileInt is used to find out a local time format, a │ │country currency sign and format, a numeric format, and the current │ │country code from the system profile. This information is used to show│ │results of the data process. │ └──────────────────────────────────────────────────────────────────────┘
Notations for presenting time, numeric figures and monetary value are not the same to all countries. Its example is demonstrated in Examples of local formats.
An application program needs to show date, time and numbers in local notations so that they are conventional to users. It must also adopt a local currency sign and format print monetary quantities.
┌──────────┬─────────────────────────┬────────────┬────────────┐ │Country │Date and Time │Monetary │Numeric │ ├──────────┼─────────────────────────┼────────────┼────────────┤ │USA │MM-DD-YY HH:MM:SS AM │$999.99 │999,999.99 │ ├──────────┼─────────────────────────┼────────────┼────────────┤ │Japan │YY-MM-DD HH:MM:SS │╛999 │999,999.99 │ └──────────┴─────────────────────────┴────────────┴────────────┘Consult National Language Design Guide Vol.2 NLS Reference (SE09-8002) for notations of other countries.
The current setting of the above formats are stored in C:\OS2\OS2.INI for a PM application program. PrfQueryProfileInt is used to find them from a PM program. The application name specified is "PM_National". The key names related to such local data format are as follows:
┌───────────────┬──────────┬────────────────────────────────────────┐ │Key name │Type │Description │ ├───────────────┼──────────┼────────────────────────────────────────┤ │iCountry │integer │Country code │ ├───────────────┼──────────┼────────────────────────────────────────┤ │iDate │integer │Date format. 0=MDY, 1=DMY, 2=YMD. │ ├───────────────┼──────────┼────────────────────────────────────────┤ │iCurrency │integer │Currency sign. 0=Preceding currency │ │ │ │simbol, no space separator, 1=Succeeding│ │ │ │currency symbol, no space separator, │ │ │ │2=Preceding currency symbol with a space│ │ │ │separator, 3=Succeeding currency symbol,│ │ │ │no space separator. │ ├───────────────┼──────────┼────────────────────────────────────────┤ │iTime │integer │Time format. 0=12-hour clock, 1=24-hour │ │ │ │clock. │ ├───────────────┼──────────┼────────────────────────────────────────┤ │s1159 │string │String representing before noon e.g."am"│ ├───────────────┼──────────┼────────────────────────────────────────┤ │s2359 │string │String representing after noon e.g."pm" │ ├───────────────┼──────────┼────────────────────────────────────────┤ │sCurrency │string │Currency sign. e.g."$" │ ├───────────────┼──────────┼────────────────────────────────────────┤ │sThousand │string │Thousand separator. e.g."." │ ├───────────────┼──────────┼────────────────────────────────────────┤ │sDecimal │string │Decimal separator. e.g."." │ ├───────────────┼──────────┼────────────────────────────────────────┤ │sDate │string │Date separator. e.g."/" │ ├───────────────┼──────────┼────────────────────────────────────────┤ │sTime │string │Time separator. e.g.":" │ └───────────────┴──────────┴────────────────────────────────────────┘
...
COUNTRYINFO ctryInfo;
/**********************************************************************/
/* Fill out a structure "ctryInfo" with items of country information*/
/* specified in a profile and/or returned from a system call */
/* DosGetCtryInfo. When the same item is available from both */
/* sources, the profile takes the precedence. */
/**********************************************************************/
SHORT InitCtryInfo(void)
{
COUNTRYCODE ctryCode;
ULONG ulCInfLength;
CHAR strBuf[20];
LONG intBuf;
/*------ Initialize variables for a system call --------------*/
ctryCode.country = 0;
ctryCode.codepage = 0;
/*------ System call to get country information ------------*/
DosQueryCtryInfo(sizeof(ctryInfo), &ctryCode, &ctryInfo, &ulCInfLength);
/*------------------------------------------------------------*/
/* Query a profile about a country code, a date format, */
/* a date/time separator, a currecy format/symbol, a decimal */
/* place/charcter, a thousand separator and a data separator,*/
/* and if available, those override DosGetCtryInfo data. */
/*------------------------------------------------------------*/
if (0L != (intBuf=PrfQueryProfileInt(HINI_PROFILE, "PM_National",
"iCountry", 0L )))
ctryInfo.country = (ULONG)intBuf;
if (0L != (intBuf=PrfQueryProfileInt(HINI_PROFILE, "PM_National",
"iDate", 0L)))
ctryInfo.fsDateFmt = (ULONG)intBuf;
if (0L != (intBuf=PrfQueryProfileInt(HINI_PROFILE, "PM_National",
"iCurrency", 0L)))
ctryInfo.fsCurrencyFmt = (UCHAR)((ctryInfo.fsCurrencyFmt && 0x00FE) ||
(intBuf && 0x0001));
if (0L != (intBuf=PrfQueryProfileInt(HINI_PROFILE, "PM_National",
"iDigits", 0L)))
ctryInfo.cDecimalPlace = (UCHAR)intBuf;
PrfQueryProfileString(HINI_PROFILE, "PM_National", "sCurrency",
NULL, strBuf, (ULONG)sizeof(strBuf));
if (strBuf[0] != '\0') strcpy(ctryInfo.szCurrency, strBuf);
PrfQueryProfileString(HINI_PROFILE, "PM_National", "sThousand",
NULL, strBuf, (ULONG)sizeof(strBuf));
if (strBuf[0] != '\0') strcpy(ctryInfo.szThousandsSeparator, strBuf);
PrfQueryProfileString(HINI_PROFILE, "PM_National", "sDecimal",
NULL, strBuf, (ULONG)sizeof(strBuf));
if (strBuf[0] != '\0') strcpy(ctryInfo.szDecimal, strBuf);
PrfQueryProfileString(HINI_PROFILE, "PM_National", "sDate",
NULL, strBuf, (ULONG)sizeof(strBuf));
if (strBuf[0] != '\0') strcpy(ctryInfo.szDateSeparator, strBuf);
PrfQueryProfileString(HINI_PROFILE, "PM_National", "sTime",
NULL, strBuf, (ULONG)sizeof(strBuf));
if (strBuf[0] != '\0') strcpy(ctryInfo.szTimeSeparator, strBuf);
PrfQueryProfileString(HINI_PROFILE, "PM_National", "sList",
NULL, strBuf, (ULONG)sizeof(strBuf));
if (strBuf[0] != '\0') strcpy(ctryInfo.szDataSeparator, strBuf);
return SUCCESS;
}
...
/**********************************************************************/
/* Check the language ID with the current code page */
/**********************************************************************/
USHORT CheckCodepage(CHAR LangID[])
{
USHORT CpList[20], i, c;
ULONG dataLength, CurrentCpList[4];
CHAR strCp[6];
FILE *stream;
/*--- Get CPs available for the Language ID ----------------*/
GetCpList(LangID, CpList);
DosQueryCp(sizeof(CurrentCpList), CurrentCpList, &dataLength);
i=0;
while (CpList[i] != 0) {
if (CpList[i] == (USHORT)CurrentCpList[0])
/*-------- If the current CP matches ------------------*/
return SUCCESS;
i++;
}
/*----------------------------------------------------------*/
/* If the current CP does not match any CPs available */
/* for the Language ID, try to determin Language ID */
/* based on the current code page. */
/* The format of DefCp.TBL is xxxxx,yyy // any comment */
/* where xxxxx is a 5-digit number of code page ID and */
/* yyy is a 3-char string of Language ID */
/*----------------------------------------------------------*/
stream = fopen("DefCp.TBL","r");
while (fscanf(stream, "%5s,", strCp) != EOF) {
if (CurrentCpList[0] == atoi(strCp)) {
fscanf(stream, "%3s", LangID);
fclose(stream);
return SUCCESS;
break;
} else {
while (c = fgetc(stream) != '\n');
}
}
fclose(stream);
return FAIL;
}
/**********************************************************************/
/* Get CPs availabe to a language ID from the "LangCp.TBL" */
/* The format of LangCp.TBL is xxx(aaaaa,bbbbb, .....,ccccc) */
/* where xxx is a 3-char string of a Language ID and */
/* aaaaa, bbbbb,..., ccccc are 5-digit numbers of */
/* code page IDs available to the language ID xxxxx */
/**********************************************************************/
USHORT GetCpList(CHAR LangID[], USHORT CpList[])
{
FILE *stream;
CHAR strCp[6], Lang[4];
USHORT i, c;
stream = fopen("LangCp.TBL","r");
while(fscanf(stream, "%3s", Lang) != EOF) {
if (strcmp(Lang, LangID) == 0) {
i = 0;
while (fgetc(stream) != ')') {
fscanf(stream, "%5s", strCp);
CpList[i] = atoi(strCp);
i++;
}
CpList[i] = 0;
fclose(stream);
return SUCCESS;
}
while (c = fgetc(stream) != '\n');
}
fclose(stream);
return FAIL;
}