1 /* Copyright (c) 1982 Regents of the University of California */
2 
3 static char sccsid[] = "@(#)objaddr.c 1.1 01/18/82";
4 
5 /*
6  * lookup the object address of a given line from the given file
7  */
8 
9 #include "defs.h"
10 #include "mappings.h"
11 #include "object.h"
12 #include "source.h"
13 #include "filetab.h"
14 #include "linetab.h"
15 
16 ADDRESS objaddr(line, name)
17 LINENO line;
18 char *name;
19 {
20 	register FILETAB *ftp;
21 	register LINENO i, j;
22 
23 	if (nlhdr.nlines == 0) {
24 		return(-1);
25 	}
26 	if (name == NULL) {
27 		name = cursource;
28 	}
29 	for (ftp = &filetab[0]; ftp < &filetab[nlhdr.nfiles]; ftp++) {
30 		if (strcmp(ftp->filename, name) == 0) {
31 			break;
32 		}
33 	}
34 	if (ftp == &filetab[nlhdr.nfiles]) {
35 		error("unknown source file \"%s\"", name);
36 	}
37 	i = ftp->lineindex;
38 	if (ftp == &filetab[nlhdr.nfiles-1]) {
39 		j = nlhdr.nlines;
40 	} else {
41 		j = (ftp + 1)->lineindex;
42 	}
43 	while (i < j) {
44 		if (linetab[i].line == line) {
45 			return(linetab[i].addr);
46 		}
47 		i++;
48 	}
49 	return(-1);
50 }
51