make remap-log handle all instances in the line
diff --git a/remap-log.c b/remap-log.c
index cc120fa..4d65a35 100644
--- a/remap-log.c
+++ b/remap-log.c
@@ -245,42 +245,47 @@
void mapline(void)
{
- struct file_map *map;
- struct range_map *range;
- unsigned long l;
- char *s1, *s2;
- char *name;
+ char *s = line, *end = line - 1, *sp = line - 1;
- s1 = strchr(line, ':');
- if (!s1)
- goto noise;
- s2 = strchr(line, ' ');
- if (s2 && s2 < s1)
- goto noise;
- l = strtoul(s1 + 1, &s2, 10);
- if (s2 == s1 + 1 || *s2 != ':' || !l || l > INT_MAX)
- goto noise;
- *s1++ = *s2++ = '\0';
- name = line;
- map = find_map(name);
- if (!map)
- goto new;
- if (!map->new_name)
- goto old;
- name = map->new_name;
- range = find_range(map, l);
- if (!range->to)
- goto old;
- l += range->to - range->from;
-new:
- printf("%s:%lu:%s\n", name, l, s2);
- return;
-old:
- s1[-1] = s2[-1] = ':';
- printf("%s%s\n", old_prefix, line);
- return;
-noise:
- printf("%s\n", line);
+ while (1) {
+ struct file_map *map;
+ struct range_map *range;
+ unsigned long l;
+ char *more;
+
+ end = strchr(end + 1, ':');
+ if (!end)
+ break;
+
+ if (sp < s)
+ sp = strchr(s, ' ');
+
+ while (sp && sp < end) {
+ fwrite(s, sp - s + 1, 1, stdout);
+ s = sp + 1;
+ sp = strchr(s , ' ');
+ }
+
+ l = strtoul(end + 1, &more, 10);
+ if (more == end + 1 || !l || l > INT_MAX)
+ continue;
+
+ *end = '\0';
+ map = find_map(s);
+ *end = ':';
+
+ if (!map)
+ continue;
+
+ if (map->new_name && (range = find_range(map, l))->to) {
+ l += range->to - range->from;
+ printf("%s:%lu", map->new_name, l);
+ } else {
+ printf("%s%*s", old_prefix, more - s, s);
+ }
+ s = more;
+ }
+ printf("%s\n", s);
}
int parse_hunk(int *l1, int *l2, int *n1, int *n2)