int main(int argc, char *argv[]) { if (argc != 3) invocation_error(argv[0], "[input file] [output file]"); puts(argv[0]); Parts db; time_t start_time = time(NULL); clock_t start_clock = clock(); if ((db = load_parts(argv[1])) == NULL) print_error( __FILE__, argv[1]); time_t end_time = time(NULL); clock_t end_clock = clock() - start_clock; printf("p %g:\tr %g:\tReading %ld from %s\n", end_clock / (double) CLOCKS_PER_SEC, difftime(end_time, start_time), size(db), argv[1]); start_time = time(NULL); start_clock = clock(); if (dump(argv[2], db) != 0) print_error( __FILE__, argv[2]); end_time = time(NULL); end_clock = clock() - start_clock; printf("p %g:\tr %g:\tWriting %s\n", end_clock / (double) CLOCKS_PER_SEC, difftime(end_time, start_time), argv[2]); puts(""); return 0; }
/** Parse a keyfile * * @param _load_mesh : whether the mesh shall loaded * @return success : whether loading the data was successful * * The parameter can be used to prevent the loading of the mesh, * even though we use parse_mesh. We need this for includes. */ bool KeyFile::load(bool _load_mesh) { // read file auto my_filepath = resolve_include_filepath(get_filepath()); std::vector<char> char_buffer = read_binary_file(my_filepath); has_linebreak_at_eof = char_buffer.back() == '\n'; #ifdef QD_DEBUG std::cout << "done." << std::endl; #endif // init parallel worker if master file // if (parent_kf == this) // _wq.init_workers(1); // convert buffer into blocks size_t iLine = 0; std::string last_keyword; std::vector<std::string> line_buffer; std::vector<std::string> line_buffer_tmp; bool found_pgp_section = false; std::string line; auto string_buffer = std::string(char_buffer.begin(), char_buffer.end()); std::stringstream st(string_buffer); // for (; std::getline(st, line); ++iLine) { for (; std::getline(st, line); ++iLine) { if (line.find("-----BEGIN PGP") != std::string::npos) { found_pgp_section = true; #ifdef QD_DEBUG std::cout << "Found PGP Section\n"; #endif } // remove windows file ending ... I hate it ... if (line.size() != 0 && line.back() == '\r') line.pop_back(); // new keyword if (line[0] == '*' || found_pgp_section) { if (!line_buffer.empty() && !last_keyword.empty()) { // transfer possible header for following keyword (see function) transfer_comment_header(line_buffer, line_buffer_tmp); // get type auto kw_type = Keyword::determine_keyword_type(last_keyword); #ifdef QD_DEBUG std::cout << last_keyword << " -> "; switch (kw_type) { case (Keyword::KeywordType::NODE): std::cout << "NODE\n"; break; case (Keyword::KeywordType::ELEMENT): std::cout << "ELEMENT\n"; break; case (Keyword::KeywordType::PART): std::cout << "PART\n"; break; case (Keyword::KeywordType::GENERIC): std::cout << "GENERIC\n"; break; case (Keyword::KeywordType::INCLUDE): std::cout << "INCLUDE\n"; break; case (Keyword::KeywordType::INCLUDE_PATH): std::cout << "INCLUDE_PATH\n"; break; } #endif auto kw = create_keyword(line_buffer, kw_type, iLine - line_buffer.size() - line_buffer_tmp.size() + 1); if (kw) keywords[kw->get_keyword_name()].push_back(kw); // transfer cropped data line_buffer = line_buffer_tmp; } // we always trim keywords trim_right(line); last_keyword = line; } // IF:line[0] == '*' // Encrypted Sections // // Extracts encrypted section here and places it in a line in the // line buffer. An encrypted section is treated like a keyword. if (found_pgp_section) { found_pgp_section = false; // get stream position const auto stream_position = st.tellg(); const auto end_position = string_buffer.find("-----END PGP", stream_position); if (end_position == std::string::npos) throw( std::runtime_error("Could not find \"-----END PGP MESSAGE-----\" for " "corresponding \"-----BEGIN PGP MESSAGE-----\" ")); // set stream position behind encrypted section st.seekg(end_position); // extract encrypted stuff line += '\n'; line += std::string(char_buffer.begin() + stream_position, char_buffer.begin() + end_position); // print_string_as_hex(line); if (line.back() == '\n') line.pop_back(); if (line.back() == '\r') line.pop_back(); } // we stupidly add every line to the buffer line_buffer.push_back(line); } // for:line // allocate last block if (!line_buffer.empty() && !last_keyword.empty()) { auto kw = create_keyword(line_buffer, Keyword::determine_keyword_type(last_keyword), iLine - line_buffer.size() + 1); if (kw) keywords[kw->get_keyword_name()].push_back(kw); } // only load files above *END! const auto end_kw_position = get_end_keyword_position(); // includes if (load_includes) { // update include dirs get_include_dirs(true); // do the thing for (auto& include_kw : include_keywords) { if (include_kw->get_position() < end_kw_position) // Note: prevent loading the mesh here include_kw->load(false); } } // wait for threads to finish preloading // _wq.wait_for_completion(); // Wait for completion // while (work_queue.size() != 0) { // work_queue.front().wait(); // work_queue.pop(); // } // load mesh if requested if (parse_mesh && _load_mesh) { // load nodes load_nodes(); // load parts load_parts(); // load elements load_elements(); } return true; }