int DotD(istream &InputFile, char *sCurrent, ostream &OutputFile) { int i = 2; int TempChar; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'e' && TempChar != 'E') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'f' && TempChar != 'F') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'i' && TempChar != 'I') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'n' && TempChar != 'N') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'e' && TempChar != 'E') goto Done; OutputFile << "DEFINE"; return -1; Done: sCurrent[--i] = 0; OutputFile << sCurrent; return TempChar; }
/* * EXCHANGE */ void EXCHANGE_ROW::Load(istream &file) { char buf[1024]; file.getline(buf, sizeof(buf)); if (file.eof()) { return; } int rc = sscanf(buf, "%[^\t]\t%[^\t]\t%d\t%d\t%[^\t]%"PRId64, EX_ID, EX_NAME, &EX_OPEN, &EX_CLOSE, EX_DESC, &EX_AD_ID); if (rc != 6) { std::ostringstream strm; strm << "EXCHANGE_ROW::Load only loaded " << rc << " values from line"; throw std::runtime_error(strm.str()); } #if 0 file>>ws; file.get(EX_ID, sizeof(EX_ID), '\t'); //read and skip past the next tab file>>ws; file.get(EX_NAME, sizeof(EX_NAME), '\t'); //read up to the delimiter file>>ws; file>>EX_OPEN; file>>ws; file>>EX_CLOSE; file>>ws; file.get(EX_DESC, sizeof(EX_DESC), '\t'); //read up to the delimiter file>>ws; file>>EX_AD_ID; #endif }
void translateStream(istream& inputStream, ostream& outputStream) { int i = 0; char ch; const int maxLength = 70; char word[maxLength] = {""}, translated[maxLength] = {""}; // no word case with eof handler while (!isalnum(inputStream.peek())){ if (inputStream.eof()) return; inputStream.get(ch); outputStream << ch; } // word case to obtain words while (isalnum(inputStream.peek())){ inputStream.get(word[i]); i++; } // obtain translation and send to output stream translateWord(word,translated); outputStream << translated; // recusive call translateStream(inputStream,outputStream); }
bool XFileToken::SkipComments(istream& s) { char c; SkipWS(s); while (s.get(c)) { if (c == '/') { if (!s.get(c)) THROW_EXCEPTION_T("Parsing error", ParsingException); if (c != '/') THROW_EXCEPTION_T("Parsing error", ParsingException); } else if (c != '#') { s.putback(c); return true; } while (s.get(c)) { if (c == '\n') break; } SkipWS(s); } return false; }
unsigned char ReadCodes(istream &stream, list<Code> &list) { while (true) { uint8_t t = stream.get(); if (t == 0xFF || t == _else || t == endif) return t; Code code = { }; code.pointer = (t & 0x80) == 0x80; code.type = (CodeType)(t & 0x7F); stream.read((char *)&code.address, sizeof(void *)); if (code.pointer) { code.offsetcount = stream.get(); code.offsets = new int[code.offsetcount]; for (int i = 0; i < code.offsetcount; i++) stream.read((char *)&code.offsets[i], sizeof(int32_t)); } stream.read((char *)&code.value, sizeof(uint32_t)); if (code.type >= ifeq8 && code.type <= ifkbkey) switch (ReadCodes(stream, code.trueCodes)) { case _else: if (ReadCodes(stream, code.falseCodes) == 0xFF) return 0xFF; break; case 0xFF: return 0xFF; } list.push_back(code); } return 0; }
void CL_TimeOfDay::FromStream (istream& s) { CL_String rep; char c; long count = 0; char fill_char = s.fill (); while (s.get (c) && c == fill_char); if (!s.good() || s.eof()) { _numSecs = 0; return; } do { if (isalnum (c) || c == ':') { rep.Append (c); count++; } else break; } while (s.get (c)); long n = ParseAndConvert (rep); if (n > 0) { if (!s.eof()) s.putback (c); _numSecs = n; } else { s.seekg (s.tellg() - count, istream::cur); _numSecs = 0; } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string Properties::readQuotedString(istream& in) { char c; // Read characters until we see a quote while(in.get(c)) { if(c == '"') break; } // Read characters until we see the close quote string s; while(in.get(c)) { if((c == '\\') && (in.peek() == '"')) in.get(c); else if((c == '\\') && (in.peek() == '\\')) in.get(c); else if(c == '"') break; else if(c == '\r') continue; s += c; } return s; }
/* static string parse_scheme( istream &is ) { string scheme; // Look for :// char ch = is.get(); while( is ) { if( ch != ':' ) scheme += ch; else { if( is.get() == '/' && is.get() == '/' ) break; else throw invalid_argument( "bad URI syntax" ); } ch = is.get(); } return scheme; } static string parse_host( istream &is ) { string host; // until : ? # or / char ch = is.get(); while( is ) { if( strchr( ":?#", ch ) ) { is.unget(); break; } host += ch; ch = is.get(); } return host; } static string parse_port( istream &is ) { string port; // until / char ch = is.get(); if( is && ch == ':' ) { ch = is.get(); while( is ) { if( strchr( "/?#", ch ) ) { is.unget(); break; } if( isdigit( ch )) port += ch; else throw invalid_argument( "port must be a number in URI" ); } } return port; } static string parse_path( istream &is ) { string path; // until ? og # char ch = is.get(); while( is ) { if( strchr( "?#", ch )) { is.unget(); break; } path += ch; ch = is.get(); } return path; } */ static options_t parse_options( istream &is ) { list<pair<string,string>> lst; char ch = is.get(); if( is && ch == '?' ) { ch = is.get(); string n, v; bool is_v = false; while( is ) { if( ch == '&' ) { lst.push_back( make_pair( n, v )); v = n = ""; is_v = false; } else if( ch == '=' ) is_v = true; else (is_v ? v : n ) += ch; ch = is.get(); } } return lst; }
int readDataLine(istream &f, strings_t &line, int &expected) { int obtained = 0; while (f.good()) { int c = skipBlank(f); if (c == '\n' || c == '\r') break; string s; f >> s; if (! s.empty()) { line.push_back(s); obtained += 1; } } int c = f.get(); if (c == '\r' && f.get() != '\n') f.unget(); if (obtained > 0) { if (expected <= 0) expected = obtained; else if (expected > 0 && expected != obtained) { cerr << "ERROR: expecting " << expected << " columns in data file." << endl; exit(10); } } else skipSpace(f); return obtained; }
int O(istream &InputFile, char *sCurrent, ostream &OutputFile) { int i = 1; int TempChar; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'r' && TempChar != 'R') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'i' && TempChar != 'I') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'g' && TempChar != 'G') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'i' && TempChar != 'i') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'n' && TempChar != 'N') goto Done; sCurrent[i] = 0; OutputFile << sCurrent << "_m"; return -1; Done: sCurrent[--i] = 0; OutputFile << sCurrent; return TempChar; }
int R(istream &InputFile, char *sCurrent, ostream &OutputFile) { int i = 1; int TempChar; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'e' && TempChar != 'E') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'a' && TempChar != 'A') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'l' && TempChar != 'L') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != '1' && TempChar != '2' && TempChar != '4' && TempChar != '8') goto Done; sCurrent[i] = 0; OutputFile << sCurrent << "_m"; return -1; Done: sCurrent[--i] = 0; OutputFile << sCurrent; return TempChar; }
int M(istream &InputFile, char *sCurrent, ostream &OutputFile) { int i = 1; int TempChar; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'a' && TempChar != 'A') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'c' && TempChar != 'C') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'r' && TempChar != 'R') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'o' && TempChar != 'O') goto Done; sCurrent[i] = 0; OutputFile << sCurrent << "_m"; return -1; Done: sCurrent[--i] = 0; OutputFile << sCurrent; return TempChar; }
int IN(istream &InputFile, char *sCurrent, ostream &OutputFile) { int i = 2; int TempChar; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'c' && TempChar != 'C') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'l' && TempChar != 'L') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'u' && TempChar != 'U') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'd' && TempChar != 'D') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'e' && TempChar != 'E') goto Done; sCurrent[i] = 0; OutputFile << sCurrent << "_m"; return -1; Done: sCurrent[--i] = 0; OutputFile << sCurrent; return TempChar; }
int EX(istream &InputFile, char *sCurrent, ostream &OutputFile) { int i = 2; int TempChar; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 't' && TempChar != 'T') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'e' && TempChar != 'E') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'r' && TempChar != 'R') goto Done; sCurrent[i++] = TempChar = InputFile.get(); if(TempChar != 'n' && TempChar != 'N') goto Done; sCurrent[i] = 0; OutputFile << sCurrent << "_m"; return -1; Done: sCurrent[--i] = 0; OutputFile << sCurrent; return TempChar; }
bool CHotKey::Load(istream& InFile) #endif { //first read in the name //read in the event name uint32 nEventNameLen; InFile >> nEventNameLen; char* pszNameBuffer = new char[nEventNameLen + 1]; //make sure that we could allocate the memory if(pszNameBuffer == NULL) { return false; } //skip past the newline InFile.get(); //read in the specified number of characters for(uint32 nCurrChar = 0; nCurrChar < nEventNameLen; nCurrChar++) { pszNameBuffer[nCurrChar] = InFile.get(); } pszNameBuffer[nEventNameLen] = '\0'; //have the other load set up the name, and load the rest bool bRV = Load(InFile, pszNameBuffer); //clean up delete [] pszNameBuffer; return bRV; }
void readline (istream &cin, string &s) { while (cin) { char c; size_t n=0; while (cin && cin.get(c) && (c!=10) && (c!=13)) { if (c==9) { int nn = 8 - (n%8); for (int i=0 ; i<nn ; i++) s+=' ', n++; } else { s+=c, n++; } } if (!cin) return; if (c==10) { if (cin.get(c) && (c!=13)) { cin.unget(); } return; } if (c==13) { if (cin.get(c) && (c!=10)) { cin.unget(); } return; } } }
int DataMatrix::GetToken( istream& in, char* tokenbuf, int maxlen, bool acceptComments /*=true*/ ) { int ok = 1; int i; char ch = ' '; // skip leading whitespace while( in && ( isspace(ch) || ch == '[' ) ){ in.get(ch); if(ch == '[' && acceptComments==false) return -1; } if( !in ) return 0; tokenbuf[0] = ch; tokenbuf[1] = '\0'; tokenbuf[maxlen-1] = '\0'; for( i = 1; i < maxlen-1; i++ ) { in.get(ch); if( isspace(ch) || ch == ']' ) break; tokenbuf[i] = ch; tokenbuf[i+1] = '\0'; } if( i >= maxlen-1 ) ok = 0; return ok; }
void XMLParser::parseXML(istream & input, vector<XMLSerializable*> & vObjects) { vector<XMLSerializable*> myWorld; while(input.get() != '<') { } if( input.get() != '?' ) { cout << "Invalid header" << endl; return; } while( input.get() != '?') { } if( input.get() != '>') { cout << "Invalid header" << endl; return ; } while(input.get() != '<') { } int index = -1; parseElement(input, "", vObjects, index ); }
void codify(istream &iss) { char out[39], *ptr = out, *cptr; out[38] = '\0'; while(ptr < &out[9]) *ptr++ = ' '; for (ptr = &out[9]; iss.get(*ptr) ; ptr = &out[9]) { prev = codeMap[*ptr - 'A']; out[34] = *ptr; for(cptr = &out[35]; *ptr && *ptr != '\n' && cptr < &out[38]; iss.get(*++ptr)) { val = codeMap[*ptr - 'A']; if (val && val != prev) *cptr++ = val + '0'; prev = val; } while (cptr < &out[38]) *cptr++ = '0'; while (*ptr && *ptr != '\n') iss.get(*++ptr); while (ptr < &out[34]) *ptr++ = ' '; cout << out << '\n'; } }
void __gmp_istream_set_digits (string &s, istream &i, char &c, bool &ok, int base) { switch (base) { case 10: while (isdigit(c)) { ok = true; // at least a valid digit was read s += c; if (! i.get(c)) break; } break; case 8: while (isdigit(c) && c != '8' && c != '9') { ok = true; // at least a valid digit was read s += c; if (! i.get(c)) break; } break; case 16: while (isxdigit(c)) { ok = true; // at least a valid digit was read s += c; if (! i.get(c)) break; } break; } }
XFileToken XFileToken::ReadNumber(istream& s) { XFileToken result; result.m_type = Integer; char c; s.get(c); result.m_content.push_back(c); while (s.get(c)) { if (c == '.') { if (result.m_type == Integer) result.m_type = Float; else { s.putback(c); return result; } } else if (!isdigit(c)) { s.putback(c); return result; } result.m_content.push_back(c); } return result; }
// File consumption bool fileConsume( istream & argstream ) { char c = '\0'; size_t pos = 0; ofstream ofile; bool haveFile = filename.length() > 0; writelog2( "Consuming and saving file: ", filename ); if( haveFile ) { ofile.open( filename.c_str(), ios::out | ios::trunc | ios::binary ); } writelog2( "fileBoundaryLen: " , fileBoundaryLen ); // fill the buffer while( argstream.rdstate() == ios::goodbit && pos < fileBoundaryLen && argstream.get(c) ) { testdata[pos++] = c; } writelog2( "final file testdata pos: ", pos-1 ) // scan the buffer while( argstream.rdstate() == ios::goodbit && fileBoundary != testdata && argstream.get(c) ) { if( haveFile ) ofile.put(testdata[0]); memmove( testdata, testdata + 1, fileBoundaryLen ); testdata[fileBoundaryLen-1]=c; } writelog2( "Closing file: ", boundary ); if( haveFile ) ofile.close(); return true; }
//--------------------------------------------------------------------------- unique_ptr<Expression> ExpressionParser::parseSingleExpression(istream& input, ExpressionType lastExpression, Environment& environment) { // read harriet::skipWhiteSpace(input); char a = input.get(); if(!input.good()) return nullptr; // other single letter operators if(a == '(') return make_unique<OpeningPharentesis>(); if(a == ')') return make_unique<ClosingPharentesis>(); if(a == '+') return make_unique<PlusOperator>(); if(a == '-') { if(lastExpression==ExpressionType::TBinaryOperator || lastExpression==ExpressionType::TUnaryOperator || lastExpression==ExpressionType::TOpeningPharentesis) return make_unique<UnaryMinusOperator>(); else return make_unique<MinusOperator>(); } if(a == '*') return make_unique<MultiplicationOperator>(); if(a == '/') return make_unique<DivisionOperator>(); if(a == '%') return make_unique<ModuloOperator>(); if(a == '^') return make_unique<ExponentiationOperator>(); if(a == '&') return make_unique<AndOperator>(); if(a == '|') return make_unique<OrOperator>(); if(a=='>' && input.peek()!='=') return make_unique<GreaterOperator>(); if(a=='<' && input.peek()!='=') return make_unique<LessOperator>(); if(a=='!' && input.peek()!='=') return make_unique<NotOperator>(); if(a=='=' && input.peek()!='=') return make_unique<AssignmentOperator>(); // check for string char b = input.get(); if(a=='"') { string result; while(b!='"' && a!='\\') { if(!input.good()) throw harriet::Exception{"unterminated string expression"}; result.push_back(b); a = b; b = input.get(); } return make_unique<StringValue>(result); } // check for two signed letters if(input.good()) { if(a=='=' && b=='=') return make_unique<EqualOperator>(); if(a=='>' && b=='=') return make_unique<GreaterEqualOperator>(); if(a=='<' && b=='=') return make_unique<LessEqualOperator>(); if(a=='!' && b=='=') return make_unique<NotEqualOperator>(); input.unget(); } else { input.clear(); } // check for a number input.unget(); if(isdigit(a)) { int32_t intNum; input >> intNum; if(input.peek()=='.' && input.good()) { float floatNum; input >> floatNum; return make_unique<FloatValue>(floatNum+intNum); } else { return make_unique<IntegerValue>(intNum);
/** * @brief Gets name in the form <Last Name>, <First Name> * * @details dates are input using cin, and then recombined for string * accommodates testing (Submit) system * * @param in: istream object * @param out: string with date * * @note resolution for redirected input, getline did not work */ bool getALine( istream &consoleIn, char *str ) { char inChar; int index = 0; consoleIn.get( inChar ); while( inChar != ENDLINE_CHAR && index < MAX_NAME_LEN - 1 ) { if( inChar != CARRIAGE_RETURN_CHAR ) { str[ index ] = inChar; index++; str[ index ] = NULL_CHAR; } consoleIn.get( inChar ); } if( strcmp( str, "QUIT" ) == 0 ) { return false; } return true; }
/* * Function to read one row from the input stream. */ void TZipCodeInputRow::Load(istream &file) { char buf[1024]; file.getline(buf, sizeof(buf)); if (file.eof()) { return; } int rc = sscanf(buf, "%d\t%[^\t]\t%[^\t]\t%[^\n]", &iDivisionTaxKey, ZC_CODE, ZC_TOWN, ZC_DIV); if (rc != 4) { std::ostringstream strm; strm << "TZipCodeInputRow::Load only loaded " << rc << " values from line"; throw std::runtime_error(strm.str()); } #if 0 file>>ws; file>>iDivisionTaxKey; file>>ws; file.get( ZC_CODE, sizeof( ZC_CODE ), '\t' ); file>>ws; file.get( ZC_TOWN, sizeof( ZC_TOWN ), '\t' ); //read up to the delimiter file>>ws; file.get( ZC_DIV, sizeof( ZC_DIV ), '\n' ); #endif }
void Hero::load(istream &in) { Unit::load(in); destroyHero(); char buf[MAX_LEN_BUF]; //out << "#-------------------- class Hero" << endl; in.getline(buf, MAX_LEN_BUF); // skip comment initHero(); slots->load(in); backpack->load(in); paperdoll->load(in); //out << "# bounce" << endl; in.getline(buf, MAX_LEN_BUF); // skip comment //out << bounce << endl; in >> bounce; in.get(); // skip enter code. //out << "# bounceRange" << endl; in.getline(buf, MAX_LEN_BUF); // skip comment //out << bounceRange << endl; in >> bounceRange; in.get(); // skip enter code. }
void importOptions(istream &in, vector<string> &optionsVector) { char ch; string currentToken; while (in) { currentToken = ""; do { in.get(ch); if (in.eof()) break; // treat '#' as line comments if (ch == '#') while (in) { in.get(ch); if (ch == '\n') break; } // break options on spaces, tabs or new-lines if (in.eof() || ch == ' ' || ch == '\t' || ch == '\n') break; else currentToken.append(1, ch); } while (in); if (currentToken.length() != 0) optionsVector.push_back(currentToken); } }
bool fcnn::internal::read_comment(istream &is, string &s) { if (!is.good() || is.eof()) return false; char c; s.clear(); c = is.peek(); if (c != '#') return false; is.get(c); start_line: do { is.get(c); } while ((is.good() && !is.eof()) && ((c == ' ') || (c == '\t'))); if (is.eof()) return true; if (is.fail()) return false; while ((is) && (c != '\n')) { s += c; is.get(c); } if (is.eof()) return true; if (is.fail()) return false; if (c == '\n') { if (is.peek() == '#') { s += c; goto start_line; } else return true; } return true; }
bool SquareMaze::SquareMazeNode::readXY (istream& inData,int *x,int *y) { char ch; // skip leading spaces, which are legit while (1) { inData.get(ch); if (ch!=' ') { break; } } if (ch!='(') { // not valid - probably a newline return false; } inData >> *x; if (inData.fail()) { inData.clear(); cout << "WARNING: Solution seems to have a bad format\n"; // a bit of random, defensive programming inData.ignore(100000,'\n'); // make sure we don't just keep reading the same thing return false; } inData.get(ch); inData >> *y; inData.get(ch); return true; }
string predicate_scan_token ( istream & is, scan_token_predicate & prd ) { char ch = '\0'; string res = ""; do { // eat whitespaces ... ch = is.get(); } while ( isspace( ch ) ); for( bool longString = false;; ch = is.get() ) { if( ch == DOUBLE_L ) { if( longString ) break; else longString = true; } else if( longString ) res += ch; else if( prd.check( ch ) ) { if( res.size() ) is.putback( ch ); else res += ch; break; } else res += ch; } return res; }