IpxAddress PacketReader::readIpxAddress() { IpxAddress temp = IpxAddress(); readArray(temp.network, 4); readArray(temp.node, 6); readArray(temp.socket, 2); return temp; }
asynStatus isisdaeDriver::readInt32Array(asynUser *pasynUser, epicsInt32 *value, size_t nElements, size_t *nIn) { asynStatus stat = readArray(pasynUser, "readInt32Array", value, nElements, nIn); callParamCallbacks(); // this flushes P_ErrMsgs doCallbacksInt32Array(value, *nIn, pasynUser->reason, 0); return stat; }
inline StringArray readStringArray(std::istream& istrm) { BinarySerialization::verifySignature(istrm, BINSIG_STRARRAY); StringArray stra; readArray(istrm, stra); return stra; }
/* get the SA of text * if filename is given search if the SA is already computed */ unsigned int* getSA(unsigned char const* text, int length, const char* filename){ char filename_temp[] = "stdin"; char filename_sa[1024]; unsigned int* sa; if(filename == NULL) filename = filename_temp; /*filename = basename(filename);*/ /*not sure about this*/ snprintf(filename_sa,1024,"%s.sa",filename); /* checks if we already computed the SA*/ if(access(filename_sa, R_OK)!=0 || strcmp(filename,"stdin") == 0 || strcmp(filename, "stdin.rev") == 0){ sa = new unsigned int[length]; unsigned int err = divsufsort(text, (saidx_t*)sa, (saidx_t)length); if(err){ fprintf(stderr, "ERROR: SA: constructing the SA\n"); } err = saveArray((unsigned char*)sa, length * sizeof(unsigned int), filename_sa); if(err != 0){ fprintf(stderr,"ERROR: SA: saving the SA\n"); } }else{ unsigned int salen; sa = (unsigned int*)readArray(filename_sa, &salen, sizeof(unsigned int)); } return sa; }
QList<segment_command_64> MACHFile::getSegmentsList64() { QList<load_command_offset> list=getLoadCommands_offset(); unsigned int nOffset=0; QList<segment_command_64> listResult; segment_command_64 record; for(int i=0; i<list.count(); i++) { if(list.at(i).cmd==LC_SEGMENT_64) { nOffset=list.at(i).offset; record.cmd=readDword(nOffset+offsetof(segment_command_64,cmd),isReverse()); record.cmdsize=readDword(nOffset+offsetof(segment_command_64,cmdsize),isReverse()); readArray(nOffset+offsetof(segment_command_64,segname),record.segname,16); record.vmaddr=readQword(nOffset+offsetof(segment_command_64,vmaddr),isReverse()); record.vmsize=readQword(nOffset+offsetof(segment_command_64,vmsize),isReverse()); record.fileoff=readQword(nOffset+offsetof(segment_command_64,fileoff),isReverse()); record.filesize=readQword(nOffset+offsetof(segment_command_64,filesize),isReverse()); record.maxprot=readDword(nOffset+offsetof(segment_command_64,maxprot),isReverse()); record.initprot=readDword(nOffset+offsetof(segment_command_64,initprot),isReverse()); record.nsects=readDword(nOffset+offsetof(segment_command_64,nsects),isReverse()); record.flags=readDword(nOffset+offsetof(segment_command_64,flags),isReverse()); listResult.append(record); } } return listResult; }
QList<section> MACHFile::getSectionsList32() { QList<section> listResult; // return listResult; QList<load_command_offset> list=getLoadCommands_offset(); unsigned int nOffset=0; section record; unsigned int nNumberOfSections=0; for(int i=0; i<list.count(); i++) { if(list.at(i).cmd==LC_SEGMENT) { nOffset=list.at(i).offset; nNumberOfSections=readDword(nOffset+offsetof(segment_command,nsects),isReverse()); nOffset+=sizeof(segment_command); for(int j=0; j<nNumberOfSections; j++) { readArray(nOffset+offsetof(section,sectname),record.sectname,16); readArray(nOffset+offsetof(section,segname),record.segname,16); record.addr=readDword(nOffset+offsetof(section,addr),isReverse()); record.size=readDword(nOffset+offsetof(section,size),isReverse()); record.offset=readDword(nOffset+offsetof(section,offset),isReverse()); record.align=readDword(nOffset+offsetof(section,align),isReverse()); record.reloff=readDword(nOffset+offsetof(section,reloff),isReverse()); record.nreloc=readDword(nOffset+offsetof(section,nreloc),isReverse()); record.flags=readDword(nOffset+offsetof(section,flags),isReverse()); record.reserved1=readDword(nOffset+offsetof(section,reserved1),isReverse()); record.reserved2=readDword(nOffset+offsetof(section,reserved2),isReverse()); listResult.append(record); nOffset+=sizeof(section); } } } return listResult; }
void SF2Reader::readList(SimpleArray<T, E>& a, const chunkHeader& h) { size_t n = h.chunkSize; if(n%sizeof(T)!=0) throw ReadError("list "+std::string(h.chunkId, 4)+" not a multiple of record size"); Assert(n/sizeof(T)>=E); a.resize(n/sizeof(T)-E); readArray(a.begin(), a.size()+E); }
int main(void) { int list[MAX_SIZE], size; size = readArray(list); printArray(list, size); printf("Sum = %d\n", sumArray(list, size)); return 0; }
int main(int argc, char * argv[]) { int howMany; double localSum, finalSum; double * masterArray; double t1, t2; /* MPI Initialization */ int numProc = -1; int id = -1; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numProc); MPI_Comm_rank(MPI_COMM_WORLD, &id); if (argc != 2) { fprintf(stderr, "\n*** Usage: arraySum <inputFile>\n\n"); exit(1); } t1 = MPI_Wtime(); /* Master */ if (id == 0) { // Read the array into memory readArray(argv[1], &masterArray, &howMany); if (debug) { printf("Master has read the array of size %d\n\n", howMany); } // Wait until the array has been read before we do anything MPI_Bcast(&howMany, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); } /* Worker */ else { // Need our workers to be patient MPI_Bcast(&howMany, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); } finalSum = parallelSumArray(masterArray, howMany, id, numProc); t2 = MPI_Wtime(); if (id == 0) { printf("\nThe sum of the values in the input file '%s' is %g\n", argv[1], finalSum); printf("It took '%g' seconds to compute \n", t2 - t1); } MPI_Finalize(); return 0; }
/** Loads initial configuration at process 0 and sends it to other processes */ void setupArrays(const char* configFile, ARRAY2D arrays[2], int* pUpper, int* pLower) { int lengthWidth[2] = {0}; int size, rank; // get the size process group and the rank of this process MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); // load initial configuration at process 0 if(rank == 0) { arrays[0] = readArray(configFile); arrays[1] = newArray(arrays[0].length, arrays[0].width); // check the size and number of processes - we currently only support even decompositions if(arrays[0].length % size != 0) { // TODO: used MPI_Scatterv and MPI_Gatherv to support uneven decompositions printf("This program does not support uneven decompositions. The number of rows (%d) \n" "should be divisible by the number of processes (%d)\n", arrays[0].length, size); MPI_Abort(MPI_COMM_WORLD, -1); } lengthWidth[0] = arrays[0].length; lengthWidth[1] = arrays[0].width; } // broadcast the size of the array to everyone MPI_Bcast(lengthWidth, 2, MPI_INT, 0, MPI_COMM_WORLD); // non root nodes must allocate buffer space if(rank != 0) { arrays[0] = newArray(lengthWidth[0], lengthWidth[1]); arrays[1] = newArray(lengthWidth[0], lengthWidth[1]); } // calculate bounds *pLower = rowsLowerBound(arrays[0].length, size, rank); *pUpper = rowsUpperBound(arrays[0].length, size, rank); // if running on more than one process if(size > 1) { // TODO: requires an even size decomposition // send configuration to each process /*MPI_Scatter( arrays[0].data, (*pUpper-*pLower)*arrays[0].width, MPI_CHAR, ARRAY2D_PTR(arrays[0],*pLower,0), (*pUpper-*pLower)*arrays[0].width, MPI_CHAR, 0, MPI_COMM_WORLD);*/ // each process needs not only its own chunk, but also the row above and // below it, so the simple MPI_Scatter call is insufficient // Broadcasting the entire config is an inefficient solution, but it's // also simple MPI_Bcast(arrays[0].data, arrays[0].length*arrays[0].width, MPI_CHAR, 0, MPI_COMM_WORLD); } }
void ScummEngine_v71he::o71_getCharIndexInString() { int array, end, len, pos, value; value = pop(); end = pop(); pos = pop(); array = pop(); if (end >= 0) { len = resStrLen(getStringAddress(array)); if (len < end) end = len; } else { end = 0; } if (pos < 0) pos = 0; writeVar(0, array); if (end > pos) { while (end >= pos) { if (readArray(0, 0, pos) == value) { push(pos); return; } pos++; } } else { while (end <= pos) { if (readArray(0, 0, pos) == value) { push(pos); return; } pos--; } } push(-1); }
int load_representation (void **representation, char *basename){ char basenametext[2048]; sprintf(basenametext,"%s.%s",basename,"lztext"); char fn_doclen[2048]; snprintf(fn_doclen,2048,"%s.doclen",basenametext); lzdoc* repr = (lzdoc*)malloc(sizeof(lzdoc)); unsigned int* doc_len = (unsigned int*)readArray(fn_doclen,(int*)(&(repr->docs)),sizeof(unsigned int)); repr->doc_array = new DeltaCodes(doc_len,repr->docs, DELTA_SAMPLING); free(doc_len); repr->extractor = new ExtractorEnd2(basenametext, DELTA_SAMPLING); *representation = repr; return 0; }
int main() { std::vector<int> data = readArray(); printArray("Input", data); //ISort* sortAlgorithm = new InsertionSort(); ISort* sortAlgorithm = new Quicksort(); sortAlgorithm->sort(data); printArray("Output with " + sortAlgorithm->name(), data); delete sortAlgorithm; return 0; }
void SF2Reader::readPdtaList() { chunkHeader pdtaList; read(pdtaList); char pdtaHeader[4]; readArray(pdtaHeader,4); size_t n = pdtaList.chunkSize-4; Assert(sizeof(SF2Bank::Rec_bag)==4); Assert(sizeof(SF2Bank::Rec_gen)==4); Assert(sizeof(SF2Bank::Rec_mod)==10); while(n>0) { if( n<sizeof(chunkHeader) ) throw ReadError("pdta-list corrupted"); chunkHeader item; read(item); switch(item.id()) { case ChunkId::phdr: readList(myBank->phdr,item); break; case ChunkId::pbag: readList(myBank->p.bag,item); break; case ChunkId::pmod: readList(myBank->p.mod,item); break; case ChunkId::pgen: readList(myBank->p.gen,item); break; case ChunkId::inst: readList(myBank->inst,item); break; case ChunkId::ibag: readList(myBank->i.bag,item); break; case ChunkId::imod: readList(myBank->i.mod,item); break; case ChunkId::igen: readList(myBank->i.gen,item); break; case ChunkId::shdr: readList(myBank->shdr,item); break; default: Assert(0); skip(item.chunkSize); break; } n -= 8 + item.chunkSize; } }
bool Reader::readValue() { Token token; skipCommentTokens( token ); bool successful = true; if ( collectComments_ && !commentsBefore_.empty() ) { currentValue().setComment( commentsBefore_, commentBefore ); commentsBefore_ = ""; } switch ( token.type_ ) { case tokenObjectBegin: successful = readObject( token ); break; case tokenArrayBegin: successful = readArray( token ); break; case tokenNumber: successful = decodeNumber( token ); break; case tokenString: successful = decodeString( token ); break; case tokenTrue: currentValue() = true; break; case tokenFalse: currentValue() = false; break; case tokenNull: currentValue() = Value(); break; default: return addError( "Syntax error: value, object or array expected.", token ); } if ( collectComments_ ) { lastValueEnd_ = current_; lastValue_ = ¤tValue(); } return successful; }
int main ( int argc, char * argv[] ) { int size = 0; scanf("%d", &size); int * myReturn = readArray( size ); int i; printf( "myReturn begin: %p\n", myReturn ); for ( i = 0; i < size; i++ ) { printf( " element %d = %d\n", i , *myReturn ); myReturn ++; } printf( "myReturn end: %p\n", myReturn ); printf( "myReturn reset: %p\n", myReturn - size ); return EXIT_SUCCESS; }
void SF2Reader::readInfoList() { chunkHeader infoList; read(infoList); if( infoList.id()!=ChunkId::LIST ) throw ReadError("LIST chunk expected"); char infoHeader[4]; readArray(infoHeader,4); size_t n = infoList.chunkSize-4; while(n>0) { chunkHeader itemHeader; read(itemHeader); skip(itemHeader.chunkSize); n -= 8 + itemHeader.chunkSize; } }
Value* Parser::readValue() { Tokenizer::TokenType tok = tokenizer->nextToken(); switch (tok) { case Tokenizer::TokenNumber: return new Value(tokenizer->getNumberValue()); case Tokenizer::TokenString: return new Value(tokenizer->getStringValue()); case Tokenizer::TokenName: if (tokenizer->getNameValue() == "false") return new Value(false); else if (tokenizer->getNameValue() == "true") return new Value(true); else { tokenizer->pushBack(); return NULL; } case Tokenizer::TokenBeginArray: tokenizer->pushBack(); { Array* array = readArray(); if (array == NULL) return NULL; else return new Value(array); } case Tokenizer::TokenBeginGroup: tokenizer->pushBack(); { Hash* hash = readHash(); if (hash == NULL) return NULL; else return new Value(hash); } default: tokenizer->pushBack(); return NULL; } }
QList<segment_command> MACHFile::getSegmentsList32() { QList<load_command_offset> list=getLoadCommands_offset(); unsigned int nOffset=0; QList<segment_command> listResult; segment_command record; for(int i=0; i<list.count(); i++) { if(list.at(i).cmd==LC_SEGMENT) { nOffset=list.at(i).offset; // uint32_t cmd; // uint32_t cmdsize; // char segname[16]; // uint32_t vmaddr; // uint32_t vmsize; // uint32_t fileoff; // uint32_t filesize; // vm_prot_t maxprot; // vm_prot_t initprot; // uint32_t nsects; // uint32_t flags; record.cmd=readDword(nOffset+offsetof(segment_command,cmd),isReverse()); record.cmdsize=readDword(nOffset+offsetof(segment_command,cmdsize),isReverse()); readArray(nOffset+offsetof(segment_command,segname),record.segname,16); record.vmaddr=readDword(nOffset+offsetof(segment_command,vmaddr),isReverse()); record.vmsize=readDword(nOffset+offsetof(segment_command,vmsize),isReverse()); record.fileoff=readDword(nOffset+offsetof(segment_command,fileoff),isReverse()); record.filesize=readDword(nOffset+offsetof(segment_command,filesize),isReverse()); record.maxprot=readDword(nOffset+offsetof(segment_command,maxprot),isReverse()); record.initprot=readDword(nOffset+offsetof(segment_command,initprot),isReverse()); record.nsects=readDword(nOffset+offsetof(segment_command,nsects),isReverse()); record.flags=readDword(nOffset+offsetof(segment_command,flags),isReverse()); listResult.append(record); } } return listResult; }
void SF2Reader::readSdtaList() { chunkHeader listHeader; read(listHeader); if( listHeader.id()!=ChunkId::LIST ) throw ReadError("sdta must be LIST"); if( listHeader.chunkSize<=4 ) throw ReadError("sdta too short"); readExpect("sdta"); chunkHeader smplHeader; read(smplHeader); if( smplHeader.id()!=ChunkId::smpl ) throw ReadError("smpl subchunk expected"); myBank->samples.resize(smplHeader.chunkSize/2); readArray(myBank->samples.begin(),myBank->samples.size()); if( size_t m = listHeader.chunkSize-4-8-smplHeader.chunkSize ) { // FIXME - use 24-bit data skip(m); } }
int main(void) { int data[10]; int repCount; //call readArray, save in data readArray(data); //call findNonRepeat, sets repCount returned value (index or -1) repCount = findNonRepeat(data); //if repCount is withing the number of indexs if (repCount >= 0 && repCount <=9) { printf("\nFirst non-repeating element: %d\n", data[repCount]); //repCount = index } else if (repCount == -1) printf("\nThere is no non-reapeating element\n"); //repCount = -1 return 0; }
bool CJson:: loadString(const std::string &lines, ValueP &value) { std::vector<std::string> strs; CStrParse parse(lines); parse.skipSpace(); if (parse.isChar('{')) { // object Object *obj; if (! readObject(parse, obj)) return false; value = ValueP(obj); } else if (parse.isChar('[')) { // array Array *array; if (! readArray(parse, array)) return false; value = ValueP(array); } else { ValueP value1; if (! readValue(parse, value1)) return false; value = value1; } parse.skipSpace(); if (! parse.eof()) return false; return true; }
void JsonSchema::readValues(cJSON *childProperties, PropertiesPtr property , const std::string &attType) { if (attType == "string") { readString(childProperties, property); } else if (attType == "integer") { readInteger(childProperties, property); } else if (attType == "array") { readArray(childProperties, property); } else if (attType == "number") { readDouble(childProperties, property); } }
Value* Parser::readValue() { Tokenizer::TokenType tok = tokenizer->nextToken(); switch (tok) { case Tokenizer::TokenInteger: return new Value(tokenizer->getIntegerValue()); case Tokenizer::TokenFloat: return new Value(tokenizer->getFloatValue()); case Tokenizer::TokenString: return new Value(tokenizer->getStringValue()); case Tokenizer::TokenBeginArray: tokenizer->pushBack(); { Array* array = readArray(); if (array == NULL) { return NULL; } else { return new Value(array); } } case Tokenizer::TokenBeginGroup: tokenizer->pushBack(); { Hash* hash = readHash(); if (hash == NULL) { return NULL; } else { return new Value(hash); } } default: tokenizer->pushBack(); return NULL; } }
/** * Convert the byte array a simple message. Assumes that the byte array is a message. * @return a message containing the data specified in the byte stream */ OSCMessage& OSCByteArrayToMsgConverter::convertMessage() { OSCMessage* message = new OSCMessage(); QString addrStr = readString(); message->setAddress(addrStr); QByteArray types = readTypes(); if(types.isNull()) return *message; moveToFourByteBoundry(); for(int i = 0; i < types.length(); i++) { if('[' == types.at(i)) { // we're looking at an array -- read it in message->addArgument(readArray(types, ++i)); // then increment i to the end of the array while(']' != types.at(i)) i++; }else message->addArgument(readArgument(types.at(i))); } return *message; }
/** * @brief Reads an element from `reader`. An element is any valid JSON type. * @param reader The JSONReader. * @return The element, or `NULL` if no element is available. */ static ident readElement(JSONReader *reader) { const int b = readByteUntil(reader, "{[\"tfn0123456789.-]}"); if (b == '{') { return readObject(reader); } else if (b == '[') { return readArray(reader); } else if (b == '\"') { return readString(reader); } else if (b == 't' || b == 'f') { return readBoole(reader); } else if (b == 'n') { return readNull(reader); } else if (b == '.' || b == '-' || isdigit(b)) { return readNumber(reader); } else if (b == ']' || b == '}') { reader->b--; } return NULL; }
QByteArray MACHFile::getUUID() { QByteArray baResult; QList<load_command_offset> list=getLoadCommands_offset(); for(int i=0; i<list.count(); i++) { if(list.at(i).cmd==LC_UUID) { unsigned int nOffset=list.at(i).offset; nOffset+=sizeof(load_command); baResult=readArray(nOffset,list.at(i).cmdsize-sizeof(load_command)); break; } } return baResult; }
int main() { printf("%d\n", special(3)); char op; printConsole(&op); if(op == 'a') { sieveBuild(); vector answer; answer = solveA(); printf("Task (a):\n"); printArray(answer); } else { printf("Task (b):\n"); vector v; v = readArray(); vector ans; ans = solveB(v); printArray(ans); } return 0; }
void line_select(uint8_t line) { switch(line) { case 0: GPIO_SetBits(GPIOB, GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); GPIO_ResetBits(GPIOB, GPIO_Pin_8); readArray(0); break; case 1: GPIO_SetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); GPIO_ResetBits(GPIOB, GPIO_Pin_9); readArray(8); break; case 2: GPIO_SetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); GPIO_ResetBits(GPIOB, GPIO_Pin_10); readArray(16); break; case 3: GPIO_SetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); GPIO_ResetBits(GPIOB,GPIO_Pin_11); readArray(24); break; case 4: GPIO_SetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); GPIO_ResetBits(GPIOB,GPIO_Pin_12); readArray(32); break; case 5: GPIO_SetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_14 | GPIO_Pin_15); GPIO_ResetBits(GPIOB,GPIO_Pin_13); readArray(40); break; case 6: GPIO_SetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_15); GPIO_ResetBits(GPIOB,GPIO_Pin_14); readArray(48); break; case 7: GPIO_SetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14); GPIO_ResetBits(GPIOB,GPIO_Pin_15); readArray(56); break; } }
bool Reader::readValue () { Token token; do readToken (token); while (token.type_ == tokenComment); bool successful = true; switch (token.type_) { case tokenObjectBegin: successful = readObject (); break; case tokenArrayBegin: successful = readArray (); break; case tokenNumber: successful = decodeNumber (token); break; case tokenString: successful = decodeString (token); break; case tokenTrue: currentValue () = true; break; case tokenFalse: currentValue () = false; break; case tokenNull: currentValue () = Value (); break; default: return addError ("Syntax error: value, object or array expected.", token); } return successful; }