コード例 #1
0
ファイル: cmdline.cpp プロジェクト: Stretto/mago
void ExecutableInfo::setDir(std::wstring directory) {
	if (directory.empty()) {
		dir.clear();
		return;
	}
	std::wstring tmp = fixPathDelimiters(unquoteString(directory));
	dir = relativeToAbsolutePath(tmp);
	CRLog::info("dir is set: %s", toUtf8z(dir));
}
コード例 #2
0
ファイル: cmdline.cpp プロジェクト: Stretto/mago
void ExecutableInfo::setExecutable(std::wstring  exe) {
	if (exe.empty()) {
		exename.clear();
		return;
	}
	std::wstring tmp = fixPathDelimiters(unquoteString(exe));
	exename = relativeToAbsolutePath(tmp);
	CRLog::info("exename is set: %s", toUtf8z(exename));
}
コード例 #3
0
void JabberClient::auth_request(const char *jid, unsigned type, const char *text, bool bCreate)
{
    Contact *contact;
    JabberUserData *data = findContact(jid, NULL, false, contact);
    if (isAgent(jid)){

        switch (type){

        case MessageAuthRequest:{
                if (data == NULL)
                    data = findContact(jid, NULL, true, contact);
                m_socket->writeBuffer.packetStart();
                m_socket->writeBuffer
                << "<presence to=\""
                << data->ID
                << "\" type=\"subscribed\"></presence>";
                sendPacket();
                m_socket->writeBuffer.packetStart();
                m_socket->writeBuffer
                << "<presence to=\""
                << data->ID
                << "\" type=\"subscribe\"><status>"
                << "</status></presence>";
                sendPacket();
                Event e(EventContactChanged, contact);
                e.process();
                return;
            }
        case MessageAuthGranted:{
                if (data == NULL)
                    data = findContact(jid, NULL, true, contact);
                Event e(EventContactChanged, contact);
                e.process();
                return;
            }

        }
    }
    if ((data == NULL) && bCreate){
        data = findContact(jid, NULL, true, contact);
        contact->setTemporary(CONTACT_TEMP);
    }
    if (data == NULL)
        return;
    AuthMessage msg(type);
    msg.setContact(contact->id());
    msg.setClient(dataName(data).c_str());
    msg.setFlags(MESSAGE_RECEIVED);
    if (text)
        msg.setText(unquoteString(QString::fromUtf8(text)));
    Event e(EventMessageReceived, &msg);
    e.process();
}
コード例 #4
0
void UnquoteParser::tag_start(const QString &tag, const list<QString> &options)
{
    if (tag == "pre"){
        if (!m_bPre)
            res += "\n";
    }else if (tag == "br"){
        res += "\n";
    }else if (tag == "hr"){
        if (!res.isEmpty() && (res[(int)(res.length() - 1)] != '\n'))
            res += "\n";
        res += "---------------------------------------------------\n";
    }else if (tag == "td"){
        if (m_bTD){
            res += "\t";
            m_bTD = false;
        }
    }else if (tag == "tr"){
        if (m_bTR){
            res += "\n";
            m_bTR = false;
        }
    }else if (tag == "p"){
        if (m_bPar){
            res += "\n";
            m_bPar = false;
        }
    }else if (tag == "img"){
        QString src;
        QString alt;
        for (list<QString>::const_iterator it = options.begin(); it != options.end(); ++it){
            QString opt   = *it;
            ++it;
            QString value = *it;
            if (opt == "src")
                src = value;
            if (opt == "alt")
                alt = value;
        }
        if (!alt.isEmpty()){
            res += unquoteString(alt);
            return;
        }
        if (src.left(5) == "icon:"){
        	list<string> smiles = getIcons()->getSmile(src.mid(5).latin1());
        	if (!smiles.empty()){
            		res += QString::fromUtf8(smiles.front().c_str());
			return;
		}
	}
	text(alt);
    }
}
コード例 #5
0
QString TextShow::plainText(int paraFrom, int paraTo, int indexFrom, int indexTo)
{
    QString res;
    if ((paraFrom > paraTo) || ((paraFrom == paraTo) && (indexFrom >= indexTo)))
        return res;
    for (int i = paraFrom; i <= paraTo; i++){
        if (i >= paragraphs())
            break;
        res += unquoteString(text(i), (i == paraFrom) ? indexFrom : 0, (i == paraTo) ? indexTo : -1);
        if ((i < paraTo) && (i < paragraphs()))
            res += "\n";
    }
    return res;
}
コード例 #6
0
void JabberClient::auth_request(const char *jid, unsigned type, const char *text, bool bCreate)
{
    Contact *contact;
    JabberUserData *data = findContact(jid, NULL, NULL, false, contact);
    if ((data == NULL) && bCreate){
        data = findContact(jid, NULL, NULL, true, contact);
        contact->setTemporary(CONTACT_TEMP);
    }
    if (data == NULL)
        return;
    AuthMessage msg(type);
    msg.setContact(contact->id());
    msg.setClient(dataName(data).c_str());
    msg.setFlags(MESSAGE_RECEIVED);
    if (text)
        msg.setText(unquoteString(QString::fromUtf8(text)));
    Event e(EventMessageReceived, &msg);
    e.process();
}
コード例 #7
0
ファイル: NetEM.cpp プロジェクト: cns-iu/nwb
int main(int argc, char *argv[])
{
    input_file input(argc, argv);

    std::string mdl = input.getStringOpt("model");
    unsigned seed = input.getUnsignedOpt("seed");
    unsigned M = input.getUnsignedOpt("M", 3);

    if(M<2)
    {
        fprintf(stderr, "Memory (M) must be larger or equal to 2\n");
        exit(3);
    }

    std::string infections = input.getStringOpt("infections");
    std::string network = input.getStringOpt("network");
    std::string output = input.getStringOpt("output");
    std::string name = input.getStringOpt("name", std::string("0"));
    unsigned days = input.getUnsignedOpt("days");
    unsigned events = input.getUnsignedOpt("events", 2);
    string outVal = input.getStringOpt("outVal");
    string date = input.getStringOpt("date");
    string frames = input.getStringOpt("frames", "none");

    output = unquoteString(output);
    outVal = unquoteString(outVal);
    frames = unquoteString(frames);

#ifdef BGDEBUG
    input.writeToFile(stderr);
    input.writeToFile(stderr, mdl);
    input.writeToFile(stderr, infections);
#endif
    //Ensure that the directory name has a trailing "/"
    if(output[output.size()-1]!='/')
        output+="/";

    if(frames != "none" && frames[frames.size()-1]!='/')
        frames+="/";


#ifdef _WIN32
    freopen((output + "NetEM." + name + ".out.dat").c_str(), "w", stdout);
    freopen((output + "NetEM." + name + ".err.dat").c_str(), "w", stderr);
#else
    stdout = fopen((output+"NetEM."+name+".out.dat").c_str(),"w");
    stderr = fopen((output+"NetEM."+name+".err.dat").c_str(),"w");
#endif // _WIN32

    for(unsigned i=0; i<argc; ++i)
        printf("# %u %s\n", i, argv[i]);

    Parse parse(mdl);
    Rand r(seed);

    Graph g(network);
    std::vector<std::vector<NODE> > graph = g.getGraph();

    unsigned N = graph.size();
    unsigned susIndex = parse.susceptible();
    unsigned recIndex = parse.recovered();
    unsigned NStates = parse.NStates();
    std::vector<unsigned> Ni = g.getPi();
    ModelNetwork model(parse, &r);
    uint64_t secondary;

    std::vector<std::string> outComp = getVector(outVal);
    std::vector<unsigned> outCompIndex;

    fprintf(stderr,"# Found %u comps\n", unsigned(outComp.size()));

    std::vector<Transition> transList = parse.getTransitions();

    std::vector<unsigned> outTrans(transList.size(), 0);

    for(unsigned i=0; i<outComp.size(); ++i)
    {
        fprintf(stderr,"%u \"%s\"",i,outComp[i].c_str());

        unsigned comp = parse.label(outComp[i]);

        outCompIndex.push_back(comp);

        for(unsigned j=0; j<transList.size(); ++j)
        {
            if(transList[j].j == comp)
            {
                outTrans[j] = 1;
                fprintf(stderr," %u",j);
            }
        }

        fprintf(stderr, "\n");
    }

    bool hasFrames = false;

    if(frames != "none")
        hasFrames = true;

    do {
        Population nodes(M, N, susIndex, recIndex);

        nodes.seeding(infections, 0, parse, r);

        FILE *fpout = input.openFile((output + "NetEM." + name + ".out"));
        FILE *fperr = input.openFile((output + "NetEM." + name + ".err"));
        FILE *fpsec = input.openFile((output + "NetEM." + name + ".sec"));

        FILE *fpstate;

        if(hasFrames)
        {
            fpstate = input.openFile((frames + "NetEM." + name + ".state"));
            g.saveHeader(fpstate);
        }

        fprintf(fpout, "# time");

        Output outData(N, days+1);
        for(unsigned i=0; i<NStates; ++i)
            fprintf(fpout, " %s", parse.index(i).c_str());

        fprintf(fpout, "\n");

        secondary = 0;

        vector<uint64_t> transCount;
        Calendar cal(date);
        unsigned day0 = cal.day();
        for(unsigned step = 0; step < days; ++step)
        {
            unsigned delta = model.step(graph, nodes, Ni, step, fperr,  outTrans, transCount);

            secondary += delta;
            outData.add(transCount, step);

            if(hasFrames)
                nodes.saveState(step, fpstate);

            nodes.savePopulations(step, NStates, fpout);

            fprintf(fpsec, "%u %u\n",step, delta);
        }

        fclose(fpout);
        fclose(fperr);
        fclose(fpsec);

        if (hasFrames)
            fclose(fpstate);

        fprintf(stderr, "outbreak = %Lu\n", secondary);

        if(secondary > events)
        {
            outData.writeToFile(output+"sum");
        }

    } while(secondary < events);



    return 0;
}
コード例 #8
0
void MigrateDialog::flush()
{
    string output;
    switch (m_state){
    case 0:
        output = "[icq/ICQ]\n";
        clientsConf.writeBlock(output.c_str(), output.length());
        output = "Uin=";
        output += number(m_uin);
        output += "\n";
        if (!m_passwd.empty()){
            m_passwd = unquoteString(m_passwd.c_str());
            unsigned char xor_table[] =
                {
                    0xf3, 0x26, 0x81, 0xc4, 0x39, 0x86, 0xdb, 0x92,
                    0x71, 0xa3, 0xb9, 0xe6, 0x53, 0x7a, 0x95, 0x7c
                };
            unsigned i;
            for (i = 0; i < m_passwd.length(); i++)
                m_passwd[i] = (char)(m_passwd[i] ^ xor_table[i]);
            string new_passwd;
            unsigned short temp = 0x4345;
            for (i = 0; i < m_passwd.length(); i++) {
                temp ^= m_passwd[i];
                new_passwd += '$';
                char buff[8];
                sprintf(buff, "%x", temp);
                new_passwd += buff;
            }
            output += "Password=\"";
            output += new_passwd;
            output += "\"\n";
        }
        clientsConf.writeBlock(output.c_str(), output.length());
        m_owner = "ICQ.";
        m_owner += number(m_uin);
        break;
    case 1:
        if (!m_name.empty()){
            output = "[Group=";
            output += number(++m_grpId);
            output += "]\n";
            output += "Name=\"";
            output += m_name;
            output += "\"\n";
            contactsConf.writeBlock(output.c_str(), output.length());
        }
        break;
    case 2:
        output = "[Contact=";
        output += number(++m_contactId);
        output += "]\n";
        if (m_uin >= 0x80000000)
            m_uin = 0;
        if (m_name.empty())
            m_name = number(m_uin);
        if (!m_name.empty()){
            output += "Name=\"";
            output += m_name;
            output += "\"\n";
        }
        if (m_uin){
            output += "[";
            output += m_owner;
            output += "]\n";
            output += "Uin=";
            output += number(m_uin);
            output += "\n";
        }
        contactsConf.writeBlock(output.c_str(), output.length());
        break;
    case 4:
        if (!m_message.empty()){
            QString msg = QString::fromLocal8Bit(m_message.c_str());
            if (!m_charset.empty()){
                QTextCodec *codec = QTextCodec::codecForName(m_charset.c_str());
                if (codec)
                    msg = codec->toUnicode(m_message.c_str());
            }
            output = "[Message]\n";
            output += "Text=\"";
            output += quoteChars(msg, "\"", false).local8Bit();
            output += "\"\n";
            if (m_direction.empty()){
                output += "Flags=2\n";
            }else{
                output += "Flags=3\n";
            }
            output += "Time=";
            output += m_time.c_str();
            output += "\n";
            hTo.writeBlock(output.c_str(), output.length());
        }
        break;
    }
    m_uin		= 0;
    m_passwd	= "";
    m_name		= "";
    m_message	= "";
    m_time		= "";
    m_direction = "";
    m_charset	= "";
}