Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

renderAutoconfAt

ConfigHeader.renderAutoconfAt
fn renderAutoconfAt(
    maker: *Maker,
    step: *Step,
    contents: []const u8,
    aw: *Writer.Allocating,
    value_pairs: []const Value.Pair,
    value_map: *const ValueMap,
    src_path: Path,
) !void

File

lib/compiler/Maker/Step/ConfigHeader.zig:219

Code

fn renderAutoconfAt(
    maker: *Maker,
    step: *Step,
    contents: []const u8,
    aw: *Writer.Allocating,
    value_pairs: []const Value.Pair,
    value_map: *const ValueMap,
    src_path: Path,
) !void {
    const w = &aw.writer;
    const conf = &maker.scanned_config.configuration;
    const newline = detectNewline(contents);

    try w.writeAll(c_generated_line);
    try w.writeAll(newline);

    var any_errors = false;
    var line_index: u32 = 0;
    var line_it = std.mem.splitScalar(u8, contents, '\n');
    while (line_it.next()) |raw_line| : (line_index += 1) {
        const last_line = line_it.index == line_it.buffer.len;
        const line = std.mem.trimEnd(u8, raw_line, "\r");

        const old_len = aw.written().len;
        expandVariablesAutoconfAt(w, line, conf, value_pairs, value_map) catch |err| switch (err) {
            error.MissingValue => {
                const name = aw.written()[old_len..];
                defer aw.shrinkRetainingCapacity(old_len);
                try step.addError(maker, "{f}:{d}: error: unspecified config header value: {s}", .{
                    src_path, line_index + 1, name,
                });
                any_errors = true;
                continue;
            },
            else => {
                try step.addError(maker, "{f}:{d}: unable to substitute variable: error: {t}", .{
                    src_path, line_index + 1, err,
                });
                any_errors = true;
                continue;
            },
        };
        if (!last_line) try w.writeAll(newline);
    }

    try ensureAllValuesUsed(maker, step, value_map, src_path);
    if (any_errors) return error.MakeFailed;
}