/** Read an unsigned 32-bit integer from the file. */ inline unsigned readLong(FILE * f, bool_t bigEndian) { if (bigEndian) return (readShort(f, bigEndian) << 16) | readShort(f, bigEndian); else return readShort(f, bigEndian) | (readShort(f, bigEndian) << 16); }
CCAFCClipMapping* CCAFCClipMapping::createWithAuroraGT(int tag, const char* data, size_t length) { // create empty mapping CCAFCClipMapping* m = create(tag); /* * parse module mapping data, its format is simple * 1. [SRC CLIP INDEX][DEST CLIP INDEX] * 2. [SRC CLIP INDEX][DEST CLIP INDEX] * 3. [SRC CLIP INDEX][DEST CLIP INDEX] * ... * * index are 2 bytes and in little endian */ s_data = data; s_pos = 0; while(s_pos + 4 <= length) { /* * Don't use m->mapClip(readShort(), readShort()), it looks ok * at first glance, but the readShort invocation order depends on argument * push priority. If right argument is pushed first, then right readShort * will be called first and it is definitely not what we expect */ short from = readShort(); short to = readShort(); m->mapClip(from, to); } return m; }
//--------------------------------------------------------------------- void BackgroundFileSerializer::readObject( Ogre::DataStreamPtr &stream, Page &pDest ) { read2ByteBool( stream, pDest.enabled ); if( !pDest.enabled ) return; readShort( stream, pDest.unknown_02 ); readShort( stream, pDest.value_size ); if( pDest.value_size != 1 && pDest.value_size != 2 ) { OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS ,"Page value_size other then 1 and 2 is not supported" ,"BackgroundFileSerializer::readObject" ); } size_t color_count( BackgroundFile::PAGE_DATA_SIZE ); pDest.colors.clear(); pDest.data.clear(); if( pDest.value_size == 2 ) { pDest.colors.reserve( color_count ); for( size_t i( color_count ); i--; ) { Color colourDest; readObject( stream, colourDest ); pDest.colors.push_back( colourDest ); } } else { pDest.data.resize( color_count ); stream->read( &pDest.data[0], color_count ); } }
void JPEGDecompressor::processDri(void) { /* Check length of variable: */ if(readShort(source)!=4) Misc::throwStdErr("JPEGDecompressor::processDri: DRI marker has wrong length"); /* Read restart interval: */ restartInterval=readShort(source); }
BOOL readFrame(unsigned short *frame_size,unsigned short *checksum,unsigned char frame[],HANDLE *hdlr) { unsigned char byte=0; if(!readByte(&byte,hdlr)) return FALSE; if(byte==0x55) { if(!readShort(frame_size,hdlr)) return FALSE; } else { while(byte!=0x55) { if(!readByte(&byte,hdlr)) return FALSE; } if(!readShort(frame_size,hdlr)) return FALSE; } unsigned char t_frame[*frame_size]; t_frame[0] = byte; t_frame[1] = *frame_size&0x00FF; t_frame[2] = (*frame_size&0xFF00)>>8; //printf("__Frame size: %d bytes \r\n",*frame_size); int i = 3; do { if(!readByte(&byte,hdlr)) return FALSE; //printf("%d:%x ",i+1,byte); t_frame[i]=byte; i=i+1; }while(i<*frame_size); memcpy(frame,t_frame,*frame_size); #ifdef _DEBUG printf("[DEBUG] "); printf("Frame received: \n"); printf("[DEBUG] "); printf("_Frame size: %d \n",*frame_size); printf("[DEBUG] "); printf("_Frame type: 0x%x \n",frame[3]); #endif return TRUE; }
int main() { short n, menor1 = 101, menor2 = 102, mayor1, mayor2; int cont; writeLnString("Ingrese valores positivos para encontrar los 2 menores y los 2 mayores, finalice el ingreso de datos con 0"); cont = 0; writeString("Ingrese un número entero: "); readShort(n); while (n != 0) { if (n < menor1 || cont == 1) { menor2 = menor1; menor1 = n; } else if (n < menor2 || cont == 2) { menor2 = n; } if (n > mayor1 || cont == 1) { mayor2 = mayor1; mayor1 = n; } else if (n > mayor2 || cont == 2) { mayor2 = n; } cont++; writeString("Ingrese un número entero: "); readShort(n); } if(cont < 3){ writeLnString("No hay suficientes valores para determinar 3 menores, los resultados parciales son: "); } if(cont >= 1) { writeString("El menor es: "); writeLnShort(menor1); writeString("El mayor es: "); writeLnShort(mayor1); } if(cont >= 2) { writeString("El segundo menor es: "); writeLnShort(menor2); writeString("El segundo mayor es: "); writeLnShort(mayor2); } }
Snap* storeBitmap(const char* fname) { // Open the file to read the bitmap snap content std::ifstream in; in.open(fname, std::ifstream::binary); assert(!in.fail() || !"Could not find file"); char store[2]; in.read(store, 2); // Check for the first two characters of the snap file, if it has // "B" and "M" then its a bmp file assert(store[0] == 'B' && store[1] == 'M' || !"Not a bitmap file"); in.ignore(8); int info = readInteger(in); // Fetch the header content int sizeH = readInteger(in); int w, h; w = readInteger(in); h = readInteger(in); in.ignore(2); assert(readShort(in) == 24 || !"Image is not 24 bits per pixel"); assert(readShort(in) == 0 || !"Image is compressed"); int BPerRCount = ((w * 3 + 3) / 4) * 4 - (w * 3 % 4); int sizeA = BPerRCount * h; vishakArray<char> pixelArrayObj(new char[sizeA]); in.seekg(info, std::ios_base::beg); in.read(pixelArrayObj.get(), sizeA); //Get the data into the right format vishakArray<char> pixelArrayObj2(new char[w * h * 3]); for(int y = 0; y < h; y++) { for(int x = 0; x < w; x++) { for(int c = 0; c < 3; c++) { pixelArrayObj2[3 * (w * y + x) + c] = pixelArrayObj[BPerRCount * y + 3 * x + (2 - c)]; } } } in.close(); return new Snap(pixelArrayObj2.release(), w, h); }
unsigned long chunkArchive::readAny(unsigned char *type, unsigned long *size) { unsigned char id = readByte(); if (type) *type = id; switch ((atoms) (id)) { case CHUNK_BYTE: if (size) *size = 1; return readByte(); break; case CHUNK_SHORT: if (size) *size = 2; return readShort(); break; case CHUNK_LONG: if (size) *size = 4; return readLong(); break; case CHUNK_STRING: return (unsigned long) readString(size); break; case CHUNK_BINARY: return (unsigned long) readBinary(size); break; default: if (size) *size = 0; return 0; } }
uint16 GfxFeatureMapRequestPacket::getEndOffset() const { int pos = endOffset_POS; return ( readShort( pos ) ); }
/*! \sa PacketProcessor */ unsigned short PacketProcessor::calculateCheckSum(unsigned char *ptr_PacketBuffer) { //checksum temp-store unsigned short l_16b=0; unsigned l_32b=0; //sum the header fields in chunks of short for (int i = 1; i < HEADER_LENGTH; i += 2) { //read next short from the header l_16b = readShort(&ptr_PacketBuffer[i]); //add it with the previous short l_32b += l_16b; } //Store low order bits l_16b = 0; l_16b |= l_32b; //shift the carry bits l_32b >>= 16; //add the carry bits and low order bits l_16b += l_32b; return l_16b; }
void ByteStream::readFormat(const char *fmt, ...) { va_list ap; va_start(ap, fmt); while (*fmt) { const char typeID = *fmt++; switch (typeID) { case 'b': *va_arg(ap, int *) = readByte(); break; case 's': *va_arg(ap, int *) = readShort(); break; case 'i': *va_arg(ap, int *) = readInt(); break; case 'l': *va_arg(ap, long *) = readLong(); break; default: core_assert(false); } } va_end(ap); }
void BufferedReader::readAndInternStringVector(std::vector<InternedString>& v) { int num_elts = readShort(); if (VERBOSITY("parsing") >= 3) printf("%d elts to read\n", num_elts); for (int i = 0; i < num_elts; i++) { v.push_back(readAndInternString()); } }
InternedString BufferedReader::readAndInternString() { int strlen = readShort(); llvm::SmallString<32> chars; for (int i = 0; i < strlen; i++) { chars.push_back(readByte()); } return intern_pool->get(chars.str()); }
void GfxFeatureMapRequestPacket::getScreenSize(uint16& screenSizeX, uint16& screenSizeY) const { int position = screenSizeX_POS; screenSizeX = incReadShort(position); screenSizeY = readShort(position); }
bool ZLZipHeader::readFrom(ZLInputStream &stream) { size_t startOffset = stream.offset(); Signature = readLong(stream); switch (Signature) { default: return false; case SignatureLocalFile: Version = readShort(stream); Flags = readShort(stream); CompressionMethod = readShort(stream); ModificationTime = readShort(stream); ModificationDate = readShort(stream); CRC32 = readLong(stream); CompressedSize = readLong(stream); UncompressedSize = readLong(stream); if (CompressionMethod == 0 && CompressedSize != UncompressedSize) { ZLLogger::Instance().println("zip", "Different compressed & uncompressed size for stored entry; the uncompressed one will be used."); CompressedSize = UncompressedSize; } NameLength = readShort(stream); ExtraLength = readShort(stream); return stream.offset() == startOffset + 30 && NameLength != 0; case SignatureData: CRC32 = readLong(stream); CompressedSize = readLong(stream); UncompressedSize = readLong(stream); NameLength = 0; ExtraLength = 0; return stream.offset() == startOffset + 16; } }
void RouteStorageGetRouteReplyPacket::getDriverPrefs( DriverPref& driverPref ) const { int pos = endStatic_POS; pos += readShort( strlenExtraUserinfo_POS ) + 1; pos += readLong( routePackLength_POS ); driverPref.load( this, pos ); }
static unsigned char *loadSound_wav( String path,int *plength,int *pchannels,int *pformat,int *phertz ){ if( FILE *f=fopenFile( path,"rb" ) ){ if( !strcmp( readTag( f ),"RIFF" ) ){ int len=readInt( f )-8;len=len; if( !strcmp( readTag( f ),"WAVE" ) ){ if( !strcmp( readTag( f ),"fmt " ) ){ int len2=readInt( f ); int comp=readShort( f ); if( comp==1 ){ int chans=readShort( f ); int hertz=readInt( f ); int bytespersec=readInt( f );bytespersec=bytespersec; int pad=readShort( f );pad=pad; int bits=readShort( f ); int format=bits/8; if( len2>16 ) skipBytes( len2-16,f ); for(;;){ const char *p=readTag( f ); if( feof( f ) ) break; int size=readInt( f ); if( strcmp( p,"data" ) ){ skipBytes( size,f ); continue; } unsigned char *data=(unsigned char*)malloc( size ); if( fread( data,size,1,f )==1 ){ *plength=size/(chans*format); *pchannels=chans; *pformat=format; *phertz=hertz; fclose( f ); return data; } free( data ); } } } } } fclose( f ); } return 0; }
static inline unsigned short *readShorts(spSkeletonBinary *self, size_t length) { unsigned short *arr = MALLOC(unsigned short, length); for (int i = 0; i < length; i++) { arr[i] = readShort(self); } return arr; }
unsigned short readShortFromStack(void) { unsigned short value = readShort(registers.sp); registers.sp += 2; #ifdef DEBUG_STACK printf("Stack read 0x%04x\n", value); #endif return value; }
bool ByteReader::readThree(unsigned int& value) { if (currPos+3>numBytesInBuffer) return false; unsigned short shrt; byte byt; readShort(shrt); readByte(byt); value=(unsigned int) ((shrt*0x100)+byt); return true; }
/*! \sa PacketProcessor */ bool PacketProcessor::incrementalCheckSumUpdate(void) { unsigned l_HCP = 0; unsigned short l_HC = readShort(&m_PacketBuffer[11]); unsigned short l_m = readShort(&m_PacketBuffer[9]); m_PacketBuffer[8] -= 1; if (m_PacketBuffer[8] <= 0) { resetPacketBuffer(); return false; } unsigned short l_mP = readShort(&m_PacketBuffer[9]); //perform the incremental update l_HC = ~l_HC; l_m = ~l_m; l_HCP = l_HC + l_m + l_mP; l_HC = (l_HCP&0xFFFF0000)>>16; l_HCP &= 0x0000FFFF; l_HC += l_HCP; l_HC = ~l_HC; setMultipleFields(&m_PacketBuffer[11], l_HC, 2); return true; }
QString DataReader::readString(){ QByteArray bstr = readBytes(readShort()); QString str; int i = 0; while(i != bstr.size()) { str.append(bstr.at(i)); i++; } return (str); }
//----------------------------------------------------------------- // destructor mgTextBuffer::~mgTextBuffer() { // delete all the child boxes unsigned int posn = 0; while (posn < m_bufferLen) { mgFormatCmd cmd = (mgFormatCmd) m_buffer[posn++]; switch (cmd) { case mgJustifyCmd: case mgLeftMarginCmd: case mgRightMarginCmd: case mgIndentCmd: case mgSpaceCmd: case mgTabCmd: case mgWrapCmd: case mgBreakCmd: case mgClearCmd: case mgFontSizeCmd: case mgFontBoldCmd: case mgFontItalicCmd: case mgDoneCmd: readShort(posn); break; case mgColorCmd: case mgAnchorCmd: case mgTargetCmd: readDWORD(posn); break; case mgFontFaceCmd: case mgTextCmd: { int textLen; const char* text; readText(posn, textLen, text); break; } case mgChildCmd: { // read child box from buffer const void* child; mgTextAlign halign; mgTextAlign valign; readChild(posn, child, halign, valign); break; } } } delete m_buffer; }
uint32 GfxFeatureMapReplyPacket::getMapIDToResend(uint32 i) const { if (i < getNbrRequestsToResend()) { // get the map id for i:th map return readLong( MAP_ID_START_POS + (i * 8) + readShort( LENGTH_COPYRIGHT_POS ) ); } else { return MAX_UINT32; } }
bool GfxFeatureMapReplyPacket::getIncludeCountryPolygonForMapToResend(uint32 i) const { if (i < getNbrRequestsToResend()) { // get countrymap bool for i:th map return (readLong( MAP_ID_START_POS + (i * 8) + 4 + readShort( LENGTH_COPYRIGHT_POS )) != 0); } else { return false; } }
UserEnums::URType RouteStorageGetRouteReplyPacket::getUrmask() const { int pos = endStatic_POS; pos += readShort( strlenExtraUserinfo_POS ) + 1; pos += readLong( routePackLength_POS ); pos += readLong( driverPrefSize_POS ); UserEnums::URType urmask; urmask.load( this, pos ); return urmask; }
/* Description: This function reads shorts and stores them into the two arrays left and right It always reads one short into left, then one into right, then again into left, and so on ... Parameters: left - first array to read into rigth - second array to read into length - length of the two arrays Returns: 0 - in case the input does not have the expected size 1 - if everything went fine */ int readData(short* left, short* right, int length) { short a, b; //two shorts to hold the values for left and right //loop through the arrays to fill them with shorts int i; for(i = 0; i < length; ++i) { //read a short into a and b, if that works store them into left and right //if it fails return 0 if(readShort(&a) && readShort(&b)) { left[i] = a; right[i] = b; } else return 0; } //return 1 if everything went fine return 1; }
std::string Message::readString(const char** source, const char* bound) { unsigned len = readShort(source, bound); const char *bytes = *source; if (bytes + len - 1 < bound) { (*source) += len; return std::string(bytes, len); } throw FormatException(); }
void InputSocketStream::readPacket(serialization::pimpl::Packet& packet) { int version = readByte(); if(version != serialization::pimpl::Packet::VERSION){ std::stringstream stringstream; stringstream << "Packet versions are not matching! This -> " << (int)serialization::pimpl::Packet::VERSION << ", Incoming -> " << version; throw exception::IllegalArgumentException("Packet::readFrom", stringstream.str()); } packet.setHeader(readShort()); packet.setPartitionId(readInt()); readValue(packet.getDataAsModifiable()); }
void JPEGDecompressor::processSof(int sofMarker) { int length=readShort(source)-2; /* Read SOF elements: */ numBits=source.getChar(); imageSize[1]=readShort(source); imageSize[0]=readShort(source); numComponents=source.getChar(); /* Check JPEG stream for sanity: */ if(imageSize[0]<=0||imageSize[1]<=0||numComponents<=0) Misc::throwStdErr("JPEGDecompressor::processSof: emtpy JPEG stream"); if(numBits<2||numBits>16) Misc::throwStdErr("JPEGDecompressor::processSof: unsupported number of bits per pixel component"); if(length!=numComponents*3+6) Misc::throwStdErr("JPEGDecompressor::processSof: wrong SOF marker length"); /* Read component information: */ components=new JPEGComponent[numComponents]; for(int i=0;i<numComponents;++i) { components[i].index=i; /* Read the component's identity: */ components[i].id=source.getChar(); /* Read the downsampling factors: */ int ds=source.getChar(); components[i].samplingFactors[0]=(ds>>4)&0xf; components[i].samplingFactors[1]=ds&0xf; /* Initialize the Huffman table index: */ components[i].huffmanTableIndex=-1; /* Skip the Tq value stored in the JPEG stream: */ source.getChar(); } }