Application Context Implementation #4
|
@ -1,6 +1,13 @@
|
||||||
const core = @import("core");
|
const core = @import("core");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
pub const Archive = struct {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
/// An entry block of an Oar archive file.
|
/// An entry block of an Oar archive file.
|
||||||
///
|
///
|
||||||
|
@ -34,7 +41,7 @@ pub const Entry = extern struct {
|
||||||
const origin = try file_access.queryCursor();
|
const origin = try file_access.queryCursor();
|
||||||
|
|
||||||
if (((try file_access.read(mem.asBytes(&entry))) != @sizeOf(Entry)) and
|
if (((try file_access.read(mem.asBytes(&entry))) != @sizeOf(Entry)) and
|
||||||
core.io.equalsBytes(&entry.signature, &signature_magic)) {
|
core.io.equals(u8, &entry.signature, &signature_magic)) {
|
||||||
|
|
||||||
try file_access.seek(origin);
|
try file_access.seek(origin);
|
||||||
|
|
||||||
|
@ -172,7 +179,7 @@ pub fn main() u8 {
|
||||||
const process = std.process;
|
const process = std.process;
|
||||||
|
|
||||||
const args = process.argsAlloc(allocator) catch {
|
const args = process.argsAlloc(allocator) catch {
|
||||||
try out_writer.print("Failed to allocate args memory", .{});
|
out_writer.print("Failed to allocate args memory\n", .{}) catch undefined;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
@ -180,19 +187,61 @@ pub fn main() u8 {
|
||||||
defer process.argsFree(allocator, args);
|
defer process.argsFree(allocator, args);
|
||||||
|
|
||||||
if (args.len < 2) {
|
if (args.len < 2) {
|
||||||
try out_writer.print("Usage: oar [OPTION]... [FILE]...", .{});
|
out_writer.print("Usage: oar [OPTION]... [FILE]...\n", .{}) catch undefined;
|
||||||
try out_writer.print("Options and arguments", .{});
|
out_writer.print("Options and arguments\n", .{}) catch undefined;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const arg = std.mem.sliceTo(args[1], 0);
|
const arg = std.mem.sliceTo(args[1], 0);
|
||||||
|
|
||||||
if (core.io.begins(arg, "--create")) {
|
if (core.io.equals(u8, arg, "--create")) {
|
||||||
|
if (args.len < 3) {
|
||||||
|
out_writer.print("Expected output file specified after `--create`\n", .{}) catch undefined;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var archive = Archive.init(allocator, Path.joined(&.{args[2]})) catch {
|
||||||
|
out_writer.print("Failed to initialize archive for create\n", .{}) catch undefined;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
defer archive.deinit();
|
||||||
|
|
||||||
|
for (args[3 .. ]) |input_file_path| {
|
||||||
|
const file = std.fs.cwd().openFile(input_file_path) catch {
|
||||||
|
out_writer.print("Failed to open {s}\n", .{input_file_path}) catch undefined;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
defer file.close();
|
||||||
|
|
||||||
|
var entry = archive.open(Path.joined(&.{input_file_path})) catch {
|
||||||
|
out_writer.print("Failed to open {s}\n", .{input_file_path}) catch undefined;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
defer archive.close(entry);
|
||||||
|
|
||||||
|
var copy_buffer = std.mem.zeroes([4096]u8);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const read = try file.read(©_buffer);
|
||||||
|
|
||||||
|
if (read == 0) break;
|
||||||
|
|
||||||
|
try entry.write(copy_buffer[read ..]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
try out_writer.print("Unrecognized command-line option `{s}`", .{arg});
|
out_writer.print("Unrecognized command-line option `{s}`\n", .{arg}) catch undefined;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue