<commit_before>#!/usr/bin/perl
#  IBM_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  $Source: src/usr/hwpf/fapi/fapiCreateIfAttrService.pl $
#
#  IBM CONFIDENTIAL
#
#  COPYRIGHT International Business Machines Corp. 2011
#
#  p1
#
#  Object Code Only (OCO) source materials
#  Licensed Internal Code Source Materials
#  IBM HostBoot Licensed Internal Code
#
#  The source code for this program is not published or other-
#  wise divested of its trade secrets, irrespective of what has
#  been deposited with the U.S. Copyright Office.
#
#  Origin: 30
#
#  IBM_PROLOG_END
#
# Purpose:  This perl script will parse HWP Attribute XML files and
# initfile attr files and create the fapiGetInitFileAttr() function
# in a file called fapiAttributeService.C
#
# Author: <NAME>
#
# Change Log **********************************************************
#
#  Flag  Track#    Userid    Date      Description
#  ----  --------  --------  --------  -----------
#                  mjjones   11/15/11  Copied from fapiParseAttributeInfo
#
# End Change Log ******************************************************

use strict;

#------------------------------------------------------------------------------
# Print Command Line Help
#------------------------------------------------------------------------------
my $numArgs = $#ARGV + 1;
if ($numArgs < 4)
{
    print ("Usage: fapiCreateIfAttrService.pl <output dir>\n");
    print ("           <if-attr-file1> [<if-attr-file2> ...]\n");
    print ("           -a <attr-xml-file1> [<attr-xml-file2> ...]\n");
    print ("  This perl script will parse initfile attr files and attribute XML\n");
    print ("  files and create the fapiGetInitFileAttr() function in a file\n");
    print ("  called fapiAttributeService.C\n");
    exit(1);
}

#------------------------------------------------------------------------------
# Specify perl modules to use
#------------------------------------------------------------------------------
use XML::Simple;
my $xml = new XML::Simple (KeyAttr=>[]);

# Uncomment to enable debug output
#use Data::Dumper;

#------------------------------------------------------------------------------
# Open output file for writing
#------------------------------------------------------------------------------
my $asFile = $ARGV[0];
$asFile .= "/";
$asFile .= "fapiAttributeService.C";
open(ASFILE, ">", $asFile);

#------------------------------------------------------------------------------
# Print Start of file information to fapiAttributeService.C
#------------------------------------------------------------------------------
print ASFILE "// fapiAttributeService.C\n";
print ASFILE "// This file is generated by perl script fapiCreateIfAttrService.pl\n\n";
print ASFILE "#include <fapiAttributeService.H>\n\n";
print ASFILE "namespace fapi\n";
print ASFILE "{\n\n";
print ASFILE "ReturnCode fapiGetInitFileAttr(const AttributeId i_id,\n";
print ASFILE "                               const Target * i_pTarget,\n";
print ASFILE "                               uint64_t & o_val,\n";
print ASFILE "                               const uint32_t i_arrayIndex1,\n";
print ASFILE "                               const uint32_t i_arrayIndex2,\n";
print ASFILE "                               const uint32_t i_arrayIndex3,\n";
print ASFILE "                               const uint32_t i_arrayIndex4)\n";
print ASFILE "{\n";
print ASFILE "    ReturnCode l_rc;\n\n";

my $xmlFiles = 0;
my $attCount = 0;
my @attrIds;

#------------------------------------------------------------------------------
# For each argument
#------------------------------------------------------------------------------
foreach my $argnum (1 .. $#ARGV)
{
    my $infile = $ARGV[$argnum];

    if ($infile eq '-a')
    {
        # Start of attribute XML files
        $xmlFiles = 1;
        next;
    }

    if ($xmlFiles == 0)
    {
        #----------------------------------------------------------------------
        # Process initfile attr file. This file contains the HWPF attributes
        # that the initfile uses.
        #----------------------------------------------------------------------
        open(ATTRFILE, "<", $infile);
        
        # Read each line of the file (each line contains an attribute)
        while(my $fileAttrId = <ATTRFILE>)
        {
            # Remove newline
            chomp($fileAttrId);

            # Store the attribute in @attrIds if it does not already exist
            my $match = 0;

            foreach my $attrId (@attrIds)
            {
                if ($fileAttrId eq $attrId)
                {
                    $match = 1;
                    last;
                }
            }

            if (!($match))
            {
                push(@attrIds, $fileAttrId);
            }
        } 

        close(ATTRFILE);
    }
    else
    {
        #----------------------------------------------------------------------
        # Process XML file
        #----------------------------------------------------------------------
        my $attributes = $xml->XMLin($infile);

        #----------------------------------------------------------------------
        # For each Attribute
        #----------------------------------------------------------------------
        foreach my $attr (@{$attributes->{attribute}})
        {
            #------------------------------------------------------------------
            # Check that the AttributeId exists
            #------------------------------------------------------------------
            if (! exists $attr->{id})
            {
                print ("fapiParseAttributeInfo.pl ERROR. Att 'id' missing\n");
                exit(1);
            }

            #------------------------------------------------------------------
            # Find if the attribute is used by any initfile
            #------------------------------------------------------------------
            my $match = 0;

            foreach my $attrId (@attrIds)
            {
                if ($attr->{id} eq $attrId)
                {
                    $match = 1;
                    last;
                }<commit_msg>HWPF: Add option to support read of all attrs for initfiles (for Cronus)<commit_after>#!/usr/bin/perl
#  IBM_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  $Source: src/usr/hwpf/fapi/fapiCreateIfAttrService.pl $
#
#  IBM CONFIDENTIAL
#
#  COPYRIGHT International Business Machines Corp. 2011
#
#  p1
#
#  Object Code Only (OCO) source materials
#  Licensed Internal Code Source Materials
#  IBM HostBoot Licensed Internal Code
#
#  The source code for this program is not published or other-
#  wise divested of its trade secrets, irrespective of what has
#  been deposited with the U.S. Copyright Office.
#
#  Origin: 30
#
#  IBM_PROLOG_END
#
# Purpose:  This perl script will parse HWP Attribute XML files and
# initfile attr files and create the fapiGetInitFileAttr() function
# in a file called fapiAttributeService.C
#
# Author: <NAME>
#
# Change Log **********************************************************
#
#  Flag  Track#    Userid    Date      Description
#  ----  --------  --------  --------  -----------
#                  mjjones   11/15/11  Copied from fapiParseAttributeInfo
#                  mjjones   12/12/11  Support all attributes if no if-attr
#                                      files specified (for Cronus)
#
# End Change Log ******************************************************

use strict;

#------------------------------------------------------------------------------
# Print Command Line Help
#------------------------------------------------------------------------------
my $numArgs = $#ARGV + 1;
if ($numArgs < 3)
{
    print ("Usage: fapiCreateIfAttrService.pl <output dir>\n");
    print ("           [<if-attr-file1> <if-attr-file2> ...]\n");
    print ("           -a <attr-xml-file1> [<attr-xml-file2> ...]\n");
    print ("  This perl script will parse if-attr files (containing the\n");
    print ("  attributes used by the initfile) and attribute XML files\n");
    print ("  (containing all HWPF attributes) and create the\n");
    print ("  fapiGetInitFileAttr() function in a file called\n");
    print ("  fapiAttributeService.C. Only the attributes specified in\n");
    print ("  the if-attr files are supported. If no if-attr files are\n");
    print ("  specified then all attributes are supported\n");
    exit(1);
}

#------------------------------------------------------------------------------
# Specify perl modules to use
#------------------------------------------------------------------------------
use XML::Simple;
my $xml = new XML::Simple (KeyAttr=>[]);

# Uncomment to enable debug output
#use Data::Dumper;

#------------------------------------------------------------------------------
# Open output file for writing
#------------------------------------------------------------------------------
my $asFile = $ARGV[0];
$asFile .= "/";
$asFile .= "fapiAttributeService.C";
open(ASFILE, ">", $asFile);

#------------------------------------------------------------------------------
# Print Start of file information to fapiAttributeService.C
#------------------------------------------------------------------------------
print ASFILE "// fapiAttributeService.C\n";
print ASFILE "// This file is generated by perl script fapiCreateIfAttrService.pl\n\n";
print ASFILE "#include <fapiAttributeService.H>\n\n";
print ASFILE "namespace fapi\n";
print ASFILE "{\n\n";
print ASFILE "ReturnCode fapiGetInitFileAttr(const AttributeId i_id,\n";
print ASFILE "                               const Target * i_pTarget,\n";
print ASFILE "                               uint64_t & o_val,\n";
print ASFILE "                               const uint32_t i_arrayIndex1,\n";
print ASFILE "                               const uint32_t i_arrayIndex2,\n";
print ASFILE "                               const uint32_t i_arrayIndex3,\n";
print ASFILE "                               const uint32_t i_arrayIndex4)\n";
print ASFILE "{\n";
print ASFILE "    ReturnCode l_rc;\n\n";

my $xmlFiles = 0;
my $attCount = 0;
my $numIfAttrFiles = 0;
my @attrIds;

#------------------------------------------------------------------------------
# For each argument
#------------------------------------------------------------------------------
foreach my $argnum (1 .. $#ARGV)
{
    my $infile = $ARGV[$argnum];

    if ($infile eq '-a')
    {
        # Start of attribute XML files
        $xmlFiles = 1;
        next;
    }

    if ($xmlFiles == 0)
    {
        #----------------------------------------------------------------------
        # Process initfile attr file. This file contains the HWPF attributes
        # that the initfile uses.
        #----------------------------------------------------------------------
        $numIfAttrFiles++;
        open(ATTRFILE, "<", $infile);
        
        # Read each line of the file (each line contains an attribute)
        while(my $fileAttrId = <ATTRFILE>)
        {
            # Remove newline
            chomp($fileAttrId);

            # Store the attribute in @attrIds if it does not already exist
            my $match = 0;

            foreach my $attrId (@attrIds)
            {
                if ($fileAttrId eq $attrId)
                {
                    $match = 1;
                    last;
                }
            }

            if (!($match))
            {
                push(@attrIds, $fileAttrId);
            }
        } 

        close(ATTRFILE);
    }
    else
    {
        #----------------------------------------------------------------------
        # Process XML file
        #----------------------------------------------------------------------
        my $attributes = $xml->XMLin($infile);

        #----------------------------------------------------------------------
        # For each Attribute
        #----------------------------------------------------------------------
        foreach my $attr (@{$attributes->{attribute}})
        {
            #------------------------------------------------------------------
            # Check that the AttributeId exists
            #------------------------------------------------------------------
            if (! exists $attr->{id})
            {
                print ("fapiParseAttributeInfo.pl ERROR. Att 'id' missing\n");
                exit(1);
            }

            #------------------------------------------------------------------
            # Find if the attribute is used by any initfile. If no if-attr
            # files were specified then support all attributes
            #------------------------------------------------------------------
            my $match = 0;

            if ($numIfAttrFiles)
            {
                foreach my $attrId (@attrIds)
                {
                    if ($attr->{id} eq $attrId)
                    {
                        $match = 1;
                        last;
                    }
                }
            }
            else
            {
                $match = 1;
{'fraction_non_alphanumeric': 0.32563264685766397, 'fraction_numerical': 0.007447374420548674, 'mean_word_length': 0.9852164730728616, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3944804', 'n_tokens_mistral': 3114, 'n_tokens_neox': 2975, 'n_words': 906}