blib/lib/Language/Dashrep.pm

filter: Statementstmt 71.2% 846 / 1187 Branchbran 52.7% 303 / 574 Conditioncond 35.8% 43 / 120 MC/DCmcdc 25.6% 19 / 74 Subroutinesub 90.9% 20 / 22 Podpod 100% 17 / 17 totaltotal 62.5% 1248 / 1994 CC 335 SCAR 60.9
CC
335
Cov
63%
dashrep_top_level_action
1128.6
dashrep_linewise_translate
420.0
dashrep_xml_tags_to_dashrep
306.0
CRAP 442.4
↑ Summary
1 package Language::Dashrep;
2  
3 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 require Exporter;
8  
9  
10 =head1 NAME
11  
12 Language::Dashrep - Dashrep language translator/interpreter
13  
14 =cut
15  
16  
17 =head1 VERSION
18  
19 Version 2.33
20  
21 =cut
22  
23 3 our $VERSION = '2.33';
24  
25  
26 =head1 SYNOPSIS
27  
28 The following sample code executes the Dashrep-language actions specified in the standard input file.
29  
30 use Language::Dashrep;
31 &Dashrep::dashrep_linewise_translate( );
32  
33 The module also supports direct access to functions that define Dashrep phrases, expand text that contains Dashrep phrases, and more.
34  
35 =cut
36  
37  
38 =head1 ABOUT
39  
40 Dashrep (TM) is a versatile descriptive programming language that recognizes hyphenated phrases, such as B<rectangle-outline-attention-begin>, and recursively expands the phrases to generate an HTML web page, an XML file, a JavaScript program, a boilerplate-based document, a template-based email message, or any other text-based content.
41  
42 See www.Dashrep.org for details about the Dashrep language.
43  
44 Although Dashrep code is not directly executable, it can generate executable code. Although it does not directly define loops, it generates lists in which any delimited (using commas and/or spaces) list of text strings (including integers) specifies the unique values for the list items. Although the Dashrep language does not directly implement a branching structure, the translated code can be completely changed at any level (including within lists) based on parameterized hyphenated phrases such as B<[-template-for-move-proposal-link-for-action-[-output-requested-action-]-]>.
45  
46 The Dashrep language has been used to convert text files into MML- and XML-format files (for two books, I<The Creative Problem Solver's Toolbox> and I<Ending The Hidden Unfairness In U.S. Elections>), specify dynamically generated HTML pages (at www.VoteFair.org and www.NegotiationTool.com), generate JavaScript code (that Adobe Illustrator executed to generate vector graphics for use in the book I<Ending The Hidden Unfairness In U.S. Elections>), generate invoices and packing slips, expand boilerplate-like text, and more.
47  
48 The design goals for the Dashrep language were:
49  
50 =over
51  
52 =item * Provide a convenient way to move descriptive code out of executable code.
53  
54 =item * Keep it simple, and keep it flexible.
55  
56 =item * Make the language speakable. (This characteristic is useful for various purposes, including circumventing keyboard-induced repetitive-stress injury, and using microphone-equipped mobile devices.)
57  
58 Note about Version 2 and later: These versions, if they are from GitHub instead of CPAN, can be used without the CPAN envioronment. The GitHub version only needs the Perl interpreter, which means that on the Windows operating system only the I<perl.exe> and I<perl512.dll> and I<libgcc_s_sjlj-1.dll> files (or their more-recent equivalents) are needed.
59  
60 =back
61  
62 =cut
63  
64  
65 =head1 EXPORT
66  
67 The following subroutines are exported.
68  
69 =head2 dashrep_define
70  
71 =head2 dashrep_import_replacements
72  
73 =head2 dashrep_get_replacement
74  
75 =head2 dashrep_get_list_of_phrases
76  
77 =head2 dashrep_delete
78  
79 =head2 dashrep_delete_all
80  
81 =head2 dashrep_expand_parameters
82  
83 =head2 dashrep_expand_phrases
84  
85 =head2 dashrep_expand_phrases_except_special
86  
87 =head2 dashrep_expand_special_phrases
88  
89 =head2 dashrep_xml_tags_to_dashrep
90  
91 =head2 dashrep_top_level_action
92  
93 =head2 dashrep_linewise_translate
94  
95 =cut
96  
97  
98 3 our @ISA = qw(Exporter);
99 3 our @EXPORT = qw(
100 dashrep_define
101 dashrep_import_replacements
102 dashrep_get_replacement
103 dashrep_get_list_of_phrases
104 dashrep_delete
105 dashrep_delete_all
106 dashrep_expand_parameters
107 dashrep_expand_phrases
108 dashrep_expand_phrases_except_special
109 dashrep_expand_special_phrases
110 dashrep_xml_tags_to_dashrep
111 dashrep_top_level_action
112 dashrep_linewise_translate
113 );
114  
115  
116 #-----------------------------------------------
117 # This Perl code is intentionally written
118 # in a subset of Perl and uses a C-like
119 # syntax so that it can be ported more
120 # easily to other languages, especially
121 # the C language for faster execution.
122 #
123 # If you offer improvements to this code,
124 # please follow this convention so that
125 # the code continues to be easily converted
126 # into other languages.
127 #-----------------------------------------------
128  
129  
130 #-----------------------------------------------
131 # Declare package variables.
132  
133 3 my $global_true ;
134 my $global_false ;
135 3 my $global_endless_loop_counter ;
136 3 my $global_endless_loop_counter_limit ;
137 3 my $global_nesting_level_of_file_actions ;
138 3 my $global_xml_level_number ;
139 3 my $global_xml_accumulated_sequence_of_tag_names ;
140 3 my $global_spaces ;
141 3 my $global_ignore_level ;
142 3 my $global_capture_level ;
143 3 my $global_phrase_to_insert_after_next_top_level_line ;
144 3 my $global_top_line_count_for_insert_phrase ;
145 3 my %global_dashrep_replacement ;
146 3 my %global_replacement_count_for_item_name ;
147 3 my %global_exists_xml_hyphenated_phrase ;
148 3 my @global_list_of_lists_to_generate ;
149 3 my @global_xml_tag_at_level_number ;
150  
151  
152 #-----------------------------------------------
153 # Define package constants, and initialize
154 # special phrases.
155  
156 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
157 3 $global_true = 1 ;
158 3 $global_false = 0 ;
159 3 $global_endless_loop_counter = 0 ;
160 3 $global_endless_loop_counter_limit = 70000 ;
161 3 $global_xml_accumulated_sequence_of_tag_names = "" ;
162 3 $global_spaces = " " ;
163 3 $global_nesting_level_of_file_actions = 0 ;
164 3 $global_ignore_level = 0 ;
165 3 $global_capture_level = 0 ;
166 3 $global_xml_level_number = 0 ;
167 3 %global_replacement_count_for_item_name = ( ) ;
168 3 @global_list_of_lists_to_generate = ( ) ;
169 3 @global_xml_tag_at_level_number = ( ) ;
170  
171 3 %global_dashrep_replacement = ( ) ;
172 3 $global_dashrep_replacement{ "dashrep-comments-ignored" } = "" ;
173 3 $global_dashrep_replacement{ "dashrep-endless-loop-counter-limit" } = "" ;
174 3 $global_dashrep_replacement{ "dashrep-debug-trace-on-or-off" } = "" ;
175 3 $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } = "" ;
176 3 $global_dashrep_replacement{ "dashrep-linewise-trace-on-or-off" } = "" ;
177 3 $global_dashrep_replacement{ "dashrep-ignore-trace-on-or-off" } = "" ;
178 3 $global_dashrep_replacement{ "dashrep-ignore-level" } = "" ;
179 3 $global_dashrep_replacement{ "dashrep-capture-trace-on-or-off" } = "" ;
180 3 $global_dashrep_replacement{ "dashrep-capture-level" } = "" ;
181 3 $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } = "" ;
182 3 $global_dashrep_replacement{ "dashrep-first-xml-tag-name" } = "" ;
183 3 $global_dashrep_replacement{ "dashrep-xml-yes-handle-open-close-tag-" } = "" ;
184 3 $global_dashrep_replacement{ "dashrep-xml-yes-handle-open-close-tag-" } = "" ;
185 3 $global_dashrep_replacement{ "dashrep-yes-or-no-export-delimited-definitions" } = "" ;
186 }
187  
188  
189 =head1 FUNCTIONS
190  
191  
192 =head2 initialize_special_phrases
193  
194 Initialize the phrases with special "dashrep_..."
195 names.
196  
197 =cut
198  
199 #-----------------------------------------------
200 #-----------------------------------------------
201 # initialize_special_phrases
202 #-----------------------------------------------
203 #-----------------------------------------------
204  
205 sub initialize_special_phrases
206 1 ▶{
Subroutine initialize_special_phrases: called CC=1 SCAR=0.0
Pod documented
207 1 $global_dashrep_replacement{ "dashrep-comments-ignored" } = "" ;
208 1 $global_dashrep_replacement{ "dashrep-endless-loop-counter-limit" } = "" ;
209 1 $global_dashrep_replacement{ "dashrep-debug-trace-on-or-off" } = "" ;
210 1 $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } = "" ;
211 1 $global_dashrep_replacement{ "dashrep-linewise-trace-on-or-off" } = "" ;
212 1 $global_dashrep_replacement{ "dashrep-ignore-trace-on-or-off" } = "" ;
213 1 $global_dashrep_replacement{ "dashrep-ignore-level" } = "" ;
214 1 $global_dashrep_replacement{ "dashrep-capture-trace-on-or-off" } = "" ;
215 1 $global_dashrep_replacement{ "dashrep-capture-level" } = "" ;
216 1 $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } = "" ;
217 1 $global_dashrep_replacement{ "dashrep-first-xml-tag-name" } = "" ;
218 1 $global_dashrep_replacement{ "dashrep-xml-yes-handle-open-close-tag-" } = "" ;
219 1 $global_dashrep_replacement{ "dashrep-xml-yes-handle-open-close-tag-" } = "" ;
220 1 $global_dashrep_replacement{ "dashrep-yes-or-no-export-delimited-definitions" } = "" ;
221 }
222  
223  
224 =head2 dashrep_define
225  
226 Associates a replacement text string with
227 the specified hyphenated phrase.
228  
229 First parameter is the hyphenated phrase.
230 Second parameter is its replacement text
231 string.
232  
233 Return value is 1 if the definition is
234 successful. Return value is zero if there
235 are not exactly two parameters.
236  
237 =cut
238  
239 #-----------------------------------------------
240 #-----------------------------------------------
241 # dashrep_define
242 #-----------------------------------------------
243 #-----------------------------------------------
244  
245 sub dashrep_define
246 12 ▶{
Subroutine dashrep_define: called CC=2 SCAR=7.2
Pod documented
247  
248 12 my $phrase_name ;
249 my $expanded_text ;
250  
251  
252 #-----------------------------------------------
253 # Do the assignment.
254  
255 12 ▶ if ( scalar( @_ ) == 2 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 2) { } 12 0 12
256 {
257 12 $phrase_name = $_[ 0 ] ;
258 12 $expanded_text = $_[ 1 ] ;
259 12 $phrase_name =~ s/^ +// ;
260 12 $phrase_name =~ s/ +$// ;
261 12 $global_dashrep_replacement{ $phrase_name } = $expanded_text ;
262 } else
263 {
264 0 carp "Warning: Call to dashrep_define subroutine does not have exactly two parameters." ;
265 0 return 0 ;
266 }
267  
268  
269 #-----------------------------------------------
270 # End of subroutine.
271  
272 12 return 1 ;
273  
274 }
275  
276  
277 =head2 dashrep_import_replacements
278  
279 Parses text that associates Dashrep phrases
280 with the definitions for those phrases.
281  
282 First, and only, parameter is the text
283 string that uses the Dashrep language.
284  
285 Return value is the count for how many
286 hyphenated phrases were defined (or
287 redefined). Return value is zero if
288 there is not exactly one parameter.
289  
290 =cut
291  
292 #-----------------------------------------------
293 #-----------------------------------------------
294 # dashrep_import_replacements
295 #-----------------------------------------------
296 #-----------------------------------------------
297  
298 sub dashrep_import_replacements
299 2 ▶{
Subroutine dashrep_import_replacements: called CC=21 SCAR=32.9
Pod documented
300  
301 2 my $definition_name ;
302 my $definition_value ;
303 2 my $input_string ;
304 2 my $replacements_text_to_import ;
305 2 my $text_before ;
306 2 my $text_including_comment_end ;
307 2 my $text_after ;
308 2 my $do_nothing ;
309 2 my @list_of_replacement_names ;
310 2 my @list_of_replacement_strings ;
311  
312  
313 #-----------------------------------------------
314 # Get the text that contains replacement
315 # definitions.
316  
317 2 ▶ if ( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 2 0 2
318 {
319 2 $replacements_text_to_import = $_[ 0 ] ;
320 } else
321 {
322 0 carp "Warning: Call to dashrep_import_replacements subroutine does not have exactly one parameter." ;
323 0 return 0 ;
324 }
325 2 ▶ if ( not( defined( $replacements_text_to_import ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $replacements_text_to_import) 0 2 2
326 {
327 0 $replacements_text_to_import = "" ;
328 0 ▶ if ( $global_dashrep_replacement{ "dashrep-debug-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on") 0 0 0
329 {
330 0 print "{{trace; imported zero definitions from empty text}}\n" ;
331 }
332 }
333  
334  
335 #-----------------------------------------------
336 # If the supplied text is empty, indicate this
337 # case and return.
338  
339 2 ▶ if ( $replacements_text_to_import !~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($replacements_text_to_import =~ /[^ ]/) 0 2 2
340 {
341 0 ▶ if ( $global_dashrep_replacement{ "dashrep-debug-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on") 0 0 0
342 {
343 0 print "{{trace; imported zero definitions from empty text}}\n" ;
344 }
345 0 return 0 ;
346 }
347  
348  
349 #-----------------------------------------------
350 # Reset the "ignore" and "capture" levels.
351  
352 2 $global_ignore_level = 0 ;
353 2 $global_capture_level = 0 ;
354  
355  
356 #-----------------------------------------------
357 # Initialization.
358  
359 2 @list_of_replacement_names = ( ) ;
360  
361  
362 #-----------------------------------------------
363 # Replace line breaks, and tabs, with spaces.
364  
365 2 $replacements_text_to_import =~ s/[\n\r\t]+/ /sg ;
366 2 $replacements_text_to_import =~ s/[\n\r\t]+/ /sg ;
367 2 $replacements_text_to_import =~ s/ +/ /sg ;
368  
369  
370 #-----------------------------------------------
371 # Ignore comments that consist of, or are embedded
372 # in, strings of the following types:
373 # *------ -------*
374 # /------ -------/
375  
376 2 $replacements_text_to_import =~ s/\*\-\-\-+\*/ /g ;
377 2 $replacements_text_to_import =~ s/\/\-\-\-+\// /g ;
378 2 ▶ while ( $replacements_text_to_import =~ /^(.*?)([\*\/]\-\-+)(.*)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($replacements_text_to_import =~ m[^(.*?)([\*/]\-\-+)(.*)$]) 6 2 8
379 {
380 6 $text_before = $1 ;
381 6 $global_dashrep_replacement{ "dashrep-comments-ignored" } .= " " . $2 ;
382 6 $text_including_comment_end = $3 ;
383 6 $text_after = "" ;
384 6 ▶ if ( $text_including_comment_end =~ /^(.*?\-\-+[\*\/])(.*)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($text_including_comment_end =~ m[^(.*?\-\-+[\*/])(.*)$]) 6 0 6
385 {
386 6 $global_dashrep_replacement{ "dashrep-comments-ignored" } .= $1 . " " ;
387 6 $text_after = $2 ;
388 }
389 6 $replacements_text_to_import = $text_before . " " . $text_after ;
390 }
391  
392  
393 #-----------------------------------------------
394 # Split the replacement text at spaces,
395 # and put the strings into an array.
396  
397 2 $replacements_text_to_import =~ s/ +/ /g ;
398 2 @list_of_replacement_strings = split( / / , $replacements_text_to_import ) ;
399  
400  
401 #-----------------------------------------------
402 # Read and handle each item in the array.
403  
404 2 $definition_name = "" ;
405 2 foreach $input_string ( @list_of_replacement_strings )
406 {
407 872 ▶ if ( $input_string =~ /^ *$/ )
Branch: 6 branches
BranchTrueFalseTotal
if ($input_string =~ /^ *$/) { } 1 871 872
elsif ($input_string eq 'define-begin') { } 0 871 871
elsif ($input_string eq 'dashrep-definitions-begin' or $input_string eq 'dashrep-definitions-end') { } 2 869 871
elsif ($input_string eq 'define-end' or $input_string =~ /^---+$/) { } 127 742 869
elsif ($definition_name eq '') { } 127 615 742
elsif ($input_string ne '') { } 615 0 615
408 {
409 1 $do_nothing ++ ;
410  
411  
412 #-----------------------------------------------
413 # Ignore the "define-begin" directive.
414  
415 } elsif ( $input_string eq 'define-begin' )
416 {
417 0 $do_nothing ++ ;
418  
419  
420 #-----------------------------------------------
421 # Ignore the "dashrep-definitions-begin" and
422 # "dashrep-definitions-end" directives.
423  
424 ▶ } elsif ( ( $input_string eq 'dashrep-definitions-begin' ) || ( $input_string eq 'dashrep-definitions-end' ) )
Condition100%3/3
$input_string eq "dashrep-definitions-begin" or $input_string eq "dashrep-definitions-end"
l!l&&r!l&&!r
11869
MC/DC100%2/2
$input_string eq "dashrep-definitions-begin" or $input_string eq "dashrep-definitions-end"
$input_string eq "dashrep-definitions-begin" $input_string eq "dashrep-definitions-end"
Truth table100%3/3
A or B
A= $input_string eq "dashrep-definitions-begin"B= $input_string eq "dashrep-definitions-end"
ABresult
1X1
011
000
425 {
426 2 $do_nothing ++ ;
427  
428  
429 #-----------------------------------------------
430 # When the "define-end" directive, or a series
431 # of at least 3 dashes ("--------"), is encountered,
432 # clear the definition name.
433 # Also remove trailing spaces from the previous
434 # replacement.
435  
436 ▶ } elsif ( ( $input_string eq 'define-end' ) || ( $input_string =~ /^---+$/ ) )
Condition66%2/3
$input_string eq "define-end" or $input_string =~ /^---+$/
l!l&&r!l&&!r
0127742
MC/DC50%1/2
$input_string eq "define-end" or $input_string =~ /^---+$/
$input_string eq "define-end" $input_string =~ /^---+$/
Truth table66%2/3
A or B
A= $input_string eq "define-end"B= $input_string =~ /^---+$/
ABresult
1X1
011
000
437 {
438 127 $definition_value = $global_dashrep_replacement{ $definition_name } ;
439 127 $definition_value =~ s/ +$// ;
440 127 ▶ if ( $definition_value =~ /[^ \n\r]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($definition_value =~ /[^ \n\r]/) { } 113 14 127
441 {
442 113 $global_dashrep_replacement{ $definition_name } = $definition_value ;
443 } else
444 {
445 14 $global_dashrep_replacement{ $definition_name } = "" ;
446 }
447 127 $definition_name = "" ;
448  
449  
450 #-----------------------------------------------
451 # Get a definition name.
452 # Allow a colon after the hyphenated name.
453 # If this definition name has already been defined,
454 # ignore the earlier definition.
455 # If the name does not contain a hyphen,
456 # prefix the name with "invalid-phrase-name-".
457  
458 } elsif ( $definition_name eq "" )
459 {
460 127 $definition_name = $input_string ;
461 127 $definition_name =~ s/\:$// ;
462 127 ▶ if ( $definition_name !~ /\-/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($definition_name =~ /\-/) 0 127 127
463 {
464 0 $definition_name = "invalid-phrase-name-" . $definition_name ;
465 }
466 127 $global_dashrep_replacement{ $definition_name } = "" ;
467 127 push( @list_of_replacement_names , $definition_name ) ;
468  
469  
470 #-----------------------------------------------
471 # Collect any text that is part of a definition.
472 # But do not allow the definition to include
473 # the name of the phrase being defined (because
474 # that would cause an endless loop when the
475 # phrase is replaced).
476  
477 } elsif ( $input_string ne "" )
478 {
479 615 ▶ if ( $input_string eq $definition_name )
Branch: 1 branch
BranchTrueFalseTotal
if ($input_string eq $definition_name) { } 0 615 615
480 {
481 0 $global_dashrep_replacement{ $definition_name } = "ERROR: Replacement for the hyphenated phrase:\n " . $definition_name . "\n" . "includes itself, which would cause an endless replacement loop." . "\n" ;
482 0 carp "Warning: Replacement for the hyphenated phrase:\n " . $definition_name . "\n" . "includes itself, which would cause an endless replacement loop.". "\n" . "Error occurred " ;
483 } else
484 {
485 615 ▶ if ( $global_dashrep_replacement{ $definition_name } ne "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{$definition_name} ne "") 502 113 615
486 {
487 502 $global_dashrep_replacement{ $definition_name } .= " " ;
488 }
489 615 $global_dashrep_replacement{ $definition_name } = $global_dashrep_replacement{ $definition_name } . $input_string ;
490 }
491 }
492  
493  
494 #-----------------------------------------------
495 # Repeat the loop for the next string.
496  
497 }
498  
499  
500 #-----------------------------------------------
501 # End of subroutine.
502  
503 2 return $#list_of_replacement_names + 1 ;
504  
505 }
506  
507  
508 =head2 dashrep_get_replacement
509  
510 Gets/returns the replacement text string that
511 is associated with the specified hyphenated
512 phrase.
513  
514 First, and only, parameter is the hyphenated
515 phrase.
516  
517 Return value is the replacement string that
518 is associated with the specified hyphenated
519 phrase. Return value is an empty string if
520 there is not exactly one parameter.
521  
522 =cut
523  
524 #-----------------------------------------------
525 #-----------------------------------------------
526 # dashrep_get_replacement
527 #-----------------------------------------------
528 #-----------------------------------------------
529  
530 sub dashrep_get_replacement
531 39 ▶{
Subroutine dashrep_get_replacement: called CC=4 SCAR=14.5
Pod documented
532  
533 39 my $phrase_name ;
534 my $expanded_text ;
535  
536  
537 #-----------------------------------------------
538 # Get the name of the hyphenated phrase.
539  
540 39 ▶ if ( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 39 0 39
541 {
542 39 $phrase_name = $_[ 0 ] ;
543 } else
544 {
545 0 $expanded_text = "" ;
546 0 return $expanded_text ;
547 }
548  
549  
550 #-----------------------------------------------
551 # Get the replacement text that is associated
552 # with the hyphenated phrase.
553  
554 39 ▶ if ( ( exists( $global_dashrep_replacement{ $phrase_name } ) ) && ( $global_dashrep_replacement{ $phrase_name } =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$phrase_name} and $global_dashrep_replacement{$phrase_name} =~ /[^ ]/) { } 36 3 39
Condition66%2/3
exists $global_dashrep_replacement{$phrase_name} and $global_dashrep_replacement{$phrase_name} =~ /[^ ]/
!ll&&!rl&&r
3036
MC/DC50%1/2
exists $global_dashrep_replacement{$phrase_name} and $global_dashrep_replacement{$phrase_name} =~ /[^ ]/
exists $global_dashrep_replacement{$phrase_name} $global_dashrep_replacement{$phrase_name} =~ /[^ ]/
Truth table66%2/3
A and B
A= exists $global_dashrep_replacement{$phrase_name}B= $global_dashrep_replacement{$phrase_name} =~ /[^ ]/
ABresult
0X0
100
111
555 {
556 36 $expanded_text = $global_dashrep_replacement{ $phrase_name } ;
557 } else
558 {
559 3 $expanded_text = "" ;
560 }
561  
562  
563 #-----------------------------------------------
564 # End of subroutine.
565  
566 39 return $expanded_text ;
567  
568 }
569  
570  
571 =head2 dashrep_get_list_of_phrases
572  
573 Returns an array that lists all the
574 hyphenated phrases that have been defined
575 so far.
576  
577 There are no parameters.
578  
579 Return value is an array that lists all the
580 hyphenated phrases that have been defined.
581 Return value is an empty array if there is
582 not exactly zero parameters.
583  
584 =cut
585  
586 #-----------------------------------------------
587 #-----------------------------------------------
588 # dashrep_get_list_of_phrases
589 #-----------------------------------------------
590 #-----------------------------------------------
591  
592 sub dashrep_get_list_of_phrases
593 3 ▶{
Subroutine dashrep_get_list_of_phrases: called CC=2 SCAR=8.5
Pod documented
594  
595 3 my @list_of_phrases ;
596  
597 3 ▶ if ( scalar( @_ ) != 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ != 0) 0 3 3
598 {
599 0 carp "Warning: Call to dashrep_define subroutine does not have exactly zero parameters." ;
600 0 @list_of_phrases = ( ) ;
601 0 return @list_of_phrases ;
602 }
603  
604 3 @list_of_phrases = keys( %global_dashrep_replacement ) ;
605 3 return @list_of_phrases ;
606  
607 }
608  
609  
610 =head2 dashrep_delete
611  
612 Deletes the specified hyphenated phrase.
613  
614 First parameter is the hyphenated phrase.
615  
616 Return value is 1 if the deletion is
617 successful. Return value is zero if there
618 is not exactly one parameter.
619  
620 =cut
621  
622 #-----------------------------------------------
623 #-----------------------------------------------
624 # dashrep_delete
625 #-----------------------------------------------
626 #-----------------------------------------------
627  
628 sub dashrep_delete
629 1 ▶{
Subroutine dashrep_delete: called CC=2 SCAR=7.3
Pod documented
630  
631 1 my $phrase_name ;
632  
633  
634 #-----------------------------------------------
635 # Delete the indicated phrase.
636  
637 1 ▶ if ( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 1 0 1
638 {
639 1 $phrase_name = $_[ 0 ] ;
640 1 $phrase_name =~ s/^ +// ;
641 1 $phrase_name =~ s/ +$// ;
642 1 delete( $global_dashrep_replacement{ $phrase_name } );
643 } else
644 {
645 0 carp "Warning: Call to dashrep_delete subroutine does not have exactly one parameter." ;
646 0 return 0 ;
647 }
648  
649  
650 #-----------------------------------------------
651 # End of subroutine.
652  
653 1 return 1 ;
654  
655 }
656  
657  
658 =head2 dashrep_delete_all
659  
660 Deletes all the hyphenated phrases.
661  
662 There are no parameters.
663  
664 Return value is 1 if the deletion is
665 successful. Return value is zero if there
666 is not exactly zero parameters.
667  
668 =cut
669  
670 #-----------------------------------------------
671 #-----------------------------------------------
672 # dashrep_delete_all
673 #-----------------------------------------------
674 #-----------------------------------------------
675  
676 sub dashrep_delete_all
677 1 ▶{
Subroutine dashrep_delete_all: called CC=2 SCAR=7.2
Pod documented
678  
679  
680 #-----------------------------------------------
681 # Reset the "ignore" and "capture" levels.
682  
683 1 $global_ignore_level = 0 ;
684 1 $global_capture_level = 0 ;
685  
686  
687 #-----------------------------------------------
688 # Reset the xml-parsing state.
689  
690 1 $global_xml_level_number = 0 ;
691 1 @global_xml_tag_at_level_number = ( ) ;
692  
693  
694 #-----------------------------------------------
695 # Delete all the phrases.
696  
697 1 ▶ if ( scalar( @_ ) == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 0) { } 1 0 1
698 {
699 1 %global_dashrep_replacement = ( );
700 1 &initialize_special_phrases( ) ;
701 } else
702 {
703 0 carp "Warning: Call to dashrep_delete_all subroutine does not have exactly zero parameters." ;
704 0 return 0 ;
705 }
706  
707  
708 #-----------------------------------------------
709 # End of subroutine.
710  
711 1 return 1 ;
712  
713 }
714  
715  
716 =head2 dashrep_expand_parameters
717  
718 Parses a text string that is written in the
719 Dashrep language and handles parameter
720 replacements and special operations. The
721 special operations must be within
722 "[- ... -]" text strings.
723 If the supplied text string is just a
724 hyphenated phrase, it is expanded to its
725 replacement string. Otherwise, any
726 hyphenated phrase that does not appear
727 within the square-bracket pattern is
728 not replaced. (Those hyphenated phrases
729 must be replaced using either the
730 dashrep_expand_phrases,
731 dashrep_expand_phrases_except_special,
732 or dashrep_expand_special_phrases subroutines.)
733  
734 First, and only, parameter is the text -- or
735 hyphenated phrase -- that is to be expanded.
736  
737 Return value is the text after expanding
738 any parameters. Return value is an empty
739 string if there is not exactly one parameter.
740  
741 =cut
742  
743 #-----------------------------------------------
744 #-----------------------------------------------
745 # dashrep_expand_parameters
746 #-----------------------------------------------
747 #-----------------------------------------------
748  
749 sub dashrep_expand_parameters
750 99 ▶{
Subroutine dashrep_expand_parameters: called CC=74 SCAR=52.4
Pod documented
751  
752 99 my $supplied_text ;
753 my $replacement_text ;
754 99 my $loop_status_done ;
755 99 my $text_begin ;
756 99 my $text_parameter_name ;
757 99 my $text_parameter_value ;
758 99 my $text_end ;
759 99 my $action_name ;
760 99 my $object_of_action ;
761 99 my $count ;
762 99 my $zero_one_multiple ;
763 99 my $empty_or_nonempty ;
764 99 my $full_length ;
765 99 my $length_half ;
766 99 my $string_beginning ;
767 99 my $string_end ;
768 99 my $same_or_not_same ;
769 99 my $sorted_numbers ;
770 99 my $text_parameter_placeholder ;
771 99 my $text_parameter ;
772 99 my $name_for_count ;
773 99 my $text_for_value ;
774 99 my $possible_new_limit ;
775 99 my $text_parameter_content ;
776 99 my $source_phrase ;
777 99 my $target_phrase ;
778 99 my $comparison_type ;
779 99 my $first_number_text ;
780 99 my $second_number_text ;
781 99 my $first_number ;
782 99 my $second_number ;
783 99 my $yes_or_no ;
784 99 my $first_object_of_action ;
785 99 my $second_object_of_action ;
786 99 my @list ;
787 99 my @list_of_sorted_numbers ;
788 99 my @list_of_replacements_to_auto_increment ;
789  
790  
791 #-----------------------------------------------
792 # Get the hyphenated phrase or supplied string.
793  
794 99 ▶ if ( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 99 0 99
795 {
796 99 $supplied_text = $_[ 0 ] ;
797 } else
798 {
799 0 $replacement_text = "" ;
800 0 return $replacement_text ;
801 }
802  
803  
804 #-----------------------------------------------
805 # Use the supplied text as the default result,
806 # without leading or trailing spaces.
807  
808 99 $replacement_text = $supplied_text ;
809 99 $replacement_text =~ s/^ +//sg;
810 99 $replacement_text =~ s/ +$//sg;
811  
812  
813 #-----------------------------------------------
814 # If just a hyphenated phrase was supplied,
815 # expand it into its replacement text.
816  
817 99 ▶ if ( $supplied_text =~ /^ *([^\- ]+-[^ ]*[^\- ]) *$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($supplied_text =~ /^ *([^\- ]+-[^ ]*[^\- ]) *$/) 98 1 99
818 {
819 98 $supplied_text = $1 ;
820 98 ▶ if ( ( exists( $global_dashrep_replacement{ $supplied_text } ) ) && ( $global_dashrep_replacement{ $supplied_text } =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$supplied_text} and $global_dashrep_replacement{$supplied_text} =~ /[^ ]/) 68 30 98
Condition66%2/3
exists $global_dashrep_replacement{$supplied_text} and $global_dashrep_replacement{$supplied_text} =~ /[^ ]/
!ll&&!rl&&r
03068
MC/DC50%1/2
exists $global_dashrep_replacement{$supplied_text} and $global_dashrep_replacement{$supplied_text} =~ /[^ ]/
exists $global_dashrep_replacement{$supplied_text} $global_dashrep_replacement{$supplied_text} =~ /[^ ]/
Truth table66%2/3
A and B
A= exists $global_dashrep_replacement{$supplied_text}B= $global_dashrep_replacement{$supplied_text} =~ /[^ ]/
ABresult
0X0
100
111
821 {
822 68 $replacement_text = $global_dashrep_replacement{ $supplied_text } ;
823 }
824 }
825  
826  
827 #-----------------------------------------------
828 # Initialize the list of replacement names
829 # encountered that need to be auto-incremented.
830  
831 99 @list_of_replacements_to_auto_increment = ( ) ;
832  
833  
834 #-----------------------------------------------
835 # Update the endless loop count limit in case
836 # it has changed.
837  
838 99 ▶ if ( $global_dashrep_replacement{ "dashrep-endless-loop-counter-limit" } =~ /^[0-9]+$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-endless-loop-counter-limit"} =~ /^[0-9]+$/) 0 99 99
839 {
840 0 $possible_new_limit = $global_dashrep_replacement{ "dashrep-endless-loop-counter-limit" } + 0 ;
841 0 ▶ if ( ( $possible_new_limit != $global_endless_loop_counter_limit ) && ( $possible_new_limit > 1000 ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_new_limit != $global_endless_loop_counter_limit and $possible_new_limit > 1000) 0 0 0
Condition0%0/3
$possible_new_limit != $global_endless_loop_counter_limit and $possible_new_limit > 1000
!ll&&!rl&&r
000
MC/DC0%0/2
$possible_new_limit != $global_endless_loop_counter_limit and $possible_new_limit > 1000
$possible_new_limit != $global_endless_loop_counter_limit $possible_new_limit > 1000
Truth table0%0/3
A and B
A= $possible_new_limit != $global_endless_loop_counter_limitB= $possible_new_limit > 1000
ABresult
0X0
100
111
842 {
843 0 $global_endless_loop_counter_limit = $possible_new_limit ;
844 0 ▶ if ( ( $global_dashrep_replacement{ "dashrep-debug-trace-on-or-off" } eq "on" ) && ( $replacement_text =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on" and $replacement_text =~ /[^ ]/) 0 0 0
Condition0%0/3
$global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on" and $replacement_text =~ /[^ ]/
!ll&&!rl&&r
000
MC/DC0%0/2
$global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on" and $replacement_text =~ /[^ ]/
$global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on" $replacement_text =~ /[^ ]/
Truth table0%0/3
A and B
A= $global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on"B= $replacement_text =~ /[^ ]/
ABresult
0X0
100
111
845 {
846 0 print "{{trace; updated endless loop counter limit: " . $possible_new_limit . "}}\n";
847 }
848 }
849 }
850  
851  
852 #-----------------------------------------------
853 # Begin a loop that repeats until there have
854 # been no more replacements.
855  
856 99 $loop_status_done = $global_false ;
857 99 ▶ while ( $loop_status_done == $global_false )
Branch: 1 branch
BranchTrueFalseTotal
if ($loop_status_done == $global_false) 247 99 346
858 {
859 247 $loop_status_done = $global_true ;
860  
861 247 ▶ if ( ( $global_dashrep_replacement{ "dashrep-debug-trace-on-or-off" } eq "on" ) && ( $replacement_text =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on" and $replacement_text =~ /[^ ]/) 0 247 247
Condition33%1/3
$global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on" and $replacement_text =~ /[^ ]/
!ll&&!rl&&r
24700
MC/DC0%0/2
$global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on" and $replacement_text =~ /[^ ]/
$global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on" $replacement_text =~ /[^ ]/
Truth table33%1/3
A and B
A= $global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on"B= $replacement_text =~ /[^ ]/
ABresult
0X0
100
111
862 {
863 0 print "{{trace; replacement string: " . $replacement_text . "}}\n";
864 }
865  
866  
867 #-----------------------------------------------
868 # Get the next inner-most parameter syntax --
869 # with "[-" at the beginning and "-]" at the end.
870 # (It must not contain a nested parameter syntax.)
871  
872 247 ▶ if ( $replacement_text =~ /^(.*?)\[\-([^\[\]]*)\-\](.*)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($replacement_text =~ /^(.*?)\[\-([^\[\]]*)\-\](.*)$/) 148 99 247
873 {
874 148 $text_begin = $1 ;
875 148 $text_parameter_content = $2 ;
876 148 $text_end = $3 ;
877 148 $text_parameter_content =~ s/^ +// ;
878 148 $text_parameter_content =~ s/ +$// ;
879 148 $loop_status_done = $global_false ;
880  
881 148 ▶ if ( ( $global_dashrep_replacement{ "dashrep-debug-trace-on-or-off" } eq "on" ) && ( $text_parameter_content =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on" and $text_parameter_content =~ /[^ ]/) 0 148 148
Condition33%1/3
$global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on" and $text_parameter_content =~ /[^ ]/
!ll&&!rl&&r
14800
MC/DC0%0/2
$global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on" and $text_parameter_content =~ /[^ ]/
$global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on" $text_parameter_content =~ /[^ ]/
Truth table33%1/3
A and B
A= $global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on"B= $text_parameter_content =~ /[^ ]/
ABresult
0X0
100
111
882 {
883 0 print "{{trace; innermost parameter: " . $text_parameter_content . "}}\n";
884 }
885  
886  
887 #-----------------------------------------------
888 # If the parameter is a defined phrase, do the
889 # replacement.
890  
891 148 ▶ if ( ( $text_parameter_content !~ / / ) && ( exists( $global_dashrep_replacement{ $text_parameter_content } ) ) )
Branch: 5 branches
BranchTrueFalseTotal
if (not $text_parameter_content =~ / / and exists $global_dashrep_replacement{$text_parameter_content}) { } 86 62 148
elsif ($text_parameter_content =~ /^ *([^ \n\:=]+) *= *([^ \n\:=]+) *$/) { } 28 34 62
elsif ($text_parameter_content =~ /^append-from-phrase-to-phrase *: *([^\n\:=]*) +([^\n\:=]*)$/) { } 0 34 34
elsif ($text_parameter_content =~ /^(yes-or-no-first-number-((equals)|(greater-than)|(less-than))-second-number) *: *([0-9\,]+) +([0-9\,]+)$/) { } 6 28 34
elsif ($text_parameter_content =~ /^([^ \n\:=]+-[^ \n\:=]+) *[: ] *([^\n\:=]*)$/) { } 25 3 28
Condition100%3/3
not $text_parameter_content =~ / / and exists $global_dashrep_replacement{$text_parameter_content}
!ll&&!rl&&r
56686
MC/DC100%2/2
not $text_parameter_content =~ / / and exists $global_dashrep_replacement{$text_parameter_content}
not $text_parameter_content =~ / / exists $global_dashrep_replacement{$text_parameter_content}
Truth table100%3/3
not(A) and B
A= not $text_parameter_content =~ / /B= exists $global_dashrep_replacement{$text_parameter_content}
ABresult
0X0
100
111
892 {
893 86 $text_parameter = $global_dashrep_replacement{ $text_parameter_content } ;
894 86 ▶ if ( $text_parameter =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($text_parameter =~ /[^ ]/) { } 86 0 86
895 {
896 86 $replacement_text = $text_begin . $text_parameter . $text_end ;
897 86 $global_replacement_count_for_item_name{ $text_parameter_content } ++ ;
898 86 $loop_status_done = $global_false ;
899 86 ▶ if ( $text_parameter_content =~ /^auto-increment-/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($text_parameter_content =~ /^auto-increment-/) 0 86 86
900 {
901 0 push( @list_of_replacements_to_auto_increment , $text_parameter_content ) ;
902 }
903 } else
904 {
905 0 $replacement_text = $text_begin . " " . $text_end ;
906 0 $loop_status_done = $global_false ;
907 }
908  
909  
910 #-----------------------------------------------
911 # If there is a parameter value assigned -- as
912 # indicated by an equal sign -- then assign
913 # the value.
914 #
915 # Problems will arise if the parameter value
916 # contains a space, bracket, colon, or equal
917 # sign, but in those cases just specify a
918 # replacement name instead of the value of
919 # that replacement.
920  
921 } elsif ( $text_parameter_content =~ /^ *([^ \n\:=]+) *= *([^ \n\:=]+) *$/ )
922 {
923 28 $text_parameter_name = $1 ;
924 28 $text_parameter_value = $2 ;
925 28 $text_parameter_value =~ s/[\- ]+$// ;
926 28 ▶ if ( length( $text_parameter_name ) > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (length $text_parameter_name > 0) 28 0 28
927 {
928 28 $global_dashrep_replacement{ $text_parameter_name } = $text_parameter_value ;
929 28 $global_replacement_count_for_item_name{ $text_parameter_name } ++ ;
930 }
931 28 $replacement_text = $text_begin . " " . $text_end ;
932 28 $global_replacement_count_for_item_name{ $text_parameter_value } ++ ;
933 28 ▶ if ( ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" ) && ( $text_parameter_name =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" and $text_parameter_name =~ /[^ ]/) 0 28 28
Condition33%1/3
$global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" and $text_parameter_name =~ /[^ ]/
!ll&&!rl&&r
2800
MC/DC0%0/2
$global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" and $text_parameter_name =~ /[^ ]/
$global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" $text_parameter_name =~ /[^ ]/
Truth table33%1/3
A and B
A= $global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on"B= $text_parameter_name =~ /[^ ]/
ABresult
0X0
100
111
934 {
935 0 print "{{trace; assignment: " . $text_parameter_name . " = " . $text_parameter_value . "}}\n";
936 }
937  
938  
939 #-----------------------------------------------
940 # Handle the two-operand action:
941 # append-from-phrase-to-phrase
942  
943 } elsif ( $text_parameter_content =~ /^append-from-phrase-to-phrase *: *([^\n\:=]*) +([^\n\:=]*)$/ )
944 {
945 0 $source_phrase = $1 ;
946 0 $target_phrase = $2 ;
947 0 $global_dashrep_replacement{ $target_phrase } .= " " . $global_dashrep_replacement{ $source_phrase } ;
948 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
949 {
950 0 print "{{trace; appended from phrase " . $source_phrase . " to phrase " . $target_phrase . "}}\n" ;
951 }
952 0 $replacement_text = $text_begin . " " . $text_end ;
953  
954  
955 #-----------------------------------------------
956 # Handle these two-operand actions:
957 # yes-or-no-first-number-equals-second-number
958 # yes-or-no-first-number-greater-than-second-number
959 # yes-or-no-first-number-less-than-second-number
960  
961 } elsif ( $text_parameter_content =~ /^(yes-or-no-first-number-((equals)|(greater-than)|(less-than))-second-number) *: *([0-9\,]+) +([0-9\,]+)$/ )
962 {
963 6 $comparison_type = $2 ;
964 6 $first_number_text = $6 ;
965 6 $second_number_text = $7 ;
966 6 $first_number = $first_number_text + 0 ;
967 6 $second_number = $second_number_text + 0 ;
968 6 ▶ if ( ( $comparison_type eq "equals" ) && ( $first_number == $second_number ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($comparison_type eq 'equals' and $first_number == $second_number) { } 1 5 6
elsif ($comparison_type eq 'greater-than' and $first_number > $second_number) { } 1 4 5
elsif ($comparison_type eq 'less-than' and $first_number < $second_number) { } 1 3 4
Condition100%3/3
$comparison_type eq "equals" and $first_number == $second_number
!ll&&!rl&&r
411
MC/DC100%2/2
$comparison_type eq "equals" and $first_number == $second_number
$comparison_type eq "equals" $first_number == $second_number
Truth table100%3/3
A and B
A= $comparison_type eq "equals"B= $first_number == $second_number
ABresult
0X0
100
111
969 {
970 1 $yes_or_no = "yes" ;
971 ▶ } elsif ( ( $comparison_type eq "greater-than" ) && ( $first_number > $second_number ) )
Condition100%3/3
$comparison_type eq "greater-than" and $first_number > $second_number
!ll&&!rl&&r
311
MC/DC100%2/2
$comparison_type eq "greater-than" and $first_number > $second_number
$comparison_type eq "greater-than" $first_number > $second_number
Truth table100%3/3
A and B
A= $comparison_type eq "greater-than"B= $first_number > $second_number
ABresult
0X0
100
111
972 {
973 1 $yes_or_no = "yes" ;
974 ▶ } elsif ( ( $comparison_type eq "less-than" ) && ( $first_number < $second_number ) )
Condition100%3/3
$comparison_type eq "less-than" and $first_number < $second_number
!ll&&!rl&&r
211
MC/DC100%2/2
$comparison_type eq "less-than" and $first_number < $second_number
$comparison_type eq "less-than" $first_number < $second_number
Truth table100%3/3
A and B
A= $comparison_type eq "less-than"B= $first_number < $second_number
ABresult
0X0
100
111
975 {
976 1 $yes_or_no = "yes" ;
977 } else
978 {
979 3 $yes_or_no = "no" ;
980 }
981 6 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 6 6
982 {
983 0 print "{{trace; comparison of type " . $comparison_type . " for numbers " . $first_number_text . " and " . $second_number_text . "}}\n" ;
984 }
985 6 $replacement_text = $text_begin . $yes_or_no . $text_end ;
986  
987  
988 #-----------------------------------------------
989 # If there is an action requested (which
990 # may include a colon between the action and
991 # its operand(s), handle it.
992  
993 } elsif ( $text_parameter_content =~ /^([^ \n\:=]+-[^ \n\:=]+) *[: ] *([^\n\:=]*)$/ )
994 {
995 25 $action_name = $1 ;
996 25 $object_of_action = $2 ;
997 25 $object_of_action =~ s/\-+$// ;
998 25 $object_of_action =~ s/^ +// ;
999 25 $object_of_action =~ s/ +$// ;
1000 25 ▶ if ( $object_of_action =~ /^([^ ]+) +(.+)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($object_of_action =~ /^([^ ]+) +(.+)$/) 0 25 25
1001 {
1002 0 $first_object_of_action = $1 ;
1003 0 $second_object_of_action = $2 ;
1004 }
1005  
1006 25 ▶ if ( ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" ) && ( $action_name =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" and $action_name =~ /[^ ]/) 0 25 25
Condition33%1/3
$global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" and $action_name =~ /[^ ]/
!ll&&!rl&&r
2500
MC/DC0%0/2
$global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" and $action_name =~ /[^ ]/
$global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" $action_name =~ /[^ ]/
Truth table33%1/3
A and B
A= $global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on"B= $action_name =~ /[^ ]/
ABresult
0X0
100
111
1007 {
1008 0 print "{{trace; action and object: " . $action_name . " : " . $object_of_action . "}}\n";
1009 }
1010  
1011  
1012 #-----------------------------------------------
1013 # Handle the action:
1014 # first-item-in-list
1015  
1016 25 ▶ if ( $action_name eq "first-item-in-list" )
Branch: 13 branches
BranchTrueFalseTotal
if ($action_name eq 'first-item-in-list') { } 1 24 25
elsif ($action_name eq 'last-item-in-list') { } 1 23 24
elsif ($action_name eq 'count-of-list') { } 3 20 23
elsif ($action_name eq 'zero-one-multiple-count-of-list') { } 3 17 20
elsif ($action_name eq 'zero-one-multiple') { } 3 14 17
elsif ($action_name eq 'empty-or-nonempty') { } 2 12 14
elsif ($action_name eq 'empty-or-nonempty-phrase') { } 0 12 12
elsif ($action_name eq 'same-or-not-same') { } 3 9 12
elsif ($action_name eq 'sort-numbers') { } 1 8 9
elsif ($action_name eq 'unique-value') { } 3 5 8
elsif ($action_name eq 'auto-increment') { } 3 2 5
elsif ($action_name eq 'create-list-named') { } 2 0 2
elsif ($action_name eq 'insert-phrase-with-brackets-after-next-top-line') { } 0 0 0
1017 {
1018 1 @list = &dashrep_internal_split_delimited_items( $object_of_action ) ;
1019 1 $count = $#list + 1 ;
1020 1 $text_for_value = " " ;
1021 1 ▶ if ( $count > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 0) 1 0 1
1022 {
1023 1 $text_for_value = $list[ 0 ] ;
1024 }
1025 1 $replacement_text = $text_begin . $text_for_value . $text_end ;
1026  
1027  
1028 #-----------------------------------------------
1029 # Handle the action:
1030 # last-item-in-list
1031  
1032 } elsif ( $action_name eq "last-item-in-list" )
1033 {
1034 1 @list = &dashrep_internal_split_delimited_items( $object_of_action ) ;
1035 1 $count = $#list + 1 ;
1036 1 $text_for_value = " " ;
1037 1 ▶ if ( $count > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 0) 1 0 1
1038 {
1039 1 $text_for_value = $list[ $#list ] ;
1040 }
1041 1 $replacement_text = $text_begin . $text_for_value . $text_end ;
1042  
1043  
1044 #-----------------------------------------------
1045 # Handle the action:
1046 # count-of-list
1047  
1048 } elsif ( $action_name eq "count-of-list" )
1049 {
1050 3 ▶ if ( $object_of_action =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($object_of_action =~ /[^ ]/) { } 2 1 3
1051 {
1052 2 @list = &dashrep_internal_split_delimited_items( $object_of_action ) ;
1053 2 $count = $#list + 1 ;
1054 2 ▶ if ( $count > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 0) { } 2 0 2
1055 {
1056 2 $text_for_value = $count ;
1057 } else
1058 {
1059 0 $text_for_value = "0" ;
1060 }
1061 } else
1062 {
1063 1 $text_for_value = "0" ;
1064 }
1065 3 $replacement_text = $text_begin . $text_for_value . $text_end ;
1066  
1067  
1068 #-----------------------------------------------
1069 # Handle the action:
1070 # zero-one-multiple-count-of-list
1071  
1072 } elsif ( $action_name eq "zero-one-multiple-count-of-list" )
1073 {
1074 3 ▶ if ( $object_of_action =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($object_of_action =~ /[^ ]/) { } 2 1 3
1075 {
1076 2 @list = &dashrep_internal_split_delimited_items( $object_of_action ) ;
1077 2 $count = $#list + 1 ;
1078 2 ▶ if ( $count == 0 )
Branch: 3 branches
BranchTrueFalseTotal
if ($count == 0) { } 0 2 2
elsif ($count == 1) { } 1 1 2
elsif ($count > 1) { } 1 0 1
1079 {
1080 0 $name_for_count = "zero" ;
1081 } elsif ( $count == 1 )
1082 {
1083 1 $name_for_count = "one" ;
1084 } elsif ( $count > 1 )
1085 {
1086 1 $name_for_count = "multiple" ;
1087 }
1088 } else
1089 {
1090 1 $name_for_count = "zero" ;
1091 }
1092 3 $replacement_text = $text_begin . $name_for_count . $text_end ;
1093  
1094  
1095 #-----------------------------------------------
1096 # Handle the action:
1097 # zero-one-multiple
1098  
1099 } elsif ( $action_name eq "zero-one-multiple" )
1100 {
1101 3 ▶ if ( $object_of_action + 0 <= 0 )
Branch: 2 branches
BranchTrueFalseTotal
if ($object_of_action + 0 <= 0) { } 1 2 3
elsif ($object_of_action + 0 == 1) { } 1 1 2
1102 {
1103 1 $zero_one_multiple = "zero" ;
1104 } elsif ( $object_of_action + 0 == 1 )
1105 {
1106 1 $zero_one_multiple = "one" ;
1107 } else
1108 {
1109 1 $zero_one_multiple = "multiple" ;
1110 }
1111 3 $replacement_text = $text_begin . $zero_one_multiple . $text_end ;
1112  
1113  
1114 #-----------------------------------------------
1115 # Handle the action:
1116 # empty-or-nonempty
1117  
1118 } elsif ( $action_name eq "empty-or-nonempty" )
1119 {
1120 2 ▶ if ( $object_of_action =~ /[^ \n\t]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($object_of_action =~ /[^ \n\t]/) { } 1 1 2
1121 {
1122 1 $empty_or_nonempty = "nonempty" ;
1123 } else
1124 {
1125 1 $empty_or_nonempty = "empty" ;
1126 }
1127 2 $replacement_text = $text_begin . $empty_or_nonempty . $text_end ;
1128  
1129  
1130 #-----------------------------------------------
1131 # Handle the action:
1132 # empty-or-nonempty-phrase
1133  
1134 } elsif ( $action_name eq "empty-or-nonempty-phrase" )
1135 {
1136 0 $empty_or_nonempty = "empty" ;
1137 0 ▶ if ( $object_of_action =~ /[^ \n\t]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($object_of_action =~ /[^ \n\t]/) 0 0 0
1138 {
1139 0 ▶ if ( exists( $global_dashrep_replacement{ $object_of_action } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$object_of_action}) 0 0 0
1140 {
1141 0 ▶ if ( $global_dashrep_replacement{ $object_of_action } =~ /[^ \n\t]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{$object_of_action} =~ /[^ \n\t]/) 0 0 0
1142 {
1143 0 $empty_or_nonempty = "nonempty" ;
1144 }
1145 }
1146 }
1147 0 $replacement_text = $text_begin . $empty_or_nonempty . $text_end ;
1148  
1149  
1150 #-----------------------------------------------
1151 # Handle the action:
1152 # same-or-not-same
1153  
1154 } elsif ( $action_name eq "same-or-not-same" )
1155 {
1156 3 $full_length = length( $object_of_action ) ;
1157 3 $length_half = int( $full_length / 2 ) ;
1158 3 $string_beginning = substr( $object_of_action , 0 , $length_half ) ;
1159 3 $string_end = substr( $object_of_action , $full_length - $length_half , $length_half ) ;
1160 3 ▶ if ( $string_beginning eq $string_end )
Branch: 1 branch
BranchTrueFalseTotal
if ($string_beginning eq $string_end) { } 1 2 3
1161 {
1162 1 $same_or_not_same = "same" ;
1163 } else
1164 {
1165 2 $same_or_not_same = "not-same" ;
1166 }
1167 3 $replacement_text = $text_begin . $same_or_not_same . $text_end ;
1168  
1169  
1170 #-----------------------------------------------
1171 # Handle the action:
1172 # sort-numbers
1173  
1174 } elsif ( $action_name eq "sort-numbers" )
1175 {
1176 1 ▶ if ( $object_of_action =~ /[1-9]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($object_of_action =~ /[1-9]/) { } 1 0 1
1177 {
1178 1 $object_of_action =~ s/ +/,/gs ;
1179 1 $object_of_action =~ s/^,// ;
1180 1 $object_of_action =~ s/,$// ;
1181 1 @list = split( /,+/ , $object_of_action ) ;
1182 1 @list_of_sorted_numbers = sort { $a <=> $b } @list ;
1183 1 $sorted_numbers = join( "," , @list_of_sorted_numbers ) ;
1184 } else
1185 {
1186 0 $sorted_numbers = " " ;
1187 }
1188 1 $replacement_text = $text_begin . $sorted_numbers . $text_end ;
1189  
1190  
1191 #-----------------------------------------------
1192 # Handle the action:
1193 # unique-value
1194 #
1195 # Currently this action is equivalent to the
1196 # auto-increment action.
1197 # It can be changed to accomodate a
1198 # parallel-processing environment where the
1199 # code here would assign values from separate
1200 # blocks of numbers assigned to each
1201 # processor/process.
1202  
1203 } elsif ( $action_name eq "unique-value" )
1204 {
1205 3 ▶ if ( exists( $global_dashrep_replacement{ $object_of_action } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$object_of_action}) { } 2 1 3
1206 {
1207 2 $global_dashrep_replacement{ $object_of_action } = $global_dashrep_replacement{ $object_of_action } + 1 ;
1208 } else
1209 {
1210 1 $global_dashrep_replacement{ $object_of_action } = 1 ;
1211 }
1212 3 $replacement_text = $text_begin . " " . $text_end ;
1213  
1214  
1215 #-----------------------------------------------
1216 # Handle the action:
1217 # auto-increment
1218  
1219 } elsif ( $action_name eq "auto-increment" )
1220 {
1221 3 ▶ if ( exists( $global_dashrep_replacement{ $object_of_action } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$object_of_action}) { } 2 1 3
1222 {
1223 2 $global_dashrep_replacement{ $object_of_action } = $global_dashrep_replacement{ $object_of_action } + 1 ;
1224 } else
1225 {
1226 1 $global_dashrep_replacement{ $object_of_action } = 1 ;
1227 }
1228 3 $replacement_text = $text_begin . " " . $text_end ;
1229  
1230  
1231 #-----------------------------------------------
1232 # Handle the action:
1233 # create-list-named
1234  
1235 } elsif ( $action_name eq "create-list-named" )
1236 {
1237 2 push ( @global_list_of_lists_to_generate , $object_of_action ) ;
1238 2 $replacement_text = $text_begin . " " . $text_end ;
1239  
1240  
1241 #-----------------------------------------------
1242 # Handle the action:
1243 # insert-phrase-with-brackets-after-next-top-line
1244 # For now, just get the phrase name.
1245  
1246 } elsif ( $action_name eq "insert-phrase-with-brackets-after-next-top-line" )
1247 {
1248 0 $global_phrase_to_insert_after_next_top_level_line = $object_of_action ;
1249 0 $global_top_line_count_for_insert_phrase = 1 ;
1250 0 $replacement_text = $text_begin . " " . $text_end ;
1251 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
1252 {
1253 0 print "{{trace; got phrase to insert after next line: " . $global_phrase_to_insert_after_next_top_level_line . "}}\n" ;
1254 }
1255  
1256  
1257 #-----------------------------------------------
1258 # Terminate the branching that handles a
1259 # parameter that looks like it might begin with
1260 # an action name, but doesn't. Just leave the
1261 # text unchanged, but remove the "[-" and "-]"
1262 # strings.
1263  
1264 } else
1265 {
1266 0 ▶ if ( ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" ) && ( $action_name =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" and $action_name =~ /[^ ]/) 0 0 0
Condition0%0/3
$global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" and $action_name =~ /[^ ]/
!ll&&!rl&&r
000
MC/DC0%0/2
$global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" and $action_name =~ /[^ ]/
$global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" $action_name =~ /[^ ]/
Truth table0%0/3
A and B
A= $global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on"B= $action_name =~ /[^ ]/
ABresult
0X0
100
111
1267 {
1268 0 print "{{trace; action not recognized: " . $action_name . "}}\n";
1269 }
1270 0 $replacement_text = $text_begin . " " . $text_parameter_content . " " . $text_end ;
1271 }
1272  
1273  
1274 #-----------------------------------------------
1275 # If the parameter content has not been
1276 # recognized, simply remove the "[-" and "-]"
1277 # strings.
1278  
1279 } else
1280 {
1281 3 $replacement_text = $text_begin . $text_parameter_content . $text_end ;
1282 }
1283  
1284  
1285 #-----------------------------------------------
1286 # Avoid an endless loop (caused by a replacement
1287 # containing, at some level, itself).
1288  
1289 148 $global_endless_loop_counter ++ ;
1290 148 ▶ if ( $global_endless_loop_counter > $global_endless_loop_counter_limit )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_endless_loop_counter > $global_endless_loop_counter_limit) 0 148 148
1291 {
1292 0 &dashrep_internal_endless_loop_info( ) ;
1293 0 die "Error: The dashrep_expand_parameters subroutine encountered an endless loop." . "\n" . "Stopped" ;
1294 }
1295  
1296  
1297 #-----------------------------------------------
1298 # Repeat the loop that gets the next inner-most
1299 # parameter syntax.
1300  
1301 }
1302  
1303  
1304 #-----------------------------------------------
1305 # Repeat the loop that repeats until no
1306 # replacement was done.
1307  
1308 }
1309  
1310  
1311 #-----------------------------------------------
1312 # For each encountered replacement that begins
1313 # with "auto-increment-", increment its value.
1314  
1315 99 foreach $text_parameter_placeholder ( @list_of_replacements_to_auto_increment )
1316 {
1317 0 $global_dashrep_replacement{ $text_parameter_placeholder } ++ ;
1318 }
1319 99 @list_of_replacements_to_auto_increment = ( ) ;
1320  
1321  
1322 #-----------------------------------------------
1323 # Return the revised text.
1324  
1325 99 return $replacement_text ;
1326  
1327  
1328 #-----------------------------------------------
1329 # End of subroutine.
1330  
1331 }
1332  
1333  
1334 =head2 dashrep_generate_lists
1335  
1336 Internal subroutine, not exported.
1337 It is only needed within the Dashrep module.
1338  
1339 =cut
1340  
1341  
1342 #-----------------------------------------------
1343 #-----------------------------------------------
1344 # Non-exported subroutine:
1345 #
1346 # dashrep_generate_lists
1347 #-----------------------------------------------
1348 #-----------------------------------------------
1349 # Generates one or more lists, and the elements
1350 # in them, and puts each list and each element
1351 # into a named replacement.
1352 # Allows new list names to be specified
1353 # while generating the initial lists.
1354  
1355 # This subroutine is not exported because it
1356 # is only needed within this Dashrep module.
1357  
1358 sub dashrep_generate_lists
1359 10 ▶{
Subroutine dashrep_generate_lists: called CC=14 SCAR=27.2
Pod documented
1360  
1361 10 my $list_name ;
1362 my $generated_list_name ;
1363 10 my $parameter_name ;
1364 10 my $do_nothing ;
1365 10 my $list_prefix ;
1366 10 my $list_separator ;
1367 10 my $list_suffix ;
1368 10 my $replacement_name ;
1369 10 my $delimited_list_of_parameters ;
1370 10 my $pointer ;
1371 10 my $parameter ;
1372 10 my $item_name ;
1373 10 my @list_of_parameters ;
1374 10 my %already_generated_list_named ;
1375  
1376  
1377 #-----------------------------------------------
1378 # Begin a loop that handles each list to
1379 # be generated.
1380  
1381 10 foreach $list_name ( @global_list_of_lists_to_generate )
1382 {
1383  
1384  
1385 #-----------------------------------------------
1386 # Don't generate the same list more than once.
1387  
1388 13 ▶ if ( exists( $already_generated_list_named{ $list_name } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $already_generated_list_named{$list_name}) 3 10 13
1389 {
1390 3 ▶ if ( $already_generated_list_named{ $list_name } == $global_true )
Branch: 1 branch
BranchTrueFalseTotal
if ($already_generated_list_named{$list_name} == $global_true) 3 0 3
1391 {
1392 3 next ;
1393 }
1394 }
1395 10 $already_generated_list_named{ $list_name } = $global_true ;
1396  
1397  
1398 #-----------------------------------------------
1399 # Get information about the list being generated.
1400  
1401 10 $generated_list_name = "generated-list-named-" . $list_name ;
1402 10 ▶ if ( exists( $global_dashrep_replacement{ "parameter-name-for-list-named-" . $list_name } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{'parameter-name-for-list-named-' . $list_name}) { } 10 0 10
1403 {
1404 10 $parameter_name = $global_dashrep_replacement{ "parameter-name-for-list-named-" . $list_name } ;
1405 } else
1406 {
1407 0 $parameter_name = "unspecified-parameter-name-for-list-named-" . $list_name ;
1408 0 ▶ if ( $global_dashrep_replacement{ "dashrep-debug-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on") 0 0 0
1409 {
1410 0 print "{{trace; WARNING: phrase parameter-name-for-list-named-" . $list_name . " is not defined}}\n";
1411 }
1412 }
1413  
1414  
1415 #-----------------------------------------------
1416 # If the list prefix, separator, or suffix is
1417 # not defined, set it to empty (the default
1418 # value).
1419  
1420 10 ▶ if ( not( exists( $global_dashrep_replacement{ "prefix-for-list-named-" . $list_name } ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $global_dashrep_replacement{'prefix-for-list-named-' . $list_name}) 1 9 10
1421 {
1422 1 $global_dashrep_replacement{ "prefix-for-list-named-" . $list_name } = "" ;
1423 }
1424 10 $list_prefix = &dashrep_expand_parameters( "prefix-for-list-named-" . $list_name ) . "\n" ;
1425  
1426 10 ▶ if ( not( exists( $global_dashrep_replacement{ "separator-for-list-named-" . $list_name } ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $global_dashrep_replacement{'separator-for-list-named-' . $list_name}) 1 9 10
1427 {
1428 1 $global_dashrep_replacement{ "separator-for-list-named-" . $list_name } = "" ;
1429 }
1430 10 $list_separator = &dashrep_expand_parameters( "separator-for-list-named-" . $list_name ) . "\n" ;
1431  
1432 10 ▶ if ( not( exists( $global_dashrep_replacement{ "suffix-for-list-named-" . $list_name } ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $global_dashrep_replacement{'suffix-for-list-named-' . $list_name}) 1 9 10
1433 {
1434 1 $global_dashrep_replacement{ "suffix-for-list-named-" . $list_name } = "" ;
1435 }
1436 10 $list_suffix = &dashrep_expand_parameters( "suffix-for-list-named-" . $list_name ) . "\n" ;
1437  
1438  
1439 #-----------------------------------------------
1440 # Get the list of parameters that define the list.
1441  
1442 10 $replacement_name = "list-of-parameter-values-for-list-named-" . $list_name ;
1443 10 $delimited_list_of_parameters = &dashrep_expand_parameters( "list-of-parameter-values-for-list-named-" . $list_name ) ;
1444 10 @list_of_parameters = &dashrep_internal_split_delimited_items( $delimited_list_of_parameters ) ;
1445 10 $global_dashrep_replacement{ "logged-list-of-parameter-values-for-list-named-" . $list_name } = join( "," , @list_of_parameters ) ;
1446  
1447  
1448 #-----------------------------------------------
1449 # Insert a prefix at the beginning of the list.
1450  
1451 10 $global_dashrep_replacement{ $generated_list_name } = $list_prefix . "\n" ;
1452  
1453  
1454 #-----------------------------------------------
1455 # If the list of values is empty, skip over
1456 # the upcoming loop.
1457  
1458 10 ▶ if ( $#list_of_parameters < 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($#list_of_parameters < 0) { } 0 10 10
1459 {
1460 0 ▶ if ( $global_dashrep_replacement{ "dashrep-debug-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on") 0 0 0
1461 {
1462 0 print "{{trace; list named " . $list_name . " is empty}}\n";
1463 }
1464 } else
1465 {
1466  
1467  
1468 #-----------------------------------------------
1469 # Begin a loop that handles each list item.
1470 # Do not change the order of the parameters.
1471  
1472 10 ▶ for ( $pointer = 0 ; $pointer <= $#list_of_parameters ; $pointer ++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($pointer <= $#list_of_parameters) 50 10 60
1473 {
1474 50 $parameter = $list_of_parameters[ $pointer ] ;
1475 50 $global_dashrep_replacement{ $parameter_name } = $parameter ;
1476  
1477  
1478 #-----------------------------------------------
1479 # Add the next item to the list.
1480  
1481 50 $item_name = "item-for-list-" . $list_name . "-and-parameter-" . $parameter ;
1482 50 $global_dashrep_replacement{ $generated_list_name } .= $item_name . "\n" ;
1483  
1484  
1485 #-----------------------------------------------
1486 # Using a template, generate each item in the list.
1487  
1488 50 $global_dashrep_replacement{ $item_name } = &dashrep_expand_parameters( "template-for-list-named-" . $list_name ) ;
1489  
1490  
1491 #-----------------------------------------------
1492 # Insert separators between items.
1493  
1494 50 ▶ if ( $pointer < $#list_of_parameters )
Branch: 1 branch
BranchTrueFalseTotal
if ($pointer < $#list_of_parameters) 40 10 50
1495 {
1496 40 $global_dashrep_replacement{ $generated_list_name } .= $list_separator . "\n" ;
1497 }
1498  
1499  
1500 #-----------------------------------------------
1501 # Protect against an endless loop.
1502  
1503 50 $global_endless_loop_counter ++ ;
1504 50 ▶ if ( $global_endless_loop_counter > $global_endless_loop_counter_limit )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_endless_loop_counter > $global_endless_loop_counter_limit) 0 50 50
1505 {
1506 0 die "Error: The dashrep_generate_lists subroutine encountered an endless loop. Stopped" ;
1507 }
1508  
1509  
1510 #-----------------------------------------------
1511 # Repeat the loop for the next list item.
1512  
1513 }
1514  
1515  
1516 #-----------------------------------------------
1517 # Finish skipping over the above sections when
1518 # the list is empty.
1519  
1520 }
1521  
1522  
1523 #-----------------------------------------------
1524 # Terminate the generated list.
1525  
1526 10 $global_dashrep_replacement{ $generated_list_name } .= $list_suffix . "\n" ;
1527  
1528  
1529 #-----------------------------------------------
1530 # Repeat the loop for the next list to be
1531 # generated.
1532  
1533 }
1534  
1535  
1536 #-----------------------------------------------
1537 # End of subroutine.
1538  
1539 10 return 1 ;
1540  
1541 }
1542  
1543  
1544 =head2 dashrep_expand_phrases_except_special
1545  
1546 Expands the hyphenated phrases in a text
1547 string that is written in the Dashrep
1548 language -- except the special
1549 (built-in) hyphenated phrases that handle
1550 spaces, hyphens, tabs, and line breaks,
1551 and except the parameterized phrases.
1552  
1553 First, and only, parameter is the text
1554 string that uses the Dashrep language.
1555  
1556 Return value is the expanded text string.
1557 Return value is an empty string if there
1558 is not exactly one parameter.
1559  
1560 =cut
1561  
1562 #-----------------------------------------------
1563 #-----------------------------------------------
1564 # dashrep_expand_phrases_except_special
1565 #-----------------------------------------------
1566 #-----------------------------------------------
1567  
1568 sub dashrep_expand_phrases_except_special
1569 10 ▶{
Subroutine dashrep_expand_phrases_except_special: called CC=9 SCAR=22.1
Pod documented
1570  
1571 10 my $current_item ;
1572 my $hyphenated_phrase_to_expand ;
1573 10 my $expanded_output_string ;
1574 10 my $first_item ;
1575 10 my $remainder ;
1576 10 my $replacement_item ;
1577 10 my @item_stack ;
1578 10 my @items_to_add ;
1579  
1580  
1581 #-----------------------------------------------
1582 # Initialization.
1583  
1584 10 $expanded_output_string = "" ;
1585  
1586  
1587 #-----------------------------------------------
1588 # Internally define the "hyphen-here" phrase.
1589  
1590 10 $global_dashrep_replacement{ "hyphen-here" } = "no-space - no-space" ;
1591  
1592  
1593 #-----------------------------------------------
1594 # Get the starting replacement name.
1595  
1596 10 ▶ if ( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 10 0 10
1597 {
1598 10 $hyphenated_phrase_to_expand = $_[ 0 ] ;
1599 } else
1600 {
1601 0 $expanded_output_string = "" ;
1602 0 return $expanded_output_string ;
1603 }
1604  
1605  
1606 #-----------------------------------------------
1607 # Generate any needed lists.
1608  
1609 10 &dashrep_generate_lists ;
1610  
1611  
1612 #-----------------------------------------------
1613 # Start with a single phrase on a stack.
1614  
1615 10 @item_stack = ( ) ;
1616 10 push( @item_stack , $hyphenated_phrase_to_expand ) ;
1617  
1618  
1619 #-----------------------------------------------
1620 # Begin a loop that does all the replacements.
1621  
1622 10 ▶ while( $#item_stack >= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($#item_stack >= 0) 297 10 307
1623 {
1624  
1625  
1626 #-----------------------------------------------
1627 # If an endless loop occurs, handle that situation.
1628  
1629 297 $global_endless_loop_counter ++ ;
1630 297 ▶ if ( $global_endless_loop_counter > $global_endless_loop_counter_limit )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_endless_loop_counter > $global_endless_loop_counter_limit) 0 297 297
1631 {
1632 0 &dashrep_internal_endless_loop_info( ) ;
1633 0 die "Error: The dashrep_expand_phrases_except_special subroutine encountered an endless loop." . "\n" . "Stopped" ;
1634 }
1635  
1636  
1637 #-----------------------------------------------
1638 # Get the first/next item from the stack.
1639 # If it is empty (after removing spaces),
1640 # repeat the loop.
1641  
1642 297 $current_item = pop( @item_stack ) ;
1643 297 $current_item =~ s/^ +// ;
1644 297 $current_item =~ s/ +$// ;
1645 297 ▶ if ( $current_item eq "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($current_item eq "") 1 296 297
1646 {
1647 1 next ;
1648 }
1649  
1650  
1651 #-----------------------------------------------
1652 # If the item contains a space or line break,
1653 # split the string at the first space or
1654 # line break, and push those strings onto the
1655 # stack, and then repeat the loop.
1656  
1657 296 ▶ if ( $current_item =~ /^ *([^ ]+)[ \n\r]+(.*)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($current_item =~ /^ *([^ ]+)[ \n\r]+(.*)$/) 25 271 296
1658 {
1659 25 $first_item = $1 ;
1660 25 $remainder = $2 ;
1661 25 ▶ if ( $remainder =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder =~ /[^ ]/) 25 0 25
1662 {
1663 25 push( @item_stack , $remainder ) ;
1664 }
1665 25 push( @item_stack , $first_item ) ;
1666 25 next ;
1667 }
1668  
1669  
1670 #-----------------------------------------------
1671 # If the item is a hyphenated phrase that has
1672 # been defined, expand the phrase into its
1673 # associated text (its definition), split the
1674 # text at any spaces or line breaks, put those
1675 # delimited items on the stack, and repeat
1676 # the loop.
1677  
1678 271 ▶ if ( exists( $global_dashrep_replacement{ $current_item } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$current_item}) 75 196 271
1679 {
1680 75 $replacement_item = $global_dashrep_replacement{ $current_item } ;
1681 75 ▶ if ( $replacement_item =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($replacement_item =~ /[^ ]/) 69 6 75
1682 {
1683 69 @items_to_add = split( /[ \n\r]+/ , $replacement_item ) ;
1684 69 push( @item_stack , reverse( @items_to_add ) ) ;
1685 69 $global_replacement_count_for_item_name{ $current_item } ++ ;
1686 69 next ;
1687 }
1688 6 next ;
1689 }
1690  
1691  
1692 #-----------------------------------------------
1693 # If the item cannot be expanded, append it to
1694 # the output string.
1695  
1696 196 $expanded_output_string .= $current_item . " " ;
1697  
1698  
1699 #-----------------------------------------------
1700 # Repeat the loop for the next replacement.
1701  
1702 }
1703  
1704  
1705 #-----------------------------------------------
1706 # End of subroutine.
1707  
1708 10 return $expanded_output_string ;
1709  
1710 }
1711  
1712  
1713 =head2 dashrep_expand_special_phrases
1714  
1715 Expands only the the special (built-in)
1716 hyphenated phrases that handle hyphens,
1717 tabs, spaces and line breaks,
1718  
1719 First, and only, parameter is the
1720 text string that contains the special
1721 hyphenated phrases.
1722  
1723 Return value is the expanded text string.
1724 Return value is an empty string if there
1725 is not exactly one parameter.
1726  
1727 =cut
1728  
1729 #-----------------------------------------------
1730 #-----------------------------------------------
1731 # dashrep_expand_special_phrases
1732 #-----------------------------------------------
1733 #-----------------------------------------------
1734  
1735 sub dashrep_expand_special_phrases
1736 26 ▶{
Subroutine dashrep_expand_special_phrases: called CC=35 SCAR=38.9
Pod documented
1737  
1738 26 my $expanded_string ;
1739 my $phrase_name ;
1740 26 my $code_for_non_breaking_space ;
1741 26 my $code_with_spaces ;
1742 26 my $code_begin ;
1743 26 my $code_end ;
1744 26 my $remaining_string ;
1745 26 my $ignore_directive ;
1746 26 my $capture_directive ;
1747  
1748  
1749 #-----------------------------------------------
1750 # Get the starting hyphenated-phrase.
1751  
1752 26 ▶ if ( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 26 0 26
1753 {
1754 26 $expanded_string = $_[ 0 ] ;
1755 } else
1756 {
1757 0 $expanded_string = "" ;
1758 0 return $expanded_string ;
1759 }
1760 26 ▶ if ( $expanded_string !~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($expanded_string =~ /[^ ]/) 1 25 26
1761 {
1762 1 return "";
1763 }
1764  
1765  
1766 #-----------------------------------------------
1767 # If a single hyphenated phrase is supplied and
1768 # is defined, expand it. Otherwise, assume
1769 # it's a text string that contains the special
1770 # phrases.
1771  
1772 25 ▶ if ( $expanded_string =~ /^ *([^ \[\]]+-[^ \[\]]+) *$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($expanded_string =~ /^ *([^ \[\]]+-[^ \[\]]+) *$/) 10 15 25
1773 {
1774 10 $phrase_name = $1 ;
1775 10 ▶ if ( exists( $global_dashrep_replacement{ $phrase_name } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$phrase_name}) 1 9 10
1776 {
1777 1 $expanded_string = $global_dashrep_replacement{ $phrase_name } ;
1778 }
1779 }
1780  
1781  
1782 #-----------------------------------------------
1783 # Get the ignore level. It can be accessed
1784 # from outside this subroutine in case multiple
1785 # streams of Dashrep code are being processed
1786 # in turn.
1787  
1788 25 ▶ if ( $global_dashrep_replacement{ "dashrep-ignore-level" } =~ /^[0-9]+$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-ignore-level"} =~ /^[0-9]+$/) 13 12 25
1789 {
1790 13 $global_ignore_level = $global_dashrep_replacement{ "dashrep-ignore-level" } + 0 ;
1791 }
1792  
1793  
1794 #-----------------------------------------------
1795 # Get the capture level. It can be accessed
1796 # from outside this subroutine in case multiple
1797 # streams of Dashrep code are being processed
1798 # in turn.
1799  
1800 25 ▶ if ( $global_dashrep_replacement{ "dashrep-capture-level" } =~ /^[0-9]+$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-capture-level"} =~ /^[0-9]+$/) 7 18 25
1801 {
1802 7 $global_capture_level = $global_dashrep_replacement{ "dashrep-capture-level" } + 0 ;
1803 }
1804  
1805  
1806 #-----------------------------------------------
1807 # If the ignore level and capture level are both
1808 # non-zero, indicate an error (because they
1809 # overlap).
1810  
1811 25 ▶ if ( ( $global_ignore_level > 0 ) && ( $global_capture_level > 0 ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_ignore_level > 0 and $global_capture_level > 0) 0 25 25
Condition66%2/3
$global_ignore_level > 0 and $global_capture_level > 0
!ll&&!rl&&r
2320
MC/DC0%0/2
$global_ignore_level > 0 and $global_capture_level > 0
$global_ignore_level > 0 $global_capture_level > 0
Truth table66%2/3
A and B
A= $global_ignore_level > 0B= $global_capture_level > 0
ABresult
0X0
100
111
1812 {
1813 0 $expanded_string .= " [warning: ignore and capture directives overlap, both directives reset] " ;
1814 0 $global_ignore_level = 0 ;
1815 0 $global_capture_level = 0 ;
1816 }
1817  
1818  
1819 #-----------------------------------------------
1820 # Handle the directives:
1821 # "ignore-begin-here" and
1822 # "ignore-end-here"
1823  
1824 25 $remaining_string = $expanded_string ;
1825 25 $expanded_string = "" ;
1826  
1827 25 ▶ if ( ( $global_ignore_level > 0 ) && ( $remaining_string !~ /((ignore-begin-here)|(ignore-end-here))/si ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_ignore_level > 0 and not $remaining_string =~ /((ignore-begin-here)|(ignore-end-here))/is) 1 24 25
Condition100%3/3
$global_ignore_level > 0 and not $remaining_string =~ /((ignore-begin-here)|(ignore-end-here))/is
!ll&&!rl&&r
2311
MC/DC100%2/2
$global_ignore_level > 0 and not $remaining_string =~ /((ignore-begin-here)|(ignore-end-here))/is
$global_ignore_level > 0 not $remaining_string =~ /((ignore-begin-here)|(ignore-end-here))/is
Truth table100%3/3
A and not(B)
A= $global_ignore_level > 0B= not $remaining_string =~ /((ignore-begin-here)|(ignore-end-here))/is
ABresult
0X0
100
111
1828 {
1829 1 ▶ if ( $global_dashrep_replacement{ "dashrep-ignore-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-ignore-trace-on-or-off"} eq "on") 0 1 1
1830 {
1831 0 print "{{trace; ignore level: " . $global_ignore_level . "}}\n" ;
1832 0 ▶ if ( $remaining_string =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining_string =~ /[^ ]/) 0 0 0
1833 {
1834 0 print "{{trace; ignored: " . $remaining_string . "}}\n" ;
1835 }
1836 }
1837 1 $remaining_string = "" ;
1838 }
1839  
1840 25 ▶ while ( $remaining_string =~ /^((.*? +)?)((ignore-begin-here)|(ignore-end-here))(( +.*)?)$/si )
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining_string =~ /^((.*? +)?)((ignore-begin-here)|(ignore-end-here))(( +.*)?)$/is) 4 25 29
1841 {
1842 4 $code_begin = $1 ;
1843 4 $ignore_directive = $3 ;
1844 4 $remaining_string = $6 ;
1845  
1846 4 ▶ if ( $global_ignore_level > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_ignore_level > 0) { } 2 2 4
1847 {
1848 2 ▶ if ( $global_dashrep_replacement{ "dashrep-ignore-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-ignore-trace-on-or-off"} eq "on") 0 2 2
1849 {
1850 0 print "{{trace; ignore level: " . $global_ignore_level . "}}\n" ;
1851 0 ▶ if ( $remaining_string =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining_string =~ /[^ ]/) 0 0 0
1852 {
1853 0 print "{{trace; ignored: " . $code_begin . "}}\n" ;
1854 }
1855 }
1856 } else
1857 {
1858 2 $expanded_string .= $code_begin . " " ;
1859 }
1860  
1861 4 ▶ if ( $ignore_directive eq "ignore-begin-here" )
Branch: 2 branches
BranchTrueFalseTotal
if ($ignore_directive eq 'ignore-begin-here') { } 2 2 4
elsif ($ignore_directive eq 'ignore-end-here') { } 2 0 2
1862 {
1863 2 ▶ if ( $global_dashrep_replacement{ "dashrep-ignore-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-ignore-trace-on-or-off"} eq "on") 0 2 2
1864 {
1865 0 print "{{trace; ignore directive: " . $ignore_directive . "}}\n" ;
1866 }
1867 2 $global_ignore_level ++ ;
1868 2 $global_dashrep_replacement{ "dashrep-ignore-level" } = sprintf( "%d" , $global_ignore_level ) ;
1869 } elsif ( $ignore_directive eq "ignore-end-here" )
1870 {
1871 2 ▶ if ( $global_dashrep_replacement{ "dashrep-ignore-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-ignore-trace-on-or-off"} eq "on") 0 2 2
1872 {
1873 0 print "{{trace; ignore directive: " . $ignore_directive . "}}\n" ;
1874 }
1875 2 $global_ignore_level -- ;
1876 2 $global_dashrep_replacement{ "dashrep-ignore-level" } = sprintf( "%d" , $global_ignore_level ) ;
1877 }
1878 }
1879 25 $expanded_string .= $remaining_string ;
1880  
1881  
1882 #-----------------------------------------------
1883 # Handle the directives:
1884 # "capture-begin-here" and
1885 # "capture-end-here"
1886  
1887 25 $remaining_string = $expanded_string ;
1888 25 $expanded_string = "" ;
1889  
1890 25 ▶ if ( ( $global_capture_level > 0 ) && ( $remaining_string !~ /((capture-begin-here)|(capture-end-here))/si ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_capture_level > 0 and not $remaining_string =~ /((capture-begin-here)|(capture-end-here))/is) 1 24 25
Condition100%3/3
$global_capture_level > 0 and not $remaining_string =~ /((capture-begin-here)|(capture-end-here))/is
!ll&&!rl&&r
2311
MC/DC100%2/2
$global_capture_level > 0 and not $remaining_string =~ /((capture-begin-here)|(capture-end-here))/is
$global_capture_level > 0 not $remaining_string =~ /((capture-begin-here)|(capture-end-here))/is
Truth table100%3/3
A and not(B)
A= $global_capture_level > 0B= not $remaining_string =~ /((capture-begin-here)|(capture-end-here))/is
ABresult
0X0
100
111
1891 {
1892 1 $global_dashrep_replacement{ "captured-text" } .= " " . $remaining_string ;
1893 1 ▶ if ( $global_dashrep_replacement{ "dashrep-capture-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-capture-trace-on-or-off"} eq "on") 0 1 1
1894 {
1895 0 print "{{trace; capture level: " . $global_capture_level . "}}\n" ;
1896 0 ▶ if ( $remaining_string =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining_string =~ /[^ ]/) 0 0 0
1897 {
1898 0 print "{{trace; captured: " . $remaining_string . "}}\n" ;
1899 }
1900 }
1901 1 $remaining_string = "" ;
1902 }
1903  
1904 25 ▶ while ( $remaining_string =~ /^((.*? +)?)((capture-begin-here)|(capture-end-here))(( +.*)?)$/si )
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining_string =~ /^((.*? +)?)((capture-begin-here)|(capture-end-here))(( +.*)?)$/is) 4 25 29
1905 {
1906 4 $code_begin = $1 ;
1907 4 $capture_directive = $3 ;
1908 4 $remaining_string = $6 ;
1909  
1910 4 ▶ if ( $global_capture_level > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_capture_level > 0) { } 2 2 4
1911 {
1912 2 $global_dashrep_replacement{ "captured-text" } .= " " . $code_begin ;
1913 2 ▶ if ( $global_dashrep_replacement{ "dashrep-capture-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-capture-trace-on-or-off"} eq "on") 0 2 2
1914 {
1915 0 print "{{trace; capture level: " . $global_capture_level . "}}\n" ;
1916 0 ▶ if ( $remaining_string =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining_string =~ /[^ ]/) 0 0 0
1917 {
1918 0 print "{{trace; captured: " . $code_begin . "}}\n" ;
1919 }
1920 }
1921 } else
1922 {
1923 2 $expanded_string .= $code_begin . " " ;
1924 }
1925  
1926 4 ▶ if ( $capture_directive eq "capture-begin-here" )
Branch: 2 branches
BranchTrueFalseTotal
if ($capture_directive eq 'capture-begin-here') { } 2 2 4
elsif ($capture_directive eq 'capture-end-here') { } 2 0 2
1927 {
1928 2 $global_dashrep_replacement{ "captured-text" } = "" ;
1929 2 ▶ if ( $global_dashrep_replacement{ "dashrep-capture-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-capture-trace-on-or-off"} eq "on") 0 2 2
1930 {
1931 0 print "{{trace; capture directive: " . $capture_directive . "}}\n" ;
1932 }
1933 2 $global_capture_level ++ ;
1934 2 $global_dashrep_replacement{ "dashrep-capture-level" } = sprintf( "%d" , $global_capture_level ) ;
1935 } elsif ( $capture_directive eq "capture-end-here" )
1936 {
1937 2 ▶ if ( $global_dashrep_replacement{ "dashrep-capture-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-capture-trace-on-or-off"} eq "on") 0 2 2
1938 {
1939 0 print "{{trace; capture directive: " . $capture_directive . "}}\n" ;
1940 }
1941 2 $global_capture_level -- ;
1942 2 $global_dashrep_replacement{ "dashrep-capture-level" } = sprintf( "%d" , $global_capture_level ) ;
1943 }
1944 }
1945 25 $expanded_string .= $remaining_string ;
1946  
1947  
1948 #-----------------------------------------------
1949 # Handle the directive:
1950 # "non-breaking-space"
1951  
1952 25 $code_for_non_breaking_space = $global_dashrep_replacement{ "non-breaking-space" } ;
1953 25 ▶ while ( $expanded_string =~ /^(.* +)?non-breaking-space( +.*)?$/sgi )
Branch: 1 branch
BranchTrueFalseTotal
if ($expanded_string =~ /^(.* +)?non-breaking-space( +.*)?$/sig) 1 25 26
1954 {
1955 1 $code_begin = $1 ;
1956 1 $code_end = $2 ;
1957 1 $code_begin =~ s/ +$//si ;
1958 1 $code_end =~ s/^ +//si ;
1959 1 $expanded_string = $code_begin . $code_for_non_breaking_space . $code_end ;
1960 }
1961  
1962  
1963 #-----------------------------------------------
1964 # Handle the directives:
1965 # "span-non-breaking-spaces-begin" and
1966 # "span-non-breaking-spaces-end"
1967  
1968 25 $code_for_non_breaking_space = $global_dashrep_replacement{ "non-breaking-space" } ;
1969 25 ▶ while ( $expanded_string =~ /^(.*)\bspan-non-breaking-spaces-begin\b *(.*?) *\bspan-non-breaking-spaces-end\b(.*)$/sgi )
Branch: 1 branch
BranchTrueFalseTotal
if ($expanded_string =~ /^(.*)\bspan-non-breaking-spaces-begin\b *(.*?) *\bspan-non-breaking-spaces-end\b(.*)$/sig) 1 25 26
1970 {
1971 1 $code_begin = $1 ;
1972 1 $code_with_spaces = $2 ;
1973 1 $code_end = $3 ;
1974 1 $code_with_spaces =~ s/ +/ ${code_for_non_breaking_space} /sgi ;
1975 1 $code_with_spaces =~ s/ +//sgi ;
1976 1 $expanded_string = $code_begin . $code_with_spaces . $code_end ;
1977 }
1978  
1979  
1980 #-----------------------------------------------
1981 # Replace multiple spaces and tabs with single spaces.
1982  
1983 25 $expanded_string =~ s/[ \n][ \t]+/ /sg ;
1984  
1985  
1986 #-----------------------------------------------
1987 # Handle the directive:
1988 # "tab-here"
1989  
1990 25 $expanded_string =~ s/ *\btab-here\b */\t/sg ;
1991  
1992  
1993 #-----------------------------------------------
1994 # Handle the directives:
1995 # "empty-line" and "new-line"
1996  
1997 25 $expanded_string =~ s/ *\bempty-line\b */\n\n/sg ;
1998 25 $expanded_string =~ s/ *\bnew-line\b */\n/sg ;
1999  
2000  
2001 #-----------------------------------------------
2002 # Concatenate lines and spaces as indicated by
2003 # the "no-space" and "one-space" directives.
2004  
2005 25 $expanded_string =~ s/\bone-space\b/<onespace>/sgi ;
2006  
2007 25 $expanded_string =~ s/\bno-space\b/<nospace>/sgi ;
2008  
2009 25 $expanded_string =~ s/[ \t]+<nospace>[ \t]*/<nospace>/sgi ;
2010 25 $expanded_string =~ s/[ \t]*<nospace>[ \t]+/<nospace>/sgi ;
2011 25 $expanded_string =~ s/<nospace>//sgi ;
2012 25 $expanded_string =~ s/<nospace>//sgi ;
2013  
2014 25 $expanded_string =~ s/[ \t]+<onespace>[ \t]*/<onespace>/sgi ;
2015 25 $expanded_string =~ s/[ \t]*<onespace>[ \t]+/<onespace>/sgi ;
2016 25 $expanded_string =~ s/<onespace>/ /sgi ;
2017 25 $expanded_string =~ s/<onespace>/ /sgi ;
2018  
2019  
2020 #-----------------------------------------------
2021 # End of subroutine.
2022  
2023 25 return $expanded_string ;
2024  
2025 }
2026  
2027  
2028 =head2 dashrep_expand_phrases
2029  
2030 Expands all the hyphenated phrases
2031 in a text string that is written in the
2032 Dashrep language. This includes expanding
2033 the special (built-in) hyphenated phrases
2034 that handle spaces, hyphens, and line breaks.
2035  
2036 First, and only, parameter is the text string
2037 that may contain hyphenated phrases to be
2038 expanded.
2039  
2040 Return value is the expanded text string.
2041 Return value is an empty string if there is not
2042 exactly one parameter.
2043  
2044 =cut
2045  
2046 #-----------------------------------------------
2047 #-----------------------------------------------
2048 # dashrep_expand_phrases
2049 #-----------------------------------------------
2050 #-----------------------------------------------
2051  
2052 sub dashrep_expand_phrases
2053 9 ▶{
Subroutine dashrep_expand_phrases: called CC=3 SCAR=12.0
Pod documented
2054  
2055 9 my $text_string_to_expand ;
2056 my $partly_expanded_string ;
2057 9 my $expanded_string ;
2058  
2059  
2060 #-----------------------------------------------
2061 # Get the starting hyphenated-phrase.
2062  
2063 9 ▶ if ( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 9 0 9
2064 {
2065 9 $text_string_to_expand = $_[ 0 ] ;
2066 } else
2067 {
2068 0 $expanded_string = "" ;
2069 0 return $expanded_string ;
2070 }
2071  
2072  
2073 #-----------------------------------------------
2074 # Expand the phrase except for special phrases.
2075  
2076 9 $partly_expanded_string = &dashrep_expand_phrases_except_special( $text_string_to_expand ) ;
2077 9 ▶ if ( $global_dashrep_replacement{ "dashrep-linewise-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on") 0 9 9
2078 {
2079 0 print "{{trace; after non-special phrases expanded: " . $partly_expanded_string . "}}\n" ;
2080 }
2081  
2082  
2083 #-----------------------------------------------
2084 # Handle special directives:
2085 # "empty-line" and "new-line" and
2086 # "no-space" and "one-space" and others
2087  
2088 9 $expanded_string = &dashrep_expand_special_phrases( $partly_expanded_string ) ;
2089  
2090  
2091 #-----------------------------------------------
2092 # End of subroutine.
2093  
2094 9 return $expanded_string ;
2095  
2096 }
2097  
2098  
2099 =head2 dashrep_xml_tags_to_dashrep
2100  
2101 Converts a single line of XML code into Dashrep
2102 code in which XML tags are replaced by Dashrep
2103 phrases.
2104 Tags are replaced by hyphenated phrases that
2105 are named according to the accumulated XML
2106 tag names, with "begin-" and "end-" to indicate
2107 the beginning and ending tags. The prefix
2108 "begin-and-end-" indicates a self-terminating
2109 XML tag (e.g. "<br />").
2110 If the resulting phrase has a Dashrep definition,
2111 that definition (which is assumed to be a single
2112 phrase) is used instead.
2113 If the non-tag content contains any hyphens,
2114 they are replaced with the phrase "hyphen-here".
2115 If a tag's opening bracket (<) and closing
2116 bracket (>) are not both on the same line, the
2117 tag will not be recognized.
2118  
2119 =cut
2120  
2121  
2122 #-----------------------------------------------
2123 #-----------------------------------------------
2124 # dashrep_xml_tags_to_dashrep
2125 #-----------------------------------------------
2126 #-----------------------------------------------
2127  
2128 sub dashrep_xml_tags_to_dashrep
2129 3 ▶{
Subroutine dashrep_xml_tags_to_dashrep: called CC=53 SCAR=57.2
Pod documented
2130  
2131 3 my $input_text ;
2132 my $first_tag_name ;
2133 3 my $output_text ;
2134 3 my $open_brackets ;
2135 3 my $close_brackets ;
2136 3 my $remaining_string ;
2137 3 my $prefix_text ;
2138 3 my $tag_full ;
2139 3 my $suffix_text ;
2140 3 my $tag_name ;
2141 3 my $previous_input_text ;
2142 3 my $text_before_tag ;
2143 3 my $tag_and_possible_parameters ;
2144 3 my $parameter_name ;
2145 3 my $parameter_value ;
2146 3 my $text_after_tag ;
2147 3 my $revised_tags ;
2148 3 my $possible_slash ;
2149 3 my $may_include_closing_slash ;
2150 3 my $previous_tag_name ;
2151 3 my $sequence_without_hyphen_prefix ;
2152 3 my $starting_position_of_last_tag_name ;
2153 3 my $full_phrase ;
2154  
2155  
2156 #-----------------------------------------------
2157 # Get the input text.
2158  
2159 3 ▶ if ( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 3 0 3
2160 {
2161 3 $input_text = $_[ 0 ] ;
2162 } else
2163 {
2164 0 carp "Warning: Call to xml_tags_to_dashrep subroutine does not have exactly one parameter." ;
2165 0 return 0 ;
2166 }
2167  
2168  
2169 #-----------------------------------------------
2170 # Trim spaces from the input line, and clear
2171 # the output text.
2172  
2173 3 $input_text =~ s/^ +// ;
2174 3 $input_text =~ s/ +$// ;
2175 3 $output_text = "" ;
2176  
2177  
2178 #-----------------------------------------------
2179 # Get the tag name that is regarded as at
2180 # the highest level of interest. Tags at
2181 # higher levels are ignored.
2182  
2183 3 $first_tag_name = $global_dashrep_replacement{ "dashrep-first-xml-tag-name" } ;
2184  
2185  
2186 #-----------------------------------------------
2187 # If a line does not contain the same number
2188 # of open angle brackets (<) as close angle
2189 # brackets (>), and tracing is on, issue a
2190 # warning.
2191  
2192 3 $open_brackets = $input_text ;
2193 3 $open_brackets =~ s/[^<]//g ;
2194 3 $close_brackets = $input_text ;
2195 3 $close_brackets =~ s/[^>]//g ;
2196 3 ▶ if ( length( $open_brackets ) != length( $close_brackets ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $open_brackets != length $close_brackets) 0 3 3
2197 {
2198 0 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 0 0
2199 {
2200 0 print "{{trace; non-matching angle brackets: " . $input_text . "}}\n" ;
2201 }
2202 }
2203  
2204  
2205 #-----------------------------------------------
2206 # If a tag is identified -- through use of
2207 # special hyphenated phrases -- as of the
2208 # open-and-close type that may not include a
2209 # closing slash (such as "<br>"), then insert
2210 # a closing tag.
2211 # Note that the match is case-sensitive.
2212  
2213 3 $remaining_string = $input_text ;
2214 3 $input_text = "" ;
2215 3 ▶ while ( $remaining_string =~ /^(.*?)(<[^ <>\/][^>]*[^>\/]>)(.*)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining_string =~ m[^(.*?)(<[^ <>/][^>]*[^>/]>)(.*)$]) 14 3 17
2216 {
2217 14 $prefix_text = $1 ;
2218 14 $tag_full = $2 ;
2219 14 $suffix_text = $3 ;
2220 14 $tag_name = $tag_full ;
2221 14 $tag_name =~ s/^<([^ >\/]+).*>$/$1/ ;
2222 14 ▶ if ( $tag_name ne "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($tag_name ne "") 14 0 14
2223 {
2224 14 ▶ if ( exists( $global_dashrep_replacement{ "dashrep-xml-yes-handle-open-close-tag-" . $tag_name } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{'dashrep-xml-yes-handle-open-close-tag-' . $tag_name}) 0 14 14
2225 {
2226 0 $tag_full .= '</' . $tag_name . ">" ;
2227 0 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 0 0
2228 {
2229 0 print "{{trace; open-and-close type xml tag: " . $tag_name . " , modified to include closing tag: " . $tag_full . "}}\n" ;
2230 }
2231 }
2232 }
2233 14 $input_text .= $prefix_text . $tag_full ;
2234 14 $remaining_string = $suffix_text ;
2235 }
2236 3 $input_text .= $remaining_string ;
2237  
2238  
2239 #-----------------------------------------------
2240 # If one of the parameters within a tag is a
2241 # "style" tag that has multiple CSS
2242 # parameters with their own parameter values
2243 # (with a colon (:) separating each
2244 # sub-parameter name from its sub-parameter
2245 # value, and with semicolons (;) separating
2246 # those name & value pairs within the XML
2247 # parameter), split up those sub-parameters
2248 # into separate parameters (with combined
2249 # names).
2250  
2251 3 $previous_input_text = "" ;
2252 3 ▶ while ( $input_text ne $previous_input_text )
Branch: 1 branch
BranchTrueFalseTotal
if ($input_text ne $previous_input_text) 3 3 6
2253 {
2254 3 $previous_input_text = $input_text ;
2255 3 $input_text =~ s/(<[^>]+ style) *= *\"([^\"\:\;>]+) *: *([^\"\:\;>]*) *; *([^\">]+)\"([^>]*>)/$1_$2=\"$3\" style=\"$4\"$5/sgi ;
2256 3 $input_text =~ s/(<[^>]+ style) *= *\"([^\"\:\;>]+) *: *([^\"\:\;>]*)\"([^>]*>)/$1_$2=\"$3\"$4/sgi ;
2257 3 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 3 3
2258 {
2259 0 ▶ if ( $previous_input_text ne $input_text )
Branch: 1 branch
BranchTrueFalseTotal
if ($previous_input_text ne $input_text) 0 0 0
2260 {
2261 0 print "{{trace; after xml sub-parameters extracted: " . $input_text . "}}\n" ;
2262 }
2263 }
2264 }
2265  
2266  
2267 #-----------------------------------------------
2268 # Expand parameters within a tag into separate
2269 # XML tags.
2270 # TODO: Insert "begin-xml-tag-parameters" and
2271 # "end-xml-tag-parameters" around parameters.
2272  
2273 3 ▶ while ( $input_text =~ /^(.*)(<[^ >\!\?\/][^>]*) ([^ >\=]+)=((\"([^>\"]*)\")|([^ >\"\']+)) *>(.*)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($input_text =~ m[^(.*)(<[^ >\!\?/][^>]*) ([^ >\=]+)=((\"([^>\"]*)\")|([^ >\"\']+)) *>(.*)$]) 0 3 3
2274 {
2275 0 $text_before_tag = $1 ;
2276 0 $tag_and_possible_parameters = $2 ;
2277 0 $parameter_name = $3 ;
2278 0 $parameter_value = $4 ;
2279 0 $text_after_tag = $8 ;
2280 0 $parameter_value =~ s/^\"(.*)\"$/$1/ ;
2281 0 $parameter_name =~ s/\-/_/g ;
2282 0 $revised_tags = $tag_and_possible_parameters . "><" . $parameter_name . ">" . $parameter_value . '</' . $parameter_name . ">" ;
2283 0 $input_text = $text_before_tag . $revised_tags . $text_after_tag ;
2284 0 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 0 0
2285 {
2286 0 print "{{trace; after xml parameter extracted: " . $revised_tags . "}}\n" ;
2287 }
2288 }
2289  
2290  
2291 #-----------------------------------------------
2292 # Begin a loop that repeats for each XML tag.
2293 #
2294 # Get the name within a (single) tag, and
2295 # ignore any other content within the tag.
2296 # Ignore the opening XML-standard-required
2297 # declaration.
2298  
2299 3 ▶ while ( $input_text =~ /^ *([^<>]*)<(\/?)([^ >\?\/]+[^ >\/]*)([^>]*)>(.*)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($input_text =~ m[^ *([^<>]*)<(/?)([^ >\?/]+[^ >/]*)([^>]*)>(.*)$]) 27 3 30
2300 {
2301 27 $text_before_tag = $1 ;
2302 27 $possible_slash = $2 ;
2303 27 $tag_name = $3 ;
2304 27 $may_include_closing_slash = $4 ;
2305 27 $suffix_text = $5 ;
2306 27 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 27 27
2307 {
2308 0 print "{{trace; input line: " . $input_text . "}}\n" ;
2309 }
2310 27 $input_text = $suffix_text ;
2311 27 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 27 27
2312 {
2313 0 print "{{trace; tag: <" . $possible_slash . $tag_name . ">}}\n" ;
2314 }
2315  
2316  
2317 #-----------------------------------------------
2318 # If the non-tag content text contains any
2319 # hyphens, replace them with the phrase
2320 # "hypen-here".
2321  
2322 27 $text_before_tag =~ s/\-/dashrep_internal_hyphen_here/sg ;
2323 27 $text_before_tag =~ s/dashrep_internal_hyphen_here/ hyphen-here /sg ;
2324  
2325  
2326 #-----------------------------------------------
2327 # If any text precedes the tag, write it on a
2328 # separate line.
2329  
2330 27 ▶ if ( $text_before_tag =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($text_before_tag =~ /[^ ]/) 8 19 27
2331 {
2332 8 ▶ if ( $global_ignore_level <= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_ignore_level <= 0) 8 0 8
2333 {
2334 8 $output_text .= $text_before_tag . "\n" ;
2335 }
2336 }
2337  
2338  
2339 #-----------------------------------------------
2340 # If a specially named Dashrep phrase indicates
2341 # that the tag should be ignored, ignore it.
2342  
2343 27 ▶ if ( exists( $global_dashrep_replacement{ "dashrep-xml-yes-ignore-tag-named-" . $tag_name } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{'dashrep-xml-yes-ignore-tag-named-' . $tag_name}) 0 27 27
2344 {
2345 0 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-yes-ignore-tag-named-" . $tag_name } eq "yes" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{'dashrep-xml-yes-ignore-tag-named-' . $tag_name} eq "yes") 0 0 0
2346 {
2347 0 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 0 0
2348 {
2349 0 print "{{trace; ignoring tag: " . $tag_name . "}}\n" ;
2350 }
2351 0 next ;
2352 }
2353 }
2354  
2355  
2356 #-----------------------------------------------
2357 # If a specially named Dashrep phrase indicates
2358 # that the XML tag should be renamed, rename it as
2359 # requested.
2360  
2361 27 ▶ if ( exists( $global_dashrep_replacement{ "dashrep-xml-replacement-name-for-tag-named-" . $tag_name } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{'dashrep-xml-replacement-name-for-tag-named-' . $tag_name}) 0 27 27
2362 {
2363 0 $previous_tag_name = $tag_name ;
2364 0 $tag_name = $global_dashrep_replacement{ "dashrep-xml-replacement-name-for-tag-named-" . $previous_tag_name } ;
2365 0 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 0 0
2366 {
2367 0 print "{{trace; changing tag name " . $previous_tag_name . " into tag name " . $tag_name . "}}\n" ;
2368 }
2369 }
2370  
2371  
2372 #-----------------------------------------------
2373 # If the tag is of the "close" type, write the
2374 # appropriate dashrep phrase (and indent it to
2375 # indicate the nesting level). Then remove the
2376 # lowest-level tag name from the phrase that
2377 # contains all the tag names.
2378  
2379 27 ▶ if ( $possible_slash eq '/' )
Branch: 2 branches
BranchTrueFalseTotal
if ($possible_slash eq '/') { } 13 14 27
elsif ($may_include_closing_slash =~ m[/]) { } 1 13 14
2380 {
2381 13 ▶ if ( length( $global_xml_accumulated_sequence_of_tag_names ) > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (length $global_xml_accumulated_sequence_of_tag_names > 0) 13 0 13
2382 {
2383 13 ▶ if ( $global_xml_tag_at_level_number[ $global_xml_level_number ] eq $tag_name )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_xml_tag_at_level_number[$global_xml_level_number] eq $tag_name) { } 13 0 13
2384 {
2385 13 $full_phrase = "end" . $global_xml_accumulated_sequence_of_tag_names ;
2386 13 ▶ if ( exists( $global_dashrep_replacement{ $full_phrase } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$full_phrase}) 0 13 13
2387 {
2388 0 $global_ignore_level = 0 ;
2389 }
2390 13 ▶ if ( $global_ignore_level <= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_ignore_level <= 0) { } 13 0 13
2391 {
2392 13 $output_text .= substr( $global_spaces , 0 , ( 2 * $global_xml_level_number ) ) ;
2393 13 $output_text .= "[-" ;
2394 13 ▶ if ( exists( $global_dashrep_replacement{ $full_phrase } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$full_phrase}) { } 0 13 13
2395 {
2396 0 $output_text .= $global_dashrep_replacement{ $full_phrase } ;
2397 } else
2398 {
2399 13 $output_text .= $full_phrase ;
2400 }
2401 13 $output_text .= "-]" ;
2402 13 $output_text .= "\n" ;
2403 } else
2404 {
2405 0 $global_ignore_level -- ;
2406 }
2407 13 $sequence_without_hyphen_prefix = $global_xml_accumulated_sequence_of_tag_names ;
2408 13 $sequence_without_hyphen_prefix =~ s/^\-// ;
2409 13 $global_exists_xml_hyphenated_phrase{ $sequence_without_hyphen_prefix } = "exists" ;
2410 13 $starting_position_of_last_tag_name = length( $global_xml_accumulated_sequence_of_tag_names ) - length( $global_xml_tag_at_level_number[ $global_xml_level_number ] ) - 1 ;
2411 13 ▶ if ( $starting_position_of_last_tag_name > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($starting_position_of_last_tag_name > 0) { } 11 2 13
2412 {
2413 11 $global_xml_accumulated_sequence_of_tag_names = substr( $global_xml_accumulated_sequence_of_tag_names , 0 , $starting_position_of_last_tag_name ) ;
2414 } else
2415 {
2416 2 $global_xml_accumulated_sequence_of_tag_names = "" ;
2417 }
2418 13 $global_xml_level_number -- ;
2419 } else
2420 {
2421 0 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 0 0
2422 {
2423 0 print "{{trace; close tag " . $tag_name . " ignored because it does not match expected close tag name " . $global_xml_tag_at_level_number[ $global_xml_level_number ] . "}}\n" ;
2424 }
2425 }
2426 }
2427  
2428  
2429 #-----------------------------------------------
2430 # If the tag is of the singular (open and close)
2431 # type, write the appropriate dashrep phrase.
2432  
2433 } elsif ( $may_include_closing_slash =~ /\// )
2434 {
2435 1 ▶ if ( length( $global_xml_accumulated_sequence_of_tag_names ) > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (length $global_xml_accumulated_sequence_of_tag_names > 0) 0 1 1
2436 {
2437 0 $full_phrase = "begin-and-end" . $global_xml_accumulated_sequence_of_tag_names . "-" . $tag_name ;
2438 0 ▶ if ( ( exists( $global_dashrep_replacement{ "dashrep-xml-yes-ignore-if-no-tag-replacement" } ) ) && ( $global_dashrep_replacement{ "dashrep-xml-yes-ignore-if-no-tag-replacement" } eq "yes" ) && ( not( exists( $global_dashrep_replacement{ $full_phrase } ) ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} and $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} eq "yes" and not exists $global_dashrep_replacement{$full_phrase}) 0 0 0
Condition0%0/6
exists $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} and $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} eq "yes" and not exists $global_dashrep_replacement{$full_phrase}
!ll&&!rl&&r
000
exists $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} and $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} eq "yes"
!ll&&!rl&&r
000
MC/DC0%0/3
exists $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} and $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} eq "yes" and not exists $global_dashrep_replacement{$full_phrase}
exists $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} eq "yes" not exists $global_dashrep_replacement{$full_phrase}
Truth table0%0/4
A and B and not(C)
A= exists $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"}B= $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} eq "yes"C= not exists $global_dashrep_replacement{$full_phrase}
ABCresult
0XX0
10X0
1100
1111
2439 {
2440 0 $global_ignore_level ++ ;
2441 }
2442 0 ▶ if ( exists( $global_dashrep_replacement{ $full_phrase } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$full_phrase}) 0 0 0
2443 {
2444 0 $global_ignore_level = 0 ;
2445 }
2446 0 ▶ if ( $global_ignore_level <= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_ignore_level <= 0) { } 0 0 0
2447 {
2448 0 $output_text .= substr( $global_spaces , 0 , ( 2 * ( $global_xml_level_number + 1 ) ) ) ;
2449 0 $output_text .= "[-" ;
2450 0 ▶ if ( exists( $global_dashrep_replacement{ $full_phrase } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$full_phrase}) { } 0 0 0
2451 {
2452 0 $output_text .= $global_dashrep_replacement{ $full_phrase } ;
2453 } else
2454 {
2455 0 $output_text .= $full_phrase ;
2456 }
2457 0 $output_text .= "-]" ;
2458 0 $output_text .= "\n" ;
2459 } else
2460 {
2461 0 $global_ignore_level -- ;
2462 }
2463 }
2464  
2465  
2466 #-----------------------------------------------
2467 # If the tag is of the "open" type, append the
2468 # new tag name to the accumulated hyphenated
2469 # phrase, and then write the appropriate Dashrep
2470 # phrase. However, do not use tag names that
2471 # occur before the specified first tag name
2472 # (of interest) -- unless the first tag name
2473 # is empty.
2474  
2475 } else
2476 {
2477 13 ▶ if ( length( $global_xml_accumulated_sequence_of_tag_names ) <= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (length $global_xml_accumulated_sequence_of_tag_names <= 0) { } 2 11 13
2478 {
2479 2 ▶ if ( $tag_name eq $first_tag_name )
Branch: 2 branches
BranchTrueFalseTotal
if ($tag_name eq $first_tag_name) { } 2 0 2
elsif ($first_tag_name =~ /^ *$/) { } 0 0 0
2480 {
2481 2 $global_xml_level_number ++ ;
2482 2 $global_xml_tag_at_level_number[ $global_xml_level_number ] = $tag_name ;
2483 2 $global_xml_accumulated_sequence_of_tag_names = "-" . $tag_name ;
2484 2 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 2 2
2485 {
2486 0 print "{{trace; specified top-level tag name: " . $first_tag_name . "}}\n" ;
2487 }
2488 } elsif ( $first_tag_name =~ /^ *$/ )
2489 {
2490 0 $global_xml_level_number ++ ;
2491 0 $global_xml_tag_at_level_number[ $global_xml_level_number ] = $tag_name ;
2492 0 $first_tag_name = $tag_name ;
2493 0 $global_dashrep_replacement{ "dashrep-first-xml-tag-name" } = $first_tag_name ;
2494 0 $global_xml_accumulated_sequence_of_tag_names = "-" . $tag_name ;
2495 0 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 0 0
2496 {
2497 0 print "{{trace; default top-level tag name: " . $tag_name . "}}\n" ;
2498 }
2499 } else
2500 {
2501 0 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 0 0
2502 {
2503 0 print "{{trace; ignored tag: " . $tag_name . "}}\n" ;
2504 }
2505 }
2506 } else
2507 {
2508 11 $global_xml_level_number ++ ;
2509 11 $global_xml_tag_at_level_number[ $global_xml_level_number ] = $tag_name ;
2510 11 $global_xml_accumulated_sequence_of_tag_names .= "-" . $tag_name ;
2511 }
2512 13 ▶ if ( length( $global_xml_accumulated_sequence_of_tag_names ) > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (length $global_xml_accumulated_sequence_of_tag_names > 0) 13 0 13
2513 {
2514 13 $full_phrase = "begin" . $global_xml_accumulated_sequence_of_tag_names ;
2515 13 ▶ if ( ( exists( $global_dashrep_replacement{ "dashrep-xml-yes-ignore-if-no-tag-replacement" } ) ) && ( $global_dashrep_replacement{ "dashrep-xml-yes-ignore-if-no-tag-replacement" } eq "yes" ) && ( not( exists( $global_dashrep_replacement{ $full_phrase } ) ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} and $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} eq "yes" and not exists $global_dashrep_replacement{$full_phrase}) 0 13 13
Condition33%2/6
exists $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} and $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} eq "yes" and not exists $global_dashrep_replacement{$full_phrase}
!ll&&!rl&&r
1300
exists $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} and $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} eq "yes"
!ll&&!rl&&r
1300
MC/DC0%0/3
exists $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} and $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} eq "yes" and not exists $global_dashrep_replacement{$full_phrase}
exists $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} eq "yes" not exists $global_dashrep_replacement{$full_phrase}
Truth table25%1/4
A and B and not(C)
A= exists $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"}B= $global_dashrep_replacement{"dashrep-xml-yes-ignore-if-no-tag-replacement"} eq "yes"C= not exists $global_dashrep_replacement{$full_phrase}
ABCresult
0XX0
10X0
1100
1111
2516 {
2517 0 $global_ignore_level ++ ;
2518 }
2519 13 ▶ if ( exists( $global_dashrep_replacement{ $full_phrase } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$full_phrase}) 0 13 13
2520 {
2521 0 $global_ignore_level = 0 ;
2522 }
2523 13 ▶ if ( $global_ignore_level <= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_ignore_level <= 0) 13 0 13
2524 {
2525 13 $output_text .= substr( $global_spaces , 0 , ( 2 * ( $global_xml_level_number - 1 ) ) ) ;
2526 13 $output_text .= "[-" ;
2527 13 ▶ if ( exists( $global_dashrep_replacement{ $full_phrase } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $global_dashrep_replacement{$full_phrase}) { } 0 13 13
2528 {
2529 0 $output_text .= $global_dashrep_replacement{ $full_phrase } ;
2530 } else
2531 {
2532 13 $output_text .= $full_phrase ;
2533 }
2534 13 $output_text .= "-]" ;
2535 13 $output_text .= "\n" ;
2536 }
2537 13 $sequence_without_hyphen_prefix = $global_xml_accumulated_sequence_of_tag_names ;
2538 13 $sequence_without_hyphen_prefix =~ s/^\-// ;
2539 13 $global_exists_xml_hyphenated_phrase{ $sequence_without_hyphen_prefix } = "exists" ;
2540 }
2541 }
2542  
2543  
2544 #-----------------------------------------------
2545 # Repeat the loop for the next tag in the
2546 # input line.
2547  
2548 }
2549  
2550  
2551 #-----------------------------------------------
2552 # If the non-tag content text contains any
2553 # hyphens, replace them with the phrase
2554 # "hypen-here".
2555  
2556 3 $input_text =~ s/\-/dashrep_internal_hyphen_here/sg ;
2557 3 $input_text =~ s/dashrep_internal_hyphen_here/ hyphen-here /sg ;
2558  
2559  
2560 #-----------------------------------------------
2561 # If any text follows the last tag, write it on a
2562 # separate line.
2563  
2564 3 ▶ if ( $input_text =~ /^ *([^ ].*)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($input_text =~ /^ *([^ ].*)$/) 0 3 3
2565 {
2566 0 $input_text = $1 ;
2567 0 $output_text .= "\n" . $input_text ;
2568 0 $input_text = "" ;
2569 }
2570  
2571  
2572 #-----------------------------------------------
2573 # End of subroutine.
2574  
2575 3 return $output_text ;
2576  
2577 }
2578  
2579  
2580 =head2 dashrep_top_level_action
2581  
2582 Handles a top-level action such as a transfer
2583 to and from files.
2584  
2585 First, and only, parameter is the
2586 text string that contains any text, which
2587 may include one top-level action (which is
2588 a hyphenated phrase).
2589  
2590 Return value is the text string after removing
2591 the executed action, or the original text
2592 string if there was no action phrase.
2593 Return value is an empty string if there
2594 is not exactly one parameter.
2595  
2596 =cut
2597  
2598  
2599 #-----------------------------------------------
2600 #-----------------------------------------------
2601 # dashrep_top_level_action
2602 #-----------------------------------------------
2603 #-----------------------------------------------
2604  
2605 sub dashrep_top_level_action
2606 21 ▶{
Subroutine dashrep_top_level_action: called CC=103 SCAR=70.3
Pod documented
2607  
2608 21 my $source_definitions ;
2609 my $input_text ;
2610 21 my $translation ;
2611 21 my $partial_translation ;
2612 21 my $source_filename ;
2613 21 my $target_filename ;
2614 21 my $source_phrase ;
2615 21 my $target_phrase ;
2616 21 my $lines_to_translate ;
2617 21 my $line_count ;
2618 21 my $text_list_of_phrases ;
2619 21 my $possible_error_message ;
2620 21 my $all_defs_begin ;
2621 21 my $all_defs_end ;
2622 21 my $phrase_begin ;
2623 21 my $phrase_end ;
2624 21 my $def_begin ;
2625 21 my $def_end ;
2626 21 my $all_lines ;
2627 21 my $input_line ;
2628 21 my $phrase_name ;
2629 21 my $tracking_on_or_off ;
2630 21 my $qualifier ;
2631 21 my $numeric_return_value ;
2632 21 my $full_line ;
2633 21 my $multi_line_limit ;
2634 21 my $open_brackets ;
2635 21 my $close_brackets ;
2636 21 my $multi_line_count ;
2637 21 my $xml_hyphenated_phrase ;
2638 21 my $counter ;
2639 21 my @list_of_phrases ;
2640  
2641  
2642 #-----------------------------------------------
2643 # Reset the xml-parsing state.
2644  
2645 21 $global_xml_level_number = 0 ;
2646 21 @global_xml_tag_at_level_number = ( ) ;
2647  
2648  
2649 #-----------------------------------------------
2650 # Get the input text.
2651  
2652 21 ▶ if ( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 21 0 21
2653 {
2654 21 $input_text = $_[ 0 ] ;
2655 } else
2656 {
2657 0 carp "Warning: Call to dashrep_top_level_action subroutine does not have exactly one parameter." ;
2658 0 return 0 ;
2659 }
2660  
2661  
2662 #-----------------------------------------------
2663 # Clear the error message.
2664  
2665 21 $possible_error_message = "" ;
2666  
2667  
2668 #-----------------------------------------------
2669 # Ensure this function is not called recursively.
2670  
2671 21 $global_nesting_level_of_file_actions ++ ;
2672 21 ▶ if ( $global_nesting_level_of_file_actions > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_nesting_level_of_file_actions > 1) 0 21 21
2673 {
2674 0 carp "Warning: Call to dashrep_top_level_action subroutine called recursivley, which is not allowed." ;
2675 0 return 0 ;
2676 }
2677  
2678  
2679 #-----------------------------------------------
2680 # In case definitions are exported, specify
2681 # which delimiters to use -- based on the "yes"
2682 # or "no" definition of the phrase
2683 # "dashrep-yes-or-no-export-delimited-definitions".
2684  
2685 21 ▶ if ( $global_dashrep_replacement{ "dashrep-yes-or-no-export-delimited-definitions" } eq "yes" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{'dashrep-yes-or-no-export-delimited-definitions'} eq 'yes') { } 0 21 21
2686 {
2687 0 $all_defs_begin = "export-defs-all-begin\n\n" ;
2688 0 $all_defs_end = "export-defs-all-end\n\n" ;
2689 0 $phrase_begin = "export-defs-phrase-begin " ;
2690 0 $phrase_end = " export-defs-phrase-end\n\n" ;
2691 0 $def_begin = "export-defs-def-begin " ;
2692 0 $def_end = " export-defs-def-end\n\n" ;
2693 } else
2694 {
2695 21 $all_defs_begin = "dashrep-definitions-begin\n\n" ;
2696 21 $all_defs_end = "dashrep-definitions-end\n\n" ;
2697 21 $phrase_begin = "" ;
2698 21 $phrase_end = ":\n" ;
2699 21 $def_begin = "" ;
2700 21 $def_end = "\n-----\n\n" ;
2701 }
2702  
2703  
2704 #-----------------------------------------------
2705 # Handle the action:
2706 # append-from-phrase-to-phrase
2707  
2708 21 ▶ if ( $input_text =~ /^ *append-from-phrase-to-phrase +([^ \[\]]+) +([^ \[\]]+) *$/ )
Branch: 12 branches
BranchTrueFalseTotal
if ($input_text =~ /^ *append-from-phrase-to-phrase +([^ \[\]]+) +([^ \[\]]+) *$/) { } 1 20 21
elsif ($input_text =~ /^ *copy-from-phrase-append-to-file +([^ \[\]]+) +([^ \[\]]+) *$/) { } 2 18 20
elsif ($input_text =~ /^ *expand-phrase-to-file +([^ \[\]]+) +([^ \[\]]+) *$/) { } 0 18 18
elsif ($input_text =~ /^ *copy-from-file-to-phrase +([^ \[\]]+) +([^ \[\]]+) *$/) { } 3 15 18
elsif ($input_text =~ /^ *create-empty-file +([^ \[\]]+) *$/) { } 3 12 15
elsif ($input_text =~ /^ *delete-file +([^ \[\]]+) *$/) { } 7 5 12
elsif ($input_text =~ /^ *write-all-dashrep-definitions-to-file +([^ \[\]]+) *$/) { } 1 4 5
elsif ($input_text =~ /^ *write-dashrep-definitions-listed-in-phrase-to-file +([^ \[\]]+) +([^ \[\]]+) *$/) { } 0 4 4
elsif ($input_text =~ /^ *get-definitions-from-file +([^ \[\]]+) *$/) { } 1 3 4
elsif ($input_text =~ /^ *clear-all-dashrep-phrases *$/) { } 1 2 3
elsif ($input_text =~ /^ *linewise-translate(()|(-parameters-only)|(-phrases-only)|(-special-phrases-only))-from-file-to-file +([^ \[\]]+) +([^ \[\]]+) *$/) { } 1 1 2
elsif ($input_text =~ /^ *linewise-translate-xml-tags-in-file-to-dashrep-phrases-in-file +([^ \[\]]+) +([^ \[\]]+) *$/) { } 1 0 1
2709 {
2710 1 $source_phrase = $1 ;
2711 1 $target_phrase = $2 ;
2712 1 $global_dashrep_replacement{ $target_phrase } .= " " . $global_dashrep_replacement{ $source_phrase } ;
2713 1 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 1 1
2714 {
2715 0 print "{{trace; appended from phrase " . $source_phrase . " to phrase " . $target_phrase . "}}\n" ;
2716 }
2717 1 $input_text = "" ;
2718  
2719  
2720 #-----------------------------------------------
2721 # Handle the action:
2722 # copy-from-phrase-append-to-file
2723 #
2724 # The filename is edited to remove any path
2725 # specifications, so that only local files
2726 # are affected.
2727  
2728 } elsif ( $input_text =~ /^ *copy-from-phrase-append-to-file +([^ \[\]]+) +([^ \[\]]+) *$/ )
2729 {
2730 2 $source_phrase = $1 ;
2731 2 $target_filename = $2 ;
2732 2 $target_filename =~ s/^.*[\\\/]// ;
2733 2 $target_filename =~ s/^\.+// ;
2734 2 ▶ if ( open ( OUTFILE , ">>" . $target_filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open OUTFILE, '>>' . $target_filename) { } 2 0 2
2735 {
2736 2 $possible_error_message .= "" ;
2737 } else
2738 {
2739 0 $possible_error_message .= " [file named " . $target_filename . " could not be opened for writing]" ;
2740 }
2741 2 ▶ if ( $possible_error_message eq "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_error_message eq '') { } 2 0 2
2742 {
2743 2 print OUTFILE "\n" . $global_dashrep_replacement{ $source_phrase } . "\n" ;
2744 2 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 2 2
2745 {
2746 0 print "{{trace; copied from phrase " . $source_phrase . " to end of file " . $target_filename . "}}\n" ;
2747 }
2748 } else
2749 {
2750 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
2751 {
2752 0 print "{{trace; error: " . $possible_error_message . "}}\n" ;
2753 }
2754 }
2755 2 close( OUTFILE ) ;
2756 2 $input_text = "" ;
2757  
2758  
2759 #-----------------------------------------------
2760 # Handle the action:
2761 # expand-phrase-to-file
2762 #
2763 # The filename is edited to remove any path
2764 # specifications, so that only local files
2765 # are affected.
2766  
2767 } elsif ( $input_text =~ /^ *expand-phrase-to-file +([^ \[\]]+) +([^ \[\]]+) *$/ )
2768 {
2769 0 $source_phrase = $1 ;
2770 0 $target_filename = $2 ;
2771 0 $target_filename =~ s/^.*[\\\/]// ;
2772 0 $target_filename =~ s/^\.+// ;
2773 0 ▶ if ( open ( OUTFILE , ">" . $target_filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open OUTFILE, '>' . $target_filename) { } 0 0 0
2774 {
2775 0 $possible_error_message .= "" ;
2776 } else
2777 {
2778 0 $possible_error_message .= " [file named " . $target_filename . " could not be opened for writing]" ;
2779 }
2780 0 ▶ if ( $possible_error_message eq "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_error_message eq '') { } 0 0 0
2781 {
2782 0 $partial_translation = &dashrep_expand_parameters( $source_phrase );
2783 0 ▶ if ( $global_dashrep_replacement{ "dashrep-debug-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-debug-trace-on-or-off"} eq "on") 0 0 0
2784 {
2785 0 print "{{trace; after parameters expanded: " . $partial_translation . "}}\n" ;
2786 }
2787 0 $translation = &dashrep_expand_phrases( $partial_translation );
2788 0 print OUTFILE $translation . "\n" ;
2789 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
2790 {
2791 0 print "{{trace; expanded phrase " . $source_phrase . " to file " . $target_filename . "}}\n" ;
2792 }
2793 } else
2794 {
2795 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
2796 {
2797 0 print "{{trace; error: " . $possible_error_message . "}}\n" ;
2798 }
2799 }
2800 0 close( OUTFILE ) ;
2801 0 $input_text = "" ;
2802  
2803  
2804 #-----------------------------------------------
2805 # Handle the action:
2806 # copy-from-file-to-phrase
2807  
2808 } elsif ( $input_text =~ /^ *copy-from-file-to-phrase +([^ \[\]]+) +([^ \[\]]+) *$/ )
2809 {
2810 3 $source_filename = $1 ;
2811 3 $target_phrase = $2 ;
2812 3 ▶ if ( open ( INFILE , "<" . $source_filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open INFILE, '<' . $source_filename) { } 3 0 3
2813 {
2814 3 $possible_error_message .= "" ;
2815 } else
2816 {
2817 0 $possible_error_message .= " [file named " . $source_filename . " not found, or could not be opened]" ;
2818 }
2819 3 ▶ if ( $possible_error_message eq "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_error_message eq '') { } 3 0 3
2820 {
2821 3 $possible_error_message .= " [file named " . $source_filename . " found, and opened]" ;
2822 3 $all_lines = "" ;
2823 3 ▶ while( $input_line = <INFILE> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($input_line = readline INFILE)) 34 3 37
2824 {
2825 34 chomp( $input_line ) ;
2826 34 $input_line =~ s/[\n\r\f\t]+/ /g ;
2827 34 $all_lines .= $input_line . "\n" ;
2828 }
2829 3 $global_dashrep_replacement{ $target_phrase } = $all_lines ;
2830 3 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 3 3
2831 {
2832 0 print "{{trace; copied from file " . $source_filename . " to phrase " . $target_phrase . "}}\n" ;
2833 }
2834 } else
2835 {
2836 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
2837 {
2838 0 print "{{trace; error: " . $possible_error_message . "}}\n" ;
2839 }
2840 }
2841 3 close( INFILE ) ;
2842 3 $input_text = "" ;
2843  
2844  
2845 #-----------------------------------------------
2846 # Handle the action:
2847 # create-empty-file
2848 #
2849 # The filename is edited to remove any path
2850 # specifications, so that only local files
2851 # are affected.
2852  
2853 } elsif ( $input_text =~ /^ *create-empty-file +([^ \[\]]+) *$/ )
2854 {
2855 3 $target_filename = $1 ;
2856 3 $target_filename =~ s/^.*[\\\/]// ;
2857 3 $target_filename =~ s/^\.+// ;
2858 3 ▶ if ( open ( OUTFILE , ">" . $target_filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open OUTFILE, '>' . $target_filename) { } 3 0 3
2859 {
2860 3 $possible_error_message .= "" ;
2861 } else
2862 {
2863 0 $possible_error_message .= " [file named " . $target_filename . " could not be created]" ;
2864 }
2865 3 ▶ if ( $possible_error_message eq "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_error_message eq '') { } 3 0 3
2866 {
2867 3 print OUTFILE "" ;
2868 3 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 3 3
2869 {
2870 0 print "{{trace; created empty file: " . $target_filename . "}}\n" ;
2871 }
2872 } else
2873 {
2874 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
2875 {
2876 0 print "{{trace; error: " . $possible_error_message . "}}\n" ;
2877 }
2878 }
2879 3 close( OUTFILE ) ;
2880 3 $input_text = "" ;
2881  
2882  
2883 #-----------------------------------------------
2884 # Handle the action:
2885 # delete-file
2886 #
2887 # The filename is edited to remove any path
2888 # specifications, so that only local files
2889 # are affected.
2890  
2891 } elsif ( $input_text =~ /^ *delete-file +([^ \[\]]+) *$/ )
2892 {
2893 7 $target_filename = $1 ;
2894 7 $target_filename =~ s/^.*[\\\/]// ;
2895 7 $target_filename =~ s/^\.+// ;
2896 7 unlink $target_filename ;
2897 7 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 7 7
2898 {
2899 0 print "{{trace; deleted file: " . $target_filename . "}}\n" ;
2900 }
2901 7 $input_text = "" ;
2902  
2903  
2904 #-----------------------------------------------
2905 # Handle the action:
2906 # write-all-dashrep-definitions-to-file
2907 #
2908 # The filename is edited to remove any path
2909 # specifications, so that only local files
2910 # are affected.
2911  
2912 } elsif ( $input_text =~ /^ *write-all-dashrep-definitions-to-file +([^ \[\]]+) *$/ )
2913 {
2914 1 $target_filename = $1 ;
2915 1 $target_filename =~ s/^.*[\\\/]// ;
2916 1 $target_filename =~ s/^\.+// ;
2917 1 @list_of_phrases = &dashrep_get_list_of_phrases( ) ;
2918 1 ▶ if ( $#list_of_phrases < 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($#list_of_phrases < 0) { } 0 1 1
2919 {
2920 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
2921 {
2922 0 print "{{trace; warning: no phrases to write (to file)}}\n" ;
2923 }
2924 } else
2925 {
2926 1 ▶ if ( open ( OUTFILE , ">" . $target_filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open OUTFILE, '>' . $target_filename) { } 1 0 1
2927 {
2928 1 $possible_error_message .= "" ;
2929 } else
2930 {
2931 0 $possible_error_message .= " [file named " . $target_filename . " could not be opened for writing]" ;
2932 }
2933 1 ▶ if ( $possible_error_message eq "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_error_message eq '') { } 1 0 1
2934 {
2935 1 $counter = 0 ;
2936 1 print OUTFILE $all_defs_begin ;
2937 1 foreach $phrase_name ( sort( @list_of_phrases ) )
2938 {
2939 93 ▶ if ( ( defined( $phrase_name ) ) &&( $phrase_name =~ /[^ ]/ ) && ( exists( $global_dashrep_replacement{ $phrase_name } ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $phrase_name and $phrase_name =~ /[^ ]/ and exists $global_dashrep_replacement{$phrase_name}) 93 0 93
Condition33%2/6
defined $phrase_name and $phrase_name =~ /[^ ]/ and exists $global_dashrep_replacement{$phrase_name}
!ll&&!rl&&r
0093
defined $phrase_name and $phrase_name =~ /[^ ]/
!ll&&!rl&&r
0093
MC/DC0%0/3
defined $phrase_name and $phrase_name =~ /[^ ]/ and exists $global_dashrep_replacement{$phrase_name}
defined $phrase_name $phrase_name =~ /[^ ]/ exists $global_dashrep_replacement{$phrase_name}
Truth table25%1/4
A and B and C
A= defined $phrase_nameB= $phrase_name =~ /[^ ]/C= exists $global_dashrep_replacement{$phrase_name}
ABCresult
0XX0
10X0
1100
1111
2940 {
2941 93 print OUTFILE $phrase_begin . $phrase_name . $phrase_end . $def_begin . $global_dashrep_replacement{ $phrase_name } . $def_end ;
2942 93 $counter ++ ;
2943 }
2944 }
2945 1 print OUTFILE $all_defs_end ;
2946 1 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 1 1
2947 {
2948 0 print "{{trace; wrote " . $counter . " definitions to file: " . $target_filename . "}}\n" ;
2949 }
2950 } else
2951 {
2952 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
2953 {
2954 0 print "{{trace; error: " . $possible_error_message . "}}\n" ;
2955 }
2956 }
2957 }
2958 1 close( OUTFILE ) ;
2959 1 $input_text = "" ;
2960  
2961  
2962 #-----------------------------------------------
2963 # Handle the action:
2964 # write-dashrep-definitions-listed-in-phrase-to-file
2965 #
2966 # The filename is edited to remove any path
2967 # specifications, so that only local files
2968 # are affected.
2969  
2970 } elsif ( $input_text =~ /^ *write-dashrep-definitions-listed-in-phrase-to-file +([^ \[\]]+) +([^ \[\]]+) *$/ )
2971 {
2972 0 $source_phrase = $1 ;
2973 0 $target_filename = $2 ;
2974 0 $target_filename =~ s/^.*[\\\/]// ;
2975 0 $target_filename =~ s/^\.+// ;
2976 0 $text_list_of_phrases = $global_dashrep_replacement{ $source_phrase } ;
2977 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
2978 {
2979 0 print "{{trace; phrase that contains list of phrases to export: " . $source_phrase . "}}\n" ;
2980 0 print "{{trace; list of phrases for exporting definitions to file: " . $text_list_of_phrases . "}}\n" ;
2981 }
2982 0 @list_of_phrases = &dashrep_internal_split_delimited_items( $text_list_of_phrases ) ;
2983 0 ▶ if ( open ( OUTFILE , ">" . $target_filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open OUTFILE, '>' . $target_filename) { } 0 0 0
2984 {
2985 0 $possible_error_message .= "" ;
2986 } else
2987 {
2988 0 $possible_error_message .= " [file named " . $target_filename . " could not be opened for writing]" ;
2989 }
2990 0 ▶ if ( $possible_error_message eq "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_error_message eq '') { } 0 0 0
2991 {
2992 0 $counter = 0 ;
2993 0 print OUTFILE $all_defs_begin ;
2994 0 foreach $phrase_name ( sort( @list_of_phrases ) )
2995 {
2996 0 ▶ if ( ( defined( $phrase_name ) ) && ( $phrase_name =~ /[^ ]/ ) && ( exists( $global_dashrep_replacement{ $phrase_name } ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $phrase_name and $phrase_name =~ /[^ ]/ and exists $global_dashrep_replacement{$phrase_name}) 0 0 0
Condition0%0/6
defined $phrase_name and $phrase_name =~ /[^ ]/ and exists $global_dashrep_replacement{$phrase_name}
!ll&&!rl&&r
000
defined $phrase_name and $phrase_name =~ /[^ ]/
!ll&&!rl&&r
000
MC/DC0%0/3
defined $phrase_name and $phrase_name =~ /[^ ]/ and exists $global_dashrep_replacement{$phrase_name}
defined $phrase_name $phrase_name =~ /[^ ]/ exists $global_dashrep_replacement{$phrase_name}
Truth table0%0/4
A and B and C
A= defined $phrase_nameB= $phrase_name =~ /[^ ]/C= exists $global_dashrep_replacement{$phrase_name}
ABCresult
0XX0
10X0
1100
1111
2997 {
2998 0 print OUTFILE $phrase_begin . $phrase_name . $phrase_end . $def_begin . $global_dashrep_replacement{ $phrase_name } . $def_end ;
2999 0 $counter ++ ;
3000 }
3001 }
3002 0 print OUTFILE $all_defs_end ;
3003 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
3004 {
3005 0 print "{{trace; wrote " . $counter . " definitions to file: " . $target_filename . "}}\n" ;
3006 }
3007 } else
3008 {
3009 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
3010 {
3011 0 print "{{trace; error: " . $possible_error_message . "}}\n" ;
3012 }
3013 }
3014 0 close( OUTFILE ) ;
3015 0 $input_text = "" ;
3016  
3017  
3018 #-----------------------------------------------
3019 # Handle the action:
3020 # get-definitions-from-file
3021  
3022 } elsif ( $input_text =~ /^ *get-definitions-from-file +([^ \[\]]+) *$/ )
3023 {
3024 1 $source_filename = $1 ;
3025 1 $source_filename =~ s/[ \t]+//g ;
3026 1 ▶ if ( open ( INFILE , "<" . $source_filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open INFILE, '<' . $source_filename) { } 1 0 1
3027 {
3028 1 $possible_error_message = "" ;
3029 } else
3030 {
3031 0 ▶ if ( -e $source_filename )
Branch: 1 branch
BranchTrueFalseTotal
if (-e $source_filename) { } 0 0 0
3032 {
3033 0 $possible_error_message .= " [file named " . $source_filename . " found, but could not be opened]" ;
3034 } else
3035 {
3036 0 $possible_error_message .= " [file named " . $source_filename . " not found]" ;
3037 }
3038 }
3039 1 ▶ if ( $possible_error_message eq "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_error_message eq '') { } 1 0 1
3040 {
3041 1 $possible_error_message .= " [file named " . $source_filename . " found, and opened]" ;
3042 1 $source_definitions = "" ;
3043 1 ▶ while( $input_line = <INFILE> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($input_line = readline INFILE)) 395 1 396
3044 {
3045 395 chomp( $input_line ) ;
3046 395 $input_line =~ s/[\n\r\f\t]+/ /g ;
3047 395 ▶ if ( ( defined( $input_line ) ) && ( $input_line =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $input_line and $input_line =~ /[^ ]/) 278 117 395
Condition66%2/3
defined $input_line and $input_line =~ /[^ ]/
!ll&&!rl&&r
0117278
MC/DC50%1/2
defined $input_line and $input_line =~ /[^ ]/
defined $input_line $input_line =~ /[^ ]/
Truth table66%2/3
A and B
A= defined $input_lineB= $input_line =~ /[^ ]/
ABresult
0X0
100
111
3048 {
3049 278 $source_definitions .= $input_line . " " ;
3050 }
3051 }
3052 1 $numeric_return_value = &dashrep_import_replacements( $source_definitions ) ;
3053 1 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 1 1
3054 {
3055 0 print "{{trace; imported " . $numeric_return_value . " definitions from file: " . $source_filename . "}}\n" ;
3056 }
3057 } else
3058 {
3059 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
3060 {
3061 0 print "{{trace; error: " . $possible_error_message . "}}\n" ;
3062 }
3063 }
3064 1 close( INFILE ) ;
3065 1 $input_text = "" ;
3066  
3067  
3068 #-----------------------------------------------
3069 # Handle the action:
3070 # clear-all-dashrep-phrases
3071  
3072 } elsif ( $input_text =~ /^ *clear-all-dashrep-phrases *$/ )
3073 {
3074 1 $tracking_on_or_off = $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } ;
3075 1 &dashrep_delete_all( );
3076 1 ▶ if ( $tracking_on_or_off eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($tracking_on_or_off eq "on") 0 1 1
3077 {
3078 0 print "{{trace; cleared all definitions}}\n" ;
3079 }
3080 1 $global_endless_loop_counter = 0 ;
3081 1 $input_text = "" ;
3082  
3083  
3084 #-----------------------------------------------
3085 # Handle the actions:
3086 # linewise-translate-from-file-to-file and
3087 # linewise-translate-parameters-only-from-file-to-file
3088 # linewise-translate-phrases-only-from-file-to-file
3089 # linewise-translate-special-phrases-only-from-file-to-file
3090 #
3091 # The output filename is edited to remove any path
3092 # specifications, so that only local files
3093 # are affected.
3094 #
3095 # If there are Dashrep definitions, get them.
3096  
3097 } elsif ( $input_text =~ /^ *linewise-translate(()|(-parameters-only)|(-phrases-only)|(-special-phrases-only))-from-file-to-file +([^ \[\]]+) +([^ \[\]]+) *$/ )
3098 {
3099 1 $qualifier = $1 ;
3100 1 $source_filename = $6 ;
3101 1 $target_filename = $7 ;
3102 1 $source_filename =~ s/[ \t]+//g ;
3103 1 $target_filename =~ s/^.*[\\\/]// ;
3104 1 $target_filename =~ s/^\.+// ;
3105 1 ▶ if ( open ( INFILE , "<" . $source_filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open INFILE, '<' . $source_filename) { } 1 0 1
3106 {
3107 1 $possible_error_message .= "" ;
3108 } else
3109 {
3110 0 ▶ if ( -e $source_filename )
Branch: 1 branch
BranchTrueFalseTotal
if (-e $source_filename) { } 0 0 0
3111 {
3112 0 $possible_error_message .= " [file named " . $source_filename . " exists, but could not be opened]" ;
3113 } else
3114 {
3115 0 $possible_error_message .= " [file named " . $source_filename . " not found]" ;
3116 }
3117 }
3118 1 ▶ if ( open ( OUTFILE , ">" . $target_filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open OUTFILE, '>' . $target_filename) { } 1 0 1
3119 {
3120 1 $possible_error_message .= "" ;
3121 } else
3122 {
3123 0 $possible_error_message .= " [file named " . $target_filename . " could not be opened for writing]" ;
3124 }
3125 1 ▶ if ( $possible_error_message eq "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_error_message eq '') { } 1 0 1
3126 {
3127 1 $global_ignore_level = 0 ;
3128 1 $global_capture_level = 0 ;
3129 1 $global_top_line_count_for_insert_phrase = 0 ;
3130 1 ▶ while( $input_line = <INFILE> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($input_line = readline INFILE)) 2 1 3
3131 {
3132 2 chomp( $input_line ) ;
3133 2 $input_line =~ s/[\n\r\f\t]+/ /g ;
3134 2 $global_endless_loop_counter = 0 ;
3135 2 %global_replacement_count_for_item_name = ( ) ;
3136 2 $lines_to_translate = 1 ;
3137 2 ▶ while ( $lines_to_translate > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($lines_to_translate > 0) 2 2 4
3138 {
3139 2 ▶ if ( $input_line =~ /^ *dashrep-definitions-begin *$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^ *dashrep-definitions-begin *$/) { } 0 2 2
3140 {
3141 0 $all_lines = "" ;
3142 0 $line_count = 0 ;
3143 0 ▶ while( $input_line = <INFILE> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($input_line = readline INFILE)) 0 0 0
3144 {
3145 0 chomp( $input_line );
3146 0 $input_line =~ s/[\n\r\f\t]+/ /g ;
3147 0 ▶ if ( $input_line =~ /^ *dashrep-definitions-end *$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^ *dashrep-definitions-end *$/) 0 0 0
3148 {
3149 0 last;
3150 }
3151 0 ▶ if ( ( $input_line =~ /[^ ]/ ) && ( defined( $input_line ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /[^ ]/ and defined $input_line) 0 0 0
Condition0%0/3
$input_line =~ /[^ ]/ and defined $input_line
!ll&&!rl&&r
000
MC/DC0%0/2
$input_line =~ /[^ ]/ and defined $input_line
$input_line =~ /[^ ]/ defined $input_line
Truth table0%0/3
A and B
A= $input_line =~ /[^ ]/B= defined $input_line
ABresult
0X0
100
111
3152 {
3153 0 $all_lines .= $input_line . " " ;
3154 }
3155 0 $line_count ++ ;
3156 }
3157 0 ▶ if ( $all_lines =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($all_lines =~ /[^ ]/) 0 0 0
3158 {
3159 0 $numeric_return_value = &dashrep_import_replacements( $all_lines );
3160 0 ▶ if ( ( $global_dashrep_replacement{ "dashrep-linewise-trace-on-or-off" } eq "on" ) && ( $input_line =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $input_line =~ /[^ ]/) 0 0 0
Condition0%0/3
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $input_line =~ /[^ ]/
!ll&&!rl&&r
000
MC/DC0%0/2
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $input_line =~ /[^ ]/
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" $input_line =~ /[^ ]/
Truth table0%0/3
A and B
A= $global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on"B= $input_line =~ /[^ ]/
ABresult
0X0
100
111
3161 {
3162 0 print "{{trace; definitions found, imported " . $numeric_return_value . " definitions from " . $line_count . " lines}}\n" ;
3163 }
3164 }
3165 0 $lines_to_translate = 0 ;
3166 } else
3167 {
3168 2 $lines_to_translate = 0 ;
3169 2 ▶ if ( $qualifier eq "-parameters-only" )
Branch: 3 branches
BranchTrueFalseTotal
if ($qualifier eq '-parameters-only') { } 0 2 2
elsif ($qualifier eq '-phrases-only') { } 0 2 2
elsif ($qualifier eq '-special-phrases-only') { } 0 2 2
3170 {
3171 0 $translation = &dashrep_expand_parameters( $input_line );
3172 } elsif ( $qualifier eq "-phrases-only" )
3173 {
3174 0 $translation = &dashrep_expand_phrases( $input_line );
3175 } elsif ( $qualifier eq "-special-phrases-only" )
3176 {
3177 0 $translation = &dashrep_expand_special_phrases( $input_line );
3178 } else
3179 {
3180 2 $partial_translation = &dashrep_expand_parameters( $input_line );
3181 2 $translation = &dashrep_expand_phrases( $partial_translation );
3182 }
3183 2 ▶ if ( ( $translation =~ /[^ ]/ ) && ( ( $global_ignore_level < 1 ) || ( $global_capture_level < 1 ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($translation =~ /[^ ]/ and $global_ignore_level < 1 || $global_capture_level < 1) 1 1 2
Condition50%3/6
$translation =~ /[^ ]/ and $global_ignore_level < 1 || $global_capture_level < 1
!ll&&!rl&&r
101
$global_ignore_level < 1 or $global_capture_level < 1
l!l&&r!l&&!r
100
MC/DC33%1/3
$translation =~ /[^ ]/ and $global_ignore_level < 1 || $global_capture_level < 1
$translation =~ /[^ ]/ $global_ignore_level < 1 $global_capture_level < 1
Truth table50%2/4
A and B or C
A= $translation =~ /[^ ]/B= $global_ignore_level < 1C= $global_capture_level < 1
ABCresult
0XX0
1000
11X1
1011
3184 {
3185 1 print OUTFILE $translation . "\n" ;
3186 }
3187 2 ▶ if ( $global_top_line_count_for_insert_phrase == 1 )
Branch: 2 branches
BranchTrueFalseTotal
if ($global_top_line_count_for_insert_phrase == 1) { } 0 2 2
elsif ($global_top_line_count_for_insert_phrase == 2) { } 0 2 2
3188 {
3189 0 $global_top_line_count_for_insert_phrase = 2 ;
3190 } elsif ( $global_top_line_count_for_insert_phrase == 2 )
3191 {
3192 0 $global_top_line_count_for_insert_phrase = 0 ;
3193 0 ▶ if ( $global_phrase_to_insert_after_next_top_level_line ne "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_phrase_to_insert_after_next_top_level_line ne "") 0 0 0
3194 {
3195 0 $input_line = "[-" . $global_phrase_to_insert_after_next_top_level_line . "-]" ;
3196 0 $lines_to_translate = 1 ;
3197 }
3198 }
3199 }
3200 }
3201 }
3202 1 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 1 1
3203 {
3204 0 print "{{trace; linewise translated from file " . $source_filename . " to file " . $target_filename . "}}\n" ;
3205 }
3206 } else
3207 {
3208 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
3209 {
3210 0 print "{{trace; failed to linewise translate from file " . $source_filename . " to file " . $target_filename . "}}\n" ;
3211 }
3212 }
3213 1 close( INFILE ) ;
3214 1 close( OUTFILE ) ;
3215 1 $input_text = "" ;
3216  
3217  
3218 #-----------------------------------------------
3219 # Handle the action:
3220 # linewise-translate-xml-tags-in-file-to-dashrep-phrases-in-file
3221 #
3222 # The output filename is edited to remove any path
3223 # specifications, so that only local files
3224 # are affected.
3225 # If a tag does not end on the same line as it
3226 # starts, more lines are read in an attempt
3227 # to reach the end of the tag, but this
3228 # capability is not robust. This is done to
3229 # accomodate XHTML generated by the "Tidy"
3230 # utility.
3231  
3232 } elsif ( $input_text =~ /^ *linewise-translate-xml-tags-in-file-to-dashrep-phrases-in-file +([^ \[\]]+) +([^ \[\]]+) *$/ )
3233 {
3234 1 $source_filename = $1 ;
3235 1 $target_filename = $2 ;
3236 1 $target_filename =~ s/^.*[\\\/]// ;
3237 1 $target_filename =~ s/^\.+// ;
3238 1 ▶ if ( open ( INFILE , "<" . $source_filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open INFILE, '<' . $source_filename) { } 1 0 1
3239 {
3240 1 $possible_error_message .= "" ;
3241 } else
3242 {
3243 0 $possible_error_message .= " [file named " . $source_filename . " not found, or could not be opened]" ;
3244 }
3245 1 ▶ if ( open ( OUTFILE , ">" . $target_filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open OUTFILE, '>' . $target_filename) { } 1 0 1
3246 {
3247 1 $possible_error_message .= "" ;
3248 } else
3249 {
3250 0 $possible_error_message .= " [file named " . $target_filename . " could not be opened for writing]" ;
3251 }
3252 1 ▶ if ( $possible_error_message eq "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_error_message eq '') { } 1 0 1
3253 {
3254 1 $full_line = "" ;
3255 1 $multi_line_limit = 10 ;
3256 1 ▶ while( $input_line = <INFILE> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($input_line = readline INFILE)) 2 1 3
3257 {
3258 2 chomp( $input_line ) ;
3259 2 $input_line =~ s/[\n\r\f\t]+/ /g ;
3260 2 ▶ if ( $full_line ne "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($full_line ne '') { } 0 2 2
3261 {
3262 0 $full_line = $full_line . " " . $input_line ;
3263 } else
3264 {
3265 2 $full_line = $input_line ;
3266 }
3267 2 $open_brackets = $full_line ;
3268 2 $close_brackets = $full_line ;
3269 2 $open_brackets =~ s/[^<]//g ;
3270 2 $close_brackets =~ s/[^>]//g ;
3271 2 ▶ if ( ( length( $open_brackets ) != length( $close_brackets ) ) && ( $multi_line_count < $multi_line_limit ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $open_brackets != length $close_brackets and $multi_line_count < $multi_line_limit) 0 2 2
Condition33%1/3
length $open_brackets != length $close_brackets and $multi_line_count < $multi_line_limit
!ll&&!rl&&r
200
MC/DC0%0/2
length $open_brackets != length $close_brackets and $multi_line_count < $multi_line_limit
length $open_brackets != length $close_brackets $multi_line_count < $multi_line_limit
Truth table33%1/3
A and B
A= length $open_brackets != length $close_bracketsB= $multi_line_count < $multi_line_limit
ABresult
0X0
100
111
3272 {
3273 0 next ;
3274 }
3275 2 ▶ if ( $global_dashrep_replacement{ "dashrep-xml-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-xml-trace-on-or-off"} eq "on") 0 2 2
3276 {
3277 0 print "{{trace; accumulated text to convert: " . $full_line . "}}\n" ;
3278 }
3279 2 $global_endless_loop_counter = 0 ;
3280 2 %global_replacement_count_for_item_name = ( ) ;
3281 2 $translation = &dashrep_xml_tags_to_dashrep( $full_line );
3282 2 print OUTFILE $translation . "\n" ;
3283 2 $full_line = "" ;
3284 }
3285 1 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 1 1
3286 {
3287 0 print "{{trace; source xml file named " . $source_filename . " expanded into dashrep phrases in file named " . $target_filename . "}}\n" ;
3288 }
3289 1 $global_dashrep_replacement{ "dashrep-list-of-xml-phrases" } = "" ;
3290 1 foreach $xml_hyphenated_phrase ( sort( keys ( %global_exists_xml_hyphenated_phrase ) ) )
3291 {
3292 9 $global_dashrep_replacement{ "dashrep-list-of-xml-phrases" } .= $xml_hyphenated_phrase . " " ;
3293 }
3294 } else
3295 {
3296 0 ▶ if ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on") 0 0 0
3297 {
3298 0 print "{{trace; failed to expand source xml file named " . $source_filename . " into dashrep phrases in file named " . $target_filename . "}}\n" ;
3299 }
3300 }
3301 1 close( INFILE ) ;
3302 1 close( OUTFILE ) ;
3303 1 $input_text = "" ;
3304  
3305  
3306 #-----------------------------------------------
3307 # Handle text that was not recognized as an
3308 # action.
3309  
3310 } else
3311 {
3312 0 ▶ if ( ( $global_dashrep_replacement{ "dashrep-action-trace-on-or-off" } eq "on" ) && ( $input_text =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" and $input_text =~ /[^ ]/) 0 0 0
Condition0%0/3
$global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" and $input_text =~ /[^ ]/
!ll&&!rl&&r
000
MC/DC0%0/2
$global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" and $input_text =~ /[^ ]/
$global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on" $input_text =~ /[^ ]/
Truth table0%0/3
A and B
A= $global_dashrep_replacement{"dashrep-action-trace-on-or-off"} eq "on"B= $input_text =~ /[^ ]/
ABresult
0X0
100
111
3313 {
3314 0 print "{{trace; not recognized as top-level action: " . $input_text . "}}\n" ;
3315 }
3316 }
3317  
3318  
3319 #-----------------------------------------------
3320 # If there was an error message, put it
3321 # into the text that is returned (and remove
3322 # the action that caused the error).
3323  
3324 21 $possible_error_message =~ s/^ +// ;
3325 21 $possible_error_message =~ s/ +$// ;
3326 21 ▶ if ( $possible_error_message =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_error_message =~ /[^ ]/) 4 17 21
3327 {
3328 4 $input_text = $possible_error_message ;
3329 }
3330  
3331  
3332 #-----------------------------------------------
3333 # Track the nesting level.
3334  
3335 21 $global_nesting_level_of_file_actions -- ;
3336  
3337  
3338 #-----------------------------------------------
3339 # Return, possibly with an error message.
3340  
3341 21 return $input_text ;
3342  
3343  
3344 #-----------------------------------------------
3345 # End of subroutine.
3346  
3347 }
3348  
3349  
3350 =head2 dashrep_linewise_translate
3351  
3352 Reads from the standard input file,
3353 does the specified Dashrep translations,
3354 and writes any requested translations
3355 into the standard output file.
3356  
3357 There are no parameters.
3358  
3359 Return value is a text string that is either
3360 empty -- if there is no error -- or else
3361 contains an error message (although currently
3362 no errors are defined).
3363  
3364 =cut
3365  
3366  
3367 #-----------------------------------------------
3368 #-----------------------------------------------
3369 # dashrep_linewise_translate
3370 #-----------------------------------------------
3371 #-----------------------------------------------
3372  
3373 sub dashrep_linewise_translate
3374 0 ▶{
Subroutine dashrep_linewise_translate: not called CC=20 SCAR=60.4
Pod documented
3375  
3376 0 my $input_line ;
3377 my $all_lines ;
3378 0 my $line_count ;
3379 0 my $numeric_return_value ;
3380 0 my $revised_text ;
3381 0 my $after_possible_action ;
3382 0 my $error_message ;
3383  
3384  
3385 #-----------------------------------------------
3386 # Ensure there is no input text.
3387  
3388 0 ▶ if ( scalar( @_ ) != 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ != 0) 0 0 0
3389 {
3390 0 carp "Warning: Call to dashrep_top_level_action subroutine does not have exactly zero parameters." ;
3391 0 return 0 ;
3392 }
3393  
3394  
3395 #-----------------------------------------------
3396 # Read each line from the input file.
3397  
3398 0 ▶ while( $input_line = <STDIN> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($input_line = readline STDIN)) 0 0 0
3399 {
3400 0 chomp( $input_line );
3401 0 $input_line =~ s/[\n\r\f\t]+/ /g ;
3402 0 ▶ if ( ( $global_dashrep_replacement{ "dashrep-linewise-trace-on-or-off" } eq "on" ) && ( $input_line =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $input_line =~ /[^ ]/) 0 0 0
Condition0%0/3
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $input_line =~ /[^ ]/
!ll&&!rl&&r
000
MC/DC0%0/2
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $input_line =~ /[^ ]/
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" $input_line =~ /[^ ]/
Truth table0%0/3
A and B
A= $global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on"B= $input_line =~ /[^ ]/
ABresult
0X0
100
111
3403 {
3404 0 print "{{trace; linewise input line: " . $input_line . "}}\n" ;
3405 }
3406  
3407  
3408 #-----------------------------------------------
3409 # If there are Dashrep definitions, get them.
3410  
3411 0 ▶ if ( $input_line =~ /^ *dashrep-definitions-begin *$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^ *dashrep-definitions-begin *$/) { } 0 0 0
3412 {
3413 0 $all_lines = "" ;
3414 0 $line_count = 0 ;
3415 0 ▶ while( $input_line = <STDIN> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($input_line = readline STDIN)) 0 0 0
3416 {
3417 0 chomp( $input_line );
3418 0 $input_line =~ s/[\n\r\f\t]+/ /g ;
3419 0 ▶ if ( $input_line =~ /^ *dashrep-definitions-end *$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^ *dashrep-definitions-end *$/) 0 0 0
3420 {
3421 0 last;
3422 }
3423 0 ▶ if ( ( $input_line =~ /[^ ]/ ) && ( defined( $input_line ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /[^ ]/ and defined $input_line) 0 0 0
Condition0%0/3
$input_line =~ /[^ ]/ and defined $input_line
!ll&&!rl&&r
000
MC/DC0%0/2
$input_line =~ /[^ ]/ and defined $input_line
$input_line =~ /[^ ]/ defined $input_line
Truth table0%0/3
A and B
A= $input_line =~ /[^ ]/B= defined $input_line
ABresult
0X0
100
111
3424 {
3425 0 $all_lines .= $input_line . " " ;
3426 }
3427 0 $line_count ++ ;
3428 }
3429 0 ▶ if ( $all_lines =~ /[^ ]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($all_lines =~ /[^ ]/) 0 0 0
3430 {
3431 0 $numeric_return_value = &dashrep_import_replacements( $all_lines );
3432 0 ▶ if ( ( $global_dashrep_replacement{ "dashrep-linewise-trace-on-or-off" } eq "on" ) && ( $input_line =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $input_line =~ /[^ ]/) 0 0 0
Condition0%0/3
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $input_line =~ /[^ ]/
!ll&&!rl&&r
000
MC/DC0%0/2
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $input_line =~ /[^ ]/
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" $input_line =~ /[^ ]/
Truth table0%0/3
A and B
A= $global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on"B= $input_line =~ /[^ ]/
ABresult
0X0
100
111
3433 {
3434 0 print "{{trace; definition line: " . $input_line . " ; imported " . $numeric_return_value . " definitions from " . $line_count . " lines}}\n" ;
3435 }
3436 }
3437  
3438  
3439 #-----------------------------------------------
3440 # Otherwise, translate this line by itself.
3441  
3442 } else
3443 {
3444 0 $global_endless_loop_counter = 0 ;
3445 0 %global_replacement_count_for_item_name = ( ) ;
3446 0 $revised_text = &dashrep_expand_parameters( $input_line );
3447 0 ▶ if ( ( $global_dashrep_replacement{ "dashrep-linewise-trace-on-or-off" } eq "on" ) && ( $revised_text =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $revised_text =~ /[^ ]/) 0 0 0
Condition0%0/3
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $revised_text =~ /[^ ]/
!ll&&!rl&&r
000
MC/DC0%0/2
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $revised_text =~ /[^ ]/
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" $revised_text =~ /[^ ]/
Truth table0%0/3
A and B
A= $global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on"B= $revised_text =~ /[^ ]/
ABresult
0X0
100
111
3448 {
3449 0 print "{{trace; line after parameters expanded: " . $revised_text . "}}\n" ;
3450 }
3451 0 $after_possible_action = &dashrep_top_level_action( $revised_text );
3452 0 ▶ if ( ( $global_dashrep_replacement{ "dashrep-linewise-trace-on-or-off" } eq "on" ) && ( $after_possible_action =~ /^ *$/ ) && ( $revised_text =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $after_possible_action =~ /^ *$/ and $revised_text =~ /[^ ]/) 0 0 0
Condition0%0/6
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $after_possible_action =~ /^ *$/ and $revised_text =~ /[^ ]/
!ll&&!rl&&r
000
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $after_possible_action =~ /^ *$/
!ll&&!rl&&r
000
MC/DC0%0/3
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $after_possible_action =~ /^ *$/ and $revised_text =~ /[^ ]/
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" $after_possible_action =~ /^ *$/ $revised_text =~ /[^ ]/
Truth table0%0/4
A and B and C
A= $global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on"B= $after_possible_action =~ /^ *$/C= $revised_text =~ /[^ ]/
ABCresult
0XX0
10X0
1100
1111
3453 {
3454 0 print "{{trace; line after action executed: " . $after_possible_action . "}}\n" ;
3455 }
3456 0 $revised_text = &dashrep_expand_phrases( $after_possible_action );
3457 0 ▶ if ( ( $global_dashrep_replacement{ "dashrep-linewise-trace-on-or-off" } eq "on" ) && ( $revised_text =~ /[^ ]/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $revised_text =~ /[^ ]/) 0 0 0
Condition0%0/3
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $revised_text =~ /[^ ]/
!ll&&!rl&&r
000
MC/DC0%0/2
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" and $revised_text =~ /[^ ]/
$global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on" $revised_text =~ /[^ ]/
Truth table0%0/3
A and B
A= $global_dashrep_replacement{"dashrep-linewise-trace-on-or-off"} eq "on"B= $revised_text =~ /[^ ]/
ABresult
0X0
100
111
3458 {
3459 0 print "{{trace; line after phrases expanded: " . $revised_text . "}}\n" ;
3460 }
3461 0 print $revised_text . "\n" ;
3462 }
3463  
3464  
3465 #-----------------------------------------------
3466 # Repeat the loop for the next line.
3467  
3468 }
3469  
3470  
3471 #-----------------------------------------------
3472 # End of subroutine.
3473  
3474 0 return $error_message ;
3475  
3476 }
3477  
3478  
3479 =head2 dashrep_internal_endless_loop_info
3480  
3481 Internal subroutine, not exported.
3482 It is only needed within the Dashrep module.
3483  
3484 =cut
3485  
3486 #-----------------------------------------------
3487 #-----------------------------------------------
3488 # Non-exported subroutine:
3489 #
3490 # dashrep_internal_endless_loop_info
3491 #-----------------------------------------------
3492 #-----------------------------------------------
3493 # This subroutine displays the name of the
3494 # most-replaced hyphenated phrase, which is
3495 # usually the one that caused the endless loop.
3496  
3497 # This subroutine is not exported because it
3498 # is only needed within this Dashrep module.
3499  
3500 # The collected information is displayed in a
3501 # warning message.
3502  
3503 sub dashrep_internal_endless_loop_info
3504 0 ▶{
Subroutine dashrep_internal_endless_loop_info: not called CC=3 SCAR=24.8
Pod documented
3505  
3506 0 my $item_name ;
3507 my $highest_usage_counter ;
3508 0 my $highest_usage_item_name ;
3509  
3510 0 $highest_usage_counter = - 1 ;
3511 0 foreach $item_name ( keys( %global_replacement_count_for_item_name ) )
3512 {
3513 0 ▶ if ( $global_replacement_count_for_item_name{ $item_name } > $highest_usage_counter )
Branch: 1 branch
BranchTrueFalseTotal
if ($global_replacement_count_for_item_name{$item_name} > $highest_usage_counter) 0 0 0
3514 {
3515 0 $highest_usage_counter = $global_replacement_count_for_item_name{ $item_name } ;
3516 0 $highest_usage_item_name = $item_name ;
3517 }
3518 }
3519 0 carp "Too many cycles of replacement (" . $global_endless_loop_counter . ").\n" . "Hyphenated phrase with highest replacement count (" . $highest_usage_counter . ") is:\n" . " " . $highest_usage_item_name . "\n" ;
3520  
3521  
3522 #-----------------------------------------------
3523 # End of subroutine.
3524  
3525 0 return 1 ;
3526  
3527 }
3528  
3529  
3530 =head2 dashrep_internal_split_delimited_items
3531  
3532 Internal subroutine, not exported.
3533 It is only needed within the Dashrep module.
3534  
3535 =cut
3536  
3537  
3538 #-----------------------------------------------
3539 #-----------------------------------------------
3540 # Non-exported subroutine:
3541 #
3542 # dashrep_internal_split_delimited_items
3543 #-----------------------------------------------
3544 #-----------------------------------------------
3545 # This subroutine converts a text-format list
3546 # of text items separated by commas, spaces, or
3547 # line breaks into an array of separate
3548 # text strings. It does not expand any
3549 # hyphenated phrases.
3550  
3551 # This subroutine is not exported because it
3552 # is only needed within this Dashrep module.
3553  
3554 sub dashrep_internal_split_delimited_items
3555 16 ▶{
Subroutine dashrep_internal_split_delimited_items: called CC=3 SCAR=11.7
Pod documented
3556 16 my $text_string ;
3557 my @array ;
3558  
3559 16 $text_string = $_[ 0 ] ;
3560  
3561  
3562 #-----------------------------------------------
3563 # Convert all delimiters to single commas.
3564  
3565 16 ▶ if ( $text_string =~ /[\n\r]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($text_string =~ /[\n\r]/) 0 16 16
3566 {
3567 0 $text_string =~ s/[\n\r][\n\r]+/,/gs ;
3568 0 $text_string =~ s/[\n\r][\n\r]+/,/gs ;
3569 }
3570  
3571 16 $text_string =~ s/ +/,/gs ;
3572 16 $text_string =~ s/,,+/,/gs ;
3573  
3574  
3575 #-----------------------------------------------
3576 # Remove leading and trailing commas.
3577  
3578 16 $text_string =~ s/^,// ;
3579 16 $text_string =~ s/,$// ;
3580  
3581  
3582 #-----------------------------------------------
3583 # If there are only commas and spaces, or
3584 # the string is empty, return an empty list.
3585  
3586 16 ▶ if ( $text_string =~ /^[ ,]*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($text_string =~ /^[ ,]*$/) { } 0 16 16
3587 {
3588 0 @array = ( ) ;
3589  
3590  
3591 #-----------------------------------------------
3592 # Split the strings into an array.
3593  
3594 } else
3595 {
3596 16 @array = split( /,+/ , $text_string ) ;
3597 }
3598  
3599  
3600 #-----------------------------------------------
3601 # Return the resulting array.
3602  
3603 16 return @array ;
3604  
3605 }
3606  
3607  
3608  
3609  
3610 =head1 AUTHOR
3611  
3612 Richard Fobes, "CPSolver" at GitHub.com
3613  
3614  
3615 =head1 DOCUMENTATION
3616  
3617 See www.Dashrep.org for details about the Dashrep language.
3618  
3619  
3620 =head1 BUGS
3621  
3622 Please report any bugs or feature requests to "CPSolver" at GitHub.com.
3623  
3624  
3625 =head1 TO DO
3626  
3627 See www.Dashrep.org for descriptions of possible future developments.
3628  
3629  
3630 =head1 ACKNOWLEDGEMENTS
3631  
3632 Richard Fobes designed the Dashrep (TM) language and
3633 developed the original version of this code over a
3634 period of many years. Richard Fobes is the author
3635 of the book titled The Creative Problem Solver's Toolbox.
3636  
3637  
3638 =head1 COPYRIGHT & LICENSE
3639  
3640 Copyright 2009 through 2011 Richard Fobes at www.Dashrep.org, all rights reserved.
3641  
3642 You can redistribute and/or modify this library module
3643 under the Perl Artistic License 2.0, a copy
3644 of which is included in the LICENSE file.
3645  
3646 Conversions of this code into other languages are also
3647 covered by the above license terms.
3648  
3649 The Dashrep (TM) name is trademarked by Richard Fobes at
3650 www.Dashrep.org to prevent the name from being co-opted.
3651  
3652 The Dashrep (TM) language is in the public domain.
3653  
3654 =cut
3655  
3656 3 1; # End of package
↑ Summary