chromeos: dbus: add Bluetooth properties support
[chromium-blink-merge.git] / third_party / lcov / bin / gendesc
blobe7a8113293b8ea4c64ccc898d509e8caa0f9ee76
1 #!/usr/bin/perl -w
3 # Copyright (c) International Business Machines Corp., 2002
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or (at
8 # your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # gendesc
22 # This script creates a description file as understood by genhtml.
23 # Input file format:
25 # For each test case:
26 # <test name><optional whitespace>
27 # <at least one whitespace character (blank/tab)><test description>
29 # Actual description may consist of several lines. By default, output is
30 # written to stdout. Test names consist of alphanumeric characters
31 # including _ and -.
34 # History:
35 # 2002-09-02: created by Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
38 use strict;
39 use File::Basename;
40 use Getopt::Long;
43 # Constants
44 our $lcov_version = "LCOV version 1.7";
45 our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
46 our $tool_name = basename($0);
49 # Prototypes
50 sub print_usage(*);
51 sub gen_desc();
52 sub warn_handler($);
53 sub die_handler($);
56 # Global variables
57 our $help;
58 our $version;
59 our $output_filename;
60 our $input_filename;
64 # Code entry point
67 $SIG{__WARN__} = \&warn_handler;
68 $SIG{__DIE__} = \&die_handler;
70 # Parse command line options
71 if (!GetOptions("output-filename=s" => \$output_filename,
72 "version" =>\$version,
73 "help|?" => \$help
76 print(STDERR "Use $tool_name --help to get usage information\n");
77 exit(1);
80 $input_filename = $ARGV[0];
82 # Check for help option
83 if ($help)
85 print_usage(*STDOUT);
86 exit(0);
89 # Check for version option
90 if ($version)
92 print("$tool_name: $lcov_version\n");
93 exit(0);
97 # Check for input filename
98 if (!$input_filename)
100 die("No input filename specified\n".
101 "Use $tool_name --help to get usage information\n");
104 # Do something
105 gen_desc();
109 # print_usage(handle)
111 # Write out command line usage information to given filehandle.
114 sub print_usage(*)
116 local *HANDLE = $_[0];
118 print(HANDLE <<END_OF_USAGE)
119 Usage: $tool_name [OPTIONS] INPUTFILE
121 Convert a test case description file into a format as understood by genhtml.
123 -h, --help Print this help, then exit
124 -v, --version Print version number, then exit
125 -o, --output-filename FILENAME Write description to FILENAME
127 For more information see: $lcov_url
128 END_OF_USAGE
134 # gen_desc()
136 # Read text file INPUT_FILENAME and convert the contained description to a
137 # format as understood by genhtml, i.e.
139 # TN:<test name>
140 # TD:<test description>
142 # If defined, write output to OUTPUT_FILENAME, otherwise to stdout.
144 # Die on error.
147 sub gen_desc()
149 local *INPUT_HANDLE;
150 local *OUTPUT_HANDLE;
151 my $empty_line = "ignore";
153 open(INPUT_HANDLE, $input_filename)
154 or die("ERROR: cannot open $input_filename!\n");
156 # Open output file for writing
157 if ($output_filename)
159 open(OUTPUT_HANDLE, ">$output_filename")
160 or die("ERROR: cannot create $output_filename!\n");
162 else
164 *OUTPUT_HANDLE = *STDOUT;
167 # Process all lines in input file
168 while (<INPUT_HANDLE>)
170 chomp($_);
172 if (/^\s*(\w[\w-]*)(\s*)$/)
174 # Matched test name
175 # Name starts with alphanum or _, continues with
176 # alphanum, _ or -
177 print(OUTPUT_HANDLE "TN: $1\n");
178 $empty_line = "ignore";
180 elsif (/^(\s+)(\S.*?)\s*$/)
182 # Matched test description
183 if ($empty_line eq "insert")
185 # Write preserved empty line
186 print(OUTPUT_HANDLE "TD: \n");
188 print(OUTPUT_HANDLE "TD: $2\n");
189 $empty_line = "observe";
191 elsif (/^\s*$/)
193 # Matched empty line to preserve paragraph separation
194 # inside description text
195 if ($empty_line eq "observe")
197 $empty_line = "insert";
202 # Close output file if defined
203 if ($output_filename)
205 close(OUTPUT_HANDLE);
208 close(INPUT_HANDLE);
211 sub warn_handler($)
213 my ($msg) = @_;
215 warn("$tool_name: $msg");
218 sub die_handler($)
220 my ($msg) = @_;
222 die("$tool_name: $msg");