3 #=======================================================================
5 # File ID: da340b94-f743-11dd-8d53-000475e441b9
7 # Lists RCS-like keywords in files. Replacement for ident(1).
10 # ©opyleft 2004– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
37 $progname =~ s/^.*\/(.*?)$/$1/;
38 our $VERSION = '0.1.0';
40 Getopt
::Long
::Configure
('bundling');
43 'expanded-only|e' => \
$Opt{'expanded'},
44 'filenames-from|f=s' => \
$Opt{'filesfrom'},
45 'filenames-only|l' => \
$Opt{'namesonly'},
46 'help|h' => \
$Opt{'help'},
47 'known-keywords-only|k' => \
$Opt{'known'},
48 'quiet|q+' => \
$Opt{'quiet'},
49 'unique-keywords|u' => \
$Opt{'unique'},
50 'verbose|v+' => \
$Opt{'verbose'},
51 'version' => \
$Opt{'version'},
52 'xml|x' => \
$Opt{'xml'}
54 ) || die("$progname: Option error. Use -h for help.\n");
56 $Opt{'verbose'} -= $Opt{'quiet'};
57 $Opt{'help'} && usage
(0);
58 if ($Opt{'version'}) {
70 # List of recognised keywords {{{
72 "Author", "LastChangedBy",
73 "Date", "LastChangedDate",
74 "LastChangedRevision", "Revision", "Rev",
85 my $Keyw = $Opt{'known'}
86 ?
join('|', @Keywords)
87 : '[A-Za-z]+'; # Used in regexps
99 if (length($Opt{'filesfrom'})) {
101 if (open(FromFP
, "<$Opt{'filesfrom'}")) {
108 die("$progname: $Opt{'filesfrom'}: " .
109 "Cannot read filenames from file: $!\n");
118 if (open(FromFP
, "<$File")) {
120 $Opt{'expanded'} || s/(\$($Keyw)\$)/push(@Out, $1)/ge;
121 s/(\$($Keyw)::? .*? \$)/push(@Out, $1)/ge;
125 if ($Opt{'unique'}) {
129 for my $Curr (@Out2) {
130 if (!defined($Done{$Curr})) {
137 $Opt{'xml'} && print(" <file>\n");
138 if ($Opt{'namesonly'}) {
140 printf(" <filename>%s</filename>\n",
148 printf(" <filename>%s</filename>\n",
154 $Opt{'xml'} && print(" <keywords>\n");
157 printf(" <keyword>%s</keyword>\n",
163 $Opt{'xml'} && print(" </keywords>\n");
165 $Opt{'xml'} && print(" </file>\n");
167 if ($Opt{'verbose'} && !-d
$File) {
168 $Opt{'xml'} && print(" <file>\n");
170 printf(" <filename>%s</filename>\n",
176 $Opt{'xml'} && print(" </file>\n");
180 warn("$progname: $File: Cannot read file: $!\n");
186 $Opt{'xml'} && print("</sident>\n");
193 # Print program version {{{
194 print("$progname $VERSION\n");
200 # Send the help message to stdout {{{
203 if ($Opt{'verbose'}) {
209 Usage: $progname [options] [file [files [...]]]
211 Lists RCS-like keywords in a file.
216 List only expanded keywords.
217 -f, --filenames-from x
218 Read filenames from file x in addition to files specified on the
222 -k, --known-keywords-only
223 Only list keywords known to Subversion and CVS.
225 Suppress normal output; only list names of files which contain
228 Be more quiet. Can be repeated to increase silence.
229 -u, --unique-keywords
230 List keywords only once per file, avoid duplicates.
232 Increase level of verbosity. Can be repeated.
233 One -v also list files without keywords.
235 Print version information.
245 # Print a status message to stderr based on verbosity level {{{
246 my ($verbose_level, $Txt) = @_;
248 if ($Opt{'verbose'} >= $verbose_level) {
249 print(STDERR
"$progname: $Txt\n");
256 # Return a XML-safe version of a string {{{
259 $Txt =~ s/&/&/gs;
268 # Plain Old Documentation (POD) {{{
280 sident [options] [file [files [...]]]
284 Replacement for ident(1), lists RCS-like keywords in a file.
290 =item B<-e>, B<--expanded-only>
292 List only expanded keywords.
294 =item B<-f>, B<--filenames-from> x
296 Read filenames from file F<x> in addition to files specified on the
299 =item B<-h>, B<--help>
301 Print a brief help summary.
303 =item B<-k>, B<--known-keywords-only>
305 Only list keywords known to Subversion and CVS.
307 =item B<-l>, B<--filenames-only>
309 Suppress normal output; only list names of files which contains
312 =item B<-u>, B<--unique-keywords>
314 Only list keywords once per file, avoid duplicates.
316 =item B<-q>, B<--quiet>
318 Be more quiet. Can be repeated to increase silence.
320 =item B<-v>, B<--verbose>
322 In addition to list keywords, also list names of files without keywords.
326 Print version information.
328 =item B<-x>, B<--xml>
340 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
344 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
345 This is free software; see the file F<COPYING> for legalese stuff.
349 This program is free software: you can redistribute it and/or modify it
350 under the terms of the GNU General Public License as published by the
351 Free Software Foundation, either version 2 of the License, or (at your
352 option) any later version.
354 This program is distributed in the hope that it will be useful, but
355 WITHOUT ANY WARRANTY; without even the implied warranty of
356 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
357 See the GNU General Public License for more details.
359 You should have received a copy of the GNU General Public License along
361 If not, see L<http://www.gnu.org/licenses/>.
371 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :