DoxigAlpha

render_autoconf_undef

Function parameters

Parameters

#
step:*Step
contents:[]const u8
bw:*Writer
values:std.StringArrayHashMap(Value)
src_path:[]const u8

Type definitions in this namespace

Types

#

Functions in this namespace

Functions

#
getOutput
Deprecated; use `getOutputFile`.

= .config_header

Values

#
base_id
= .config_header

Source

Implementation

#
fn render_autoconf_undef(
    step: *Step,
    contents: []const u8,
    bw: *Writer,
    values: std.StringArrayHashMap(Value),
    src_path: []const u8,
) !void {
    const build = step.owner;
    const allocator = build.allocator;

    var is_used: std.DynamicBitSetUnmanaged = try .initEmpty(allocator, values.count());
    defer is_used.deinit(allocator);

    var any_errors = false;
    var line_index: u32 = 0;
    var line_it = std.mem.splitScalar(u8, contents, '\n');
    while (line_it.next()) |line| : (line_index += 1) {
        if (!std.mem.startsWith(u8, line, "#")) {
            try bw.writeAll(line);
            try bw.writeByte('\n');
            continue;
        }
        var it = std.mem.tokenizeAny(u8, line[1..], " \t\r");
        const undef = it.next().?;
        if (!std.mem.eql(u8, undef, "undef")) {
            try bw.writeAll(line);
            try bw.writeByte('\n');
            continue;
        }
        const name = it.next().?;
        const index = values.getIndex(name) orelse {
            try step.addError("{s}:{d}: error: unspecified config header value: '{s}'", .{
                src_path, line_index + 1, name,
            });
            any_errors = true;
            continue;
        };
        is_used.set(index);
        try renderValueC(bw, name, values.values()[index]);
    }

    var unused_value_it = is_used.iterator(.{ .kind = .unset });
    while (unused_value_it.next()) |index| {
        try step.addError("{s}: error: config header value unused: '{s}'", .{ src_path, values.keys()[index] });
        any_errors = true;
    }

    if (any_errors) {
        return error.MakeFailed;
    }
}