Diff for /np2/wince/dosio.cpp between versions 1.1.1.1 and 1.7

version 1.1.1.1, 2003/10/16 17:59:32 version 1.7, 2004/06/20 04:32:18
Line 2 Line 2
 #include        "dosio.h"  #include        "dosio.h"
   
   
 static  char    curpath[MAX_PATH];  static  OEMCHAR curpath[MAX_PATH];
 static  char    *curfilep = curpath;  static  OEMCHAR *curfilep = curpath;
   
 #define ISKANJI(c)      (((((c) ^ 0x20) - 0xa1) & 0xff) < 0x3c)  
   
 #if defined(UNICODE)  // ----
   
   void dosio_init(void) { }
   void dosio_term(void) { }
   
 static HANDLE CreateFile_A(LPCSTR lpFileName,                                                                                          // ファイル操作
   #if defined(UNICODE) && defined(OSLANG_SJIS)
   static HANDLE _CreateFile(const OEMCHAR *lpFileName,
                                         DWORD dwDesiredAccess,                                          DWORD dwDesiredAccess,
                                         DWORD dwShareMode,                                          DWORD dwShareMode,
                                         LPSECURITY_ATTRIBUTES lpSecurityAttributes,                                          LPSECURITY_ATTRIBUTES lpSecurityAttributes,
Line 17  static HANDLE CreateFile_A(LPCSTR lpFile Line 21  static HANDLE CreateFile_A(LPCSTR lpFile
                                         DWORD dwFlagsAndAttributes,                                          DWORD dwFlagsAndAttributes,
                                         HANDLE hTemplateFile) {                                          HANDLE hTemplateFile) {
   
         TCHAR   FileNameW[MAX_PATH*2];          UINT16  ucs2[MAX_PATH];
   
         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1,          MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1,
                                                         FileNameW, sizeof(FileNameW)/sizeof(TCHAR));                                                                                                          ucs2, NELEMENTS(ucs2));
         return(CreateFile(FileNameW, dwDesiredAccess, dwShareMode,          return(CreateFile(ucs2, dwDesiredAccess, dwShareMode,
                                                 lpSecurityAttributes, dwCreationDisposition,                                                  lpSecurityAttributes, dwCreationDisposition,
                                                 dwFlagsAndAttributes, hTemplateFile));                                                  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) {
   
 static inline BOOL DeleteFile_A(LPCSTR lpFileName) {          UINT16  ucs2[MAX_PATH];
   
         TCHAR   FileNameW[MAX_PATH*2];  
   
         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1,  
                                                         FileNameW, sizeof(FileNameW)/sizeof(TCHAR));  
         return(DeleteFile(FileNameW));  
 }  
   
 static inline DWORD GetFileAttributes_A(LPCSTR lpFileName) {  
   
         TCHAR   FileNameW[MAX_PATH*2];  
   
         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1,  
                                                         FileNameW, sizeof(FileNameW)/sizeof(TCHAR));  
         return(GetFileAttributes(FileNameW));  
 }  
   
 static inline BOOL CreateDirectory_A(LPCSTR lpFileName,  
                                                                                                 LPSECURITY_ATTRIBUTES atr) {  
   
         TCHAR   FileNameW[MAX_PATH*2];  
   
         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1,  
                                                         FileNameW, sizeof(FileNameW)/sizeof(TCHAR));  
         return(CreateDirectory(FileNameW, atr));  
 }  
   
 static inline HANDLE FindFirstFile_A(LPCSTR lpFileName,  
                                                                                                         WIN32_FIND_DATA *w32fd) {  
   
         TCHAR   FileNameW[MAX_PATH*2];  
   
         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpFileName, -1,          ucscnv_utf8toucs2(ucs2, NELEMENTS(ucs2), lpFileName, (UINT)-1);
                                                         FileNameW, sizeof(FileNameW)/sizeof(TCHAR));          return(CreateFile(ucs2, dwDesiredAccess, dwShareMode,
         return(FindFirstFile(FileNameW, w32fd));                                                  lpSecurityAttributes, dwCreationDisposition,
                                                   dwFlagsAndAttributes, hTemplateFile));
 }  }
 #else  #else
   #define _CreateFile(a, b, c, d, e, f, g)        CreateFile(a, b, c, d, e, f, g)
 #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  #endif
   
   
 // ----  FILEH file_open(const OEMCHAR *path) {
   
 void dosio_init(void) { }  
 void dosio_term(void) { }  
   
                                                                                         // ファイル操作  
 FILEH file_open(const char *path) {  
   
         FILEH   ret;          FILEH   ret;
   
         if ((ret = CreateFile_A(path, GENERIC_READ | GENERIC_WRITE,          if ((ret = _CreateFile(path, GENERIC_READ | GENERIC_WRITE,
                                                 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))                                                  0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))
                                                                                                         == INVALID_HANDLE_VALUE) {                                                                                                          == INVALID_HANDLE_VALUE) {
                 if ((ret = CreateFile_A(path, GENERIC_READ,                  if ((ret = _CreateFile(path, GENERIC_READ,
                                                 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))                                                  0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))
                                                                                                         == INVALID_HANDLE_VALUE) {                                                                                                          == INVALID_HANDLE_VALUE) {
                         return(FILEH_INVALID);                          return(FILEH_INVALID);
Line 97  FILEH file_open(const char *path) { Line 66  FILEH file_open(const char *path) {
         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 ((ret = _CreateFile(path, GENERIC_READ, FILE_SHARE_READ, 0,
                                                                 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))                                                                  OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))
                                                                                                         == INVALID_HANDLE_VALUE) {                                                                                                          == INVALID_HANDLE_VALUE) {
                 return(FILEH_INVALID);                  return(FILEH_INVALID);
Line 109  FILEH file_open_rb(const char *path) { Line 78  FILEH file_open_rb(const char *path) {
         return(ret);          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 ((ret = _CreateFile(path, GENERIC_READ | GENERIC_WRITE,
                                                  0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL))                                                   0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL))
                                                                                         == INVALID_HANDLE_VALUE) {                                                                                          == INVALID_HANDLE_VALUE) {
                 return(FILEH_INVALID);                  return(FILEH_INVALID);
Line 162  UINT file_getsize(FILEH handle) { Line 131  UINT file_getsize(FILEH handle) {
         return(GetFileSize(handle, NULL));          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        localtime;
         FILETIME        localwrite;          SYSTEMTIME      systime;
         SYSTEMTIME      syswrite;  
   
         if ((GetFileTime(handle, NULL, NULL, &lastwrite) == 0) ||          if ((FileTimeToLocalFileTime(file, &localtime) == 0) ||
                 (FileTimeToLocalFileTime(&lastwrite, &localwrite) == 0) ||                  (FileTimeToSystemTime(&localtime, &systime) == 0)) {
                 (FileTimeToSystemTime(&localwrite, &syswrite) == 0)) {                  return(FAILURE);
                 return(-1);  
         }          }
         if (dosdate) {          if (dosdate) {
                 dosdate->year = (WORD)syswrite.wYear;                  dosdate->year = (UINT16)systime.wYear;
                 dosdate->month = (BYTE)syswrite.wMonth;                  dosdate->month = (UINT8)systime.wMonth;
                 dosdate->day = (BYTE)syswrite.wDay;                  dosdate->day = (UINT8)systime.wDay;
         }          }
         if (dostime) {          if (dostime) {
                 dostime->hour = (BYTE)syswrite.wHour;                  dostime->hour = (UINT8)systime.wHour;
                 dostime->minute = (BYTE)syswrite.wMinute;                  dostime->minute = (UINT8)systime.wMinute;
                 dostime->second = (BYTE)syswrite.wSecond;                  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);          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  ucs2[MAX_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
           return(DeleteFile(path)?0:-1);
   #endif
 }  }
   
 short file_attr(const char *path) {  short file_attr(const OEMCHAR *path) {
   
         return((short)GetFileAttributes_A(path));  #if defined(UNICODE) && defined(OSLANG_SJIS)
           UINT16  ucs2[MAX_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
           return((short)GetFileAttributes(path));
   #endif
 }  }
   
 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  ucs2[MAX_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
           return(CreateDirectory(path, NULL)?0:-1);
   #endif
 }  }
   
   
                                                                                         // カレントファイル操作                                                                                          // カレントファイル操作
 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) {  char *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));
 }  }
   
   
 FILEFINDH file_find1st(const char *path, FILEFINDT *fft) {  // ----
   
         HANDLE                  hdl;  #if !defined(_WIN32_WCE)
         WIN32_FIND_DATA w32fd;  static const OEMCHAR str_selfdir[] = OEMTEXT(".");
   static const OEMCHAR str_parentdir[] = OEMTEXT("..");
   #endif
   static const OEMCHAR str_wildcard[] = OEMTEXT("*.*");
   
   static BOOL setflist(WIN32_FIND_DATA *w32fd, FLINFO *fli) {
   
         hdl = FindFirstFile_A(path, &w32fd);  #if defined(UNICODE) && defined(OSLANG_SJIS)
         if (hdl == INVALID_HANDLE_VALUE) {          WideCharToMultiByte(CP_ACP, 0, w32fd->cFileName, -1,
                 return(FILEFINDH_INVALID);                                                                  fli->path, NELEMENTS(fli->path), NULL, NULL);
         }  #elif defined(OSLANG_UTF8)
         if (fft) {          ucscnv_ucs2toutf8(fli->path, NELEMENTS(fli->path), w32fd->cFileName, -1);
 #if defined(UNICODE)  
                 WideCharToMultiByte(CP_ACP, 0, w32fd.cFileName, -1,  
                                                                 fft->path, sizeof(fft->path), NULL, NULL);  
 #else  #else
                 milstr_ncpy(fft->path, w32fd.cFileName, sizeof(fft->path));          file_cpyname(fli->path, w32fd->cFileName, NELEMENTS(fli->path));
 #endif  #endif
                 fft->size = w32fd.nFileSizeLow;  #if !defined(_WIN32_WCE)
                 fft->attr = w32fd.dwFileAttributes;          if ((w32fd->dwFileAttributes & FILEATTR_DIRECTORY) &&
                   ((!file_cmpname(fli->path, str_selfdir)) ||
                   (!file_cmpname(fli->path, str_parentdir)))) {
                   return(FAILURE);
         }          }
         return(hdl);  #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);
 }  }
   
 BOOL file_findnext(FILEFINDH hdl, FILEFINDT *fft) {  FLISTH file_list1st(const OEMCHAR *dir, FLINFO *fli) {
   
           OEMCHAR                 path[MAX_PATH];
           HANDLE                  hdl;
         WIN32_FIND_DATA w32fd;          WIN32_FIND_DATA w32fd;
   
         if (!FindNextFile(hdl, &w32fd)) {          file_cpyname(path, dir, NELEMENTS(path));
                 return(FAILURE);          file_setseparator(path, NELEMENTS(path));
         }          file_catname(path, str_wildcard, NELEMENTS(path));
         if (fft) {          TRACEOUT(("file_list1st %s", path));
 #if defined(UNICODE)  
                 WideCharToMultiByte(CP_ACP, 0, w32fd.cFileName, -1,  #if defined(UNICODE) && defined(OSLANG_SJIS)
                                                                 fft->path, sizeof(fft->path), NULL, NULL);          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
                 milstr_ncpy(fft->path, w32fd.cFileName, sizeof(fft->path));          hdl = FindFirstFile(path, &w32fd);
 #endif  #endif
                 fft->size = w32fd.nFileSizeLow;          if (hdl != INVALID_HANDLE_VALUE) {
                 fft->attr = w32fd.dwFileAttributes;                  do {
                           if (setflist(&w32fd, fli) == SUCCESS) {
                                   return(hdl);
                           }
                   } while(FindNextFile(hdl, &w32fd));
                   FindClose(hdl);
         }          }
         return(SUCCESS);          return(FLISTH_INVALID);
 }  }
   
 void file_findclose(FILEFINDH hdl) {  BOOL file_listnext(FLISTH hdl, FLINFO *fli) {
   
         if (hdl) {          WIN32_FIND_DATA w32fd;
                 FindClose(hdl);  
           while(FindNextFile(hdl, &w32fd)) {
                   if (setflist(&w32fd, fli) == SUCCESS) {
                           return(SUCCESS);
                   }
         }          }
           return(FAILURE);
   }
   
   void file_listclose(FLISTH hdl) {
   
           FindClose(hdl);
 }  }
   
   
 char *file_getname(char *path) {  OEMCHAR *file_getname(const OEMCHAR *path) {
   
         char    *ret;          int                     csize;
   const OEMCHAR   *ret;
   
         ret = path;          ret = path;
         while(*path != '\0') {          while((csize = milstr_charsize(path)) != 0) {
                 if (!ISKANJI(*path)) {                  if ((csize == 1) &&
                         if ((*path == '\\') || (*path == '/') || (*path == ':')) {                          ((*path == '\\') || (*path == '/') || (*path == ':'))) {
                                 ret = path + 1;                          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 = file_getname(path);
         p[0] = '\0';          p[0] = '\0';
 }  }
   
 char *file_getext(char *path) {  OEMCHAR *file_getext(const OEMCHAR *path) {
   
         char    *p;          OEMCHAR *p;
         char    *q;          OEMCHAR *q;
           int             csize;
   
         p = file_getname(path);          p = file_getname(path);
         q = NULL;          q = NULL;
           while((csize = milstr_charsize(p)) != 0) {
         while(*p != '\0') {                  if ((csize == 1) && (*p == '.')) {
                 if (!ISKANJI(*p)) {                          q = p + 1;
                         if (*p == '.') {  
                                 q = p + 1;  
                         }  
                 }                  }
                 else {                  p += csize;
                         if (p[1]) {  
                                 p++;  
                         }  
                 }  
                 p++;  
         }          }
         if (!q) {          if (!q) {
                 q = p;                  q = p;
         }          }
         return(q);          return((OEMCHAR *)q);
 }  }
   
 void file_cutext(char *path) {  void file_cutext(OEMCHAR *path) {
   
         char    *p;          OEMCHAR *p;
         char    *q;          OEMCHAR *q;
           int             csize;
   
         p = file_getname(path);          p = file_getname(path);
         q = NULL;          q = NULL;
           while((csize = milstr_charsize(p)) != 0) {
         while(*p != '\0') {                  if ((csize == 1) && (*p == '.')) {
                 if (!ISKANJI(*p)) {                          q = p + 1;
                         if (*p == '.') {  
                                 q = p;  
                         }  
                 }  
                 else {  
                         if (p[1]) {  
                                 p++;  
                         }  
                 }                  }
                 p++;                  p += csize;
         }          }
         if (q) {          if (q) {
                 *q = '\0';                  *q = '\0';
         }          }
 }  }
   
 void file_cutseparator(char *path) {  void file_cutseparator(OEMCHAR *path) {
   
         int             pos;          int             pos;
   
Line 399  void file_cutseparator(char *path) { Line 419  void file_cutseparator(char *path) {
         }          }
 }  }
   
 void file_setseparator(char *path, int maxlen) {  void file_setseparator(OEMCHAR *path, int maxlen) {
   
         int             pos;          int             pos;
   

Removed from v.1.1.1.1  
changed lines
  Added in v.1.7


RetroPC.NET-CVS <cvs@retropc.net>