--- np2/wince/dosio.cpp 2003/10/16 17:59:32 1.1.1.1 +++ np2/wince/dosio.cpp 2004/06/20 02:57:47 1.6 @@ -2,10 +2,10 @@ #include "dosio.h" -static char curpath[MAX_PATH]; -static char *curfilep = curpath; +static OEMCHAR curpath[MAX_PATH]; +static OEMCHAR *curfilep = curpath; -#define ISKANJI(c) (((((c) ^ 0x20) - 0xa1) & 0xff) < 0x3c) +// #define ISKANJI(c) (((((c) ^ 0x20) - 0xa1) & 0xff) < 0x3c) #if defined(UNICODE) @@ -17,10 +17,15 @@ static HANDLE CreateFile_A(LPCSTR lpFile DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { - TCHAR FileNameW[MAX_PATH*2]; + UINT16 FileNameW[MAX_PATH]; +#if defined(OSLANG_SJIS) MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1, - FileNameW, sizeof(FileNameW)/sizeof(TCHAR)); + FileNameW, sizeof(FileNameW)/sizeof(UINT16)); +#else + ucscnv_utf8toucs2(FileNameW, sizeof(FileNameW)/sizeof(UINT16), + lpFileName, (UINT)-1); +#endif return(CreateFile(FileNameW, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile)); @@ -28,39 +33,59 @@ static HANDLE CreateFile_A(LPCSTR lpFile static inline BOOL DeleteFile_A(LPCSTR lpFileName) { - TCHAR FileNameW[MAX_PATH*2]; + UINT16 FileNameW[MAX_PATH]; +#if defined(OSLANG_SJIS) MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1, - FileNameW, sizeof(FileNameW)/sizeof(TCHAR)); + FileNameW, sizeof(FileNameW)/sizeof(UINT16)); +#else + ucscnv_utf8toucs2(FileNameW, sizeof(FileNameW)/sizeof(UINT16), + lpFileName, (UINT)-1); +#endif return(DeleteFile(FileNameW)); } static inline DWORD GetFileAttributes_A(LPCSTR lpFileName) { - TCHAR FileNameW[MAX_PATH*2]; + UINT16 FileNameW[MAX_PATH]; +#if defined(OSLANG_SJIS) MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1, - FileNameW, sizeof(FileNameW)/sizeof(TCHAR)); + FileNameW, sizeof(FileNameW)/sizeof(UINT16)); +#else + ucscnv_utf8toucs2(FileNameW, sizeof(FileNameW)/sizeof(UINT16), + lpFileName, (UINT)-1); +#endif return(GetFileAttributes(FileNameW)); } static inline BOOL CreateDirectory_A(LPCSTR lpFileName, LPSECURITY_ATTRIBUTES atr) { - TCHAR FileNameW[MAX_PATH*2]; + UINT16 FileNameW[MAX_PATH]; +#if defined(OSLANG_SJIS) MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1, - FileNameW, sizeof(FileNameW)/sizeof(TCHAR)); + FileNameW, sizeof(FileNameW)/sizeof(UINT16)); +#else + ucscnv_utf8toucs2(FileNameW, sizeof(FileNameW)/sizeof(UINT16), + lpFileName, (UINT)-1); +#endif return(CreateDirectory(FileNameW, atr)); } static inline HANDLE FindFirstFile_A(LPCSTR lpFileName, WIN32_FIND_DATA *w32fd) { - TCHAR FileNameW[MAX_PATH*2]; + UINT16 FileNameW[MAX_PATH]; +#if defined(OSLANG_SJIS) MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1, - FileNameW, sizeof(FileNameW)/sizeof(TCHAR)); + FileNameW, sizeof(FileNameW)/sizeof(UINT16)); +#else + ucscnv_utf8toucs2(FileNameW, sizeof(FileNameW)/sizeof(UINT16), + lpFileName, (UINT)-1); +#endif return(FindFirstFile(FileNameW, w32fd)); } #else @@ -162,26 +187,35 @@ UINT file_getsize(FILEH handle) { return(GetFileSize(handle, NULL)); } -short file_getdatetime(FILEH handle, DOSDATE *dosdate, DOSTIME *dostime) { +static BOOL cnvdatetime(FILETIME *file, DOSDATE *dosdate, DOSTIME *dostime) { - FILETIME lastwrite; - FILETIME localwrite; - SYSTEMTIME syswrite; + FILETIME localtime; + SYSTEMTIME systime; - if ((GetFileTime(handle, NULL, NULL, &lastwrite) == 0) || - (FileTimeToLocalFileTime(&lastwrite, &localwrite) == 0) || - (FileTimeToSystemTime(&localwrite, &syswrite) == 0)) { - return(-1); + if ((FileTimeToLocalFileTime(file, &localtime) == 0) || + (FileTimeToSystemTime(&localtime, &systime) == 0)) { + return(FAILURE); } if (dosdate) { - dosdate->year = (WORD)syswrite.wYear; - dosdate->month = (BYTE)syswrite.wMonth; - dosdate->day = (BYTE)syswrite.wDay; + dosdate->year = (UINT16)systime.wYear; + dosdate->month = (UINT8)systime.wMonth; + dosdate->day = (UINT8)systime.wDay; } if (dostime) { - dostime->hour = (BYTE)syswrite.wHour; - dostime->minute = (BYTE)syswrite.wMinute; - dostime->second = (BYTE)syswrite.wSecond; + dostime->hour = (UINT8)systime.wHour; + dostime->minute = (UINT8)systime.wMinute; + dostime->second = (UINT8)systime.wSecond; + } + return(SUCCESS); +} + +short file_getdatetime(FILEH handle, DOSDATE *dosdate, DOSTIME *dostime) { + + FILETIME lastwrite; + + if ((GetFileTime(handle, NULL, NULL, &lastwrite) == 0) || + (cnvdatetime(&lastwrite, dosdate, dostime) != SUCCESS)) { + return(-1); } return(0); } @@ -253,139 +287,134 @@ short file_attr_c(const char *path) { } -FILEFINDH file_find1st(const char *path, FILEFINDT *fft) { +static BOOL setflist(WIN32_FIND_DATA *w32fd, FLINFO *fli) { +#if defined(UNICODE) && defined(OSLANG_SJIS) + WideCharToMultiByte(CP_ACP, 0, w32fd->cFileName, -1, + fli->path, sizeof(fli->path), NULL, NULL); +#elif defined(UNICODE) && defined(OSLANG_UTF8) + ucscnv_ucs2toutf8(fli->path, sizeof(fli->path), w32fd->cFileName, -1); +#else + milstr_ncpy(fli->path, w32fd->cFileName, sizeof(fli->path)); +#endif +#if !defined(_WIN32_WCE) + if ((w32fd->dwFileAttributes & FILEATTR_DIRECTORY) && + ((!file_cmpname(fli->path, ".")) || + (!file_cmpname(fli->path, "..")))) { + return(FAILURE); + } +#endif + fli->caps = FLICAPS_SIZE | FLICAPS_ATTR | FLICAPS_DATE | FLICAPS_TIME; + fli->size = w32fd->nFileSizeLow; + fli->attr = w32fd->dwFileAttributes; + cnvdatetime(&w32fd->ftLastWriteTime, &fli->date, &fli->time); + return(SUCCESS); +} + +FLISTH file_list1st(const char *dir, FLINFO *fli) { + + char path[MAX_PATH]; HANDLE hdl; WIN32_FIND_DATA w32fd; + milsjis_ncpy(path, dir, sizeof(path)); + file_setseparator(path, sizeof(path)); + milsjis_ncat(path, "*.*", sizeof(path)); + TRACEOUT(("file_list1st %s", path)); hdl = FindFirstFile_A(path, &w32fd); - if (hdl == INVALID_HANDLE_VALUE) { - return(FILEFINDH_INVALID); - } - if (fft) { -#if defined(UNICODE) - WideCharToMultiByte(CP_ACP, 0, w32fd.cFileName, -1, - fft->path, sizeof(fft->path), NULL, NULL); -#else - milstr_ncpy(fft->path, w32fd.cFileName, sizeof(fft->path)); -#endif - fft->size = w32fd.nFileSizeLow; - fft->attr = w32fd.dwFileAttributes; + if (hdl != INVALID_HANDLE_VALUE) { + do { + if (setflist(&w32fd, fli) == SUCCESS) { + return(hdl); + } + } while(FindNextFile(hdl, &w32fd)); + FindClose(hdl); } - return(hdl); + return(FLISTH_INVALID); } -BOOL file_findnext(FILEFINDH hdl, FILEFINDT *fft) { +BOOL file_listnext(FLISTH hdl, FLINFO *fli) { WIN32_FIND_DATA w32fd; - if (!FindNextFile(hdl, &w32fd)) { - return(FAILURE); - } - if (fft) { -#if defined(UNICODE) - WideCharToMultiByte(CP_ACP, 0, w32fd.cFileName, -1, - fft->path, sizeof(fft->path), NULL, NULL); -#else - milstr_ncpy(fft->path, w32fd.cFileName, sizeof(fft->path)); -#endif - fft->size = w32fd.nFileSizeLow; - fft->attr = w32fd.dwFileAttributes; + while(FindNextFile(hdl, &w32fd)) { + if (setflist(&w32fd, fli) == SUCCESS) { + return(SUCCESS); + } } - return(SUCCESS); + return(FAILURE); } -void file_findclose(FILEFINDH hdl) { +void file_listclose(FLISTH hdl) { - if (hdl) { - FindClose(hdl); - } + FindClose(hdl); } -char *file_getname(char *path) { +OEMCHAR *file_getname(const OEMCHAR *path) { - char *ret; + int csize; +const OEMCHAR *ret; ret = path; - while(*path != '\0') { - if (!ISKANJI(*path)) { - if ((*path == '\\') || (*path == '/') || (*path == ':')) { - ret = path + 1; - } + while((csize = milstr_charsize(path)) != 0) { + if ((csize == 1) && + ((*path == '\\') || (*path == '/') || (*path == ':'))) { + ret = path + 1; } - else { - if (path[1]) { - path++; - } - } - path++; + path += csize; } - return(ret); + return((OEMCHAR *)ret); } -void file_cutname(char *path) { +void file_cutname(OEMCHAR *path) { - char *p; + OEMCHAR *p; p = file_getname(path); p[0] = '\0'; } -char *file_getext(char *path) { +OEMCHAR *file_getext(const OEMCHAR *path) { - char *p; - char *q; + OEMCHAR *p; + OEMCHAR *q; + int csize; p = file_getname(path); q = NULL; - - while(*p != '\0') { - if (!ISKANJI(*p)) { - if (*p == '.') { - q = p + 1; - } - } - else { - if (p[1]) { - p++; - } + while((csize = milstr_charsize(p)) != 0) { + if ((csize == 1) && (*p == '.')) { + q = p + 1; } - p++; + p += csize; } if (!q) { q = p; } - return(q); + return((OEMCHAR *)q); } -void file_cutext(char *path) { +void file_cutext(OEMCHAR *path) { - char *p; - char *q; + OEMCHAR *p; + OEMCHAR *q; + int csize; p = file_getname(path); q = NULL; - - while(*p != '\0') { - if (!ISKANJI(*p)) { - if (*p == '.') { - q = p; - } - } - else { - if (p[1]) { - p++; - } + while((csize = milstr_charsize(p)) != 0) { + if ((csize == 1) && (*p == '.')) { + q = p + 1; } - p++; + p += csize; } if (q) { *q = '\0'; } } -void file_cutseparator(char *path) { +void file_cutseparator(OEMCHAR *path) { int pos; @@ -399,7 +428,7 @@ void file_cutseparator(char *path) { } } -void file_setseparator(char *path, int maxlen) { +void file_setseparator(OEMCHAR *path, int maxlen) { int pos;