-
Notifications
You must be signed in to change notification settings - Fork 242
/
Copy pathgendesc
executable file
·190 lines (163 loc) · 4.61 KB
/
gendesc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env perl
#
# Copyright (c) International Business Machines Corp., 2002
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see
# <http://www.gnu.org/licenses/>.
#
#
# gendesc
#
# This script creates a description file as understood by genhtml.
# Input file format:
#
# For each test case:
# <test name><optional whitespace>
# <at least one whitespace character (blank/tab)><test description>
#
# Actual description may consist of several lines. By default, output is
# written to stdout. Test names consist of alphanumeric characters
# including _ and -.
#
#
# History:
# 2002-09-02: created by Peter Oberparleiter <[email protected]>
#
use strict;
use warnings;
use File::Basename;
use Getopt::Long;
use Cwd qw/abs_path/;
use FindBin;
use lib "$FindBin::RealBin/../lib";
use lcovutil qw ($tool_name $tool_dir $lcov_version $lcov_url
die_handler warn_handler);
# Constants
# (now imported from lcovutil.pm)
# Prototypes
sub print_usage(*);
sub gen_desc();
# Global variables
our $help;
our $version;
our $output_filename;
our $input_filename;
#
# Code entry point
#
$SIG{__WARN__} = \&warn_handler;
$SIG{__DIE__} = \&die_handler;
# Parse command line options
if (!GetOptions("output-filename=s" => \$output_filename,
"version" => \$version,
"help|?" => \$help
)) {
print(STDERR "Use $tool_name --help to get usage information\n");
exit(1);
}
$input_filename = $ARGV[0];
# Check for help option
if ($help) {
print_usage(*STDOUT);
exit(0);
}
# Check for version option
if ($version) {
print("$tool_name: $lcov_version\n");
exit(0);
}
# Check for input filename
if (!$input_filename) {
die("No input filename specified\n" .
"Use $tool_name --help to get usage information\n");
}
# Do something
gen_desc();
#
# print_usage(handle)
#
# Write out command line usage information to given filehandle.
#
sub print_usage(*)
{
local *HANDLE = $_[0];
print(HANDLE <<END_OF_USAGE)
Usage: $tool_name [OPTIONS] INPUTFILE
Convert a test case description file into a format as understood by genhtml.
OPTIONS
-h, --help Print this help, then exit
--version Print version number, then exit
-o, --output-filename FILENAME Write description to FILENAME
For more information see the gendesc man page.
END_OF_USAGE
;
}
#
# gen_desc()
#
# Read text file INPUT_FILENAME and convert the contained description to a
# format as understood by genhtml, i.e.
#
# TN:<test name>
# TD:<test description>
#
# If defined, write output to OUTPUT_FILENAME, otherwise to stdout.
#
# Die on error.
#
sub gen_desc()
{
local *INPUT_HANDLE;
local *OUTPUT_HANDLE;
my $empty_line = "ignore";
open(INPUT_HANDLE, "<", $input_filename) or
die("cannot open $input_filename!\n");
# Open output file for writing
if ($output_filename) {
open(OUTPUT_HANDLE, ">", $output_filename) or
die("cannot create $output_filename!\n");
} else {
*OUTPUT_HANDLE = *STDOUT;
}
# Process all lines in input file
while (<INPUT_HANDLE>) {
chomp($_);
if (/^(\w[\w-]*)(\s*)$/) {
# Matched test name
# Name starts with alphanum or _, continues with
# alphanum, _ or -
print(OUTPUT_HANDLE "TN: $1\n");
$empty_line = "ignore";
} elsif (/^(\s+)(\S.*?)\s*$/) {
# Matched test description
if ($empty_line eq "insert") {
# Write preserved empty line
print(OUTPUT_HANDLE "TD: \n");
}
print(OUTPUT_HANDLE "TD: $2\n");
$empty_line = "observe";
} elsif (/^\s*$/) {
# Matched empty line to preserve paragraph separation
# inside description text
if ($empty_line eq "observe") {
$empty_line = "insert";
}
}
}
# Close output file if defined
if ($output_filename) {
close(OUTPUT_HANDLE);
}
close(INPUT_HANDLE);
}