|
|
| version 1.6, 2004/06/20 02:57:47 | version 1.11, 2005/03/24 04:40:33 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #if defined(UNICODE) && defined(OSLANG_UTF8) | |
| #include "codecnv.h" | |
| #endif | |
| #include "dosio.h" | #include "dosio.h" |
| static OEMCHAR curpath[MAX_PATH]; | static OEMCHAR curpath[MAX_PATH]; |
| static OEMCHAR *curfilep = curpath; | static OEMCHAR *curfilep = curpath; |
| // #define ISKANJI(c) (((((c) ^ 0x20) - 0xa1) & 0xff) < 0x3c) | |
| #if defined(UNICODE) | |
| static HANDLE CreateFile_A(LPCSTR lpFileName, | |
| DWORD dwDesiredAccess, | |
| DWORD dwShareMode, | |
| LPSECURITY_ATTRIBUTES lpSecurityAttributes, | |
| DWORD dwCreationDisposition, | |
| DWORD dwFlagsAndAttributes, | |
| HANDLE hTemplateFile) { | |
| UINT16 FileNameW[MAX_PATH]; | |
| #if defined(OSLANG_SJIS) | |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1, | |
| 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)); | |
| } | |
| static inline BOOL DeleteFile_A(LPCSTR lpFileName) { | |
| UINT16 FileNameW[MAX_PATH]; | |
| #if defined(OSLANG_SJIS) | |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1, | |
| 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) { | |
| UINT16 FileNameW[MAX_PATH]; | |
| #if defined(OSLANG_SJIS) | |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1, | |
| 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) { | |
| UINT16 FileNameW[MAX_PATH]; | |
| #if defined(OSLANG_SJIS) | |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1, | |
| 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) { | |
| UINT16 FileNameW[MAX_PATH]; | |
| #if defined(OSLANG_SJIS) | |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1, | |
| FileNameW, sizeof(FileNameW)/sizeof(UINT16)); | |
| #else | |
| ucscnv_utf8toucs2(FileNameW, sizeof(FileNameW)/sizeof(UINT16), | |
| lpFileName, (UINT)-1); | |
| #endif | |
| return(FindFirstFile(FileNameW, w32fd)); | |
| } | |
| #else | |
| #define CreateFile_A(a, b, c, d, e, f, g) \ | |
| CreateFile(a, b, c, d, e, f, g) | |
| #define DeleteFile_A(a) DeleteFile(a) | |
| #define GetFileAttributes_A(a) GetFileAttributes(a) | |
| #define CreateDirectory_A(a, b) CreateDirectory(a, b) | |
| #define FindFirstFile_A(a, b) FindFirstFile(a, b) | |
| #endif | |
| // ---- | // ---- |
| void dosio_init(void) { } | void dosio_init(void) { } |
| void dosio_term(void) { } | void dosio_term(void) { } |
| // ファイル操作 | // ファイル操作 |
| FILEH file_open(const char *path) { | FILEH file_open(const OEMCHAR *path) { |
| FILEH ret; | FILEH ret; |
| if ((ret = CreateFile_A(path, GENERIC_READ | GENERIC_WRITE, | #if defined(UNICODE) && defined(OSLANG_SJIS) |
| 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) | UINT16 oempath[MAX_PATH]; |
| == INVALID_HANDLE_VALUE) { | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, |
| if ((ret = CreateFile_A(path, GENERIC_READ, | oempath, NELEMENTS(oempath)); |
| 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) | #elif defined(UNICODE) && defined(OSLANG_UTF8) |
| == INVALID_HANDLE_VALUE) { | UINT16 oempath[MAX_PATH]; |
| codecnv_utf8toucs2(oempath, NELEMENTS(oempath), path, (UINT)-1); | |
| #else | |
| const OEMCHAR *oempath; | |
| oempath = path; | |
| #endif | |
| ret = CreateFile(oempath, GENERIC_READ | GENERIC_WRITE, | |
| 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |
| if (ret == INVALID_HANDLE_VALUE) { | |
| ret = CreateFile(oempath, GENERIC_READ, | |
| 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |
| if (ret == INVALID_HANDLE_VALUE) { | |
| return(FILEH_INVALID); | return(FILEH_INVALID); |
| } | } |
| } | } |
| return(ret); | return(ret); |
| } | } |
| FILEH file_open_rb(const char *path) { | FILEH file_open_rb(const OEMCHAR *path) { |
| FILEH ret; | FILEH ret; |
| if ((ret = CreateFile_A(path, GENERIC_READ, FILE_SHARE_READ, 0, | #if defined(UNICODE) && defined(OSLANG_SJIS) |
| OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) | UINT16 oempath[MAX_PATH]; |
| == INVALID_HANDLE_VALUE) { | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, |
| oempath, NELEMENTS(oempath)); | |
| #elif defined(UNICODE) && defined(OSLANG_UTF8) | |
| UINT16 oempath[MAX_PATH]; | |
| codecnv_utf8toucs2(oempath, NELEMENTS(oempath), path, (UINT)-1); | |
| #else | |
| const OEMCHAR *oempath; | |
| oempath = path; | |
| #endif | |
| ret = CreateFile(oempath, GENERIC_READ, FILE_SHARE_READ, 0, | |
| OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |
| if (ret != INVALID_HANDLE_VALUE) { | |
| return(ret); | |
| } | |
| else { | |
| return(FILEH_INVALID); | return(FILEH_INVALID); |
| } | } |
| return(ret); | |
| } | } |
| FILEH file_create(const char *path) { | FILEH file_create(const OEMCHAR *path) { |
| FILEH ret; | FILEH ret; |
| if ((ret = CreateFile_A(path, GENERIC_READ | GENERIC_WRITE, | #if defined(UNICODE) && defined(OSLANG_SJIS) |
| 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) | UINT16 oempath[MAX_PATH]; |
| == INVALID_HANDLE_VALUE) { | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, |
| oempath, NELEMENTS(oempath)); | |
| #elif defined(UNICODE) && defined(OSLANG_UTF8) | |
| UINT16 oempath[MAX_PATH]; | |
| codecnv_utf8toucs2(oempath, NELEMENTS(oempath), path, (UINT)-1); | |
| #else | |
| const OEMCHAR *oempath; | |
| oempath = path; | |
| #endif | |
| ret = CreateFile(oempath, GENERIC_READ | GENERIC_WRITE, | |
| 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | |
| if (ret != INVALID_HANDLE_VALUE) { | |
| return(ret); | |
| } | |
| else { | |
| return(FILEH_INVALID); | return(FILEH_INVALID); |
| } | } |
| return(ret); | |
| } | } |
| long file_seek(FILEH handle, long pointer, int method) { | long file_seek(FILEH handle, long pointer, int method) { |
| Line 220 short file_getdatetime(FILEH handle, DOS | Line 169 short file_getdatetime(FILEH handle, DOS |
| return(0); | return(0); |
| } | } |
| short file_delete(const char *path) { | short file_delete(const OEMCHAR *path) { |
| return(DeleteFile_A(path)?0:-1); | #if defined(UNICODE) && defined(OSLANG_SJIS) |
| UINT16 oempath[MAX_PATH]; | |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, | |
| oempath, NELEMENTS(oempath)); | |
| #elif defined(UNICODE) && defined(OSLANG_UTF8) | |
| UINT16 oempath[MAX_PATH]; | |
| codecnv_utf8toucs2(oempath, NELEMENTS(oempath), path, (UINT)-1); | |
| #else | |
| const OEMCHAR *oempath; | |
| oempath = path; | |
| #endif | |
| return(DeleteFile(oempath)?0:-1); | |
| } | } |
| short file_attr(const char *path) { | short file_attr(const OEMCHAR *path) { |
| return((short)GetFileAttributes_A(path)); | #if defined(UNICODE) && defined(OSLANG_SJIS) |
| UINT16 oempath[MAX_PATH]; | |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, | |
| oempath, NELEMENTS(oempath)); | |
| #elif defined(UNICODE) && defined(OSLANG_UTF8) | |
| UINT16 oempath[MAX_PATH]; | |
| codecnv_utf8toucs2(oempath, NELEMENTS(oempath), path, (UINT)-1); | |
| #else | |
| const OEMCHAR *oempath; | |
| oempath = path; | |
| #endif | |
| return((short)GetFileAttributes(oempath)); | |
| } | } |
| short file_dircreate(const char *path) { | short file_dircreate(const OEMCHAR *path) { |
| return(CreateDirectory_A(path, NULL)?0:-1); | #if defined(UNICODE) && defined(OSLANG_SJIS) |
| UINT16 oempath[MAX_PATH]; | |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, | |
| oempath, NELEMENTS(oempath)); | |
| #elif defined(UNICODE) && defined(OSLANG_UTF8) | |
| UINT16 oempath[MAX_PATH]; | |
| codecnv_utf8toucs2(oempath, NELEMENTS(oempath), path, (UINT)-1); | |
| #else | |
| const OEMCHAR *oempath; | |
| oempath = path; | |
| #endif | |
| return(CreateDirectory(oempath, NULL)?0:-1); | |
| } | } |
| // カレントファイル操作 | // カレントファイル操作 |
| void file_setcd(const char *exepath) { | void file_setcd(const OEMCHAR *exepath) { |
| file_cpyname(curpath, exepath, sizeof(curpath)); | file_cpyname(curpath, exepath, NELEMENTS(curpath)); |
| curfilep = file_getname(curpath); | curfilep = file_getname(curpath); |
| *curfilep = '\0'; | *curfilep = '\0'; |
| } | } |
| char *file_getcd(const char *path) { | OEMCHAR *file_getcd(const OEMCHAR *path) { |
| *curfilep = '\0'; | file_cpyname(curfilep, path, NELEMENTS(curpath) - (curfilep - curpath)); |
| file_catname(curpath, path, sizeof(curpath)); | |
| return(curpath); | return(curpath); |
| } | } |
| FILEH file_open_c(const char *path) { | FILEH file_open_c(const OEMCHAR *path) { |
| *curfilep = '\0'; | file_cpyname(curfilep, path, NELEMENTS(curpath) - (curfilep - curpath)); |
| file_catname(curpath, path, sizeof(curpath)); | |
| return(file_open(curpath)); | return(file_open(curpath)); |
| } | } |
| FILEH file_open_rb_c(const char *path) { | FILEH file_open_rb_c(const OEMCHAR *path) { |
| *curfilep = '\0'; | file_cpyname(curfilep, path, NELEMENTS(curpath) - (curfilep - curpath)); |
| file_catname(curpath, path, sizeof(curpath)); | |
| return(file_open_rb(curpath)); | return(file_open_rb(curpath)); |
| } | } |
| FILEH file_create_c(const char *path) { | FILEH file_create_c(const OEMCHAR *path) { |
| *curfilep = '\0'; | file_cpyname(curfilep, path, NELEMENTS(curpath) - (curfilep - curpath)); |
| file_catname(curpath, path, sizeof(curpath)); | |
| return(file_create(curpath)); | return(file_create(curpath)); |
| } | } |
| short file_delete_c(const char *path) { | short file_delete_c(const OEMCHAR *path) { |
| *curfilep = '\0'; | file_cpyname(curfilep, path, NELEMENTS(curpath) - (curfilep - curpath)); |
| file_catname(curpath, path, sizeof(curpath)); | |
| return(file_delete(curpath)); | return(file_delete(curpath)); |
| } | } |
| short file_attr_c(const char *path) { | short file_attr_c(const OEMCHAR *path) { |
| *curfilep = '\0'; | file_cpyname(curfilep, path, NELEMENTS(curpath) - (curfilep - curpath)); |
| file_catname(curpath, path, sizeof(curpath)); | |
| return(file_attr(curpath)); | return(file_attr(curpath)); |
| } | } |
| static BOOL setflist(WIN32_FIND_DATA *w32fd, FLINFO *fli) { | // ---- |
| #if !defined(_WIN32_WCE) | |
| static const OEMCHAR str_selfdir[] = OEMTEXT("."); | |
| static const OEMCHAR str_parentdir[] = OEMTEXT(".."); | |
| #endif | |
| static const OEMCHAR str_wildcard[] = OEMTEXT("*.*"); | |
| static BRESULT setflist(WIN32_FIND_DATA *w32fd, FLINFO *fli) { | |
| #if defined(UNICODE) && defined(OSLANG_SJIS) | #if defined(UNICODE) && defined(OSLANG_SJIS) |
| WideCharToMultiByte(CP_ACP, 0, w32fd->cFileName, -1, | WideCharToMultiByte(CP_ACP, 0, w32fd->cFileName, -1, |
| fli->path, sizeof(fli->path), NULL, NULL); | fli->path, NELEMENTS(fli->path), NULL, NULL); |
| #elif defined(UNICODE) && defined(OSLANG_UTF8) | #elif defined(UNICODE) && defined(OSLANG_UTF8) |
| ucscnv_ucs2toutf8(fli->path, sizeof(fli->path), w32fd->cFileName, -1); | codecnv_ucs2toutf8(fli->path, NELEMENTS(fli->path), w32fd->cFileName, -1); |
| #else | #else |
| milstr_ncpy(fli->path, w32fd->cFileName, sizeof(fli->path)); | file_cpyname(fli->path, w32fd->cFileName, NELEMENTS(fli->path)); |
| #endif | #endif |
| #if !defined(_WIN32_WCE) | #if !defined(_WIN32_WCE) |
| if ((w32fd->dwFileAttributes & FILEATTR_DIRECTORY) && | if ((w32fd->dwFileAttributes & FILEATTR_DIRECTORY) && |
| ((!file_cmpname(fli->path, ".")) || | ((!file_cmpname(fli->path, str_selfdir)) || |
| (!file_cmpname(fli->path, "..")))) { | (!file_cmpname(fli->path, str_parentdir)))) { |
| return(FAILURE); | return(FAILURE); |
| } | } |
| #endif | #endif |
| Line 311 static BOOL setflist(WIN32_FIND_DATA *w3 | Line 295 static BOOL setflist(WIN32_FIND_DATA *w3 |
| return(SUCCESS); | return(SUCCESS); |
| } | } |
| FLISTH file_list1st(const char *dir, FLINFO *fli) { | FLISTH file_list1st(const OEMCHAR *dir, FLINFO *fli) { |
| char path[MAX_PATH]; | OEMCHAR path[MAX_PATH]; |
| HANDLE hdl; | HANDLE hdl; |
| WIN32_FIND_DATA w32fd; | WIN32_FIND_DATA w32fd; |
| milsjis_ncpy(path, dir, sizeof(path)); | file_cpyname(path, dir, NELEMENTS(path)); |
| file_setseparator(path, sizeof(path)); | file_setseparator(path, NELEMENTS(path)); |
| milsjis_ncat(path, "*.*", sizeof(path)); | file_catname(path, str_wildcard, NELEMENTS(path)); |
| TRACEOUT(("file_list1st %s", path)); | TRACEOUT(("file_list1st %s", path)); |
| hdl = FindFirstFile_A(path, &w32fd); | |
| #if defined(UNICODE) && defined(OSLANG_SJIS) | |
| UINT16 ucs2[MAX_PATH]; | |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, | |
| ucs2, NELEMENTS(ucs2)); | |
| hdl = FindFirstFile(ucs2, &w32fd); | |
| #elif defined(UNICODE) && defined(OSLANG_UTF8) | |
| UINT16 ucs2[MAX_PATH]; | |
| codecnv_utf8toucs2(ucs2, NELEMENTS(ucs2), path, (UINT)-1); | |
| hdl = FindFirstFile(ucs2, &w32fd); | |
| #else | |
| hdl = FindFirstFile(path, &w32fd); | |
| #endif | |
| if (hdl != INVALID_HANDLE_VALUE) { | if (hdl != INVALID_HANDLE_VALUE) { |
| do { | do { |
| if (setflist(&w32fd, fli) == SUCCESS) { | if (setflist(&w32fd, fli) == SUCCESS) { |
| Line 405 void file_cutext(OEMCHAR *path) { | Line 401 void file_cutext(OEMCHAR *path) { |
| q = NULL; | q = NULL; |
| while((csize = milstr_charsize(p)) != 0) { | while((csize = milstr_charsize(p)) != 0) { |
| if ((csize == 1) && (*p == '.')) { | if ((csize == 1) && (*p == '.')) { |
| q = p + 1; | q = p; |
| } | } |
| p += csize; | p += csize; |
| } | } |
| Line 418 void file_cutseparator(OEMCHAR *path) { | Line 414 void file_cutseparator(OEMCHAR *path) { |
| int pos; | int pos; |
| pos = strlen(path) - 1; | pos = OEMSTRLEN(path) - 1; |
| if ((pos > 0) && // 2文字以上でー | if ((pos > 0) && // 2文字以上でー |
| (path[pos] == '\\') && // ケツが \ でー | (path[pos] == '\\') && // ケツが \ でー |
| (!milstr_kanji2nd(path, pos)) && // 漢字の2バイト目ぢゃなくてー | (!milstr_kanji2nd(path, pos)) && // 漢字の2バイト目ぢゃなくてー |
| Line 432 void file_setseparator(OEMCHAR *path, in | Line 428 void file_setseparator(OEMCHAR *path, in |
| int pos; | int pos; |
| pos = strlen(path) - 1; | pos = OEMSTRLEN(path) - 1; |
| if ((pos < 0) || | if ((pos < 0) || |
| ((pos == 1) && (path[1] == ':')) || | ((pos == 1) && (path[1] == ':')) || |
| ((path[pos] == '\\') && (!milstr_kanji2nd(path, pos))) || | ((path[pos] == '\\') && (!milstr_kanji2nd(path, pos))) || |