#define set _set
#define uint _uint
#define File _File
+#define strlen _strlen
#undef __BLOCKS__
#include <stdio.h>
#include <stdarg.h>
#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);
+BOOL __declspec(dllimport) WINAPI GetVolumePathName(LPCTSTR lpszFileName,LPTSTR lpszVolumePathName,DWORD cchBufferLength);
// Missing function...
/*
-#ifndef WNetGetResourceInformation
+#ifndef WNetGetResourceInformation
DWORD APIENTRY WNetGetResourceInformationA(LPNETRESOURCE lpNetResource, LPVOID lpBuffer, LPDWORD lpcbBuffer, LPTSTR* lplpSystem);
#ifdef UNICODE
#define WNetGetResourceInformation WNetGetResourceInformationW
#undef set
#undef uint
#undef File
+#undef strlen
import "System"
// 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);
-FileAttribs FILE_FileExists(char * fileName);
-bool FILE_FileGetSize(char * fileName, FileSize * size);
-bool FILE_FileGetStats(char * fileName, FileStats stats);
+FileAttribs FILE_FileExists(const char * fileName);
+bool FILE_FileGetSize(const char * fileName, FileSize * size);
+bool FILE_FileGetStats(const char * fileName, FileStats stats);
void FILE_FileFixCase(char * file);
-void FILE_FileOpen(char * fileName, FileOpenMode mode, FILE ** input, FILE **output);
+void FILE_FileOpen(const char * fileName, FileOpenMode mode, FILE ** input, FILE **output);
private:
return result;
}
- char * OnGetString(char * string, void * fieldData, bool * needClass)
+ const char * OnGetString(char * string, void * fieldData, bool * needClass)
{
PrintSize(string, this, 2);
return string;
}
- bool OnGetDataFromString(char * string)
+ bool OnGetDataFromString(const char * string)
{
char * end;
double value = strtod(string, &end);
return result;
}
- char * OnGetString(char * string, void * fieldData, bool * needClass)
+ const char * OnGetString(char * string, void * fieldData, bool * needClass)
{
PrintBigSize(string, this, 2);
return string;
}
- bool OnGetDataFromString(char * string)
+ bool OnGetDataFromString(const char * string)
{
char * end;
double value = strtod(string, &end);
class FileSystem
{
- virtual File ::Open(char * archive, char * name, FileOpenMode mode);
+ virtual File ::Open(const char * archive, const char * name, FileOpenMode mode);
// Query on names
- virtual FileAttribs ::Exists(char * archive, char * fileName);
- virtual bool ::GetSize(char * archive, char * fileName, FileSize * size);
- virtual bool ::Stats(char * archive, char * fileName, FileStats stats);
- virtual void ::FixCase(char * archive, char * fileName);
+ virtual FileAttribs ::Exists(const char * archive, const char * fileName);
+ virtual bool ::GetSize(const char * archive, const char * fileName, FileSize * size);
+ virtual bool ::Stats(const char * archive, const char * fileName, FileStats stats);
+ virtual void ::FixCase(const char * archive, char * fileName);
// File Listing
- virtual bool ::Find(FileDesc file, char * archive, char * name);
+ virtual bool ::Find(FileDesc file, const char * archive, const char * name);
virtual bool ::FindNext(FileDesc file);
virtual void ::CloseDir(FileDesc file);
// Archive manipulation
- virtual Archive ::OpenArchive(char * fileName, ArchiveOpenFlags create);
- virtual bool ::QuerySize(char * fileName, FileSize * size);
+ virtual Archive ::OpenArchive(const char * fileName, ArchiveOpenFlags create);
+ virtual bool ::QuerySize(const char * fileName, FileSize * size);
};
public enum FileOpenMode { read = 1, write, append, readWrite, writeRead, appendRead };
return Read(bytes, 1, numBytes);
}
- uint WriteData(byte * bytes, uint numBytes)
+ uint WriteData(const byte * bytes, uint numBytes)
{
return Write(bytes, 1, numBytes);
}
output = null;
}
- bool OnGetDataFromString(char * string)
+ bool OnGetDataFromString(const char * string)
{
if(!string[0])
{
return false;
}
- char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+ const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
{
if(this)
{
{
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)
if(fileDialog.Modal() == ok)
{
- char * filePath = fileDialog.filePath;
+ const char * filePath = fileDialog.filePath;
File output = null;
if(output.OnGetDataFromString(filePath))
{
}
};
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)
fileDialog.filePath = "";
if(fileDialog.Modal() == ok)
{
- char * filePath = fileDialog.filePath;
+ const char * filePath = fileDialog.filePath;
File f = FileOpen(filePath, write);
if(f)
{
{
byte buffer[4096];
uint read = input.Read(buffer, 1, sizeof(buffer));
- f.Write(buffer, 1, read);
+ f.Write(buffer, 1, read);
}
delete f;
- }
+ }
}
return true;
}
uint count = Read(uncompressed, 1, size);
if(count == size)
{
- uint cSize = size + size / 1000 + 12;
+ uLongf cSize = size + size / 1000 + 12;
byte * compressed = new byte[cSize];
if(compressed)
{
size.OnSerialize(channel);
cSize.OnSerialize(channel);
- channel.WriteData(compressed, cSize);
+ channel.WriteData(compressed, (uint)cSize);
delete compressed;
}
void OnUnserialize(IOChannel channel)
{
- uint size, cSize;
+ uLongf size;
+ uint cSize;
this = null;
{
this = TempFile { };
uncompress(uncompressed, &size, compressed, cSize);
- Write(uncompressed, 1, size);
+ Write(uncompressed, 1, (uint)size);
Seek(0, start);
delete uncompressed;
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)
return input ? (int)fread(buffer, size, count, input) : 0;
}
- virtual int Write(void * buffer, uint size, uint count)
+ virtual int Write(const void * buffer, uint size, uint count)
{
return output ? (int)fwrite(buffer, size, count, output) : 0;
}
virtual bool Eof(void)
{
- return input ? feof(input) : true;
+ return input ? feof(input) != 0 : true;
}
-
+
virtual bool Truncate(FileSize size)
{
#ifdef ECERE_BOOTSTRAP
return output ? (_chsize(fileno(output), size) == 0) : false;
#else
return output ? (ftruncate(fileno(output), size) == 0) : false;
- #endif
+ #endif
#endif
}
{
return FILE_GetSize(input);
}
-
+
virtual void CloseInput(void)
{
if(input)
}
// Normal Methods
- int Printf(char * format, ...)
+ int Printf(const char * format, ...)
{
int result = 0;
if(format)
while(c<max-1)
{
char ch = 0;
-
+
if(/*!Peek() || */ !Getc(&ch))
{
result = false;
break;
}
- if(ch =='\n')
+ if(ch =='\n')
break;
if(ch !='\r')
s[c++]=ch;
while(true)
{
if(!Getc(&ch))
+ {
result = false;
+ break;
+ }
if( (ch!='\n') && (ch!='\r') && (ch!=' ') && (ch!=',') && (ch!='\t'))
break;
if(Eof()) break;
else
string[c]=ch;
- if(!Getc(&ch))
+ if(!Getc(&ch))
{
c++;
result = false;
- break;
+ break;
}
}
string[c]=0;
{
char string[32];
GetString(string, sizeof(string));
- return strtoul(string, null, 16);
+ return (uint)strtoul(string, null, 16);
}
float GetFloat(void)
set
{
FILE_set_buffered(input, output, value);
- }
+ }
}
property bool eof { get { return Eof(); } }
return c;
}
- bool CopyTo(char * outputFileName)
+ bool CopyTo(const char * outputFileName)
{
bool result = false;
File f = FileOpen(outputFileName, write);
}
#if 0
- virtual bool Open(char * fileName, FileOpenMode mode)
+ virtual bool Open(const char * fileName, FileOpenMode mode)
{
bool result = false;
if(this)
//if(!result)
{
/* TOFIX:
- LogErrorCode((mode == Read || mode == ReadWrite) ?
+ LogErrorCode((mode == Read || mode == ReadWrite) ?
ERR_FILE_NOT_FOUND : ERR_FILE_WRITE_FAILED, fileName);
*/
}
}
}
+#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;
// property bool { };
};
+#ifdef ECERE_BOOTSTRAP
+public class SecSince1970 : int64;
+#endif
+
public struct FileStats
{
FileAttribs attribs;
// TIME_ZONE_INFORMATION tz = { 0 };
SYSTEMTIME st, lt;
DateTime tm;
-
+
tm = t;
st.wYear = (short)tm.year;
- st.wMonth = (short)tm.month + 1;
+ st.wMonth = (short)(tm.month + 1);
st.wDay = (short)tm.day;
st.wHour = (short)tm.hour;
st.wMinute = (short)tm.minute;
#endif
-public FileAttribs FileExists(char * fileName)
+public FileAttribs FileExists(const char * fileName)
{
- char archiveName[MAX_LOCATION], * archiveFile;
#if !defined(ECERE_BOOTSTRAP)
+ char archiveName[MAX_LOCATION];
+ const char * archiveFile;
if(SplitArchivePath(fileName, archiveName, &archiveFile))
{
return EARFileSystem::Exists(archiveName, archiveFile);
static int openCount;
-public File FileOpen(char * fileName, FileOpenMode mode)
+public File FileOpen(const char * fileName, FileOpenMode mode)
{
File result = null;
if(fileName)
{
- char archiveName[MAX_LOCATION], * archiveFile;
#if !defined(ECERE_BOOTSTRAP)
+ char archiveName[MAX_LOCATION];
+ const char * archiveFile;
if(SplitArchivePath(fileName, archiveName, &archiveFile))
{
result = EARFileSystem::Open(archiveName, archiveFile, mode);
}
#if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
- else if(strstr(fileName, "http://") == fileName)
+ else if(strstr(fileName, "http://") == fileName || strstr(fileName, "https://"))
{
result = FileOpenURL(fileName);
}
#endif
if(strstr(fileName, "File://") == fileName)
{
- result = (File)strtoul(fileName+7, null, 16);
+ result = (File)(uintptr)strtoull(fileName+7, null, 16);
if(result)
{
if(result._class && eClass_IsDerived(result._class, class(File)))
{
delete file;
/* TOFIX:
- LogErrorCode((mode == Read || mode == ReadWrite) ?
+ LogErrorCode((mode == Read || mode == ReadWrite) ?
ERR_FILE_NOT_FOUND : ERR_FILE_WRITE_FAILED, fileName);
*/
}
}
#if !defined(ECERE_BOOTSTRAP)
-public bool FileTruncate(char * fileName, FileSize size)
+public bool FileTruncate(const char * fileName, FileSize size)
{
#if defined(__WIN32__)
uint16 * _wfileName = UTF8toUTF16(fileName, null);
}
#endif
-public bool FileGetSize(char * fileName, FileSize * size)
+public bool FileGetSize(const char * fileName, FileSize * size)
{
bool result = false;
if(size)
if(fileName)
{
#if !defined(ECERE_BOOTSTRAP)
- char archiveName[MAX_LOCATION], * archiveFile;
+ char archiveName[MAX_LOCATION];
+ const char * archiveFile;
if(SplitArchivePath(fileName, archiveName, &archiveFile))
return EARFileSystem::GetSize(archiveName, archiveFile, size);
else
return result;
}
-public bool FileGetStats(char * fileName, FileStats stats)
+public bool FileGetStats(const char * fileName, FileStats stats)
{
bool result = false;
if(stats && fileName)
{
#if !defined(ECERE_BOOTSTRAP)
- char archiveName[MAX_LOCATION], * archiveFile;
+ char archiveName[MAX_LOCATION];
+ const char * archiveFile;
if(SplitArchivePath(fileName, archiveName, &archiveFile))
result = EARFileSystem::Stats(archiveName, archiveFile, stats);
else
#ifndef ECERE_BOOTSTRAP
-public bool FileSetAttribs(char * fileName, FileAttribs attribs)
+public bool FileSetAttribs(const char * fileName, FileAttribs attribs)
{
#ifdef __WIN32__
uint winAttribs = 0;
return true;
}
-public bool FileSetTime(char * fileName, TimeStamp created, TimeStamp accessed, TimeStamp modified)
+public bool FileSetTime(const char * fileName, TimeStamp created, TimeStamp accessed, TimeStamp modified)
{
bool result = false;
TimeStamp currentTime = time(null);
if(hFile != INVALID_HANDLE_VALUE)
{
FILETIME c, a, m;
-
+
TimeStampToWin32FileTime(created, &c);
TimeStampToWin32FileTime(accessed, &a);
TimeStampToWin32FileTime(modified, &m);
mm = Win32FileTimeToTimeStamp(&m);
}
*/
-
+
if(SetFileTime(hFile, &c, &a, &m))
result = true;
}
#else
struct utimbuf t = { (int)accessed, (int)modified };
+#if !defined(__pnacl__)
if(!utime(fileName, &t))
result = true;
#endif
+#endif
}
return result;
}
char name[MAX_LOCATION];
};
-static FileDesc FileFind(char * path, char * extensions)
+static FileDesc FileFind(const char * path, const char * extensions)
{
FileDesc result = null;
FileDesc file;
if((file = FileDesc {}))
{
- char archiveName[MAX_LOCATION], * archiveFile;
+ char archiveName[MAX_LOCATION];
+ const char * archiveFile;
if(SplitArchivePath(path, archiveName, &archiveFile))
{
if(EARFileSystem::Find(file, archiveName, archiveFile))
else
{
Dir d;
-
+
if((d = file.dir = Dir {}))
{
#if defined(__WIN32__)
if(!strcmp(path, "/"))
{
int c;
- d.fHandle = (void *)0xFFFFFFFF; //GetLogicalDrives();
+ uint drives = 0xFFFFFFFF;
+ d.fHandle = (HANDLE)(uintptr)drives; //GetLogicalDrives();
for(c = 0; c<26; c++)
- if(((uint)d.fHandle) & (1<<c))
+ if(((uint)(uintptr)d.fHandle) & (1<<c))
{
char volume[MAX_FILENAME] = "";
uint16 _wvolume[MAX_FILENAME];
case DRIVE_REMOTE: file.stats.attribs.isRemote = true; break;
case DRIVE_CDROM: file.stats.attribs.isCDROM = true; break;
}
- *((uint *)&d.fHandle) ^= (1<<c);
+ drives ^= (1<<c);
if(driveType == DRIVE_NO_ROOT_DIR) continue;
-
- if(driveType != DRIVE_REMOVABLE && driveType != DRIVE_REMOTE &&
+
+ if(driveType != DRIVE_REMOVABLE && driveType != DRIVE_REMOTE &&
GetVolumeInformation(_wfilePath, _wvolume, MAX_FILENAME - 1, null, null, null, null, 0))
{
file.path[2] = '\0';
result = file;
break;
}
+ d.fHandle = (HANDLE)(uintptr) drives;
d.resource = 0;
}
else if(path[0] != '\\' || path[1] != '\\' || strstr(path+2, "\\"))
else
{
HANDLE handle = 0;
- int count = 0xFFFFFFFF;
- uint size = 512 * sizeof(NETRESOURCE);
+ DWORD count = 0xFFFFFFFF;
+ DWORD size = 512 * sizeof(NETRESOURCE);
NETRESOURCE * buffer = (NETRESOURCE *)new0 byte[size];
NETRESOURCE nr = {0};
d.fHandle = null;
nr.dwScope = RESOURCE_GLOBALNET;
nr.dwType = RESOURCETYPE_DISK;
- nr.lpProvider = L"Microsoft Windows Network";
+ nr.lpProvider = (uint16 *)L"Microsoft Windows Network";
strcpy(d.name, path);
if(path[2])
else
{
int c;
- nr.lpProvider = L"Microsoft Windows Network";
+ nr.lpProvider = (uint16 *)L"Microsoft Windows Network";
// Entire Network
WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, &nr, &handle);
for(c = 0; c<count; c++)
{
NETRESOURCE * resources;
- int countInGroup = 0xFFFFFFFF;
+ DWORD countInGroup = 0xFFFFFFFF;
size = 512 * sizeof(NETRESOURCE);
resources = (NETRESOURCE *)new0 byte[size];
-
+
// Entire Network
WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, &buffer[c], &handle);
while(true)
strcat(file.path, file.name);
if(!stat(file.path, &s))
{
+#if !defined(__pnacl__)
file.stats.attribs = (s.st_mode&S_IFDIR) ? FileAttribs { isDirectory = true } : FileAttribs { isFile = true };
- file.stats.size = s.st_size;
+ 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;
+#endif
}
strcpy(d.name, path);
subclass(FileSystem) system;
Dir dir;
- bool Validate(char * extensions)
+ bool Validate(const char * extensions)
{
if(strcmp(name, "..") && strcmp(name, ".") && strcmp(name, ""))
{
return false;
}
- FileDesc FindNext(char * extensions)
+ FileDesc FindNext(const char * extensions)
{
FileDesc result = null;
if(!strcmp(d.name, "/"))
{
int c;
+ uint drives = (uint)(uintptr)d.fHandle;
for(c = 0; c<26; c++)
{
- if(((uint)d.fHandle) & (1<<c))
+ if(drives & (1<<c))
{
char volume[MAX_FILENAME] = "";
int driveType;
_wpath[2] = path[2] = '\\';
_wpath[3] = path[3] = 0;
driveType = GetDriveType(_wpath);
- *((uint *)&d.fHandle) ^= (1<<c);
+ drives ^= (1<<c);
switch(driveType)
{
{
uint16 remoteName[1024];
int status;
- int size = 1024;
+ DWORD size = 1024;
_wpath[2] = 0;
status = WNetGetConnection(_wpath, remoteName, &size);
_wpath[3] = 0;
}
- if(driveType != DRIVE_REMOVABLE && driveType != DRIVE_REMOTE &&
+ if(driveType != DRIVE_REMOVABLE && driveType != DRIVE_REMOTE &&
GetVolumeInformation(_wpath, _wvolume, MAX_FILENAME - 1, null, null, null, null, 0))
{
UTF16toUTF8Buffer(_wvolume, volume, MAX_FILENAME);
break;
}
}
+ d.fHandle = (HANDLE)(uintptr) drives;
break;
}
else if(d.name[0] != '\\' || d.name[1] != '\\' || strstr(d.name+2, "\\"))
{
if(c != d.workGroup)
{
- int countInGroup = 0xFFFFFFFF;
+ DWORD countInGroup = 0xFFFFFFFF;
HANDLE handle;
NETRESOURCE * resources;
- uint size = 512 * sizeof(NETRESOURCE);
+ DWORD size = 512 * sizeof(NETRESOURCE);
resources = (NETRESOURCE *)new0 byte[size];
// Entire Network
break;
countInGroup = 0xFFFFFFFF;
resources = (NETRESOURCE *)renew0 resources byte[size];
-
+
}
WNetCloseEnum(handle);
d.numResources = countInGroup;
}
else
{
- if(d.resources)
+ if(d.resources)
delete d.resources;
}
}
strcat(path, name);
if(!stat(path, &s))
{
+#if !defined(__pnacl__)
stats.attribs = FileAttribs { };
stats.attribs = (s.st_mode&S_IFDIR) ? FileAttribs { isDirectory = true } : FileAttribs { isFile = true };
- stats.size = s.st_size;
+ stats.size = (FileSize)s.st_size;
stats.accessed = s.st_atime;
stats.modified = s.st_mtime;
stats.created = s.st_ctime;
+#endif
}
result = this;
}
public struct FileListing
{
public:
- char * directory;
- char * extensions;
+ const char * directory;
+ const char * extensions;
bool Find()
{
- bool result = false;
if(desc)
desc = desc.FindNext(extensions);
else
desc = null;
}
- property char * name { get { return (char *)(desc ? desc.name : null); } };
- property char * path { get { return (char *)(desc ? desc.path : null); } };
+ property const char * name { get { return desc ? desc.name : null; } };
+ property const char * path { get { return desc ? desc.path : null; } };
property FileStats stats { get { value = desc ? desc.stats : FileStats { }; } };
private:
};
#endif
-public File CreateTemporaryFile(char * tempFileName, char * template)
+public File CreateTemporaryFile(char * tempFileName, const char * template)
{
#ifndef ECERE_BOOTSTRAP // quick fix for now
File f;
//strcpy(buffer, template);
strcat(buffer, "XXXXXX");
// mktemp(buffer);
- fd = mkstemp(buffer);
+ fd = mkstemp(buffer);
strcpy(tempFileName, buffer);
f = { };
f.output = f.input = fdopen(fd, "r+");
GetTempPathA(MAX_LOCATION, tempPath); // TODO: Patch this whole thing to support Unicode temp path
GetTempFileNameA(tempPath, template, 0, tempFileName);
f = FileOpen(tempFileName, readWrite);
-#endif
+#endif
return f;
+#else
+ return null;
#endif
}
#undef DeleteFile
-public void CreateTemporaryDir(char * tempFileName, char * template)
+public void CreateTemporaryDir(char * tempFileName, const char * template)
{
#ifndef ECERE_BOOTSTRAP // quick fix for now
#if defined(__unix__) || defined(__APPLE__)
public void MakeSlashPath(char * p)
{
FileFixCase(p);
-#ifdef WIN32
- ChangeCh(p, '\\', '/');
-#endif
+ if(__runtimePlatform == win32)
+ ChangeCh(p, '\\', '/');
}
public void MakeSystemPath(char * p)
FileFixCase(p);
}
-public char * CopySystemPath(char * p)
+public char * CopySystemPath(const char * p)
{
char * d = CopyString(p);
if(d)
return d;
}
-public char * CopyUnixPath(char * p)
+public char * CopyUnixPath(const char * p)
{
char * d = CopyString(p);
if(d)
return d;
}
-public char * GetSystemPathBuffer(char * d, char * p)
+public char * GetSystemPathBuffer(char * d, const char * p)
{
if(d != p)
strcpy(d, p ? p : "");
return d;
}
-public char * GetSlashPathBuffer(char * d, char * p)
+public char * GetSlashPathBuffer(char * d, const char * p)
{
if(d != p)
strcpy(d, p ? p : "");