1 /* Copyright (c) 1982 Regents of the University of California */
2 
3 static char sccsid[] = "@(#)srcfile.c 1.1 01/18/82";
4 
5 /*
6  * get the source file name associated with a given address
7  */
8 
9 #include "defs.h"
10 #include "mappings.h"
11 #include "object.h"
12 #include "filetab.h"
13 
14 char *srcfilename(addr)
15 ADDRESS addr;
16 {
17 	register ADDRESS i, j, k;
18 	ADDRESS a;
19 	FILETAB *ftp;
20 
21 	if (addr < filetab[0].addr) {
22 		return(NIL);
23 	}
24 	i = 0;
25 	j = nlhdr.nfiles - 1;
26 	while (i < j) {
27 		k = (i + j) / 2;
28 		ftp = &filetab[k];
29 		if ((a = ftp->addr) == addr) {
30 			return(ftp->filename);
31 		} else if (addr > a) {
32 			i = k + 1;
33 		} else {
34 			j = k - 1;
35 		}
36 	}
37 	if (addr >= filetab[i].addr) {
38 		return(filetab[i].filename);
39 	} else {
40 		return(filetab[i-1].filename);
41 	}
42 	/*NOTREACHED*/
43 }
44