Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
version: 0.16.0

- name: Build
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.zig-cache/
zig-out/
zig-pkg/
6 changes: 3 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
.name = .hyperdoc,
.version = "0.1.0",
.fingerprint = 0xfd1a4802abc4739e,

.minimum_zig_version = "0.16.0",
.dependencies = .{
.parser_toolkit = .{
.url = "git+https://github.com/ikskuh/parser-toolkit.git#62e0a3dca3632bb361df59407b2d7805280ab1b9",
.hash = "parser_toolkit-0.1.0-baYGPUVCEwBaVmu09ORh0lLlVjRaJ489TdSIdTa_8VWg",
},
.args = .{
.url = "git+https://github.com/ikskuh/zig-args.git#8ae26b44a884ff20dca98ee84c098e8f8e94902f",
.hash = "args-0.0.0-CiLiqojRAACGzDRO7A9dw7kWSchNk29caJZkXuMCb0Cn",
.url = "git+https://github.com/ikskuh/zig-args.git#d47ae21768f9ec47c2a4154ab48b87166965b820",
.hash = "args-0.0.0-CiLiqmvgAADyJmrzcQTP9IOYNvTzR_KGrg3ZNNsH2Qv0",
},
},

Expand Down
32 changes: 15 additions & 17 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@ const std = @import("std");
const hdoc = @import("hyperdoc");
const args_parser = @import("args");

pub fn main() !u8 {
pub fn main(init: std.process.Init) !u8 {
var stdout_buf: [1024]u8 = undefined;
const stdout_file: std.fs.File = .stdout();
var stdout_writer = stdout_file.writer(&stdout_buf);
const stdout_file: std.Io.File = .stdout();
var stdout_writer = stdout_file.writer(init.io, &stdout_buf);
const stdout = &stdout_writer.interface;
var stderr_buf: [1024]u8 = undefined;
const stderr_file: std.fs.File = .stderr();
var stderr_writer = stderr_file.writer(&stderr_buf);
const stderr_file: std.Io.File = .stderr();
var stderr_writer = stderr_file.writer(init.io, &stderr_buf);
const stderr = &stderr_writer.interface;

var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = init.gpa;

const allocator = gpa.allocator();

var cli = args_parser.parseForCurrentProcess(CliOptions, allocator, .print) catch return 1;
var cli = args_parser.parseForCurrentProcess(CliOptions, init, .print) catch return 1;
defer cli.deinit();

if (cli.options.help) {
Expand All @@ -33,10 +30,11 @@ pub fn main() !u8 {
var error_location: hdoc.ErrorLocation = undefined;

var document: hdoc.Document = blk: {
const source_text = try std.fs.cwd().readFileAlloc(
allocator,
const source_text = try std.Io.Dir.cwd().readFileAlloc(
init.io,
cli.positionals[0],
512 << 20,
allocator,
.limited(512 << 20),
); // 512MB
defer allocator.free(source_text);

Expand Down Expand Up @@ -64,11 +62,11 @@ pub fn main() !u8 {
};
defer document.deinit();

const output_file: ?std.fs.File = if (cli.options.output != null and !std.mem.eql(u8, cli.options.output.?, "-"))
try std.fs.cwd().createFile(cli.options.output.?, .{})
const output_file: ?std.Io.File = if (cli.options.output != null and !std.mem.eql(u8, cli.options.output.?, "-"))
try std.Io.Dir.cwd().createFile(init.io, cli.options.output.?, .{})
else
null;
defer if (output_file) |f| f.close();
defer if (output_file) |f| f.close(init.io);

const renderDocument = switch (cli.options.format) {
.hdoc => &@import("renderer/HyperDoc.zig").render,
Expand All @@ -78,7 +76,7 @@ pub fn main() !u8 {

if (output_file) |f| {
var out_buf: [1024]u8 = undefined;
var out_writer = f.writer(&out_buf);
var out_writer = f.writer(init.io, &out_buf);
const output_stream = &out_writer.interface;
try renderDocument(output_stream, document);
try output_stream.flush();
Expand Down
Loading