<commit_before>// Copyright ***********************************************************
//                                                                      
// File ecmdPnorUser.C                                  
//                                                                      
// IBM Confidential                                                     
// OCO Source Materials                                                 
// 9400 Licensed Internal Code                                          
// (C) COPYRIGHT IBM CORP. 2003                                         
//                                                                      
// The source code for this program is not published or otherwise       
// divested of its trade secrets, irrespective of what has been         
// deposited with the U.S. Copyright Office.                            
//                                                                      
// End Copyright *******************************************************

//----------------------------------------------------------------------
//  Includes
//----------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>

#include <ecmdCommandUtils.H>
#include <ecmdReturnCodes.H>
#include <ecmdClientCapi.H>
#include <ecmdUtils.H>
#include <ecmdDataBuffer.H>
#include <ecmdInterpreter.H>
#include <ecmdSharedUtils.H>

//----------------------------------------------------------------------
//  User Types
//----------------------------------------------------------------------


//----------------------------------------------------------------------
//  Constants
//----------------------------------------------------------------------

//----------------------------------------------------------------------
//  Macros
//----------------------------------------------------------------------

//----------------------------------------------------------------------
//  Internal Function Prototypes
//----------------------------------------------------------------------


//----------------------------------------------------------------------
//  Global Variables
//----------------------------------------------------------------------

//---------------------------------------------------------------------
// Member Function Specifications
//---------------------------------------------------------------------
#ifndef ECMD_REMOVE_PNOR_FUNCTIONS
uint32_t ecmdGetPnorUser(int argc, char * argv[]) {

    uint32_t rc = ECMD_SUCCESS;
    ecmdChipTarget l_target;
    ecmdLooperData looperdata;            ///< Store internal Looper data
    ecmdDataBuffer data;                  ///< Data from the pnor api call
    bool validPosFound = false;           ///< Did the looper find anything to execute on
    std::ostringstream oss;
    uint32_t match = 1;
    
    /************************************************************************/
    /* Parse Local FLAGS here!                                              */
    /************************************************************************/

    /* Get the filename if -fb is specified */
    char * filename = ecmdParseOptionWithArgs(&argc, &argv, "-fb");

    bool l_listPnor = ecmdParseOption( &argc, &argv, "-list" );

    if( (filename != NULL) && (l_listPnor) ) 
    {
        oss << "getpnor - Options '-fb' cannot be specified with '--list' option." << std::endl;
        ecmdOutputError(oss.str().c_str());
        return ECMD_INVALID_ARGS;
    } 

    char *partitionName = ecmdParseOptionWithArgs(&argc, &argv, "-name"); 

    if ( (!l_listPnor) && (filename == NULL || partitionName == NULL) )
    {
        oss << "getpnor usage incorrect, -fb and -name are required when not using -list" << std::endl;
        oss << "Use 'getpnor -h' for usage" << std::endl;
        ecmdOutputError(oss.str().c_str());
        return ECMD_INVALID_ARGS;
    }

    char *charOffset = ecmdParseOptionWithArgs(&argc, &argv, "-offset");
    uint32_t offset = 0;
    if ( charOffset != NULL )
    {
        if ( (strchr( charOffset, 'x' )) == NULL && ecmdIsAllDecimal( charOffset ) )
        {
            // no occurance of x in string assuming decimal
            match = sscanf( charOffset, "%d", &offset );
        } 
        else if ( (strchr( charOffset, 'x' )) != NULL || ecmdIsAllHex( charOffset ) )
        {
            char *newCharOffset = strchr( charOffset, 'x' );
            if ( newCharOffset != NULL )
            {
                // move past the x in the string
                newCharOffset++;
            }
            else
            {
                newCharOffset = charOffset;
            }
            // occurrance of x in string, assume hex
            match = sscanf( newCharOffset, "%x", &offset );
        }
        else
        {
            oss << "getpnor - Option '-offset' unable to process value " << charOffset << std::endl;
            ecmdOutputError(oss.str().c_str());
            return ECMD_INVALID_ARGS;
        }
        if ( match != 1 )
        {
            oss << "getpnor - Option '-offset' Error occurred processing value " << charOffset << std::endl;
            ecmdOutputError(oss.str().c_str());
            return ECMD_INVALID_ARGS;
        }
    }

    char* charBlockSize = ecmdParseOptionWithArgs(&argc, &argv, "-block-size");
    uint32_t blockSize = 0;
    if ( charBlockSize != NULL )
    {
        if ( (strchr( charBlockSize, 'x' )) == NULL && ecmdIsAllDecimal( charBlockSize ) )
        {
            // no occurance of x in string assuming decimal
            match = sscanf( charBlockSize, "%d", &blockSize );
        } 
        else if ( (strchr( charBlockSize, 'x' )) != NULL || ecmdIsAllHex( charBlockSize ) )
        {
            char *newCharblockSize = strchr( charBlockSize, 'x' );
            if ( newCharblockSize != NULL )
            {
                // move past the x in the string
                newCharblockSize++;
            }
            else
            {
                newCharblockSize = charBlockSize;
            }
            // occurrance of x in string, assume hex
            match = sscanf( newCharblockSize, "%x", &blockSize );
        }
        else
        {
            oss << "getpnor - Option '-block-size' unable to process value " << charBlockSize << std::endl;
            ecmdOutputError(oss.str().c_str());
            return ECMD_INVALID_ARGS;
        }
        if ( match != 1 )
        {
            oss << "getpnor - Option '-block-size' Error occurred processing value " << charBlockSize << std::endl;
            ecmdOutputError(oss.str().c_str());
            return ECMD_INVALID_ARGS;
        }
    }

    /************************************************************************/
    /* Parse Common Cmdline Args                                            */
    /************************************************************************/
    rc = ecmdCommandArgs(&argc, &argv);
    if (rc) return rc;

    l_target.cageState = l_target.nodeState = ECMD_TARGET_FIELD_WILDCARD;
    l_target.posState = l_target.chipTypeState = ECMD_TARGET_FIELD_UNUSED;
    l_target.slotState = l_target.chipUnitTypeState = l_target.chipUnitNumState = l_target.threadState = ECMD_TARGET_FIELD_UNUSED;

    rc = ecmdLooperInit(l_target, ECMD_SELECTED_TARGETS_LOOP, looperdata);
    if (rc) return rc;
              
    if ( l_listPnor )
    {
        while ( ecmdLooperNext(l_target, looperdata) ) 
        {
            validPosFound = true;
            ecmdPnorListData myPnorData;

            rc = ecmdGetPnorList( l_target, partitionName, offset, myPnorData );
            if ( rc ) break;

            std::ostringstream ossPnor;
            ossPnor << "=========================" << "[ PARTITION TABLE 0x";
            ossPnor << std::hex << offset << " ]" << "=========================";
            ossPnor << std::endl;
            ossPnor << "vers:" << std::setfill('0') << std::setw(4) << std::dec << myPnorData.hdrVersion;
            ossPnor << " size:" << std::setfill('0') << std::setw(4) << std::dec << myPnorData.hdrSize;
            ossPnor << " * blk:" << std::setfill('0') << std::setw(6) << std::hex << myPnorData.hdrBlockSize;
            ossPnor << " blk(s):" << std::setfill('0') << std::setw(6) << std::hex << myPnorData.hdrBlockCount;
            ossPnor << " * entsz:" << std::setfill('0') << std::setw(6) << std::hex << myPnorData.hdrEntrySize;
            ossPnor << " ent(s):" << std::setfill('0') << std::setw(6) << std::hex << myPnorData.hdrEntryCount;
            ossPnor << std::endl;
            ossPnor << "-------------------------------------------------------------------------" << std::endl;
            
            std::list<ecmdPnorListEntryData>::iterator myIt;
            for ( myIt = (myPnorData.hdrEntries).begin(); myIt != (myPnorData.hdrEntries).end(); myIt++ )
            {
                if ( partitionName != NULL && strcmp((myIt)->entryName.c_str(), partitionName) != 0 )
                {
                    continue;
                }
                uint32_t baseAddr = myPnorData.hdrBlockSize * (myIt)->entryBase;
                uint32_t sizeAddr = myPnorData.hdrBlockSize * (myIt)->entrySize;
                ossPnor << std::setw(3) << std::dec << (myIt)->entryId;
                ossPnor << " [" << std::setfill('0') << std::setw(8) << std::hex << baseAddr;
                ossPnor << "-" << std::setfill('0') << std::setw(8) << std::hex << baseAddr+sizeAddr-1;
                ossPnor << "] [" << std::setfill(' ') << std::setw(8) << std::hex << sizeAddr;
                ossPnor << ":" << std::setfill(' ') << std::setw(8) << std::hex << (myIt)->entryActual;
                ossPnor << "] [";
                if ( (myIt)->entryType & ECMD_PNOR_TYPE_LOGICAL )
                {
                    ossPnor << "l";
                }
                else if ( (myIt)->entryType & ECMD_PNOR_TYPE_DATA )
                {
                    ossPnor << "d";
                }
                else if ( (myIt)->entryType & ECMD_PNOR_TYPE_PARTITION )
                {
                    ossPnor << "p";
                }
                else
                {
                    ossPnor << "-";
                }
                ossPnor << "---";
                if ( (myIt)->entryFlags & ECMD_PNOR_FLAGS_U_BOOT_ENV )
                {
                    ossPnor << " ";
                }
                else
                {
                    ossPnor << "-";<commit_msg>functionality updates for pnor function<commit_after>// Copyright ***********************************************************
//                                                                      
// File ecmdPnorUser.C                                  
//                                                                      
// IBM Confidential                                                     
// OCO Source Materials                                                 
// 9400 Licensed Internal Code                                          
// (C) COPYRIGHT IBM CORP. 2003                                         
//                                                                      
// The source code for this program is not published or otherwise       
// divested of its trade secrets, irrespective of what has been         
// deposited with the U.S. Copyright Office.                            
//                                                                      
// End Copyright *******************************************************

//----------------------------------------------------------------------
//  Includes
//----------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>

#include <ecmdCommandUtils.H>
#include <ecmdReturnCodes.H>
#include <ecmdClientCapi.H>
#include <ecmdUtils.H>
#include <ecmdDataBuffer.H>
#include <ecmdInterpreter.H>
#include <ecmdSharedUtils.H>

//----------------------------------------------------------------------
//  User Types
//----------------------------------------------------------------------


//----------------------------------------------------------------------
//  Constants
//----------------------------------------------------------------------

//----------------------------------------------------------------------
//  Macros
//----------------------------------------------------------------------

//----------------------------------------------------------------------
//  Internal Function Prototypes
//----------------------------------------------------------------------


//----------------------------------------------------------------------
//  Global Variables
//----------------------------------------------------------------------

//---------------------------------------------------------------------
// Member Function Specifications
//---------------------------------------------------------------------
#ifndef ECMD_REMOVE_PNOR_FUNCTIONS
uint32_t ecmdGetPnorUser(int argc, char * argv[]) {

    uint32_t rc = ECMD_SUCCESS;
    ecmdChipTarget l_target;
    ecmdLooperData looperdata;            ///< Store internal Looper data
    ecmdDataBuffer data;                  ///< Data from the pnor api call
    bool validPosFound = false;           ///< Did the looper find anything to execute on
    std::ostringstream oss;
    uint32_t match = 1;
    
    /************************************************************************/
    /* Parse Local FLAGS here!                                              */
    /************************************************************************/

    /* Get the filename if -fb is specified */
    char * filename = ecmdParseOptionWithArgs(&argc, &argv, "-fb");

    bool l_listPnor = ecmdParseOption( &argc, &argv, "-list" );

    if( (filename != NULL) && (l_listPnor) ) 
    {
        oss << "getpnor - Options '-fb' cannot be specified with '--list' option." << std::endl;
        ecmdOutputError(oss.str().c_str());
        return ECMD_INVALID_ARGS;
    } 

    char *partName = ecmdParseOptionWithArgs(&argc, &argv, "-name"); 

    if ( (!l_listPnor) && (filename == NULL || partName == NULL) )
    {
        oss << "getpnor usage incorrect, -fb and -name are required when not using -list" << std::endl;
        oss << "Use 'getpnor -h' for usage" << std::endl;
        ecmdOutputError(oss.str().c_str());
        return ECMD_INVALID_ARGS;
    }

    std::string partitionName;
    if ( partName == NULL )
    {
        partitionName = std::string();
    }
    else
    {
        partitionName = partName;
    }

    char *charOffset = ecmdParseOptionWithArgs(&argc, &argv, "-offset");
    uint32_t offset = 0;
    if ( charOffset != NULL )
    {
        if ( (strchr( charOffset, 'x' )) == NULL && ecmdIsAllDecimal( charOffset ) )
        {
            // no occurance of x in string assuming decimal
            match = sscanf( charOffset, "%d", &offset );
        } 
        else if ( (strchr( charOffset, 'x' )) != NULL || ecmdIsAllHex( charOffset ) )
        {
            char *newCharOffset = strchr( charOffset, 'x' );
            if ( newCharOffset != NULL )
            {
                // move past the x in the string
                newCharOffset++;
            }
            else
            {
                newCharOffset = charOffset;
            }
            // occurrance of x in string, assume hex
            match = sscanf( newCharOffset, "%x", &offset );
        }
        else
        {
            oss << "getpnor - Option '-offset' unable to process value " << charOffset << std::endl;
            ecmdOutputError(oss.str().c_str());
            return ECMD_INVALID_ARGS;
        }
        if ( match != 1 )
        {
            oss << "getpnor - Option '-offset' Error occurred processing value " << charOffset << std::endl;
            ecmdOutputError(oss.str().c_str());
            return ECMD_INVALID_ARGS;
        }
    }

    char* charBlockSize = ecmdParseOptionWithArgs(&argc, &argv, "-block-size");
    uint32_t blockSize = 0;
    if ( charBlockSize != NULL )
    {
        if ( (strchr( charBlockSize, 'x' )) == NULL && ecmdIsAllDecimal( charBlockSize ) )
        {
            // no occurance of x in string assuming decimal
            match = sscanf( charBlockSize, "%d", &blockSize );
        } 
        else if ( (strchr( charBlockSize, 'x' )) != NULL || ecmdIsAllHex( charBlockSize ) )
        {
            char *newCharblockSize = strchr( charBlockSize, 'x' );
            if ( newCharblockSize != NULL )
            {
                // move past the x in the string
                newCharblockSize++;
            }
            else
            {
                newCharblockSize = charBlockSize;
            }
            // occurrance of x in string, assume hex
            match = sscanf( newCharblockSize, "%x", &blockSize );
        }
        else
        {
            oss << "getpnor - Option '-block-size' unable to process value " << charBlockSize << std::endl;
            ecmdOutputError(oss.str().c_str());
            return ECMD_INVALID_ARGS;
        }
        if ( match != 1 )
        {
            oss << "getpnor - Option '-block-size' Error occurred processing value " << charBlockSize << std::endl;
            ecmdOutputError(oss.str().c_str());
            return ECMD_INVALID_ARGS;
        }
    }

    /************************************************************************/
    /* Parse Common Cmdline Args                                            */
    /************************************************************************/
    rc = ecmdCommandArgs(&argc, &argv);
    if (rc) return rc;

    l_target.cageState = l_target.nodeState = ECMD_TARGET_FIELD_WILDCARD;
    l_target.posState = l_target.chipTypeState = ECMD_TARGET_FIELD_UNUSED;
    l_target.slotState = l_target.chipUnitTypeState = l_target.chipUnitNumState = l_target.threadState = ECMD_TARGET_FIELD_UNUSED;

    rc = ecmdLooperInit(l_target, ECMD_SELECTED_TARGETS_LOOP, looperdata);
    if (rc) return rc;
              
    if ( l_listPnor )
    {
        while ( ecmdLooperNext(l_target, looperdata) ) 
        {
            validPosFound = true;
            ecmdPnorListData myPnorData;

            rc = ecmdGetPnorList( l_target, partitionName, offset, myPnorData );
            if ( rc ) break;

            std::ostringstream ossPnor;
            ossPnor << "==========================" << "[ PARTITION TABLE 0x";
            ossPnor << std::hex << offset << " ]" << "==========================";
            ossPnor << std::endl;
            ossPnor << "vers:" << std::setfill('0') << std::setw(4) << std::dec << myPnorData.hdrVersion;
            ossPnor << " size:" << std::setfill('0') << std::setw(4) << std::dec << myPnorData.hdrSize;
            ossPnor << " * blk:" << std::setfill('0') << std::setw(6) << std::hex << myPnorData.hdrBlockSize;
            ossPnor << " blk(s):" << std::setfill('0') << std::setw(6) << std::hex << myPnorData.hdrBlockCount;
            ossPnor << " * entsz:" << std::setfill('0') << std::setw(6) << std::hex << myPnorData.hdrEntrySize;
            ossPnor << " ent(s):" << std::setfill('0') << std::setw(6) << std::hex << myPnorData.hdrEntryCount;
            ossPnor << std::endl;
            ossPnor << "---------------------------------------------------------------------------" << std::endl;
            
            std::list<ecmdPnorListEntryData>::iterator myIt;
            for ( myIt = (myPnorData.hdrEntries).begin(); myIt != (myPnorData.hdrEntries).end(); myIt++ )
            {
                if ( partitionName.size() != 0 && ((myIt)->entryName != partitionName) )
                {
                    continue;
                }
                uint32_t baseAddr = myPnorData.hdrBlockSize * (myIt)->entryBase;
                uint32_t sizeAddr = myPnorData.hdrBlockSize * (myIt)->entrySize;
                ossPnor << std::setfill(' ') << std::setw(3) << std::dec << (myIt)->entryId;
                ossPnor << " [" << std::setfill('0') << std::setw(8) << std::hex << baseAddr;
                ossPnor << "-" << std::setfill('0') << std::setw(8) << std::hex << baseAddr+sizeAddr-1;
                ossPnor << "] [" << std::setfill(' ') << std::setw(8) << std::hex << sizeAddr;
                ossPnor << ":" << std::setfill(' ') << std::setw(8) << std::hex << (myIt)->entryActual;
                ossPnor << "] [";
                if ( (myIt)->entryType == ECMD_PNOR_TYPE_LOGICAL )
                {
                    ossPnor << "l";
                }
                else if ( (myIt)->entryType == ECMD_PNOR_TYPE_DATA )
                {
                    ossPnor << "d";
                }
                else if ( (myIt)->entryType == ECMD_PNOR_TYPE_PARTITION )
                {
                    ossPnor << "p";
                }
                else
                {
                    ossPnor << "-";
                }
                ossPnor << "---";
                if ( (myIt)->entryFlags & ECMD_PNOR_FLAGS_U_BOOT_ENV )
                {
                    ossPnor << " ";
                }
                else
                {
                    ossPnor << "-";
{'fraction_non_alphanumeric': 0.253592996582557, 'fraction_numerical': 0.004587800196620009, 'mean_word_length': 1.2660443407234538, 'pattern_counts': {'":': 2, '<': 395, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5540324', 'n_tokens_mistral': 5596, 'n_tokens_neox': 5308, 'n_words': 1168}