OS/2 codes: How to execute a child process in a specific code page
A code page is legacy and is being replaced with a unicode system. Unfortunately, however, OS/2 still use a code page. In addition, it supports maximum 2 code pages only at a time. They are called as primary code page and secondary code page, respectively. Of course, PM programs can more free from a code page, but they are also affected by a code page, so called process code page. In this ariticle, we will find how to control those code pages, especially for child process.
OS/2 provides several APIs for a code page. Out of them, our concern is DosSetProcessCp(). Its systanx is
DosSetProcessCp() changes the current process code page. And the important thing is the changed code page is inherited by a child process.
However, this does not work on Warp 4.5, Warp 4 + FixPak #13 and eComStation. Because they introduced a new feature. That is, [Language] tab in [Properties]. There, you can select a locale and a code page with which you start a program. The code page changed by DosSetProcessCp() is ignored by this setting.
Then, we cannot override this settings ? Yes, we can ! ^^
Warp 4.5 introduced WORKPLACE_PRIMARY_CP environmental variable with introducing [Language] tab. If it is set to 1, then child process are started in a primary code page. If it is set to 0, then chid process are started in a secondary code page. Both these ignore DosSetProcessCp(). Then, What should we do to respect DosSetProcessCp() ? Set it to ?. It means to start a child process in a current process.
As a result, if you want to start a child process in a code page which you want, do like the following.
As I said above, WORKPLACE_PRIMARY_CP ignores DosSetProcessCp(). Therefore, if you just set WORKPLACE_PRIMARY_CP to 1 or 0 without calling DosSetProcessCp(), a child process will be started in a primary code page or a secondary code page, respectively.
For example codes, see
OS/2 provides several APIs for a code page. Out of them, our concern is DosSetProcessCp(). Its systanx is
#define INCL_DOSNLS #include <os2.h> ULONG cp; /* A code page identifier. */ APIRET ulrc; /* Return Code. */ ulrc = DosSetProcessCp(cp);
Reference: http://cyberkinetica.homeunix.net/os2tk45/cp1/1726_L2H_DosSetProcessCpSynta.html
DosSetProcessCp() changes the current process code page. And the important thing is the changed code page is inherited by a child process.
However, this does not work on Warp 4.5, Warp 4 + FixPak #13 and eComStation. Because they introduced a new feature. That is, [Language] tab in [Properties]. There, you can select a locale and a code page with which you start a program. The code page changed by DosSetProcessCp() is ignored by this setting.
Then, we cannot override this settings ? Yes, we can ! ^^
Warp 4.5 introduced WORKPLACE_PRIMARY_CP environmental variable with introducing [Language] tab. If it is set to 1, then child process are started in a primary code page. If it is set to 0, then chid process are started in a secondary code page. Both these ignore DosSetProcessCp(). Then, What should we do to respect DosSetProcessCp() ? Set it to ?. It means to start a child process in a current process.
As a result, if you want to start a child process in a code page which you want, do like the following.
- Check existence of WORKPLACE_PRIMARY_CP
- If exists, set it to ?, else ignore
- Change a code page with DosSetProcessCp()
- Start a child process
As I said above, WORKPLACE_PRIMARY_CP ignores DosSetProcessCp(). Therefore, if you just set WORKPLACE_PRIMARY_CP to 1 or 0 without calling DosSetProcessCp(), a child process will be started in a primary code page or a secondary code page, respectively.
For example codes, see
- https://github.com/komh/os2codes/blob/master/process/setprocesscp.h
- https://github.com/komh/os2codes/blob/master/process/setprocesscp.c
- https://github.com/komh/os2codes/blob/master/process/setprocesscp-test.c
댓글
댓글 쓰기