/** * Deserializes the supplied (wire) buffer into suback data * @param packetid returned integer - the MQTT packet identifier * @param maxcount - the maximum number of members allowed in the grantedQoSs array * @param count returned integer - number of members in the grantedQoSs array * @param grantedQoSs returned array of integers - the granted qualities of service * @param buf the raw buffer data, of the correct length determined by the remaining length field * @param buflen the length in bytes of the data in the supplied buffer * @return error code. 1 is success, 0 is failure */ int MQTTDeserialize_suback(unsigned short* packetid, int maxcount, int* count, int grantedQoSs[], unsigned char* buf, int buflen) { MQTTHeader header = {0}; unsigned char* curdata = buf; unsigned char* enddata = NULL; int rc = 0; int mylen; FUNC_ENTRY; header.byte = readChar(&curdata); if (header.bits.type != SUBACK) goto exit; curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ enddata = curdata + mylen; if (enddata - curdata < 2) goto exit; *packetid = readInt(&curdata); *count = 0; while (curdata < enddata) { if (*count > maxcount) { rc = -1; goto exit; } grantedQoSs[(*count)++] = readChar(&curdata); } rc = 1; exit: FUNC_EXIT_RC(rc); return rc; }
int GetByte(void) /* get one byte */ { unsigned i; while (getlen <= 8) { if ((i = readChar()) == -1) i = 0; getbuf |= i << (8 - getlen); getlen += 8; } i = getbuf; getbuf <<= 8; getlen -= 8; return (i >> 8) & 0xFF; }
Token* readConstChar(void) { Token* token = makeToken(TK_CHAR, lineNo, colNo); // Read next character readChar(); if (currentChar == -1) { // End of File error(ERR_INVALIDCHARCONSTANT, token->lineNo, token->colNo); } else { switch(charCodes[currentChar]) { // Escape character for Single Quote: case CHAR_SINGLEQUOTE: // Read next character readChar(); if (charCodes[currentChar] == CHAR_SINGLEQUOTE) { token->string[0] = currentChar; readChar(); if (charCodes[currentChar] == CHAR_SINGLEQUOTE) { token->string[1] = '\0'; readChar(); return token; } else { error(ERR_INVALIDCHARCONSTANT, token->lineNo, token->colNo); } } else { error(ERR_INVALIDCHARCONSTANT, token->lineNo, token->colNo); } break; default: // Add the character to token string token->string[0] = currentChar; // Read next character readChar(); switch(charCodes[currentChar]) { case CHAR_SINGLEQUOTE: // End token token->string[1] = '\0'; readChar(); return token; default: error(ERR_INVALIDCHARCONSTANT, token->lineNo, token->colNo); break; } break; } } return token; }
int GetBit(void) /* get one bit */ { int i; while (getlen <= 8) { if ((i = readChar()) == -1) i = 0; getbuf |= i << (8 - getlen); getlen += 8; } i = getbuf; getbuf <<= 1; getlen--; return ((i>>15) & 1); }
bool GLECSVData::isComment(GLEBYTE ch) { int currentPos = m_pos; size_t commentPos = 0; while (commentPos < m_comment.size() && ch == m_comment[commentPos]) { ch = readChar(); commentPos++; } if (commentPos == m_comment.size()) { goBack(); return true; } else { m_pos = currentPos; return false; } }
bool UtlXMLStream::readObjectReference(std::string& sTypeName, std::string& sIDAttrName, std::string& sIdentifier) { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '<') { return false; } std::string sTrash; // reference if (!readString( getInputStream(), sTrash)) return false; if (strcmp(sTrash.c_str(),"reference")) return false; // type if (!readAttribute(sTrash, sTypeName)) return false; // ID if (!readAttribute( sIDAttrName, sIdentifier)) return false; iChar=readChar( getInputStream() ); if (iChar != '/') { return false; } iChar=readChar( getInputStream() ); if (iChar != '>') { return false; } return true; }
Token* readNumber(void) { //TO DO doc khi van con la so, luu vao toke Token *token = makeToken(TK_NUMBER, lineNo, colNo); int count = 0; token->string[count++]='0'; token->string[count++]='.'; while ((currentChar != EOF) && (charCodes[currentChar] == CHAR_DIGIT)) { token->string[count++] = (char)currentChar; readChar(); } token->string[count] = '\0'; //token->value = atoi(token->string); return token; }
char dmtcp::Util::readDec (int fd, VA *value) { char c; unsigned long int v; v = 0; while (1) { c = readChar (fd); if ((c >= '0') && (c <= '9')) c -= '0'; else break; v = v * 10 + c; } *value = (VA)v; return (c); }
bool UtlXMLStream::readTag(std::string& sTag) { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '<') { return false; } if (!readWord( getInputStream(), sTag )) return false; if (iChar != '/') { return false; } iChar=readChar( getInputStream() ); if (iChar != '>') { return false; } return true; }
WifiMessage ESP8266wifi::listenForIncomingMessage(int timeout){ watchdog(); char buf[16] = {'\0'}; msgIn[0] = '\0'; static WifiMessage msg; msg.hasData = false; msg.channel = '-'; msg.message = msgIn; //TODO listen for unlink etc... byte msgOrRestart = readCommand(timeout, IPD, READY); //Detected a esp8266 restart if (msgOrRestart == 2){ restart(); return msg; } //Message received.. else if (msgOrRestart == 1) { char channel = readChar(); if (channel == SERVER) flags.connectedToServer = true; readChar(); // removing comma readBuffer(&buf[0], sizeof(buf) - 1, ':'); // read char count readChar(); // removing ':' delim byte length = atoi(buf); readBuffer(&msgIn[0], min(length, sizeof(msgIn) - 1)); msg.hasData = true; msg.channel = channel; msg.message = msgIn; readCommand(10, OK); // cleanup after rx } return msg; }
bool CssTokenizer::readComment () { if (!lastReadEq('*')) return false; currentToken.add(lastRead); readChar(); while (in != NULL) { if (lastReadEq('*')) { currentToken.add(lastRead); readChar(); if (lastReadEq('/')) { currentToken.add(lastRead); readChar(); return true; } continue; } currentToken.add(lastRead); readChar(); } throw new ParseException(&lastRead, "end of comment (*/)"); return false; }
bool CssTokenizer::readNMChar () { if (in == NULL) return false; if (lastReadEq('_') || lastReadInRange('a', 'z') || lastReadInRange('A', 'Z') || lastReadIsDigit() || lastReadEq('-')) { currentToken.add(lastRead); readChar(); return true; } else return (readNonAscii() || readEscape()); }
/** * Deserializes the supplied (wire) buffer into advertise data * @param gatewayid the returned gateway id * @param duration the returned duration - the time interval until the next advertise will be sent * @param buf the raw buffer data, of the correct length determined by the remaining length field * @param buflen the length in bytes of the data in the supplied buffer * @return error code. 1 is success */ int MQTTSNDeserialize_advertise(unsigned char* gatewayid, unsigned short* duration, unsigned char* buf, int buflen) { unsigned char* curdata = buf; unsigned char* enddata = NULL; int rc = 0; int mylen = 0; FUNC_ENTRY; curdata += (rc = MQTTSNPacket_decode(curdata, buflen, &mylen)); /* read length */ enddata = buf + mylen; if (enddata - curdata > buflen) goto exit; if (readChar(&curdata) != MQTTSN_ADVERTISE) goto exit; *gatewayid = readChar(&curdata); *duration = readInt(&curdata); rc = 1; exit: FUNC_EXIT_RC(rc); return rc; }
long readHex() { if ( err ) return 0; skipWhitespace(); // hex must start with alphanumeric character char ch; if ( !peekChar(&ch) || !isalnum(ch) ) { err = TextFile::ERROR_PARSE; return 0; } long x = 0; while ( peekChar(&ch) ) { switch ( ch ) { case '0': x <<= 4; x += 0; break; case '1': x <<= 4; x += 1; break; case '2': x <<= 4; x += 2; break; case '3': x <<= 4; x += 3; break; case '4': x <<= 4; x += 4; break; case '5': x <<= 4; x += 5; break; case '6': x <<= 4; x += 6; break; case '7': x <<= 4; x += 7; break; case '8': x <<= 4; x += 8; break; case '9': x <<= 4; x += 9; break; case 'a': case 'A': x <<= 4; x += 0xA; break; case 'b': case 'B': x <<= 4; x += 0xB; break; case 'c': case 'C': x <<= 4; x += 0xC; break; case 'd': case 'D': x <<= 4; x += 0xD; break; case 'e': case 'E': x <<= 4; x += 0xE; break; case 'f': case 'F': x <<= 4; x += 0xF; break; default: return x; } readChar( &ch ); } return x; }
bool UtlXMLStream::readBeginningOfObject(std::string& sTypeName) { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '<') { return false; } if (!readWord( getInputStream(), sTypeName )) return false; return true; }
string readLabel(char ch,FILE *f,int& a){ string s=""; s=s+ch; char c=readChar(f,"input tree"); while (c!=':' && c!=';' && c!=')'){ s=s+c; fscanf(f,"%c",&c); } if (c==')') { while (c==')') { fscanf(f,"%c",&c); a--; } } return s.c_str(); }
int getData(FILE *in, Student list[]) { char temp[MaxNameBuffer]; void getString(FILE *, char[]); char readChar(FILE *); int n = 0; getString(in, temp); while (n < MaxStudents && strcmp(temp, "END") != 0) { strcpy(list[n].name, temp); fscanf(in, "%d", &list[n].age); list[n].gender = readChar(in); n++; getString(in, temp); } return n; } //end getData
void PgnStream::parseComment(char opBracket) { int level = 1; char clBracket = (opBracket == '(') ? ')' : '}'; char c; while ((c = readChar()) != 0) { if (c == opBracket) level++; else if (c == clBracket && --level <= 0) break; m_tokenString.append(c); } }
Token *readFloat (void){ Token *token = makeToken(TK_NUMBER, lineNo, colNo); int count = 0; while ((currentChar != EOF) && ((charCodes[currentChar] == CHAR_DIGIT) || (charCodes[currentChar] == CHAR_PERIOD))) { if((charCodes[currentChar] == CHAR_PERIOD)&&(count==0)) token->string[count++]='0'; token->string[count++] = (char)currentChar; if((charCodes[currentChar]== CHAR_PERIOD)&& (count>0)) token->string[count++]='0'; readChar(); } token->string[count] = '\0'; token->value = atoi(token->string); return token; }
bool Parser::parseName( std::string &name ) { if( !isInSet( firstNameSet, current ) ) return false; name = ""; do { name += current; readChar( true ); } while( isInSet( nameSet, current ) ); return true; }
/*! \brief Read a string from the serial device \param string : string read on the serial device \param finalChar : final char of the string \param maxChars : maximum allowed number of chars read \return >0 success, return the number of chars read \return -1 error while reading the char \return -2 maxChars is reached */ int LibSerial::readString (char * string, char finalChar, unsigned int maxChars) { unsigned int nbChars = 0; // Number of chars read int ret; // Returned value from read while (nbChars < maxChars) { // While the buffer is not full ret = readChar (&string[nbChars]); // Read a char with the restant time if (ret == 1) { // If a char has been read if (string[nbChars] == finalChar) { // Check if it is the final char string [++nbChars] = '\0'; // Yes : add the end character '\0' return nbChars; // Return the number of chars read } nbChars++; // If not, just increase the number of chars read } if (ret < 0) return ret; // Error while reading : return the error number } return -2; // Buffer is full : return -3 }
bool Parser::parseCharData( Node *node ) { std::string data; while( !isInSet( "<&\0", current ) ) { data += current; readChar(); } if( data.find( "]]>" ) != 0xffffffff ) reportError( "Character data cannot contain ']]>'" ); node->setData( node->data() + data ); return ( data.length() > 0 ); }
void ConvertGtp::readColumnEffects(vector<TabTrack>::iterator &trk, int x) { char fx_bitmask1 = 0, fx_bitmask2 = 0, num; fx_bitmask1 = readChar(); if (versionMajor >= 4) { fx_bitmask2 = readChar(); //osg::notify(osg::INFO) << "column-wide fx: " << (int) fx_bitmask1 << "/" << (int) fx_bitmask2 << "\n"; } else { //osg::notify(osg::INFO) << "column-wide fx: " << (int) fx_bitmask1 << "\n"; } if (fx_bitmask1 & 0x20) { // GREYFIX: string torture num = readChar(); switch (num) { case 0: // GREYFIX: tremolo bar if (versionMajor < 4) readDelphiInteger(); break; case 1: // GREYFIX: tapping if (versionMajor < 4) readDelphiInteger(); // ? break; case 2: // GREYFIX: slapping if (versionMajor < 4) readDelphiInteger(); // ? break; case 3: // GREYFIX: popping if (versionMajor < 4) readDelphiInteger(); // ? break; default: throw string("Unknown string torture effect: %1"); } } if (fx_bitmask1 & 0x04) { // GP3 column-wide natural harmonic //osg::notify(osg::INFO) << "GP3 column-wide natural harmonic\n"; for (int y = 0; y < trk->strings; y++) trk->c[x].e[y] |= EFFECT_HARMONIC; } if (fx_bitmask1 & 0x08) { // GP3 column-wide artificial harmonic //osg::notify(osg::INFO) << "GP3 column-wide artificial harmonic\n"; for (int y = 0; y < trk->strings; y++) trk->c[x].e[y] |= EFFECT_ARTHARM; } if (fx_bitmask2 & 0x04) readChromaticGraph(trk->c[x]); // GREYFIX: tremolo graph if (fx_bitmask1 & 0x40) { num = readChar(); // GREYFIX: down stroke length num = readChar(); // GREYFIX: up stroke length } if (fx_bitmask2 & 0x02) { num = readChar(); // GREYFIX: stroke pick direction } if (fx_bitmask1 & 0x01) { // GREYFIX: GP3 column-wide vibrato } if (fx_bitmask1 & 0x02) { // GREYFIX: GP3 column-wide wide vibrato (="tremolo" in GP3) } }
//readString method //(The kernel improvement part is not working. But the orinignal code should be working) int readString(char *buf){ int i = 0; int result; while(i == 0 ||buf[i-1] != 0x0D){ result =readChar()%256; buf[i] =result; interrupt(0x10,0x0E*256+result, 0, 0, 0); i++; } buf[i++] = 0; return i - 1; }
//The handelInterrupt21 function int handleInterrupt21(int ax, int bx, int cx, int dx){ if (ax == 0x00) { printString(bx); return 1; } else if(ax == 0x11){ ((char*)bx)[0] = readChar(); return 1; } else if(ax == 0x01){ readString(bx); return 1; } else if(ax == 0x02){ readSector(bx,cx); } else if(ax == 0x03){ readfile(bx,cx); } else if(ax == 0x04){ executeProgram(bx); } else if(ax == 0x05){ terminate(); } else if(ax == 0x07){ deleteFile(bx); } else if(ax == 0x08){ writeFile(bx,cx,dx); } else if(ax == 0x09){ yield(); return 1; } else if(ax == 0x0A){ showProcesses(); return 1; } else if(ax == 0x0B){ kill(bx); } else{ return -1; } }
Node *Parser::parseDocument() { readChar( false ); Node *result = new Node; result->setName( "" ); result->setNodeType( Document ); if( !parseProlog( result ) ) reportError( "Missing prolog" ); if( !parseElement( result ) ) reportError( "Missing content" ); while( parseMisc( result ) ) {} return result; }
void* MQTTSPacket_ack_with_reasoncode(MQTTSHeader header, char* data) { MQTTS_Ack* pack = NULL; char* curdata = data; FUNC_ENTRY; if (header.len != 7) goto exit; pack = malloc(sizeof(MQTTS_Ack)); pack->header = header; pack->topicId = readInt(&curdata); pack->msgId = readInt(&curdata); pack->returnCode = readChar(&curdata); exit: FUNC_EXIT; return pack; }
IdentifierToken* Lexer::scanIdentifier(const int tokenID) throw (std::runtime_error) { std::string id; if (! isAlpha(peek_)) return 0; while (true) { id += peek_; if ((! isAlpha(nextChar())) && (! isDigit(nextChar()))) break; readChar(); } if (id.empty()) return 0; return new IdentifierToken(tokenID, id); }
char dmtcp::Util::readHex (int fd, VA *value) { char c; unsigned long int v; v = 0; while (1) { c = readChar (fd); if ((c >= '0') && (c <= '9')) c -= '0'; else if ((c >= 'a') && (c <= 'f')) c -= 'a' - 10; else if ((c >= 'A') && (c <= 'F')) c -= 'A' - 10; else break; v = v * 16 + c; } *value = (VA)v; return (c); }
char readUntil(FILE *stream, string &token, const char *stops, int &depth) { char chr; token = ""; while (true) { chr = readChar(stream, depth); if (!chr) return chr; // compare char to stop characters for (const char *i=stops; *i; i++) { if (chr == *i) return chr; } token += chr; } }