|
|
| version 1.7, 2004/06/20 04:32:18 | 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" |
| Line 11 static OEMCHAR *curfilep = curpath; | Line 14 static OEMCHAR *curfilep = curpath; |
| void dosio_init(void) { } | void dosio_init(void) { } |
| void dosio_term(void) { } | void dosio_term(void) { } |
| // ファイル操作 | |
| #if defined(UNICODE) && defined(OSLANG_SJIS) | |
| static HANDLE _CreateFile(const OEMCHAR *lpFileName, | |
| DWORD dwDesiredAccess, | |
| DWORD dwShareMode, | |
| LPSECURITY_ATTRIBUTES lpSecurityAttributes, | |
| DWORD dwCreationDisposition, | |
| DWORD dwFlagsAndAttributes, | |
| HANDLE hTemplateFile) { | |
| UINT16 ucs2[MAX_PATH]; | |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1, | // ファイル操作 |
| ucs2, NELEMENTS(ucs2)); | FILEH file_open(const OEMCHAR *path) { |
| return(CreateFile(ucs2, dwDesiredAccess, dwShareMode, | |
| lpSecurityAttributes, dwCreationDisposition, | |
| dwFlagsAndAttributes, hTemplateFile)); | |
| } | |
| #elif defined(OSLANG_UTF8) | |
| static HANDLE _CreateFile(const OEMCHAR *lpFileName, | |
| DWORD dwDesiredAccess, | |
| DWORD dwShareMode, | |
| LPSECURITY_ATTRIBUTES lpSecurityAttributes, | |
| DWORD dwCreationDisposition, | |
| DWORD dwFlagsAndAttributes, | |
| HANDLE hTemplateFile) { | |
| UINT16 ucs2[MAX_PATH]; | FILEH ret; |
| ucscnv_utf8toucs2(ucs2, NELEMENTS(ucs2), lpFileName, (UINT)-1); | #if defined(UNICODE) && defined(OSLANG_SJIS) |
| return(CreateFile(ucs2, dwDesiredAccess, dwShareMode, | UINT16 oempath[MAX_PATH]; |
| lpSecurityAttributes, dwCreationDisposition, | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, |
| dwFlagsAndAttributes, hTemplateFile)); | oempath, NELEMENTS(oempath)); |
| } | #elif defined(UNICODE) && defined(OSLANG_UTF8) |
| UINT16 oempath[MAX_PATH]; | |
| codecnv_utf8toucs2(oempath, NELEMENTS(oempath), path, (UINT)-1); | |
| #else | #else |
| #define _CreateFile(a, b, c, d, e, f, g) CreateFile(a, b, c, d, e, f, g) | const OEMCHAR *oempath; |
| oempath = path; | |
| #endif | #endif |
| ret = CreateFile(oempath, GENERIC_READ | GENERIC_WRITE, | |
| FILEH file_open(const OEMCHAR *path) { | 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| if (ret == INVALID_HANDLE_VALUE) { | |
| FILEH ret; | ret = CreateFile(oempath, GENERIC_READ, |
| 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |
| if ((ret = _CreateFile(path, GENERIC_READ | GENERIC_WRITE, | if (ret == INVALID_HANDLE_VALUE) { |
| 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) | |
| == INVALID_HANDLE_VALUE) { | |
| if ((ret = _CreateFile(path, GENERIC_READ, | |
| 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) | |
| == INVALID_HANDLE_VALUE) { | |
| return(FILEH_INVALID); | return(FILEH_INVALID); |
| } | } |
| } | } |
| Line 70 FILEH file_open_rb(const OEMCHAR *path) | Line 48 FILEH file_open_rb(const OEMCHAR *path) |
| FILEH ret; | FILEH ret; |
| if ((ret = _CreateFile(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 OEMCHAR *path) { | FILEH file_create(const OEMCHAR *path) { |
| FILEH ret; | FILEH ret; |
| if ((ret = _CreateFile(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 167 short file_getdatetime(FILEH handle, DOS | Line 172 short file_getdatetime(FILEH handle, DOS |
| short file_delete(const OEMCHAR *path) { | short file_delete(const OEMCHAR *path) { |
| #if defined(UNICODE) && defined(OSLANG_SJIS) | #if defined(UNICODE) && defined(OSLANG_SJIS) |
| UINT16 ucs2[MAX_PATH]; | UINT16 oempath[MAX_PATH]; |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, |
| ucs2, NELEMENTS(ucs2)); | oempath, NELEMENTS(oempath)); |
| return(DeleteFile(ucs2)?0:-1); | #elif defined(UNICODE) && defined(OSLANG_UTF8) |
| #elif defined(OSLANG_UTF8) | UINT16 oempath[MAX_PATH]; |
| UINT16 ucs2[MAX_PATH]; | codecnv_utf8toucs2(oempath, NELEMENTS(oempath), path, (UINT)-1); |
| ucscnv_utf8toucs2(ucs2, NELEMENTS(ucs2), path, (UINT)-1); | |
| return(DeleteFile(ucs2)?0:-1); | |
| #else | #else |
| return(DeleteFile(path)?0:-1); | const OEMCHAR *oempath; |
| oempath = path; | |
| #endif | #endif |
| return(DeleteFile(oempath)?0:-1); | |
| } | } |
| short file_attr(const OEMCHAR *path) { | short file_attr(const OEMCHAR *path) { |
| #if defined(UNICODE) && defined(OSLANG_SJIS) | #if defined(UNICODE) && defined(OSLANG_SJIS) |
| UINT16 ucs2[MAX_PATH]; | UINT16 oempath[MAX_PATH]; |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, |
| ucs2, NELEMENTS(ucs2)); | oempath, NELEMENTS(oempath)); |
| return((short)GetFileAttributes(ucs2)); | #elif defined(UNICODE) && defined(OSLANG_UTF8) |
| #elif defined(OSLANG_UTF8) | UINT16 oempath[MAX_PATH]; |
| UINT16 ucs2[MAX_PATH]; | codecnv_utf8toucs2(oempath, NELEMENTS(oempath), path, (UINT)-1); |
| ucscnv_utf8toucs2(ucs2, NELEMENTS(ucs2), path, (UINT)-1); | |
| return((short)GetFileAttributes(ucs2)); | |
| #else | #else |
| return((short)GetFileAttributes(path)); | const OEMCHAR *oempath; |
| oempath = path; | |
| #endif | #endif |
| return((short)GetFileAttributes(oempath)); | |
| } | } |
| short file_dircreate(const OEMCHAR *path) { | short file_dircreate(const OEMCHAR *path) { |
| #if defined(UNICODE) && defined(OSLANG_SJIS) | #if defined(UNICODE) && defined(OSLANG_SJIS) |
| UINT16 ucs2[MAX_PATH]; | UINT16 oempath[MAX_PATH]; |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, |
| ucs2, NELEMENTS(ucs2)); | oempath, NELEMENTS(oempath)); |
| return(CreateDirectory(ucs2, NULL)?0:-1); | #elif defined(UNICODE) && defined(OSLANG_UTF8) |
| #elif defined(OSLANG_UTF8) | UINT16 oempath[MAX_PATH]; |
| UINT16 ucs2[MAX_PATH]; | codecnv_utf8toucs2(oempath, NELEMENTS(oempath), path, (UINT)-1); |
| ucscnv_utf8toucs2(ucs2, NELEMENTS(ucs2), path, (UINT)-1); | |
| return(CreateDirectory(ucs2, NULL)?0:-1); | |
| #else | #else |
| return(CreateDirectory(path, NULL)?0:-1); | const OEMCHAR *oempath; |
| oempath = path; | |
| #endif | #endif |
| return(CreateDirectory(oempath, NULL)?0:-1); | |
| } | } |
| Line 221 void file_setcd(const OEMCHAR *exepath) | Line 226 void file_setcd(const OEMCHAR *exepath) |
| *curfilep = '\0'; | *curfilep = '\0'; |
| } | } |
| char *file_getcd(const OEMCHAR *path) { | OEMCHAR *file_getcd(const OEMCHAR *path) { |
| file_cpyname(curfilep, path, NELEMENTS(curpath) - (curfilep - curpath)); | file_cpyname(curfilep, path, NELEMENTS(curpath) - (curfilep - curpath)); |
| return(curpath); | return(curpath); |
| Line 266 static const OEMCHAR str_parentdir[] = O | Line 271 static const OEMCHAR str_parentdir[] = O |
| #endif | #endif |
| static const OEMCHAR str_wildcard[] = OEMTEXT("*.*"); | static const OEMCHAR str_wildcard[] = OEMTEXT("*.*"); |
| static BOOL setflist(WIN32_FIND_DATA *w32fd, FLINFO *fli) { | 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, NELEMENTS(fli->path), NULL, NULL); | fli->path, NELEMENTS(fli->path), NULL, NULL); |
| #elif defined(OSLANG_UTF8) | #elif defined(UNICODE) && defined(OSLANG_UTF8) |
| ucscnv_ucs2toutf8(fli->path, NELEMENTS(fli->path), w32fd->cFileName, -1); | codecnv_ucs2toutf8(fli->path, NELEMENTS(fli->path), w32fd->cFileName, -1); |
| #else | #else |
| file_cpyname(fli->path, w32fd->cFileName, NELEMENTS(fli->path)); | file_cpyname(fli->path, w32fd->cFileName, NELEMENTS(fli->path)); |
| #endif | #endif |
| Line 306 FLISTH file_list1st(const OEMCHAR *dir, | Line 311 FLISTH file_list1st(const OEMCHAR *dir, |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, |
| ucs2, NELEMENTS(ucs2)); | ucs2, NELEMENTS(ucs2)); |
| hdl = FindFirstFile(ucs2, &w32fd); | hdl = FindFirstFile(ucs2, &w32fd); |
| #elif defined(OSLANG_UTF8) | #elif defined(UNICODE) && defined(OSLANG_UTF8) |
| UINT16 ucs2[MAX_PATH]; | UINT16 ucs2[MAX_PATH]; |
| ucscnv_utf8toucs2(ucs2, NELEMENTS(ucs2), path, (UINT)-1); | codecnv_utf8toucs2(ucs2, NELEMENTS(ucs2), path, (UINT)-1); |
| hdl = FindFirstFile(ucs2, &w32fd); | hdl = FindFirstFile(ucs2, &w32fd); |
| #else | #else |
| hdl = FindFirstFile(path, &w32fd); | hdl = FindFirstFile(path, &w32fd); |
| Line 396 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 409 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 423 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))) || |