int main(int argc, char const *argv[]) { int n[10]={0,1,2,3,4,8,34,21,6,10}; sortArray(n,10); putArray(n,10); return 0; }
uint32_t ecmdPutArrayUser(int argc, char * argv[]) { uint32_t rc = ECMD_SUCCESS; uint32_t coeRc = ECMD_SUCCESS; //@02 ecmdChipTarget target; ///< Current target ecmdChipTarget cuTarget; ///< Current target being operated on for the chipUnits std::string arrayName; ///< Name of array to access ecmdDataBuffer address; ///< Buffer to store address ecmdDataBuffer buffer; ///< Buffer to store data to write with ecmdDataBuffer cmdlineBuffer; ///< Buffer to store data to be inserted bool validPosFound = false; ///< Did we find something to actually execute on ? std::string printed; ///< Print Buffer ecmdLooperData looperData; ///< Store internal Looper data ecmdLooperData cuLooper; ///< Store internal Looper data for the chipUnit loop std::list<ecmdArrayData> arrayDataList; ///< Query data about array std::list<ecmdArrayData>::iterator arrayData; ///< arrayData from the query uint8_t oneLoop = 0; ///< Used to break out of the chipUnit loop after the first pass for non chipUnit operations std::string inputformat = "x"; ///< Default input format std::string dataModifier = "insert"; ///< Default data Modifier (And/Or/insert) uint32_t startbit = ECMD_UNSET; ///< Startbit to insert data uint32_t numbits = 0; ///< Number of bits to insert data char* cmdlinePtr = NULL; ///< Pointer to data in argv array /************************************************************************/ /* Parse Local ARGS here! */ /************************************************************************/ char* formatPtr = ecmdParseOptionWithArgs(&argc, &argv, "-i"); if (formatPtr != NULL) { inputformat = formatPtr; } formatPtr = ecmdParseOptionWithArgs(&argc, &argv, "-b"); if (formatPtr != NULL) { dataModifier = formatPtr; } /************************************************************************/ /* Parse Common Cmdline Args */ /************************************************************************/ rc = ecmdCommandArgs(&argc, &argv); if (rc) return rc; /* Global args have been parsed, we can read if -coe was given */ bool coeMode = ecmdGetGlobalVar(ECMD_GLOBALVAR_COEMODE); ///< Are we in continue on error mode if (argc < 4) { ecmdOutputError("putarray - Too few arguments specified; you need at least a chip, an array, an address, and some data.\n"); ecmdOutputError("putarray - Type 'putarray -h' for usage.\n"); return ECMD_INVALID_ARGS; } //Setup the target that will be used to query the system config std::string chipType, chipUnitType; ecmdParseChipField(argv[0], chipType, chipUnitType); target.chipType = chipType; target.chipTypeState = ECMD_TARGET_FIELD_VALID; target.cageState = target.nodeState = target.slotState = target.posState = ECMD_TARGET_FIELD_WILDCARD; target.chipUnitTypeState = target.chipUnitNumState = target.threadState = ECMD_TARGET_FIELD_UNUSED; /* Get the name */ arrayName = argv[1]; /* Get the index into the array */ rc = ecmdReadDataFormatted(address, argv[2], "xr"); /* Did they specify a start/numbits */ if (argc > 4) { if (argc != 6) { ecmdOutputError("putarray - Too many arguments specified; you probably added an unsupported option.\n"); ecmdOutputError("putarray - Type 'putarray -h' for usage.\n"); return ECMD_INVALID_ARGS; } if (!ecmdIsAllDecimal(argv[3])) { ecmdOutputError("putarray - Non-decimal characters detected in startbit field\n"); return ECMD_INVALID_ARGS; } startbit = (uint32_t)atoi(argv[3]); if (!ecmdIsAllDecimal(argv[4])) { ecmdOutputError("putarray - Non-decimal characters detected in numbits field\n"); return ECMD_INVALID_ARGS; } numbits = (uint32_t)atoi(argv[4]); /* Bounds check */ if ((startbit + numbits) > ECMD_MAX_DATA_BITS) { char errbuf[100]; sprintf(errbuf,"putarray - Too much data requested > %d bits\n", ECMD_MAX_DATA_BITS); ecmdOutputError(errbuf); return ECMD_DATA_BOUNDS_OVERFLOW; } else if (numbits == 0) { ecmdOutputError("putarray - Number of bits == 0, operation not performed\n"); return ECMD_INVALID_ARGS; } rc = ecmdReadDataFormatted(cmdlineBuffer, argv[5], inputformat, numbits); if (rc) { ecmdOutputError("putarray - Problems occurred parsing input data, must be an invalid format\n"); return rc; } } else { cmdlinePtr = argv[3]; } rc = ecmdLooperInit(target, ECMD_SELECTED_TARGETS_LOOP, looperData); if (rc) return rc; while (ecmdLooperNext(target, looperData) && (!coeRc || coeMode)) { /* We need to find out info about this array */ rc = ecmdQueryArray(target, arrayDataList , arrayName.c_str(), ECMD_QUERY_DETAIL_LOW); if (rc || arrayDataList.empty()) { printed = "putarray - Problems retrieving data about array '" + arrayName + "' on "; printed += ecmdWriteTarget(target) + "\n"; ecmdOutputError( printed.c_str() ); coeRc = rc; continue; } arrayData = arrayDataList.begin(); /* If we have a cmdlinePtr, read it in now that we have a length we can use */ if (cmdlinePtr != NULL) { if (dataModifier == "insert") { rc = ecmdReadDataFormatted(buffer, cmdlinePtr, inputformat, arrayData->width); } else { rc = ecmdReadDataFormatted(cmdlineBuffer, cmdlinePtr, inputformat, arrayData->width); } if (rc) { ecmdOutputError("putarray - Problems occurred parsing input data, must be an invalid format\n"); coeRc = rc; continue; } } /* Set the length of the address field if it wasn't given properly */ if (arrayData->writeAddressLength > address.getBitLength()) { uint32_t difference = (arrayData->writeAddressLength - address.getBitLength()); address.shiftRightAndResize(difference); } else if (address.getBitLength() > arrayData->writeAddressLength) { char errbuf[100]; sprintf(errbuf,"putarray - Too much address data provided with a length of %d bits.\n", address.getBitLength()); ecmdOutputError(errbuf); sprintf(errbuf,"putarray - The array you are writing only supports an address of %d bits.\n", arrayData->writeAddressLength); ecmdOutputError(errbuf); coeRc = ECMD_DATA_BOUNDS_OVERFLOW; continue; } address.setBitLength(arrayData->writeAddressLength); rc = address.insertFromHexRight(argv[2], 0, arrayData->writeAddressLength); if (rc) { ecmdOutputError("putarray - Invalid number format detected trying to parse address\n"); coeRc = rc; continue; } /* Setup our chipUnit looper if needed */ cuTarget = target; if (arrayData->isChipUnitRelated) { /* Error check the chipUnit returned */ if (!arrayData->isChipUnitMatch(chipUnitType)) { printed = "putarray - Provided chipUnit \""; printed += chipUnitType; printed += "\"doesn't match chipUnit returned by queryArray \""; printed += arrayData->relatedChipUnit + "\"\n"; ecmdOutputError( printed.c_str() ); rc = ECMD_INVALID_ARGS; break; } /* If we have a chipUnit, set the state fields properly */ if (chipUnitType != "") { cuTarget.chipUnitType = chipUnitType; cuTarget.chipUnitTypeState = ECMD_TARGET_FIELD_VALID; } cuTarget.chipUnitNumState = ECMD_TARGET_FIELD_WILDCARD; cuTarget.threadState = ECMD_TARGET_FIELD_UNUSED; /* Init the chipUnit loop */ rc = ecmdLooperInit(cuTarget, ECMD_SELECTED_TARGETS_LOOP, cuLooper); if (rc) return rc; } else { // !arrayData->isChipUnitRelated if (chipUnitType != "") { printed = "putarray - A chipUnit \""; printed += chipUnitType; printed += "\" was given on a non chipUnit array\n"; ecmdOutputError(printed.c_str()); rc = ECMD_INVALID_ARGS; break; } // Setup the variable oneLoop variable for this non-chipUnit case oneLoop = 1; } /* If this isn't a chipUnit array we will fall into while loop and break at the end, if it is we will call run through configloopernext */ while ((arrayData->isChipUnitRelated ? ecmdLooperNext(cuTarget, cuLooper) : (oneLoop--)) && (!coeRc || coeMode)) { /* Do we need to perform a read/modify/write op ? */ if ((dataModifier != "insert") || (startbit != ECMD_UNSET)) { rc = getArray(cuTarget, arrayName.c_str(), address, buffer); if (rc) { printed = "putarray - Error occured performing getarray on "; printed += ecmdWriteTarget(cuTarget); printed += "\n"; ecmdOutputError( printed.c_str() ); coeRc = rc; continue; } else { validPosFound = true; } rc = ecmdApplyDataModifier(buffer, cmdlineBuffer, (startbit == ECMD_UNSET ? 0 : startbit), dataModifier); if (rc) { coeRc = rc; continue; } } rc = putArray(cuTarget, arrayName.c_str(), address, buffer); if (rc) { printed = "putarray - Error occured performing putarray on "; printed += ecmdWriteTarget(target) + "\n"; ecmdOutputError( printed.c_str() ); coeRc = rc; continue; } else { validPosFound = true; } if (!ecmdGetGlobalVar(ECMD_GLOBALVAR_QUIETMODE)) { printed = ecmdWriteTarget(target) + "\n"; ecmdOutput(printed.c_str()); } } /* End cuLooper */ } /* End PosLooper */ // coeRc will be the return code from in the loop, coe mode or not. if (coeRc) return coeRc; if (!validPosFound) { //this is an error common across all UI functions ecmdOutputError("putarray - Unable to find a valid chip to execute command on\n"); return ECMD_TARGET_NOT_CONFIGURED; } return rc; }