OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/perl -w |
| 2 # |
| 3 # Copyright (c) International Business Machines Corp., 2002 |
| 4 # |
| 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. |
| 9 # |
| 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. |
| 14 # |
| 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 |
| 18 # |
| 19 # |
| 20 # gendesc |
| 21 # |
| 22 # This script creates a description file as understood by genhtml. |
| 23 # Input file format: |
| 24 # |
| 25 # For each test case: |
| 26 # <test name><optional whitespace> |
| 27 # <at least one whitespace character (blank/tab)><test description> |
| 28 # |
| 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 -. |
| 32 # |
| 33 # |
| 34 # History: |
| 35 # 2002-09-02: created by Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com> |
| 36 # |
| 37 |
| 38 use strict; |
| 39 use File::Basename; |
| 40 use Getopt::Long; |
| 41 |
| 42 |
| 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); |
| 47 |
| 48 |
| 49 # Prototypes |
| 50 sub print_usage(*); |
| 51 sub gen_desc(); |
| 52 sub warn_handler($); |
| 53 sub die_handler($); |
| 54 |
| 55 |
| 56 # Global variables |
| 57 our $help; |
| 58 our $version; |
| 59 our $output_filename; |
| 60 our $input_filename; |
| 61 |
| 62 |
| 63 # |
| 64 # Code entry point |
| 65 # |
| 66 |
| 67 $SIG{__WARN__} = \&warn_handler; |
| 68 $SIG{__DIE__} = \&die_handler; |
| 69 |
| 70 # Parse command line options |
| 71 if (!GetOptions("output-filename=s" => \$output_filename, |
| 72 "version" =>\$version, |
| 73 "help|?" => \$help |
| 74 )) |
| 75 { |
| 76 print(STDERR "Use $tool_name --help to get usage information\n"); |
| 77 exit(1); |
| 78 } |
| 79 |
| 80 $input_filename = $ARGV[0]; |
| 81 |
| 82 # Check for help option |
| 83 if ($help) |
| 84 { |
| 85 print_usage(*STDOUT); |
| 86 exit(0); |
| 87 } |
| 88 |
| 89 # Check for version option |
| 90 if ($version) |
| 91 { |
| 92 print("$tool_name: $lcov_version\n"); |
| 93 exit(0); |
| 94 } |
| 95 |
| 96 |
| 97 # Check for input filename |
| 98 if (!$input_filename) |
| 99 { |
| 100 die("No input filename specified\n". |
| 101 "Use $tool_name --help to get usage information\n"); |
| 102 } |
| 103 |
| 104 # Do something |
| 105 gen_desc(); |
| 106 |
| 107 |
| 108 # |
| 109 # print_usage(handle) |
| 110 # |
| 111 # Write out command line usage information to given filehandle. |
| 112 # |
| 113 |
| 114 sub print_usage(*) |
| 115 { |
| 116 local *HANDLE = $_[0]; |
| 117 |
| 118 print(HANDLE <<END_OF_USAGE) |
| 119 Usage: $tool_name [OPTIONS] INPUTFILE |
| 120 |
| 121 Convert a test case description file into a format as understood by genhtml. |
| 122 |
| 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 |
| 126 |
| 127 For more information see: $lcov_url |
| 128 END_OF_USAGE |
| 129 ; |
| 130 } |
| 131 |
| 132 |
| 133 # |
| 134 # gen_desc() |
| 135 # |
| 136 # Read text file INPUT_FILENAME and convert the contained description to a |
| 137 # format as understood by genhtml, i.e. |
| 138 # |
| 139 # TN:<test name> |
| 140 # TD:<test description> |
| 141 # |
| 142 # If defined, write output to OUTPUT_FILENAME, otherwise to stdout. |
| 143 # |
| 144 # Die on error. |
| 145 # |
| 146 |
| 147 sub gen_desc() |
| 148 { |
| 149 local *INPUT_HANDLE; |
| 150 local *OUTPUT_HANDLE; |
| 151 my $empty_line = "ignore"; |
| 152 |
| 153 open(INPUT_HANDLE, $input_filename) |
| 154 or die("ERROR: cannot open $input_filename!\n"); |
| 155 |
| 156 # Open output file for writing |
| 157 if ($output_filename) |
| 158 { |
| 159 open(OUTPUT_HANDLE, ">$output_filename") |
| 160 or die("ERROR: cannot create $output_filename!\n"); |
| 161 } |
| 162 else |
| 163 { |
| 164 *OUTPUT_HANDLE = *STDOUT; |
| 165 } |
| 166 |
| 167 # Process all lines in input file |
| 168 while (<INPUT_HANDLE>) |
| 169 { |
| 170 chomp($_); |
| 171 |
| 172 if (/^\s*(\w[\w-]*)(\s*)$/) |
| 173 { |
| 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"; |
| 179 } |
| 180 elsif (/^(\s+)(\S.*?)\s*$/) |
| 181 { |
| 182 # Matched test description |
| 183 if ($empty_line eq "insert") |
| 184 { |
| 185 # Write preserved empty line |
| 186 print(OUTPUT_HANDLE "TD: \n"); |
| 187 } |
| 188 print(OUTPUT_HANDLE "TD: $2\n"); |
| 189 $empty_line = "observe"; |
| 190 } |
| 191 elsif (/^\s*$/) |
| 192 { |
| 193 # Matched empty line to preserve paragraph separation |
| 194 # inside description text |
| 195 if ($empty_line eq "observe") |
| 196 { |
| 197 $empty_line = "insert"; |
| 198 } |
| 199 } |
| 200 } |
| 201 |
| 202 # Close output file if defined |
| 203 if ($output_filename) |
| 204 { |
| 205 close(OUTPUT_HANDLE); |
| 206 } |
| 207 |
| 208 close(INPUT_HANDLE); |
| 209 } |
| 210 |
| 211 sub warn_handler($) |
| 212 { |
| 213 my ($msg) = @_; |
| 214 |
| 215 warn("$tool_name: $msg"); |
| 216 } |
| 217 |
| 218 sub die_handler($) |
| 219 { |
| 220 my ($msg) = @_; |
| 221 |
| 222 die("$tool_name: $msg"); |
| 223 } |
OLD | NEW |