void add_paths(set<PathAndConds>& frontier){ stringstream action; action << "echo 'select path from frontend;' | sqlite3 database.db > paths"; systm(action.str()); action.str(""); action << "echo 'select conditions from frontend;' | sqlite3 database.db > conditions"; systm(action.str()); action.str(""); action << "echo 'select file_initializations from frontend;' | sqlite3 database.db > file_initializations"; systm(action.str()); string line; vector<string> paths; vector<string> conds; vector<string> file_initializations; { ifstream input(tmp_file("paths").c_str()); while( getline( input, line ) ) { paths.push_back(line); } } { ifstream input(tmp_file("conditions").c_str()); while( getline( input, line ) ) { conds.push_back(line); } } { ifstream input(tmp_file("file_initializations").c_str()); while( getline( input, line ) ) { file_initializations.push_back(line); } } assert(paths.size() == conds.size()); for ( unsigned int i = 0; i < paths.size(); i++) { PathAndConds path_and_cond = {paths[i], conds[i], width(conds[i]), get_last_bb(), file_initializations[i]}; frontier.insert(path_and_cond); } }
ptr_file direction::get_file(std::string name) { if (m_data.find(name) == m_data.end()) { return tmp_file(nullptr, [](mfile*) {}); } auto ptr = m_data[name]; if (ptr->mod.type == file_type::file) { return tmp_file( (mfile*)ptr->open(), [](mfile*) {}) ; } return tmp_file(nullptr, [](mfile*) {}); }
QString IconProvider::fileExtensionType(const QString &extension) const { QFileIconProvider icon_provider; QString type; QTemporaryFile tmp_file(QDir::tempPath() + QDir::separator() + QCoreApplication::applicationName() + "_XXXXXX" + extension); tmp_file.setAutoRemove(false); if(tmp_file.open()) { QString file_name = tmp_file.fileName(); tmp_file.write(QByteArray()); tmp_file.close(); type = icon_provider.type(QFileInfo(file_name)); tmp_file.remove(); } else { // qCritical()<<QString("failed to write temporary file %1") .arg(tmp_file.fileName()); } return type; }
string get_last_bb(){ stringstream command; command << "echo 'select last_bb from last_bb;' | sqlite3 database.db > " << tmp_file("last_bb"); systm(command.str().c_str()); ifstream input(tmp_file("last_bb").c_str()); string line; input >> line; return line; }
QIcon IconProvider::fileExtensionIcon(const QString &extension) const { QFileIconProvider icon_provider; QFile tmp_file(QDir::tempPath() + QDir::separator() + QCoreApplication::applicationName() + "_XXXXXX" + extension); // tmp_file.setAutoRemove(false); QString file_name = tmp_file.fileName() ; //如果文件存在 if(tmp_file.exists()) { // tmp_file.write(QByteArray()); tmp_file.close(); // tmp_file.remove(); } else { //创建文件 tmp_file.open(QIODevice::WriteOnly); tmp_file.close(); } // qDebug() << file_name; QIcon icon = icon_provider.icon(QFileInfo(file_name)); return icon; }
void LoggerSimp::clearLogFile(void) { //----- // clears the log file // std::ofstream tmp_file(mLogFile.c_str(), std::ios::out); tmp_file.close(); }
VideoPartitioner::~VideoPartitioner() { for (auto partition : this->_partitions) { bfs::path tmp_file(partition.get_path()); if (bfs::exists(tmp_file)) bfs::remove(tmp_file); } }
static void output_vertices (vertex_db & vertices) { std::string tmp_file_name = "tmpidmap"; boost::shared_ptr<SpatialIndex::IStorageManager> tmp_file (SpatialIndex::StorageManager::createNewDiskStorageManager ( tmp_file_name,page_size)); idmap_t idmap (tmp_file, page_size); vertex_db::iterator v_start = vertices.begin (); vertex_db::iterator v_ptr = v_start; ofstream myfile; myfile.open ("example.txt"); long v_id = 1; long edges = 0; // map<vertex_id,long> idmap; while (v_ptr != vertices.end ()) { edges += ((vertex_info)v_ptr->second).neighbours.size (); // idmap.insert(pair<vertex_id,long>((vertex_id)v_ptr->first,v_id)); idmap.insert (v_ptr->first, v_id); v_id++; v_ptr++; } v_id--; ldiv_t divresult = ldiv(edges,2); myfile << v_id << " " << divresult.quot << " 0\n"; v_start = vertices.begin (); v_ptr = v_start; v_id = 1; while (v_ptr != vertices.end ()) { std::vector<vertex_id> n = ((vertex_info)v_ptr->second).neighbours; vertex_id id = (vertex_id)v_ptr->first; // map<vertex_id,long>::iterator it; // it = idmap.find(id); std::cout << get_remapped_vertex (idmap, id) << " : "; //std::cout << it->second << " : "; BOOST_FOREACH (vertex_id n_id, n) { // it = idmap.find(n_id); myfile << get_remapped_vertex (idmap, n_id) << " "; } myfile << endl; v_id++; v_ptr++; }
void gen_final_for_measurement(){ string base_path = cmd_option_str("base_path"); string llvm_path = cmd_option_str("llvm_path"); string output_file = cmd_option_str("output_file"); stringstream cmd; make_initial_bc(); // First optimization pass cmd.str(""); cmd << "opt -load " << llvm_path << "/Release+Asserts/lib/ForestMeasure.so -meas_fillnames < file.bc > file-2.bc"; systm(cmd.str().c_str()); // Second optimization pass cmd.str(""); cmd << "opt -load " << llvm_path << "/Release+Asserts/lib/ForestMeasure.so -meas_all < file-2.bc > file-3.bc"; systm(cmd.str().c_str()); if(cmd_option_bool("link_bc")){ // link cmd.str(""); cmd << "llvm-link -o=" << tmp_file("final.bc") << " " << base_path << "/lib/forest.a file-3.bc"; systm(cmd.str().c_str()); // from .bc to .s cmd.str(""); cmd << "llc final.bc -o final.s"; systm(cmd.str().c_str()); // From .s to .o cmd.str(""); cmd << "gcc -c final.s -o final.o"; systm(cmd.str().c_str()); // link cmd.str(""); cmd << "g++ final.o -lpthread -ldl -lrt -o " << output_file; systm(cmd.str().c_str()); } else { // From .bc to .s cmd.str(""); cmd << "llc file-3.bc -o file-3.s"; systm(cmd.str().c_str()); // from .s to .o cmd.str(""); cmd << "gcc -c file-3.s -o file-3.o"; systm(cmd.str().c_str()); // link cmd.str(""); cmd << "g++ file-3.o " << base_path << "/lib/forest.a -lpthread -ldl -lrt -o " << output_file; systm(cmd.str().c_str()); } }
void load_heuristics(){ ifstream input(tmp_file("heuristics").c_str()); string line; while( getline( input, line ) ) { if(line != "") heuristics.insert(line); } }
void ExternalAligner::align_seqs_impl(Strings& seqs) const { std::string input = tmp_file(); ASSERT_FALSE(input.empty()); std::string output = tmp_file(); ASSERT_FALSE(output.empty()); { boost::shared_ptr<std::ostream> file = name_to_ostream(input); std::ostream& out = *file; for (int i = 0; i < seqs.size(); i++) { write_fasta(out, TO_S(i), "", seqs[i], 60); } } align_file(input, output); Strings rows; read_alignment(rows, output); ASSERT_EQ(rows.size(), seqs.size()); seqs.swap(rows); if (!go("NPGE_DEBUG").as<bool>()) { remove_file(input); remove_file(output); } }
void TorrentPostHandler::post(HttpClientHandler* hdlr, const QHttpRequestHeader& hdr, const QByteArray& data) { const char* ptr = data.data(); int len = data.size(); int pos = QString(data).indexOf("\r\n\r\n"); if (pos == -1 || pos + 4 >= len) { HttpResponseHeader rhdr(500); server->setDefaultResponseHeaders(rhdr, "text/html", false); hdlr->send500(rhdr, i18n("Invalid data received")); return; } // save torrent to a temporary file QString save_file = kt::DataDir() + "webgui_load_torrent"; QFile tmp_file(save_file); if (!tmp_file.open(QIODevice::WriteOnly)) { HttpResponseHeader rhdr(500); server->setDefaultResponseHeaders(rhdr, "text/html", false); hdlr->send500(rhdr, i18n("Failed to open temporary file")); return; } QDataStream out(&tmp_file); out.writeRawData(ptr + (pos + 4), len - (pos + 4)); tmp_file.close(); Out(SYS_WEB | LOG_NOTICE) << "Loading file " << save_file << endl; core->loadSilently(KUrl(save_file), QString()); KUrl url; url.setEncodedPathAndQuery(hdr.path()); QString page = url.queryItem("page"); // there needs to be a page to send back if (page.isEmpty()) { server->redirectToLoginPage(hdlr); } else { // redirect to page mentioned in page parameter HttpResponseHeader rhdr(301); server->setDefaultResponseHeaders(rhdr, "text/html", true); rhdr.setValue("Location", "/" + page); hdlr->send(rhdr, QByteArray()); } }
void gen_file_free_variables_from_xml(){ vector<string> free_variables = cmd_option_string_vector("random_variable"); string filename; filename = tmp_file("free_variables"); FILE* file = fopen(filename.c_str(), "w"); for( vector<string>::iterator it = free_variables.begin(); it != free_variables.end(); it++ ){ fprintf(file, "%s\n", it->c_str() ); } fclose(file); }
void HttpServer::handleTorrentPost(HttpClientHandler* hdlr,const QHttpRequestHeader & hdr,const QByteArray & data) { const char* ptr = data.data(); Uint32 len = data.size(); int pos = QString(data).find("\r\n\r\n"); if (!session.logged_in || !checkSession(hdr)) { // You can't post torrents if you are not logged in // or the session is not OK redirectToLoginPage(hdlr); return; } if (pos == -1 || pos + 4 >= len || ptr[pos + 4] != 'd') { HttpResponseHeader rhdr(500); setDefaultResponseHeaders(rhdr,"text/html",false); hdlr->send500(rhdr); return; } // save torrent to a temporary file KTempFile tmp_file(locateLocal("tmp", "ktwebgui-"), ".torrent"); QDataStream* out = tmp_file.dataStream(); if (!out) { HttpResponseHeader rhdr(500); setDefaultResponseHeaders(rhdr,"text/html",false); hdlr->send500(rhdr); return; } out->writeRawBytes(ptr + (pos + 4),len - (pos + 4)); tmp_file.sync(); tmp_file.setAutoDelete(true); Out(SYS_WEB|LOG_NOTICE) << "Loading file " << tmp_file.name() << endl; core->loadSilently(KURL::fromPathOrURL(tmp_file.name())); handleGet(hdlr,hdr); }
void ui_menu_file_create::handle() { // process the menu const ui_menu_event *event = process(0); // process the event if (event != NULL) { // handle selections switch(event->iptkey) { case IPT_UI_SELECT: if ((event->itemref == ITEMREF_CREATE) || (event->itemref == ITEMREF_NEW_IMAGE_NAME)) { std::string tmp_file(m_filename_buffer); if (tmp_file.find(".") != -1 && tmp_file.find(".") < tmp_file.length() - 1) { m_current_file.append(m_filename_buffer); ui_menu::stack_pop(machine()); } else machine().ui().popup_time(1, "Please enter a file extension too"); } break; case IPT_SPECIAL: if (get_selection() == ITEMREF_NEW_IMAGE_NAME) { input_character( m_filename_buffer, ARRAY_LENGTH(m_filename_buffer), event->unichar, is_valid_filename_char); reset(UI_MENU_RESET_REMEMBER_POSITION); } break; case IPT_UI_CANCEL: *m_ok = false; break; } } }
int SMTPFileSystem::getattr(const char *path, struct stat *buf) { memset(buf, 0, sizeof(struct stat)); struct fuse_context *fc = fuse_get_context(); buf->st_uid = fc->uid; buf->st_gid = fc->gid; if (path == std::string("/")) { buf->st_mode = S_IFDIR | 0775; buf->st_nlink = 2; return 0; } else { std::string tmp_path(smtpfs_dirname(path)); std::string tmp_file(smtpfs_basename(path)); const TypeDir *content = m_device.dirFetchContent(tmp_path); if (!content) { return -ENOENT; } if (content->dir(tmp_file)) { const TypeDir *dir = content->dir(tmp_file); buf->st_ino = dir->id(); buf->st_mode = S_IFDIR | 0775; buf->st_nlink = 2; buf->st_mtime = dir->modificationDate(); } else if (content->file(tmp_file)) { const TypeFile *file = content->file(tmp_file); buf->st_ino = file->id(); buf->st_size = file->size(); buf->st_blocks = (file->size() / 512) + (file->size() % 512 > 0 ? 1 : 0); buf->st_nlink = 1; buf->st_mode = S_IFREG | 0644; buf->st_mtime = file->modificationDate(); buf->st_ctime = buf->st_mtime; buf->st_atime = buf->st_mtime; } else { return -ENOENT; } } return 0; }
// //////////////////////////////////////////////////////////////////////////// void LogHandlerFileBase::OpenFile(const char *base_name, const char *dir_name, const MLB::Utility::TimeT &start_time) { std::string file_name; if ((base_name == NULL) || (!(*base_name))) file_name = "LogFile."; else { file_name = base_name; if (base_name[strlen(base_name) - 1] != '.') file_name += '.'; } std::string tmp_date_time(start_time.ToString()); tmp_date_time[10] = '.'; tmp_date_time[13] = '.'; tmp_date_time[16] = '.'; file_name += tmp_date_time + "." + GetHostNameCanonical() + "." + AnyToString(CurrentProcessId()) + ".log"; boost::filesystem::path tmp_file(file_name, boost::filesystem::native); if ((dir_name != NULL) && *dir_name) { std::string tmp_dir_name; ResolveFilePathGeneral(dir_name, tmp_dir_name, "", true, true, false); boost::filesystem::path tmp_path(tmp_dir_name, boost::filesystem::native); boost::filesystem::path this_file; this_file = tmp_path / tmp_file; file_name = this_file.native_file_string(); } else { if (!tmp_file.has_root_path()) tmp_file = boost::filesystem::system_complete(tmp_file); file_name = tmp_file.native_file_string(); } OpenFile(file_name); }
//! Constructor lcp_wt(cache_config& config, std::string other_key="") { std::string temp_file = tmp_file(config, "_lcp_sml"); std::string lcp_key = conf::KEY_LCP; if ("" != other_key) { lcp_key = other_key; } int_vector_buffer<> lcp_buf(cache_file_name(lcp_key, config)); size_type l=0, max_l=0, big_sum=0, n = lcp_buf.size(); { int_vector<8> small_lcp = int_vector<8>(n); for (size_type i=0; i < n; ++i) { if ((l=lcp_buf[i]) < 255) { small_lcp[i] = l; } else { small_lcp[i] = 255; if (l > max_l) max_l = l; ++big_sum; } } store_to_file(small_lcp, temp_file); } { int_vector_buffer<8> lcp_sml_buf(temp_file); small_lcp_type tmp(lcp_sml_buf, lcp_sml_buf.size()); m_small_lcp.swap(tmp); } sdsl::remove(temp_file); m_big_lcp = int_vector<>(big_sum, 0, bits::hi(max_l)+1); { for (size_type i=0, ii=0; i < n; ++i) { if (lcp_buf[i] >= 255) { m_big_lcp[ ii++ ] = lcp_buf[i]; } } } }
void check_coverage(){ start_pass("check_coverage"); vector<string> coverages; coverages.push_back("fn"); coverages.push_back("bb"); for( vector<string>::iterator it = coverages.begin(); it != coverages.end(); it++ ){ string cov = *it; int expected_coverage = cmd_option_int("expected_" + cov + "_coverage"); stringstream cmd; // Show results of database cmd.str(""); if(get_project_path() != "") cmd << "cd " << get_project_path() << ";"; cmd << "echo 'select value from measurements where key = \"visited_" + cov + "s\";' | sqlite3 " << tmp_file("database.db"); FILE *fp; stringstream command; char ret[SIZE_STR]; vector<string> ret_vector; fp = popen(cmd.str().c_str(), "r"); while (fgets(ret,SIZE_STR, fp) != NULL) ret_vector.push_back(ret); pclose(fp); if(!ret_vector.size()){ printf("No coverage measurements\n"); exit(0); } //assert( ret_vector.size() && "No coverage measurements"); vector<string> tokens = tokenize( *(ret_vector.begin()), " "); string coverage_s = tokens[2]; int archived_coverage = stoi(coverage_s); string explanation = cmd_option_str("explanation") + " "; while( explanation.length() < 51 ) explanation = explanation + "."; printf("* Coverage of %s", explanation.c_str() ); if( archived_coverage < expected_coverage ) printf("\e[31m Less coverage than expected :( (%d < %d)\e[0m\n", archived_coverage, expected_coverage); if( archived_coverage > expected_coverage ) printf("\e[33m More coverage than expected :S (%d > %d)\e[0m\n", archived_coverage, expected_coverage); if( archived_coverage == expected_coverage ) printf("\e[32m Same coverage as expected :) (%d)\e[0m\n", archived_coverage); } end_pass("check_coverage"); }
void ui_menu_barcode_reader::handle() { // rebuild the menu (so to update the selected device, if the user has pressed L or R) reset(UI_MENU_RESET_REMEMBER_POSITION); populate(); // process the menu const ui_menu_event *event = process(UI_MENU_PROCESS_LR_REPEAT); // process the event if (event != NULL) { // handle selections switch (event->iptkey) { case IPT_UI_LEFT: if (event->itemref == ITEMREF_SELECT_READER) previous(); break; case IPT_UI_RIGHT: if (event->itemref == ITEMREF_SELECT_READER) next(); break; case IPT_UI_SELECT: if (event->itemref == ITEMREF_ENTER_BARCODE) { std::string tmp_file(m_barcode_buffer); //printf("code %s\n", m_barcode_buffer); if (!current_device()->is_valid(tmp_file.length())) machine().ui().popup_time(5, "Barcode length invalid!"); else { current_device()->write_code(tmp_file.c_str(), tmp_file.length()); // if sending was successful, reset char buffer if (m_barcode_buffer[0] != '\0') memset(m_barcode_buffer, '\0', ARRAY_LENGTH(m_barcode_buffer)); reset(UI_MENU_RESET_REMEMBER_POSITION); } } break; case IPT_SPECIAL: if (get_selection() == ITEMREF_NEW_BARCODE) { int buflen = strlen(m_barcode_buffer); // if it's a backspace and we can handle it, do so if ((event->unichar == 8 || event->unichar == 0x7f) && buflen > 0) *(char *)utf8_previous_char(&m_barcode_buffer[buflen]) = 0; else if (event->unichar >= '0' && event->unichar <= '9') { buflen += utf8_from_uchar(&m_barcode_buffer[buflen], ARRAY_LENGTH(m_barcode_buffer) - buflen, event->unichar); m_barcode_buffer[buflen] = 0; } reset(UI_MENU_RESET_REMEMBER_POSITION); } break; case IPT_UI_CANCEL: // reset the char buffer also in this case if (m_barcode_buffer[0] != '\0') memset(m_barcode_buffer, '\0', ARRAY_LENGTH(m_barcode_buffer)); break; } } }
void gen_file_vectors_random(){ string filename; filename = tmp_file("vectors"); FILE* file = fopen(filename.c_str(), "w"); vector<string> types; vector<string> names; vector<string> free_variables = cmd_option_string_vector("random_variable"); for( vector<string>::iterator it = free_variables.begin(); it != free_variables.end(); it++ ){ vector<string> tokens = tokenize(*it, " "); types.push_back(tokens[1]); names.push_back(tokens[0]); } map<string, string> distributions_map; vector<string> distributions = cmd_option_string_vector("distribution"); for( vector<string>::iterator it = distributions.begin(); it != distributions.end(); it++ ){ vector<string> tokens = tokenize(*it, " "); string distribution; for ( unsigned int i = 1; i < tokens.size(); i++) { distribution += " " + tokens[i]; } distributions_map[tokens[0]] = distribution; } for ( unsigned int i = 0; i < cmd_option_int("num_random_vectors"); i++) { for ( unsigned int j = 0; j < types.size(); j++) { string type = types[j]; string name = names[j]; if( type == "Int32" ){ fprintf(file, "%d ", (int)custom_random(name, distributions_map) ); } else if( type == "Int16" ){ fprintf(file, "%d ", (short)custom_random(name, distributions_map) ); } else if( type == "Int8"){ fprintf(file, "%d ", (char)custom_random(name, distributions_map) ); } else { assert(0 && "Unknown type"); } } fprintf(file, "\n"); } fclose(file); }
void plotE_L(TString file_name="test_gamma.root"){ gROOT->Reset(); // Draw histos filled by Geant4 simulation TCanvas* c1 = new TCanvas("c1", " "); TString tmp_file(file_name); Int_t bins = 4096; TH1D *h1 = new TH1D("1.33MeV Gamma Spectrum","1.33MeV Gamma Spectrum",bins,0.,1.5); TH1D *h2 = new TH1D("e1.33MeV Gamma length","e1.33MeV Gamma length",bins,0.,250.); TH2D *h3 = new TH2D("e1.33MeV Gamma","e1.33MeV Gamma",bins,0.,1.5,bins,0.,250.); TFile f(tmp_file.Data()); if(f.IsOpen()) { TTree *t1; f.GetObject("ntuple/test",t1); Int_t entrise = t1->GetEntries(); Double_t e_e; Double_t l_e; Double_t energy_tmp=0.0; Int_t number=0; t1->SetBranchAddress("e_g",&e_e); t1->SetBranchAddress("l_g",&l_e); for(int j=0; j<entrise; j++) { t1->GetEntry(j); if(e_e>1.E-5) { if(energy_tmp<e_e) energy_tmp=e_e; number++; } h1->Fill(fun_unfold_gause(e_e)); h2->Fill(l_e); h3->Fill(e_e,l_e); } } tmp_file.Clear(); f.Close(); TH1D* hist1; f.GetObject("histo/1;1",hist1); c1->Divide(1,3); c1->cd(1); h1->SetTitle("1.332MeV gamma spectrum"); h1->GetXaxis()->CenterTitle(true); h1->GetYaxis()->CenterTitle(true); h1->GetXaxis()->SetTitle("energy /MeV"); h1->GetYaxis()->SetTitle("Count"); gPad->SetLogy(1); h1->Draw(); double xxx=GetRateOfPeakComputom(h1); double kkk=0; kkk=h1->GetBinContent(h1->FindFixBin(1.332)); printf("coputom:%lf\tPeak:%lf\tPeakComputom:%lf\n",xxx,kkk,kkk/xxx); c1->cd(2); h2->SetTitle("1.332MeV gamma length"); h2->GetXaxis()->CenterTitle(true); h2->GetYaxis()->CenterTitle(true); h2->GetXaxis()->SetTitle("length /mm"); h2->GetYaxis()->SetTitle("Count"); h2->Draw(); c1->cd(3); h3->SetTitle("1.332MeV gamma energy_length histo"); h3->GetXaxis()->CenterTitle(true); h3->GetYaxis()->CenterTitle(true); h3->GetXaxis()->SetTitle("energy /MeV"); h3->GetYaxis()->SetTitle("length/mm"); h3->Draw("FB"); c1->cd(); plot_FWHM(); }
/** * Load a pointcloud from a pcd file. * Checks whether the .pcd has padding after the header, and removes it it if needed. * (binary PCD files in versions < 1.0 required padding, PCL >= version 1.0 does not) * @param filename pcd file to load * @param cloud pointer to which the loaded cloud is written * @return 0 for success, != 0 otherwise **/ int read_binary_PCL(const std::string& filename, PointCloud::Ptr cloud) { std::ifstream in_file(filename.c_str()); std::string token("DATA binary\n"); const size_t BUFFER_SIZE = 4096; char buffer[BUFFER_SIZE]; in_file.read(buffer, BUFFER_SIZE); if (in_file.gcount() < BUFFER_SIZE) { std::cerr << "could not read whole file" << std::endl; return -1; } bool null_after_header = false; size_t matched_chars = 0; size_t header_length = 0; for(size_t i=0; i<BUFFER_SIZE; i++) { if (buffer[i] == token[matched_chars]) { matched_chars++; } else matched_chars = 0; if (matched_chars == token.length()) { header_length = i; size_t num_nulls = 0; for(size_t j=header_length+1; j<BUFFER_SIZE; j++) { if (buffer[j] == '\0') num_nulls++; else break; } null_after_header = num_nulls > 10; if (null_after_header) { std::cout << "null bytes found after header, converting from old PCD binary format" << std::endl; } break; } } std::string tmp_filename; int temp_file_fd; if (null_after_header) { char tmp_name[] = "/tmp/pcd_file_XXXXXX"; temp_file_fd = mkstemp(tmp_name); if (temp_file_fd < 0) { std::cerr << "could not create temporary file" << std::endl; return -1; } tmp_filename = tmp_name; std::ofstream tmp_file(tmp_filename.c_str()); tmp_file.write(buffer, header_length+1); in_file.seekg(4096, std::ios::beg); while(in_file.good()) { in_file.read(buffer, BUFFER_SIZE); tmp_file.write(buffer, in_file.gcount()); } in_file.close(); tmp_file.close(); pcl::io::loadPCDFile(tmp_filename, *cloud); remove(tmp_filename.c_str()); } else { in_file.close(); // just load it pcl::io::loadPCDFile(filename, *cloud); } return 0; }
int main(int argc, char *argv[]) { QApplication::setApplicationName("SubutaiTray"); QApplication::setOrganizationName("subut.ai"); QApplication app(argc, argv); QCommandLineParser cmd_parser; cmd_parser.setApplicationDescription("This tray application should help users to work with hub"); QCommandLineOption log_level_opt("l", "Log level can be TRACE (0), INFO (1) and ERROR (2). Trace is most detailed logs.", "log_level", "ERROR"); QCommandLineOption version_opt("v", "Version", "Version"); cmd_parser.addOption(log_level_opt); cmd_parser.addPositionalArgument("log_level", "Log level to use in this application"); cmd_parser.addOption(version_opt); cmd_parser.addHelpOption(); cmd_parser.parse(QApplication::arguments()); CApplicationLog::Instance()->SetDirectory(QApplication::applicationDirPath().toStdString().c_str()); QString ll = cmd_parser.value(log_level_opt).toLower().trimmed(); if(ll == "trace" || ll == "0") CApplicationLog::Instance()->SetLogLevel(CApplicationLog::LT_TRACE); else if (ll == "info" || ll == "1") CApplicationLog::Instance()->SetLogLevel(CApplicationLog::LT_INFO); else if (ll == "error" || ll == "2") CApplicationLog::Instance()->SetLogLevel(CApplicationLog::LT_ERROR); if (cmd_parser.isSet(version_opt)) { std::cout << GIT_VERSION << std::endl; return 0; } CApplicationLog::Instance()->LogTrace("Tray application %s launched\n", GIT_VERSION); app.setQuitOnLastWindowClosed(false); qRegisterMetaType<com::Bstr>("com::Bstr"); QString tmp_file_path = CCommons::AppNameTmp(); QFile tmp_file(tmp_file_path); if (tmp_file.exists()) { if (!tmp_file.remove()) { CApplicationLog::Instance()->LogError("Couldn't remove file %s", tmp_file_path.toStdString().c_str()); } } DlgLogin dlg; dlg.setModal(true); dlg.exec(); if (dlg.result() == QDialog::Rejected) return 0; CTrayServer::Instance()->Init(); CVBoxManagerSingleton::Instance()->init_com(); TrayControlWindow tcw; return app.exec(); }
void menu_barcode_reader::handle() { // rebuild the menu (so to update the selected device, if the user has pressed L or R) reset(reset_options::REMEMBER_POSITION); populate(); // process the menu const event *event = process(PROCESS_LR_REPEAT); // process the event if (event) { // handle selections switch (event->iptkey) { case IPT_UI_LEFT: if (event->itemref == ITEMREF_SELECT_READER) previous(); break; case IPT_UI_RIGHT: if (event->itemref == ITEMREF_SELECT_READER) next(); break; case IPT_UI_SELECT: if (event->itemref == ITEMREF_ENTER_BARCODE) { std::string tmp_file(m_barcode_buffer); //printf("code %s\n", m_barcode_buffer); if (!current_device()->is_valid(tmp_file.length())) ui().popup_time(5, "%s", _("Barcode length invalid!")); else { current_device()->write_code(tmp_file.c_str(), tmp_file.length()); // if sending was successful, reset char buffer if (m_barcode_buffer[0] != '\0') memset(m_barcode_buffer, '\0', ARRAY_LENGTH(m_barcode_buffer)); reset(reset_options::REMEMBER_POSITION); } } break; case IPT_SPECIAL: if (get_selection_ref() == ITEMREF_NEW_BARCODE) { auto const buflen = std::strlen(m_barcode_buffer); // if it's a backspace and we can handle it, do so if ((event->unichar == 8) || (event->unichar == 0x7f)) { if (0 < buflen) *const_cast<char *>(utf8_previous_char(&m_barcode_buffer[buflen])) = 0; } else if ((event->unichar >= '0') && (event->unichar <= '9')) { event->append_char(m_barcode_buffer, buflen); } reset(reset_options::REMEMBER_POSITION); } break; case IPT_UI_CANCEL: // reset the char buffer also in this case if (m_barcode_buffer[0] != '\0') memset(m_barcode_buffer, '\0', ARRAY_LENGTH(m_barcode_buffer)); break; } } }
fs::path JobDir::deliver( std::string const& contents, std::string const& tag ) { pt::ptime t = universal_time(); std::string file_name(to_iso_string(t)); assert( file_name.size() == 15 || file_name.size() == (unsigned)16 + pt::time_duration::num_fractional_digits() ); if (file_name.size() == 15) { // without fractional seconds file_name += '.'; file_name += std::string(pt::time_duration::num_fractional_digits(), '0'); } file_name += '_'; file_name += m_impl->id_str; if (!tag.empty()) { file_name += '_'; file_name += tag; } fs::path const file(file_name, fs::native); fs::path tmp_path; fs::path new_path; try { tmp_path = m_impl->tmp_dir / file; new_path = m_impl->new_dir / file; } catch (boost::filesystem::filesystem_error const& e) { throw JobDirError(e.what()); } fs::ofstream tmp_file(tmp_path); if (!tmp_file) { std::string msg("create failed for "); msg += tmp_path.string(); msg += " (" + boost::lexical_cast<std::string>(errno) + ')'; throw JobDirError(msg); } tmp_file << contents << std::flush; if (!tmp_file) { std::string msg("write failed for "); msg += tmp_path.string(); msg += " (" + boost::lexical_cast<std::string>(errno) + ')'; throw JobDirError(msg); } tmp_file.close(); // sync too? yes, rename doesn't sync (TODO) bool e = std::rename(tmp_path.string().c_str(), new_path.string().c_str()); if (e) { std::string msg("rename failed for "); msg += tmp_path.string(); msg += " (" + boost::lexical_cast<std::string>(errno) + ')'; throw JobDirError(msg); } return new_path; }