#!/usr/bin/perl 'di'; 'ig00'; # # ptags: create a tags file for perl scripts # @id = split( ' ', '$Id: ptags,v 1.11 1994/03/22 18:34:33 ln_smr Exp $' ); $id[1] =~ s/,v//; # obvious... :-) sub usage { print <<_EOUSAGE_ ; USAGE: $program [-mvwV] [-t ] -m Merge with existing tags file. -t Name of tags file to create. (default is 'tags') -v Include variable definitions. (variables mentioned at the start of a line) -V Print version information. -w Suppress "duplicate tag" warnings. List of files to scan for tags. _EOUSAGE_ exit 0 } # # initialisations # ($program = $0) =~ s,.*/,,; require 'getopts.pl'; # # parse command line # &Getopts( "mt:vVw" ) || &usage(); $tags_file = $opt_t || 'tags'; $merge = $opt_m; $variable_tags = $opt_v; $allow_warnings = ! $opt_w; die "$id[1]: ($id[5]) Version: $id[2] $id[3] $id[4]\n" if $opt_V; if( $merge && open( TAGS, "< $tags_file" ) ) { while( ) { /^\S+/; $tags{$&} = $_; } close( TAGS ); } # # for each line of every file listed on the command line, look for a # 'sub' definition, or, if variables are wanted aswell, look for a # variable definition at the start of a line # while( <> ) { next unless /^\s*sub\s+(\w+('|::))?(\w+)/ || ( $variable_tags && /^(([(\s]*[\$\@\%]{1}(\w+).*=))/ ); chop; warn "$3 - duplicate ignored\n" if ( $new{$3}++ || !( $tags{$3} = sprintf( "%s\t%s\t?^%s\$?\n", $3, $ARGV, $_ ) ) ) && $allow_warnings; } rename( "$tags_file", "$tags_file.bak" ); open( TAGS, "> $tags_file" ); foreach( sort( keys %tags ) ) { print TAGS "$tags{$_}"; } close( TAGS ); ############################################################ # The next few lines are legal in both Perl and Nroff! .00; 'di \" Finish diversion-previous line must be blank .nr nl 0-1 \" fake up transition to first page again .nr % 0 \" start at page 1 '; __END__ ##### From here on it's a standard manual page ##### .TH ptags 1 "NMS Utilities" .SH NAME ptags \- Create a tags file for Perl scripts. .SH SYNOPSIS .B ptags [\fI-mvw\fP] [\fI-t \fP] .SH DESCRIPTION .IP \fB-m\fP Merge new tags with existing tags. Old tags that match new tags will be quietly overwritten, while new duplicated tags will generate warning messages. .IP "\fB-t \fP" Name of tags file to create. (default is 'tags') .IP \fB-v\fP Include variable definitions (variables mentioned at the start of a line) .IP \fB-V\fP Print version information. .IP \fB-w\fP Suppress "duplicate tag" warning messages. .PP \fBPtags\fP scans the specified files for subroutines and possibly variable definitions, and creates a \fBvi\fP style tags file. .SH FILES .IP \fBtags\fP Tags file containing a sorted list of tags, one tag per line. The format is the same as that used by \fBvi\fP(1) .SH AUTHOR Stephen Riehm .br steve@dingbat.franken.de .SH VERSION $Id: ptags,v 1.11 1994/03/22 18:34:33 ln_smr Exp $ .SH "SEE ALSO" perl(1), ctags(1).