Skip to content

Commit

Permalink
adopt zig master
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Mar 23, 2024
1 parent 1e83260 commit 300278e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/simargs-demo.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const std = @import("std");
const simargs = @import("simargs");

pub const std_options = struct {
pub const log_level: std.log.Level = .info;
pub const std_options = .{
.log_level = .info,
};

pub fn main() !void {
Expand Down
20 changes: 14 additions & 6 deletions src/bin/loc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const util = @import("util.zig");
const StringUtil = util.StringUtil;
const fs = std.fs;

pub const std_options = .{
.log_level = .info,
};

const IGNORE_DIRS = [_][]const u8{ ".git", "zig-cache", "zig-out", "target", "vendor", "node_modules", "out" };

const Language = enum {
Expand Down Expand Up @@ -172,10 +176,6 @@ const LinesOfCode = struct {

const LocMap = std.enums.EnumMap(Language, LinesOfCode);

pub const std_options = struct {
pub const log_level: std.log.Level = .info;
};

pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
Expand Down Expand Up @@ -350,8 +350,16 @@ fn populateLoc(allocator: std.mem.Allocator, loc_map: *LocMap, dir: fs.Dir, base
}
},
else => {
var ptr = try std.os.mmap(null, file_size, std.os.PROT.READ, std.os.MAP.PRIVATE, file.handle, 0);
defer std.os.munmap(ptr);
var ptr = try std.posix.mmap(
null,
file_size,
std.posix.PROT.READ,
.{ .TYPE = .PRIVATE },

file.handle,
0,
);
defer std.posix.munmap(ptr);

var offset_so_far: usize = 0;
while (offset_so_far < ptr.len) {
Expand Down
8 changes: 4 additions & 4 deletions src/bin/pidof.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ pub fn findPids(allocator: std.mem.Allocator, opt: Options, program: []const u8)
var procSize: usize = 0;
var rc = c.sysctl(&mib, mib.len, null, &procSize, null, 0);
if (rc != 0) {
std.debug.print("get proc size, err:{any}", .{std.c.getErrno(rc)});
std.debug.print("get proc size, err:{any}", .{std.posix.errno(rc)});
return error.sysctl;
}

const procList = try allocator.alloc(c.struct_kinfo_proc, procSize / @sizeOf(c.struct_kinfo_proc));
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/sysctl.3.html
rc = c.sysctl(&mib, mib.len, @ptrCast(procList), &procSize, null, 0);
if (rc != 0) {
std.debug.print("get proc list failed, err:{any}", .{std.c.getErrno(rc)});
std.debug.print("get proc list failed, err:{any}", .{std.posix.errno(rc)});
return error.sysctl;
}

Expand Down Expand Up @@ -91,14 +91,14 @@ pub fn main() !void {

if (opt.positional_args.items.len == 0) {
std.debug.print("program is not given", .{});
std.os.exit(1);
std.posix.exit(1);
}

const program = opt.positional_args.items[0];

const pids = try findPids(allocator, opt.args, program);
if (pids.items.len == 0) {
std.os.exit(1);
std.posix.exit(1);
}

var stdout = std.io.getStdOut().writer();
Expand Down
4 changes: 2 additions & 2 deletions src/bin/tree.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const mem = std.mem;
const testing = std.testing;
const fmt = std.fmt;

pub const std_options = struct {
pub const log_level: std.log.Level = .info;
pub const std_options = .{
.log_level = .info,
};

const Mode = enum {
Expand Down
6 changes: 3 additions & 3 deletions src/mod/simargs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ test "parse/valid option values" {
\\
\\ OPTIONS:
\\ -h, --help print this help message(required)
\\ -r, --rate FLOAT (default: 2.0e+00)
\\ -r, --rate FLOAT (default: 2e0)
\\ --timeout INTEGER (required)
\\ --user-agent STRING (default: Brave)
\\
Expand Down Expand Up @@ -773,8 +773,8 @@ test "parse/default value" {
\\ --a2 STRING (default: A2)
\\ --b1 INTEGER (default: 1)
\\ --b2 INTEGER (default: 11)
\\ --c1 FLOAT (default: 1.5e+00)
\\ --c2 FLOAT (default: 2.5e+00)
\\ --c1 FLOAT (default: 1.5e0)
\\ --c2 FLOAT (default: 2.5e0)
\\ --d1 (default: true)
\\ --d2 padding message
\\
Expand Down

0 comments on commit 300278e

Please sign in to comment.