示例#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);
    }
示例#2
0
文件: utils.c 项目: yuejoo/APEUFinal
char* display_prompt(){


	if( gethostname(hostname,HOST_NAME_MAX) != SUCCESS)
		stdErr("Can not get the host name");

	/* hostuser to get both username and the pwd */
	if( (hostuser = getpwuid(getuid()))  == NULL)
		stdErr("Can not get the user info");

	if( getcwd(pwd, PATH_MAX) == NULL)
		stdErr("Can not get the current path");

	checkHomeDir(pwd);
	setenv("SHELL", pwd, 1);

	int lenth = strlen(hostuser->pw_name)+strlen(pwd)+9;
	char *out;

	if((out = (char*)malloc(lenth)) == NULL)
		stdErr("Can not allocate space");
	strcpy(out, hostuser->pw_name);
	strcat(out, "@sish:");
	strcat(out, pwd);
	strcat(out, "$ ");

	return out;
}
示例#3
0
    void bomAdd(const FileUnit& file)
    {
        bf::ifstream strm;
        const auto result=bomUtf8Check(file, strm);
        if(strm.is_open()==false)
            return;

        if(result.second==false)
        {
            stdErr() << "utf8-invalid: " << file.total << std::endl;
            return;
        }

        if(result.first==true)
        {
            stdErr() << "utf8-BOM: " << file.total << std::endl;
            return;
        }

        strm.seekg(0);

        auto newFile=file.total;
        newFile += pathCreate(".new");
        bf::ofstream out(newFile);
        out.write(reinterpret_cast<const char*>(utf8::bom), sizeof(utf8::bom));
        std::copy(std::istreambuf_iterator<char>(strm), std::istreambuf_iterator<char>(), std::ostreambuf_iterator<char>(out));
        bf::rename(newFile, file.total);
    }
示例#4
0
    void bomRemove(const FileUnit& file)
    {
        bf::ifstream strm;
        const auto result=bomUtf8Check(file, strm);
        if(strm.is_open()==false)
            return;

        if(result.second==false)
        {
            stdErr() << "utf8-invalid: " << file.total << std::endl;
            return;
        }

        if(result.first==false)
        {
            stdErr() << "utf8-no-BOM: " << file.total << std::endl;
            return;
        }

        strm.seekg(3);

        auto newFile=file.total;
        newFile += pathCreate(".new");
        bf::ofstream out(newFile);
        std::copy(std::istreambuf_iterator<char>(strm), std::istreambuf_iterator<char>(), std::ostreambuf_iterator<char>(out));
        bf::rename(newFile, file.total);
    }
示例#5
0
文件: manviever.cpp 项目: merlok/Hyde
manViever::manViever(QWidget *parent)
    : QWidget(parent)
{
    lneSearch = new QLineEdit;
    lneSearch->setText("");
    txtMan = new QTextEdit;
    txtMan->setText("");
    txtMan->setReadOnly(true);
    btnSearch = new QPushButton;
    btnSearch->setText("Search");

    Hlayout = new QHBoxLayout;
    Hlayout->addWidget(lneSearch);
    Hlayout->addWidget(btnSearch);

    Vlayout =  new QVBoxLayout;
    Vlayout->addLayout(Hlayout);
    Vlayout->addWidget(txtMan);

    setLayout(Vlayout);
    out="";

    connect(btnSearch,SIGNAL(clicked()),this,SLOT(startSearch()));
    connect(lneSearch,SIGNAL(returnPressed()),this,SLOT(startSearch()));
    connect(&proc,SIGNAL(readyReadStandardOutput()),this,SLOT(stdOut()));
    connect(&proc,SIGNAL(readyReadStandardError()),this,SLOT(stdErr()));
    connect(&proc,SIGNAL(finished(int ,QProcess::ExitStatus)),this,SLOT(procFinished(int,QProcess::ExitStatus)));
}
void SynchronousProcess::processStdErr(bool emitSignals)
{
    // Handle binary data
    const QByteArray ba = m_d->m_process.readAllStandardError();

    if (debug > 1) {
        qDebug() << Q_FUNC_INFO << emitSignals << ba;
    }
    if (!ba.isEmpty()) {
        m_d->m_stdErr.data += ba;
        if (emitSignals) {
            // Emit binary signals
            emit stdErr(ba, m_d->m_stdErr.firstData);
            m_d->m_stdErr.firstData = false;
            if (m_d->m_stdErr.bufferedSignalsEnabled) {
                // Buffered. Emit complete lines?
                const QByteArray lines = m_d->m_stdErr.linesRead();
                if (!lines.isEmpty()) {
                    emit stdErrBuffered(convertStdErr(lines), m_d->m_stdErr.firstBuffer);
                    m_d->m_stdErr.firstBuffer = false;
                }
            }
        }
    }
}
示例#7
0
void Log::open()
{
    Guard<Mutex> guard(mutex_);

    if (path() != "") {
        errorStream_   =
        warningStream_ =
        noticeStream_  =
        infoStream_    =
        debugStream_   = File::open(path(), File::WriteOnly|File::Append);
    }
    else if (Process::isDaemonized()) {
        errorStream_   = systemLog()->errorStream();
        warningStream_ = systemLog()->warningStream();
        noticeStream_  = systemLog()->noticeStream();
        infoStream_    = systemLog()->infoStream();
        debugStream_   = systemLog()->debugStream();
    }
    else {
        errorStream_   =
        warningStream_ =
        noticeStream_  =
        infoStream_    =
        debugStream_   = stdErr();
    }

    if (level() < ErrorLogLevel)   errorStream_   = nullStream();
    if (level() < WarningLogLevel) warningStream_ = nullStream();
    if (level() < NoticeLogLevel)  noticeStream_  = nullStream();
    if (level() < InfoLogLevel)    infoStream_    = nullStream();
    if (level() < DebugLogLevel)   debugStream_   = nullStream();
}
示例#8
0
void CMapQMAPExport::slotStart()
{
    if(!states.isEmpty() || !state.isNull()) return;
    pushExport->setEnabled(false);
    pushCancel->setText(tr("Cancel"));
    textBrowser->clear();

    tainted = false;

    if(mapsel.subtype == IMapSelection::eGDAL)
    {
        startExportGDAL();
    }
    else if(mapsel.subtype == IMapSelection::eTMS || mapsel.subtype == IMapSelection::eWMS)
    {
        startExportStreaming();
    }
    else
    {
        stdErr(tr("Unknown map format."), true);
    }

    totalNumberOfStates = states.count();
    // start the statemachine
    setNextState();
}
void PythonQtScriptingConsole::flushStdOut()
{
  if (!_stdOut.isEmpty()) {
    stdOut("\n");
  }
  if (!_stdErr.isEmpty()) {
    stdErr("\n");
  }
}
示例#10
0
ShapeKnotsProcess::ShapeKnotsProcess(QObject *parent) :
    QProcess(parent)
{
    connect(this, SIGNAL(readyReadStandardOutput()),
            this, SLOT(stdOut()));
    connect(this, SIGNAL(readyReadStandardError()),
            this, SLOT(stdErr()));
    connect(this, SIGNAL(finished(int,QProcess::ExitStatus)),
            this, SLOT(terminate()));
}
示例#11
0
文件: utils.c 项目: yuejoo/APEUFinal
int read_cmd(char* in, char* param[]){
	
	
	char *tempCmd;
		
	if(!cflg)
		tempCmd  = readline(in);
	int paraNum;
	/* Handle the non-input in cmd */
	
	if(!cflg){
		free(in);
		in = tempCmd;
	}

	if( in == NULL || strlen(in) == 0){
		param[0] = in;
		return 0;
	}

	if( strcpy(cmd,in) == NULL)
		stdErr("err in strycpy()");

	int length = sperateCMD(cmd);
	if( length < 0){
		cmd[0] = '\0';
	}
	else{
		int i=0, index=1;
		for(i=0; i< length; i++)
			if(cmd[i]!='\0'){
				param[0] = &cmd[i];
				break;
			}

		/* skip the space before the first char in cmd*/
		int firstItem = i;
		for(i = firstItem+1; i< length; i++){
			if(cmd[i] == '>' || cmd[i] == '<' || cmd[i] == '|' || cmd[i] == '&'){
				if(cmd[i+1] == '>' && cmd[i] == '>'){
					param[index++] = makeOperator('d');
					cmd[i+1] = '\0';cmd[i]='\0';
				}
				else{
					param[index++] = makeOperator(cmd[i]);
					cmd[i] = '\0';
				}
			}
			else if(cmd[i] != '\0' && cmd[i-1] == '\0')
				param[index++] = &cmd[firstItem]+i;
		}
		paraNum = index;
	}
	return paraNum;
}
void milxQtPythonConsole::flushStdOut()
{
    if (!_stdOut.isEmpty())
    {
        stdOut("\n");
    }
    if (!_stdErr.isEmpty())
    {
        stdErr("\n");
    }
}
示例#13
0
文件: utils.c 项目: yuejoo/APEUFinal
int buildin_cmd(char* in, char *param[]){
	in = param[0];

	if( strcmp(in,"exit")==0 ){
		if(xflg)
			fprintf(stderr,"+ exit\n");
		exit(0);
	}
	
	if( strcmp(param[0],"cd")==0 ){
		if(xflg){
			fprintf(stderr,"+ %s", param[0]);
			if(param[1] != NULL)
				fprintf(stderr," %s\n", param[1]);
			else
				fprintf(stderr, "\n");
		} 
		if(param[1] == NULL){
			chdir("/home");
			return 1;
		}
		if(strcmp(param[1],".") == 0 ){
			return 1;
		}
		if( strcmp(param[1],"..") == 0){
			if(chdir("../") < 0)
				stdErr("No such directory.");
		}
		else{
			if(chdir(param[1]) < 0)
				stdErr("No such directory.");
		}

		return 1;	
	}
	return 0;
}
示例#14
0
void Process::slotFinished(int, QProcess::ExitStatus exitc){
	/*
	 * This piece of code try to catch error messages.
	 * In fact exitCode() not always can return error code
	 * (for example kdesu\gksu)
	 * So the beast way is to inform user about troubles is to show to him any STDERR messages.
	 */

		QTextStream stdErr(stderr);
		QString lang = this->getLocale();

		// Read STDERR with locale support
		QTextCodec *codec = QTextCodec::codecForName(lang.toLatin1());
		if (!codec){
			stdErr<<"[ee] Cannot setup codec for \""<<lang<<"\""<<endl;
			stdErr<<"[ee] Aborting current operation!"<<endl;
			reject();
			return;
		}

		QString string = codec->toUnicode(myProcess->readAllStandardError());

#ifdef DEBUG
		qDebug()<<"[ii] Process::slotFinished exitstatus:"<<exitc<<"exitcode:"<<myProcess->exitCode();
		qDebug()<<"[ii] Process::slotFinished STDERR:"<<codec->toUnicode(myProcess->readAllStandardError());
		qDebug()<<"[ii] Process::slotFinished STDOUT:"<<codec->toUnicode(myProcess->readAllStandardOutput());
#endif

		if (!string.isEmpty()){
			if ((exitc == 0) && (myProcess->exitCode() == 0)){
				if (showErr){
					QMessageBox::warning(this, tr("Output"), tr("It seems that the process exited normally.<br><br>STDERR log:<br>%1").arg(string));
				}
				accept();
                return;
			} else {
				QMessageBox::warning(this, tr("Output"), tr("It seems that the process crashed.<br><br>STDERR log:<br>%1").arg(string));
				reject();
                return;
			}
		}

	accept();

	return;
}
示例#15
0
void Process::slotError(QProcess::ProcessError err){
	if (myProcess->exitCode()!=0){

		QTextStream stdErr(stderr);
		QString lang = this->getLocale();

		QTextCodec *codec = QTextCodec::codecForName(lang.toLatin1());
		if (!codec){
			stdErr<<"[ee] Cannot setup codec for \""<<lang<<"\""<<endl;
			stdErr<<"[ee] Aborting current operation!"<<endl;
			reject();
			return;
		}

		QString string = codec->toUnicode(myProcess->readAllStandardError());

		if (!string.isEmpty()){
			QMessageBox::warning(this, tr("Error"), tr("It seems that the process failed.<br><br>Error log:<br>%1").arg(string));
		} else {
			switch (err){
			case 0:
				QMessageBox::warning(this, tr("Error"), tr("Process: The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program."));
				break;
			case 1:
				QMessageBox::warning(this, tr("Error"), tr("Process: The process crashed some time after starting successfully."));
				break;
			case 2:
				QMessageBox::warning(this, tr("Error"), tr("Process: The last waitFor...() function timed out."));
				break;
			case 3:
				QMessageBox::warning(this, tr("Error"), tr("Process: An error occurred when attempting to read from the process. For example, the process may not be running."));
				break;
			case 4:
				QMessageBox::warning(this, tr("Error"), tr("Process: An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel."));
				break;
			case 5:
				QMessageBox::warning(this, tr("Error"), tr("Process: An unknown error occurred. This is the default return value of error()."));
				break;
			}
            reject ();
		}
	} else {
		switch (err){
			case 0:
			QMessageBox::warning(this, tr("Error"), tr("Process: The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program."));
			break;
			case 1:
			QMessageBox::warning(this, tr("Error"), tr("Process: The process crashed some time after starting successfully."));
			break;
			case 2:
			QMessageBox::warning(this, tr("Error"), tr("Process: The last waitFor...() function timed out."));
			break;
			case 3:
			QMessageBox::warning(this, tr("Error"), tr("Process: An error occurred when attempting to read from the process. For example, the process may not be running."));
			break;
			case 4:
			QMessageBox::warning(this, tr("Error"), tr("Process: An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel."));
			break;
			case 5:
			QMessageBox::warning(this, tr("Error"), tr("Process: An unknown error occurred. This is the default return value of error()."));
			break;
		}
		reject ();
	}
	return;
}