added more for OS/2

This commit is contained in:
hyung-hwan 2011-03-16 09:20:03 +00:00
parent 3822b48eea
commit 8869368a02
6 changed files with 124 additions and 49 deletions

View File

@ -34,6 +34,7 @@
#if defined(_WIN32) #if defined(_WIN32)
# include <windows.h> # include <windows.h>
#elif defined(__OS2__) #elif defined(__OS2__)
# define INCL_DOSPROCESS
# include <os2.h> # include <os2.h>
#else #else
# include "syscall.h" # include "syscall.h"

View File

@ -1,5 +1,5 @@
/* /*
* $Id: pio.c 397 2011-03-15 03:40:39Z hyunghwan.chung $ * $Id: pio.c 398 2011-03-15 15:20:03Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -26,6 +26,8 @@
# include <windows.h> # include <windows.h>
# include <tchar.h> # include <tchar.h>
#elif defined(__OS2__) #elif defined(__OS2__)
# define INCL_DOSPROCESS
# define INCL_DOSERRORS
# include <os2.h> # include <os2.h>
#else #else
# include "syscall.h" # include "syscall.h"
@ -94,13 +96,15 @@ qse_pio_t* qse_pio_init (
int i, minidx = -1, maxidx = -1; int i, minidx = -1, maxidx = -1;
#ifdef _WIN32 #if defined(_WIN32)
SECURITY_ATTRIBUTES secattr; SECURITY_ATTRIBUTES secattr;
PROCESS_INFORMATION procinfo; PROCESS_INFORMATION procinfo;
STARTUPINFO startup; STARTUPINFO startup;
qse_char_t* dup = QSE_NULL; qse_char_t* dup = QSE_NULL;
HANDLE windevnul = INVALID_HANDLE_VALUE; HANDLE windevnul = INVALID_HANDLE_VALUE;
BOOL x; BOOL x;
#elif defined(__OS2__)
/* TODO: implmenet this for os/2 */
#else #else
qse_pio_pid_t pid; qse_pio_pid_t pid;
#endif #endif
@ -184,9 +188,9 @@ qse_pio_t* qse_pio_init (
startup.hStdOutput = INVALID_HANDLE_VALUE; startup.hStdOutput = INVALID_HANDLE_VALUE;
*/ */
startup.hStdInput = GetStdHandle (STD_INPUT_HANDLE); startup.hStdInput = GetStdHandle (STD_INPUT_HANDLE);
startup.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE); startup.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE);
startup.hStdOutput = GetStdHandle (STD_ERROR_HANDLE); startup.hStdOutput = GetStdHandle (STD_ERROR_HANDLE);
if (startup.hStdInput == INVALID_HANDLE_VALUE || if (startup.hStdInput == INVALID_HANDLE_VALUE ||
startup.hStdOutput == INVALID_HANDLE_VALUE || startup.hStdOutput == INVALID_HANDLE_VALUE ||
@ -269,7 +273,9 @@ qse_pio_t* qse_pio_init (
} }
CloseHandle (procinfo.hThread); CloseHandle (procinfo.hThread);
pio->child = procinfo.hProcess; pio->child = procinfo.hProcess;
#elif defined(__OS2__)
/* TODO: implement this for OS/2 */
#else #else
if (oflags & QSE_PIO_WRITEIN) if (oflags & QSE_PIO_WRITEIN)
@ -602,8 +608,11 @@ oops:
{ {
if (tio[i] != QSE_NULL) qse_tio_close (tio[i]); if (tio[i] != QSE_NULL) qse_tio_close (tio[i]);
} }
#ifdef _WIN32 #if defined(_WIN32)
for (i = minidx; i < maxidx; i++) CloseHandle (handle[i]); for (i = minidx; i < maxidx; i++) CloseHandle (handle[i]);
#elif defined(__OS2__)
/* TODO: */
for (i = minidx; i < maxidx; i++) DosClose (handle[i]);
#else #else
for (i = minidx; i < maxidx; i++) QSE_CLOSE (handle[i]); for (i = minidx; i < maxidx; i++) QSE_CLOSE (handle[i]);
#endif #endif
@ -668,8 +677,11 @@ qse_pio_pid_t qse_pio_getchild (qse_pio_t* pio)
static qse_ssize_t pio_read ( static qse_ssize_t pio_read (
qse_pio_t* pio, void* buf, qse_size_t size, qse_pio_hnd_t hnd) qse_pio_t* pio, void* buf, qse_size_t size, qse_pio_hnd_t hnd)
{ {
#ifdef _WIN32 #if defined(_WIN32)
DWORD count; DWORD count;
#elif defined(__OS2__)
ULONG count;
APIRET rc;
#else #else
qse_ssize_t n; qse_ssize_t n;
#endif #endif
@ -681,9 +693,9 @@ static qse_ssize_t pio_read (
return (qse_ssize_t)-1; return (qse_ssize_t)-1;
} }
#ifdef _WIN32 #if defined(_WIN32)
if (size > QSE_TYPE_MAX(DWORD)) size = QSE_TYPE_MAX(DWORD); if (size > QSE_TYPE_MAX(DWORD)) size = QSE_TYPE_MAX(DWORD);
if (ReadFile(hnd, buf, size, &count, QSE_NULL) == FALSE) if (ReadFile(hnd, buf, (DWORD)size, &count, QSE_NULL) == FALSE)
{ {
/* ReadFile receives ERROR_BROKEN_PIPE when the write end /* ReadFile receives ERROR_BROKEN_PIPE when the write end
* is closed in the child process */ * is closed in the child process */
@ -691,6 +703,16 @@ static qse_ssize_t pio_read (
pio->errnum = QSE_PIO_ESUBSYS; pio->errnum = QSE_PIO_ESUBSYS;
return -1; return -1;
} }
return (qse_ssize_t)count;
#elif defined(__OS2__)
if (size > QSE_TYPE_MAX(ULONG)) size = QSE_TYPE_MAX(ULONG);
rc = DosRead (hnd, buf, (ULONG)size, &count);
if (rc != NO_ERROR)
{
if (rc == ERROR_BROKEN_PIPE) return 0; /* TODO: check this */
pio->errnum = QSE_PIO_ESUBSYS;
return -1;
}
return (qse_ssize_t)count; return (qse_ssize_t)count;
#else #else
@ -732,8 +754,11 @@ qse_ssize_t qse_pio_read (
static qse_ssize_t pio_write ( static qse_ssize_t pio_write (
qse_pio_t* pio, const void* data, qse_size_t size, qse_pio_hnd_t hnd) qse_pio_t* pio, const void* data, qse_size_t size, qse_pio_hnd_t hnd)
{ {
#ifdef _WIN32 #if defined(_WIN32)
DWORD count; DWORD count;
#elif defined(__OS2__)
ULONG count;
APIRET rc;
#else #else
qse_ssize_t n; qse_ssize_t n;
#endif #endif
@ -745,15 +770,26 @@ static qse_ssize_t pio_write (
return (qse_ssize_t)-1; return (qse_ssize_t)-1;
} }
#ifdef _WIN32 #if defined(_WIN32)
if (size > QSE_TYPE_MAX(DWORD)) size = QSE_TYPE_MAX(DWORD); if (size > QSE_TYPE_MAX(DWORD)) size = QSE_TYPE_MAX(DWORD);
if (WriteFile (hnd, data, size, &count, QSE_NULL) == FALSE) if (WriteFile (hnd, data, (DWORD)size, &count, QSE_NULL) == FALSE)
{ {
pio->errnum = (GetLastError() == ERROR_BROKEN_PIPE)? pio->errnum = (GetLastError() == ERROR_BROKEN_PIPE)?
QSE_PIO_EPIPE: QSE_PIO_ESUBSYS; QSE_PIO_EPIPE: QSE_PIO_ESUBSYS;
return -1; return -1;
} }
return (qse_ssize_t)count; return (qse_ssize_t)count;
#elif defined(__OS2__)
if (size > QSE_TYPE_MAX(ULONG)) size = QSE_TYPE_MAX(ULONG);
rc = DosWrite (hnd, (PVOID)data, (ULONG)size, &count);
if (rc != NO_ERROR)
{
pio->errnum = (rc == ERROR_BROKEN_PIPE)?
QSE_PIO_EPIPE: QSE_PIO_ESUBSYS; /* TODO: check this */
return -1;
}
return (qse_ssize_t)count;
#else #else
if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t); if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t);
@ -806,8 +842,10 @@ void qse_pio_end (qse_pio_t* pio, qse_pio_hid_t hid)
if (pio->pin[hid].handle != QSE_PIO_HND_NIL) if (pio->pin[hid].handle != QSE_PIO_HND_NIL)
{ {
#ifdef _WIN32 #if defined(_WIN32)
CloseHandle (pio->pin[hid].handle); CloseHandle (pio->pin[hid].handle);
#elif defined(__OS2__)
DosClose (pio->pin[hid].handle);
#else #else
QSE_CLOSE (pio->pin[hid].handle); QSE_CLOSE (pio->pin[hid].handle);
#endif #endif
@ -817,7 +855,7 @@ void qse_pio_end (qse_pio_t* pio, qse_pio_hid_t hid)
int qse_pio_wait (qse_pio_t* pio) int qse_pio_wait (qse_pio_t* pio)
{ {
#ifdef _WIN32 #if defined(_WIN32)
DWORD ecode, w; DWORD ecode, w;
if (pio->child == QSE_PIO_PID_NIL) if (pio->child == QSE_PIO_PID_NIL)
@ -868,7 +906,10 @@ int qse_pio_wait (qse_pio_t* pio)
return -1; return -1;
} }
return ecode; return ecode;
#elif defined(__OS2__)
/* TODO: implement this */
return -1;
#else #else
int opt = 0; int opt = 0;
int ret = -1; int ret = -1;
@ -948,8 +989,10 @@ int qse_pio_wait (qse_pio_t* pio)
int qse_pio_kill (qse_pio_t* pio) int qse_pio_kill (qse_pio_t* pio)
{ {
#ifdef _WIN32 #if defined(_WIN32)
DWORD n; DWORD n;
#elif defined(__OS2__)
APIRET n;
#else #else
int n; int n;
#endif #endif
@ -960,7 +1003,7 @@ int qse_pio_kill (qse_pio_t* pio)
return -1; return -1;
} }
#ifdef _WIN32 #if defined(_WIN32)
/* 9 was chosen below to treat TerminateProcess as kill -KILL. */ /* 9 was chosen below to treat TerminateProcess as kill -KILL. */
n = TerminateProcess (pio->child, 255 + 1 + 9); n = TerminateProcess (pio->child, 255 + 1 + 9);
if (n == FALSE) if (n == FALSE)
@ -968,7 +1011,17 @@ int qse_pio_kill (qse_pio_t* pio)
pio->errnum = QSE_PIO_ESUBSYS; pio->errnum = QSE_PIO_ESUBSYS;
return -1; return -1;
} }
return 0; return 0;
#elif defined(__OS2__)
/*TODO: must use DKP_PROCESSTREE? */
n = DosKillProcess (pio->child, DKP_PROCESS);
if (n != NO_ERROR)
{
pio->errnum = QSE_PIO_ESUBSYS;
return -1;
}
return 0;
#else #else
n = QSE_KILL (pio->child, SIGKILL); n = QSE_KILL (pio->child, SIGKILL);
if (n <= -1) pio->errnum = QSE_PIO_ESUBSYS; if (n <= -1) pio->errnum = QSE_PIO_ESUBSYS;
@ -978,9 +1031,9 @@ int qse_pio_kill (qse_pio_t* pio)
static qse_ssize_t pio_input (int cmd, void* arg, void* buf, qse_size_t size) static qse_ssize_t pio_input (int cmd, void* arg, void* buf, qse_size_t size)
{ {
qse_pio_pin_t* pin = (qse_pio_pin_t*)arg; qse_pio_pin_t* pin = (qse_pio_pin_t*)arg;
QSE_ASSERT (pin != QSE_NULL); QSE_ASSERT (pin != QSE_NULL);
if (cmd == QSE_TIO_IO_DATA) if (cmd == QSE_TIO_IO_DATA)
{ {
QSE_ASSERT (pin->self != QSE_NULL); QSE_ASSERT (pin->self != QSE_NULL);
return pio_read (pin->self, buf, size, pin->handle); return pio_read (pin->self, buf, size, pin->handle);
@ -993,9 +1046,9 @@ static qse_ssize_t pio_input (int cmd, void* arg, void* buf, qse_size_t size)
static qse_ssize_t pio_output (int cmd, void* arg, void* buf, qse_size_t size) static qse_ssize_t pio_output (int cmd, void* arg, void* buf, qse_size_t size)
{ {
qse_pio_pin_t* pin = (qse_pio_pin_t*)arg; qse_pio_pin_t* pin = (qse_pio_pin_t*)arg;
QSE_ASSERT (pin != QSE_NULL); QSE_ASSERT (pin != QSE_NULL);
if (cmd == QSE_TIO_IO_DATA) if (cmd == QSE_TIO_IO_DATA)
{ {
QSE_ASSERT (pin->self != QSE_NULL); QSE_ASSERT (pin->self != QSE_NULL);
return pio_write (pin->self, buf, size, pin->handle); return pio_write (pin->self, buf, size, pin->handle);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: rex.c 368 2010-11-03 14:24:29Z hyunghwan.chung $ * $Id: rex.c 398 2011-03-15 15:20:03Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -887,7 +887,15 @@ static qse_rex_node_t* comp_atom (comp_t* com)
default: default:
if (com->rex->option & QSE_REX_STRICT) if (com->rex->option & QSE_REX_STRICT)
{ {
qse_char_t spc[] = QSE_T(")?*+{"); qse_char_t spc[] =
{
QSE_T(')'),
QSE_T('?'),
QSE_T('*'),
QSE_T('+'),
QSE_T('{'),
QSE_T('\0')
};
if (com->rex->option & QSE_REX_NOBOUND) if (com->rex->option & QSE_REX_NOBOUND)
spc[4] = QSE_T('\0'); spc[4] = QSE_T('\0');

View File

@ -360,10 +360,14 @@ QSE_FILE* qse_fopen (const qse_char_t* path, const qse_char_t* mode)
} }
QSE_FILE* qse_popen (const qse_char_t* cmd, const qse_char_t* mode) QSE_FILE* qse_popen (const qse_char_t* cmd, const qse_char_t* mode)
{ {
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
return popen (cmd, mode); #if defined(__OS2__)
#elif defined(_WIN32) return _popen (cmd, mode);
#else
return popen (cmd, mode);
#endif
#elif defined(_WIN32) || defined(__OS2__)
return _wpopen (cmd, mode); return _wpopen (cmd, mode);
#else #else
char cmd_mb[PATH_MAX + 1]; char cmd_mb[PATH_MAX + 1];

View File

@ -1,5 +1,5 @@
/* /*
* $Id: time.c 287 2009-09-15 10:01:02Z hyunghwan.chung $ * $Id: time.c 398 2011-03-15 15:20:03Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -21,8 +21,10 @@
#include <qse/cmn/time.h> #include <qse/cmn/time.h>
#include "mem.h" #include "mem.h"
#ifdef _WIN32 #if defined(_WIN32)
# include <windows.h> # include <windows.h>
#elif defined(__OS2__)
# include <os2.h>
#else #else
# include "syscall.h" # include "syscall.h"
# include <sys/time.h> # include <sys/time.h>
@ -73,7 +75,7 @@ static int get_leap_days (int fy, int ty)
int qse_gettime (qse_ntime_t* t) int qse_gettime (qse_ntime_t* t)
{ {
#ifdef _WIN32 #if defined(_WIN32)
SYSTEMTIME st; SYSTEMTIME st;
FILETIME ft; FILETIME ft;
@ -86,7 +88,10 @@ int qse_gettime (qse_ntime_t* t)
if (SystemTimeToFileTime (&st, &ft) == FALSE) return -1; if (SystemTimeToFileTime (&st, &ft) == FALSE) return -1;
*t = ((qse_ntime_t)(*((qse_int64_t*)&ft)) / (10 * 1000)); *t = ((qse_ntime_t)(*((qse_int64_t*)&ft)) / (10 * 1000));
*t -= EPOCH_DIFF_MSECS; *t -= EPOCH_DIFF_MSECS;
return 0; return 0;
#elif defined(__OS2__)
/* TODO: implement this */
return -1;
#else #else
struct timeval tv; struct timeval tv;
int n; int n;
@ -102,14 +107,17 @@ int qse_gettime (qse_ntime_t* t)
int qse_settime (qse_ntime_t t) int qse_settime (qse_ntime_t t)
{ {
#ifdef _WIN32 #if defined(_WIN32)
FILETIME ft; FILETIME ft;
SYSTEMTIME st; SYSTEMTIME st;
*((qse_int64_t*)&ft) = ((t + EPOCH_DIFF_MSECS) * (10 * 1000)); *((qse_int64_t*)&ft) = ((t + EPOCH_DIFF_MSECS) * (10 * 1000));
if (FileTimeToSystemTime (&ft, &st) == FALSE) return -1; if (FileTimeToSystemTime (&ft, &st) == FALSE) return -1;
if (SetSystemTime(&st) == FALSE) return -1; if (SetSystemTime(&st) == FALSE) return -1;
return 0; return 0;
#elif defined(__OS2__)
/* TODO: implement this */
return -1;
#else #else
struct timeval tv; struct timeval tv;
int n; int n;
@ -215,8 +223,9 @@ int qse_localtime (qse_ntime_t nt, qse_btime_t* bt)
qse_ntime_t rem = nt % QSE_MSECS_PER_SEC; qse_ntime_t rem = nt % QSE_MSECS_PER_SEC;
/* TODO: remove dependency on localtime/localtime_r */ /* TODO: remove dependency on localtime/localtime_r */
#ifdef _WIN32 #if defined(_WIN32)
tm = localtime (&t); tm = localtime (&t);
#elif defined(__OS2__)
#else #else
struct tm btm; struct tm btm;
tm = localtime_r (&t, &btm); tm = localtime_r (&t, &btm);

View File

@ -766,10 +766,10 @@ void qse_xma_dump (qse_xma_t* xma, qse_xma_dumper_t dumper, void* target)
dumper (target, QSE_T("Total : %18llu bytes\n"), (unsigned long long)(asum + fsum + isum)); dumper (target, QSE_T("Total : %18llu bytes\n"), (unsigned long long)(asum + fsum + isum));
#endif #endif
#endif #endif
#ifdef QSE_XMA_ENABLE_STAT
QSE_ASSERT (asum == xma->stat.alloc); QSE_ASSERT (asum == xma->stat.alloc);
QSE_ASSERT (fsum == xma->stat.avail); QSE_ASSERT (fsum == xma->stat.avail);
#ifdef QSE_XMA_ENABLE_STAT
QSE_ASSERT (isum == xma->stat.total - (xma->stat.alloc + xma->stat.avail)); QSE_ASSERT (isum == xma->stat.total - (xma->stat.alloc + xma->stat.avail));
QSE_ASSERT (asum + fsum + isum == xma->stat.total); QSE_ASSERT (asum + fsum + isum == xma->stat.total);
#endif #endif