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.10';
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 # Prettify version string
71 $lcov_version =~ s/\$\s*Revision\s*:?\s*(\S+)\s*\$/$1/;
73 # Parse command line options
74 if (!GetOptions
("output-filename=s" => \
$output_filename,
75 "version" =>\
$version,
79 print(STDERR
"Use $tool_name --help to get usage information\n");
83 $input_filename = $ARGV[0];
85 # Check for help option
92 # Check for version option
95 print("$tool_name: $lcov_version\n");
100 # Check for input filename
101 if (!$input_filename)
103 die("No input filename specified\n".
104 "Use $tool_name --help to get usage information\n");
112 # print_usage(handle)
114 # Write out command line usage information to given filehandle.
119 local *HANDLE
= $_[0];
121 print(HANDLE
<<END_OF_USAGE)
122 Usage: $tool_name [OPTIONS] INPUTFILE
124 Convert a test case description file into a format as understood by genhtml.
126 -h, --help Print this help, then exit
127 -v, --version Print version number, then exit
128 -o, --output-filename FILENAME Write description to FILENAME
130 For more information see: $lcov_url
139 # Read text file INPUT_FILENAME and convert the contained description to a
140 # format as understood by genhtml, i.e.
143 # TD:<test description>
145 # If defined, write output to OUTPUT_FILENAME, otherwise to stdout.
153 local *OUTPUT_HANDLE;
154 my $empty_line = "ignore";
156 open(INPUT_HANDLE, "<", $input_filename)
157 or die("ERROR: cannot open $input_filename!\n");
159 # Open output file for writing
160 if ($output_filename)
162 open(OUTPUT_HANDLE, ">", $output_filename)
163 or die("ERROR: cannot create $output_filename!\n");
167 *OUTPUT_HANDLE = *STDOUT;
170 # Process all lines in input file
171 while (<INPUT_HANDLE>)
175 if (/^(\w[\w-]*)(\s*)$/)
178 # Name starts with alphanum or _, continues with
180 print(OUTPUT_HANDLE "TN: $1\n");
181 $empty_line = "ignore";
183 elsif (/^(\s+)(\S.*?)\s*$/)
185 # Matched test description
186 if ($empty_line eq "insert")
188 # Write preserved empty line
189 print(OUTPUT_HANDLE "TD: \n");
191 print(OUTPUT_HANDLE "TD: $2\n");
192 $empty_line = "observe";
196 # Matched empty line to preserve paragraph separation
197 # inside description text
198 if ($empty_line eq "observe")
200 $empty_line = "insert";
205 # Close output file if defined
206 if ($output_filename)
208 close(OUTPUT_HANDLE);
218 warn("$tool_name: $msg");
225 die("$tool_name: $msg");