1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)srcline.c	5.1 (Berkeley) 6/6/85";
   9: #endif not lint
  10: /*
  11:  * lookup the source line number nearest from below to an address
  12:  */
  13: 
  14: #include "defs.h"
  15: #include "mappings.h"
  16: #include "object.h"
  17: #include "linetab.h"
  18: 
  19: LINENO srcline(addr)
  20: ADDRESS addr;
  21: {
  22:     register ADDRESS i, j, k;
  23:     ADDRESS a;
  24: 
  25:     if (nlhdr.nlines == 0) {
  26:         return(0);
  27:     }
  28:     i = 0;
  29:     j = nlhdr.nlines - 1;
  30:     if (addr <= linetab[i].addr) {
  31:         return(linetab[i].line);
  32:     } else if (addr >= linetab[j].addr) {
  33:         return(linetab[j].line);
  34:     }
  35:     while (i <= j) {
  36:         k = (i + j) / 2;
  37:         if ((a = linetab[k].addr) == addr) {
  38:             return(linetab[k].line);
  39:         } else if (addr > a) {
  40:             i = k+1;
  41:         } else {
  42:             j = k-1;
  43:         }
  44:     }
  45:     if (addr > linetab[i].addr) {
  46:         return(linetab[i].line);
  47:     } else {
  48:         return(linetab[i-1].line);
  49:     }
  50:     /*NOTREACHED*/
  51: }
  52: 
  53: /*
  54:  * look for a line exactly corresponding to the given address
  55:  */
  56: 
  57: LINENO linelookup(addr)
  58: ADDRESS addr;
  59: {
  60:     register ADDRESS i, j, k;
  61:     ADDRESS a;
  62: 
  63:     if (nlhdr.nlines == 0 || addr < linetab[0].addr) {
  64:         return(0);
  65:     }
  66:     i = 0;
  67:     j = nlhdr.nlines - 1;
  68:     while (i <= j) {
  69:         k = (i + j) / 2;
  70:         if ((a = linetab[k].addr) == addr) {
  71:             return(linetab[k].line);
  72:         } else if (addr > a) {
  73:             i = k+1;
  74:         } else {
  75:             j = k-1;
  76:         }
  77:     }
  78:     return(0);
  79: }

Defined functions

linelookup defined in line 57; never used
srcline defined in line 19; never used

Defined variables

sccsid defined in line 8; never used
Last modified: 1985-06-06
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1542
Valid CSS Valid XHTML 1.0 Strict