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