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