コード例 #1
0
ファイル: Logger.cpp プロジェクト: AllenWangxiao/winner
	void Logger::printv(const char* fmt, va_list vl){
		// prepare out
		FILE* out =stdout;
		if(m_szName){
			_open_file();
			if(m_file){
				out =m_file;
			}
		}
		// out
		vfprintf(out, fmt, vl);

		// try flush
		if((FLUSH_MODE_FLUSH==m_flush_mode) || (m_log_count_before_flush>=FLUSH_THRESHOLD)){
			fflush(out);
			m_flush_last_time =DateTime::Now();
			m_log_count_before_flush =0;
		}
		else{
			const int64_t now =DateTime::Now();
			if(now-m_flush_last_time >= FLUSH_TIMER){
				fflush(out);
				m_flush_last_time =now;
				m_log_count_before_flush =0;
			}
			else{
				++m_log_count_before_flush;
			}
		}
		ASSERT(out);
	}
コード例 #2
0
ファイル: phillip.cpp プロジェクト: disooqi/phillip
void phillip_main_t::execute_convertor(
    ilp::ilp_problem_t **out_ilp, duration_time_t *out_time,
    const std::string &path_out_xml)
{
    IF_VERBOSE_2("Converting LHS into linear-programming-problems...");

    auto begin = std::chrono::system_clock::now();
    (*out_ilp) = m_ilp_convertor->execute();
    (*out_time) = util::duration_time(begin);

    IF_VERBOSE_2(
        m_ilp->has_timed_out() ?
        "Interrupted convertion into linear-programming-problems." :
        "Completed convertion into linear-programming-problems.");

    if (not path_out_xml.empty())
    {
        std::ios::openmode mode = std::ios::out | std::ios::app;
        std::ofstream *fo = _open_file(path_out_xml, mode);
        if (fo != NULL)
        {
            m_ilp->print(fo);
            delete fo;
        }
    }
}
コード例 #3
0
ファイル: phillip.cpp プロジェクト: disooqi/phillip
void phillip_main_t::execute_solver(
    std::vector<ilp::ilp_solution_t> *out_sols,
    duration_time_t *out_time,
    const std::string &path_out_xml)
{
    IF_VERBOSE_2("Solving...");

    auto begin = std::chrono::system_clock::now();
    m_ilp_solver->execute(out_sols);
    (*out_time) = util::duration_time(begin);

    IF_VERBOSE_2("Completed inference.");

    if (not path_out_xml.empty())
    {
        std::ios::openmode mode = std::ios::out | std::ios::app;
        std::ofstream *fo = _open_file(path_out_xml, mode);
        if (fo != NULL)
        {
            for (auto sol = m_sol.begin(); sol != m_sol.end(); ++sol)
                sol->print(fo);
            delete fo;
        }
    }
}
コード例 #4
0
ファイル: phillip.cpp プロジェクト: disooqi/phillip
void phillip_main_t::execute_enumerator(
    pg::proof_graph_t **out_lhs, duration_time_t *out_time,
    const std::string &path_out_xml)
{
    IF_VERBOSE_2("Generating latent-hypotheses-set...");

    if ((*out_lhs) != NULL) delete m_lhs;

    auto begin = std::chrono::system_clock::now();
    (*out_lhs) = m_lhs_enumerator->execute();
    (*out_time) = util::duration_time(begin);

    IF_VERBOSE_2(
        m_lhs->has_timed_out() ?
        "Interrupted generating latent-hypotheses-set." :
        "Completed generating latent-hypotheses-set.");

    if (not path_out_xml.empty())
    {       
        std::ios::openmode mode = std::ios::out | std::ios::app;
        std::ofstream *fo = _open_file(path_out_xml, mode);
        if (fo != NULL)
        {
            m_lhs->print(fo);
            delete fo;
        }
    }
}
コード例 #5
0
ファイル: mainwindow.cpp プロジェクト: WatsonBauer/LimiEditor
void MainWindow::_direct_Open()
{
    QString fileName = QFileDialog::getOpenFileName( this, ui->action_Open->whatsThis(),
                                                     _fileName, ui->menu_File->whatsThis() );
    if ( ! fileName.isEmpty() )
        _open_file( fileName );
}
コード例 #6
0
ファイル: ebook.c プロジェクト: WangDongfang/DfewOS
/*==============================================================================
 * - _ebook_cb_read()
 *
 * - start read a file. when user [release] a [*.txt] file icon, call this
 */
static OS_STATUS _ebook_cb_read (GUI_CBI *pCBI_file, GUI_COOR *pCoor)
{
    GUI_COOR left_up = {EBOOK_START_X, 0};
    GUI_SIZE size = {0, 0};

    /* restore the frame */
    cbf_default_release(pCBI_file, pCoor);

    /* open file */
    if (_open_file (pCBI_file->name) == OS_STATUS_ERROR) {
        msg_box_create ("Open file failed!");
        return OS_STATUS_ERROR;
    }
    
    /* show middle fb */
    gra_set_show_fb (1);

    /* create & register 'ebook' cbi */
    _G_pCBI_ebook = cbi_create_default (EBOOK_BG_PIC, &left_up, &size, TRUE);
    _G_pCBI_ebook->left_up.x    -= EBOOK_START_X;
    _G_pCBI_ebook->right_down.x -= EBOOK_START_X;
    _G_pCBI_ebook->func_release = _ebook_cb_page;
    cbi_register (_G_pCBI_ebook);

    /* show page 0 */
    _show_page (PAGE_HOME);

    return OS_STATUS_OK;
}
コード例 #7
0
ファイル: Logger.cpp プロジェクト: AllenWangxiao/winner
	/** query **/
	void Logger::setName(String* name){
		ASSIGN_POINTER(m_szName, name);
		if(m_file){
			fclose(m_file);
			m_file =0;
			m_file_open_time =0;
		}
		if(m_szName){
			_open_file();
		}
	}
コード例 #8
0
ファイル: left_redirection.c プロジェクト: NegMozzie/42sh
int		left_redirection(t_tree *tree, t_shell *st_shell)
{
  int		fd;
  char		**args;

  args = tree->right->args;
  if (!args || !args[0] || (fd = _open_file(args[0])) == -1)
    return (EXIT_FAILURE);
  set_fd_in(tree->left, fd);
  return (execute_it(tree->left, st_shell));
}
コード例 #9
0
ファイル: fileiodevice.cpp プロジェクト: karagog/gutil
void FileIODevice::send_data(const QByteArray &data)
{
    lock_file(true);
    _open_file(true);

    // At this point the settings file is ours for sole writing
    QT_IODevice::send_data(data);

    _close_file();
    unlock_file();
}
コード例 #10
0
ファイル: phillip.cpp プロジェクト: disooqi/phillip
void phillip_main_t::learn(const lf::input_t &input)
{
    auto get_path_for_gold = [this](const std::string &key) -> std::string
    {
        std::string path = param(key);
        if (not path.empty())
        {
            int idx = path.rfind('.');
            if (idx > 0)
                path = path.substr(0, idx) + ".gold" + path.substr(idx);
            else
                path += ".gold";
        }
        return path;
    };

    reset_for_inference();
    set_input(input);

    auto begin = std::chrono::system_clock::now();

    erase_flag("get_pseudo_positive");

    execute_enumerator();
    execute_convertor();
    execute_solver();

    set_flag("get_pseudo_positive");

    execute_convertor(
        &m_ilp_gold, &m_time_for_convert_gold,
        get_path_for_gold("path_ilp_out"));
    execute_solver(
        &m_sol_gold, &m_time_for_solve_gold,
        get_path_for_gold("path_sol_out"));

    util::xml_element_t elem("learn", "");
    m_ilp_convertor->tune(m_sol.front(), m_sol_gold.front(), &elem);

    m_time_for_learn = util::duration_time(begin);

    std::ofstream *fo(NULL);
    if ((fo = _open_file(param("path_out"), std::ios::out | std::ios::app)) != NULL)
    {
        if (not flag("omit_proof_graph_from_xml"))
        {
            m_sol.front().print_graph(fo);
            m_sol_gold.front().print_graph(fo);
        }
        elem.print(fo);
        delete fo;
    }
}
コード例 #11
0
ファイル: left_redirection.c プロジェクト: NegMozzie/42sh
int		spe_left(t_tree *tree, t_shell *st_shell)
{
  int		fd;
  char		**args;

  (void)st_shell;
  args = tree->right->args;
  if (!args || !args[0] || (fd = _open_file(args[0])) == -1)
    return (EXIT_FAILURE);
  set_fd_in(tree->left, fd);
  return (EXIT_SUCCESS);
}
コード例 #12
0
ファイル: fileiodevice.cpp プロジェクト: karagog/gutil
QByteArray FileIODevice::receive_data()
{
    lock_file(false);
    _open_file(false);

    QByteArray ret = QT_IODevice::receive_data();

    _close_file();
    unlock_file();

    _last_update_time = QFileInfo(FileName()).lastModified();

    return ret;
}
コード例 #13
0
ファイル: right_redirection.c プロジェクト: NegMozzie/42sh
int		execute_right_redir_spe(t_tree *tree, t_shell *st_shell)
{
  int		fd;
  t_tree	*file;
  t_tree	*cmd;

  file = tree->right;
  cmd = tree->left;
  if (!file || !cmd)
    return (EXIT_FAILURE);
  if ((fd = _open_file(file->args[0], tree->type)) == -1)
    return (EXIT_FAILURE);
  set_fd_out(cmd, fd);
  return (execute_last_command(tree->left, st_shell));
}
コード例 #14
0
ファイル: right_redirection.c プロジェクト: NegMozzie/42sh
int		right_redirection(t_tree *tree, t_shell *st_shell)
{
  int		fd;
  t_tree	*file;
  t_tree	*cmd;

  file = tree->right;
  cmd = tree->left;
  if (!file || !cmd)
    return (FATAL_ERROR);
  if ((fd = _open_file(tree->right->args[0], tree->type)) == -1)
    return (EXIT_FAILURE);
  set_fd_out(tree->left, fd);
  return (execute_it(tree->left, st_shell));
}
コード例 #15
0
ファイル: cm.cpp プロジェクト: SeTriones/56wlk
int ts_cm_t::init(const char *path, const char *file)
{
    char namebuf[TS_FILEPATH_MAXSIZE];
    snprintf(namebuf, sizeof(namebuf), "%s/%s%s", path, file, CM_SUFFIX_I2O);
    int fd = _open_file(namebuf, O_CREAT | O_RDWR);
    if(fd <= 0)
    {
        return -1;
    }
    i2o_fd = fd;

    snprintf(namebuf, sizeof(namebuf), "%s/%s%s", path, file, CM_SUFFIX_O2I);
    fd = _open_file(namebuf, O_CREAT | O_RDWR);
    if(fd <= 0)
    {
        return -2;
    }
    o2i_fd = fd;

    snprintf(namebuf, sizeof(namebuf), "%s/%s%s", path, file, CM_SUFFIX_FLAG);
    flag_fp = fopen(namebuf, "r+");
    if(NULL == flag_fp)
    {
        return -3;
    }
    int ret = fscanf(flag_fp, "%u : %u\n", &i_max, &o_max);
    if(2 != ret)
    {
        return -4;
    }
    ///先填充id=0的位置
    i_max = (i_max == 0) ? 1 : i_max;
    o_max = (o_max == 0) ? 1 : o_max;

    return 0;
}
コード例 #16
0
ファイル: mainwindow.cpp プロジェクト: WatsonBauer/LimiEditor
void MainWindow::dropEvent( QDropEvent *event )
{
    QList<QUrl> urls = event->mimeData()->urls();
    if ( urls.isEmpty() )
        return;

    QString fileName = urls.first().toLocalFile();
    if ( fileName.isEmpty() )
        return;

    int ret;
    if ( ui->textEdit->document()->isModified() )
        ret = _Save_query();

    if ( ret != QMessageBox::Cancel )
        _open_file( fileName );
}
コード例 #17
0
ファイル: Master.cpp プロジェクト: belldandyxtq/burstbuffer
int Master::_parse_open_file(int clientfd, std::string& ip)
{
	char *file_path;
	fprintf(stderr, "request for open file, ip=%s\n", ip.c_str()); 
	Recvv(clientfd, &file_path); 
	int flag ,ret=SUCCESS;
	Recv(clientfd, flag); 
	try
	{
		ssize_t file_no;
		_open_file(file_path, flag, file_no); 
		size_t size=_buffered_files.at(file_no).size;
		delete file_path; 
		Send(clientfd, SUCCESS);
		Send(clientfd, file_no);
		Send(clientfd, size);
		/*Send(clientfd, static_cast<int>(nodes.size()));
		for(node_t::const_iterator it=nodes.begin(); it!=nodes.end(); ++it)
		{
			Send(clientfd, it->first);
			std::string ip=_registed_IOnodes.at(it->second).ip;
			Sendv(clientfd, ip.c_str(),ip.size());
		}*/
	}
	catch(std::runtime_error &e)
	{
		fprintf(stderr, "%s\n",e.what());
		Send(clientfd, UNKNOWN_ERROR);
		ret=FAILURE;
	}
	catch(std::invalid_argument &e)
	{
		fprintf(stderr, "%s\n",e.what());
		Send(clientfd, FILE_NOT_FOUND);
		ret=FAILURE;
	}
	catch(std::bad_alloc &e)
	{
		Send(clientfd, TOO_MANY_FILES);
		ret=FAILURE;
	}
	close(clientfd);
	return ret;
}
コード例 #18
0
ファイル: phillip.cpp プロジェクト: disooqi/phillip
void phillip_main_t::infer(const lf::input_t &input)
{
    reset_for_inference();
    set_input(input);

    auto begin = std::chrono::system_clock::now();

    execute_enumerator();
    execute_convertor();
    execute_solver();

    m_time_for_infer = util::duration_time(begin);

    std::ofstream *fo(NULL);
    if ((fo = _open_file(param("path_out"), std::ios::out | std::ios::app)) != NULL)
    {
        for (auto sol = m_sol.begin(); sol != m_sol.end(); ++sol)
            sol->print_graph(fo);
        delete fo;
    }
}
コード例 #19
0
ファイル: phillip.cpp プロジェクト: disooqi/phillip
void phillip_main_t::write_footer() const
{
    auto write = [this](std::ostream *os)
    {
        (*os) << "</phillip>" << std::endl;
    };
    auto f_write = [&](const std::string &key)
    {
        std::ofstream *fo(NULL);
        if ((fo = _open_file(param(key), (std::ios::out | std::ios::app))) != NULL)
        {
            write(fo);
            delete fo;
        }
    };

    f_write("path_lhs_out");
    f_write("path_ilp_out");
    f_write("path_sol_out");
    f_write("path_out");
    write(&std::cout);
}
コード例 #20
0
ファイル: phillip.cpp プロジェクト: disooqi/phillip
void phillip_main_t::write_header() const
{
    auto write = [this](std::ostream *os)
    {
        (*os) << "<phillip>" << std::endl;
        (*os) << "<configure>" << std::endl;
        (*os) << "<version>" << VERSION << "</version>" << std::endl;

        auto get_time_stamp_exe = []() -> std::string
        {
            int year, month, day, hour, min, sec;
            std::string out;
            util::beginning_time(&year, &month, &day, &hour, &min, &sec);
            switch (month)
            {
            case 1:  out = "Jan"; break;
            case 2:  out = "Feb"; break;
            case 3:  out = "Mar"; break;
            case 4:  out = "Apr"; break;
            case 5:  out = "May"; break;
            case 6:  out = "Jun"; break;
            case 7:  out = "Jul"; break;
            case 8:  out = "Aug"; break;
            case 9:  out = "Sep"; break;
            case 10: out = "Oct"; break;
            case 11: out = "Nov"; break;
            case 12: out = "Dec"; break;
            default: throw;
            }
            return out + util::format(" %2d %4d %02d:%02d:%02d", day, year, hour, min, sec);
        };
        
        (*os)
            << "<time_stamp compiled=\"" << util::format("%s %s", __DATE__, __TIME__)
            << "\" executed=\"" << get_time_stamp_exe()
            << "\"></time_stamp>" << std::endl;

        (*os)
            << "<components lhs=\"" << m_lhs_enumerator->repr()
            << "\" ilp=\"" << m_ilp_convertor->repr()
            << "\" sol=\"" << m_ilp_solver->repr()
            << "\"></components>" << std::endl;

        const kb::knowledge_base_t *base = kb::knowledge_base_t::instance();
        (*os)
            << "<knowledge_base path=\"" << base->filename()
            << "\" size=\"" << base->num_of_axioms()
            << "\" max_distance=\"" << base->get_max_distance()
            << "\"></knowledge_base>" << std::endl;

        (*os)
            << "<params timeout_lhs=\"" << timeout_lhs().get()
            << "\" timeout_ilp=\"" << timeout_ilp().get()
            << "\" timeout_sol=\"" << timeout_sol().get()
            << "\" timeout_all=\"" << timeout_all().get()
            << "\" verbose=\"" << verbose();

        for (auto it = m_params.begin(); it != m_params.end(); ++it)
            (*os) << "\" " << it->first << "=\"" << it->second;

        for (auto it = m_flags.begin(); it != m_flags.end(); ++it)
            (*os) << "\" " << (*it) << "=\"yes";

#ifdef DISABLE_CANCELING
        (*os) << "\" disable_canceling=\"yes";
#endif

#ifdef DISABLE_HARD_TERM
        (*os) << "\" disable_hard_term=\"yes";
#endif

        (*os) << "\"></params>" << std::endl;

        (*os) << "</configure>" << std::endl;
    };

    auto f_write = [&](const std::string &key)
    {
        std::ofstream *fo(NULL);
        if ((fo = _open_file(param(key), (std::ios::out | std::ios::trunc))) != NULL)
        {
            write(fo);
            delete fo;
        }
    };

    f_write("path_lhs_out");
    f_write("path_ilp_out");
    f_write("path_sol_out");
    f_write("path_out");
    write(&std::cout);
}
コード例 #21
0
ファイル: Logger.cpp プロジェクト: AllenWangxiao/winner
	void Logger::logv(const int64_t lv, const char* fmt, va_list vl){
		if(lv < m_level) return;
		// prepare out
		FILE* out =stdout;
		if(m_szName){
			_open_file();
			if(m_file){
				out =m_file;
			}
		}

		// tm
		struct tm t;
		int microsecs =0;
		struct timeval tv;
		if(0 == gettimeofday(&tv, 0)){
			if(struct tm* tmp =localtime_r(&tv.tv_sec, &t)){
				t =*tmp;
				microsecs =tv.tv_usec;
			}
			else{
				memset(&t, 0, sizeof(t));
			}
		}
		else{
			memset(&t, 0, sizeof(t));
		}

		// out
		const char* tag =0;
		switch(lv){
		case Logger::INFO:
			tag ="INFO "; break;
		case Logger::WARN:
			tag ="WARN "; break;
		case Logger::ERROR:
			tag ="ERROR"; break;
		case Logger::FATAL:
			tag ="FATAL"; break;
		case Logger::DEBUG:
			tag ="DEBUG"; break;
		}
		if(tag){
			fprintf(out, "[%04d-%02d-%02d %02d:%02d:%02d.%06d] %s > ", t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, microsecs, tag);
		}
		else{
			fprintf(out, "[%04d-%02d-%02d %02d:%02d:%02d.%06d] %.5lld > ", t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, microsecs, (long long)lv);
		}

		/*
		char x[1024] ={0};
		vsprintf(x, fmt, vl);
		if(strcmp(x, "fail to call a1, arg test invalid") == 0){
			ASSERT(0);
		}
		*/
		vfprintf(out, fmt, vl);
		fprintf(out, "\n");
		if(FLUSH_MODE_FLUSH == m_flush_mode){
			fflush(out);
		}
	}
//-----------------------------------------------------------------------------
// fopen: Open or Create a file for reading or writing
//-----------------------------------------------------------------------------
void* fl_fopen(const char *path, const char *mode)
{
	int i;
	FL_FILE* file; 
	unsigned char flags = 0;

	// If first call to library, initialise
	CHECK_FL_INIT();

	if (!_filelib_valid)
		return NULL;

	if (!path || !mode)
		return NULL;
		
	// Supported Modes:
	// "r" Open a file for reading. The file must exist. 
	// "w" Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.  
	// "a" Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist. 
	// "r+" Open a file for update both reading and writing. The file must exist. 
	// "w+" Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file. 
	// "a+" Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist. 

	for (i=0;i<(int)strlen(mode);i++)
	{
		switch (tolower(mode[i]))
		{
		case 'r':
			flags |= FILE_READ;
			break;
		case 'w':
			flags |= FILE_WRITE;
			flags |= FILE_ERASE;
			flags |= FILE_CREATE;
			break;
		case 'a':
			flags |= FILE_WRITE;
			flags |= FILE_APPEND;
			flags |= FILE_CREATE;
			break;
		case '+':
			if (flags & FILE_READ)
				flags |= FILE_WRITE;
			else if (flags & FILE_WRITE)
			{
				flags |= FILE_READ;
				flags |= FILE_ERASE;
				flags |= FILE_CREATE;
			}
			else if (flags & FILE_APPEND)
			{
				flags |= FILE_READ;
				flags |= FILE_WRITE;
				flags |= FILE_APPEND;
				flags |= FILE_CREATE;
			}
			break;
		case 'b':
			flags |= FILE_BINARY;
			break;
		}
	}
	
	file = NULL;

#ifndef FATFS_INC_WRITE_SUPPORT
	// No write support!
	flags &= ~(FILE_CREATE | FILE_WRITE | FILE_APPEND);
#endif

	// No write access - remove write/modify flags
	if (!_fs.disk_io.write_sector)
		flags &= ~(FILE_CREATE | FILE_WRITE | FILE_APPEND);

	FL_LOCK(&_fs);

	// Read
	file = _open_file(path);
	//if (!(flags & FILE_READ))
	//	_free_file(file);

	// Create New
#ifdef FATFS_INC_WRITE_SUPPORT

	// Remove old file
    if(flags & FILE_ERASE)
	{
	   fl_remove(path);

	   if(file)
	   	  _free_file(file);
	}

	if (!file && (flags & FILE_CREATE))
		file = _create_file(path);
#endif

	// Write Existing (and not open due to read or create)
	//if (!(flags & FILE_READ))
	//	if (!(flags & FILE_CREATE))
	//		if (flags & (FILE_WRITE | FILE_APPEND))
	//			file = _open_file(path);

	if (file)
		file->flags = flags;

	FL_UNLOCK(&_fs);
	return file;	
}