コード例 #1
0
ファイル: bitsx.cpp プロジェクト: heavilessrose/my-sync
ChrString _Bitsxstr(istream& Is_, Subscript Num_)
{
  Boolean Changed_ = FALSE;
  ChrString Str_('\0', Num_);

  if (Num_ == PTRDIFFT_MAX)
    --Num_;

  if (_Ipfx(Is_))
  {
    int ch;
    while (0 < Num_ && (ch = Is_.rdbuf()->sbumpc()) != EOF)
      if (ch != '0' && ch != '1')
      {
	Is_.rdbuf()->sputbackc(ch);
	break;
      }
      else
      {
	Str_ += ch;
	Changed_ = TRUE;
	--Num_;
      }
  }

  if (!Changed_)
    Is_.clear(ios::failbit);

  if (!_Ipfx(Is_))
    THROW (FallibleBase::IOFailureErr());

  return Str_;
}
コード例 #2
0
ファイル: zipfiletest.cpp プロジェクト: ming81/zipios
void zipios::ZipFileTest::compareStreams(const std::string& entryName,
        istream &is1, istream &is2) {
    OutputStringStream buf1, buf2;
    buf1 << is1.rdbuf();
    buf2 << is2.rdbuf();
    CPPUNIT_ASSERT_MESSAGE("Streams differ for entry '"+entryName+"'",
                           buf1.str() == buf2.str());
}
コード例 #3
0
ファイル: tinypipe.hpp プロジェクト: r-lyeh/tinybits
void copy( T &s, const istream &is ) {
    std::stringstream ss;
    std::streamsize at = is.rdbuf()->pubseekoff(0,is.cur);
    ss << is.rdbuf();
    is.rdbuf()->pubseekpos(at);
    auto x = ss.str();
    s.assign( x.begin(), x.end() );
}
コード例 #4
0
ファイル: DDoc.cpp プロジェクト: open-eid/libdigidocpp
/**
 * Adds signature to the container.
 *
 * @param signature signature, which is added to the container.
 * @throws ContainerException throws exception if there are no documents in container.
 */
void DDoc::addAdESSignature(istream &sigdata)
{
#if USE_SIGFROMMEMORY
    stringstream ofs;
    ofs << sigdata.rdbuf();
    ofs.flush();
    int err = d->lib->f_ddocAddSignatureFromMemory(d->doc, d->filename.c_str(), ofs.str().c_str(), ofs.str().size());
    d->throwCodeError(err, "Failed to sign document", __LINE__);
    d->loadSignatures();
#else
    string fileName = File::tempFileName();
    ofstream ofs(File::encodeName(fileName).c_str());
    ofs << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n";
    ofs << "<SignedDoc format=\"DIGIDOC-XML\" version=\"1.3\" xmlns=\"http://www.sk.ee/DigiDoc/v1.3.0#\">\n";
    ofs << sigdata.rdbuf();
    ofs << "</SignedDoc>";
    ofs.flush();
    ofs.close();

    SignedDoc *sigDoc = nullptr;
    int err = d->lib->f_ddocSaxReadSignedDocFromFile( &sigDoc, fileName.c_str(), 0, 0 );
    d->throwCodeError(err, "Failed to sign document", __LINE__);

    SignatureInfo **signatures = (SignatureInfo**)realloc( d->doc->pSignatures,
        (d->doc->nSignatures + sigDoc->nSignatures) * sizeof(SignatureInfo*));
    if( !signatures )
    {
        d->lib->f_SignedDoc_free( sigDoc );
        d->throwError("Failed to sign document", __LINE__);
        return;
    }

    d->doc->pSignatures = signatures;
    for( int i = 0; i < sigDoc->nSignatures; ++i )
    {
        d->doc->pSignatures[d->doc->nSignatures + i] = sigDoc->pSignatures[i]; // take ownership
        sigDoc->pSignatures[i] = nullptr;
        // from ddocReadNewSignaturesFromDdoc
        ((char*)d->doc->pSignatures[d->doc->nSignatures + i]->pDocs[0]->szDigest)[0] = 0x0A;
    }
    d->doc->nSignatures += sigDoc->nSignatures;
    sigDoc->nSignatures = 0;

    d->lib->f_SignedDoc_free( sigDoc );
#endif
    //Force reload
    save(fileName);
    load(fileName);
}
コード例 #5
0
ファイル: main.cpp プロジェクト: Boomaga/boomaga
static bool createJobFile(istream &src, const string &destFile, const Args &args)
{
    Log::debug("Create job file %s", destFile.c_str());

    ofstream dest(destFile, ios::binary | ios::trunc);
    dest << "\033CUPS_BOOMAGA\n";
    dest << "JOB="     << escapeString(args.jobID)   << "\n";
    dest << "USER="******"\n";
    dest << "TITLE="   << escapeString(args.title)   << "\n";
    dest << "COUNT="   << args.count                 << "\n";
    dest << "OPTIONS=" << escapeString(args.options) << "\n";
    dest << "CUPS_BOOMAGA_DATA\n";
    dest << src.rdbuf();
    dest.close();

    if (src.bad() || !dest.good())
    {
        Log::debug("Delete file %s", destFile.c_str());
        unlink(destFile.c_str());
        Log::error("Can't create job file: %s", strerror(errno));
        return false;
    }

    if (chown(destFile.c_str(), args.pwd->pw_uid, -1) != 0)
    {
        Log::error("Can't change owner on directory %s: %s", destFile.c_str(), std::strerror(errno));
        return false;
    }

    return true;
}
コード例 #6
0
ファイル: calPrinDir.cpp プロジェクト: Changtx/3dRendering
void safeGetline(istream& is, string& t)
{
    t.clear();
    std::istream::sentry se(is, true);
    std::streambuf* sb = is.rdbuf();
    
    while (true)
    {
        int c = sb->sbumpc();
        switch (c)
        {
            case '\n':
                return;
            case '\r':
                if (sb->sgetc() == '\n')
                    sb->sbumpc();
                return;
            case EOF:
                if (t.empty())
                    is.setstate(std::ios::eofbit);
                return;
            default:
                t += (char)c;
        }
    }
}
コード例 #7
0
ファイル: istream.cpp プロジェクト: wgoossens/mb-linux-labx
	template <> _UCXXEXPORT string _readToken<char, char_traits<char> >(istream & stream)
	{
		string temp;
		char_traits<char>::int_type c;
		while(true){
			c = stream.rdbuf()->sgetc();
			if(c != char_traits<char>::eof() && isspace(c) == false){
				stream.rdbuf()->sbumpc();
				temp.append(1, char_traits<char>::to_char_type(c));
			}else{
				break;
			}
		}
		if (temp.size() == 0)
			stream.setstate(ios_base::eofbit|ios_base::failbit);

		return temp;
        }
コード例 #8
0
ファイル: bitsx.cpp プロジェクト: heavilessrose/my-sync
short _Ipfx(istream& Is_, int noskip)
{
  if (Is_.good())
  {
    if (Is_.tie() != 0)
      Is_.tie()->flush();

    if (!noskip && Is_.flags() & ios::skipws)
    {
      int ch;
      while (isspace(ch = Is_.rdbuf()->sbumpc()))
	;
      if (ch != EOF)
	Is_.rdbuf()->sputbackc(ch);
    }

    if (Is_.good())
      return  1;
  }

  Is_.clear(ios::failbit);
  return 0;
}
コード例 #9
0
ファイル: zipoutputstreamtest.cpp プロジェクト: ming81/zipios
void zipios::ZipOutputStreamTest::entryToFile(const string &ent_name, istream &is, 
					      const string &outfile,
                                              bool cerr_report) {
  ofstream ofs( outfile.c_str(), ios::out | ios::binary ) ;
  
  
  ofs << is.rdbuf() ;
  if ( cerr_report ) {
    cerr << "writing " << ent_name << " to " << outfile << endl ;
    cerr << "Stream state: "  ;
    cerr << "good() = " << is.good() << ",\t" ;
    cerr << "fail() = " << is.fail() << ",\t" ;
    cerr << "bad()  = " << is.bad()  << ",\t" ;
    cerr << "eof()  = " << is.eof()  << endl << endl;
  }
  ofs.close() ;
}
コード例 #10
0
ファイル: ios.cpp プロジェクト: reynoldsbd3/robot-d5
bool
ios_base::sync_with_stdio(bool sync)
{
    static ios_base::Init  __make_sure_streams_are_constructed;
    static bool previous_sync = true;
    bool result = previous_sync;
    previous_sync = sync;
    cin.rdbuf()->pubsetbuf(0, !sync);
    cout.rdbuf()->pubsetbuf(0, !sync);
    clog.rdbuf()->pubsetbuf(0, !sync);
    cerr.rdbuf()->pubsetbuf(0, !sync);
#ifndef _EWL_NO_WCHART_CPP_SUPPORT
    wcin.rdbuf()->pubsetbuf(0, !sync);
    wcout.rdbuf()->pubsetbuf(0, !sync);
    wclog.rdbuf()->pubsetbuf(0, !sync);
    wcerr.rdbuf()->pubsetbuf(0, !sync);
#endif  // _EWL_NO_WCHART_CPP_SUPPORT
    return result;
}
コード例 #11
0
ファイル: lexer.cpp プロジェクト: Bhare8972/Cyth
//ring buffer
ring_buffer::ring_buffer(const istream& fin_) :fin(fin_.rdbuf())
{
    has_loaded_EOF=false;
    has_read_EOF=false;
    length_read=0;
    length_loaded=0;
    n_nodes=1;

    ring_buffer_node* new_node=new ring_buffer_node();
    new_node->next=new_node;
    new_node->previous=new_node;

    start_node=new_node;
    end_node=new_node;
    empty_node=new_node;

    add_nodes(2000);
    load_data();
}
コード例 #12
0
ファイル: CommandFoeWrite.cpp プロジェクト: BlastTNG/flight
void CommandFoeWrite::loadFoeData(
        ec_ioctl_slave_foe_t *data,
        const istream &in
        )
{
    stringstream err;
    ostringstream tmp;

    tmp << in.rdbuf();
    string const &contents = tmp.str();

    if (getVerbosity() == Verbose) {
        cerr << "Read " << contents.size() << " bytes of FoE data." << endl;
    }

    data->buffer_size = contents.size();

    if (data->buffer_size) {
        // allocate buffer and read file into buffer
        data->buffer = new uint8_t[data->buffer_size];
        contents.copy((char *) data->buffer, contents.size());
    }
}
コード例 #13
0
/*
 * Clears an istream object if unusuable characters are entered. Copied from MSDN.
 */
void clear_error(istream& in)
{
	streambuf* sbpThis;
    char szTempBuf[20];
    std::streamsize nCount;

	in.clear();                 // Clear error flags
    sbpThis = in.rdbuf();       // Get streambuf pointer
    nCount = sbpThis->in_avail(); // Number of characters in buffer

    while (nCount)                // Extract them to szTempBuf
    {
        if  (nCount > 20)
        {
            sbpThis->sgetn(szTempBuf, 20);
            nCount -= 20;
        }
        else
        {
            sbpThis->sgetn(szTempBuf, nCount);
            nCount = 0;
        }
    }
}
コード例 #14
0
ファイル: SignatureBES.cpp プロジェクト: vallov/libdigidocpp
/**
 *
 * @param path
 * @throws SignatureException
 */
SignatureBES::SignatureBES(istream &sigdata, BDoc *bdoc)
 : signature(nullptr)
 , asicsignature(nullptr)
 , bdoc(bdoc)
{
    try
    {
        stringstream is;
        is << sigdata.rdbuf();
        sigdata_ = is.str();

        Properties properties;
        properties.schema_location(XADES_NAMESPACE, File::fullPathUrl(Conf::instance()->xsdPath() + "/XAdES.xsd"));
        properties.schema_location(XADESv141_NAMESPACE, File::fullPathUrl(Conf::instance()->xsdPath() + "/XAdESv141.xsd"));
        properties.schema_location(URI_ID_DSIG, File::fullPathUrl(Conf::instance()->xsdPath() + "/xmldsig-core-schema.xsd"));
        properties.schema_location(ASIC_NAMESPACE, File::fullPathUrl(Conf::instance()->xsdPath() + "/ts_102918v010201.xsd"));
        asicsignature = xAdESSignatures(is, Flags::dont_initialize, properties).release();
        if(asicsignature->signature().size() > 1)
            THROW("More than one signature in signatures.xml file is unsupported");
        if(asicsignature->signature().empty())
            THROW("Failed to parse signature XML");
        signature = &asicsignature->signature()[0];
    }
    catch(const Parsing& e)
    {
        stringstream s;
        s << e;
        THROW("Failed to parse signature XML: %s", s.str().c_str());
    }
    catch(const xsd::cxx::exception& e)
    {
        THROW("Failed to parse signature XML: %s", e.what());
    }

#if 0
    for(const ReferenceType &ref: signature->signedInfo().reference())
        if(ref.transforms().present())
            THROW("Transforms are not supported");
#endif
    const QualifyingPropertiesType::SignedPropertiesOptional &sp = qualifyingProperties().signedProperties();
    if(sp.present())
    {
        const SignedPropertiesType::SignedDataObjectPropertiesOptional &sdop = sp->signedDataObjectProperties();
        if(sdop.present())
        {
            if(!sdop->commitmentTypeIndication().empty())
                THROW("CommitmentTypeIndicationType is not supported");
            if(!sdop->allDataObjectsTimeStamp().empty())
                THROW("AllDataObjectsTimeStamp is not supported");
            if(!sdop->individualDataObjectsTimeStamp().empty())
                THROW("IndividualDataObjectsTimeStampType is not supported");
        }
    }
    const QualifyingPropertiesType::UnsignedPropertiesOptional &up = qualifyingProperties().unsignedProperties();
    if(up.present())
    {
        if(up->unsignedDataObjectProperties().present())
            THROW("UnsignedDataObjectProperties are not supported");
        const UnsignedPropertiesType::UnsignedSignaturePropertiesOptional &usp = up->unsignedSignatureProperties();
        if(usp.present())
        {
            if(!usp->counterSignature().empty())
                THROW("CounterSignature is not supported");
            if(!usp->completeCertificateRefs().empty())
                THROW("CompleteCertificateRefs are not supported");
            if(!usp->completeRevocationRefs().empty())
                THROW("CompleteRevocationRefs are not supported");
            if(!usp->attributeCertificateRefs().empty())
                THROW("AttributeCertificateRefs are not supported");
            if(!usp->attributeRevocationRefs().empty())
                THROW("AttributeRevocationRefs are not supported");
            if(!usp->sigAndRefsTimeStamp().empty())
                THROW("SigAndRefsTimeStamp is not supported");
            if(!usp->refsOnlyTimeStamp().empty())
                THROW("RefsOnlyTimeStamp is not supported");
            if(!usp->attrAuthoritiesCertValues().empty())
                THROW("AttrAuthoritiesCertValues are not supported");
            if(!usp->attributeRevocationValues().empty())
                THROW("AttributeRevocationValues are not supported");
            if(!usp->archiveTimeStamp().empty())
                THROW("ArchiveTimeStamp is not supported");
            if(!usp->timeStampValidationData().empty())
                THROW("TimeStampValidationData is not supported");
        }
    }

    // Base class has verified the signature to be valid according to XML-DSig.
    // Now perform additional checks here and throw if this signature is
    // ill-formed according to BDoc.

    getSignedSignatureProperties(); // assumed to throw in case this block doesn't exist
    signingCertificate(); // assumed to throw in case this block doesn't exist

    if(id().empty())
        THROW("Signature element mandatory attribute 'Id' is missing");
}
コード例 #15
0
ファイル: istgalin.cpp プロジェクト: kendallb/scitech-mgl
ios::iostate __getaline( istream &istrm, char *buf, int len,
/***************************************************************/
    char delim, int is_get, int &chars_read ) {
// Read characters into buffer "buf".
// At most "len - 1" characters are read, and a 0 is added at the end.
// If "delim" is encountered, it is left in the stream and the read is
// terminated (and the NULLCHAR is added).
// Used by:
//    get( char *buf, int len, char delim )
//    getline( char *buf, int len, char delim )
//
// NOTE: Borland sets eofbit only. A full buffer just stops reading.
//       If something has been read, set eofbit anyway.
//
//       The proposed standard says to set failbit if the buffer is filled
//       without finding the delimiter (if doing a "getline"), or if a read
//       fails and no characters are extracted. It says nothing about eofbit.
//
//       Currently we set eofbit only if eof occurs on first character read.
//       failbit is set if no characters were read.
//
//       Failbit was being set (prior to Nov15,95) when len-1 characters were
//       read in the buffer.  At that time we discerned that no one else
//       was setting failbit in that case, so we stopped doing it.

    int           c;
    int           offset;
    ios::iostate  state = 0;
    streambuf    *sb;

    offset = 0;
    __lock_it( istrm.__i_lock );
    if( len > 1 && istrm.ipfx( 1 ) ) {
        sb = istrm.rdbuf();
        __lock_it( sb->__b_lock );
        len--;  // leave a space for the NULLCHAR
        while( offset < len ) {
            c = sb->speekc();
            if( c == EOF ) {
                if( offset == 0 ) {
                    state |= ios::eofbit;
                }
                break;
            }
            if( c == delim ) {
                if( !is_get ) {
                    sb->sbumpc();
                }
                break;
            }
            buf[offset++] = (char)c;
            sb->sbumpc();
        }
        istrm.isfx();
    }
    buf[offset]  = '\0';
    chars_read = offset;

    // the draft standard says that no characters is an
    // error if using get() or getline().
    // the IOStreams Handbook suggests that no characters is not
    // an error if the delim was seen, this seems to be what our
    // competitors do.
    if( (offset == 0) && (c != delim) ) {
        state |= ios::failbit;
    }
    // the draft standard says that len-1 characters is an
    // error if using getline()
    // our competitors don't agree with the draft, we won't follow the
    // draft either
    #if 0
    if( offset == len && !is_get ) {
        state |= ios::failbit;
    }
    #endif
    return( state );
}
コード例 #16
0
static string slurpStream(istream& in) {
    stringstream sstr;
    sstr << in.rdbuf();
    string result = sstr.str();
    return result;
}
コード例 #17
0
void
Redirect( istream& from, istream& to )
{
  CheckInit();
  from.rdbuf( to.rdbuf() );
}
コード例 #18
0
string slurpStream(istream& in) {
  stringstream sstr;
  sstr << in.rdbuf();
  return sstr.str();
}
コード例 #19
0
ファイル: text.cpp プロジェクト: ngoctnq/CSC121-15FA-FINAL
Text parse(bool cli, istream& is) {
	// some initialization
	int line = 0;
	ifstream file;
	std::streambuf *backup = is.rdbuf();

	// if text is not from files
	if (cli) {
		bool invalid = true;
		string dir;
		do {
			line = headline();
			cout << "\n\n\n\n";
			if (dir == "") cout << "\n\n";
			else cout << "        You can't break this, "
				<< "I'm handling errors properly!\n\n";
			cout << "        Please insert the directory "
				<< "of a text file for analysis.\n";
			cout << "        The file should be pre-formatted "
				<< "like this:\n\n";
			cout << "             <Title>\n";
			cout << "             <Author>\n\n";
			cout << "             <text to analyze>\n\n";
			cout << "        or pipe an input stream before "
				<< "executing.\n";
			for (int i = line += 9 + 7; i<25 - 1; i++) cout << "\n";
			cout << "Directory: ";
			if (getline(is, dir)) {
				(file.open(dir.c_str(), ifstream::in));
				if (file) invalid = false;
                else {
                    cout << "file could not be opened\n";
//                    exit(69);
                }
            }
		} while (invalid);
		is.rdbuf(file.rdbuf());
		cout << "istream mapped to cin.\n";
	}

	// check how many paragraphs are there
	string paragraph; int no_of_pars = 0; vector<string> pars;
	while (getline(is, paragraph)) {
		if (paragraph != "") {
			++no_of_pars;
			pars.push_back(paragraph);
		}
	}

	// invalid format
	if (no_of_pars < 2) {
        is.rdbuf(backup);
        file.close();
        
		line = headline();
		cout << "\n\n\n\n\n\n\n                     Invalid format!"
			<< "\n                     Error: "
			<< "file has less than 2 lines."
			<< "\n\n                     Try again maybe?";
		for (int i = line + 11; i < 24; i++) cout << "\n";
		if (!cli) {
			//cout << "piped, quitting";
			exit(1);
		}
		cout << "Press Enter to try again.";
		is.ignore();
		return parse(cli, is);
	}

	// new text object, having all word pairs
	Text text(pars[0], pars[1]);
	text.paragraphs = no_of_pars - 2;

	// count words and split
	vector<string> words;		// word vector
	int no_of_sentences = 0;
	for (auto iter = pars.begin() + 2; iter != pars.end(); ++iter) {
		no_of_sentences += split(*iter, words);
	}
	text.sentences = no_of_sentences;
	text.words = words.size();

	// sorting word
	sort(words.begin(), words.end());

	// reusing variable paragraph for temp read word
	paragraph = "";
	int times_appeared = 0;
	for (auto iter = words.begin(); iter != words.end(); ++iter) {
		if (!iter->compare(paragraph)) {
			++times_appeared;
		}
		else {
			if (times_appeared != 0) text.wordMap.insert(pair<string, int>(paragraph, times_appeared));
			cout << "pushed in " << paragraph << " " << times_appeared << "\n";
			times_appeared = 1;
		}
		paragraph = *iter;
	}
	// the last one never got included, so we have to manually add it
	text.wordMap.insert(pair<string, int>(paragraph, times_appeared));
	cout << "pushed in " << paragraph << " " << times_appeared << "\n";

	cout << "pushed all in, size " << text.wordMap.size() << "\n";

	// return cin rdbuf
	if (cli) {
		is.rdbuf(backup);
		cout << "istream (cin) reverted.\n";
		file.close();
		cout << "Opened file closed.\n";
	}

	cout << "Parse successful.\n";
	return text;
}