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