|
|
| version 1.7, 2004/06/20 04:32:18 | version 1.12, 2005/04/01 15:35:50 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #include "oemtext.h" | |
| #include "dosio.h" | #include "dosio.h" |
| Line 11 static OEMCHAR *curfilep = curpath; | Line 12 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)); | |
| 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]; | |
| ucscnv_utf8toucs2(ucs2, NELEMENTS(ucs2), lpFileName, (UINT)-1); | |
| return(CreateFile(ucs2, dwDesiredAccess, dwShareMode, | |
| lpSecurityAttributes, dwCreationDisposition, | |
| dwFlagsAndAttributes, hTemplateFile)); | |
| } | |
| #else | |
| #define _CreateFile(a, b, c, d, e, f, g) CreateFile(a, b, c, d, e, f, g) | |
| #endif | |
| // ファイル操作 | |
| FILEH file_open(const OEMCHAR *path) { | FILEH file_open(const OEMCHAR *path) { |
| FILEH ret; | #if defined(OEMCHAR_SAME_TCHAR) |
| const TCHAR *tcharpath = path; | |
| if ((ret = _CreateFile(path, GENERIC_READ | GENERIC_WRITE, | #else |
| 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) | TCHAR tcharpath[MAX_PATH]; |
| == INVALID_HANDLE_VALUE) { | oemtotchar(tcharpath, NELEMENTS(tcharpath), path, (UINT)-1); |
| if ((ret = _CreateFile(path, GENERIC_READ, | #endif |
| 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) | FILEH ret; |
| == INVALID_HANDLE_VALUE) { | ret = CreateFile(tcharpath, GENERIC_READ | GENERIC_WRITE, |
| 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |
| if (ret == INVALID_HANDLE_VALUE) { | |
| ret = CreateFile(tcharpath, GENERIC_READ, | |
| 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |
| if (ret == INVALID_HANDLE_VALUE) { | |
| return(FILEH_INVALID); | return(FILEH_INVALID); |
| } | } |
| } | } |
| Line 68 FILEH file_open(const OEMCHAR *path) { | Line 37 FILEH file_open(const OEMCHAR *path) { |
| FILEH file_open_rb(const OEMCHAR *path) { | FILEH file_open_rb(const OEMCHAR *path) { |
| FILEH ret; | #if defined(OEMCHAR_SAME_TCHAR) |
| const TCHAR *tcharpath = path; | |
| if ((ret = _CreateFile(path, GENERIC_READ, FILE_SHARE_READ, 0, | #else |
| OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) | TCHAR tcharpath[MAX_PATH]; |
| == INVALID_HANDLE_VALUE) { | oemtotchar(tcharpath, NELEMENTS(tcharpath), path, (UINT)-1); |
| #endif | |
| FILEH ret; | |
| ret = CreateFile(tcharpath, 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; | #if defined(OEMCHAR_SAME_TCHAR) |
| const TCHAR *tcharpath = path; | |
| if ((ret = _CreateFile(path, GENERIC_READ | GENERIC_WRITE, | #else |
| 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) | TCHAR tcharpath[MAX_PATH]; |
| == INVALID_HANDLE_VALUE) { | oemtotchar(tcharpath, NELEMENTS(tcharpath), path, (UINT)-1); |
| #endif | |
| FILEH ret; | |
| ret = CreateFile(tcharpath, 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 131 UINT file_getsize(FILEH handle) { | Line 114 UINT file_getsize(FILEH handle) { |
| return(GetFileSize(handle, NULL)); | return(GetFileSize(handle, NULL)); |
| } | } |
| static BOOL cnvdatetime(FILETIME *file, DOSDATE *dosdate, DOSTIME *dostime) { | static BRESULT cnvdatetime(const FILETIME *file, |
| DOSDATE *dosdate, DOSTIME *dostime) { | |
| FILETIME localtime; | FILETIME localtime; |
| SYSTEMTIME systime; | SYSTEMTIME systime; |
| Line 166 short file_getdatetime(FILEH handle, DOS | Line 150 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(OEMCHAR_SAME_TCHAR) |
| UINT16 ucs2[MAX_PATH]; | const TCHAR *tcharpath = path; |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, | |
| ucs2, NELEMENTS(ucs2)); | |
| return(DeleteFile(ucs2)?0:-1); | |
| #elif defined(OSLANG_UTF8) | |
| UINT16 ucs2[MAX_PATH]; | |
| ucscnv_utf8toucs2(ucs2, NELEMENTS(ucs2), path, (UINT)-1); | |
| return(DeleteFile(ucs2)?0:-1); | |
| #else | #else |
| return(DeleteFile(path)?0:-1); | TCHAR tcharpath[MAX_PATH]; |
| oemtotchar(tcharpath, NELEMENTS(tcharpath), path, (UINT)-1); | |
| #endif | #endif |
| return(DeleteFile(tcharpath)?0:-1); | |
| } | } |
| short file_attr(const OEMCHAR *path) { | short file_attr(const OEMCHAR *path) { |
| #if defined(UNICODE) && defined(OSLANG_SJIS) | #if defined(OEMCHAR_SAME_TCHAR) |
| UINT16 ucs2[MAX_PATH]; | const TCHAR *tcharpath = path; |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, | |
| ucs2, NELEMENTS(ucs2)); | |
| return((short)GetFileAttributes(ucs2)); | |
| #elif defined(OSLANG_UTF8) | |
| UINT16 ucs2[MAX_PATH]; | |
| ucscnv_utf8toucs2(ucs2, NELEMENTS(ucs2), path, (UINT)-1); | |
| return((short)GetFileAttributes(ucs2)); | |
| #else | #else |
| return((short)GetFileAttributes(path)); | TCHAR tcharpath[MAX_PATH]; |
| oemtotchar(tcharpath, NELEMENTS(tcharpath), path, (UINT)-1); | |
| #endif | #endif |
| return((short)GetFileAttributes(tcharpath)); | |
| } | } |
| short file_dircreate(const OEMCHAR *path) { | short file_dircreate(const OEMCHAR *path) { |
| #if defined(UNICODE) && defined(OSLANG_SJIS) | #if defined(OEMCHAR_SAME_TCHAR) |
| UINT16 ucs2[MAX_PATH]; | const TCHAR *tcharpath = path; |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, | |
| ucs2, NELEMENTS(ucs2)); | |
| return(CreateDirectory(ucs2, NULL)?0:-1); | |
| #elif defined(OSLANG_UTF8) | |
| UINT16 ucs2[MAX_PATH]; | |
| ucscnv_utf8toucs2(ucs2, NELEMENTS(ucs2), path, (UINT)-1); | |
| return(CreateDirectory(ucs2, NULL)?0:-1); | |
| #else | #else |
| return(CreateDirectory(path, NULL)?0:-1); | TCHAR tcharpath[MAX_PATH]; |
| oemtotchar(tcharpath, NELEMENTS(tcharpath), path, (UINT)-1); | |
| #endif | #endif |
| return(CreateDirectory(tcharpath, NULL)?0:-1); | |
| } | } |
| Line 221 void file_setcd(const OEMCHAR *exepath) | Line 190 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 261 short file_attr_c(const OEMCHAR *path) { | Line 230 short file_attr_c(const OEMCHAR *path) { |
| // ---- | // ---- |
| #if !defined(_WIN32_WCE) | #if !defined(_WIN32_WCE) |
| static const OEMCHAR str_selfdir[] = OEMTEXT("."); | static const TCHAR str_selfdir[] = _T("."); |
| static const OEMCHAR str_parentdir[] = OEMTEXT(".."); | static const TCHAR str_parentdir[] = _T(".."); |
| #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(const WIN32_FIND_DATA *w32fd, FLINFO *fli) { |
| #if defined(UNICODE) && defined(OSLANG_SJIS) | |
| WideCharToMultiByte(CP_ACP, 0, w32fd->cFileName, -1, | |
| fli->path, NELEMENTS(fli->path), NULL, NULL); | |
| #elif defined(OSLANG_UTF8) | |
| ucscnv_ucs2toutf8(fli->path, NELEMENTS(fli->path), w32fd->cFileName, -1); | |
| #else | |
| file_cpyname(fli->path, w32fd->cFileName, NELEMENTS(fli->path)); | |
| #endif | |
| #if !defined(_WIN32_WCE) | #if !defined(_WIN32_WCE) |
| if ((w32fd->dwFileAttributes & FILEATTR_DIRECTORY) && | if ((w32fd->dwFileAttributes & FILEATTR_DIRECTORY) && |
| ((!file_cmpname(fli->path, str_selfdir)) || | ((!lstrcmp(w32fd->cFileName, str_selfdir)) || |
| (!file_cmpname(fli->path, str_parentdir)))) { | (!lstrcmp(w32fd->cFileName, str_parentdir)))) { |
| return(FAILURE); | return(FAILURE); |
| } | } |
| #endif | #endif |
| Line 287 static BOOL setflist(WIN32_FIND_DATA *w3 | Line 248 static BOOL setflist(WIN32_FIND_DATA *w3 |
| fli->size = w32fd->nFileSizeLow; | fli->size = w32fd->nFileSizeLow; |
| fli->attr = w32fd->dwFileAttributes; | fli->attr = w32fd->dwFileAttributes; |
| cnvdatetime(&w32fd->ftLastWriteTime, &fli->date, &fli->time); | cnvdatetime(&w32fd->ftLastWriteTime, &fli->date, &fli->time); |
| #if defined(OEMCHAR_SAME_TCHAR) | |
| file_cpyname(fli->path, w32fd->cFileName, NELEMENTS(fli->path)); | |
| #else | |
| tchartooem(fli->path, NELEMENTS(fli->path), w32fd->cFileName, (UINT)-1); | |
| #endif | |
| return(SUCCESS); | return(SUCCESS); |
| } | } |
| FLISTH file_list1st(const OEMCHAR *dir, FLINFO *fli) { | FLISTH file_list1st(const OEMCHAR *dir, FLINFO *fli) { |
| OEMCHAR path[MAX_PATH]; | OEMCHAR path[MAX_PATH]; |
| HANDLE hdl; | |
| WIN32_FIND_DATA w32fd; | |
| file_cpyname(path, dir, NELEMENTS(path)); | file_cpyname(path, dir, NELEMENTS(path)); |
| file_setseparator(path, NELEMENTS(path)); | file_setseparator(path, NELEMENTS(path)); |
| file_catname(path, str_wildcard, NELEMENTS(path)); | file_catname(path, str_wildcard, NELEMENTS(path)); |
| TRACEOUT(("file_list1st %s", path)); | TRACEOUT(("file_list1st %s", path)); |
| #if defined(OEMCHAR_SAME_TCHAR) | |
| #if defined(UNICODE) && defined(OSLANG_SJIS) | const TCHAR *tcharpath = path; |
| UINT16 ucs2[MAX_PATH]; | |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, | |
| ucs2, NELEMENTS(ucs2)); | |
| hdl = FindFirstFile(ucs2, &w32fd); | |
| #elif defined(OSLANG_UTF8) | |
| UINT16 ucs2[MAX_PATH]; | |
| ucscnv_utf8toucs2(ucs2, NELEMENTS(ucs2), path, (UINT)-1); | |
| hdl = FindFirstFile(ucs2, &w32fd); | |
| #else | #else |
| hdl = FindFirstFile(path, &w32fd); | TCHAR tcharpath[MAX_PATH]; |
| oemtotchar(tcharpath, NELEMENTS(tcharpath), path, (UINT)-1); | |
| #endif | #endif |
| HANDLE hdl; | |
| WIN32_FIND_DATA w32fd; | |
| hdl = FindFirstFile(tcharpath, &w32fd); | |
| if (hdl != INVALID_HANDLE_VALUE) { | if (hdl != INVALID_HANDLE_VALUE) { |
| do { | do { |
| if (setflist(&w32fd, fli) == SUCCESS) { | if (setflist(&w32fd, fli) == SUCCESS) { |
| Line 324 FLISTH file_list1st(const OEMCHAR *dir, | Line 283 FLISTH file_list1st(const OEMCHAR *dir, |
| return(FLISTH_INVALID); | return(FLISTH_INVALID); |
| } | } |
| BOOL file_listnext(FLISTH hdl, FLINFO *fli) { | BRESULT file_listnext(FLISTH hdl, FLINFO *fli) { |
| WIN32_FIND_DATA w32fd; | WIN32_FIND_DATA w32fd; |
| Line 344 void file_listclose(FLISTH hdl) { | Line 303 void file_listclose(FLISTH hdl) { |
| OEMCHAR *file_getname(const OEMCHAR *path) { | OEMCHAR *file_getname(const OEMCHAR *path) { |
| int csize; | |
| const OEMCHAR *ret; | const OEMCHAR *ret; |
| int csize; | |
| ret = path; | ret = path; |
| while((csize = milstr_charsize(path)) != 0) { | while((csize = milstr_charsize(path)) != 0) { |
| Line 368 void file_cutname(OEMCHAR *path) { | Line 327 void file_cutname(OEMCHAR *path) { |
| OEMCHAR *file_getext(const OEMCHAR *path) { | OEMCHAR *file_getext(const OEMCHAR *path) { |
| OEMCHAR *p; | const OEMCHAR *p; |
| OEMCHAR *q; | const OEMCHAR *q; |
| int csize; | int csize; |
| p = file_getname(path); | p = file_getname(path); |
| q = NULL; | q = NULL; |
| Line 380 OEMCHAR *file_getext(const OEMCHAR *path | Line 339 OEMCHAR *file_getext(const OEMCHAR *path |
| } | } |
| p += csize; | p += csize; |
| } | } |
| if (!q) { | if (q == NULL) { |
| q = p; | q = p; |
| } | } |
| return((OEMCHAR *)q); | return((OEMCHAR *)q); |
| Line 396 void file_cutext(OEMCHAR *path) { | Line 355 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 368 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 382 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))) || |