| ... | @@ -188,34 +188,7 @@ fn render_autoconf( | ... | @@ -188,34 +188,7 @@ fn render_autoconf( |
| 188 | any_errors = true; | 188 | any_errors = true; |
| 189 | continue; | 189 | continue; |
| 190 | }; | 190 | }; |
| 191 | switch (kv.value) { | 191 | try renderValue(output, name, kv.value); |
| 192 | .undef => { | | |
| 193 | try output.appendSlice("/* #undef "); | | |
| 194 | try output.appendSlice(name); | | |
| 195 | try output.appendSlice(" */\n"); | | |
| 196 | }, | | |
| 197 | .defined => { | | |
| 198 | try output.appendSlice("#define "); | | |
| 199 | try output.appendSlice(name); | | |
| 200 | try output.appendSlice("\n"); | | |
| 201 | }, | | |
| 202 | .boolean => |b| { | | |
| 203 | try output.appendSlice("#define "); | | |
| 204 | try output.appendSlice(name); | | |
| 205 | try output.appendSlice(" "); | | |
| 206 | try output.appendSlice(if (b) "true\n" else "false\n"); | | |
| 207 | }, | | |
| 208 | .int => |i| { | | |
| 209 | try output.writer().print("#define {s} {d}\n", .{ name, i }); | | |
| 210 | }, | | |
| 211 | .ident => |ident| { | | |
| 212 | try output.writer().print("#define {s} {s}\n", .{ name, ident }); | | |
| 213 | }, | | |
| 214 | .string => |string| { | | |
| 215 | // TODO: use C-specific escaping instead of zig string literals | | |
| 216 | try output.writer().print("#define {s} \"{}\"\n", .{ name, std.zig.fmtEscapes(string) }); | | |
| 217 | }, | | |
| 218 | } | | |
| 219 | } | 192 | } |
| 220 | | 193 | |
| 221 | { | 194 | { |
| ... | @@ -237,9 +210,79 @@ fn render_cmake( | ... | @@ -237,9 +210,79 @@ fn render_cmake( |
| 237 | values_copy: *std.StringHashMap(Value), | 210 | values_copy: *std.StringHashMap(Value), |
| 238 | src_path: []const u8, | 211 | src_path: []const u8, |
| 239 | ) !void { | 212 | ) !void { |
| 240 | _ = contents; | 213 | var any_errors = false; |
| 241 | _ = output; | 214 | var line_index: u32 = 0; |
| 242 | _ = values_copy; | 215 | var line_it = std.mem.split(u8, contents, "\n"); |
| 243 | _ = src_path; | 216 | while (line_it.next()) |line| : (line_index += 1) { |
| 244 | @panic("TODO: render_cmake is not implemented yet"); | 217 | if (!std.mem.startsWith(u8, line, "#")) { |
| | 218 | try output.appendSlice(line); |
| | 219 | try output.appendSlice("\n"); |
| | 220 | continue; |
| | 221 | } |
| | 222 | var it = std.mem.tokenize(u8, line[1..], " \t\r"); |
| | 223 | const cmakedefine = it.next().?; |
| | 224 | if (!std.mem.eql(u8, cmakedefine, "cmakedefine")) { |
| | 225 | try output.appendSlice(line); |
| | 226 | try output.appendSlice("\n"); |
| | 227 | continue; |
| | 228 | } |
| | 229 | const name = it.next() orelse { |
| | 230 | std.debug.print("{s}:{d}: error: missing define name\n", .{ |
| | 231 | src_path, line_index + 1, |
| | 232 | }); |
| | 233 | any_errors = true; |
| | 234 | continue; |
| | 235 | }; |
| | 236 | const kv = values_copy.fetchRemove(name) orelse { |
| | 237 | std.debug.print("{s}:{d}: error: unspecified config header value: '{s}'\n", .{ |
| | 238 | src_path, line_index + 1, name, |
| | 239 | }); |
| | 240 | any_errors = true; |
| | 241 | continue; |
| | 242 | }; |
| | 243 | try renderValue(output, name, kv.value); |
| | 244 | } |
| | 245 | |
| | 246 | { |
| | 247 | var it = values_copy.iterator(); |
| | 248 | while (it.next()) |entry| { |
| | 249 | const name = entry.key_ptr.*; |
| | 250 | std.debug.print("{s}: error: config header value unused: '{s}'\n", .{ src_path, name }); |
| | 251 | } |
| | 252 | } |
| | 253 | |
| | 254 | if (any_errors) { |
| | 255 | return error.HeaderConfigFailed; |
| | 256 | } |
| | 257 | } |
| | 258 | |
| | 259 | fn renderValue(output: *std.ArrayList(u8), name: []const u8, value: Value) !void { |
| | 260 | switch (value) { |
| | 261 | .undef => { |
| | 262 | try output.appendSlice("/* #undef "); |
| | 263 | try output.appendSlice(name); |
| | 264 | try output.appendSlice(" */\n"); |
| | 265 | }, |
| | 266 | .defined => { |
| | 267 | try output.appendSlice("#define "); |
| | 268 | try output.appendSlice(name); |
| | 269 | try output.appendSlice("\n"); |
| | 270 | }, |
| | 271 | .boolean => |b| { |
| | 272 | try output.appendSlice("#define "); |
| | 273 | try output.appendSlice(name); |
| | 274 | try output.appendSlice(" "); |
| | 275 | try output.appendSlice(if (b) "true\n" else "false\n"); |
| | 276 | }, |
| | 277 | .int => |i| { |
| | 278 | try output.writer().print("#define {s} {d}\n", .{ name, i }); |
| | 279 | }, |
| | 280 | .ident => |ident| { |
| | 281 | try output.writer().print("#define {s} {s}\n", .{ name, ident }); |
| | 282 | }, |
| | 283 | .string => |string| { |
| | 284 | // TODO: use C-specific escaping instead of zig string literals |
| | 285 | try output.writer().print("#define {s} \"{}\"\n", .{ name, std.zig.fmtEscapes(string) }); |
| | 286 | }, |
| | 287 | } |
| 245 | } | 288 | } |