Diff for /np2/x11/dosio.c between versions 1.2 and 1.8

version 1.2, 2003/11/16 16:43:45 version 1.8, 2004/01/14 16:15:49
Line 1 Line 1
   #define VERBOSE(s)      printf s
   
 #include "compiler.h"  #include "compiler.h"
   
 #include <sys/stat.h>  #include <sys/stat.h>
 #include <time.h>  #include <time.h>
 #if defined(WIN32)  #include <dirent.h>
 #include <direct.h>  
 #endif  
   
 #include "codecnv.h"  #include "codecnv.h"
 #include "dosio.h"  #include "dosio.h"
Line 34  dosio_term(void) Line 34  dosio_term(void)
 FILEH  FILEH
 file_open(const char *path)  file_open(const char *path)
 {  {
           FILEH fh;
   
           fh = fopen(path, "rb+");
           if (fh)
                   return fh;
         return fopen(path, "rb");          return fopen(path, "rb");
 }  }
   
Line 100  file_attr(const char *path) Line 104  file_attr(const char *path)
   
         if (stat(path, &sb) == 0) {          if (stat(path, &sb) == 0) {
                 if (S_ISDIR(sb.st_mode)) {                  if (S_ISDIR(sb.st_mode)) {
                         return(FILEATTR_DIRECTORY);                          return FILEATTR_DIRECTORY;
                 }                  }
                 attr = 0;                  attr = 0;
                 if (!(sb.st_mode & S_IWUSR)) {                  if (!(sb.st_mode & S_IWUSR)) {
Line 111  file_attr(const char *path) Line 115  file_attr(const char *path)
         return -1;          return -1;
 }  }
   
 short  static BOOL
 file_getdatetime(FILEH handle, DOSDATE *dosdate, DOSTIME *dostime)  cnvdatetime(struct stat *sb, DOSDATE *dosdate, DOSTIME *dostime)
 {  {
         struct stat sb;  
         struct tm *ftime;          struct tm *ftime;
   
         if (fstat(fileno(handle), &sb) == 0) {          ftime = localtime(&sb->st_mtime);
                 ftime = localtime(&sb.st_mtime);          if (ftime) {
                 if (ftime) {                  if (dosdate) {
                         if (dosdate) {                          dosdate->year = ftime->tm_year + 1900;
                                 dosdate->year = ftime->tm_year + 1900;                          dosdate->month = ftime->tm_mon + 1;
                                 dosdate->month = ftime->tm_mon + 1;                          dosdate->day = ftime->tm_mday;
                                 dosdate->day = ftime->tm_mday;                  }
                         }                  if (dostime) {
                         if (dostime) {                          dostime->hour = ftime->tm_hour;
                                 dostime->hour = ftime->tm_hour;                          dostime->minute = ftime->tm_min;
                                 dostime->minute = ftime->tm_min;                          dostime->second = ftime->tm_sec;
                                 dostime->second = ftime->tm_sec;  
                         }  
                         return 0;  
                 }                  }
                   return SUCCESS;
         }          }
           return FAILURE;
   }
   
   short
   file_getdatetime(FILEH handle, DOSDATE *dosdate, DOSTIME *dostime)
   {
           struct stat sb;
   
           if ((fstat(fileno(handle), &sb) == 0)
            && (cnvdatetime(&sb, dosdate, dostime)))
                   return 0;
         return -1;          return -1;
 }  }
   
Line 215  file_attr_c(const char *sjis) Line 227  file_attr_c(const char *sjis)
         return file_attr_c(curpath);          return file_attr_c(curpath);
 }  }
   
   FLISTH
   file_list1st(const char *dir, FLINFO *fli)
   {
           char eucpath[MAX_PATH];
           DIR *ret;
   
           mileuc_ncpy(eucpath, dir, sizeof(eucpath));
           file_setseparator(eucpath, sizeof(eucpath));
           ret = opendir(eucpath);
           VERBOSE(("file_list1st: opendir(%s)\n", eucpath));
           if (ret == NULL) {
                   VERBOSE(("file_list1st: opendir failure"));
                   return FLISTH_INVALID;
           }
           if (file_listnext((FLISTH)ret, fli) == SUCCESS) {
                   return (FLISTH)ret;
           }
           VERBOSE(("file_list1st: file_listnext failure\n"));
           closedir(ret);
           return FLISTH_INVALID;
   }
   
   BOOL
   file_listnext(FLISTH hdl, FLINFO *fli)
   {
           struct dirent *de;
           struct stat sb;
   
           de = readdir((DIR *)hdl);
           if (de == NULL) {
                   VERBOSE(("file_listnext: readdir failure\n"));
                   return FAILURE;
           }
           if (stat(de->d_name, &sb) != 0) {
                   VERBOSE(("file_listnext: stat failure\n"));
                   return FAILURE;
           }
   
           fli->caps = FLICAPS_SIZE | FLICAPS_ATTR | FLICAPS_DATE | FLICAPS_TIME;
           fli->size = sb.st_size;
           if (S_ISDIR(sb.st_mode)) {
                   fli->attr |= FILEATTR_DIRECTORY;
           }
           if (!(sb.st_mode & S_IWUSR)) {
                   fli->attr |= FILEATTR_READONLY;
           }
           cnvdatetime(&sb, &fli->date, &fli->time);
           mileuc_ncpy(fli->path, de->d_name, sizeof(fli->path));
   
           VERBOSE(("file_listnext: success\n"));
           return SUCCESS;
   }
   
   void
   file_listclose(FLISTH hdl)
   {
   
           closedir((DIR *)hdl);
   }
   
 #if 0  
 static int  static int
 euckanji1st(const char *str, int pos)  euckanji1st(const char *str, int pos)
 {  {
Line 228  euckanji1st(const char *str, int pos) Line 298  euckanji1st(const char *str, int pos)
         }          }
         return ret;          return ret;
 }  }
 #endif  
   void
   file_cpyname(char *dst, const char *src, int maxlen)
   {
           int i;
   
           if (maxlen--) {
                   for (i = 0; i < maxlen && src[i] != '\0'; i++) {
                           dst[i] = src[i];
                   }
                   if (i > 0) {
                           if (euckanji1st(src, i-1)) {
                                   i--;
                           }
                   }
                   dst[i] = '\0';
           }
   }
   
 void  void
 file_catname(char *path, const char *sjis, int maxlen)  file_catname(char *path, const char *sjis, int maxlen)
Line 243  file_catname(char *path, const char *sji Line 330  file_catname(char *path, const char *sji
         }          }
         if (maxlen) {          if (maxlen) {
                 codecnv_sjis2euc(path, maxlen, sjis, (UINT)-1);                  codecnv_sjis2euc(path, maxlen, sjis, (UINT)-1);
                 for (;;) {                  for (; path[0] != '\0'; path++) {
                         if (!ISKANJI(*path)) {                          if (!ISKANJI(path[0])) {
                                 if (*(path+1) == '\0') {                                  if (path[1] == '\0') {
                                         break;                                          break;
                                 }                                  }
                                 path++;                                  path++;
                         } else if ((((*path) - 0x41) & 0xff) < 26) {                          } else if ((((path[0]) - 0x41) & 0xff) < 26) {
                                 *path |= 0x20;                                  path[0] |= 0x20;
                         } else if (*path == '\\') {                          } else if (path[0] == '\\') {
                                 *path = '/';                                  path[0] = '/';
                         } else if (*path == '\0') {  
                                 break;  
                         }                          }
                         path++;  
                 }                  }
         }          }
 }  }
   
   BOOL
   file_cmpname(const char *path, const char *sjis)
   {
           char euc[MAX_PATH];
   
           codecnv_sjis2euc(euc, sizeof(euc), sjis, (UINT)-1);
           return strcmp(path, euc);
   }
   
 char *  char *
 file_getname(char *path)  file_getname(char *path)
 {  {

Removed from v.1.2  
changed lines
  Added in v.1.8


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