15494Slinton /* Copyright (c) 1982 Regents of the University of California */ 25494Slinton 3*5884Slinton static char sccsid[] = "@(#)objaddr.c 1.2 02/17/82"; 45494Slinton 55494Slinton /* 6*5884Slinton * Lookup the object address of a given line from the named file. 7*5884Slinton * 8*5884Slinton * Potentially all files in the file table need to be checked 9*5884Slinton * until the line is found since a particular file name may appear 10*5884Slinton * more than once in the file table (caused by includes). 115494Slinton */ 125494Slinton 135494Slinton #include "defs.h" 145494Slinton #include "mappings.h" 155494Slinton #include "object.h" 165494Slinton #include "source.h" 175494Slinton #include "filetab.h" 185494Slinton #include "linetab.h" 195494Slinton 205494Slinton ADDRESS objaddr(line, name) 215494Slinton LINENO line; 225494Slinton char *name; 235494Slinton { 24*5884Slinton register FILETAB *ftp; 25*5884Slinton register LINENO i, j; 26*5884Slinton BOOLEAN foundfile; 275494Slinton 28*5884Slinton if (nlhdr.nlines == 0) { 29*5884Slinton return(-1); 30*5884Slinton } 31*5884Slinton if (name == NULL) { 32*5884Slinton name = cursource; 33*5884Slinton } 34*5884Slinton foundfile = FALSE; 35*5884Slinton for (ftp = &filetab[0]; ftp < &filetab[nlhdr.nfiles]; ftp++) { 36*5884Slinton if (streq(ftp->filename, name)) { 37*5884Slinton foundfile = TRUE; 38*5884Slinton i = ftp->lineindex; 39*5884Slinton if (ftp == &filetab[nlhdr.nfiles-1]) { 405494Slinton j = nlhdr.nlines; 41*5884Slinton } else { 425494Slinton j = (ftp + 1)->lineindex; 43*5884Slinton } 44*5884Slinton while (i < j) { 455494Slinton if (linetab[i].line == line) { 46*5884Slinton return linetab[i].addr; 475494Slinton } 485494Slinton i++; 49*5884Slinton } 505494Slinton } 51*5884Slinton } 52*5884Slinton if (!foundfile) { 53*5884Slinton error("unknown source file \"%s\"", name); 54*5884Slinton } 55*5884Slinton return(-1); 565494Slinton } 57