Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,106 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.io;
#if doc_gen
enum FileHandle {}
#else
typedef FileHandle = hl.Abstract<"hl_fdesc">;
#end
@:access(Sys)
@:coreApi class File {
public static function getContent(path:String):String {
var bytes = file_contents(Sys.getPath(path), null);
if (bytes == null)
throw new Sys.SysError("Can't read " + path);
return @:privateAccess String.fromUTF8(bytes);
}
public static function getBytes(path:String):haxe.io.Bytes {
var size = 0;
var bytes = file_contents(Sys.getPath(path), size);
if (bytes == null)
throw new Sys.SysError("Can't read " + path);
return @:privateAccess new haxe.io.Bytes(bytes, size);
}
public static function saveContent(path:String, content:String):Void {
var f = write(path);
f.writeString(content);
f.close();
}
public static function saveBytes(path:String, bytes:haxe.io.Bytes):Void {
var f = write(path);
f.write(bytes);
f.close();
}
public static function read(path:String, binary:Bool = true):FileInput {
var f = file_open(Sys.getPath(path), 0, binary);
if (f == null)
throw new Sys.SysError("Can't open " + path);
return @:privateAccess new FileInput(f);
}
public static function write(path:String, binary:Bool = true):FileOutput {
var f = file_open(Sys.getPath(path), 1, binary);
if (f == null)
throw new Sys.SysError("Can't open " + path + " for writing");
return @:privateAccess new FileOutput(f);
}
public static function append(path:String, binary:Bool = true):FileOutput {
var f = file_open(Sys.getPath(path), 2, binary);
if (f == null)
throw new Sys.SysError("Can't open " + path + " for append");
return @:privateAccess new FileOutput(f);
}
public static function update(path:String, binary:Bool = true):FileOutput {
if (!FileSystem.exists(path)) {
write(path).close();
}
var f = file_open(Sys.getPath(path), 3, binary);
if (f == null)
throw new Sys.SysError("Can't open " + path + " for update");
return @:privateAccess new FileOutput(f);
}
public static function copy(srcPath:String, dstPath:String):Void {
var s = read(srcPath, true);
var d = write(dstPath, true);
d.writeInput(s);
s.close();
d.close();
}
@:hlNative("std", "file_open") static function file_open(path:hl.Bytes, mode:Int, binary:Bool):FileHandle {
return null;
}
@:hlNative("std", "file_contents") static function file_contents(path:hl.Bytes, size:hl.Ref<Int>):hl.Bytes {
return null;
}
}

View File

@ -0,0 +1,97 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.io;
import sys.io.File;
@:coreApi class FileInput extends haxe.io.Input {
private var __f:FileHandle;
function new(f:FileHandle):Void {
__f = f;
}
public override function readByte():Int {
var c = file_read_char(__f);
if (c < 0)
throw new haxe.io.Eof();
return c;
}
public override function readBytes(s:haxe.io.Bytes, p:Int, l:Int):Int {
if (p < 0 || l < 0 || p + l > s.length)
throw haxe.io.Error.OutsideBounds;
var v = file_read(__f, s.getData(), p, l);
if (v <= 0)
throw new haxe.io.Eof();
return v;
}
public override function close():Void {
super.close();
file_close(__f);
__f = null;
}
public function seek(p:Int, pos:FileSeek):Void {
if (!file_seek(__f, p, switch (pos) {
case SeekBegin: 0;
case SeekCur: 1;
case SeekEnd: 2;
}))
throw haxe.io.Error.Custom("seek() failure");
}
public function tell():Int {
var p = file_tell(__f);
if (p < 0)
throw haxe.io.Error.Custom("tell() failure");
return p;
}
public function eof():Bool {
return file_eof(__f);
}
@:hlNative("std", "file_eof") static function file_eof(f:FileHandle):Bool {
return false;
}
@:hlNative("std", "file_read") static function file_read(f:FileHandle, bytes:hl.Bytes, pos:Int, len:Int):Int {
return 0;
}
@:hlNative("std", "file_read_char") static function file_read_char(f:FileHandle):Int {
return 0;
}
@:hlNative("std", "file_close") static function file_close(f:FileHandle):Void {}
@:hlNative("std", "file_seek") static function file_seek(f:FileHandle, pos:Int, from:Int):Bool {
return true;
}
@:hlNative("std", "file_tell") static function file_tell(f:FileHandle):Int {
return 0;
}
}

View File

@ -0,0 +1,86 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.io;
import sys.io.File;
@:coreApi class FileOutput extends haxe.io.Output {
private var __f:FileHandle;
function new(f:FileHandle):Void {
__f = f;
}
public override function writeByte(c:Int):Void {
if (!file_write_char(__f, c))
throw new haxe.io.Eof();
}
public override function writeBytes(s:haxe.io.Bytes, p:Int, l:Int):Int {
if (p < 0 || l < 0 || p + l > s.length)
throw haxe.io.Error.OutsideBounds;
var v = file_write(__f, s.getData(), p, l);
if (v <= 0)
throw new haxe.io.Eof();
return v;
}
public override function flush():Void {
if (!file_flush(__f))
throw haxe.io.Error.Custom("flush() failure");
}
public override function close():Void {
super.close();
@:privateAccess FileInput.file_close(__f);
__f = null;
}
public function seek(p:Int, pos:FileSeek):Void {
if (@:privateAccess !FileInput.file_seek(__f, p, switch (pos) {
case SeekBegin: 0;
case SeekCur: 1;
case SeekEnd: 2;
}))
throw haxe.io.Error.Custom("seek() failure");
}
public function tell():Int {
var p = @:privateAccess FileInput.file_tell(__f);
if (p < 0)
throw haxe.io.Error.Custom("tell() failure");
return p;
}
@:hlNative("std", "file_flush") static function file_flush(f:FileHandle):Bool {
return true;
}
@:hlNative("std", "file_write") static function file_write(f:FileHandle, bytes:hl.Bytes, pos:Int, len:Int):Int {
return 0;
}
@:hlNative("std", "file_write_char") static function file_write_char(f:FileHandle, v:Int):Bool {
return true;
}
}

View File

@ -0,0 +1,201 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.io;
private typedef ProcessHandle = hl.Abstract<"hl_process">;
private class Stdin extends haxe.io.Output {
var p:Dynamic;
var buf:haxe.io.Bytes;
public function new(p) {
this.p = p;
buf = haxe.io.Bytes.alloc(1);
}
public override function close() {
super.close();
_stdin_close(p);
}
public override function writeByte(c) {
buf.set(0, c);
writeBytes(buf, 0, 1);
}
public override function writeBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
var v = _stdin_write(p, buf.getData().bytes, pos, len);
if (v < 0)
throw new haxe.io.Eof();
return v;
}
@:hlNative("std", "process_stdin_write") static function _stdin_write(p:ProcessHandle, bytes:hl.Bytes, pos:Int, len:Int):Int {
return 0;
}
@:hlNative("std", "process_stdin_close") static function _stdin_close(p:ProcessHandle):Bool {
return false;
}
}
private class Stdout extends haxe.io.Input {
var p:ProcessHandle;
var out:Bool;
var buf:haxe.io.Bytes;
public function new(p, out) {
this.p = p;
this.out = out;
buf = haxe.io.Bytes.alloc(1);
}
public override function readByte() {
if (readBytes(buf, 0, 1) == 0)
throw haxe.io.Error.Blocked;
return buf.get(0);
}
public override function readBytes(str:haxe.io.Bytes, pos:Int, len:Int):Int {
var v = out ? _stdout_read(p, str.getData().bytes, pos, len) : _stderr_read(p, str.getData().bytes, pos, len);
if (v < 0)
throw new haxe.io.Eof();
return v;
}
@:hlNative("std", "process_stdout_read") static function _stdout_read(p:ProcessHandle, bytes:hl.Bytes, pos:Int, len:Int):Int {
return 0;
}
@:hlNative("std", "process_stderr_read") static function _stderr_read(p:ProcessHandle, bytes:hl.Bytes, pos:Int, len:Int):Int {
return 0;
}
}
@:access(Sys)
@:coreApi class Process {
var p:ProcessHandle;
public var stdout(default, null):haxe.io.Input;
public var stderr(default, null):haxe.io.Input;
public var stdin(default, null):haxe.io.Output;
static var isWin = Sys.systemName() == "Windows";
public function new(cmd:String, ?args:Array<String>, ?detached:Bool):Void {
var runCmd = cmd;
if (isWin) {
var b = new StringBuf();
if (args == null) {
var exe = Sys.getEnv("COMSPEC");
if (exe == null)
exe = "cmd.exe";
b.add("\"");
b.add(exe);
b.add("\" /C \"");
b.add(cmd);
b.addChar('"'.code);
} else {
b.addChar('"'.code);
b.add(cmd);
b.addChar('"'.code);
for (a in args) {
b.add(" \"");
var bsCount = 0;
for (i in 0...a.length) {
switch (StringTools.fastCodeAt(a, i)) {
case '"'.code:
for (i in 0...bsCount * 2)
b.addChar('\\'.code);
bsCount = 0;
b.add("\\\"");
case '\\'.code:
bsCount++;
case c:
for (i in 0...bsCount)
b.addChar('\\'.code);
bsCount = 0;
b.addChar(c);
}
}
// Add remaining backslashes, if any.
for (i in 0...bsCount * 2)
b.addChar('\\'.code);
b.addChar('"'.code);
}
args = null;
}
runCmd = b.toString();
}
@:privateAccess {
var aargs = null;
if (args != null) {
aargs = new hl.NativeArray<hl.Bytes>(args.length);
for (i in 0...args.length)
aargs[i] = Sys.getPath(args[i]);
}
p = _run(Sys.getPath(runCmd), aargs, detached);
}
if (p == null)
throw new Sys.SysError("Process creation failure : " + cmd);
stdin = new Stdin(p);
stdout = new Stdout(p, true);
stderr = new Stdout(p, false);
}
public function getPid():Int {
return _pid(p);
}
public function exitCode(block:Bool = true):Null<Int> {
var running = false;
var code = _exit(p, block == false ? new hl.Ref(running) : null);
if (block == false)
return running ? null : code;
return code;
}
public function close():Void {
_close(p);
}
public function kill():Void {
_kill(p);
}
@:hlNative("std", "process_run") static function _run(cmd:hl.Bytes, args:hl.NativeArray<hl.Bytes>, detached:Bool):ProcessHandle {
return null;
}
@:hlNative("std", "process_exit") static function _exit(p:ProcessHandle, running:hl.Ref<Bool>):Int {
return 0;
}
@:hlNative("std", "process_pid") static function _pid(p:ProcessHandle):Int {
return 0;
}
@:hlNative("std", "process_close") static function _close(p:ProcessHandle):Void {}
@:hlNative("std", "process_kill") static function _kill(p:ProcessHandle):Void {}
}