feature. See also
. The project being documented here (as the example) is the Zig library itself.
source_mapping.handleLineCommand
pub fn handleLineCommand(allocator: Allocator, line_command: []const u8, current_mapping: *CurrentMapping) error
File
Code
pub fn handleLineCommand(allocator: Allocator, line_command: []const u8, current_mapping: *CurrentMapping) error{ OutOfMemory, InvalidLineCommand }!void {
var tokenizer = std.mem.tokenizeAny(u8, line_command, " \t");
const line_directive = tokenizer.next() orelse return error.InvalidLineCommand;
if (!std.mem.eql(u8, line_directive, "#line")) return error.InvalidLineCommand;
const linenum_str = tokenizer.next() orelse return error.InvalidLineCommand;
const linenum = std.fmt.parseUnsigned(usize, linenum_str, 10) catch return error.InvalidLineCommand;
if (linenum == 0) return error.InvalidLineCommand;
var filename_literal = tokenizer.rest();
while (filename_literal.len > 0 and std.ascii.isWhitespace(filename_literal[filename_literal.len - 1])) {
filename_literal.len -= 1;
}
if (filename_literal.len < 2) return error.InvalidLineCommand;
const is_quoted = filename_literal[0] == '"' and filename_literal[filename_literal.len - 1] == '"';
if (!is_quoted) return error.InvalidLineCommand;
const unquoted_filename = filename_literal[1 .. filename_literal.len - 1];
if (std.mem.eql(u8, unquoted_filename, "<builtin>") or std.mem.eql(u8, unquoted_filename, "<command line>")) return;
const filename = parseFilename(allocator, unquoted_filename) catch |err| switch (err) {
error.OutOfMemory => |e| return e,
else => return error.InvalidLineCommand,
};
defer allocator.free(filename);
if (std.mem.indexOfScalar(u8, filename, '\x00') != null) return error.InvalidLineCommand;
current_mapping.line_num = linenum;
current_mapping.filename.clearRetainingCapacity();
try current_mapping.filename.appendSlice(allocator, filename);
current_mapping.pending = true;
current_mapping.ignore_contents = std.ascii.endsWithIgnoreCase(filename, ".c") or std.ascii.endsWithIgnoreCase(filename, ".h");
}