fixed a few issues in qse_env_t functions on OS2 with Watcom C

This commit is contained in:
hyung-hwan 2011-08-13 10:35:34 +00:00
parent 66fa01b2cf
commit 14572f08aa
5 changed files with 189 additions and 45 deletions

View File

@ -29,7 +29,12 @@
* an environment block.
*/
/*
* Note:
* The wprintf function provided by Watcom C doesn't seem to be able to
* print multibyte-characters properly at least on OS2. You may have
* difficulty if you try to print the environment strings with Watcom C.
*/
#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR)
typedef qse_wchar_t qse_env_char_t;
# define QSE_ENV_CHAR_IS_WCHAR
@ -123,7 +128,6 @@ int qse_env_deletem (
const qse_mchar_t* name
);
int qse_env_insertsysw (
qse_env_t* env,
const qse_wchar_t* name
@ -134,7 +138,6 @@ int qse_env_insertsysm (
const qse_mchar_t* name
);
#if defined(QSE_CHAR_IS_WCHAR)
# define qse_env_insert(env,name,value) qse_env_insertw(env,name,value)
# define qse_env_delete(env,name) qse_env_deletew(env,name)

View File

@ -23,6 +23,8 @@
#include <qse/cmn/str.h>
#include "mem.h"
#include <qse/cmn/stdio.h>
#if defined(_WIN32)
# include <windows.h>
#endif
@ -85,7 +87,7 @@ void qse_env_clear (qse_env_t* env)
{
if (env->str.ptr)
{
#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR)
#if defined(QSE_ENV_CHAR_IS_WCHAR)
env->str.ptr[0] = QSE_WT('\0');
#else
env->str.ptr[0] = QSE_MT('\0');
@ -166,7 +168,7 @@ static int expandstr (qse_env_t* env, qse_size_t inc)
return 0;
}
#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR)
#if defined(QSE_ENV_CHAR_IS_WCHAR)
static int insertw (qse_env_t* env, const qse_wchar_t* name, const qse_wchar_t* value)
{
qse_size_t nl, vl, tl;
@ -329,7 +331,7 @@ static int deletem (qse_env_t* env, const qse_mchar_t* name)
int qse_env_insertw (
qse_env_t* env, const qse_wchar_t* name, const qse_wchar_t* value)
{
#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR)
#if defined(QSE_ENV_CHAR_IS_WCHAR)
/* no conversion -> wchar */
return insertw (env, name, value);
#else
@ -356,7 +358,7 @@ int qse_env_insertw (
int qse_env_insertm (
qse_env_t* env, const qse_mchar_t* name, const qse_mchar_t* value)
{
#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR)
#if defined(QSE_ENV_CHAR_IS_WCHAR)
/* convert mchar to wchar */
qse_wchar_t* namedup, * valuedup;
int n;
@ -383,7 +385,7 @@ int qse_env_insertm (
int qse_env_deletew (qse_env_t* env, const qse_wchar_t* name)
{
#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR)
#if defined(QSE_ENV_CHAR_IS_WCHAR)
return deletew (env, name);
#else
/* convert wchar to mchar */
@ -402,7 +404,7 @@ int qse_env_deletew (qse_env_t* env, const qse_wchar_t* name)
int qse_env_deletem (qse_env_t* env, const qse_mchar_t* name)
{
#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR)
#if defined(QSE_ENV_CHAR_IS_WCHAR)
/* convert mchar to wchar */
qse_wchar_t* namedup;
int n;
@ -444,11 +446,61 @@ static qse_char_t* get_env (qse_env_t* env, const qse_char_t* name, int* free)
return QSE_NULL;
}
#elif defined(QSE_ENV_CHAR_IS_WCHAR)
static qse_wchar_t* get_env (qse_env_t* env, const qse_wchar_t* name, int* free)
{
/*
* This dindn't work with WATCOM C on OS2 because
* _wenviron resolved to NULL.
extern qse_wchar_t** _wenviron;
qse_wchar_t** p = _wenviron;
while (*p)
{
qse_wchar_t* eq;
eq = qse_wcsbeg (*p, name);
if (eq && *eq == QSE_WT('='))
{
*free = 0;
return eq + 1;
}
p++;
}
*/
extern char** environ;
qse_mchar_t** p = environ;
while (*p)
{
qse_wchar_t* dup;
qse_wchar_t* eq;
dup = qse_mbstowcsdup (*p, env->mmgr);
if (dup == QSE_NULL) return QSE_NULL;
eq = qse_wcsbeg (dup, name);
if (eq && *eq == QSE_WT('='))
{
*free = 1;
return eq + 1;
}
QSE_MMGR_FREE (env->mmgr, dup);
p++;
}
return 0;
}
#else
static qse_mchar_t* get_env (qse_env_t* env, const qse_mchar_t* name, int* free)
{
extern char** environ;
char** p = environ;
qse_mchar_t** p = environ;
while (*p)
{
@ -468,7 +520,7 @@ static qse_mchar_t* get_env (qse_env_t* env, const qse_mchar_t* name, int* free)
int qse_env_insertsysw (qse_env_t* env, const qse_wchar_t* name)
{
#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR)
#if defined(QSE_ENV_CHAR_IS_WCHAR)
qse_wchar_t* v;
int free;
int ret = -1;
@ -498,7 +550,7 @@ int qse_env_insertsysw (qse_env_t* env, const qse_wchar_t* name)
int qse_env_insertsysm (qse_env_t* env, const qse_mchar_t* name)
{
#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR)
#if defined(QSE_ENV_CHAR_IS_WCHAR)
/* convert mchar to wchar */
qse_wchar_t* namedup;
int ret = -1;
@ -563,9 +615,44 @@ done:
FreeEnvironmentStrings (envstr);
return ret;
#elif defined(QSE_ENV_CHAR_IS_WCHAR)
/*
* This dindn't work with WATCOM C on OS2 because
* _wenviron resolved to NULL.
*
extern qse_wchar_t** _wenviron;
qse_wchar_t** p = _wenviron;
while (*p)
{
if (add_envstrw (env, *p) <= -1) return -1;
p++;
}
*/
extern char** environ;
qse_mchar_t** p = environ;
while (*p)
{
qse_wchar_t* dup;
int n;
dup = qse_mbstowcsdup (*p, env->mmgr);
if (dup == QSE_NULL) return -1;
n = add_envstrw (env, dup);
QSE_MMGR_FREE (env->mmgr, dup);
if (n <= -1) return -1;
p++;
}
return 0;
#else
extern char** environ;
char** p = environ;
qse_mchar_t** p = environ;
while (*p)
{

View File

@ -1,5 +1,5 @@
/*
* $Id: pio.c 542 2011-08-12 14:39:18Z hyunghwan.chung $
* $Id: pio.c 543 2011-08-12 16:35:34Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -591,7 +591,7 @@ qse_pio_t* qse_pio_init (
QSE_SIZEOF(load_error),
EXEC_ASYNCRESULT,
cmd_line,
NULL,
(env? qse_env_getstr(env): QSE_NULL),
&child_rc,
cmd_file
);

View File

@ -1,4 +1,5 @@
#include <qse/cmn/pio.h>
#include <qse/cmn/env.h>
#include <qse/cmn/stdio.h>
#include <string.h>
@ -9,6 +10,7 @@
#elif defined(__OS2__)
# define INCL_DOSPROCESS
# define INCL_DOSERRORS
# define INCL_DOSDATETIME
# include <os2.h>
#else
# include <unistd.h>
@ -21,7 +23,7 @@
if (f() == -1) return -1; \
} while (0)
static int pio1 (const qse_char_t* cmd, int oflags, qse_pio_hid_t rhid)
static int pio1 (const qse_char_t* cmd, qse_env_t* env, int oflags, qse_pio_hid_t rhid)
{
qse_pio_t* pio;
int x;
@ -30,7 +32,7 @@ static int pio1 (const qse_char_t* cmd, int oflags, qse_pio_hid_t rhid)
QSE_NULL,
0,
cmd,
QSE_NULL,
env,
oflags
);
if (pio == QSE_NULL)
@ -81,7 +83,7 @@ static int pio1 (const qse_char_t* cmd, int oflags, qse_pio_hid_t rhid)
return 0;
}
static int pio2 (const qse_char_t* cmd, int oflags, qse_pio_hid_t rhid)
static int pio2 (const qse_char_t* cmd, qse_env_t* env, int oflags, qse_pio_hid_t rhid)
{
qse_pio_t* pio;
int x;
@ -90,7 +92,7 @@ static int pio2 (const qse_char_t* cmd, int oflags, qse_pio_hid_t rhid)
QSE_NULL,
0,
cmd,
QSE_NULL,
env,
oflags | QSE_PIO_TEXT
);
if (pio == QSE_NULL)
@ -141,11 +143,12 @@ static int test1 (void)
{
return pio1 (
#ifdef _WIN32
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
QSE_T("dir /a"),
#else
QSE_T("ls -laF"),
#endif
QSE_NULL,
QSE_PIO_READOUT|QSE_PIO_WRITEIN|QSE_PIO_SHELL,
QSE_PIO_OUT
);
@ -154,11 +157,12 @@ static int test1 (void)
static int test2 (void)
{
return pio1 (
#ifdef _WIN32
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
QSE_T("dir /a"),
#else
QSE_T("ls -laF"),
#endif
QSE_NULL,
QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN|QSE_PIO_SHELL,
QSE_PIO_ERR
);
@ -167,11 +171,12 @@ static int test2 (void)
static int test3 (void)
{
return pio1 (
#ifdef _WIN32
QSE_T(".\\sll.exe"),
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
QSE_T("tree.com"),
#else
QSE_T("/bin/ls -laF"),
#endif
QSE_NULL,
QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN,
QSE_PIO_ERR
);
@ -180,11 +185,12 @@ static int test3 (void)
static int test4 (void)
{
return pio2 (
#ifdef _WIN32
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
QSE_T("dir /a"),
#else
QSE_T("ls -laF"),
#endif
QSE_NULL,
QSE_PIO_READOUT|QSE_PIO_WRITEIN|QSE_PIO_SHELL,
QSE_PIO_OUT
);
@ -193,11 +199,12 @@ static int test4 (void)
static int test5 (void)
{
return pio2 (
#ifdef _WIN32
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
QSE_T("dir /a"),
#else
QSE_T("ls -laF"),
#endif
QSE_NULL,
QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN|QSE_PIO_SHELL,
QSE_PIO_ERR
);
@ -206,11 +213,12 @@ static int test5 (void)
static int test6 (void)
{
return pio2 (
#ifdef _WIN32
QSE_T(".\\sll.exe"),
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
QSE_T("tree.com"),
#else
QSE_T("/bin/ls -laF"),
#endif
QSE_NULL,
QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN,
QSE_PIO_ERR
);
@ -219,11 +227,12 @@ static int test6 (void)
static int test7 (void)
{
return pio1 (
#ifdef _WIN32
QSE_T(".\\sll.exe"),
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
QSE_T("tree.com"),
#else
QSE_T("/bin/ls -laF"),
#endif
QSE_NULL,
QSE_PIO_READOUT|QSE_PIO_ERRTOOUT|QSE_PIO_WRITEIN,
QSE_PIO_OUT
);
@ -232,11 +241,12 @@ static int test7 (void)
static int test8 (void)
{
return pio1 (
#ifdef _WIN32
QSE_T(".\\sll.exe"),
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
QSE_T("tree.com"),
#else
QSE_T("/bin/ls -laF"),
#endif
QSE_NULL,
QSE_PIO_READOUT|QSE_PIO_WRITEIN|
QSE_PIO_OUTTONUL|QSE_PIO_ERRTONUL|QSE_PIO_INTONUL,
QSE_PIO_OUT
@ -246,11 +256,12 @@ static int test8 (void)
static int test9 (void)
{
return pio1 (
#ifdef _WIN32
(const qse_char_t*)".\\sll.exe",
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
(const qse_char_t*)"tree.com",
#else
(const qse_char_t*)"/bin/ls -laF",
#endif
QSE_NULL,
QSE_PIO_MBSCMD|QSE_PIO_READOUT|QSE_PIO_WRITEIN,
QSE_PIO_OUT
);
@ -259,17 +270,44 @@ static int test9 (void)
static int test10 (void)
{
return pio1 (
#ifdef _WIN32
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
(const qse_char_t*)"dir /a",
#else
(const qse_char_t*)"/bin/ls -laF",
(const qse_char_t*)"ls -laF",
#endif
QSE_NULL,
QSE_PIO_MBSCMD|QSE_PIO_READOUT|QSE_PIO_WRITEIN|QSE_PIO_SHELL,
QSE_PIO_OUT
);
}
static int test11 (void)
{
qse_env_t* env;
int n;
env = qse_env_open (QSE_NULL, 0, 0);
if (env == QSE_NULL) return -1;
qse_env_insertsys (env, QSE_T("PATH"));
qse_env_insert (env, QSE_T("HELLO"), QSE_T("WORLD"));
n = pio1 (
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
QSE_T("set"),
#else
QSE_T("printenv"),
#endif
env,
QSE_PIO_READOUT|QSE_PIO_WRITEIN|QSE_PIO_SHELL,
QSE_PIO_OUT
);
qse_env_close (env);
return n;
}
static int test12 (void)
{
qse_pio_t* pio;
int x;
@ -277,8 +315,8 @@ static int test11 (void)
pio = qse_pio_open (
QSE_NULL,
0,
#if defined(_WIN32) || defined(__OS2__)
QSE_T(".\\sll.exe"),
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
QSE_T("tree.com"),
#else
QSE_T("/bin/ls -laF"),
#endif
@ -303,14 +341,29 @@ static int test11 (void)
#elif defined(__OS2__)
{
int n = 5;
RESULTCODES result;
PID pid;
#error NO IMPLEMENTED YET.
qse_printf (QSE_T("sleeping for %d seconds\n"), n);
DosSleep (n * 1000);
qse_printf (QSE_T("WaitForSingleObject....%d\n"),
(int)WaitForSingleObject (pio->child, 0));
DosWaitChild (DCWA_PROCESS, DCWW_WAIT,..);
/* it doesn't seem to proceed if the pipe is not read out.
* maybe the OS2 pipe buffer is too smally?? */
while (1)
{
qse_mchar_t buf[100];
qse_ssize_t x = qse_pio_read (pio, buf, QSE_SIZEOF(buf), QSE_PIO_OUT);
if (x <= 0) break;
}
qse_printf (QSE_T("DosWaitChild....%d\n"),
(int)DosWaitChild (DCWA_PROCESS, DCWW_WAIT, &result, &pid, pio->child));
}
#elif defined(__DOS__)
#error NOT SUPPORTED
#else
{
int status;
@ -352,6 +405,7 @@ int main ()
R (test9);
R (test10);
R (test11);
R (test12);
return 0;
}

View File

@ -124,8 +124,8 @@ release/os2/cmd/sed/qsesed.tgt
VComponent
29
WRect
2490
120
2470
93
5700
4240
1
@ -135,7 +135,7 @@ WFileName
28
debug/os2/lib/cmn/qsecmn.tgt
0
7
0
31
VComponent
32
@ -280,4 +280,4 @@ WFileName
debug/win32/cmd/awk/qseawk.tgt
0
1
40
28