#!/usr/local/bin/php -q $v ) { // its an options if( $v[0] == "-" ) { $option = substr($v,1); if( $option == 'R' ) $option = 'recurse'; if( $option != "" ) $opts[$option] = 1; $opts[$option] = 1; } if( is_file($v) ) { indexfile($v); } if( is_dir($v) && $opts['recurse'] ) { indexDir($v); } } if( count($buffer) ) { sort($buffer); $fp = fopen( tagfilename, "w" ) or die( "error while opening tag file ". tagfilename ); foreach($buffer as $l ) { fputs( $fp, "$l\n" ); } fclose( $fp ); } function indexDir( $dir ) { global $opts; $fd = opendir( $dir ); while( $file = readdir( $fd ) ) { if( $file == "." or $file == ".." ) continue; if( is_file( "$dir/$file" ) ) indexfile( "$dir/$file" ); if( is_dir("$dir/$file") and $opts['recurse'] ) indexDir( "$dir/$file" ); } closedir( $fd ); } function indexfile( $file ) { global $buffer, $fmtTagLine, $fmtDefTagLine, $tagfilename, $opts, $allowed_extensions; if( $opts['verbose'] ) { echo "$file\n"; } $atmp = explode( ".", $file ); $extension = $atmp[count($atmp)-1]; if( ! in_array( $extension, $allowed_extensions ) ) return; $lines = file( $file ); for( $i=0; $i< count($lines); $i++ ) { $l = chop($lines[$i]); if( preg_match( "/function\s+([[:alnum:]_]+)\s*\(/", $l, $a ) ) { $tagline = sprintf( $fmtTagLine, $a[1], $file, $l ); $buffer[] = $tagline; }elseif( preg_match( "/define\s*\(\s*[\"']?([[:alnum:]_]+)[\"']?/", $l, $a ) ) { $tagline = sprintf( $fmtDefTagLine, $a[1], $file, $i+1 ); $buffer[] = $tagline; } } return true; } ?>