Beispiel #1
0
    std::pair<bool, bool> bomUtf8Check(const FileUnit& file, bf::ifstream& strm)
    {
        if(!file.isExist())
        {
            stdErr() << file.total << ": notExist" << std::endl;
            return std::make_pair(false, false);
        }

        ErrorCode ec;
        if(file.isDir())
        {
            stdErr() << file.total << ": isDir" << std::endl;
            return std::make_pair(false, false);
        }

        strm.open(file.total);
        if(!strm)
        {
            stdErr() << file.total << ": openFailed" << std::endl;
            return std::make_pair(false, false);
        }

        std::istreambuf_iterator<char> const end;
        std::istreambuf_iterator<char> const strmItr(strm);
        const bool isBOM=utf8::starts_with_bom(strmItr, end);
        if(!isBOM)
            strm.seekg(0);

        auto const itr=std::istreambuf_iterator<char>(strm);
        const auto isValid=utf8::is_valid(itr, end);
        return std::make_pair(isBOM, isValid);
    }
 void open_file( fs::ifstream& configuration_file ) const {
     configuration_file.open( path_to_configuration_file );
     if ( !configuration_file.good() ) {
         notify( "Cannot open configuration file '" + path_to_configuration_file.string()
                 + "', probably you have not permissions..." );
     } else {}
 }
Beispiel #3
0
    static bool parsing_supported(boost::filesystem::ifstream& f) {
        static const uint32_t magic_bytes = (sizeof(AddressOffsetT) <= sizeof(uint32_t) ? 0xfeedface : 0xfeedfacf);

        uint32_t magic;
        f.seekg(0);
        f.read(reinterpret_cast<char*>(&magic), sizeof(magic));
        return (magic_bytes == magic);
    }
Beispiel #4
0
void definefile( std::ostringstream& data, fs::ifstream& input, std::string& name, bool useconst = false ) {
	/* Check if already defined */
	std::vector<std::string>::iterator search = std::find( list.begin(), list.end(), name );
	if ( search == list.end() ) {
		list.push_back( name );
	} else {
		/* Show warning, object of this name is already processed! */
		std::cout << "Warning: '" << name << "' already defined, processing of new one stopped." << std::endl;
		return;
	}

	/* Define array */
	data << "static" << ( useconst ? " const " : " " ) << "unsigned char " << name << "[] = {" << std::endl;
	
	int size = input.tellg();
	input.seekg( 0, std::ios::beg );

	int c = 0;
	int col = 0;

	for ( int i = 1; i <= size; ++i ) {
		/* Get character and add to array */
		c = input.get();

		/*
			Using a static copy of the boost::format string gives a nice performance boost!
			Boost help says using const boost::format fmter(fstring);
			But static is faster and using the object without copy constructor is even faster!
		*/
		//static boost::format fmt( "0x%02X" );
		//data << fmt % c;

		/*
			Fast option then... this code is executed allot!
			Still faster then the optimized boost::format use, but not that much!
		*/
		static char temp[5];
		snprintf( temp, 5, "0x%02X", c );
		data << temp;

		if ( i >= size ) {
			/* Last character */
			data << std::endl;
		} else {
			/* Next */
			data << ", ";
		}

		/* New colume? */
		int curcol = ( i / 10 );
		if ( col < curcol ) {
			col = curcol;
			data << std::endl;
		}
	}

	data << "};" << std::endl << std::endl;
}
Beispiel #5
0
    static bool parsing_supported(boost::filesystem::ifstream& f) {
        dos_t dos;
        f.seekg(0);
        f.read((char*)&dos, sizeof(dos));

        // 'MZ' and 'ZM' according to Wikipedia
        if (dos.e_magic != 0x4D5A && dos.e_magic != 0x5A4D) {
            return false;
        }

        header_t h;
        f.seekg(dos.e_lfanew);
        f.read((char*)&h, sizeof(h));

        return h.Signature == 0x00004550; // 'PE00'
    }
 cvs_iterator( const boost::filesystem::path & dir_path ) : dir_path(dir_path)
 {
   boost::filesystem::path entries_file_path( dir_path / "CVS/Entries" ); 
   entries_file.open( entries_file_path );
   if ( !entries_file )
     throw std::string( "could not open: " ) + entries_file_path.string();
   ++*this;
 }
    cvs_iterator & operator++()
    {
      assert( !!entries_file );
      std::string contents;
      do
      {
        do
        {
          std::getline( entries_file, contents );
          if ( entries_file.eof() )
          { 
            entries_file.close(); 
            value_path = "";
            return *this;
          }
        } while ( contents == "D" );
        if ( contents[0] == 'D' ) contents.erase( 0, 1 );
        value_path = dir_path
          / boost::filesystem::path( contents.substr( 1, contents.find( '/', 1 ) ), boost::filesystem::no_check );

      // in case entries file is mistaken, do until value_path actually found
      } while ( !boost::filesystem::exists( value_path ) );  
      return *this;
    }
Beispiel #8
0
    static bool parsing_supported(boost::filesystem::ifstream& f) {
        const unsigned char magic_bytes[5] = { 
            0x7f, 'E', 'L', 'F', sizeof(boost::uint32_t) == sizeof(AddressOffsetT) ? 1 : 2
        };

        unsigned char ch;
        f.seekg(0);
        for (std::size_t i = 0; i < sizeof(magic_bytes); ++i) {
            f >> ch;
            if (ch != magic_bytes[i]) {
                return false;
            }
        }

        return true;
    }
Beispiel #9
0
  void ErrorFile::parse(boost::filesystem::ifstream& is)
  {
    std::string line;


    // matches[1], warning/error type
    // matches[2], rest of line
    boost::regex warningOrError("^\\s*\\**\\s+\\*\\*\\s*([^\\s\\*]+)\\s*\\*\\*(.*)$");

    // matches[1], rest of line
    boost::regex warningOrErrorContinue("^\\s*\\**\\s+\\*\\*\\s*~~~\\s*\\*\\*(.*)$");

    // completed successfully
    boost::regex completedSuccessful("^\\s*\\*+ EnergyPlus Completed Successfully.*");

    // ground temp completed successfully
    boost::regex groundTempCompletedSuccessful("^\\s*\\*+ GroundTempCalc\\S* Completed Successfully.*");

    // completed unsuccessfully
    boost::regex completedUnsuccessful("^\\s*\\*+ EnergyPlus Terminated.*");

    // repeat count


    // read the file line by line using regexes
    while(std::getline(is, line)){

      boost::smatch matches;

//      LOG(Debug, "Parsing ErrorFile Line: " << line);


      // parse the file
      if (boost::regex_search(line, matches, warningOrError)){
        std::string warningOrErrorType = std::string(matches[1].first, matches[1].second); boost::trim(warningOrErrorType);
        std::string warningOrErrorString = std::string(matches[2].first, matches[2].second); boost::trim(warningOrErrorString);

        // read the rest of the multi line warning or error
        while(true){
          std::streampos pos = is.tellg();
          if (!std::getline(is, line)){
            break;
          }
          if (boost::regex_search(line, matches, warningOrErrorContinue)){
            std::string temp = std::string(matches[1].first, matches[1].second); boost::trim_right(temp);
            warningOrErrorString += "\n" + temp;
          }else{
            // unget the line
            is.seekg(pos);
            break;
          }
        }

        LOG(Trace, "Error parsed: " << warningOrErrorString);


        // correctly sort warnings and errors
        try{
          ErrorLevel level(warningOrErrorType);

          switch(level.value()){
            case ErrorLevel::Warning:
              m_warnings.push_back(warningOrErrorString);
              break;
            case ErrorLevel::Severe:
              m_severeErrors.push_back(warningOrErrorString);
              break;
            case ErrorLevel::Fatal:
              m_fatalErrors.push_back(warningOrErrorString);
              break;
          }

        }catch(...){
          LOG(Error, "Unknown warning or error level '" << warningOrErrorType << "'");
        }

      }else if (boost::regex_match(line, completedSuccessful) 
                || boost::regex_match(line, groundTempCompletedSuccessful)) {
        m_completed = true;
        m_completedSuccessfully = true;
        break;
      }else if (boost::regex_match(line, completedUnsuccessful)){
        m_completed = true;
        m_completedSuccessfully = false;
        break;
      }
    }

  }
 ~cvs_iterator() { if ( !!entries_file ) entries_file.close(); }