summaryrefslogtreecommitdiffstats
path: root/src/usr/targeting/xmltohb/updatetempsxml.pl
blob: 87e0b9f84c3459526640bab30866132e5b50f957 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/usr/targeting/xmltohb/updatetempsxml.pl $
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2012,2016
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG

#
# Original file, updatetargetxml.pl, created for fsp.
# File copied to Hostboot and modified
# File used as basis for updatetempsxml.pl
#
# Usage:
#
#    updatetempsxml --generic=temp_generic.xml
#                   --fapi=fapiattrs.xml
#                   --fapi_inc=fapi2PlatAttrService.H
#                   --fw_dflts=hb_temp_defaults.xml
#                   --defaults=tempdefaults.xml
#
# Purpose:
#
#   This perl script processes the fapiattrs.xml and hb_temp_defaults.xml
#   files to find any new attributes which need to be defined in the
#   generic.xml file.  It also process the tempdefaults.xml file to find the
#   <tempDefault> tags and any new attribute definitions so that generic.xml
#   can be updated with default values and attribute definitions as needed.
#   The updated generic.xml is written to the console.
#

use strict;
use XML::Simple;
use Data::Dumper;


$XML::Simple::PREFERRED_PARSER = 'XML::Parser';

my $generic = "";
my $fapi = "";
my $fapi_inc = "";
my $fw_dflts = "";
my $defaults = "";
my $usage = 0;
use Getopt::Long;
GetOptions( "generic:s"  => \$generic,
            "fapi:s"     => \$fapi,
            "fapi_inc:s" => \$fapi_inc,
            "fw_dflts:s" => \$fw_dflts,
            "defaults:s" => \$defaults,
            "help"       => \$usage, );

if (($generic eq "") || ($fapi eq "") || ($fapi_inc eq "") ||
    ($fw_dflts eq "") || ($defaults eq ""))
{
    display_help();
    exit 1;
}
elsif ($usage)
{
    display_help();
    exit 0;
}


open (FH, "<$generic") ||
    die "ERROR: unable to open $generic\n";
close (FH);

#print STDERR "XMLin($generic)\n";
my $genericXml = XMLin("$generic");
#print STDERR "XMLin($generic, ForceArray=>1)\n";
my $genericXmlArray = XMLin("$generic", ForceArray=>1);

open (FH, "<$fapi") ||
    die "ERROR: unable to open $fapi\n";
close (FH);

#print STDERR "XMLin($fapi, ForceArray=>1)\n";
my $fapiXml = XMLin("$fapi", ForceArray=>1);

open (FH, "<$fapi_inc") ||
    die "ERROR: unable to open $fapi_inc\n";
close (FH);

open (FH, "<$fw_dflts") ||
    die "ERROR: unable to open $fw_dflts\n";
close (FH);

#print STDERR "XMLin($fw_dflts, ForceArray=>1)\n";
my $fwDfltsXml = XMLin("$fw_dflts", ForceArray=>1);

open (FH, "<$defaults") ||
    die "ERROR: unable to open $defaults\n";
close (FH);

#print STDERR "XMLin($defaults, ForceArray=>1)\n";
my $defaultsXml = XMLin("$defaults", ForceArray=>1);


# Walk through temp_generic.xml file looking for target types
my @TgtTypeInfo;

foreach my $TgtType ( @{$genericXmlArray->{targetType}} )
{
    my $TgtTypeType = "";
    my $TgtTypeAttrIds = " ";

    # Find attributes for this target type
    foreach my $TgtTypeAttr ( @{$TgtType->{attribute}} )
    {
        # Find default for TYPE attribute
        if($TgtTypeAttr->{id}->[0] eq "TYPE")
        {
            if(exists $TgtTypeAttr->{default})
            {
                $TgtTypeType = $TgtTypeAttr->{default}->[0];
            }
            elsif($TgtType->{id}->[0] ne "base")
            {
                print STDERR "Target ".$TgtType->{id}->[0].
                    " has TYPE attribute without a value\n";
            }
        }
        # Record IDs of all other attributes for this target type
        else
        {
            $TgtTypeAttrIds .= $TgtTypeAttr->{id}->[0]." ";
        }
    }

    # Create entry with information for this target type
    if($TgtTypeType ne "")
    {
        push @TgtTypeInfo, [ $TgtType->{id}->[0], $TgtTypeType,
                             $TgtTypeAttrIds ];
    }
}


# Walk through hb_temp_defaults.xml file looking for new FAPI attributes
my @NewAttr;
my @UpdtTgt;

foreach my $TempAttr ( @{$fwDfltsXml->{attribute}} )
{
    my $fapi_attr = "";
    my $fapi_id = $TempAttr->{id}->[0];
    $fapi_id =~ s/\s//g;
#    print STDERR "Processing FAPI Id $fapi_id\n";
    my $generic_id = $fapi_id;
    $generic_id =~ s/ATTR_//;
    my $found = 0;

    my $persistency = "volatile";

    # First, check if attribute definition exists in fapiattrs.xml
    foreach my $FapiAttr ( @{$fapiXml->{attribute}} )
    {
        my $fapi_attr_id = $FapiAttr->{id}->[0];
        $fapi_attr_id =~ s/\s//g;
        if ($fapi_attr_id eq $fapi_id)
        {
            $found = 1;
            $fapi_attr = $FapiAttr;

            # Check if FAPI attribute is associated with specific target types
            if (exists $FapiAttr->{targetType})
            {
                my @types = split(',',$FapiAttr->{targetType}->[0]);
                foreach my $type(@types)
                {
                    $type =~ s/\s//g;
                    $type =~ s/TARGET_TYPE_//;
                    $type =~ s/_ENDPOINT//;
                    $type =~ s/_CHIPLET//;
                    $type =~ s/_CHIP//;
                    $type =~ s/^SYSTEM$/SYS/;

                    my $msgNeeded = 1;

                    # Loop through target type info from temp_generic.xml file
                    for my $i ( 0 .. $#TgtTypeInfo)
                    {
                        # Check for entry of specified target type without a
                        # definition of the given attribute
                        if(($TgtTypeInfo[$i][1] eq $type) &&
                           !($TgtTypeInfo[$i][2] =~ /\s$generic_id\s/))
                        {
                            # Determine if default exists for the update
                            if (exists $TempAttr->{default})
                            {
                                push @UpdtTgt, [ $TgtTypeInfo[$i][0], $type,
                                                 $generic_id,
                                                 $TempAttr->{default}->[0]];
                            }
                            else
                            {
                                push @UpdtTgt, [ $TgtTypeInfo[$i][0], $type,
                                                 $generic_id, ""];
                            }
                            $msgNeeded = 0;
                        }
                        elsif($TgtTypeInfo[$i][2] =~ /\s$generic_id\s/)
                        {
                            print STDERR "Target $TgtTypeInfo[$i][0] of type ".
                                  "$type already has attribute $generic_id\n";
                            $msgNeeded = 0;
                        }
                    }

                    print STDERR "Type $type not found in $fapi for attribute ".
                          "$generic_id\n" if($msgNeeded);
                }
            }
            else
            {
                 die "FATAL: FAPI attribute $fapi_id is not associated with ".
                     "any specific target type\n";
            }

            # Non-platInit attributes need to be volatile-zeroed
            #  or xmltohb.pl will throw an error
            if( !(exists $FapiAttr->{platInit}) )
            {
                $persistency = "volatile-zeroed";
            }

            last;
        }
    }
    die "FATAL: FAPI attribute definition not found in $fapi for "
        . "$fapi_id\n" if($found == 0);

    # Second, check if handling already exists in fapi2PlatAttrService.H
    $found = 0;
    open (FH, "<$fapi_inc");
    while (my $line = <FH>)
    {
        # Check if line starts a GETMACRO or SETMACRO #define statement
        if (($line =~ /^\s*\#define\s*(ATTR_.*)_(.ETMACRO).*/) &&
            ($1 eq $fapi_id))
        {
            print STDERR "Existing handling found in $fapi_inc for "
                . "$fapi_id\n";
            $found = 1;
            last;
        }
    }
    close (FH);
    next if($found);

    # Third, check if mapping already exists in generic.xml
    $found = 0;
    foreach my $GenericAttr ( @{$genericXmlArray->{attribute}} )
    {
        # Check for attribute mapping
        if (exists $GenericAttr->{hwpfToHbAttrMap})
        {
            my $GenericMap = $GenericAttr->{hwpfToHbAttrMap}->[0];

            # Check if FAPI and generic attributes are mapped to each other
            if ($GenericMap->{id}->[0] eq $fapi_id)
            {
                print STDERR "Existing mapping found in $generic for "
                    . "$fapi_id\n";
                $found = 1;
                last;
            }
        }
    }
    next if($found);

    # Collect information for creating attribute definitions
    my $description = $fapi_attr->{description}->[0];

    my $valueType = $fapi_attr->{valueType}->[0];
    $valueType =~ s/(uint\d*)/$1_t/ if($valueType =~ /^uint\d*/);
    $valueType =~ s/(int\d+)/$1_t/ if ($valueType =~ /^int\d+$/);

    my $fwDefault = "";
    if (exists $TempAttr->{default})
    {
        $fwDefault = $TempAttr->{default}->[0];
    }

    my $array = "";
    if(exists $fapi_attr->{array})
    {
        my @dimensions = split(' ',$fapi_attr->{array}->[0]);
        $array = @dimensions[0];
        for my $i ( 1 .. $#dimensions )
        {
            $array .= ",$dimensions[$i]";
        }
    }

    # Create generic attribute with mapping
    push @NewAttr, [ "<attribute>\n" ];
    push @NewAttr, [ "    <id>$generic_id</id>\n" ];
    push @NewAttr, [ "    <description>\n" ];
    push @NewAttr, [ "        $description\n" ];
    push @NewAttr, [ "    </description>\n" ];
    push @NewAttr, [ "    <simpleType>\n" ];
    if($fwDefault ne "")
    {
        push @NewAttr, [ "        <$valueType>\n" ];
        push @NewAttr, [ "            <default>$fwDefault</default>\n" ];
        push @NewAttr, [ "        </$valueType>\n" ];
    }
    else
    {
        push @NewAttr, [ "        <$valueType></$valueType>\n" ];
    }
    push @NewAttr, [ "        <array>$array</array>\n" ] if($array ne "");
    push @NewAttr, [ "    </simpleType>\n" ];
    push @NewAttr, [ "    <persistency>$persistency</persistency>\n" ];
    push @NewAttr, [ "    <readable/>\n" ];
    push @NewAttr, [ "    <writeable/>\n" ] if(exists $fapi_attr->{writeable});
    push @NewAttr, [ "    <hwpfToHbAttrMap>\n" ];
    push @NewAttr, [ "        <id>$fapi_id</id>\n" ];
    push @NewAttr, [ "        <macro>DIRECT</macro>\n" ];
    push @NewAttr, [ "    </hwpfToHbAttrMap>\n" ];
    push @NewAttr, [ "    <tempAttribute/>\n" ];
    push @NewAttr, [ "</attribute>\n" ];
    push @NewAttr, [ "\n" ];
}


# Check tempdefaults.xml for <tempDefault> entries which are setting temporary
# default values for existing attributes going into the generic.xml file
my @ChgAttr;

foreach my $Default ( @{$defaultsXml->{tempDefault}} )
{
    foreach my $attr ( @{$Default->{attribute}} )
    {
        my $attribute_id = $attr->{id}->[0];
        my $default = "";
        my $force = "n";

        # Check entry for setting a default value
        if (exists $attr->{default})
        {
            $default = $attr->{default}->[0];
        }

        # Check entry for forcing the default setting
        if (exists $attr->{force})
        {
            $force = "y";
        }

        # Check that the temporary default is for an existing attribute
        if (exists $genericXml->{attribute}->{$attribute_id})
        {
            # Check that temporary default was set for the attribute, that is,
            # <default> was specified and value was set
            if (($default ne "") && !($default =~ /^HASH\(0x.*\)/))
            {
#                print STDERR "[ $attribute_id, $default, $force ]\n";
                push @ChgAttr, [ $attribute_id, $default, $force ];
            }
            else
            {
                die "ERROR: Attribute $attribute_id default not specified\n";
            }
        }
        else
        {
            die "ERROR: Attribute $attribute_id definition not found\n";
        }
    }
}


# Check tempdefaults.xml for <attribute> and <enumerationType> entries to be
# appended to the generic.xml file and for <tempDefault> entries to be ignored.
# Save <attribute> and <enumerationType> entry lines in @NewAttr so that they
# can be appended to the generic.xml file later.
use constant
{
    stateFindEntry      =>  0,  # Find start of an <attribute>,
                                # <enumerationType>, or <tempDefault> entry
                                # in the tempdefaults.xml file
    stateFindID         =>  1,  # Find ID field in the current entry
    stateFindEntryEnd   =>  2,  # Find end of the current entry
    stateTempDefault    => -1,  # Find end of the <tempDefault> entry
};

my $state = stateFindEntry; # First find an entry
my $count = 0;
my $id = "";
my $type = "";

open (FH, "<$defaults");

while (my $line = <FH>)
{
    # Check if line starts an <attribute> and <enumerationType> entry
    if ($state == stateFindEntry &&
        $line =~ /^\s*<(attribute|enumerationType)>.*/)
    {
        $state = stateFindID; # Next find the ID within this entry
        $type = $1;
        push @NewAttr, [ $line ];
        $count = 1;
    }
    # Check if line specifies the ID of the entry
    elsif ($state == stateFindID && $line =~ /^\s*<id>/)
    {
        $state = stateFindEntryEnd; # Now find the end of this entry
        $id = $line;
        $id =~ s/\n//;
        $id =~ s/.*<id>(.*)<\/id>.*/$1/;

        # Check that the ID doesn't already exist in the generic.xml data
        if (exists $genericXml->{$type}->{$id})
        {
            print STDERR "Attribute $id definition already exists\n";

            # Ignore the tempdefaults.xml definition
            $state = stateFindEntry; # Find another entry
            for my $i ( 1 .. $count )
            {
                pop @NewAttr;
            }
            $count = 0;
        }
        else
        {
            push @NewAttr, [ $line ];
            $count += 1;
        }
    }
    # Check if line ends the <attribute> and <enumerationType> entry
    elsif ($state == stateFindEntryEnd && $line =~ /^\s*<\/$type>.*/)
    {
        $state = stateFindEntry; # Find another entry
        push @NewAttr, [ $line ];
        push @NewAttr, [ "\n" ];
        $count = 0;
    }
    # Save each line of the entry
    elsif ($state == stateFindID || $state == stateFindEntryEnd)
    {
        push @NewAttr, [ $line ];
        $count += 1;
    }
    # Check if line starts a <tempDefault> entry that can be ignored
    elsif ($state == stateFindEntry && $line =~ /^\s*<(tempDefault)>.*/)
    {
        $state = stateTempDefault; # Now find the end of <tempDefault> entry
        $type = $1;
    }
    # Check if line ends the <tempDefault> entry
    elsif ($state == stateTempDefault && $line =~ /^\s*<\/$type>.*/)
    {
        $state = stateFindEntry; # Find another entry
    }
}

close (FH);


# Check input temp_generic.xml file for attributes which have a temporary
# default defined in tempdefaults.xml file.  When an attribute with a temporary
# default is found, either create a default value in the generic.xml data if a
# value does not exist or substitute the default value in the generic.xml data
# if the temporary value is being forced.
#
# Check input temp_generic.xml file for targets which have a temporary default
# defined in hb_temp_defaults.xml file.  Use data from @UpdtTgt to update a
# <targetType> entry for a matching target.
#
# Append <attribute> and <enumerationType> entry lines from @NewAttr before
# ending the attributes section of the generic.xml file.
use constant
{
    stateFindEntry          =>  0,  # Find start of an <attribute> or
                                    # <targetType> entry in the
                                    # temp_generic.xml file
    stateFindAttrID         =>  1,  # Find ID field in the <attribute> entry
    stateFindAttrDataType   =>  2,  # Find data type of the <attribute> entry
    stateFindMultiTypeLns   =>  3,  # Find multiple lines for data type
    stateFindDefaultEnd     =>  4,  # Find end of the default definition
    stateMaxAttr            =>  9,  # Maximum value for attribute states
    stateFindTgtTypeID      => 11,  # Find ID field in the <targetType> entry
    stateFindTgtTypeEnd     => 12,  # Find end of the <targetType> entry
};

$state = stateFindEntry; # First find an entry

open (FH, "<$generic");

while (my $line = <FH>)
{
    # Check if line starts an <attribute> entry
    if ($state < stateMaxAttr && $line =~ /^\s*<attribute>.*/)
    {
        $state = stateFindAttrID; # Next find the ID within attribute entry
    }
    # Check if line starts a <targetType> entry
    elsif ($state == stateFindEntry && $line =~ /^\s*<targetType>.*/)
    {
        $state = stateFindTgtTypeID; # Next find ID within target type entry
    }
    # Check if line specifies the ID of the entry
    elsif (($state == stateFindAttrID || $state == stateFindTgtTypeID) &&
           $line =~ /^\s*<id>/)
    {
        $state += 1; # Increment to the next state, find data type of the
                     # <attribute> entry or end of the <targetType> entry
        $id = $line;
        $id =~ s/\n//;
        $id =~ s/.*<id>(.*)<\/id>.*/$1/;
    }
    # Check if line specifies the data type of the entry
    elsif ($state == stateFindAttrDataType &&
           $line =~ /^.*<(uint8_t|uint16_t|uint32_t|uint64_t|
                            hbmutex|enumeration)>/)
    {
        $type = $1;
        my $definition = $line;
        # If the data type is specified on a single line
        if ($definition =~ /^\s*(.*)<$type>(.*)<\/$type>(.*)/)
        {
            $state = stateFindEntry; # Find another entry
            my $pre = $1;
            $definition = $2;
            my $post = $3;
            $post =~ s/\n//;

            # Go through temporary default data
            for my $i ( 0 .. $#ChgAttr )
            {
                # If ID of temporary default data matches ID of file entry
                if ($ChgAttr[$i][0] eq $id)
                {
                    # If file entry already has a default defined
                    if ($definition =~ /^.*<default>(.*)<\/default>.*/)
                    {
                        # Check if temporary default is not being forced
                        if ($ChgAttr[$i][2] eq "n")
                        {
                            print STDERR
                                "Attribute $id default already exists\n";
                        }
                        else
                        {
                            # Substitute temporary default value
                            $line =~ s/<default>$1/<default>$ChgAttr[$i][1]/;
                        }
                    }
                    else # Create a default definition using temporary default
                    {
                        print "        $pre<$type>\n";
                        print "            <default>$ChgAttr[$i][1]";
                        print "</default>\n";
                        print "            $definition\n" if($definition ne "");
                        $line = "        </$type>$post\n";
                    }

                    last;
                }
            }
        }
        else
        {
            $state = stateFindMultiTypeLns; # Look for data type definition
                                            # across multiple lines
        }
    }
    # Check if line specifies a default value for a multi line data type def
    elsif ($state == stateFindMultiTypeLns && $line =~ /^\s*<default>.*/)
    {
        $state = stateFindEntry; # Find another entry
        # Go through temporary default data
        for my $i ( 0 .. $#ChgAttr )
        {
            # If ID of temporary default data matches ID of file entry
            if ($ChgAttr[$i][0] eq $id)
            {
                # Check if temporary default is not being forced
                if ($ChgAttr[$i][2] eq "n")
                {
                    print STDERR "Attribute $id default already exists\n";
                }
                # If the default is specified on a single line
                elsif ($line =~ /^\s*<default>(.*)<\/default>.*/)
                {
                    # Substitute temporary default value
                    $line =~ s/<default>$1/<default>$ChgAttr[$i][1]/;
                }
                else # Start a default definition using temporary default
                {
                    $state = stateFindDefaultEnd; # Look for end of default
                                                  # definition
                    print "            <default>";
                    print "                $ChgAttr[$i][1]";
                }

                last;
            }
        }
    }
    # Check if line ends a multi line data type definition
    elsif ($state == stateFindMultiTypeLns && $line =~ /^\s*<\/$type>.*/)
    {
        $state = stateFindEntry; # Find another entry
        # Go through temporary default data
        for my $i ( 0 .. $#ChgAttr )
        {
            # If ID of temporary default data matches ID of file entry
            if ($ChgAttr[$i][0] eq $id)
            {
                # Create a default definition using temporary default
                print "        <default>$ChgAttr[$i][1]</default>\n";
            }

            last;
        }
    }
    # Check if line ends default definition for multi line data type definition
    elsif ($state == stateFindDefaultEnd && $line =~ /^\s*<\/default>.*/)
    {
        $state = stateFindEntry; # Find another entry
    }
    # Check if line ends an <attribute> entry
    elsif ($state < stateMaxAttr && $line =~ /^\s*<\/attribute>.*/)
    {
        $state = stateFindEntry; # Find another entry
    }
    # Check if line ends a <targetType> entry
    elsif ($state == stateFindTgtTypeEnd && $line =~ /^\s*<\/targetType>.*/)
    {
        $state = stateFindEntry; # Find another entry
        # Go through update target data
        for my $i ( 0 .. $#UpdtTgt )
        {
            # If ID of update target data matches ID of file entry
            if ($UpdtTgt[$i][0] eq $id)
            {
                # Create new attribute entry for this target
                print "    <attribute>\n";
                print "        <id>$UpdtTgt[$i][2]</id>\n";
                if ($UpdtTgt[$i][3] ne "")
                {
                    print "        <default>$UpdtTgt[$i][3]</default>\n";
                }
                print "    </attribute>\n";
            }
        }
    }
    # Check if line ends the attributes in the input temp_generic.xml file
    elsif ($line =~ /^\s*<\/attributes>.*/)
    {
        # Go through new temporary attribute entries from tempdefaults.xml
        for my $i ( 0 .. $#NewAttr )
        {
            print "$NewAttr[$i][0]";
        }
    }

    print "$line" if $state != stateFindDefaultEnd;
}

close (FH);


sub display_help
{
    use File::Basename;
    my $scriptname = basename($0);
    print STDERR "
Description:

    This perl script processes the fapiattrs.xml and hb_temp_defaults.xml
    files to find any new attributes which need to be defined in the
    generic.xml file.  It also process the tempdefaults.xml file to find the
    <tempDefault> tags and any new attribute definitions so that generic.xml
    can be updated with default values and attribute definitions as needed.
    The updated generic.xml is written to the console.

Usage:

    $scriptname --help
    $scriptname --generic=genericfname
                --fapi=fapifname
                --fapi_inc=fapiincfname
                --fw_dflts=fwdfltsfname
                --defaults=defaultsfname
        --generic=genericfname
              genericfname is complete pathname of the generic.xml file
        --fapi=fapifname
              fapifname is complete pathname of the fapiattrs.xml file
        --fapi_inc=fapiincfname
              fapiincfname is complete pathname of the
              fapi2PlatAttrService.H file
        --fw_dflts=fwdfltsfname
              fwdfltsfname is complete pathname of the
              hb_temp_defaults.xml file
        --defaults=defaultsfname
              defaultsfname is complete pathname of the tempdefaults.xml file
\n";
}
OpenPOWER on IntegriCloud