Open file in relative or absolute path. Delete useless conf code.

This commit is contained in:
KikooDX 2021-02-24 09:30:48 +01:00
parent 63ebdee01f
commit 98bfeb385b
4 changed files with 18 additions and 24 deletions

0
sample.kble Normal file
View File

View File

@ -12,24 +12,3 @@ pub const arg_type: type = u16;
pub const mouse_enabled: bool = true;
pub const mouse_left_btn: c_int = 0;
pub const mouse_right_btn: c_int = 1;
/// Read /etc/kble.conf and execute all bytes as keypresses.
pub fn source_config() void {
// Open file in read mode.
const file: std.fs.File = std.fs.openFileAbsolute("/etc/kble.conf", std.fs.File.OpenFlags{
.read = true,
.write = false,
}) catch {
std.log.err("Can't open /etc/kble.conf", .{});
return;
};
// Get reader.
const reader: std.fs.File.Reader = file.reader();
// Read all bytes.
while (true) {
const byte: u8 = reader.readByte() catch {
break;
};
std.log.info("{}", .{byte});
}
}

View File

@ -58,6 +58,15 @@ pub fn init_load(allocator: *std.mem.Allocator, kble_file_path: []const u8) !Sel
.selection = undefined,
};
// Open directory.
var dir: std.fs.Dir = std.fs.cwd();
// Open file in read mode.
const file: std.fs.File = try dir.openFile(kble_file_path, std.fs.File.OpenFlags{
.read = true,
.write = false,
});
defer file.close();
return self;
}
@ -207,3 +216,12 @@ test "select rectangle area" {
expect(level.selection[31]);
expect(!level.selection[245]);
}
test "load level from existing file" {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = &arena.allocator;
var level: Self = try Self.init_load(allocator, "sample.kble");
//defer level.deinit(allocator);
}

View File

@ -89,9 +89,6 @@ pub fn main() void {
bindings['v'] = &ActionsDef.mode_rectangle;
bindings['c'] = &ActionsDef.mode_camera;
// Load config.
conf.source_config();
// Create input buffer.
const input_buffer_len = 255;
var input_buffer: [input_buffer_len]u32 = undefined;