documentor, ecere: Fix for documentor closing when being debugged
[sdk] / ecere / src / sys / File.ec
index 149a356..68030c6 100644 (file)
@@ -1,8 +1,10 @@
 namespace sys;
 
 default:
+#define set _set
 #define uint _uint
 #define File _File
+#define strlen _strlen
 #undef __BLOCKS__
 #include <stdio.h>
 #include <stdarg.h>
@@ -39,7 +41,9 @@ default:
 
 #if defined(__WIN32__)
 #define WIN32_LEAN_AND_MEAN
+#define String String_
 #include <windows.h>
+#undef String
 #include <io.h>
 
 BOOL WINAPI GetVolumePathName(LPCTSTR lpszFileName,LPTSTR lpszVolumePathName,DWORD cchBufferLength);
@@ -66,8 +70,10 @@ DWORD APIENTRY WNetGetResourceInformationA(LPNETRESOURCE lpNetResource, LPVOID l
 #endif //#ifndef ECERE_BOOTSTRAP
 private:
 
+#undef set
 #undef uint
 #undef File
+#undef strlen
 
 import "System"
 
@@ -80,6 +86,9 @@ import "dataTypes"
 // IMPLEMENTATION OF THESE IS IN _File.c
 default:
 
+FILE *eC_stdin(void);
+FILE *eC_stdout(void);
+
 uint FILE_GetSize(FILE * input);
 bool FILE_Lock(FILE * input, FILE * output, FileLock type, uint64 start, uint64 length, bool wait);
 void FILE_set_buffered(FILE * input, FILE * output, bool value);
@@ -282,7 +291,7 @@ public class File : IOChannel
       Window editData = class::OnEdit(dataBox, obsolete, x + 24, y, w - 48, h, userData);
       Button load
       { 
-         dataBox, inactive = true, text = $"Imp", hotKey = f2,
+         dataBox, inactive = true, text = $"Import"."Imp", hotKey = f2,
          position = { Max(x + 24, x + w - 24), y }, size = { 24, h };
 
          bool DataBox::NotifyClicked(Button button, int x, int y, Modifiers mods)
@@ -306,7 +315,7 @@ public class File : IOChannel
       };
       Button save
       { 
-         dataBox, inactive = true, text = $"Exp", hotKey = f2,
+         dataBox, inactive = true, text = $"Export"."Exp", hotKey = f2,
          position = { Max(x + 24, x + w - 48), y }, size = { 24, h };
 
          bool DataBox::NotifyClicked(Button button, int x, int y, Modifiers mods)
@@ -461,7 +470,7 @@ public:
 
    virtual uint Tell(void)
    {
-      return input ? ftell(input) : ftell(output);
+      return (uint)(input ? ftell(input) : ftell(output));
    }
 
    virtual int Read(void * buffer, uint size, uint count)
@@ -570,7 +579,8 @@ public:
          char text[MAX_F_STRING];
          va_list args;
          va_start(args, format);
-         vsprintf(text, format, args);
+         vsnprintf(text, sizeof(text), format, args);
+         text[sizeof(text)-1] = 0;
          if(Puts(text))
             result = strlen(text);
          va_end(args);
@@ -693,7 +703,7 @@ public:
    {
       char string[32];
       GetString(string, sizeof(string));
-      return strtoul(string, null, 16);
+      return (uint)strtoul(string, null, 16);
    }
 
    float GetFloat(void)
@@ -811,10 +821,28 @@ public:
    }
 }
 
+#if defined(__WIN32__)
+default extern intptr_t stdinHandle;
+default extern intptr_t stdoutHandle;
+#endif
+
 public class ConsoleFile : File
 {
-   input = stdin;
-   output = stdout;
+   input = eC_stdin();
+   output = eC_stdout();
+
+#if defined(__WIN32__)
+   void CloseInput()
+   {
+      CloseHandle((HANDLE)stdinHandle);
+   }
+   /*
+   void CloseOutput()
+   {
+      CloseHandle((HANDLE)stdoutHandle);
+   }*/
+#endif
+
    ~ConsoleFile()
    {
       input = null;
@@ -1382,13 +1410,14 @@ static FileDesc FileFind(char * path, char * extensions)
                }
                strcpy(file.name,de->d_name);
                strcat(file.path, file.name);
-               stat(file.path, &s);
-               file.stats.attribs = (s.st_mode&S_IFDIR) ? FileAttribs { isDirectory = true } : FileAttribs { isFile = true };
-               file.stats.size = s.st_size;
-               file.stats.accessed = s.st_atime;
-               file.stats.modified = s.st_mtime;
-               file.stats.created = s.st_ctime;
-          
+               if(!stat(file.path, &s))
+               {
+                  file.stats.attribs = (s.st_mode&S_IFDIR) ? FileAttribs { isDirectory = true } : FileAttribs { isFile = true };
+                  file.stats.size = (FileSize)s.st_size;
+                  file.stats.accessed = s.st_atime;
+                  file.stats.modified = s.st_mtime;
+                  file.stats.created = s.st_ctime;
+               }
                strcpy(d.name, path);
 
                result = file;
@@ -1656,13 +1685,15 @@ private class FileDesc : struct
                if(d.name[0] && d.name[1])
                   strcat(path, DIR_SEPS);
                strcat(path, name);
-               stat(path, &s);
-               stats.attribs = FileAttribs { };
-               stats.attribs = (s.st_mode&S_IFDIR) ? FileAttribs { isDirectory = true } : FileAttribs { isFile = true };
-               stats.size = s.st_size;
-               stats.accessed = s.st_atime;
-               stats.modified = s.st_mtime;
-               stats.created = s.st_ctime;
+               if(!stat(path, &s))
+               {
+                  stats.attribs = FileAttribs { };
+                  stats.attribs = (s.st_mode&S_IFDIR) ? FileAttribs { isDirectory = true } : FileAttribs { isFile = true };
+                  stats.size = (FileSize)s.st_size;
+                  stats.accessed = s.st_atime;
+                  stats.modified = s.st_mtime;
+                  stats.created = s.st_ctime;
+               }
                result = this;
             }
             else