1 /* Map logical line numbers to (source file, line number) pairs.
3 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 In other words, you are welcome to use, share and improve this program.
20 You are forbidden to forbid anyone else to use, share and improve
21 what you give them. Help stamp out software-hoarding! */
27 /* Initialize a line map set. */
31 struct line_maps *set;
38 /* Free a line map set. */
40 void free_line_maps (set)
41 struct line_maps *set;
47 /* Add a mapping of logical source line to physical source file and
48 line number. Ther text pointed to by TO_FILE must have a lifetime
49 at least as long as the final call to lookup_line ().
51 FROM_LINE should be monotonic increasing across calls to this
55 add_line_map (set, reason, from_line, to_file, to_line)
56 struct line_maps *set;
57 enum lc_reason reason;
58 unsigned int from_line;
64 if (set->used && from_line < set->maps[set->used - 1].from_line)
67 if (set->used == set->allocated)
69 set->allocated = 2 * set->allocated + 256;
70 set->maps = (struct line_map *)
71 xrealloc (set->maps, set->allocated * sizeof (struct line_map));
74 map = &set->maps[set->used];
75 map->from_line = from_line;
76 map->to_file = to_file;
77 map->to_line = to_line;
80 map->included_from = -1;
81 else if (reason == LC_ENTER)
82 map->included_from = set->used - 1;
83 else if (reason == LC_RENAME)
84 map->included_from = map[-1].included_from;
85 else if (reason == LC_LEAVE)
87 if (map[-1].included_from < 0)
89 map->included_from = set->maps[map[-1].included_from].included_from;
96 /* Translate a logical line number into a (source file, line) pair. */
99 lookup_line (set, line)
100 struct line_maps *set;
103 unsigned int md, mn = 0, mx = set->used;
111 if (set->maps[md].from_line > line)
117 return &set->maps[mn];