enhanced pio for WIN32

This commit is contained in:
2009-07-24 07:01:52 +00:00
parent 704e1c2ac7
commit 9fabea2cd2
6 changed files with 195 additions and 86 deletions

View File

@ -34,27 +34,32 @@ static int pio1 (const qse_char_t* cmd, int oflags, qse_pio_hid_t rhid)
while (1)
{
qse_byte_t buf[128];
qse_ssize_t i;
/*qse_pio_canread (pio, QSE_PIO_ERR, 1000)*/
qse_ssize_t n = qse_pio_read (pio, buf, sizeof(buf), rhid);
if (n == 0) break;
if (n < 0)
if (n <= -1)
{
qse_printf (QSE_T("qse_pio_read() returned error - %s\n"), qse_pio_geterrmsg(pio));
break;
}
qse_printf (QSE_T("N===> %d\n"), (int)n);
qse_printf (QSE_T("N===> %d buf => ["), (int)n);
for (i = 0; i < n; i++)
{
#ifdef QSE_CHAR_IS_MCHAR
qse_printf (QSE_T("buf => [%.*s]\n"), (int)n, buf);
qse_printf (QSE_T("%c"), buf[i]);
#else
qse_printf (QSE_T("buf => [%.*S]\n"), (int)n, buf);
qse_printf (QSE_T("%C"), buf[i]);
#endif
}
qse_printf (QSE_T("]\n"));
}
x = qse_pio_wait (pio);
qse_printf (QSE_T("qse_pio_wait returns %d\n"), x);
if (x == -1)
if (x <= -1)
{
qse_printf (QSE_T("error code : %d, error string: %s\n"), (int)qse_pio_geterrnum(pio), qse_pio_geterrmsg(pio));
}
@ -84,6 +89,7 @@ static int pio2 (const qse_char_t* cmd, int oflags, qse_pio_hid_t rhid)
while (1)
{
qse_char_t buf[128];
qse_ssize_t i;
qse_ssize_t n = qse_pio_read (pio, buf, QSE_COUNTOF(buf), rhid);
if (n == 0) break;
@ -93,13 +99,17 @@ static int pio2 (const qse_char_t* cmd, int oflags, qse_pio_hid_t rhid)
break;
}
qse_printf (QSE_T("N===> %d\n"), (int)n);
qse_printf (QSE_T("buf => [%.*s]\n"), (int)n, buf);
qse_printf (QSE_T("N===> %d buf => ["), (int)n);
for (i = 0; i < n; i++)
{
qse_printf (QSE_T("%c"), buf[i]);
}
qse_printf (QSE_T("]\n"));
}
x = qse_pio_wait (pio);
qse_printf (QSE_T("qse_pio_wait returns %d\n"), x);
if (x == -1)
if (x <= -1)
{
qse_printf (QSE_T("error code : %d, error string: %s\n"), (int)qse_pio_geterrnum(pio), qse_pio_geterrmsg(pio));
}
@ -115,7 +125,7 @@ static int test1 (void)
return pio1 (
#ifdef _WIN32
QSE_T("lda.exe"),
QSE_T("sll.exe"),
#else
QSE_T("ls -laF"),
#endif
@ -128,7 +138,7 @@ static int test2 (void)
{
return pio1 (
#ifdef _WIN32
QSE_T("lda.exe"),
QSE_T("sll.exe"),
#else
QSE_T("ls -laF"),
#endif
@ -139,67 +149,84 @@ static int test2 (void)
static int test3 (void)
{
return pio1 (QSE_T("/bin/ls -laF"), QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN, QSE_PIO_ERR);
return pio1 (
#ifdef _WIN32
QSE_T(".\\sll.exe"),
#else
QSE_T("/bin/ls -laF"),
#endif
QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN,
QSE_PIO_ERR
);
}
static int test4 (void)
{
return pio2 (QSE_T("ls -laF"), QSE_PIO_READOUT|QSE_PIO_WRITEIN|QSE_PIO_SHELL, QSE_PIO_OUT);
return pio2 (
#ifdef _WIN32
QSE_T("sll.exe"),
#else
QSE_T("ls -laF"),
#endif
QSE_PIO_READOUT|QSE_PIO_WRITEIN|QSE_PIO_SHELL,
QSE_PIO_OUT
);
}
static int test5 (void)
{
return pio2 (QSE_T("ls -laF"), QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN|QSE_PIO_SHELL, QSE_PIO_ERR);
return pio2 (
#ifdef _WIN32
QSE_T("sll.exe"),
#else
QSE_T("ls -laF"),
#endif
QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN|QSE_PIO_SHELL,
QSE_PIO_ERR
);
}
static int test6 (void)
{
return pio2 (QSE_T("/bin/ls -laF"), QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN, QSE_PIO_ERR);
return pio2 (
#ifdef _WIN32
QSE_T(".\\sll.exe"),
#else
QSE_T("/bin/ls -laF"),
#endif
QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN,
QSE_PIO_ERR
);
}
static int test7 (void)
{
qse_pio_t* pio;
int x;
pio = qse_pio_open (
QSE_NULL,
0,
QSE_T("/bin/ls -laF"),
QSE_PIO_READOUT|QSE_PIO_ERRTOOUT|QSE_PIO_WRITEIN
return pio1 (
#ifdef _WIN32
QSE_T(".\\sll.exe"),
#else
QSE_T("/bin/ls -laF"),
#endif
QSE_PIO_READOUT|QSE_PIO_ERRTOOUT|QSE_PIO_WRITEIN,
QSE_PIO_OUT
);
if (pio == QSE_NULL)
{
qse_printf (QSE_T("cannot open program through pipe\n"));
return -1;
}
while (1)
{
qse_byte_t buf[128];
/*qse_pio_canread (pio, QSE_PIO_ERR, 1000)*/
qse_ssize_t n = qse_pio_read (pio, buf, sizeof(buf), QSE_PIO_OUT);
if (n == 0) break;
if (n < 0)
{
qse_printf (QSE_T("qse_pio_read() returned error - %s\n"), qse_pio_geterrmsg(pio));
break;
}
}
x = qse_pio_wait (pio);
qse_printf (QSE_T("qse_pio_wait returns %d\n"), x);
if (x == -1)
{
qse_printf (QSE_T("error code : %d, error string: %s\n"), (int)QSE_PIO_ERRNUM(pio), qse_pio_geterrmsg(pio));
}
qse_pio_close (pio);
return 0;
}
static int test8 (void)
{
return pio1 (
#ifdef _WIN32
QSE_T("sll.exe"),
#else
QSE_T("ls -laF"),
#endif
QSE_PIO_READOUT|QSE_PIO_WRITEIN|
QSE_PIO_OUTTONUL|QSE_PIO_ERRTONUL|QSE_PIO_INTONUL,
QSE_PIO_OUT
);
}
static int test9 (void)
{
qse_pio_t* pio;
int x;
@ -207,7 +234,11 @@ static int test8 (void)
pio = qse_pio_open (
QSE_NULL,
0,
#ifdef _WIN32
QSE_T(".\\sll.exe"),
#else
QSE_T("/bin/ls -laF"),
#endif
QSE_PIO_READOUT|QSE_PIO_READERR|QSE_PIO_WRITEIN
);
if (pio == QSE_NULL)
@ -263,6 +294,7 @@ int main ()
R (test6);
R (test7);
R (test8);
R (test9);
return 0;
}

View File

@ -54,7 +54,7 @@ static int test2 (void)
qse_ssize_t n;
qse_char_t buf[20];
qse_sio_puts (qse_sio_out, QSE_T("type somthing...\n"));
qse_sio_puts (qse_sio_out, QSE_T("type something...\n"));
while (1)
{
n = qse_sio_gets (qse_sio_in, buf, QSE_COUNTOF(buf));

View File

@ -14,7 +14,11 @@
void print_time (qse_ntime_t nt, const qse_btime_t* bt)
{
#ifdef _WIN32
qse_printf (QSE_T("TIME: %I64d\n"), (__int64)nt);
#else
qse_printf (QSE_T("TIME: %lld\n"), (long long)nt);
#endif
qse_printf (QSE_T("year: %d\n"), bt->year + QSE_BTIME_YEAR_BASE);
qse_printf (QSE_T("mon: %d\n"), bt->mon + 1);
qse_printf (QSE_T("mday: %d\n"), bt->mday);
@ -48,7 +52,11 @@ static int test1 (void)
}
else
{
#ifdef _WIN32
qse_printf (QSE_T("back to ntime: %I64d\n"), (__int64)nt);
#else
qse_printf (QSE_T("back to ntime: %lld\n"), (long long)nt);
#endif
qse_gmtime (nt, &bt);
print_time (nt, &bt);
qse_printf (QSE_T("-------------------------------\n"));
@ -63,19 +71,32 @@ static int test1 (void)
for (nt = (qse_ntime_t)QSE_TYPE_MIN(int);
nt <= (qse_ntime_t)QSE_TYPE_MAX(int); nt += QSE_SECS_PER_DAY)
{
#ifdef _WIN32
__time64_t t = (__time64_t)nt;
#else
time_t t = (time_t)nt;
#endif
qse_ntime_t qnt = nt * 1000;
struct tm* tm;
if (qnt >= 0) qnt += rand() % 1000;
else qnt -= rand() % 1000;
#ifdef _WIN32
tm = _gmtime64 (&t);
#else
tm = gmtime (&t);
#endif
qse_gmtime (qnt, &bt);
qse_printf (QSE_T(">>> time %lld: "), (long long)qnt);
if (tm->tm_year != bt.year ||
#ifdef _WIN32
qse_printf (QSE_T(">>> time %I64d: "), (__int64)qnt);
#else
qse_printf (QSE_T(">>> time %lld: "), (long long)qnt);
#endif
if (tm == QSE_NULL ||
tm->tm_year != bt.year ||
tm->tm_mon != bt.mon ||
tm->tm_mday != bt.mday ||
tm->tm_wday != bt.wday ||
@ -83,14 +104,18 @@ static int test1 (void)
tm->tm_min != bt.min ||
tm->tm_sec != bt.sec)
{
#ifdef _WIN32
qse_printf (QSE_T("[GMTIME ERROR %I64d]\n"), (__int64)t);
#else
qse_printf (QSE_T("[GMTIME ERROR %lld]\n"), (long long)t);
#endif
if (tm == QSE_NULL) qse_printf (QSE_T(">> GMTIME RETURNED NULL\n"));
print_time (qnt, &bt);
qse_printf (QSE_T("-------------------------------\n"));
}
else
{
qse_ntime_t xx;
qse_printf (QSE_T("[GMTIME OK]"));
if (qse_timegm (&bt, &xx) == -1)
@ -100,8 +125,17 @@ static int test1 (void)
else
{
if (xx == qnt)
{
qse_printf (QSE_T("[TIMEGM OK %d/%d/%d %d:%d:%d]\n"), bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
else qse_printf (QSE_T("[TIMEGM ERROR %lld, %d/%d/%d %d:%d:%d]\n"), (long long)xx, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
}
else
{
#ifdef _WIN32
qse_printf (QSE_T("[TIMEGM ERROR %I64d, %d/%d/%d %d:%d:%d]\n"), (__int64)xx, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
#else
qse_printf (QSE_T("[TIMEGM ERROR %lld, %d/%d/%d %d:%d:%d]\n"), (long long)xx, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
#endif
}
}
}