Skip to content

Commit a0c49b2

Browse files
committed
Fix formatting and uncomment code in main.zig file
1 parent 4d5ff27 commit a0c49b2

File tree

8 files changed

+172
-262
lines changed

8 files changed

+172
-262
lines changed

compiled_starters/zig/app/main.zig

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
const std = @import("std");
22

33
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+
}
3534
}

compiled_starters/zig/src/main.zig

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
const std = @import("std");
22

33
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+
}
3534
}

solutions/zig/01-dr6/code/app/main.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ pub fn main() !void {
88
const args = try std.process.argsAlloc(allocator);
99
defer std.process.argsFree(allocator, args);
1010

11-
1211
if (args.len < 3) {
1312
try std.io.getStdErr().writer().print("Usage: {s} <database_file_path> <command>\n", .{args[0]});
1413
return;
1514
}
1615

17-
var database_file_path: []const u8 = args[1];
18-
var command: []const u8 = args[2];
16+
const database_file_path: []const u8 = args[1];
17+
const command: []const u8 = args[2];
18+
1919

2020
if (std.mem.eql(u8, command, ".dbinfo")) {
2121
var file = try std.fs.cwd().openFile(database_file_path, .{});
@@ -24,7 +24,7 @@ pub fn main() !void {
2424
var buf: [2]u8 = undefined;
2525
_ = try file.seekTo(16);
2626
_ = try file.read(&buf);
27-
const page_size = std.mem.readInt(u16, &buf, .Big);
27+
const page_size = std.mem.readInt(u16, &buf, .big);
2828
try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size});
2929
}
3030
}

solutions/zig/01-dr6/code/src/main.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ pub fn main() !void {
88
const args = try std.process.argsAlloc(allocator);
99
defer std.process.argsFree(allocator, args);
1010

11-
1211
if (args.len < 3) {
1312
try std.io.getStdErr().writer().print("Usage: {s} <database_file_path> <command>\n", .{args[0]});
1413
return;
1514
}
1615

17-
var database_file_path: []const u8 = args[1];
18-
var command: []const u8 = args[2];
16+
const database_file_path: []const u8 = args[1];
17+
const command: []const u8 = args[2];
18+
1919

2020
if (std.mem.eql(u8, command, ".dbinfo")) {
2121
var file = try std.fs.cwd().openFile(database_file_path, .{});
@@ -24,7 +24,7 @@ pub fn main() !void {
2424
var buf: [2]u8 = undefined;
2525
_ = try file.seekTo(16);
2626
_ = try file.read(&buf);
27-
const page_size = std.mem.readInt(u16, &buf, .Big);
27+
const page_size = std.mem.readInt(u16, &buf, .big);
2828
try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size});
2929
}
3030
}
Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,40 @@
1-
@@ -1,35 +1,30 @@
1+
@@ -1,34 +1,30 @@
22
const std = @import("std");
33

44
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();
108

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});
5534
+ var buf: [2]u8 = undefined;
5635
+ _ = try file.seekTo(16);
5736
+ _ = try file.read(&buf);
58-
+ const page_size = std.mem.readInt(u16, &buf, .Big);
37+
+ const page_size = std.mem.readInt(u16, &buf, .big);
5938
+ try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size});
60-
+ }
39+
}
6140
}
Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,40 @@
1-
@@ -1,35 +1,30 @@
1+
@@ -1,34 +1,30 @@
22
const std = @import("std");
33

44
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();
108

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});
5534
+ var buf: [2]u8 = undefined;
5635
+ _ = try file.seekTo(16);
5736
+ _ = try file.read(&buf);
58-
+ const page_size = std.mem.readInt(u16, &buf, .Big);
37+
+ const page_size = std.mem.readInt(u16, &buf, .big);
5938
+ try std.io.getStdOut().writer().print("database page size: {}\n", .{page_size});
60-
+ }
39+
}
6140
}

0 commit comments

Comments
 (0)