Commit | Line | Data |
---|---|---|
f644bb55 DF |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | */ | |
67454b75 | 6 | |
f644bb55 DF |
7 | #ifndef lint |
8 | static char sccsid[] = "@(#)objaddr.c 5.1 (Berkeley) %G%"; | |
9 | #endif not lint | |
67454b75 | 10 | /* |
6b60bc4f ML |
11 | * Lookup the object address of a given line from the named file. |
12 | * | |
13 | * Potentially all files in the file table need to be checked | |
14 | * until the line is found since a particular file name may appear | |
15 | * more than once in the file table (caused by includes). | |
67454b75 ML |
16 | */ |
17 | ||
18 | #include "defs.h" | |
19 | #include "mappings.h" | |
20 | #include "object.h" | |
21 | #include "source.h" | |
22 | #include "filetab.h" | |
23 | #include "linetab.h" | |
24 | ||
25 | ADDRESS objaddr(line, name) | |
26 | LINENO line; | |
27 | char *name; | |
28 | { | |
6b60bc4f ML |
29 | register FILETAB *ftp; |
30 | register LINENO i, j; | |
31 | BOOLEAN foundfile; | |
67454b75 | 32 | |
6b60bc4f ML |
33 | if (nlhdr.nlines == 0) { |
34 | return(-1); | |
35 | } | |
36 | if (name == NULL) { | |
37 | name = cursource; | |
38 | } | |
39 | foundfile = FALSE; | |
40 | for (ftp = &filetab[0]; ftp < &filetab[nlhdr.nfiles]; ftp++) { | |
41 | if (streq(ftp->filename, name)) { | |
42 | foundfile = TRUE; | |
43 | i = ftp->lineindex; | |
44 | if (ftp == &filetab[nlhdr.nfiles-1]) { | |
67454b75 | 45 | j = nlhdr.nlines; |
6b60bc4f | 46 | } else { |
67454b75 | 47 | j = (ftp + 1)->lineindex; |
6b60bc4f ML |
48 | } |
49 | while (i < j) { | |
67454b75 | 50 | if (linetab[i].line == line) { |
6b60bc4f | 51 | return linetab[i].addr; |
67454b75 ML |
52 | } |
53 | i++; | |
6b60bc4f | 54 | } |
67454b75 | 55 | } |
6b60bc4f ML |
56 | } |
57 | if (!foundfile) { | |
58 | error("unknown source file \"%s\"", name); | |
59 | } | |
60 | return(-1); | |
67454b75 | 61 | } |