Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /svnutils/trunk/src/

svnutils
Discussion topic

Back to topic list

CVS update: /svnutils/trunk/src/

Author sunny256
Full name Øyvind A. Holm
Date 2005-08-20 07:40:19 PDT
Message User: sunny256
Date: 2005/08/20 07:40:19

Modified:
   svnutils/trunk/src/sident

Log:
 r153 | sunny256 | 2005-08-20 14:30:53 +0000 (Sat, 20 Aug 2005) | 11 lines
 
 sident: Added the "-x"/"--xml" option which generates XML output. The
 standard ident(1) format isn’t 100% parseable.
 
 * /trunk/src/sident
   Added option for generating XML output.
   ($opt_xml): New global variable.
   (txt_to_xml): New subroutine.
   (usage): If --xml is specified, the help screen is printed as a tiny
     DocBook XML document.
   (POD): Added info about the XML thing.

File Changes:

Directory: /svnutils/trunk/src/
===============================

File [changed]: sident
Url: http://svnutils.tigr​is.org/source/browse​/svnutils/trunk/src/​sident?r1=1.10&r​2=1.11
Delta lines: +101 -16
----------------------
--- sident 20 Aug 2005 14:39:42 -0000 1.10
+++ sident 20 Aug 2005 14:40:17 -0000 1.11
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 #===================​====================​====================​============
-# $Id: sident 152 2005-08-20 03:54:46Z sunny256 $
+# $Id: sident 153 2005-08-20 14:30:53Z sunny256 $
 # Lists RCS-like keywords in files. Replacement for ident(1).
 #
 # Character set: UTF-8
@@ -16,13 +16,13 @@
 
 our $Debug = 0;
 
-our ($opt_help, $opt_known, $opt_namesonly, $opt_verbose) =
- ( 0, 0, 0, 0);
+our ($opt_help, $opt_known, $opt_namesonly, $opt_verbose, $opt_xml) =
+ ( 0, 0, 0, 0, 0);
 
 our $progname = $0;
 $progname =~ s#^.*/(.*?)$#$1#;
 
-my $rcs_id = '$Id: sident 152 2005-08-20 03:54:46Z sunny256 $';
+my $rcs_id = '$Id: sident 153 2005-08-20 14:30:53Z sunny256 $';
 my $id_date = $rcs_id;
 
 Getopt::Long::Config​ure("bundling");
@@ -30,7 +30,8 @@
     "help|h" => \$opt_help,
     "known-keywords-only|k" => \$opt_known,
     "filenames-only|l" => \$opt_namesonly,
- "verbose|v" => \$opt_verbose
+ "verbose|v" => \$opt_verbose,
+ "xml|x" => \$opt_xml
 ) || die("$progname: Option error. Use -h for help.\n");
 
 $opt_help && usage(0);
@@ -51,34 +52,88 @@
                );
 my $Keyw = $opt_known ? join('|', @Keywords) : '[A-Za-z]+'; # Used in regexps
 
+if ($opt_xml) {
+ print(<<END);
+<?xml version="1.0"?>
+<sident>
+END
+}
+
 for (@ARGV) {
     my @Out = ();
     my $File = $_;
     if (open(FromFP, "<$File")) {
         while (<FromFP>) {
- s/(\$($Keyw)\$)/push(@Out, " $1\n")/ge;
- s/(\$($Keyw)::? .*? \$)/push(@Out, " $1\n")/ge;
+ s/(\$($Keyw)\$)/push(@Out, $1)/ge;
+ s/(\$($Keyw)::? .*? \$)/push(@Out, $1)/ge;
         }
         if (scalar(@Out)) {
+ $opt_xml && print(" <file>\n");
             if ($opt_namesonly) {
+ if ($opt_xml) {
+ printf(" <filename>%s​</filename>\n",​
+ txt_to_xml($File)
+ );
+ } else {
                 print("$File\n");
+ }
+ } else {
+ if ($opt_xml) {
+ printf(" <filename>%s​</filename>\n",​
+ txt_to_xml($File)
+ );
             } else {
                 print("\n$File:\n");
+ }
+ $opt_xml && print(" <keywords>\n");
                 for (@Out) {
- print($_);
+ if ($opt_xml) {
+ printf(" <keyword>%s​</keyword>\n",
+ txt_to_xml($_));
+ } else {
+ print(" $_\n");
+ }
                 }
+ $opt_xml && print(" </keywords>\n");
             }
+ $opt_xml && print(" </file>\n");
         } else {
- print("\n$File:\n") if ($opt_verbose);
+ if ($opt_verbose) {
+ $opt_xml && print(" <file>\n");
+ if ($opt_xml) {
+ printf(" <filename>%s​</filename>\n",​
+ txt_to_xml($File)
+ );
+ } else {
+ print("\n$File:\n");
+ }
+ $opt_xml && print(" </file>\n");
+ }
         }
     }
 }
 
+$opt_xml && print("</sident>\n");
+
 sub usage {
     # Send the help message to stdout {{{
     my $Retval = shift;
- print(<<END);
+ my ($xml_start, $xml_end) =
+ ( "", "");
 
+ if ($opt_xml) {
+ $xml_start = <<END;
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4//EN" "http://docbook.org/x​ml/4.3/docbookx.dtd">
+<article>
+ <screen>
+END
+ $xml_end = <<END;
+</screen>
+</article>
+END
+ }
+ my $Txt = <<END;
 $rcs_id
 
 Usage: $progname [options] [file [files [...]]]
@@ -96,8 +151,14 @@
       keywords
   -v, --verbose
       Also list files without keywords.
-
+ -x, --xml
+ Create XML output
 END
+ printf("%s%s%s",
+ $xml_start,
+ $opt_xml ? txt_to_xml($Txt) : "\n$Txt\n",
+ $xml_end
+ );
     exit($Retval);
     # }}}
 }
@@ -110,11 +171,31 @@
     my $File = $call_info[1];
     $File =~ s#\\#/#g;
     $File =~ s#^.*/(.*?)$#$1#;
+ if ($opt_xml) {
+ printf(STDERR "<debug> <pid>%s</pid> <file>%s</file> <line>%s</line> <msg>%s</msg> </debug>\n",
+ txt_to_xml($$),
+ txt_to_xml($File),
+ txt_to_xml($call_info[2]),
+ txt_to_xml($Txt)
+ );
+ } else {
     print(STDERR "$File:$call_info[2] $$ $Txt\n");
+ }
     return("");
     # }}}
 } # D()
 
+sub txt_to_xml {
+ # Return a XML-safe version of a string {{{
+ my $Txt = shift;
+
+ $Txt =~ s/&/&amp;/gs;
+ $Txt =~ s/</&lt;/gs;
+ $Txt =~ s/>/&gt;/gs;
+ return($Txt);
+ # }}}
+} # txt_to_xml()
+
 __END__
 
 # Plain Old Documentation (POD) {{{
@@ -127,7 +208,7 @@
 
 =head1 REVISION
 
-$Id: sident 152 2005-08-20 03:54:46Z sunny256 $
+$Id: sident 153 2005-08-20 14:30:53Z sunny256 $
 
 =head1 SYNOPSIS
 
@@ -158,6 +239,10 @@
 
 In addition to list keywords, also list names of files without keywords.
 
+=item B<-x>, B<--xml>
+
+Create XML output.
+
 =back
 
 =head1 BUGS
@@ -196,4 +281,4 @@
 # }}}
 
 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
-# End of file $Id: sident 152 2005-08-20 03:54:46Z sunny256 $
+# End of file $Id: sident 153 2005-08-20 14:30:53Z sunny256 $

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /svnutils/trunk/src/ sunny256 Øyvind A. Holm 2005-08-20 07:40:19 PDT
Messages per page: