feature. See also
. The project being documented here (as the example) is the Zig library itself.
ConfigHeader.renderAutoConfUndef
fn renderAutoConfUndef(
maker: *Maker,
step: *Step,
contents: []const u8,
w: *Writer,
value_pairs: []const Value.Pair,
value_map: *ValueMap,
src_path: Path,
) !void
File
Code
fn renderAutoConfUndef(
maker: *Maker,
step: *Step,
contents: []const u8,
w: *Writer,
value_pairs: []const Value.Pair,
value_map: *ValueMap,
src_path: Path,
) !void {
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");
if (!std.mem.startsWith(u8, line, "#")) {
try w.writeAll(line);
if (!last_line) try w.writeAll(newline);
continue;
}
var it = std.mem.tokenizeAny(u8, line[1..], " \t\r");
const undef = it.next().?;
if (!std.mem.eql(u8, undef, "undef")) {
try w.writeAll(line);
if (!last_line) try w.writeAll(newline);
continue;
}
const name = it.next().?;
const index = value_map.getIndex(name) orelse {
try step.addError(maker, "{f}:{d}: unspecified config header value: {s}", .{
src_path, line_index + 1, name,
});
any_errors = true;
continue;
};
value_map.values()[index] = true;
try renderValueC(conf, w, newline, name, value_pairs[index].index);
}
try ensureAllValuesUsed(maker, step, value_map, src_path);
if (any_errors) return error.MakeFailed;
}