|
1 | | -@@ -1,35 +1,30 @@ |
| 1 | +@@ -1,34 +1,30 @@ |
2 | 2 | const std = @import("std"); |
3 | 3 |
|
4 | 4 | pub fn main() !void { |
5 | | -- // You can use print statements as follows for debugging, they'll be visible when running tests. |
6 | | -- try std.io.getStdOut().writer().print("Logs from your program will appear here\n", .{}); |
7 | | -+ var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
8 | | -+ defer _ = gpa.deinit(); |
9 | | -+ const allocator = gpa.allocator(); |
| 5 | + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| 6 | + defer _ = gpa.deinit(); |
| 7 | + const allocator = gpa.allocator(); |
10 | 8 |
|
11 | | -- // Uncomment this to pass the first stage |
12 | | -- // |
13 | | -- // var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
14 | | -- // defer _ = gpa.deinit(); |
15 | | -- // const allocator = gpa.allocator(); |
16 | | -- // |
17 | | -- // const args = try std.process.argsAlloc(allocator); |
18 | | -- // defer std.process.argsFree(allocator, args); |
19 | | -- // |
20 | | -- // |
21 | | -- // if (args.len < 3) { |
22 | | -- // try std.io.getStdErr().writer().print("Usage: {s} <database_file_path> <command>\n", .{args[0]}); |
23 | | -- // return; |
24 | | -- // } |
25 | | -- // |
26 | | -- // var database_file_path: []const u8 = args[1]; |
27 | | -- // var command: []const u8 = args[2]; |
28 | | -- // |
29 | | -- // if (std.mem.eql(u8, command, ".dbinfo")) { |
30 | | -- // var file = try std.fs.cwd().openFile(database_file_path, .{}); |
31 | | -- // defer file.close(); |
32 | | -- // |
33 | | -- // var buf: [2]u8 = undefined; |
34 | | -- // _ = try file.seekTo(16); |
35 | | -- // _ = try file.read(&buf); |
36 | | -- // const page_size = std.mem.readInt(u16, &buf, .Big); |
37 | | -- // try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size}); |
38 | | -- // } |
39 | | -+ const args = try std.process.argsAlloc(allocator); |
40 | | -+ defer std.process.argsFree(allocator, args); |
41 | | -+ |
42 | | -+ |
43 | | -+ if (args.len < 3) { |
44 | | -+ try std.io.getStdErr().writer().print("Usage: {s} <database_file_path> <command>\n", .{args[0]}); |
45 | | -+ return; |
46 | | -+ } |
47 | | -+ |
48 | | -+ var database_file_path: []const u8 = args[1]; |
49 | | -+ var command: []const u8 = args[2]; |
50 | | -+ |
51 | | -+ if (std.mem.eql(u8, command, ".dbinfo")) { |
52 | | -+ var file = try std.fs.cwd().openFile(database_file_path, .{}); |
53 | | -+ defer file.close(); |
54 | | -+ |
| 9 | + const args = try std.process.argsAlloc(allocator); |
| 10 | + defer std.process.argsFree(allocator, args); |
| 11 | + |
| 12 | + if (args.len < 3) { |
| 13 | + try std.io.getStdErr().writer().print("Usage: {s} <database_file_path> <command>\n", .{args[0]}); |
| 14 | + return; |
| 15 | + } |
| 16 | + |
| 17 | + const database_file_path: []const u8 = args[1]; |
| 18 | + const command: []const u8 = args[2]; |
| 19 | + |
| 20 | + |
| 21 | + if (std.mem.eql(u8, command, ".dbinfo")) { |
| 22 | + var file = try std.fs.cwd().openFile(database_file_path, .{}); |
| 23 | + defer file.close(); |
| 24 | + |
| 25 | +- // You can use print statements as follows for debugging, they'll be visible when running tests. |
| 26 | +- try std.io.getStdOut().writer().print("Logs from your program will appear here\n", .{}); |
| 27 | +- |
| 28 | +- // Uncomment this block to pass the first stage |
| 29 | +- // var buf: [2]u8 = undefined; |
| 30 | +- // _ = try file.seekTo(16); |
| 31 | +- // _ = try file.read(&buf); |
| 32 | +- // const page_size = std.mem.readInt(u16, &buf, .big); |
| 33 | +- // try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size}); |
55 | 34 | + var buf: [2]u8 = undefined; |
56 | 35 | + _ = try file.seekTo(16); |
57 | 36 | + _ = try file.read(&buf); |
58 | | -+ const page_size = std.mem.readInt(u16, &buf, .Big); |
| 37 | ++ const page_size = std.mem.readInt(u16, &buf, .big); |
59 | 38 | + try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size}); |
60 | | -+ } |
| 39 | + } |
61 | 40 | } |
0 commit comments