int LookAhead(tParser *File) { if( File->NextState.Token != TOK_INVAL ) return File->NextState.Token; // TODO: Should I save the entire state here? int ret = GetToken(File); PutBack(File); return ret; }
//***************************************************************************** // Lex::IsSpaceNextChar - checks is the next character space and skip it if // true; correctly deals with the lines' counter. // Returns : 1 if space character, 0 otherwise. //***************************************************************************** int Lex::IsSpaceNextChar( void ) { QChar ch = NextChar(); if( _isspace( ch ) ) return 1; else { PutBack(); return 0; } }
bool AutoCaptureMechanism::Capture(wxBitmap* bitmap, Control& ctrl) { // no manual specification for the control name // or name adjustment is disabled globally if (ctrl.name == wxT("") || m_flag & AJ_DisableNameAdjust) { // Get its name from wxRTTI ctrl.name = ctrl.ctrl->GetClassInfo()->GetClassName(); } int choice = wxNO; wxRect rect = GetRect(ctrl.ctrl, ctrl.flag); if (ctrl.flag & AJ_Dropdown && !(m_flag & AJ_DisableDropdown)) { // for drop-down controls we need the help of the user wxString caption = _("Drop-down screenshot..."); wxString msg = wxString::Format(_("Do you wish to capture the drop-down list of '%s' ?\n\n If YES, please drop down the list of '%s' in 5 seconds after closing this message box.\n If NO, the screenshot for this control won't contain its drop-down list."), ctrl.name, ctrl.name); choice = wxMessageBox(msg, caption, wxYES_NO, m_notebook); if (choice == wxYES) { //A little hint ctrl.ctrl->SetCursor(wxCursor(wxCURSOR_HAND)); // Do some rect adjust so it can include the dropdown list // This adjust isn't pretty, but it works fine on all three paltforms. // Looking forward to a better solution int h = rect.GetHeight(); rect.SetHeight(h * 4); } } // cut off "wx" and change the name into lowercase. // e.g. wxButton will have a name of "button" at the end ctrl.name.StartsWith(wxT("wx"), &(ctrl.name)); ctrl.name.MakeLower(); // take the screenshot Capture(bitmap, rect, (choice == wxYES)?5:0); if (choice == wxYES) ctrl.ctrl->SetCursor(wxNullCursor); if (ctrl.flag & AJ_RegionAdjust) PutBack(ctrl.ctrl); return true; }
bool GenericXMLParser::ParseTag(String &tag, Anything &tagAttributes) { StartTrace(GenericXMLParser.ParseTag); tag = ParseName(); Trace("tag = " << tag); while (!IsEof()) { SkipWhitespace(); int c = Peek(); switch (c) { case '>': // done with tag c = Get(); return true;//lint !e438 case '/': // an empty tag? i.e. <br /> c = Get(); if ('>' == Peek()) { c = Get(); return false;//lint !e438 } // an error occured, ignore '/' silently PutBack(c); default: {//lint !e616 String name; String value; if (ParseAttribute(name, value)) { tagAttributes[name] = value; } else { // non-well formed XML...no value given if (name.Length() > 0) { tagAttributes.Append(name); } else { String msg("Unexpected character <"); c = Get(); msg.AppendAsHex((unsigned char)c).Append("> near ").Append(tag); Error(msg); tagAttributes.Append(String(char(c))); } } } } } Error("unexpected EOF in Tag"); return false; // no body to expect }
// Word must be in a CAPITAL LETTERS void TsScanner :: FillBuffer ( char c ) { unsigned int i = 0; LexBuff [0] = c; while ( i < MaxIDLength && isLegalIdChar ( c = NextChar() ) ) LexBuff[++i] = c; LexBuff[++i] = 0; if ( i > MaxIDLength ) { fpp_assert ( i == MaxIDLength + 1 ); std::cerr << "Identifier was restricted to " << LexBuff << "\n"; do { c = NextChar(); } while ( isLegalIdChar(c) ); } // OK or read the end of ID PutBack ( c ); }
//***************************************************************************** // TXML_Lex::NextLexem (m) - returns next extracted lexem. // Your should define the function yourself. //***************************************************************************** Lexem TXML_Lex::NextLexem( void ) { Lexem ret; double *p_d; QString *p_s; ret.LexType = LEX_NONE; do { while( IsSpaceNextChar() ) ; //*** Remarks' termination *** if( RemTermination( ret ) == -1 ) { if( ret.LexType == __LEX_eof ) { ret.LexType = LEX_eof; PutBack(); } continue; } ret.line = GetLine(); ret.col = GetCol(); ret.shift = GetShift(); if( ( SoleChar().isDigit() || SoleChar() == _T('.') || SoleChar() == _T('+') || SoleChar() == _T('-') ) && mode == TXML_Lex_MODE_INTAG ) { static LSDigit ldigit; ldigit.Reset(); ret.LexType = ldigit.Analisys( getCurrentText() ); switch( ret.LexType ) { case LSDigit::Integer: ret.Index = ldigit.asign * ldigit.mnt_int; ret.LexType = LEX_const_int; break; case LSDigit::Float: ret.LexType = LEX_const_real; ldigit.mnt_float *= pow( 10.0, (int)ldigit.power ); ret.Smth = d_autoheap.Add2List( p_d = new double( ldigit.asign * ldigit.mnt_float ) ); break; case LSDigit::FloatIEEE: ret.LexType = LEX_const_real; ldigit.mnt_float *= pow( 10.0, (int)(ldigit.power + ldigit.sign * ldigit.powerE) ); ret.Smth = d_autoheap.Add2List( p_d = new double( ldigit.asign * ldigit.mnt_float ) ); break; default: lex_err = Lex::BadNumericFormat; ret.LexType = LEX_NONE; ret.Smth = 0; } Inc( ldigit.GetRead() ); continue; } if( (SoleChar() == _T('\"') || SoleChar() == _T('\'')) && mode == TXML_Lex_MODE_INTAG ) { static LXMLString lstring( SoleChar() ); lstring.Reset( SoleChar() ); if( ( ret.LexType = lstring.Analisys( getCurrentText() ) ) != LEX_NONE ) { ret.LexType = LEX_const_string; ret.Smth = s_autoheap.Add2List( p_s = new QString( lstring.read_string ) ); } Inc( lstring.GetRead() ); continue; } if( (SoleChar().isLetter() || (SoleChar() == _T('_'))) && mode == TXML_Lex_MODE_INTAG ) { static LXMLVar lvar; lvar.Reset(); int r = lvar.Analisys( getCurrentText() ); if( r ) { if( r == LXMLVar::XML ) ret.LexType = LEX_kw_xml; else if( r == LXMLVar::DOCTYPE ) ret.LexType = LEX_kw_doctype; else ret.LexType = LEX_id; ret.Smth = s_autoheap.Add2List( p_s = new QString( (lvar.getNS().length() == 0) ? lvar.getID() : (lvar.getNS() + _T(":") + lvar.getID()) ) ); Inc( lvar.GetRead() ); } else ret.LexType = LEX_NONE; continue; } if( mode == TXML_Lex_MODE_INTAG ) { QChar tch = NextChar(); switch( tch.unicode() ) { case _T('<'): if( SoleChar() == _T('?') ) { ret.LexType = LEX_begintag_q; NextChar(); } else if( SoleChar() == _T('!') ) { ret.LexType = LEX_begintag_e; NextChar(); } else if( SoleChar() == _T('/') ) { ret.LexType = LEX_begintag_s; NextChar(); } else ret.LexType = LEX_begintag; mode = TXML_Lex_MODE_INTAG; break; case _T('>'): ret.LexType = LEX_endtag; mode = TXML_Lex_MODE_OUTTAG; break; case _T('='): ret.LexType = LEX_equal; break; case _T('['): ret.LexType = LEX_lab; break; case _T(']'): ret.LexType = LEX_rab; break; case EOF_ASCII_1A : case EOF_ASCII_NULL : ret.LexType = LEX_eof; PutBack(); break; case _T('/'): case _T('?'): if( SoleChar() == _T('>') ) { ret.LexType = tch == _T('/') ? LEX_endtag_s : LEX_endtag_q; mode = TXML_Lex_MODE_OUTTAG; NextChar(); } else ret.LexType = LEX_NONE; break; } } else { switch( NextChar().unicode() ) { case _T('<'): if( SoleChar() == _T('?') ) { ret.LexType = LEX_begintag_q; NextChar(); } else if( SoleChar() == _T('!') ) { ret.LexType = LEX_begintag_e; NextChar(); } else if( SoleChar() == _T('/') ) { ret.LexType = LEX_begintag_s; NextChar(); } else ret.LexType = LEX_begintag; mode = TXML_Lex_MODE_INTAG; break; case EOF_ASCII_1A : // !!! eof !!! case EOF_ASCII_NULL : // !!! eof !!! ret.LexType = LEX_eof; PutBack(); break; default : { QChar pch; PutBack( 2 ); while( SoleChar().isSpace() && !isBOF() ) PutBack(); NextChar(); ret.Smth = s_autoheap.Add2List( p_s = new QString( _T("") ) ); ret.LexType = LEX_text; for( pch = NextChar(); pch != QChar('<') && pch != QChar(EOF_ASCII_1A) && pch != QChar(EOF_ASCII_NULL); pch = NextChar() ) { *(QString*)ret.Smth += pch; } PutBack(); } } } } while( 0 ); prev_lexem.LexType = ret.LexType; return ret; }
//***************************************************************************** // Lex::RemTermination - Terminates remarks. // Returns : -1 if <NextLexem> must returns something, 0 otherwise. //***************************************************************************** int Lex::RemTermination( Lexem& ret ) // ~~~~~~~~~~~~~~ { bool is_slsl; QString startRem, endRem; //*** Remarks' termination *** while( NextChar() == '/' ) { if( NextChar() == '*' ) // Remark like this => /*...*/ { startRem = QString("/*"); endRem = QString("*/"); is_slsl = false; } else { PutBack(); if( NextChar() == _T('/') ) // Remark like this => //... { startRem = QString("//"); endRem = QString("\r\n"); is_slsl = true; } else { PutBack(); break; } } QChar ch; while( !_iseof( SoleChar() ) && !isLA( endRem ) ) { ch = NextChar(); if( !is_slsl && (ch == _T('\x0D')) ) { if( NextChar() == _T('\x0A') ) line++; else PutBack(); } } if( _iseof( SoleChar() ) ) { if( is_slsl ) { ret.LexType = __LEX_eof; PutBack(); } else { lex_err = Lex::UnterminatedComment; ret.LexType = 0 /*LEX_NONE*/; PutBack(); } return -1; } else { Inc( endRem.length() ); if( is_slsl ) line++; } //*** Space symbols' termination *** while( IsSpaceNextChar() ) ; } PutBack(); return 0; }
int IOBase::ReadUntilEOS(char*& readbuf, size_t* readedBytes, char* eosString, long timeout_in_ms, char quota) { int n = 0; int timeout = 0; int bufsize = DELTA_BUFSIZE; int result = 0; int quoted = 0; char* buf = new char[bufsize]; char* des = buf; char* eos = eosString; char ch; Timer t(timeout_in_ms,&timeout,NULL); t.start(); while(!timeout) { if(des >= &buf[bufsize]) { // buffer full, realloc more memory char* tmp = new char[bufsize + DELTA_BUFSIZE + 1]; memcpy(tmp,buf,bufsize); delete[] buf; buf = tmp; des = &buf[bufsize]; bufsize += DELTA_BUFSIZE; } // read next byte n = Read(&ch,1); if(n < 0) { // an error occured result = -1; break; } else if(n == 0) { // no data available, give up the processor for some time // to reduce the cpu last sleepms(10); continue; } // if eos is composed of more than one char, and the current // byte doesn't match the next eos character, we handle the // readed byte as a normal char (and not an eos) if((eos != eosString) && (ch != *eos)) { // FIXME! // write all characters, which was matched the eos string // until now (with the first wrong character all received // eos characters are invalid and must handled as normal // characters). // This doesn't work right and is only a little workaround // because the received eos chars are lost PutBack(ch); // because we doesn't match the eos string, we must 'reset' // the eos match eos = eosString; continue; } else { if((ch == *eos) && !quoted) { if(*++eos == 0) { // the eos string is complete result = 1; break; } continue; } } if(ch == quota) { quoted ^= 1; } *des++ = ch; } *des = 0; readbuf = buf; *readedBytes = des - buf; return result; }