int CStdInStream::GetChar() { int c = getc(_stream); if(c == EOF && !Eof()) throw kReadErrorMessage; return c; }
void LcfReader::SkipDebug(const struct LcfReader::Chunk& chunk_info, const char* srcfile) { // Dump the Chunk Data in Debug Mode #ifdef _WIN32 const char* srcfilename = strrchr(srcfile, '\\'); #else const char* srcfilename = strrchr(srcfile, '/'); #endif if (srcfilename == NULL) { srcfilename = srcfile; } else { srcfilename++; } fprintf(stderr, "Skipped Chunk %02X (%d byte) in lcf at %X (%s)\n", chunk_info.ID, chunk_info.length, Tell(), srcfilename); for (uint32_t i = 0; i < chunk_info.length; ++i) { uint8_t byte; LcfReader::Read(byte); fprintf(stderr, "%02X ", byte); if ((i+1) % 16 == 0) { fprintf(stderr, "\n"); } if (Eof()) { break; } } fprintf(stderr, "\n"); }
bool wxPipeInputStream::CanRead() const { if ( m_lasterror == wxSTREAM_EOF ) return false; // check if there is any input available struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 0; const int fd = m_file->fd(); fd_set readfds; FD_ZERO(&readfds); FD_SET(fd, &readfds); switch ( select(fd + 1, &readfds, NULL, NULL, &tv) ) { case -1: wxLogSysError(_("Impossible to get child process input")); // fall through case 0: return false; default: wxFAIL_MSG(_T("unexpected select() return value")); // still fall through case 1: // input available -- or maybe not, as select() returns 1 when a // read() will complete without delay, but it could still not read // anything return !Eof(); } }
void ASNLexer::LookupTag(void) { while ( true ) { char c = Char(); switch ( c ) { case '\r': case '\n': LexerWarning("unclosed tag", 11); return; case 0: if ( Eof() ) { LexerWarning("unclosed tag", 12); return; } AddChar(); LexerWarning("illegal character in tag", 13); break; case ']': AddChar(); return; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': // case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': AddChar(); break; default: AddChar(); LexerWarning("illegal character in tag", 14); break; } } }
int CStdInStream::GetChar() { int c = fgetc(_stream); // getc() doesn't work in BeOS? if (c == EOF && !Eof()) throw kReadErrorMessage; return c; }
void ASNLexer::SkipComment(void) { CComment& comment = AddComment(); while ( true ) { // wait for end of comments char c = Char(); switch ( c ) { case '\n': SkipChar(); NextLine(); return; case 0: if ( Eof() ) return; break; case '-': if ( Char(1) == '-' ) { SkipChars(2); return; } break; case '*': if ( Char(1) == '/' ) { SkipChars(2); return; } break; } comment.AddChar(c); SkipChar(); } }
TStr THttpLx::GetRespReasonPhrase(){ GetLws(); TChA RPStr; while (!Eof()&&ChDef.IsText(Ch)&&(Ch!=TCh::CrCh)&&(Ch!=TCh::LfCh)){ RPStr+=Ch; GetCh();} return RPStr; }
void ImageSectionsReader::Next(void) { if(Eof()) return; m_SectionsLeft--; m_Section = (PIMAGE_SECTION_HEADER) PtrFromRva( m_Section, sizeof(IMAGE_SECTION_HEADER) ); }
wxArrayString CTextFile::ReadLines(EReadTextFile flags, const wxMBConv& conv) { wxArrayString lines; while (!Eof()) { wxString line = GetNextLine(conv); if (flags & txtStripWhitespace) { line = line.Strip(wxString::both); } if (flags & txtIgnoreEmptyLines) { if (line.IsEmpty()) { continue; } } if (flags & txtIgnoreComments) { if (flags & txtStripWhitespace) { if (line.StartsWith(wxT("#"))) { continue; } } else if (line.Strip(wxString::leading).StartsWith(wxT("#"))) { continue; } } lines.Add(line); } return lines; }
bool CFCMReadFile::ParsingTextFile(CString szDelimiter) { if(!IsOpen()) { return false; } CString szLine; ResetData(); // m_nCols = GetNumberColums(szDelimiter); m_nCols = GetNumberColumsMulti(szDelimiter); while(!Eof()) { if(ReadLine(szLine)) { if (!szLine.IsEmpty()) { ++m_nRows; //ParsingLine(szLine, szDelimiter); ParsingLineMulti(szLine, szDelimiter); } } }; return true; }
TStr THttpLx::GetUrlStr(){ TChA UrlChA; while ((!Eof())&&(!ChDef.IsSp(Ch))){ UrlChA+=Ch; GetCh();} if (UrlChA.Empty()){ throw THttpEx(heUrlEmpty);} return UrlChA; }
void ImageSectionsReader::Next(DWORD characteristicsFilter) { for(;!Eof();Next()) { if(characteristicsFilter == (m_Section->Characteristics & characteristicsFilter)) break; } }
int FileStream::ReadLine(void * data, int maxsize) { char * buf = (char *)data; int size = 0; if (!Eof()) { char c = 0; while (size < maxsize && c != '\n' && !Eof()) { mFile.Read(&c, sizeof(char), 1); buf[size++] = c; } } return size; }
int FileStream::SkipLine() { int size = 0; if (!Eof()) { char c; mFile.Read(&c, sizeof(char), 1); while (c != '\n' && !Eof()) { ++size; } } return size; }
// Plain text, up until an angled bracket bool wxSimpleHtmlParser::ParseText(wxString& text) { while (!Eof() && GetChar(m_pos) != wxT('<')) { text += GetChar(m_pos); m_pos ++; } return TRUE; }
char InSituStringStream::GetClear() { // get the character and then clear value if (Eof()) return 0; char value = *src_; *src_++ = 0; return value; }
bool TSIn::GetNextLn(TChA& LnChA){ LnChA.Clr(); while (!Eof()){ const char Ch=GetCh(); if (Ch=='\n'){return true;} if (Ch=='\r' && PeekCh()=='\n'){GetCh(); return true;} LnChA.AddCh(Ch); } return !LnChA.Empty(); }
bool wxSimpleHtmlParser::ParseAttributes(wxSimpleHtmlTag* tag) { // Parse attributes of a tag header until we reach > while (!IsTagEndBracket(GetChar(m_pos)) && !Eof()) { EatWhitespace(); wxString attrName, attrValue; if (IsString()) { ReadString(attrName, TRUE); tag->AppendAttribute(attrName, wxEmptyString); } else if (IsNumeric(GetChar(m_pos))) { ReadNumber(attrName, TRUE); tag->AppendAttribute(attrName, wxEmptyString); } else { // Try to read an attribute name/value pair, or at least a name // without the value ReadLiteral(attrName, TRUE); EatWhitespace(); if (GetChar(m_pos) == wxT('=')) { m_pos ++; EatWhitespace(); if (IsString()) ReadString(attrValue, TRUE); else if (!Eof() && !IsTagEndBracket(GetChar(m_pos))) ReadLiteral(attrValue, TRUE); } if (!attrName.IsEmpty()) tag->AppendAttribute(attrName, attrValue); } } return TRUE; }
char ReadFileStream::Get() { char c = *current_; if (!Eof()) { current_++; count_++; Read(); } return c; }
THttpRqMethod THttpLx::GetRqMethod(){ TChA MethodNm; while (!Eof() && ChDef.IsAlpha(Ch)){ MethodNm+=Ch; GetCh();} THttpRqMethod Method=hrmUndef; if (MethodNm==THttp::GetMethodNm){Method=hrmGet;} else if (MethodNm==THttp::HeadMethodNm){Method=hrmHead;} else if (MethodNm==THttp::PostMethodNm){Method=hrmPost;} if (Method==hrmUndef){throw THttpEx(heMethodNmExpected);} return Method; }
PUrl THttpLx::GetUrl(){ TChA UrlChA; while ((!Eof())&&(!ChDef.IsSp(Ch))){ UrlChA+=Ch; GetCh();} if (UrlChA.Empty()){ throw THttpEx(heUrlEmpty);} static TStr LocalBaseUrlStr="http://localhost/"; PUrl Url=PUrl(new TUrl(UrlChA, LocalBaseUrlStr)); if (!Url->IsOk()){ throw THttpEx(heBadUrl);} return Url; }
bool wxSimpleHtmlParser::ParseComment() { // Eat the comment tag start Matches(wxT("<!--"), TRUE); while (!Eof() && !Matches(wxT("-->"), TRUE)) { m_pos ++; } return TRUE; }
inline int64_t Barrier::wait_for (int64_t pos) const { if (last_min_ > pos) { return last_min_; } int64_t min_pos = kMaxInt64Value; for (auto itr = limit_seq_.begin (); itr != limit_seq_.end (); ++itr) { int64_t itr_pos = 0; itr_pos = (*itr)->pos().aquire(); // spin for a bit for (int i = 0; itr_pos < pos && i < 1000; ++i) { itr_pos = (*itr)->pos().aquire(); if ((*itr)->pos().alert()) break; } // yield for a while, queue slowing down for (int y = 0; itr_pos < pos && y < 1000; ++y) { usleep(0); itr_pos = (*itr)->pos().aquire(); if ((*itr)->pos().alert()) break; } // queue stalled, don't peg the CPU but don't wait too long either... while (itr_pos < pos) { usleep (10 * 1000); // 10ms itr_pos = (*itr)->pos ().aquire (); if ((*itr)->pos ().alert ()) break; } if ((*itr)->pos ().alert ()) { (*itr)->check_alert (); if (itr_pos > pos) { // process everything up to itr_pos return itr_pos - 1; } else { throw Eof(); } } if (itr_pos < min_pos) { min_pos = itr_pos; } } assert (min_pos != kMaxInt64Value); return last_min_ = min_pos; }
// Could be number, string, whatever, but read up until whitespace or end of tag (but not a quoted string) bool wxSimpleHtmlParser::ReadLiteral(wxString& str, bool eatIt) { int pos = m_pos; while (!Eof(pos) && !IsWhitespace(GetChar(pos)) && !IsTagEndBracket(GetChar(pos)) && GetChar(pos) != wxT('=')) { str += GetChar(pos); pos ++; } if (eatIt) m_pos = pos; return TRUE; }
void SNetStorageObjectImpl::Read(string* data) { char buffer[READ_CHUNK_SIZE]; data->resize(0); size_t bytes_read; do { Read(buffer, sizeof(buffer), &bytes_read); data->append(buffer, bytes_read); } while (!Eof()); Close(); }
size_t LcfReader::Read0(void *ptr, size_t size, size_t nmemb) { if (size == 0) { //avoid division by 0 return 0; } //Read nmemb elements of size and return the number of read elements stream.read(reinterpret_cast<char*>(ptr), size*nmemb); size_t result = stream.gcount() / size; #ifdef NDEBUG if (result != nmemb && !Eof()) { perror("Reading error: "); } #endif return result; }
TToken ASNLexer::LookupBinHexString(void) { TToken token = T_BINARY_STRING; while ( true ) { char c = Char(); switch ( c ) { case '\r': case '\n': LexerWarning("unclosed bit string", 5); return token; case 0: if ( Eof() ) { LexerWarning("unclosed bit string", 6); return token; } AddChar(); LexerWarning("illegal character in bit string", 7); break; case '0': case '1': AddChar(); break; case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': AddChar(); token = T_HEXADECIMAL_STRING; break; case '\'': switch ( Char(1) ) { case 'B': AddChars(2); if ( token != T_BINARY_STRING ) LexerWarning("binary string contains hexadecimal digits", 8); return T_BINARY_STRING; case 'H': AddChars(2); return T_HEXADECIMAL_STRING; default: AddChar(); LexerWarning("unknown type of bit string", 9); return token; } default: AddChar(); LexerWarning("illegal character in bit string", 10); break; } } }
// Sets BfN to the end of line or end of buffer. Reads more data, if needed. // Returns 1, when an end of line was found, BfN is end of line. // Returns 0, when an end of line was not found and more data is required, // BfN is end of buffer. // Returns -1, when an end of file was found, BfN is not defined. int TZipIn::FindEol(int& BfN) { char Ch; if (BfC >= BfL) { // check for eof, read more data if (Eof()) { return -1; } FillBf(); } while (BfC < BfL) { Ch = Bf[BfC++]; if (Ch=='\n') { BfN = BfC-1; return 1; } if (Ch=='\r' && Bf[BfC+1]=='\n') { BfC++; BfN = BfC-2; return 1; } } BfN = BfC; return 0; }
void CFileDataIO::Read(void *buffer, size_t count) const { MULE_VALIDATE_PARAMS(buffer, wxT("Attempting to write to NULL buffer.")); // Check that we read everything we wanted. if (doRead(buffer, count) == (signed)count) { return; } // To reduce potential system calls, we only do EOF checks when reads fail. if (Eof()) { throw CEOFException(wxT("Attempt to read past end of file.")); } else { throw CIOFailureException(wxT("Read error, failed to read from file.")); } }
size_t ReadFileStream::Read(char* ptr, size_t length) { size_t bytesRead = 0; while ((length > 0) && !Eof()) { // copy up to the available data in the buffer size_t availBytes = std::min(static_cast<size_t>(bufferLast_ - current_), length); memcpy(ptr, current_, availBytes); length -= availBytes; ptr += availBytes; current_ += availBytes; bytesRead += availBytes; // get more data Read(); } count_ += bytesRead; return bytesRead; }