From b8c66b5b8d6c6519233fe10cfdf61ef9a5f15a6f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 25 Dec 2012 14:10:02 +0000 Subject: [PATCH] added qse_dir_geterrnum() --- qse/bld/readme.txt | 2 +- qse/configure | 4 +- qse/include/qse/awk/awk.h | 1 + qse/include/qse/cmn/dir.h | 10 +- qse/include/qse/cmn/fio.h | 3 +- qse/include/qse/cmn/pio.h | 2 +- qse/lib/awk/err.c | 1 + qse/lib/awk/fnc.c | 4 + qse/lib/awk/parse.c | 1 - qse/lib/cmn/dir.c | 165 +++++++++++++++++++++++----- qse/lib/cmn/fio.c | 126 +-------------------- qse/lib/cmn/glob.c | 2 +- qse/lib/cmn/pio.c | 121 +------------------- qse/lib/cmn/syserr.h | 139 +++++++++++++++++++++++ qse/m4/lx_find_mpi.m4 | 2 +- qse/mod/awk/dir.c | 226 ++++++++++++++++++++++++-------------- 16 files changed, 446 insertions(+), 363 deletions(-) create mode 100644 qse/lib/cmn/syserr.h diff --git a/qse/bld/readme.txt b/qse/bld/readme.txt index 162e59b2..cd333390 100644 --- a/qse/bld/readme.txt +++ b/qse/bld/readme.txt @@ -2,7 +2,7 @@ The directory contains makefiles generated with bakefile(www.bakefile.org) for non-autoconf environments. - os2-watcom/makefile Watcom C/C++ for OS/2 - - win32-watcom/makefile Watcom C/C++ for OS/2 + - win32-watcom/makefile Watcom C/C++ for Windows - win32-borland/makefile Borland C/C++ for Windows - win32-msvc/makefile Microsoft Visual C/C++ for Windows diff --git a/qse/configure b/qse/configure index 78a85542..1a876e66 100755 --- a/qse/configure +++ b/qse/configure @@ -18183,7 +18183,7 @@ rm -f core conftest.err conftest.$ac_objext \ LIBS=$OLD_LIBS CPPFLAGS=$OLD_CPPFLAGS else - Echo Unable to find suitable MPI Compiler. Try setting MPICC. + echo Unable to find suitable MPI Compiler. Try setting MPICC. have_C_mpi='no' fi @@ -18331,7 +18331,7 @@ rm -f core conftest.err conftest.$ac_objext \ LIBS=$OLD_LIBS CPPFLAGS=$OLD_CPPFLAGS else - Echo Unable to find suitable MPI Compiler. Try setting MPICC. + echo Unable to find suitable MPI Compiler. Try setting MPICC. have_C_mpi='no' fi diff --git a/qse/include/qse/awk/awk.h b/qse/include/qse/awk/awk.h index 01fc09ad..6da8498c 100644 --- a/qse/include/qse/awk/awk.h +++ b/qse/include/qse/awk/awk.h @@ -1133,6 +1133,7 @@ enum qse_awk_errnum_t /* common errors */ QSE_AWK_ENOMEM, /**< insufficient memory */ QSE_AWK_EINVAL, /**< invalid parameter or data */ + QSE_AWK_EACCES, /**< access denied */ QSE_AWK_ENOSUP, /**< not supported */ QSE_AWK_ENOPER, /**< operation not allowed */ QSE_AWK_ENOENT, /**< '${0}' not found */ diff --git a/qse/include/qse/cmn/dir.h b/qse/include/qse/cmn/dir.h index ab2c52bd..643807a2 100644 --- a/qse/include/qse/cmn/dir.h +++ b/qse/include/qse/cmn/dir.h @@ -45,7 +45,8 @@ enum qse_dir_errnum_t QSE_DIR_EACCES, /**< access denied */ QSE_DIR_ENOENT, /**< no such file */ QSE_DIR_EEXIST, /**< already exist */ - QSE_DIR_EINTR /**< interrupted */ + QSE_DIR_EINTR, /**< interrupted */ + QSE_DIR_EPIPE /**< broken pipe */ }; typedef enum qse_dir_errnum_t qse_dir_errnum_t; @@ -76,7 +77,8 @@ QSE_EXPORT qse_dir_t* qse_dir_open ( qse_mmgr_t* mmgr, qse_size_t xtnsize, const qse_char_t* path, - int flags + int flags, + qse_dir_errnum_t* errnum /** error number */ ); QSE_EXPORT void qse_dir_close ( @@ -91,6 +93,10 @@ QSE_EXPORT void* qse_dir_getxtn ( qse_dir_t* dir ); +QSE_EXPORT qse_dir_errnum_t qse_dir_geterrnum ( + qse_dir_t* dir +); + QSE_EXPORT int qse_dir_reset ( qse_dir_t* dir, const qse_char_t* path diff --git a/qse/include/qse/cmn/fio.h b/qse/include/qse/cmn/fio.h index c407541e..7bdaccf0 100644 --- a/qse/include/qse/cmn/fio.h +++ b/qse/include/qse/cmn/fio.h @@ -83,7 +83,8 @@ enum qse_fio_errnum_t QSE_FIO_EACCES, /**< access denied */ QSE_FIO_ENOENT, /**< no such file */ QSE_FIO_EEXIST, /**< already exist */ - QSE_FIO_EINTR /**< interrupted */ + QSE_FIO_EINTR, /**< interrupted */ + QSE_FIO_EPIPE, /**< broken pipe */ }; typedef enum qse_fio_errnum_t qse_fio_errnum_t; diff --git a/qse/include/qse/cmn/pio.h b/qse/include/qse/cmn/pio.h index da968f57..bfb95302 100644 --- a/qse/include/qse/cmn/pio.h +++ b/qse/include/qse/cmn/pio.h @@ -123,9 +123,9 @@ enum qse_pio_errnum_t QSE_PIO_ENOENT, /**< no such file */ QSE_PIO_EEXIST, /**< already exist */ QSE_PIO_EINTR, /**< interrupted */ + QSE_PIO_EPIPE, /**< broken pipe */ QSE_PIO_ENOHND, /**< no handle available */ QSE_PIO_ECHILD, /**< the child is not valid */ - QSE_PIO_EPIPE, /**< broken pipe */ QSE_PIO_EILSEQ, /**< illegal sequence */ QSE_PIO_EICSEQ, /**< incomplete sequence */ QSE_PIO_EILCHR /**< illegal character */ diff --git a/qse/lib/awk/err.c b/qse/lib/awk/err.c index 4a0701b3..6be88608 100644 --- a/qse/lib/awk/err.c +++ b/qse/lib/awk/err.c @@ -32,6 +32,7 @@ const qse_char_t* qse_awk_dflerrstr (const qse_awk_t* awk, qse_awk_errnum_t errn QSE_T("insufficient memory"), QSE_T("invalid parameter or data"), + QSE_T("access denied"), QSE_T("not supported"), QSE_T("operation not allowed"), QSE_T("'${0}' not found"), diff --git a/qse/lib/awk/fnc.c b/qse/lib/awk/fnc.c index 6e5aa3c6..73c30377 100644 --- a/qse/lib/awk/fnc.c +++ b/qse/lib/awk/fnc.c @@ -718,6 +718,10 @@ static int fnc_split (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi) t1 = qse_awk_rtx_makemapval (run); if (t1 == QSE_NULL) goto oops; + /* use the following 3 lines intead of + * qse_awk_rtx_setrefval (run, a1, t1); + * just for less overhead. + */ qse_awk_rtx_refdownval (run, *a1_ref); *a1_ref = t1; qse_awk_rtx_refupval (run, *a1_ref); diff --git a/qse/lib/awk/parse.c b/qse/lib/awk/parse.c index ac70713b..bf668d7d 100644 --- a/qse/lib/awk/parse.c +++ b/qse/lib/awk/parse.c @@ -2155,7 +2155,6 @@ static qse_awk_nde_t* parse_while (qse_awk_t* awk, const qse_awk_loc_t* xloc) oops: if (body) qse_awk_clrpt (awk, body); if (test) qse_awk_clrpt (awk, test); - QSE_ASSERT (nde == QSE_NULL); return QSE_NULL; } diff --git a/qse/lib/cmn/dir.c b/qse/lib/cmn/dir.c index 367d393a..d3245310 100644 --- a/qse/lib/cmn/dir.c +++ b/qse/lib/cmn/dir.c @@ -40,6 +40,7 @@ struct qse_dir_t { qse_mmgr_t* mmgr; + qse_dir_errnum_t errnum; int flags; qse_str_t tbuf; @@ -72,7 +73,12 @@ void qse_dir_fini (qse_dir_t* dir); static int reset_to_path (qse_dir_t* dir, const qse_char_t* path); -qse_dir_t* qse_dir_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, const qse_char_t* path, int flags) +#include "syserr.h" +IMPLEMENT_SYSERR_TO_ERRNUM (dir, DIR) + +qse_dir_t* qse_dir_open ( + qse_mmgr_t* mmgr, qse_size_t xtnsize, + const qse_char_t* path, int flags, qse_dir_errnum_t* errnum) { qse_dir_t* dir; @@ -81,11 +87,16 @@ qse_dir_t* qse_dir_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, const qse_char_t* { if (qse_dir_init (dir, mmgr, path, flags) <= -1) { + if (errnum) *errnum = qse_dir_geterrnum (dir); QSE_MMGR_FREE (mmgr, dir); dir = QSE_NULL; } else QSE_MEMSET (dir + 1, 0, xtnsize); } + else + { + if (errnum) *errnum = QSE_DIR_ENOMEM; + } return dir; } @@ -106,6 +117,11 @@ void* qse_dir_getxtn (qse_dir_t* dir) return QSE_XTN (dir); } +qse_dir_errnum_t qse_dir_geterrnum (qse_dir_t* dir) +{ + return dir->errnum; +} + int qse_dir_init (qse_dir_t* dir, qse_mmgr_t* mmgr, const qse_char_t* path, int flags) { int n; @@ -177,8 +193,17 @@ static qse_mchar_t* wcs_to_mbuf (qse_dir_t* dir, const qse_wchar_t* wcs, qse_mbs { qse_size_t ml, wl; - if (qse_wcstombs (wcs, &wl, QSE_NULL, &ml) <= -1 || - qse_mbs_setlen (mbs, ml) == (qse_size_t)-1) return QSE_NULL; + if (qse_wcstombs (wcs, &wl, QSE_NULL, &ml) <= -1) + { + dir->errnum = QSE_DIR_EINVAL; + return QSE_NULL; + } + + if (qse_mbs_setlen (mbs, ml) == (qse_size_t)-1) + { + dir->errnum = QSE_DIR_ENOMEM; + return QSE_NULL; + } qse_wcstombs (wcs, &wl, QSE_MBS_PTR(mbs), &ml); return QSE_MBS_PTR(mbs); @@ -188,8 +213,16 @@ static qse_wchar_t* mbs_to_wbuf (qse_dir_t* dir, const qse_mchar_t* mbs, qse_wcs { qse_size_t ml, wl; - if (qse_mbstowcs (mbs, &ml, QSE_NULL, &wl) <= -1 || - qse_wcs_setlen (wcs, wl) == (qse_size_t)-1) return QSE_NULL; + if (qse_mbstowcs (mbs, &ml, QSE_NULL, &wl) <= -1) + { + dir->errnum = QSE_DIR_EINVAL; + return QSE_NULL; + } + if (qse_wcs_setlen (wcs, wl) == (qse_size_t)-1) + { + dir->errnum = QSE_DIR_ENOMEM; + return QSE_NULL; + } qse_mbstowcs (mbs, &ml, QSE_WCS_PTR(wcs), &wl); return QSE_WCS_PTR(wcs); @@ -199,7 +232,11 @@ static qse_mchar_t* make_mbsdos_path (qse_dir_t* dir, const qse_mchar_t* mpath) { if (mpath[0] == QSE_MT('\0')) { - if (qse_mbs_cpy (&dir->mbuf, QSE_MT("*.*")) == (qse_size_t)-1) return QSE_NULL; + if (qse_mbs_cpy (&dir->mbuf, QSE_MT("*.*")) == (qse_size_t)-1) + { + dir->errnum = QSE_DIR_ENOMEM; + return QSE_NULL; + } } else { @@ -210,6 +247,7 @@ static qse_mchar_t* make_mbsdos_path (qse_dir_t* dir, const qse_mchar_t* mpath) qse_mbs_ccat (&dir->mbuf, QSE_MT('\\')) == (qse_size_t)-1) || qse_mbs_cat (&dir->mbuf, QSE_MT("*.*")) == (qse_size_t)-1) { + dir->errnum = QSE_DIR_ENOMEM; return QSE_NULL; } } @@ -221,7 +259,11 @@ static qse_char_t* make_dos_path (qse_dir_t* dir, const qse_char_t* path) { if (path[0] == QSE_T('\0')) { - if (qse_str_cpy (&dir->tbuf, QSE_T("*.*")) == (qse_size_t)-1) return QSE_NULL; + if (qse_str_cpy (&dir->tbuf, QSE_T("*.*")) == (qse_size_t)-1) + { + dir->errnum = QSE_DIR_ENOMEM; + return QSE_NULL; + } } else { @@ -232,6 +274,7 @@ static qse_char_t* make_dos_path (qse_dir_t* dir, const qse_char_t* path) qse_str_ccat (&dir->tbuf, QSE_T('\\')) == (qse_size_t)-1) || qse_str_cat (&dir->tbuf, QSE_T("*.*")) == (qse_size_t)-1) { + dir->errnum = QSE_DIR_ENOMEM; return QSE_NULL; } } @@ -293,7 +336,11 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path) if (tptr == QSE_NULL) return -1; dir->h = FindFirstFile (tptr, &dir->wfd); - if (dir->h == INVALID_HANDLE_VALUE) return -1; + if (dir->h == INVALID_HANDLE_VALUE) + { + dir->errnum = syserr_to_errnum (GetLastError()); + return -1; + } return 0; /* ------------------------------------------------------------------- */ @@ -337,7 +384,11 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path) #endif ); - if (rc != NO_ERROR) return -1; + if (rc != NO_ERROR) + { + dir->errnum = syserr_to_errnum (rc); + return -1; + } dir->opened = 1; return 0; @@ -368,7 +419,11 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path) if (mptr == QSE_NULL) return -1; rc = _dos_findfirst (mptr, _A_NORMAL | _A_SUBDIR, &dir->f); - if (rc != 0) return -1; + if (rc != 0) + { + dir->errnum = syserr_to_errnum (errno); + return -1; + } dir->opened = 1; return 0; @@ -402,7 +457,11 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path) } } #endif - if (dp == QSE_NULL) return -1; + if (dp == QSE_NULL) + { + dir->errnum = syserr_to_errnum (errno); + return -1; + } dir->dp = dp; return 0; @@ -423,7 +482,11 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name) if (dir->done) return (dir->done > 0)? 0: -1; #if defined(QSE_CHAR_IS_MCHAR) - if (qse_str_cpy (&dir->tbuf, dir->wfd.cFileName) == (qse_size_t)-1) return -1; + if (qse_str_cpy (&dir->tbuf, dir->wfd.cFileName) == (qse_size_t)-1) + { + dir->errnum = QSE_DIR_ENOMEM; + return -1; + } *name = QSE_STR_PTR(&dir->tbuf); #else if (dir->flags & QSE_DIR_MBSPATH) @@ -433,13 +496,25 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name) } else { - if (qse_str_cpy (&dir->tbuf, dir->wfd.cFileName) == (qse_size_t)-1) return -1; + if (qse_str_cpy (&dir->tbuf, dir->wfd.cFileName) == (qse_size_t)-1) + { + dir->errnum = QSE_DIR_ENOMEM; + return -1; + } *name = QSE_STR_PTR(&dir->tbuf); } #endif if (FindNextFile (dir->h, &dir->wfd) == FALSE) - dir->done = (GetLastError() == ERROR_NO_MORE_FILES)? 1: -1; + { + DWORD x = GetLastError(); + if (x == ERROR_NO_MORE_FILES) dir->done = 1; + else + { + dir->errnum = syserr_to_errnum (x); + dir->done = -1; + } + } return 1; /* ------------------------------------------------------------------- */ @@ -452,12 +527,20 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name) if (dir->count <= 0) return 0; #if defined(QSE_CHAR_IS_MCHAR) - if (qse_str_cpy (&dir->tbuf, dir->ffb.achName) == (qse_size_t)-1) return -1; + if (qse_str_cpy (&dir->tbuf, dir->ffb.achName) == (qse_size_t)-1) + { + dir->errnum = QSE_DIR_ENOMEM; + return -1; + } *name = QSE_STR_PTR(&dir->tbuf); #else if (dir->flags & QSE_DIR_MBSPATH) { - if (qse_mbs_cpy (&dir->mbuf, dir->ffb.achName) == (qse_size_t)-1) return -1; + if (qse_mbs_cpy (&dir->mbuf, dir->ffb.achName) == (qse_size_t)-1) + { + dir->errnum = QSE_DIR_ENOMEM; + return -1; + } *name = QSE_MBS_PTR(&dir->mbuf); } else @@ -469,7 +552,11 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name) rc = DosFindNext (dir->h, &dir->ffb, QSE_SIZEOF(dir->ffb), &dir->count); if (rc == ERROR_NO_MORE_FILES) dir->count = 0; - else if (rc != NO_ERROR) return -1; + else if (rc != NO_ERROR) + { + dir->errnum = syserr_to_errnum (rc); + return -1; + } return 1; /* ------------------------------------------------------------------- */ @@ -477,17 +564,24 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name) #elif defined(__DOS__) /* ------------------------------------------------------------------- */ - unsigned int rc; if (dir->done) return (dir->done > 0)? 0: -1; #if defined(QSE_CHAR_IS_MCHAR) - if (qse_str_cpy (&dir->tbuf, dir->f.name) == (qse_size_t)-1) return -1; + if (qse_str_cpy (&dir->tbuf, dir->f.name) == (qse_size_t)-1) + { + dir->errnum = QSE_DIR_ENOMEM; + return -1; + } *name = QSE_STR_PTR(&dir->tbuf); #else if (dir->flags & QSE_DIR_MBSPATH) { - if (qse_mbs_cpy (&dir->mbuf, dir->f.name) == (qse_size_t)-1) return -1; + if (qse_mbs_cpy (&dir->mbuf, dir->f.name) == (qse_size_t)-1) + { + dir->errnum = QSE_DIR_ENOMEM; + return -1; + } *name = QSE_MBS_PTR(&dir->mbuf); } else @@ -497,8 +591,15 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name) } #endif - rc = _dos_findnext (&dir->f); - if (rc != 0) dir->done = (errno == ENOENT)? 1: -1; + if (_dos_findnext (&dir->f) != 0) + { + if (errno == ENOENT) dir->done = 1; + else + { + dir->errnum = syserr_to_errnum (errno); + dir->done = -1; + } + } return 1; /* ------------------------------------------------------------------- */ @@ -510,15 +611,29 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name) errno = 0; de = QSE_READDIR (dir->dp); - if (de == NULL) return (errno == 0)? 0: -1; + if (de == NULL) + { + if (errno == 0) return 0; + dir->errnum = syserr_to_errnum (errno); + return -1; + } #if defined(QSE_CHAR_IS_MCHAR) - if (qse_str_cpy (&dir->tbuf, de->d_name) == (qse_size_t)-1) return -1; + if (qse_str_cpy (&dir->tbuf, de->d_name) == (qse_size_t)-1) + { + dir->errnum = QSE_DIR_ENOMEM; + return -1; + } + *name = QSE_STR_PTR(&dir->tbuf); #else if (dir->flags & QSE_DIR_MBSPATH) { - if (qse_mbs_cpy (&dir->mbuf, de->d_name) == (qse_size_t)-1) return -1; + if (qse_mbs_cpy (&dir->mbuf, de->d_name) == (qse_size_t)-1) + { + dir->errnum = QSE_DIR_ENOMEM; + return -1; + } *name = QSE_MBS_PTR(&dir->mbuf); } else diff --git a/qse/lib/cmn/fio.c b/qse/lib/cmn/fio.c index c1423b4f..6e52cd36 100644 --- a/qse/lib/cmn/fio.c +++ b/qse/lib/cmn/fio.c @@ -55,130 +55,8 @@ enum STATUS_NOCLOSE = (1 << 1) }; -#if defined(_WIN32) -static qse_fio_errnum_t syserr_to_errnum (DWORD e) -{ - switch (e) - { - case ERROR_NOT_ENOUGH_MEMORY: - case ERROR_OUTOFMEMORY: - return QSE_FIO_ENOMEM; - - case ERROR_INVALID_PARAMETER: - case ERROR_INVALID_HANDLE: - case ERROR_INVALID_NAME: - return QSE_FIO_EINVAL; - - case ERROR_ACCESS_DENIED: - case ERROR_SHARING_VIOLATION: - return QSE_FIO_EACCES; - - case ERROR_FILE_NOT_FOUND: - case ERROR_PATH_NOT_FOUND: - return QSE_FIO_ENOENT; - - case ERROR_ALREADY_EXISTS: - case ERROR_FILE_EXISTS: - return QSE_FIO_EEXIST; - - default: - return QSE_FIO_ESYSERR; - } -} -#elif defined(__OS2__) -static qse_fio_errnum_t syserr_to_errnum (APIRET e) -{ - switch (e) - { - case ERROR_NOT_ENOUGH_MEMORY: - return QSE_FIO_ENOMEM; - - case ERROR_INVALID_PARAMETER: - case ERROR_INVALID_HANDLE: - case ERROR_INVALID_NAME: - return QSE_FIO_EINVAL; - - case ERROR_ACCESS_DENIED: - case ERROR_SHARING_VIOLATION: - return QSE_FIO_EACCES; - - case ERROR_FILE_NOT_FOUND: - case ERROR_PATH_NOT_FOUND: - return QSE_FIO_ENOENT; - - case ERROR_ALREADY_EXISTS: - return QSE_FIO_EEXIST; - - default: - return QSE_FIO_ESYSERR; - } -} -#elif defined(__DOS__) -static qse_fio_errnum_t syserr_to_errnum (int e) -{ - switch (e) - { - case ENOMEM: - return QSE_FIO_ENOMEM; - - case EINVAL: - return QSE_FIO_EINVAL; - - case EACCES: - return QSE_FIO_EACCES; - - case ENOENT: - return QSE_FIO_ENOENT; - - case EEXIST: - return QSE_FIO_EEXIST; - - default: - return QSE_FIO_ESYSERR; - } -} -#elif defined(vms) || defined(__vms) -static qse_fio_errnum_t syserr_to_errnum (unsigned long e) -{ - switch (e) - { - case RMS$_NORMAL: - return QSE_FIO_ENOERR; - - /* TODO: add more */ - - default: - return QSE_FIO_ESYSERR; - } -} -#else -static qse_fio_errnum_t syserr_to_errnum (int e) -{ - switch (e) - { - case ENOMEM: - return QSE_FIO_ENOMEM; - - case EINVAL: - return QSE_FIO_EINVAL; - - case ENOENT: - return QSE_FIO_ENOENT; - - case EACCES: - return QSE_FIO_EACCES; - - case EEXIST: - return QSE_FIO_EEXIST; - - case EINTR: - return QSE_FIO_EINTR; - - default: - return QSE_FIO_ESYSERR; - } -} -#endif +#include "syserr.h" +IMPLEMENT_SYSERR_TO_ERRNUM (fio, FIO) #if defined(__OS2__) diff --git a/qse/lib/cmn/glob.c b/qse/lib/cmn/glob.c index 3e00b3f7..34c5fe09 100644 --- a/qse/lib/cmn/glob.c +++ b/qse/lib/cmn/glob.c @@ -408,7 +408,7 @@ entry: if (seg->wild) { - dp = qse_dir_open (g->mmgr, 0, QSE_STR_PTR(&g->path), 0); + dp = qse_dir_open (g->mmgr, 0, QSE_STR_PTR(&g->path), 0, QSE_NULL); if (dp) { tmp = QSE_STR_LEN(&g->path); diff --git a/qse/lib/cmn/pio.c b/qse/lib/cmn/pio.c index 48d6ea74..69e48cef 100644 --- a/qse/lib/cmn/pio.c +++ b/qse/lib/cmn/pio.c @@ -45,125 +45,8 @@ static qse_ssize_t pio_input ( static qse_ssize_t pio_output ( qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size); -#if defined(_WIN32) -static qse_pio_errnum_t syserr_to_errnum (DWORD e) -{ - switch (e) - { - case ERROR_NOT_ENOUGH_MEMORY: - case ERROR_OUTOFMEMORY: - return QSE_PIO_ENOMEM; - - case ERROR_INVALID_PARAMETER: - case ERROR_INVALID_HANDLE: - case ERROR_INVALID_NAME: - return QSE_PIO_EINVAL; - - case ERROR_ACCESS_DENIED: - case ERROR_SHARING_VIOLATION: - return QSE_PIO_EACCES; - - case ERROR_FILE_NOT_FOUND: - case ERROR_PATH_NOT_FOUND: - return QSE_PIO_ENOENT; - - case ERROR_ALREADY_EXISTS: - case ERROR_FILE_EXISTS: - return QSE_PIO_EEXIST; - - case ERROR_BROKEN_PIPE: - return QSE_PIO_EPIPE; - - default: - return QSE_PIO_ESYSERR; - } -} -#elif defined(__OS2__) -static qse_pio_errnum_t syserr_to_errnum (APIRET e) -{ - switch (e) - { - case ERROR_NOT_ENOUGH_MEMORY: - return QSE_PIO_ENOMEM; - - case ERROR_INVALID_PARAMETER: - case ERROR_INVALID_HANDLE: - case ERROR_INVALID_NAME: - return QSE_PIO_EINVAL; - - case ERROR_ACCESS_DENIED: - case ERROR_SHARING_VIOLATION: - return QSE_PIO_EACCES; - - case ERROR_FILE_NOT_FOUND: - case ERROR_PATH_NOT_FOUND: - return QSE_PIO_ENOENT; - - case ERROR_ALREADY_EXISTS: - return QSE_PIO_EEXIST; - - case ERROR_BROKEN_PIPE: - return QSE_PIO_EPIPE; - - default: - return QSE_PIO_ESYSERR; - } -} -#elif defined(__DOS__) -static qse_pio_errnum_t syserr_to_errnum (int e) -{ - switch (e) - { - case ENOMEM: - return QSE_PIO_ENOMEM; - - case EINVAL: - return QSE_PIO_EINVAL; - - case EACCES: - return QSE_PIO_EACCES; - - case ENOENT: - return QSE_PIO_ENOENT; - - case EEXIST: - return QSE_PIO_EEXIST; - - default: - return QSE_PIO_ESYSERR; - } -} -#else -static qse_pio_errnum_t syserr_to_errnum (int e) -{ - switch (e) - { - case ENOMEM: - return QSE_PIO_ENOMEM; - - case EINVAL: - return QSE_PIO_EINVAL; - - case EACCES: - return QSE_PIO_EACCES; - - case ENOENT: - return QSE_PIO_ENOENT; - - case EEXIST: - return QSE_PIO_EEXIST; - - case EINTR: - return QSE_PIO_EINTR; - - case EPIPE: - return QSE_PIO_EPIPE; - - default: - return QSE_PIO_ESYSERR; - } -} -#endif +#include "syserr.h" +IMPLEMENT_SYSERR_TO_ERRNUM (pio, PIO) static qse_pio_errnum_t tio_errnum_to_pio_errnum (qse_tio_t* tio) { diff --git a/qse/lib/cmn/syserr.h b/qse/lib/cmn/syserr.h new file mode 100644 index 00000000..41f97493 --- /dev/null +++ b/qse/lib/cmn/syserr.h @@ -0,0 +1,139 @@ +/* + * $Id$ + * + Copyright 2006-2012 Chung, Hyung-Hwan. + This file is part of QSE. + + QSE is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + QSE is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with QSE. If not, see . + */ + +/* + * this file is intended for internal use only. + * you can include this file and use IMPLEMENT_SYSERR_TO_ERRNUM. + * + * #include "syserr.h" + * IMPLEMENT_SYSERR_TO_ERRNUM (pio, PIO) + * + * header files defining system error codes must be included + * before this file. + */ + +#define __SYSERRTYPE__(obj) qse_ ## obj ## _errnum_t +#define __SYSERRNUM__(obj,num) (QSE_ ## obj ## _ ## num) + +#if defined(_WIN32) + + #define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \ + static __SYSERRTYPE__(obj1) syserr_to_errnum (DWORD e) \ + { \ + switch (e) \ + { \ + case ERROR_NOT_ENOUGH_MEMORY: \ + case ERROR_OUTOFMEMORY: \ + return __SYSERRNUM__ (obj2, ENOMEM); \ + case ERROR_INVALID_PARAMETER: \ + case ERROR_INVALID_HANDLE: \ + case ERROR_INVALID_NAME: \ + return __SYSERRNUM__ (obj2, EINVAL); \ + case ERROR_ACCESS_DENIED: \ + case ERROR_SHARING_VIOLATION: \ + return __SYSERRNUM__ (obj2, EACCES); \ + case ERROR_FILE_NOT_FOUND: \ + case ERROR_PATH_NOT_FOUND: \ + return __SYSERRNUM__ (obj2, ENOENT); \ + case ERROR_ALREADY_EXISTS: \ + case ERROR_FILE_EXISTS: \ + return __SYSERRNUM__ (obj2, EEXIST); \ + case ERROR_BROKEN_PIPE: \ + return __SYSERRNUM__ (obj2, EPIPE); \ + default: \ + return __SYSERRNUM__ (obj2, ESYSERR); \ + } \ + } + +#elif defined(__OS2__) + + #define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \ + static __SYSERRTYPE__(obj1) syserr_to_errnum (APIRET e) \ + { \ + switch (e) \ + { \ + case ERROR_NOT_ENOUGH_MEMORY: \ + return __SYSERRNUM__ (obj2, ENOMEM); \ + case ERROR_INVALID_PARAMETER: \ + case ERROR_INVALID_HANDLE: \ + case ERROR_INVALID_NAME: \ + return __SYSERRNUM__ (obj2, EINVAL); \ + case ERROR_ACCESS_DENIED: \ + case ERROR_SHARING_VIOLATION: \ + return __SYSERRNUM__ (obj2, EACCES); \ + case ERROR_FILE_NOT_FOUND: \ + case ERROR_PATH_NOT_FOUND: \ + return __SYSERRNUM__ (obj2, ENOENT); \ + case ERROR_ALREADY_EXISTS: \ + return __SYSERRNUM__ (obj2, EEXIST); \ + case ERROR_BROKEN_PIPE: \ + return __SYSERRNUM__ (obj2, EPIPE); \ + default: \ + return __SYSERRNUM__ (obj2, ESYSERR); \ + } \ + } + +#elif defined(__DOS__) + + #define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \ + static __SYSERRTYPE__(obj1) syserr_to_errnum (int e) \ + { \ + switch (e) \ + { \ + case ENOMEM: return __SYSERRNUM__ (syserrobj, ENOMEM); \ + case EINVAL: return __SYSERRNUM__ (syserrobj, EINVAL); \ + case EACCES: return __SYSERRNUM__ (syserrobj, EACCES); \ + case ENOENT: return __SYSERRNUM__ (syserrobj, ENOENT); \ + case EEXIST: return __SYSERRNUM__ (syserrobj, EEXIST); \ + default: return __SYSERRNUM__ (syserrobj, ESYSERR); \ + } \ + } + +#elif defined(vms) || defined(__vms) + + #define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \ + static __SYSERRTYPE__(obj1) syserr_to_errnum (unsigned long e) \ + { \ + switch (e) \ + { \ + case RMS$_NORMAL: return __SYSERRNUM__ (obj2, ENOERR); \ + default: return __SYSERRNUM__ (obj2, ESYSERR); \ + } \ + } + +#else + + #define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \ + static __SYSERRTYPE__(obj1) syserr_to_errnum (int e) \ + { \ + switch (e) \ + { \ + case ENOMEM: return __SYSERRNUM__ (obj2, ENOMEM); \ + case EINVAL: return __SYSERRNUM__ (obj2, EINVAL); \ + case EACCES: return __SYSERRNUM__ (obj2, EACCES); \ + case ENOENT: return __SYSERRNUM__ (obj2, ENOENT); \ + case EEXIST: return __SYSERRNUM__ (obj2, EEXIST); \ + case EINTR: return __SYSERRNUM__ (obj2, EINTR); \ + case EPIPE: return __SYSERRNUM__ (obj2, EPIPE); \ + default: return __SYSERRNUM__ (obj2, ESYSERR); \ + } \ + } + +#endif diff --git a/qse/m4/lx_find_mpi.m4 b/qse/m4/lx_find_mpi.m4 index f86c43b3..11a9bb36 100644 --- a/qse/m4/lx_find_mpi.m4 +++ b/qse/m4/lx_find_mpi.m4 @@ -197,7 +197,7 @@ AC_DEFUN([LX_QUERY_MPI_COMPILER], LIBS=$OLD_LIBS CPPFLAGS=$OLD_CPPFLAGS else - Echo Unable to find suitable MPI Compiler. Try setting $1. + echo Unable to find suitable MPI Compiler. Try setting $1. have_$3_mpi='no' fi ]) diff --git a/qse/mod/awk/dir.c b/qse/mod/awk/dir.c index 85569a3a..df7f4385 100644 --- a/qse/mod/awk/dir.c +++ b/qse/mod/awk/dir.c @@ -30,8 +30,11 @@ typedef struct dir_node_t dir_node_t; enum { DIR_ENOERR, + DIR_EOTHER, + DIR_ESYSERR, DIR_ENOMEM, DIR_EINVAL, + DIR_EACCES, DIR_ENOENT }; @@ -60,10 +63,49 @@ struct dir_list_t int errnum; }; +static int dir_err_to_errnum (qse_dir_errnum_t num) +{ + switch (num) + { + case QSE_DIR_ESYSERR: + return DIR_ESYSERR; + case QSE_DIR_ENOMEM: + return DIR_ENOMEM; + case QSE_DIR_EINVAL: + return DIR_EINVAL; + case QSE_DIR_EACCES: + return DIR_EACCES; + case QSE_DIR_ENOENT: + return DIR_ENOENT; + default: + return DIR_EOTHER; + } +} + +static int awk_err_to_errnum (qse_awk_errnum_t num) +{ + switch (num) + { + case QSE_AWK_ESYSERR: + return DIR_ESYSERR; + case QSE_AWK_ENOMEM: + return DIR_ENOMEM; + case QSE_AWK_EINVAL: + return DIR_EINVAL; + case QSE_AWK_EACCES: + return DIR_EACCES; + case QSE_AWK_ENOENT: + return DIR_ENOENT; + default: + return DIR_EOTHER; + } +} + static dir_node_t* new_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, const qse_char_t* path) { /* create a new context node and append it to the list tail */ dir_node_t* node; + qse_dir_errnum_t oe; node = QSE_NULL; @@ -71,11 +113,19 @@ static dir_node_t* new_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, const qse else { node = qse_awk_rtx_callocmem (rtx, QSE_SIZEOF(*node)); - if (!node) goto oops; + if (!node) + { + list->errnum = DIR_ENOMEM; + goto oops; + } } - node->ctx = qse_dir_open (qse_awk_rtx_getmmgr(rtx), 0, path, 0); - if (!node->ctx) goto oops; + node->ctx = qse_dir_open (qse_awk_rtx_getmmgr(rtx), 0, path, 0, &oe); + if (!node->ctx) + { + list->errnum = dir_err_to_errnum (oe); + goto oops; + } if (node == list->free) list->free = node->next; else @@ -90,7 +140,11 @@ static dir_node_t* new_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, const qse tmp = (dir_node_t**) qse_awk_rtx_reallocmem ( rtx, list->map.tab, QSE_SIZEOF(*tmp) * newcapa); - if (!tmp) goto oops; + if (!tmp) + { + list->errnum = DIR_ENOMEM; + goto oops; + } QSE_MEMSET (&tmp[list->map.capa], 0, QSE_SIZEOF(*tmp) * (newcapa - list->map.capa)); @@ -116,7 +170,6 @@ static dir_node_t* new_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, const qse oops: if (node) qse_awk_rtx_freemem (rtx, node); - qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL); return QSE_NULL; } @@ -177,53 +230,68 @@ static void free_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, dir_node_t* nod static int close_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_long_t id) { - int x = DIR_EINVAL; - if (id >= 0 && id < list->map.high && list->map.tab[id]) { free_dir_node (rtx, list, list->map.tab[id]); - x = DIR_ENOERR; + return 0; + } + else + { + list->errnum = DIR_EINVAL; + return -1; } - - return -x; } static int reset_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_long_t id, const qse_char_t* path) { - int x = DIR_EINVAL; - if (id >= 0 && id < list->map.high && list->map.tab[id]) { - if (qse_dir_reset (list->map.tab[id]->ctx, path) >= 0) x = DIR_ENOERR; + if (qse_dir_reset (list->map.tab[id]->ctx, path) <= -1) + { + list->errnum = dir_err_to_errnum (qse_dir_geterrnum (list->map.tab[id]->ctx)); + return -1; + } + return 0; + } + else + { + list->errnum = DIR_EINVAL; + return -1; } - - return -x; } -static int read_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_long_t id, qse_awk_val_t** retv) +static int read_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_long_t id, qse_awk_val_ref_t* ref) { - int x = DIR_EINVAL; - if (id >= 0 && id < list->map.high && list->map.tab[id]) { int y; qse_dir_ent_t ent; + qse_awk_val_t* tmp; + y = qse_dir_read (list->map.tab[id]->ctx, &ent); - if (y == 0) x = DIR_ENOENT; - else if (y >= 1) + if (y <= -1) { - qse_awk_val_t* tmp; - tmp = qse_awk_rtx_makestrvalwithstr (rtx, ent.name); - if (tmp) - { - *retv = tmp; - x = DIR_ENOERR; - } - else x = DIR_ENOMEM; + list->errnum = dir_err_to_errnum (qse_dir_geterrnum (list->map.tab[id]->ctx)); + return -1; } + + if (y == 0) return 0; + + tmp = qse_awk_rtx_makestrvalwithstr (rtx, ent.name); + if (!tmp || qse_awk_rtx_setrefval (rtx, ref, tmp) <= -1) + { + list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx)); + if (tmp) qse_awk_rtx_freemem (rtx, tmp); + return -1; + } + + return 1; + } + else + { + list->errnum = DIR_EINVAL; + return -1; } - - return -x; } /* ------------------------------------------------------------------------ */ @@ -253,8 +321,11 @@ static int fnc_dir_errno (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static qse_char_t* errmsg[] = { QSE_T("no error"), - QSE_T("out of memory"), + QSE_T("other error"), + QSE_T("system error"), + QSE_T("insufficient memory"), QSE_T("invalid data"), + QSE_T("access denied"), QSE_T("no entry"), QSE_T("unknown error") }; @@ -287,122 +358,107 @@ static int fnc_dir_open (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) dir_list_t* list; dir_node_t* node; qse_long_t ret; - qse_awk_val_t* retv; qse_char_t* path; list = rtx_to_list (rtx, fi); path = qse_awk_rtx_valtostrdup (rtx, qse_awk_rtx_getarg (rtx, 0), QSE_NULL); - if (path == QSE_NULL) + if (path) { - list->errnum = DIR_ENOMEM; - ret = -DIR_ENOMEM; + node = new_dir_node (rtx, list, path); + if (node) ret = node->id; + else ret = -1; + qse_awk_rtx_freemem (rtx, path); } else { - node = new_dir_node (rtx, list, path); - ret = node? node->id: -DIR_ENOMEM; - qse_awk_rtx_freemem (rtx, path); - } - - if (ret <= -1) - { - list->errnum = -ret; + list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx)); ret = -1; } - retv = qse_awk_rtx_makeintval (rtx, ret); - if (retv == QSE_NULL) return -1; - - qse_awk_rtx_setretval (rtx, retv); + qse_awk_rtx_setretval (rtx, qse_awk_rtx_makeintval (rtx, ret)); return 0; } static int fnc_dir_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) { dir_list_t* list; - qse_awk_val_t* retv; qse_long_t id; int ret; list = rtx_to_list (rtx, fi); ret = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &id); - if (ret <= -1) ret = -DIR_EINVAL; - else ret = close_byid (rtx, list, id); - - if (ret <= -1) + if (ret <= -1) { - list->errnum = -ret; + list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx)); ret = -1; } + else + { + ret = close_byid (rtx, list, id); + } - retv = qse_awk_rtx_makeintval (rtx, ret); - if (retv == QSE_NULL) return -1; - - qse_awk_rtx_setretval (rtx, retv); + qse_awk_rtx_setretval (rtx, qse_awk_rtx_makeintval (rtx, ret)); return 0; } static int fnc_dir_reset (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) { dir_list_t* list; - qse_awk_val_t* retv; qse_long_t id; int ret; + qse_char_t* path; list = rtx_to_list (rtx, fi); ret = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &id); - if (ret <= -1) ret = -DIR_EINVAL; + if (ret <= -1) + { + list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx)); + } else { - qse_char_t* path; - path = qse_awk_rtx_valtostrdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); if (path) { ret = reset_byid (rtx, list, id, path); qse_awk_rtx_freemem (rtx, path); } - else ret = -DIR_ENOMEM; + else + { + list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx)); + ret = -1; + } } - if (ret <= -1) - { - list->errnum = -ret; - ret = -1; - } - - retv = qse_awk_rtx_makeintval (rtx, ret); - if (retv == QSE_NULL) return -1; - - qse_awk_rtx_setretval (rtx, retv); + /* no error check for qse_awk_rtx_makeintval() here since ret + * is 0 or -1. it will never fail for those numbers */ + qse_awk_rtx_setretval (rtx, qse_awk_rtx_makeintval (rtx, ret)); return 0; } static int fnc_dir_read (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) { dir_list_t* list; - qse_awk_val_t* retv; qse_long_t id; int ret; list = rtx_to_list (rtx, fi); ret = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &id); - if (ret <= -1) ret = -DIR_EINVAL; - else ret = read_byid (rtx, list, id, &retv); - if (ret <= -1) { - list->errnum = -ret; + list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx)); } else { - qse_awk_rtx_setretval (rtx, retv); + ret = read_byid (rtx, list, id, qse_awk_rtx_getarg (rtx, 1)); } + /* no error check for qse_awk_rtx_makeintval() here since ret + * is 0, 1, -1. it will never fail for those numbers */ + qse_awk_rtx_setretval (rtx, qse_awk_rtx_makeintval (rtx, ret)); return 0; } @@ -417,12 +473,12 @@ struct fnctab_t static fnctab_t fnctab[] = { - { QSE_T("close"), { { 1, 1, QSE_NULL }, fnc_dir_close, 0 } }, - { QSE_T("errno"), { { 0, 0, QSE_NULL }, fnc_dir_errno, 0 } }, - { QSE_T("errstr"), { { 0, 1, QSE_NULL }, fnc_dir_errstr, 0 } }, - { QSE_T("open"), { { 1, 1, QSE_NULL }, fnc_dir_open, 0 } }, - { QSE_T("read"), { { 1, 1, QSE_NULL }, fnc_dir_read, 0 } }, - { QSE_T("reset"), { { 2, 2, QSE_NULL }, fnc_dir_reset, 0 } }, + { QSE_T("close"), { { 1, 1, QSE_NULL }, fnc_dir_close, 0 } }, + { QSE_T("errno"), { { 0, 0, QSE_NULL }, fnc_dir_errno, 0 } }, + { QSE_T("errstr"), { { 0, 1, QSE_NULL }, fnc_dir_errstr, 0 } }, + { QSE_T("open"), { { 1, 1, QSE_NULL }, fnc_dir_open, 0 } }, + { QSE_T("read"), { { 2, 2, QSE_T("vr") }, fnc_dir_read, 0 } }, + { QSE_T("reset"), { { 2, 2, QSE_NULL }, fnc_dir_reset, 0 } }, }; /* ------------------------------------------------------------------------ */ @@ -430,7 +486,7 @@ static fnctab_t fnctab[] = static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym) { qse_cstr_t ea; - int left, right, mid, n; + int left, right, mid, n; left = 0; right = QSE_COUNTOF(fnctab) - 1;