$main['repname'] = "phLXR"
$main['path'] = "/"
$main['file'] = "/ident"

$HTTP_SERVER_VARS['PATH_INFO']: /phLXR/ident

1	<?
2	
3	/*
4	 *
5	 *   Copyright (c) 2001, W.A.D, Roman Neuhauser
6	 *   All rights reserved.
7	 *   
8	 *   Redistribution and use in source and binary forms, with or without 
9	 *   modification, are permitted provided that the following conditions 
10	 *   are met:
11	 *   
12	 *   * Redistributions of source code must retain the above copyright notice, 
13	 *     this list of conditions and the following disclaimer. 
14	 *   * Redistributions in binary form must reproduce the above copyright 
15	 *     notice, this list of conditions and the following disclaimer in the 
16	 *     documentation and/or other materials provided with the distribution. 
17	 *   * Neither the name of the W.A.D nor the names of its contributors may be 
18	 *     used to endorse or promote products derived from this software without 
19	 *     specific prior written permission. 
20	 *   
21	 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
22	 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
23	 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
24	 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 
25	 *   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
26	 *   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
27	 *   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
28	 *   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
29	 *   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
30	 *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
31	 *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32	 *
33	 *
34	 *   $Id: ident,v 1.5 2001/04/16 21:15:34 cynicz Exp $
35	 *
36	 */
37	
38	
39	error_reporting( E_ALL ) ;
40	
41	require( './include/config.inc' ) ;
42	require( './include/functions.inc' ) ;
43	require( './include/class.layout.inc' ) ;
44	
45	require( './include/class.logger.inc' ) ;
46	$log = new Clogger( './log/ident.log' , 'w' ) ;
47	
48	newhtml( $page ) ;
49	
50	$db = db_connect() ;
51	
52	if( ! isset( $HTTP_SERVER_VARS['PATH_INFO'] ) || '/' == $HTTP_SERVER_VARS['PATH_INFO'] ) {
53	    header( $_path ) ;
54	    exit ;
55	} 
56	
57	$path = $HTTP_SERVER_VARS['PATH_INFO'] ;
58	if( $secondslash = strnpos( $path , '/' , 2 ) ) {
59	    $repname = substr( $path , 1 , $secondslash-1 ) ;
60	    $idname = substr( $path , $secondslash+1 ) ;
61	    if( '/' == $idname ) {
62	        header( "Location: $_path" ) ;
63	        exit ;
64	    }
65	} else {
66	    header( "Location: $_path" ) ;
67	    exit ;
68	}
69	
70	$q = 'select
71	            id.idtype ,
72	            file.file ,
73	            id.linenr
74	        from
75	            identifier id ,
76	            file ,
77	            repository rep
78	        where
79	            id.idname = "' . $idname . '"
80	          and
81	            id.fileid = file.fileid
82	          and
83	            file.repid = rep.repid
84	          and
85	            rep.repname="' . $repname . '"' ;
86	
87	$rs = mysql_query( $q ) ;
88	
89	while( $def = mysql_fetch_assoc( $rs ) ) {
90	    $defs[] = $def ;
91	}
92	
93	$rs = mysql_query( 'select
94	                        id.idname ,
95	                        file.file ,
96	                        loc.linenr
97	                    from
98	                        identifier id ,
99	                        file ,
100	                        location loc ,
101	                        repository rep
102	                    where
103	                        id.idname = "' . $idname . '"
104	                      and
105	                        id.idid = loc.idid
106	                      and
107	                        loc.fileid = file.fileid
108	                      and
109	                        file.repid = rep.repid
110	                      and 
111	                        loc.linenr <> id.linenr
112	                      and
113	                        rep.repname="' . $repname . '"
114	                    order by file.file, loc.linenr' ) ;
115	
116	
117	while( $loc = mysql_fetch_assoc( $rs ) ) {
118	    $locs[] = $loc ;
119	}
120	
121	/*
122	foreach( $defs as $def ) {
123	    array_walk( $locs , 'remove_defs' , $def ) ;
124	}
125	
126	function remove_defs( &$loc , $k , $def )
127	{
128	    if( $loc['file'] == $def['file'] && $loc['linenr'] == $def['linenr'] ) {
129	        unset( $GLOBALS['locs'][$k] ) ;
130	    }
131	}
132	*/
133	
134	insert( $page , heading( 1 , $idname ) ) ;
135	foreach( $defs as $def ) {
136	    insert( $page , block( 'Defined as <tt>' . get_identifier_type( $def['idtype'] ) . '</tt> in file ' ) ) ;
137	    insert( $page , anchor( realuri( "source/$repname{$def['file']}#{$def['linenr']}" ) , 
138	                            "<tt>{$def['file']}, line {$def['linenr']}</tt>" ) ) ;
139	    insert( $page , generic( 'br' ) ) ;
140	}
141	
142	insert( $page , block( 'Referenced (in ' . unique_files( $locs ) . ' files total) in:<br>' ) ) ;
143	foreach( $locs as $loc ) {
144	#    if( ! in_array( $loc , $defs ) ) {
145	        insert( $page , anchor( realuri( "source/$repname{$loc['file']}#{$loc['linenr']}" ) , 
146	                            "<tt>{$loc['file']}, line {$loc['linenr']}</tt>" ) ) ;
147	        insert( $page , generic( 'br' ) ) ;
148	#    }
149	#         insert( $page , block( "<tt><a href='/phlxr/source/$repname{$loc['file']}#{$loc['linenr']}'>{$loc['file']}</a></tt> "
150	#         . "on line <tt><a href='/phlxr/source/$repname{$loc['file']}#{$loc['linenr']}'>{$loc['linenr']}</a></tt><br>\n" ) ) ;
151	}
152	
153	printhtml( $page ) ;
154	
155	?>