Subversion Repositories DevTools

Rev

Rev 7322 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
#! perl
2
########################################################################
7300 dpurdie 3
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 4
#
5
# Module name   : jats.sh
6
# Module type   : Perl Package
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
10
# Description   : This package contains functions to create a makefile entry
11
#                 The entry may consist of the following (optional) fields
12
#
13
#                 .PHONY <targets>
14
#                 <targets> : VARAIBLE = VALUE
15
#                 <targets> : <prerequisites>
16
#                       @echo "Run time comment"
17
#                       Recipe
18
#                       ( ShellRecipe )
19
#
20
#                 The order that information is added is not important
21
#                 Recipes and prerequisites may be mixed to simplify
22
#                 programming.
23
#
4344 dpurdie 24
#                 The --Define option creates
25
#                 define <name>
26
#                   Recipe
27
#                 endef
28
#
29
#                The --Raw option creates
30
#                   Recipe
31
#
4778 dpurdie 32
#                The --Raw with --Phony option creates
33
#                   .PHONY <targets>
34
#                   <targets>:
35
#                       Recipe
4344 dpurdie 36
#
4778 dpurdie 37
#
38
#
227 dpurdie 39
#......................................................................#
40
 
255 dpurdie 41
use 5.006_001;
227 dpurdie 42
use strict;
43
use warnings;
44
 
45
package MakeEntry;
46
use JatsError;
47
use ArrayHashUtils;
48
 
49
#
50
#   Global variables
51
#
52
my $llength = 80;                           # Target line length
53
 
54
 
55
#-------------------------------------------------------------------------------
56
# Function        : New
57
#
58
# Description     : Create a new empty entry
59
#
271 dpurdie 60
# Inputs          : handle              - FILEHANDLE or variable ref
61
#                                         eg: *MAKEFILE     - print to handle
62
#                                              \$var        - print to variable
63
#
64
#                   name                - Primary target name
65
#                   options             - Preload the fields
227 dpurdie 66
#                           --Target=name,name,name
67
#                           --Comment=text
68
#                           --Prereq=name,name,name
69
#                           --Recipe=text
70
#                           --Phony
4344 dpurdie 71
#                           --Define
72
#                           --Raw
227 dpurdie 73
#                           --Print
74
#
75
# Returns         : Ref to a an object that can be manipulated
76
#
77
sub New
78
{
79
    my ($handle, $name, @args ) = @_;
80
    my $self  = {};
81
    $self->{DEPENDANCY}     = [];
82
    $self->{NAME}           = [];
83
    $self->{RECIPE}         = [];
84
    $self->{SHELL}          = [];
85
    $self->{PRINTED}        = 0;
86
    $self->{COMMENT}        = [];
7322 dpurdie 87
    $self->{DEFN}           = [];
227 dpurdie 88
    $self->{PHONY}          = 0;
4344 dpurdie 89
    $self->{DEFINE}         = 0;
90
    $self->{RAW}            = 0;
227 dpurdie 91
    $self->{FH}             = $handle;
271 dpurdie 92
    $self->{FH_inmemory}    = 0;
227 dpurdie 93
    $self->{RECIPE_PREFIX}  = '';
5708 dpurdie 94
    $self->{RECIPE_WRAPPER}  = ['(', ')'];
227 dpurdie 95
    $self->{RECIPE_COMMENT} = '';
4778 dpurdie 96
    $self->{STACK}          = [];
4781 dpurdie 97
    $self->{SDEF}           = '';
227 dpurdie 98
 
99
    push @{$self->{NAME}}, split(/,/,$name) if ( $name );
100
 
101
    bless ($self, __PACKAGE__);
102
 
103
    #
104
    #   Process any argument
105
    #
106
    my $print = 0;
107
    foreach ( @args )
108
    {
109
        if ( m/^--Target=(.*)/ ) {
110
            $self->AddName(split(/,/,$1));
111
 
112
        } elsif ( m/^--Comment=(.*)/ ) {
113
            $self->AddComment($1);
114
 
115
        } elsif ( m/^--Prereq=(.*)/ ) {
116
            $self->AddDependancy(split(/,/,$1));
117
 
118
        } elsif ( m/^--Phony/ ) {
119
            $self->Phony();
120
 
4344 dpurdie 121
        } elsif ( m/^--Define/ ) {
122
            $self->Define();
123
 
124
        } elsif ( m/^--Raw/ ) {
125
            $self->Raw();
126
 
227 dpurdie 127
        } elsif ( m/^--Recipe=(.*)/ ) {
128
            $self->AddRecipe($1);
129
 
130
        } elsif ( m/^--Print/ ) {
131
            $print = 1;
132
 
133
        } elsif ( m/^--/ ) {
134
            Error ("MakeEntry: Unknown option: $_");
135
 
136
        } else {
137
            $self->AddDependancy( $_ );
138
 
139
        }
140
    }
141
 
271 dpurdie 142
    #
143
    #   Set up the printer handle
144
    #   May be
145
    #       Empty           - use stderr
146
    #       ref to a scalar - use in memory file
147
    #       typeglob        - normal handle
148
    #
149
    if ( ref $handle eq 'SCALAR' )
150
    {
151
        $$handle = '' if ( ! defined $$handle );
152
        open(MEMORY,'>>', $handle) || Error ("Cannot open in-memory file");
153
        $self->{FH_inmemory} = $handle;
154
        $self->{FH} = \*MEMORY;
155
 
156
    } elsif ( ! $handle ) {
157
       $self->{FH} = \*STDERR;
158
    }
159
 
160
    #
161
    #   Print simple entry if required
162
    #
227 dpurdie 163
    $self->Print() if ( $print );
164
    return $self;
165
}
166
 
167
#-------------------------------------------------------------------------------
168
# Function        : AddName
169
#
4778 dpurdie 170
# Description     : Add a target name to the entry
227 dpurdie 171
#
172
# Inputs          : An array of names to add
173
#
174
# Returns         :
175
#
176
sub AddName
177
{
178
    my $self = shift;
179
    push @{$self->{NAME}}, @_
180
}
181
 
182
#-------------------------------------------------------------------------------
183
# Function        : Phony
184
#
185
# Description     : Flag the entry as a phony
186
#
187
# Inputs          :
188
#
189
# Returns         :
190
#
191
sub Phony
192
{
193
    my $self = shift;
194
    $self->{PHONY} = 1;
195
}
196
 
4344 dpurdie 197
#-------------------------------------------------------------------------------
198
# Function        : Define
199
#
200
# Description     : Flag the entry as a define, rather than a normal target
201
#                   Many of the other commands are not supported
7323 dpurdie 202
#                   Only:
203
#                       AddComment
204
#                       AddRecipe OR AddShellRecipe
205
#                       SectionIfDef and related fuction
206
#                           Will generate an empty definition for the 'else'
4344 dpurdie 207
#
208
# Inputs          :
209
#
210
# Returns         :
211
#
212
sub Define
213
{
214
    my $self = shift;
215
    $self->{DEFINE} = 1;
216
}
227 dpurdie 217
 
218
#-------------------------------------------------------------------------------
4344 dpurdie 219
# Function        : Raw
220
#
221
# Description     : Flag the entry as raw text
222
#                   Many of the other commands are not supported
223
#                   Only AddComment and AddRecipe
224
#
225
# Inputs          :
226
#
227
# Returns         :
228
#
229
sub Raw
230
{
231
    my $self = shift;
232
    $self->{RAW} = 1;
233
}
234
 
235
#-------------------------------------------------------------------------------
227 dpurdie 236
# Function        : AddComment
237
#
238
# Description     : Add a comment to the entry
239
#
240
# Inputs          : An array of names to add
241
#
242
# Returns         :
243
#
244
sub AddComment
245
{
246
    my $self = shift;
247
    push @{$self->{COMMENT}}, @_
248
}
249
 
5991 dpurdie 250
 
227 dpurdie 251
#-------------------------------------------------------------------------------
5991 dpurdie 252
# Function        : QuoteDependency
253
#
254
# Description     : Escape/Quote a pathname for make
255
#                       Allow files with a $ in the name
256
#                       Allow files with a space in the name
257
#                       Allow files with a comma in the name
258
#                       Allow files with a colon in the name
259
#                       Allow for paths that have make-varible prefixes
7322 dpurdie 260
#                           $(GBE_...) or ${GBE_...} or $(OBJDIR) or $(BUILDVERNUM)
5991 dpurdie 261
#                           as these may be generated internally
262
#
263
#                       Must also allow $(GBE_TYPE) in the remainder
264
#
265
# Inputs          : uarg                - Arg to quote
266
#
267
# Returns         : Quoted arg
268
#
269
 
270
sub QuoteDependency
271
{
272
    my ($uarg) = @_;
273
 
274
    #
275
    #   Split into two
276
    #       $(xxx)/             - Makefile variables
277
    #       Remainder           - Stuff to quote
278
    #
279
    $uarg =~ m~^((\$\(.*?\)/)*)(.*)~;
280
    my $prefix = defined $1 ? $1 : '';
281
    my $arg    = defined $3 ? $3 : '';
282
 
7322 dpurdie 283
    $arg =~ s~\$(?!\(GBE_[A-Z]+\)|{GBE_[A-Z]+}|\(OBJDIR\)|\(BUILDVERNUM\))~\$\$~g;       # $, not followed by (GBE_ or ${GBE_ or (OBJDIR)- is not $(GBE_ AND not $(OBJDIR)
5991 dpurdie 284
    $arg =~ s~ ~\\ ~g;
285
    $arg =~ s~,~\$(comma)~g;
286
    $arg =~ s~%~\\%~g;
5999 dpurdie 287
    $arg =~ s~:~\\:~g if ($::ScmHost eq 'Unix');
5991 dpurdie 288
    return $prefix . $arg;
289
}
290
 
291
#-------------------------------------------------------------------------------
292
# Function        : AddDependancyEscaped
293
#
294
# Description     : Add a dependancy to the entry and Quote the value so that
295
#                   it can be it can be processed by make
296
#
297
# Inputs          : An array of dependencies to add
298
#
299
# Returns         :
300
#
301
sub AddDependancyEscaped
302
{
303
    my $self = shift;
304
    my @escaped;
305
 
306
    push @escaped, QuoteDependency($_) foreach (@_);
307
    UniquePush $self->{DEPENDANCY}, @escaped ;
308
}
309
 
310
#-------------------------------------------------------------------------------
227 dpurdie 311
# Function        : AddDependancy
312
#
313
# Description     : Add a dependancy to the entry
5991 dpurdie 314
#                   These will not be escaped.
227 dpurdie 315
#
5991 dpurdie 316
# Inputs          : An array of dependencies to add
227 dpurdie 317
#
318
# Returns         :
319
#
320
sub AddDependancy
321
{
322
    my $self = shift;
323
    UniquePush $self->{DEPENDANCY}, @_ ;
324
}
325
 
326
#-------------------------------------------------------------------------------
327
# Function        : AddDefn
328
#
329
# Description     : Add a definition to the entry
7322 dpurdie 330
#                   Preserve the order
227 dpurdie 331
#
332
# Inputs          : A hash of definitions to add
333
#                   The Hash gets lost in the subcall. Its simply a list
334
#                   of NAME, VALUE pairs
335
#
336
# Returns         :
337
#
338
sub AddDefn
339
{
340
    my $self = shift;
341
    while ( @_ )
342
    {
343
        my $defn = shift;
344
        my $value = shift || '';
7322 dpurdie 345
        push @{$self->{DEFN}}, join( $;, $defn, $value) ;
227 dpurdie 346
    }
347
}
348
 
349
#-------------------------------------------------------------------------------
350
# Function        : RecipePrefix
351
#
352
# Description     : Set the recipe prefix
353
#                   This will be added to ALL recipe entries
354
#
355
# Inputs          :
356
#
357
# Returns         :
358
#
359
sub RecipePrefix
360
{
361
    my $self = shift;
362
    my $prefix = shift || '';
363
    $self->{RECIPE_PREFIX} = $prefix;
364
}
365
 
366
#-------------------------------------------------------------------------------
367
# Function        : RecipeComment
368
#
369
# Description     : Add a runtime comment to the entry
370
#
371
# Inputs          : String to print at runtime
372
#
373
# Returns         :
374
#
375
sub RecipeComment
376
{
377
    my $self = shift;
378
    $self->{RECIPE_COMMENT} = join( ' ', @_);
379
}
380
 
381
 
5708 dpurdie 382
#-------------------------------------------------------------------------------
383
# Function        : RecipeWrapper
384
#
385
# Description     : Add a wrapper around the recipe
386
#
387
# Inputs          : begin   - Start of wrapper
388
#                   end     - End of wrapper
389
#
390
# Returns         :
391
#
392
sub RecipeWrapper
393
{
394
    my $self = shift;
395
    Error("RecipeWrapper requires exacly two arguments") unless scalar @_ == 2;
396
    my ($begin, $end) = @_;
397
    $self->{RECIPE_WRAPPER}[0] = $begin;
398
    $self->{RECIPE_WRAPPER}[1] = $end;
399
}
227 dpurdie 400
 
401
#-------------------------------------------------------------------------------
402
# Function        : AddRecipe
403
#
404
# Description     : Add a line to the line-by-line recipe
405
#
406
# Inputs          : One or more recipe lines
407
#                   Each line of the recipe will be prefixed with the current
408
#                   recipe prefix.
409
#
410
#                   An array will be treated as a recipe with implicit line
4344 dpurdie 411
#                   breaks for formatting purposes.
227 dpurdie 412
#
413
# Returns         :
414
#
415
sub AddRecipe
416
{
417
    my $self = shift;
418
    my $prefix = $self->{RECIPE_PREFIX};
419
    foreach ( @_ )
420
    {
421
        if (ref($_) eq "ARRAY")
422
        {
423
            $_->[0] = $prefix . $_->[0];
424
            push @{$self->{RECIPE}}, $_;
425
        }
426
        else
427
        {
428
            push @{$self->{RECIPE}}, $prefix . $_;
429
        }
430
    }
431
}
432
 
433
#-------------------------------------------------------------------------------
7323 dpurdie 434
# Function        : AddOneRecipe
435
#
436
# Description     : Add an array as a single recipe that has been formatted with implicit line breaks
437
#
438
# Inputs          : A recipe with implicit line breaks for formatting purposes.
439
#
440
# Returns         :
441
#
442
sub AddOneRecipe
443
{
444
    my $self = shift;
445
    my @data = @_;
446
    my $prefix = $self->{RECIPE_PREFIX};
447
 
448
    $data[0] = $prefix . $data[0];
449
    push @{$self->{RECIPE}}, \@data;
450
}
451
 
452
#-------------------------------------------------------------------------------
227 dpurdie 453
# Function        : AddShellRecipe
454
#
455
# Description     : Add recipe lines that will be processed within a 'shell'
456
#
457
# Inputs          : One or more recipe lines
458
#
459
#                   An array will be treated as a recipe with implicit line
4778 dpurdie 460
#                   breaks for formatting purposes.
227 dpurdie 461
#
462
# Returns         :
463
#
464
sub AddShellRecipe
465
{
466
    my $self = shift;
467
    push @{$self->{SHELL}}, @_
468
}
469
 
4778 dpurdie 470
#-------------------------------------------------------------------------------
471
# Function        : NewSection 
472
#
473
# Description     : Create a new section within the current recipe
474
#                   Only used within a standard recipe (not raw or defined)
475
#                   Used to create multiple sections in cases with multiple shell
476
#                   and recipe sections.
477
#
478
#                   Save existing entries and start again
479
#
480
# Inputs          : None 
481
#
482
# Returns         : 
483
#
484
sub NewSection
485
{
486
    my $self = shift;
487
    my %data;
227 dpurdie 488
 
4778 dpurdie 489
    $data{RECIPE}           = $self->{RECIPE};
490
    $data{SHELL}            = $self->{SHELL};
491
    $data{RECIPE_PREFIX}    = $self->{RECIPE_PREFIX};
492
    $data{RECIPE_COMMENT}   = $self->{RECIPE_COMMENT};
5708 dpurdie 493
    $data{RECIPE_WRAPPER}   = $self->{RECIPE_WRAPPER};
4781 dpurdie 494
    $data{SDEF}             = $self->{SDEF};
495
 
4778 dpurdie 496
 
497
    push @{$self->{STACK}}, \%data;
498
 
499
    $self->{RECIPE}         = []; 
500
    $self->{SHELL}          = [];
501
    $self->{RECIPE_PREFIX}  = '';
502
    $self->{RECIPE_COMMENT} = '';
5708 dpurdie 503
    $self->{RECIPE_WRAPPER} = ['(', ')'];
4781 dpurdie 504
    $self->{SDEF}           = '';
4778 dpurdie 505
}
506
 
4889 dpurdie 507
#-------------------------------------------------------------------------------
508
# Function        : SectionIfDef 
509
#
510
# Description     : Place the current section within a ifdef ... endif block
511
#
512
# Inputs          : defn        - Definition to use within the ifdef construct 
513
#
514
# Returns         : Nothing
515
#
516
 
517
sub SectionIfDef
4781 dpurdie 518
{
519
    my $self = shift;
7322 dpurdie 520
    $self->{SDEF} = 'ifdef ' . $_[0];
4781 dpurdie 521
}
522
 
227 dpurdie 523
#-------------------------------------------------------------------------------
7322 dpurdie 524
# Function        : SectionIfEq
525
#
526
# Description     : Place the current section within a ifeq ... endif block
527
#
528
# Inputs          : arg1
529
#                   arg2
530
#
531
# Returns         : Nothing
532
#
533
 
534
sub SectionIfEq
535
{
536
    my $self = shift;
537
    $self->{SDEF} = 'ifeq "' . $_[0] . '" "' . $_[1] . '"';
538
}
539
 
540
#-------------------------------------------------------------------------------
541
# Function        : SectionIfNeq
542
#
543
# Description     : Place the current section within a ifeq ... endif block
544
#
545
# Inputs          : arg1
546
#                   arg2
547
#
548
# Returns         : Nothing
549
#
550
sub SectionIfNeq
551
{
552
    my $self = shift;
553
    $self->{SDEF} = 'ifneq "' . $_[0] . '" "' . $_[1] . '"';
554
}
555
 
556
 
557
#-------------------------------------------------------------------------------
227 dpurdie 558
# Function        : Print
559
#
560
# Description     : Print the entry
561
#
562
# Inputs          : None
563
#
564
# Returns         : Nothing
565
#
566
sub Print
567
{
568
    my $self = shift;
569
 
570
    #
571
    #   Set the default print stream to the desired stream
572
    #   This greatly simplifies the use of print
573
    #
574
    my $fh = $self->{FH};
575
    my $old_fh = select($fh);
576
 
271 dpurdie 577
 
227 dpurdie 578
    #
579
    #   A nice comment header
580
    #
581
    if ( @{$self->{COMMENT}} )
582
    {
583
        print( "#\n" );
584
        print map {"# $_\n"} @{$self->{COMMENT}};
585
        print( "#\n" );
586
    }
587
 
588
    #
589
    #   Print the targets
590
    #   Print PHONY information
591
    #   Print on multiple lines if multiple targets are very long
592
    #
593
    if ( $self->{PHONY} )
594
    {
595
        my $phony_string = ".PHONY: ";
596
        my $tstring = join $;, @{$self->{NAME}};
597
        my $join = length ($tstring) < $llength ? ' ' : "\n$phony_string";
598
        $tstring =~ s~$;~$join~g;
599
        print "$phony_string$tstring\n";
600
    }
601
 
602
    #
603
    #   Print any definitions
5986 dpurdie 604
    #       target: DEFN := VALUE
227 dpurdie 605
    #
606
    if ( $self->{DEFN}  )
607
    {
608
        my $tstring = join $;, @{$self->{NAME}};
609
        my $join = length ($tstring) < $llength ? ' ' : " \\\n    ";
610
        $tstring =~ s~$;~$join~g;
7322 dpurdie 611
 
612
        foreach ( @{$self->{DEFN}} ){
613
            my ($defn,$value) = split($;, $_);
614
            print( "$tstring: $defn := $value\n" );
227 dpurdie 615
        }
616
    }
617
 
4344 dpurdie 618
    if ( $self->{RAW}  )
227 dpurdie 619
    {
4778 dpurdie 620
        if ( $self->{PHONY} )
621
        {
622
            my $tstring = $self->{NAME}[0];
623
            print($tstring . ":\n");
624
        }
4344 dpurdie 625
        my $tstring = join ("\n", @{$self->{RECIPE}});
626
        print $tstring;
227 dpurdie 627
    }
4344 dpurdie 628
    elsif ( $self->{DEFINE}  )
629
    {
7323 dpurdie 630
        # Just print the recipe
631
        # May be warpped in an ifdef with an empty 'else'
227 dpurdie 632
 
4344 dpurdie 633
        my $tstring = $self->{NAME}[0];
7323 dpurdie 634
        my $sdef =    $self->{SDEF};
635
 
636
        print "$sdef" if ($sdef);
637
 
638
        print "\ndefine $tstring";
4344 dpurdie 639
        print_list ( '', '', $self->{RECIPE}, '');
7323 dpurdie 640
        print_list ( $self->{RECIPE_WRAPPER}[0], '; \\', $self->{SHELL}, $self->{RECIPE_WRAPPER}[1] );
4344 dpurdie 641
        print "\nendef";
7323 dpurdie 642
        if ($sdef) {
643
            print "\nelse";
644
            print "\ndefine $tstring";
645
            print "\nendef";
646
            print "\nendif";
647
        }
4344 dpurdie 648
    }
649
    else
650
    {
651
        #
652
        #   Print the main target name
653
        #   Print on multiple lines if multiple targets are very long
654
        #
655
        my $tstring = join $;, @{$self->{NAME}};
656
        my $join = length ($tstring) < $llength ? ' ' : " \\\n";
657
        $tstring =~ s~$;~$join~g;
658
        my $nlength = length $tstring;
659
        print "$tstring:";
660
 
661
        #
662
        #   Print the prerequisites
663
        #   Print on multiple lines if long
664
        #
665
        $tstring = join $;, @{$self->{DEPENDANCY}};
666
        $join = $nlength + length ($tstring) < $llength ? ' ' : " \\\n\t";
667
        $tstring =~ s~$;~$join~g;
668
        print $join . $tstring;
227 dpurdie 669
 
4344 dpurdie 670
        #
4778 dpurdie 671
        #   Push the current section onto the stack
672
        #   This will simplify processing of all sections
4344 dpurdie 673
        #
4778 dpurdie 674
        $self->NewSection();
675
        foreach my $recipeEntry (@{$self->{STACK}})
4344 dpurdie 676
        {
4778 dpurdie 677
            my $comment = $recipeEntry->{RECIPE_COMMENT};
5708 dpurdie 678
            my $wrapper = $recipeEntry->{RECIPE_WRAPPER};
4778 dpurdie 679
            my $prefix =  $recipeEntry->{RECIPE_PREFIX};
680
            my $recipe =  $recipeEntry->{RECIPE};
681
            my $shell =   $recipeEntry->{SHELL};
4781 dpurdie 682
            my $sdef =    $recipeEntry->{SDEF};
683
 
7323 dpurdie 684
            if ($sdef) {
7322 dpurdie 685
                print "\n$sdef";
4781 dpurdie 686
            }
687
 
4778 dpurdie 688
            #
689
            #   Print the Recipe runtime comment
690
            #
7323 dpurdie 691
            if ( $comment ) {
4778 dpurdie 692
                print "\n\t\@echo \"$comment\"";
693
            }
694
 
695
            #
696
            #   Print the recipe
697
            #
698
            print_list ( '', '', $recipe, '');
699
 
700
            #
701
            #   Print the recipe as a shell command
702
            #   Bracket the recipes with ( .. ) and place semi colons between lines
703
            #   Use the current recipe prefix
704
            #
5708 dpurdie 705
            print_list ( $prefix . $wrapper->[0], ';\\', $shell, $wrapper->[1]);
4781 dpurdie 706
 
7323 dpurdie 707
            if ($sdef) {
4781 dpurdie 708
                print "\nendif";
709
            }
4344 dpurdie 710
        }
711
    }
712
 
227 dpurdie 713
    print "\n\n";
714
 
715
    #
716
    #   Flag the entry as having been printed
717
    #   Used as a sanity test when the object is destroyed
718
    #
719
    $self->{PRINT} = 1;
720
 
721
    #
722
    #   Restore default output stream handle
723
    #
724
    select($old_fh);
725
}
726
 
727
#-------------------------------------------------------------------------------
728
# Function        : print_list
729
#
730
# Description     : Internal helper rouitine
731
#
732
# Inputs          : $prefix     - Optional prefix to wrap the list
733
#                                 If present will cause extra indentation
734
#                   $linesep    - Line seperator string
735
#                   $ref        - Ref to the list to display
736
#                                 Each element will be a line of text, or an
737
#                                 array of arguments which will be displayed on
738
#                                 new lines for pretty printing
739
#                   $suffix     - Optional suffix.
740
#
741
# Returns         :
742
#
743
sub print_list
744
{
745
    my ($prefix, $linesep ,$ref, $suffix) = @_;
746
    my @entry = @{$ref};
747
    my $leadin = "\t";
748
 
749
    if ( @entry  )
750
    {
751
        if ( $prefix )
752
        {
753
            print( "\n" . $leadin . $prefix . "\\" );
754
            $leadin .= "\t";
755
        }
756
 
757
        foreach ( @entry )
758
        {
759
            if (ref($_) eq "ARRAY")
760
            {
761
                my @array = @{$_};
762
                my $indent = '';
763
                my $tail = '';
764
                foreach ( @array )
765
                {
7323 dpurdie 766
                    next unless (defined $_);
767
                    next unless ( length($_));
227 dpurdie 768
                    print( $tail . "\n" . $leadin . $indent . $_ );
769
                    $indent = "\t";
770
                    $tail = " \\";
771
                }
772
                print $linesep;
773
            }
774
            else
775
            {
776
                print( "\n" . $leadin . $_ . $linesep );
777
            }
778
        }
779
 
780
        if ( $suffix )
781
        {
4778 dpurdie 782
            $leadin = chop($leadin) if ($prefix);
227 dpurdie 783
            print( "\n" . $leadin . $suffix );
784
        }
785
    }
786
}
787
 
788
#-------------------------------------------------------------------------------
789
# Function        : DESTROY
790
#
791
# Description     : Sanity test
792
#
793
# Inputs          :
794
#
795
# Returns         :
796
#
797
sub DESTROY
798
{
799
    my $self = shift;
800
    unless ($self->{PRINT} )
801
    {
802
        $self->{PRINT} = 1;
803
        Error ("Destroying MakeEntry before printing.",
804
               "Name: @{$self->{NAME}}");
805
    }
271 dpurdie 806
 
807
    #
808
    #   If using an in-memory file close the handle
809
    #
810
    close $self->{FH} if ( $self->{FH_inmemory} );
227 dpurdie 811
}
812
 
813
1;
814
 
815