From 8869368a02273fbfeaa3ff4a7c53547ec82b694d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 16 Mar 2011 09:20:03 +0000 Subject: [PATCH] added more for OS/2 --- qse/lib/cmn/assert.c | 1 + qse/lib/cmn/pio.c | 117 +++++++++++++++++++++++++++++++------------ qse/lib/cmn/rex.c | 12 ++++- qse/lib/cmn/stdio.c | 12 +++-- qse/lib/cmn/time.c | 27 ++++++---- qse/lib/cmn/xma.c | 4 +- 6 files changed, 124 insertions(+), 49 deletions(-) diff --git a/qse/lib/cmn/assert.c b/qse/lib/cmn/assert.c index 9131e2a5..0f503a89 100644 --- a/qse/lib/cmn/assert.c +++ b/qse/lib/cmn/assert.c @@ -34,6 +34,7 @@ #if defined(_WIN32) # include #elif defined(__OS2__) +# define INCL_DOSPROCESS # include #else # include "syscall.h" diff --git a/qse/lib/cmn/pio.c b/qse/lib/cmn/pio.c index 98625844..4337c0e6 100644 --- a/qse/lib/cmn/pio.c +++ b/qse/lib/cmn/pio.c @@ -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. This file is part of QSE. @@ -26,6 +26,8 @@ # include # include #elif defined(__OS2__) +# define INCL_DOSPROCESS +# define INCL_DOSERRORS # include #else # include "syscall.h" @@ -94,13 +96,15 @@ qse_pio_t* qse_pio_init ( int i, minidx = -1, maxidx = -1; -#ifdef _WIN32 +#if defined(_WIN32) SECURITY_ATTRIBUTES secattr; PROCESS_INFORMATION procinfo; STARTUPINFO startup; qse_char_t* dup = QSE_NULL; HANDLE windevnul = INVALID_HANDLE_VALUE; - BOOL x; + BOOL x; +#elif defined(__OS2__) + /* TODO: implmenet this for os/2 */ #else qse_pio_pid_t pid; #endif @@ -184,9 +188,9 @@ qse_pio_t* qse_pio_init ( startup.hStdOutput = INVALID_HANDLE_VALUE; */ - startup.hStdInput = GetStdHandle (STD_INPUT_HANDLE); - startup.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE); - startup.hStdOutput = GetStdHandle (STD_ERROR_HANDLE); + startup.hStdInput = GetStdHandle (STD_INPUT_HANDLE); + startup.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE); + startup.hStdOutput = GetStdHandle (STD_ERROR_HANDLE); if (startup.hStdInput == INVALID_HANDLE_VALUE || startup.hStdOutput == INVALID_HANDLE_VALUE || @@ -269,7 +273,9 @@ qse_pio_t* qse_pio_init ( } CloseHandle (procinfo.hThread); - pio->child = procinfo.hProcess; + pio->child = procinfo.hProcess; +#elif defined(__OS2__) + /* TODO: implement this for OS/2 */ #else if (oflags & QSE_PIO_WRITEIN) @@ -602,8 +608,11 @@ oops: { if (tio[i] != QSE_NULL) qse_tio_close (tio[i]); } -#ifdef _WIN32 - for (i = minidx; i < maxidx; i++) CloseHandle (handle[i]); +#if defined(_WIN32) + for (i = minidx; i < maxidx; i++) CloseHandle (handle[i]); +#elif defined(__OS2__) + /* TODO: */ + for (i = minidx; i < maxidx; i++) DosClose (handle[i]); #else for (i = minidx; i < maxidx; i++) QSE_CLOSE (handle[i]); #endif @@ -668,8 +677,11 @@ qse_pio_pid_t qse_pio_getchild (qse_pio_t* pio) static qse_ssize_t pio_read ( qse_pio_t* pio, void* buf, qse_size_t size, qse_pio_hnd_t hnd) { -#ifdef _WIN32 - DWORD count; +#if defined(_WIN32) + DWORD count; +#elif defined(__OS2__) + ULONG count; + APIRET rc; #else qse_ssize_t n; #endif @@ -681,9 +693,9 @@ static qse_ssize_t pio_read ( return (qse_ssize_t)-1; } -#ifdef _WIN32 +#if defined(_WIN32) 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 * is closed in the child process */ @@ -691,6 +703,16 @@ static qse_ssize_t pio_read ( pio->errnum = QSE_PIO_ESUBSYS; 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; #else @@ -732,8 +754,11 @@ qse_ssize_t qse_pio_read ( static qse_ssize_t pio_write ( qse_pio_t* pio, const void* data, qse_size_t size, qse_pio_hnd_t hnd) { -#ifdef _WIN32 - DWORD count; +#if defined(_WIN32) + DWORD count; +#elif defined(__OS2__) + ULONG count; + APIRET rc; #else qse_ssize_t n; #endif @@ -745,15 +770,26 @@ static qse_ssize_t pio_write ( return (qse_ssize_t)-1; } -#ifdef _WIN32 +#if defined(_WIN32) 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)? QSE_PIO_EPIPE: QSE_PIO_ESUBSYS; 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 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) { -#ifdef _WIN32 - CloseHandle (pio->pin[hid].handle); +#if defined(_WIN32) + CloseHandle (pio->pin[hid].handle); +#elif defined(__OS2__) + DosClose (pio->pin[hid].handle); #else QSE_CLOSE (pio->pin[hid].handle); #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) { -#ifdef _WIN32 +#if defined(_WIN32) DWORD ecode, w; if (pio->child == QSE_PIO_PID_NIL) @@ -868,7 +906,10 @@ int qse_pio_wait (qse_pio_t* pio) return -1; } - return ecode; + return ecode; +#elif defined(__OS2__) + /* TODO: implement this */ + return -1; #else int opt = 0; int ret = -1; @@ -948,8 +989,10 @@ int qse_pio_wait (qse_pio_t* pio) int qse_pio_kill (qse_pio_t* pio) { -#ifdef _WIN32 - DWORD n; +#if defined(_WIN32) + DWORD n; +#elif defined(__OS2__) + APIRET n; #else int n; #endif @@ -960,7 +1003,7 @@ int qse_pio_kill (qse_pio_t* pio) return -1; } -#ifdef _WIN32 +#if defined(_WIN32) /* 9 was chosen below to treat TerminateProcess as kill -KILL. */ n = TerminateProcess (pio->child, 255 + 1 + 9); if (n == FALSE) @@ -968,7 +1011,17 @@ int qse_pio_kill (qse_pio_t* pio) pio->errnum = QSE_PIO_ESUBSYS; 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 n = QSE_KILL (pio->child, SIGKILL); 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) { - qse_pio_pin_t* pin = (qse_pio_pin_t*)arg; - QSE_ASSERT (pin != QSE_NULL); - if (cmd == QSE_TIO_IO_DATA) + qse_pio_pin_t* pin = (qse_pio_pin_t*)arg; + QSE_ASSERT (pin != QSE_NULL); + if (cmd == QSE_TIO_IO_DATA) { QSE_ASSERT (pin->self != QSE_NULL); 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) { - qse_pio_pin_t* pin = (qse_pio_pin_t*)arg; - QSE_ASSERT (pin != QSE_NULL); - if (cmd == QSE_TIO_IO_DATA) + qse_pio_pin_t* pin = (qse_pio_pin_t*)arg; + QSE_ASSERT (pin != QSE_NULL); + if (cmd == QSE_TIO_IO_DATA) { QSE_ASSERT (pin->self != QSE_NULL); return pio_write (pin->self, buf, size, pin->handle); diff --git a/qse/lib/cmn/rex.c b/qse/lib/cmn/rex.c index 24b7d1b2..babebfbd 100644 --- a/qse/lib/cmn/rex.c +++ b/qse/lib/cmn/rex.c @@ -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. This file is part of QSE. @@ -887,7 +887,15 @@ static qse_rex_node_t* comp_atom (comp_t* com) default: 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) spc[4] = QSE_T('\0'); diff --git a/qse/lib/cmn/stdio.c b/qse/lib/cmn/stdio.c index 84998433..e013bfb7 100644 --- a/qse/lib/cmn/stdio.c +++ b/qse/lib/cmn/stdio.c @@ -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) -{ -#if defined(QSE_CHAR_IS_MCHAR) - return popen (cmd, mode); -#elif defined(_WIN32) +{ +#if defined(QSE_CHAR_IS_MCHAR) +#if defined(__OS2__) + return _popen (cmd, mode); +#else + return popen (cmd, mode); +#endif +#elif defined(_WIN32) || defined(__OS2__) return _wpopen (cmd, mode); #else char cmd_mb[PATH_MAX + 1]; diff --git a/qse/lib/cmn/time.c b/qse/lib/cmn/time.c index 12b8b27a..f1657a1a 100644 --- a/qse/lib/cmn/time.c +++ b/qse/lib/cmn/time.c @@ -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. This file is part of QSE. @@ -21,8 +21,10 @@ #include #include "mem.h" -#ifdef _WIN32 -# include +#if defined(_WIN32) +# include +#elif defined(__OS2__) +# include #else # include "syscall.h" # include @@ -73,7 +75,7 @@ static int get_leap_days (int fy, int ty) int qse_gettime (qse_ntime_t* t) { -#ifdef _WIN32 +#if defined(_WIN32) SYSTEMTIME st; FILETIME ft; @@ -86,7 +88,10 @@ int qse_gettime (qse_ntime_t* t) if (SystemTimeToFileTime (&st, &ft) == FALSE) return -1; *t = ((qse_ntime_t)(*((qse_int64_t*)&ft)) / (10 * 1000)); *t -= EPOCH_DIFF_MSECS; - return 0; + return 0; +#elif defined(__OS2__) + /* TODO: implement this */ + return -1; #else struct timeval tv; int n; @@ -102,14 +107,17 @@ int qse_gettime (qse_ntime_t* t) int qse_settime (qse_ntime_t t) { -#ifdef _WIN32 +#if defined(_WIN32) FILETIME ft; SYSTEMTIME st; *((qse_int64_t*)&ft) = ((t + EPOCH_DIFF_MSECS) * (10 * 1000)); if (FileTimeToSystemTime (&ft, &st) == FALSE) return -1; if (SetSystemTime(&st) == FALSE) return -1; - return 0; + return 0; +#elif defined(__OS2__) + /* TODO: implement this */ + return -1; #else struct timeval tv; 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; /* TODO: remove dependency on localtime/localtime_r */ -#ifdef _WIN32 - tm = localtime (&t); +#if defined(_WIN32) + tm = localtime (&t); +#elif defined(__OS2__) #else struct tm btm; tm = localtime_r (&t, &btm); diff --git a/qse/lib/cmn/xma.c b/qse/lib/cmn/xma.c index dfc7e74d..a281c682 100644 --- a/qse/lib/cmn/xma.c +++ b/qse/lib/cmn/xma.c @@ -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)); #endif #endif - + +#ifdef QSE_XMA_ENABLE_STAT QSE_ASSERT (asum == xma->stat.alloc); 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 (asum + fsum + isum == xma->stat.total); #endif