| ... | @@ -80,7 +80,7 @@ const Action = struct { | ... | @@ -80,7 +80,7 @@ const Action = struct { |
| 80 | const hay = mem.trim(u8, haystack, " "); | 80 | const hay = mem.trim(u8, haystack, " "); |
| 81 | const phrase = mem.trim(u8, act.phrase.resolve(b, step), " "); | 81 | const phrase = mem.trim(u8, act.phrase.resolve(b, step), " "); |
| 82 | | 82 | |
| 83 | var candidate_var: ?struct { name: []const u8, value: u64 } = null; | 83 | var candidate_vars = std.ArrayList(struct { name: []const u8, value: u64 }).init(b.allocator); |
| 84 | var hay_it = mem.tokenizeScalar(u8, hay, ' '); | 84 | var hay_it = mem.tokenizeScalar(u8, hay, ' '); |
| 85 | var needle_it = mem.tokenizeScalar(u8, phrase, ' '); | 85 | var needle_it = mem.tokenizeScalar(u8, phrase, ' '); |
| 86 | | 86 | |
| ... | @@ -92,18 +92,21 @@ const Action = struct { | ... | @@ -92,18 +92,21 @@ const Action = struct { |
| 92 | | 92 | |
| 93 | const name = needle_tok[1..closing_brace]; | 93 | const name = needle_tok[1..closing_brace]; |
| 94 | if (name.len == 0) return error.MissingBraceValue; | 94 | if (name.len == 0) return error.MissingBraceValue; |
| 95 | const value = try std.fmt.parseInt(u64, hay_tok, 16); | 95 | const value = std.fmt.parseInt(u64, hay_tok, 16) catch return false; |
| 96 | candidate_var = .{ | 96 | try candidate_vars.append(.{ |
| 97 | .name = name, | 97 | .name = name, |
| 98 | .value = value, | 98 | .value = value, |
| 99 | }; | 99 | }); |
| 100 | } else { | 100 | } else { |
| 101 | if (!mem.eql(u8, hay_tok, needle_tok)) return false; | 101 | if (!mem.eql(u8, hay_tok, needle_tok)) return false; |
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | | 104 | |
| 105 | if (candidate_var) |v| try global_vars.putNoClobber(v.name, v.value); | 105 | if (candidate_vars.items.len == 0) return false; |
| 106 | return candidate_var != null; | 106 | |
| | 107 | for (candidate_vars.items) |cv| try global_vars.putNoClobber(cv.name, cv.value); |
| | 108 | |
| | 109 | return true; |
| 107 | } | 110 | } |
| 108 | | 111 | |
| 109 | /// Returns true if the `phrase` is an exact match with the haystack. | 112 | /// Returns true if the `phrase` is an exact match with the haystack. |
| ... | @@ -1253,7 +1256,7 @@ const ElfDumper = struct { | ... | @@ -1253,7 +1256,7 @@ const ElfDumper = struct { |
| 1253 | } else if (sym.st_shndx == elf.SHN_UNDEF) { | 1256 | } else if (sym.st_shndx == elf.SHN_UNDEF) { |
| 1254 | try writer.writeAll(" UND"); | 1257 | try writer.writeAll(" UND"); |
| 1255 | } else { | 1258 | } else { |
| 1256 | try writer.print(" {d}", .{sym.st_shndx}); | 1259 | try writer.print(" {x}", .{sym.st_shndx}); |
| 1257 | } | 1260 | } |
| 1258 | } | 1261 | } |
| 1259 | | 1262 | |