std::string mm_io_c::getline() { char c; std::string s; if (eof()) throw mtx::mm_io::end_of_file_x{mtx::mm_io::make_error_code()}; while (read(&c, 1) == 1) { if (c == '\r') continue; if (c == '\n') return s; s += c; } return s; }
const char *RTextFile::GetNextStrToken(std::string &str) { char *set = "\r\t\n "; char *strstart; str=""; // Strip la classe blank avant le nouveau token; while (_curpos < _buff+_size && (*_curpos == '\r' || *_curpos == '\n' || *_curpos == ' ' || *_curpos == '\t')) _curpos++; strstart = _curpos; if (!eof()) { int next = mystrcmp(_curpos,set,_buff+_size); str.assign(_curpos,_curpos+next); _curpos = _curpos+next; } return str.c_str(); }
bool Dataset::locate(){ bool result; if (plist.empty()) return false; std::map<std::string, field_value>::const_iterator i; first(); while (!eof()) { result = true; for (i=plist.begin();i!=plist.end();++i) if (fv(i->first.c_str()).get_asString() == i->second.get_asString()) { continue; } else {result = false; break;} if (result) { return result;} next(); } return false; }
const char *XMLParser::seekNextTag(const char *m[], const char *d[]){ doublebuffer->clear(); boolean f = true; while (f && !eof()){ doublebuffer->add(seekNextTag()); size_t pos1 = pos; const char *s = getNextTag(); const char *ds = NULL; size_t i; for(i = 0; d[i]; i++) if (cmpTag(s, d[i]) > 0){ ds=extractDoubleTag(d[i], true); break; } const char *cs=d[i]; for(i = 0; m[i]; i++) if (cmpTag(s, m[i]) > 0){ f = false; break; } if (f){ if (!isempty(s)){ doublebuffer->add(OPENTAG); doublebuffer->add(s); doublebuffer->add(CLOSETAG); } if (!isempty(ds)){ doublebuffer->add(ds); doublebuffer->add(OPENTAG); doublebuffer->add(OFFTAG); doublebuffer->add(cs); doublebuffer->add(CLOSETAG); } }else pos=pos1; } return doublebuffer->get(); };
// getline( char *, int, int ): This is a variation on the // standard getline() functions (which, incidentially, can // still be used instead of this function). The file's // current EOL type is used if none is supplied // Note that the file MUST be in binary mode for this to // work correctly; if it isn't not, it will assert. char * pifstream::getline( char *buffer, unsigned int bufsize, int eoltype ) { // Do some legality tests if( eoltype == -1 ) // Handle -1 (current EOL type) eoltype = eol; else assert( IsEOL( eoltype ) ); // Bounds-check EOL assert( buffer != NULL ); // Make sure the buffer isn't NULL char c; const char * EOL = EOLType2String(eoltype); int EOLLength = strlen(EOL); int sofar = 0; for( unsigned int i = 0; i < bufsize-1; i++ ) { get(c); // Test for errors/EOF if( !good() ) break; if( eof() ) break; // Add the char to the buffer buffer[i] = c; // Store the current char // Check for EOL(s) if( c == EOL[sofar] ) sofar++; else sofar = 0; // Exit if we've found our EOL(s) if( sofar == EOLLength ) { sofar--; break; } } // Finish Up buffer[ i - sofar ] = '\0'; return buffer; }
void UnwrappedLineParser::parseEnum() { nextToken(); if (FormatTok->Tok.is(tok::identifier) || FormatTok->Tok.is(tok::kw___attribute) || FormatTok->Tok.is(tok::kw___declspec)) { nextToken(); // We can have macros or attributes in between 'enum' and the enum name. if (FormatTok->Tok.is(tok::l_paren)) { parseParens(); } if (FormatTok->Tok.is(tok::identifier)) nextToken(); } if (FormatTok->Tok.is(tok::l_brace)) { if (Style.BreakBeforeBraces == FormatStyle::BS_Allman) addUnwrappedLine(); nextToken(); addUnwrappedLine(); ++Line->Level; do { switch (FormatTok->Tok.getKind()) { case tok::l_paren: parseParens(); break; case tok::r_brace: addUnwrappedLine(); nextToken(); --Line->Level; return; case tok::comma: nextToken(); addUnwrappedLine(); break; default: nextToken(); break; } } while (!eof()); } // We fall through to parsing a structural element afterwards, so that in // enum A {} n, m; // "} n, m;" will end up in one unwrapped line. }
static page_p get_page_for_next_record ( schema_p s ) { page_p pg = s->tbl->current_pg; if (eof(pg)) return NULL; if (eob(pg)) { unpin (pg); pg = get_next_page (pg); if ( pg == NULL) { put_msg (FATAL, "get_page_for_next_record failed at block %d\n", page_block_nr(pg) + 1); exit (EXIT_FAILURE); } page_set_pos_begin (pg); s->tbl->current_pg = pg; } return pg; }
bool UnwrappedLineParser::tryToParseLambdaIntroducer() { nextToken(); if (FormatTok->is(tok::equal)) { nextToken(); if (FormatTok->is(tok::r_square)) { nextToken(); return true; } if (FormatTok->isNot(tok::comma)) return false; nextToken(); } else if (FormatTok->is(tok::amp)) { nextToken(); if (FormatTok->is(tok::r_square)) { nextToken(); return true; } if (!FormatTok->isOneOf(tok::comma, tok::identifier)) { return false; } if (FormatTok->is(tok::comma)) nextToken(); } else if (FormatTok->is(tok::r_square)) { nextToken(); return true; } do { if (FormatTok->is(tok::amp)) nextToken(); if (!FormatTok->isOneOf(tok::identifier, tok::kw_this)) return false; nextToken(); if (FormatTok->is(tok::comma)) { nextToken(); } else if (FormatTok->is(tok::r_square)) { nextToken(); return true; } else { return false; } } while (!eof()); return false; }
String File::read(int64 length) { if (length <= 0) { raise_notice("Invalid length %lld", length); return ""; } String s = String(length, ReserveString); char *ret = s.mutableSlice().ptr; int64 copied = 0; int64 avail = m_writepos - m_readpos; while (avail < length && !eof()) { if (m_buffer == NULL) { m_buffer = (char *)malloc(CHUNK_SIZE); } if (avail > 0) { memcpy(ret + copied, m_buffer + m_readpos, avail); copied += avail; length -= avail; } m_writepos = readImpl(m_buffer, CHUNK_SIZE); m_readpos = 0; avail = m_writepos - m_readpos; if (avail == 0 || m_nonblocking) { // For nonblocking mode, temporary out of data. break; } } avail = m_writepos - m_readpos; if (avail > 0) { int64 n = length < avail ? length : avail; memcpy(ret + copied, m_buffer + m_readpos, n); m_readpos += n; copied += n; } m_position += copied; return s.setSize(copied); }
bool BufferedStreamMgr::readFileChunk() { if (eof()) { return false; } memset(_mainBuf, 0, _useBufSize +1); _mainBufCurrStartPos = 0; if (!_streamFinished) { _mainBufCurrLen = _inputStreamMgr->read((char *)_mainBuf, _useBufSize); if (_mainBufCurrLen < _useBufSize) { _streamFinished = true; } return _mainBufCurrLen > 0; } else { _mainBufCurrLen = 0; return false; } }
initmsg() { char s[80],k[80]; int i; numread=0; i=curconf; i++; strcpy(s,config.supportdir); itoa(i,k,10); strcat(s,k); strcat(s,"MSG.IDX"); i=0; filefile=open(s,O_RDWR | O_BINARY); if(filefile!=-1 && (filelength(filefile)!=0)) { while(!eof(filefile)) { read(filefile,&bidx[i],sizeof(struct boardindex)); i++; numread++; } close(filefile); return; } filefile=open(s,O_BINARY | O_RDWR | O_CREAT,S_IWRITE | S_IREAD); strcpy(bidx[0].name,"General"); bidx[0].num=1; bidx[0].level=10; bidx[0].maxmsgs=255; bidx[0].net=0; bidx[0].totalmsgs=0; bidx[0].options=0; bidx[0].pass[0]=0; write(filefile,&bidx[0],sizeof(struct boardindex)); close(filefile); numread=1; }
std::streamsize NoSeekFile::read(void *dst, std::streamsize bytes) { #ifdef GNASH_NOSEEK_FD_VERBOSE std::cerr << boost::format("read_cache(%d) called") % bytes << std::endl; #endif if (eof()) { #ifdef GNASH_NOSEEK_FD_VERBOSE std::cerr << "read_cache: at eof!" << std::endl; #endif return 0; } fill_cache(bytes + tell()); #ifdef GNASH_NOSEEK_FD_VERBOSE printInfo(); #endif std::streamsize ret = std::fread(dst, 1, bytes, _cache); if (ret == 0) { if (std::ferror(_cache)) { std::cerr << "an error occurred while reading from cache" << std::endl; } #if GNASH_NOSEEK_FD_VERBOSE if (std::feof(_cache)) { std::cerr << "EOF reached while reading from cache" << std::endl; } #endif } #ifdef GNASH_NOSEEK_FD_VERBOSE std::cerr << boost::format("fread from _cache returned %d") % ret << std::endl; #endif return ret; }
bool istream::readtags(string& s, const string& tag) { char buf[8192]; s.clear(); while (!eof()) { size_t size = sizeof(buf); if (readtags(buf, &size, tag.c_str(), tag.length()) == true) { if (size > 0) s.append(buf, size); return true; } if (size > 0) s.append(buf, size); } return false; }
Token Lexer::Next() { char curr_c; TType a_type; while (!eof()) { curr_c = read(); state = SwitchState(curr_c, state, a_type); if (state == accept) { Token Tok = Accept(a_type); if (a_type == Skip) continue; return Tok; } } if (state == ready) return Token(Eof, ""); }
/** Parse a source string as an expression */ Tuple parseString(const char* str, const char* srcName) { auto input = new Input( str, srcName ); input->eatWS(); auto expr = parseExpr(input); input->eatWS(); if (!input->eof()) { throw ParseError(input, "unconsumed input remains"); } return expr; }
bool IntervalBtreeCursor::advance() { RARELY killCurrentOp.checkForInterrupt(); if ( eof() ) { return false; } // Advance _curr to the next key in the btree. _curr.bucket = _curr.bucket.btree<V1>()->advance( _curr.bucket, _curr.pos, 1, __FUNCTION__ ); skipUnused( &_curr ); if ( _curr == _end ) { // _curr has reached _end, so iteration is complete. _curr.bucket.Null(); } else { ++_nscanned; } return ok(); }
void UnwrappedLineParser::parseObjCUntilAtEnd() { do { if (FormatTok->Tok.isObjCAtKeyword(tok::objc_end)) { nextToken(); addUnwrappedLine(); break; } if (FormatTok->is(tok::l_brace)) { parseBlock(/*MustBeDeclaration=*/false); // In ObjC interfaces, nothing should be following the "}". addUnwrappedLine(); } else if (FormatTok->is(tok::r_brace)) { // Ignore stray "}". parseStructuralElement doesn't consume them. nextToken(); addUnwrappedLine(); } else { parseStructuralElement(); } } while (!eof()); }
char *MemFile::fgets(char *s, int size) const { int n = 0; while (n < size - 1 && !eof()) { char c; size_t sz = fread(&c, 1, 1); if (sz) { if (c == 10) { s[n] = 0; return s; } s[n++] = c; } } s[n] = 0; return s; }
int BitInputStream::readBit() { if (bufi==8) { if(eof()) return -1; buf=in.get(); bufi=0; } bufi++; int i = buf>>7; buf=buf<<1; #define test4 #ifndef test4 #define test4 cout<<i<<endl; #endif return i; }
main() { printf("\n ENTER NAME : "); startname[0] = 20; startname[1] = 8; readstring(&startname[2]); printf("\n ENTER SERIAL NO. : "); readstring(serial); for (i = strlen(startname);i < 30;i++) startname[i] = ' '; sprintf(&startname[30],"SERIAL No. %s%c",serial,0); pirated(); printf("\nSearching....."); fhandle = open("options.exe",NORM); lseek(fhandle,1,SEEK_SET); do { lastseek = read(fhandle,&buffer,BUFLEN); string1 = find(_osmajor * _osminor - ALPHA + 'C',buffer,&buffer[BUFLEN],checkdisktype()- GAMMA + 5); if (string1 != NULL) { printf("\nsuccessful 1\n"); sprintf(string1,"%s",startname); string1 = find(_osminor / _osmajor - BETA + 'A',buffer,&buffer[BUFLEN],checkdisktype()- GAMMA + 5); if (string1 != NULL) { printf("successful 2\n"); sprintf(string1,"%s",codesname); lseek(fhandle,-lastseek,SEEK_CUR); write(fhandle,&buffer,BUFLEN); printf("\nSuccessfully Installed for :\n%s",startname); exit(0); } } } while (string1 == NULL && !eof(fhandle)); printf("Un-Successful\n"); close(fhandle); }
void netlist_parser::skipws() { while (unsigned char c = getc()) { switch (c) { case ' ': case 9: case 10: case 13: break; case '#': skipeol(); // treat preprocessor defines as comments break; case '/': c = getc(); if (c == '/') { skipeol(); } else if (c == '*') { int f=0; while (!eof() ) { c = getc(); if (f == 0 && c == '*') f=1; else if (f == 1 && c== '/' ) break; else f=0; } } break; default: ungetc(); return; } } }
int readID(int file) { char id[5]; id[4]=0; BYTE a; for(a=0; a<4; a++) id[a]=readChar(file); if(eof(file)) { printf("End of file reached."); return ID_EOF; } if(rb->strcmp(id, "MThd")==0) return ID_MTHD; if(rb->strcmp(id, "MTrk")==0) return ID_MTRK; if(rb->strcmp(id, "RIFF")==0) return ID_RIFF; return ID_UNKNOWN; }
//--------------------------------------------------------------------------- long CSVFile::countRows (void) { long count = 0; long oldPosition = logicalPosition; seek(0); //Start at the top. char tmp[2048]; readLine((MemoryPtr)tmp,2047); while (!eof()) { count++; readLine((MemoryPtr)tmp,2047); } //---------------------------------- // Move back to where we were. seek(oldPosition); return(count); }
const byte* FileIo::mmap() { assert(fp_ != 0); munmap(); mappedLength_ = size(); #if defined EXV_HAVE_MMAP && defined EXV_HAVE_MUNMAP void* rc = ::mmap(0, mappedLength_, PROT_READ, MAP_SHARED, fileno(fp_), 0); if (MAP_FAILED == rc) { throw Error(2, path_, strError(), "mmap"); } pMappedArea_ = static_cast<byte*>(rc); #else // Workaround for platforms without mmap: Read the file into memory DataBuf buf(static_cast<long>(mappedLength_)); read(buf.pData_, buf.size_); if (error() || eof()) throw Error(2, path_, strError(), "FileIo::mmap"); pMappedArea_ = buf.release().first; isMalloced_ = true; #endif return pMappedArea_; }
void vcf_file::read_header() { string line; unsigned int line_index = 0; line_index += meta_data.add_FILTER_descriptor("ID=PASS,Description=PASS", line_index); while (!eof()) { read_line(line); if (line[0] == '#') if (line[1] == '#') meta_data.parse_meta(line, line_index); else { meta_data.parse_header(line); return; } else return; } }
/** * @brief Member function <b>overflow</b> writes the specified character to all the destination * outptu strema buffers. * * @param c an <b>int</b> const value of the character to write. * * @return an <b>int</b> value of the character written. */ virtual typename std::basic_streambuf<Ch, Tr>::int_type overflow(const int c) { if (m_destinations.empty()) return 1; StreamErrorMap return_code; for (StreamSet::const_iterator it = m_destinations.begin(); it != m_destinations.end(); ++it) { int ret = (*it)->rdbuf()->sputc(c); return_code[*it] = ret; } // Remove streambufs with errors for (StreamSet::iterator it = m_destinations.begin(); it != m_destinations.end(); ++it) if (return_code[*it] == eof()) m_destinations.erase(it); if (m_destinations.empty()) return 1; return 1; }
void File::readString(std::string& str, size_t maxChar, bool seekToEnd) { size_t temp = cursor; str.clear(); char c; size_t count = 1; read(c); while (c && count < maxChar && !eof()) { str.push_back(c); read(c); count++; } if (c) str.push_back(c); if (seekToEnd) { seek(temp+maxChar); } }
typename hash_table<T, Hash, Equals, Allocator>::size_type hash_table<T, Hash, Equals, Allocator>:: nice_index(const_reference x) const { size_type n = capacity(); size_type i = best_index(x); size_type j = i; do { const auto &slot = _vector[j]; switch (slot.status) { case slot_type::free: case slot_type::erased: return j; case slot_type::busy: j = ((j + 1) % n); } } while (i != j); return eof(); }
void UnwrappedLineParser::parseParens() { assert(FormatTok->Tok.is(tok::l_paren) && "'(' expected."); nextToken(); do { switch (FormatTok->Tok.getKind()) { case tok::l_paren: parseParens(); break; case tok::r_paren: nextToken(); return; case tok::r_brace: // A "}" inside parenthesis is an error if there wasn't a matching "{". return; case tok::l_brace: { if (!tryToParseBracedList()) { nextToken(); { ScopedLineState LineState(*this); ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack, /*MustBeDeclaration=*/false); Line->Level += 1; parseLevel(/*HasOpeningBrace=*/true); Line->Level -= 1; } nextToken(); } break; } case tok::at: nextToken(); if (FormatTok->Tok.is(tok::l_brace)) parseBracedList(); break; default: nextToken(); break; } } while (!eof()); }
point_count_t PgReader::read(PointBuffer& buffer, point_count_t count) { if (eof()) return 0; log()->get(LogLevel::Debug) << "readBufferImpl called with " "PointBuffer filled to " << buffer.size() << " points" << std::endl; point_count_t totalNumRead = 0; while (totalNumRead < count) { if (m_patch.remaining == 0) if (!NextBuffer()) return totalNumRead; PointId bufBegin = buffer.size(); point_count_t numRead = readPgPatch(buffer, count - totalNumRead); PointId bufEnd = bufBegin + numRead; totalNumRead += numRead; } return totalNumRead; }