Zig bindings for orca (still WIP) #140
268
src/orca.zig
268
src/orca.zig
|
@ -1797,24 +1797,127 @@ pub const Canvas = extern struct {
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
const File = extern struct {
|
const File = extern struct {
|
||||||
|
const OpenFlags = packed struct(u16) {
|
||||||
|
none: bool,
|
||||||
|
append: bool,
|
||||||
|
truncate: bool,
|
||||||
|
create: bool,
|
||||||
|
|
||||||
|
symlink: bool,
|
||||||
|
no_follow: bool,
|
||||||
|
restrict: bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
const AccessFlags = packed struct(u16) {
|
||||||
|
none: bool,
|
||||||
|
read: bool,
|
||||||
|
write: bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
const Whence = enum(c_uint) {
|
||||||
|
Set,
|
||||||
|
End,
|
||||||
|
Current,
|
||||||
|
};
|
||||||
|
|
||||||
|
const Type = enum(c_uint) {
|
||||||
|
Unknown,
|
||||||
|
Regular,
|
||||||
|
Directory,
|
||||||
|
Symlink,
|
||||||
|
Block,
|
||||||
|
Character,
|
||||||
|
Fifo,
|
||||||
|
Socket,
|
||||||
|
};
|
||||||
|
|
||||||
|
const Perm = packed struct(u16) {
|
||||||
|
other_exec: bool,
|
||||||
|
other_write: bool,
|
||||||
|
other_read: bool,
|
||||||
|
group_exec: bool,
|
||||||
|
group_write: bool,
|
||||||
|
group_read: bool,
|
||||||
|
owner_exec: bool,
|
||||||
|
owner_write: bool,
|
||||||
|
owner_read: bool,
|
||||||
|
sticky_bit: bool,
|
||||||
|
set_gid: bool,
|
||||||
|
set_uid: bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
const DateStamp = extern struct {
|
||||||
|
seconds: i64, // seconds relative to NTP epoch.
|
||||||
|
fraction: u64, // fraction of seconds elapsed since the time specified by seconds.
|
||||||
|
};
|
||||||
|
|
||||||
|
const Status = extern struct {
|
||||||
|
uid: u64,
|
||||||
|
type: Type,
|
||||||
|
perm: Perm,
|
||||||
|
size: u64,
|
||||||
|
|
||||||
|
creation_date: DateStamp,
|
||||||
|
access_date: DateStamp,
|
||||||
|
modification_date: DateStamp,
|
||||||
|
};
|
||||||
|
|
||||||
|
const DialogKind = enum(c_uint) {
|
||||||
|
Save,
|
||||||
|
Open,
|
||||||
|
};
|
||||||
|
|
||||||
|
const DialogFlags = packed struct(u32) {
|
||||||
|
files: bool,
|
||||||
|
directories: bool,
|
||||||
|
multiple: bool,
|
||||||
|
create_directories: bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
const DialogDesc = extern struct {
|
||||||
|
kind: DialogKind,
|
||||||
|
flags: DialogFlags,
|
||||||
|
title: Str8,
|
||||||
|
ok_label: Str8,
|
||||||
|
start_at: File,
|
||||||
|
start_path: Str8,
|
||||||
|
filters: Str8List,
|
||||||
|
};
|
||||||
|
|
||||||
|
const DialogButton = enum(c_uint) {
|
||||||
|
Cancel,
|
||||||
|
Ok,
|
||||||
|
};
|
||||||
|
|
||||||
|
const OpenWithDialogElt = extern struct {
|
||||||
|
list_elt: ListElt,
|
||||||
|
file: File,
|
||||||
|
};
|
||||||
|
|
||||||
|
const OpenWithDialogResult = extern struct {
|
||||||
|
button: DialogButton,
|
||||||
|
file: File,
|
||||||
|
selection: List,
|
||||||
|
};
|
||||||
|
|
||||||
h: u64,
|
h: u64,
|
||||||
|
|
||||||
extern fn oc_file_nil() File;
|
extern fn oc_file_nil() File;
|
||||||
extern fn oc_file_is_nil(file: File) bool;
|
extern fn oc_file_is_nil(file: File) bool;
|
||||||
extern fn oc_file_open(path: Str8, rights: FileAccessFlags, flags: FileOpenFlags) File;
|
extern fn oc_file_open(path: Str8, rights: AccessFlags, flags: OpenFlags) File;
|
||||||
extern fn oc_file_open_at(dir: File, path: Str8, rights: FileAccessFlags, flags: FileOpenFlags) File;
|
extern fn oc_file_open_at(dir: File, path: Str8, rights: AccessFlags, flags: OpenFlags) File;
|
||||||
extern fn oc_file_close(file: File) void;
|
extern fn oc_file_close(file: File) void;
|
||||||
extern fn oc_file_last_error(file: File) IoError;
|
extern fn oc_file_last_error(file: File) io.Error;
|
||||||
extern fn oc_file_pos(file: File) i64;
|
extern fn oc_file_pos(file: File) i64;
|
||||||
extern fn oc_file_seek(file: File, offset: i64, whence: FileWhence) i64;
|
extern fn oc_file_seek(file: File, offset: i64, whence: Whence) i64;
|
||||||
extern fn oc_file_write(file: File, size: u64, buffer: ?[*]u8) u64;
|
extern fn oc_file_write(file: File, size: u64, buffer: ?[*]u8) u64;
|
||||||
extern fn oc_file_read(file: File, size: u64, buffer: ?[*]u8) u64;
|
extern fn oc_file_read(file: File, size: u64, buffer: ?[*]u8) u64;
|
||||||
|
|
||||||
extern fn oc_file_get_status(file: File) FileStatus;
|
extern fn oc_file_get_status(file: File) Status;
|
||||||
extern fn oc_file_size(file: File) u64;
|
extern fn oc_file_size(file: File) u64;
|
||||||
|
|
||||||
extern fn oc_file_open_with_request(path: Str8, rights: FileAccessFlags, flags: FileOpenFlags) File;
|
extern fn oc_file_open_with_request(path: Str8, rights: AccessFlags, flags: OpenFlags) File;
|
||||||
extern fn oc_file_open_with_dialog(arena: *Arena, rights: FileAccessFlags, flags: FileOpenFlags, desc: *FileDialogDesc) FileOpenWithDialogResult;
|
extern fn oc_file_open_with_dialog(arena: *Arena, rights: AccessFlags, flags: OpenFlags, desc: *DialogDesc) OpenWithDialogResult;
|
||||||
|
|
||||||
pub const nil = oc_file_nil;
|
pub const nil = oc_file_nil;
|
||||||
pub const isNil = oc_file_is_nil;
|
pub const isNil = oc_file_is_nil;
|
||||||
|
@ -1834,33 +1937,15 @@ const File = extern struct {
|
||||||
pub const openWithDialog = oc_file_open_with_dialog;
|
pub const openWithDialog = oc_file_open_with_dialog;
|
||||||
};
|
};
|
||||||
|
|
||||||
const FileOpenFlags = packed struct(u16) {
|
//------------------------------------------------------------------------------------------
|
||||||
none: bool,
|
// [FILE IO] low-level io queue api
|
||||||
append: bool,
|
//------------------------------------------------------------------------------------------
|
||||||
truncate: bool,
|
|
||||||
create: bool,
|
|
||||||
|
|
||||||
symlink: bool,
|
const io = struct {
|
||||||
no_follow: bool,
|
const ReqId = u16;
|
||||||
restrict: bool,
|
const Op = u32;
|
||||||
};
|
|
||||||
|
|
||||||
const FileAccessFlags = packed struct(u16) {
|
const OpEnum = enum(c_uint) {
|
||||||
none: bool,
|
|
||||||
read: bool,
|
|
||||||
write: bool,
|
|
||||||
};
|
|
||||||
|
|
||||||
const FileWhence = enum(c_uint) {
|
|
||||||
Set,
|
|
||||||
End,
|
|
||||||
Current,
|
|
||||||
};
|
|
||||||
|
|
||||||
const IoReqId = u16;
|
|
||||||
const IoOp = u32;
|
|
||||||
|
|
||||||
const IoOpEnum = enum(c_uint) {
|
|
||||||
OpenAt = 0,
|
OpenAt = 0,
|
||||||
Close,
|
Close,
|
||||||
FStat,
|
FStat,
|
||||||
|
@ -1868,11 +1953,11 @@ const IoOpEnum = enum(c_uint) {
|
||||||
Read,
|
Read,
|
||||||
Write,
|
Write,
|
||||||
Error,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
const IoReq = extern struct {
|
const Req = extern struct {
|
||||||
id: IoReqId,
|
id: ReqId,
|
||||||
op: IoOp,
|
op: Op,
|
||||||
handle: File,
|
handle: File,
|
||||||
|
|
||||||
offset: i64,
|
offset: i64,
|
||||||
|
@ -1885,14 +1970,14 @@ const IoReq = extern struct {
|
||||||
|
|
||||||
type: extern union {
|
type: extern union {
|
||||||
open: extern struct {
|
open: extern struct {
|
||||||
rights: FileAccessFlags,
|
rights: File.AccessFlags,
|
||||||
flags: FileOpenFlags,
|
flags: File.OpenFlags,
|
||||||
},
|
},
|
||||||
whence: FileWhence,
|
whence: File.Whence,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const IoError = enum(i32) {
|
const Error = enum(i32) {
|
||||||
Ok = 0,
|
Ok = 0,
|
||||||
Unknown,
|
Unknown,
|
||||||
Op, // unsupported operation
|
Op, // unsupported operation
|
||||||
|
@ -1916,103 +2001,20 @@ const IoError = enum(i32) {
|
||||||
Physical, // physical IO error
|
Physical, // physical IO error
|
||||||
NoDevice, // device not found
|
NoDevice, // device not found
|
||||||
Walkout, // attempted to walk out of root directory
|
Walkout, // attempted to walk out of root directory
|
||||||
};
|
};
|
||||||
|
|
||||||
const IoCmp = extern struct {
|
const Cmp = extern struct {
|
||||||
id: IoReqId,
|
id: ReqId,
|
||||||
err: IoError,
|
err: Error,
|
||||||
data: extern union {
|
data: extern union {
|
||||||
result: i64,
|
result: i64,
|
||||||
size: u64,
|
size: u64,
|
||||||
offset: i64,
|
offset: i64,
|
||||||
handle: File,
|
handle: File,
|
||||||
},
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
extern fn oc_io_wait_single_req(req: *Req) Cmp;
|
||||||
|
|
||||||
|
pub const waitSingleReq = oc_io_wait_single_req;
|
||||||
};
|
};
|
||||||
|
|
||||||
const FileType = enum(c_uint) {
|
|
||||||
Unknown,
|
|
||||||
Regular,
|
|
||||||
Directory,
|
|
||||||
Symlink,
|
|
||||||
Block,
|
|
||||||
Character,
|
|
||||||
Fifo,
|
|
||||||
Socket,
|
|
||||||
};
|
|
||||||
|
|
||||||
const FilePerm = packed struct(u16) {
|
|
||||||
other_exec: bool,
|
|
||||||
other_write: bool,
|
|
||||||
other_read: bool,
|
|
||||||
group_exec: bool,
|
|
||||||
group_write: bool,
|
|
||||||
group_read: bool,
|
|
||||||
owner_exec: bool,
|
|
||||||
owner_write: bool,
|
|
||||||
owner_read: bool,
|
|
||||||
sticky_bit: bool,
|
|
||||||
set_gid: bool,
|
|
||||||
set_uid: bool,
|
|
||||||
};
|
|
||||||
|
|
||||||
const DateStamp = extern struct {
|
|
||||||
seconds: i64, // seconds relative to NTP epoch.
|
|
||||||
fraction: u64, // fraction of seconds elapsed since the time specified by seconds.
|
|
||||||
};
|
|
||||||
|
|
||||||
const FileStatus = extern struct {
|
|
||||||
uid: u64,
|
|
||||||
type: FileType,
|
|
||||||
perm: FilePerm,
|
|
||||||
size: u64,
|
|
||||||
|
|
||||||
creation_date: DateStamp,
|
|
||||||
access_date: DateStamp,
|
|
||||||
modification_date: DateStamp,
|
|
||||||
};
|
|
||||||
|
|
||||||
const FileDialogKind = enum(c_uint) {
|
|
||||||
Save,
|
|
||||||
Open,
|
|
||||||
};
|
|
||||||
|
|
||||||
const FileDialogFlags = packed struct(u32) {
|
|
||||||
files: bool,
|
|
||||||
directories: bool,
|
|
||||||
multiple: bool,
|
|
||||||
create_directories: bool,
|
|
||||||
};
|
|
||||||
|
|
||||||
const FileDialogDesc = extern struct {
|
|
||||||
kind: FileDialogKind,
|
|
||||||
flags: FileDialogFlags,
|
|
||||||
title: Str8,
|
|
||||||
ok_label: Str8,
|
|
||||||
start_at: File,
|
|
||||||
start_path: Str8,
|
|
||||||
filters: Str8List,
|
|
||||||
};
|
|
||||||
|
|
||||||
const FileDialogButton = enum(c_uint) {
|
|
||||||
Cancel,
|
|
||||||
Ok,
|
|
||||||
};
|
|
||||||
|
|
||||||
const FileOpenWithDialogElt = extern struct {
|
|
||||||
list_elt: ListElt,
|
|
||||||
file: File,
|
|
||||||
};
|
|
||||||
|
|
||||||
const FileOpenWithDialogResult = extern struct {
|
|
||||||
button: FileDialogButton,
|
|
||||||
file: File,
|
|
||||||
selection: List,
|
|
||||||
};
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------
|
|
||||||
// [FILE IO] complete io queue api
|
|
||||||
//------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
extern fn oc_io_wait_single_req(req: *IoReq) IoCmp;
|
|
||||||
|
|
||||||
pub const ioWaitSingleReq = oc_io_wait_single_req;
|
|
||||||
|
|
Loading…
Reference in New Issue