|
|
1.1 ! root 1: /* Copyright (c) 1982 Regents of the University of California */ ! 2: ! 3: static char sccsid[] = "@(#)srcline.c 1.1 1/18/82"; ! 4: ! 5: /* ! 6: * lookup the source line number nearest from below to an address ! 7: */ ! 8: ! 9: #include "defs.h" ! 10: #include "mappings.h" ! 11: #include "object.h" ! 12: #include "linetab.h" ! 13: ! 14: LINENO srcline(addr) ! 15: ADDRESS addr; ! 16: { ! 17: register ADDRESS i, j, k; ! 18: ADDRESS a; ! 19: ! 20: if (nlhdr.nlines == 0) { ! 21: return(0); ! 22: } ! 23: i = 0; ! 24: j = nlhdr.nlines - 1; ! 25: if (addr <= linetab[i].addr) { ! 26: return(linetab[i].line); ! 27: } else if (addr >= linetab[j].addr) { ! 28: return(linetab[j].line); ! 29: } ! 30: while (i <= j) { ! 31: k = (i + j) / 2; ! 32: if ((a = linetab[k].addr) == addr) { ! 33: return(linetab[k].line); ! 34: } else if (addr > a) { ! 35: i = k+1; ! 36: } else { ! 37: j = k-1; ! 38: } ! 39: } ! 40: if (addr > linetab[i].addr) { ! 41: return(linetab[i].line); ! 42: } else { ! 43: return(linetab[i-1].line); ! 44: } ! 45: /*NOTREACHED*/ ! 46: } ! 47: ! 48: /* ! 49: * look for a line exactly corresponding to the given address ! 50: */ ! 51: ! 52: LINENO linelookup(addr) ! 53: ADDRESS addr; ! 54: { ! 55: register ADDRESS i, j, k; ! 56: ADDRESS a; ! 57: ! 58: if (nlhdr.nlines == 0 || addr < linetab[0].addr) { ! 59: return(0); ! 60: } ! 61: i = 0; ! 62: j = nlhdr.nlines - 1; ! 63: while (i <= j) { ! 64: k = (i + j) / 2; ! 65: if ((a = linetab[k].addr) == addr) { ! 66: return(linetab[k].line); ! 67: } else if (addr > a) { ! 68: i = k+1; ! 69: } else { ! 70: j = k-1; ! 71: } ! 72: } ! 73: return(0); ! 74: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.