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
22 # This script creates a description file as understood by genhtml.
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
35 # 2002-09-02: created by Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
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);
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,
76 print(STDERR
"Use $tool_name --help to get usage information\n");
80 $input_filename = $ARGV[0];
82 # Check for help option
89 # Check for version option
92 print("$tool_name: $lcov_version\n");
97 # Check for input filename
100 die("No input filename specified\n".
101 "Use $tool_name --help to get usage information\n");
109 # print_usage(handle)
111 # Write out command line usage information to given filehandle.
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
136 # Read text file INPUT_FILENAME and convert the contained description to a
137 # format as understood by genhtml, i.e.
140 # TD:<test description>
142 # If defined, write output to OUTPUT_FILENAME, otherwise to stdout.
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");
164 *OUTPUT_HANDLE = *STDOUT;
167 # Process all lines in input file
168 while (<INPUT_HANDLE>)
172 if (/^\s*(\w[\w-]*)(\s*)$/)
175 # Name starts with alphanum or _, continues with
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";
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);
215 warn("$tool_name: $msg");
222 die("$tool_name: $msg");