Skip to content

Change command separator to ; #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn build(b: *std.Build) void {
b.installArtifact(mkfs_fat);

// Usage:
var self_dep = std.Build.Dependency{
var self_dep: std.Build.Dependency = .{
.builder = b,
};
usageDemo(b, &self_dep, debug_step);
Expand Down Expand Up @@ -175,7 +175,7 @@ fn installDebugDisk(
pub fn initializeDisk(dependency: *std.Build.Dependency, size: u64, content: Content) *InitializeDiskStep {
const ids = dependency.builder.allocator.create(InitializeDiskStep) catch @panic("out of memory");

ids.* = InitializeDiskStep{
ids.* = .{
.step = std.Build.Step.init(.{
.owner = dependency.builder, // TODO: Is this correct?
.id = .custom,
Expand Down Expand Up @@ -459,16 +459,16 @@ pub const InitializeDiskStep = struct {
for (fs.items) |item| {
switch (item) {
.empty_dir => |dir| {
try argv.append(b.fmt("mkdir:{s}", .{dir}));
try argv.append(b.fmt("mkdir;{s}", .{dir}));
},
.copy_dir => |src_dst| {
try argv.append(b.fmt("dir:{s}:{s}", .{
try argv.append(b.fmt("dir;{s};{s}", .{
src_dst.source.getPath2(b, asking),
src_dst.destination,
}));
},
.copy_file => |src_dst| {
try argv.append(b.fmt("file:{s}:{s}", .{
try argv.append(b.fmt("file;{s};{s}", .{
src_dst.source.getPath2(b, asking),
src_dst.destination,
}));
Expand Down Expand Up @@ -564,7 +564,7 @@ pub const InitializeDiskStep = struct {
try disk.writeAll("\x00");
try disk.seekTo(0);

var context = HumanContext{};
var context: HumanContext = .{};
context.appendSliceAssumeCapacity("disk");

const disk_image = DiskImage{
Expand Down Expand Up @@ -943,9 +943,9 @@ pub const FileSystem = struct {
/// <ops...> is a list of operations that should be performed on the file system:
/// - format Formats the disk image.
/// - mount Mounts the file system, must be before all following:
/// - mkdir:<dst> Creates directory <dst> and all necessary parents.
/// - file:<src>:<dst> Copy <src> to path <dst>. If <dst> exists, it will be overwritten.
/// - dir:<src>:<dst> Copy <src> recursively into <dst>. If <dst> exists, they will be merged.
/// - mkdir;<dst> Creates directory <dst> and all necessary parents.
/// - file;<src>;<dst> Copy <src> to path <dst>. If <dst> exists, it will be overwritten.
/// - dir;<src>;<dst> Copy <src> recursively into <dst>. If <dst> exists, they will be merged.
///
/// <dst> paths are always rooted, even if they don't start with a /, and always use / as a path separator.
///
Expand Down Expand Up @@ -986,7 +986,7 @@ pub const FileSystemBuilder = struct {
format: FileSystem.Format,
label: []const u8,
}) FileSystem {
return FileSystem{
return .{
.format = options.format,
.label = fsb.b.dupe(options.label),
.items = fsb.list.toOwnedSlice(fsb.b.allocator) catch @panic("out of memory"),
Expand Down
2 changes: 1 addition & 1 deletion src/mkfs.fat.zig
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn mkfile(path: []const u8, host_file: std.fs.File) !void {

fn disk_getStatus(intf: *fatfs.Disk) fatfs.Disk.Status {
_ = intf;
return fatfs.Disk.Status{
return .{
.initialized = true,
.disk_present = true,
.write_protected = false,
Expand Down
22 changes: 10 additions & 12 deletions src/shared.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const std = @import("std");
// <ops...> is a list of operations that should be performed on the file system:
// - format Formats the disk image.
// - mount Mounts the file system, must be before all following:
// - mkdir:<dst> Creates directory <dst> and all necessary parents.
// - file:<src>:<dst> Copy <src> to path <dst>. If <dst> exists, it will be overwritten.
// - dir:<src>:<dst> Copy <src> recursively into <dst>. If <dst> exists, they will be merged.
// - mkdir;<dst> Creates directory <dst> and all necessary parents.
// - file;<src>;<dst> Copy <src> to path <dst>. If <dst> exists, it will be overwritten.
// - dir;<src>;<dst> Copy <src> recursively into <dst>. If <dst> exists, they will be merged.
//
// <dst> paths are always rooted, even if they don't start with a /, and always use / as a path separator.
//
Expand Down Expand Up @@ -56,7 +56,7 @@ pub fn App(comptime Context: type) type {
if (byte_base + byte_len > stat.size)
return mistake("invalid offsets.", .{});

device = BlockDevice{
device = .{
.file = &image_file,
.base = byte_base,
.count = byte_len / BlockDevice.block_size,
Expand All @@ -70,7 +70,7 @@ pub fn App(comptime Context: type) type {
try Context.init(file_system);

for (command_list) |command_sequence| {
var cmd_iter = std.mem.splitScalar(u8, command_sequence, ':');
var cmd_iter = std.mem.splitScalar(u8, command_sequence, ';');

const command_str = cmd_iter.next() orelse return mistake("bad command", .{});

Expand All @@ -84,15 +84,15 @@ pub fn App(comptime Context: type) type {
try Context.mount();
},
.mkdir => {
const dir = try normalize(cmd_iter.next() orelse return mistake("mkdir:<dst> is missing it's <dst> path!", .{}));
const dir = try normalize(cmd_iter.next() orelse return mistake("mkdir;<dst> is missing it's <dst> path!", .{}));

// std.log.info("mkdir(\"{}\")", .{std.zig.fmtEscapes(dir)});

try recursiveMkDir(dir);
},
.file => {
const src = cmd_iter.next() orelse return mistake("file:<src>:<dst> is missing it's <src> path!", .{});
const dst = try normalize(cmd_iter.next() orelse return mistake("file:<src>:<dst> is missing it's <dst> path!", .{}));
const src = cmd_iter.next() orelse return mistake("file;<src>;<dst> is missing it's <src> path!", .{});
const dst = try normalize(cmd_iter.next() orelse return mistake("file;<src>;<dst> is missing it's <dst> path!", .{}));

// std.log.info("file(\"{}\", \"{}\")", .{ std.zig.fmtEscapes(src), std.zig.fmtEscapes(dst) });

Expand All @@ -102,10 +102,8 @@ pub fn App(comptime Context: type) type {
try addFile(file, dst);
},
.dir => {
const src = cmd_iter.next() orelse return mistake("dir:<src>:<dst> is missing it's <src> path!", .{});
const dst = try normalize(cmd_iter.next() orelse return mistake("dir:<src>:<dst> is missing it's <dst> path!", .{}));

// std.log.info("dir(\"{}\", \"{}\")", .{ std.zig.fmtEscapes(src), std.zig.fmtEscapes(dst) });
const src = cmd_iter.next() orelse return mistake("dir;<src>;<dst> is missing it's <src> path!", .{});
const dst = try normalize(cmd_iter.next() orelse return mistake("dir;<src>;<dst> is missing it's <dst> path!", .{}));

var iter_dir = try std.fs.cwd().openDir(src, .{ .iterate = true });
defer iter_dir.close();
Expand Down
Loading