#!/usr/local/bin/perl # $Id: mtags,v 1.3 1997/07/20 15:27:19 joi Exp $ # $Log: mtags,v $ # Revision 1.3 1997/07/20 15:27:19 joi # Added -l list parameter. # # Revision 1.2 1997/07/20 14:07:24 joi # fixed the usage. # # Revision 1.1 1997/07/19 18:58:01 joi # Initial revision # # # This script builds a tags file for mushcode files provided on the command line. # sub usage { print <fixed.tags writes tags for "*.pretty" files to STDOUT, and the grep pipe removes the Desc tags and rewrites the rest to "fixed.tags". mtags -t tags reads "tags" for filelist, writes new "tags" from filelist. Updates the tags. Useful for deleting duplicates caused by -a, too. mtags -l Lists source files listed in tags file. Useful with "grep foo `mtags -l`" EOF } unless (@ARGV) { &usage; exit; }; require "getopt.pl"; &Getopt("ot"); die "$opt_t looks like a flag, not a filename!\n" if $opt_t =~ /^-.+/; die "$opt_o looks like a flag, not a filename!\n" if $opt_t =~ /^-.+/; if ($opt_l && !$opt_t) { $opt_t = "./tags"; } if ($opt_t) { # override rest of ARGV $opt_a = 0; # overrides append mode. open(TAGS,"<$opt_t") || die "Unable to read $opt_t tags file.\n"; while () { ($tag,$file,$ex) = split; if ($file && -e $file) { print STDERR "$file identified\n" if $opt_v && !$files{$file}; $files{$file} = 1; } } # print STDERR "Updating tags from ",join(" ",@files),"\n" if $opt_v; close(TAGS); @ARGV = (@ARGV, keys %files); } if ($opt_l) { print join(" ",sort keys %files),"\n"; { exit; } } $file = "./tags"; $file = $opt_t if $opt_t; # update input file $file = $opt_o if $opt_o; # unless output is specified. if ($opt_a) { open(TAGS,">>$file") || die "Unable to append to tags file!\n"; print STDERR "Appending to $file\n" if $opt_v; } else { open(TAGS,">$file") || die "Unable to create tags file!\n"; print STDERR "Creating $file\n" if $opt_v; } while (<>) { $thisfile = $ARGV unless $thisfile; next unless /^[\@&]/; # it's can't an attribute line next if /^\@\@/; # it's a mpp comment next if /^\@set/i; # is it a common install command? next if /^\@parent/i; next if /^\@create/i; next if /^\@dig/i; next if /^\@lock/i; next if /^\@link/i; next if /^\@open/i; next if /^\@fo/i; chop; next if /^-$/; if (($char,$tag) =/^([&@])(\S+)/) { # print TAGS "$tag\t$ARGV\t/^$char$tag /\n"; $tags{$tag}= "$tag\t$ARGV\t/^$char$tag /"; print STDERR "$tag\t$ARGV\t/^$char$tag /\n" if $opt_v; } if ($thisfile && $thisfile ne $ARGV) { foreach $tag (sort keys %tags) { print TAGS $tags{$tag},"\n"; } %tags = (); $thisfile = $ARGV; } } close(TAGS);