fprintf takes a FILE pointer too
[unix-history] / usr / src / usr.bin / gprof / lookup.c
CommitLineData
c0bc4ef7
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
ddb85eed
KB
3 * All rights reserved.
4 *
6ecf3d85 5 * %sccs.include.redist.c%
c0bc4ef7
DF
6 */
7
6b32aa07 8#ifndef lint
3d5e7f25 9static char sccsid[] = "@(#)lookup.c 5.5 (Berkeley) %G%";
ddb85eed 10#endif /* not lint */
6b32aa07 11
31f0a970 12#include "gprof.h"
6b32aa07
PK
13
14 /*
15 * look up an address in a sorted-by-address namelist
16 * this deals with misses by mapping them to the next lower
17 * entry point.
18 */
19nltype *
20nllookup( address )
21 unsigned long address;
22{
23 register long low;
24 register long middle;
25 register long high;
26# ifdef DEBUG
27 register int probes;
28
29 probes = 0;
30# endif DEBUG
31 for ( low = 0 , high = nname - 1 ; low != high ; ) {
32# ifdef DEBUG
33 probes += 1;
34# endif DEBUG
35 middle = ( high + low ) >> 1;
36 if ( nl[ middle ].value <= address && nl[ middle+1 ].value > address ) {
37# ifdef DEBUG
29da1d26 38 if ( debug & LOOKUPDEBUG ) {
6b32aa07
PK
39 printf( "[nllookup] %d (%d) probes\n" , probes , nname-1 );
40 }
41# endif DEBUG
42 return &nl[ middle ];
43 }
44 if ( nl[ middle ].value > address ) {
45 high = middle;
46 } else {
47 low = middle + 1;
48 }
49 }
50 fprintf( stderr , "[nllookup] binary search fails???\n" );
51 return 0;
52}
53
54arctype *
55arclookup( parentp , childp )
56 nltype *parentp;
57 nltype *childp;
58{
59 arctype *arcp;
60
61 if ( parentp == 0 || childp == 0 ) {
3d5e7f25 62 fprintf( stderr, "[arclookup] parentp == 0 || childp == 0\n" );
6b32aa07
PK
63 return 0;
64 }
65# ifdef DEBUG
29da1d26 66 if ( debug & LOOKUPDEBUG ) {
6b32aa07
PK
67 printf( "[arclookup] parent %s child %s\n" ,
68 parentp -> name , childp -> name );
69 }
70# endif DEBUG
71 for ( arcp = parentp -> children ; arcp ; arcp = arcp -> arc_childlist ) {
72# ifdef DEBUG
29da1d26 73 if ( debug & LOOKUPDEBUG ) {
6b32aa07
PK
74 printf( "[arclookup]\t arc_parent %s arc_child %s\n" ,
75 arcp -> arc_parentp -> name ,
76 arcp -> arc_childp -> name );
77 }
78# endif DEBUG
79 if ( arcp -> arc_childp == childp ) {
80 return arcp;
81 }
82 }
83 return 0;
84}