Пример #1
0
Файл: split.cpp Проект: n-sm/qrs
std::vector< std::string> split (std::string  s)
{
  std::vector< std::string> retsv;

  int desde;
  int c = 0;
  int i = 0;
  int len = s.size();
  while(s[i] == ' ') i++;
  desde = i;
  for(; i < len ; i++)
    {
      if (s[i] == ' ') {
	if(s[i+1] == ' ') continue;
	std::string tmpstr( s.substr(desde, i - desde) );
	retsv.insert(retsv.begin() + c++, tmpstr) ;
	desde = i + 1;
      }
    }
  // i == len - 1
  std::string tmpstr( s.substr(desde, ++i - desde ) );
  retsv.insert(retsv.begin() + c, tmpstr) ;

  return retsv;
}
Пример #2
0
QStringList
KGpgImport::getImportedIds(const QStringList &log, const int reason)
{
	QStringList res;

	foreach (const QString &str, log) {
		if (!str.startsWith(QLatin1String("[GNUPG:] IMPORT_OK ")))
			continue;

		QString tmpstr(str.mid(19).simplified());

		int space = tmpstr.indexOf(QLatin1Char( ' ' ));
		if (space <= 0) {
            qDebug() << __LINE__ << "invalid format:" << str;
			continue;
		}

		bool ok;
		unsigned char code = tmpstr.left(space).toUInt(&ok);
		if (!ok) {
            qDebug() << __LINE__ << "invalid format:" << str << space << tmpstr.left(space - 1);
			continue;
		}

		if ((reason == -1) || ((reason == 0) && (code == 0)) || ((reason & code) != 0))
			res << tmpstr.mid(space + 1);
	}

	return res;
}
Пример #3
0
bool segmentSina::SegmentPos(string & sentence,WPList & result)
{
      char tmp[1024];
    
      int iret = AnalyTextWithLex2(lexicon, sentence.c_str(), sentence.length(), "GBK", wordseg, flags , 0);
      if( iret <  0 )
      {
        return false;
      }
     
     for (int j = 0; j < wordseg->word_num; j++)
     {
         int lenth = uniToBytes(wordseg->uni+wordseg->wordlist[j].wordPos, wordseg->wordlist[j].        wordLen, tmp, 1023, "GBK");
         tmp[lenth] =0;
    
         string tmpstr(tmp);
         int posid=wordseg->wordlist[j].postagid;
         
         WordPos segpos;
         segpos.word=tmpstr;
         segpos.pos=posid;

         result.push_back(segpos);
    
     }
     
    return true;


}
Пример #4
0
posfreq qgramGM::mostFrequent(uInt gramLen, const string & s){
  posfreq posFreq;
  assert(gramLen <= s.size());
  uInt count, pos;
  pos = 0; count = 0;
  substrCmp compclass(s);
  // map<string,uInt> counts;
  map<substr, uInt, substrCmp> counts(compclass);
  // cout << "qgramGM::mostFrequent(" << k << "'" << s << "'" << endl;
  for(uInt i = 0; i < s.size() - gramLen + 1; i++){
    // string tmpstr = s.substr(i, k);
    substr tmpstr(i, gramLen);
    // map<string,uInt>::iterator it = counts.find(tmpstr);
    map<substr, uInt, substrCmp>::iterator it = counts.find(tmpstr);
    if(it != counts.end()){
      (*it).second ++;
      if((*it).second > count){
        count = (*it).second;
        pos = i;
      }
    } else {
      counts[tmpstr] = 1;
      if(1 > count){
        count = 1;
        pos = i;
      }
    }
  }
  posFreq.pos = pos; posFreq.freq = count;
  return posFreq;
}
Пример #5
0
wxString ReplaceString(const wxString &str, const wxString &oldStr, const wxString &newStr)
{
	int buflen = str.Length() + 100;
	int len = 0;

	wxChar *buf = new wxChar[buflen + 1];

	const wxChar *ptrIn = str.c_str();
	const wxChar *ptrFound = wxStrstr(ptrIn, oldStr);

	while (ptrFound)
	{
		AppendBuf(buf, buflen, len, ptrIn, ptrFound - ptrIn);
		AppendBuf(buf, buflen, len, newStr.c_str());
		ptrIn = ptrFound + oldStr.Length();
		ptrFound = wxStrstr(ptrIn, oldStr);
	}

	AppendBuf(buf, buflen, len, ptrIn);
	buf[len] = 0;
	wxString tmpstr(buf);
	delete[] buf;

	return tmpstr;
}
Пример #6
0
bool segmentSina::SegmentIdf(string & sentence,WPList & result)
{

	 char tmp[1024];
	  
	 int iret = AnalyTextWithLex2(lexicon, sentence.c_str(), sentence.length(), "GBK", wordseg, flags , 0);
	 if( iret <  0 )
	 {
		return false;
	 }
			 
	 for (int j = 0; j < wordseg->word_num; j++)
	 {
		int lenth = uniToBytes(wordseg->uni+wordseg->wordlist[j].wordPos, wordseg->wordlist[j].wordLen, tmp, 1023, "GBK");
		tmp[lenth] =0;
					 
		 string tmpstr(tmp);
		 int posid=wordseg->wordlist[j].idf;
		 if(posid==0)//some new word has the idf value=0,that is wrong,so give a high value
			 posid=70;
					 
		 WordPos segpos;                                                          
		 segpos.word=tmpstr;                                                      
		 segpos.pos=posid;                                                        
					 
		 result.push_back(segpos);                                                
					    
	 }
					    


}
Пример #7
0
void output(MotifSearch* ms) {
	string tmpstr(outfile);
	string outstr(outfile);
	string lockstr(outfile);
	tmpstr.append(".tmp.ms");
	outstr.append(".ms");
	lockstr.append(".lock");
	ofstream tmp(tmpstr.c_str(), ios::trunc);
	ms->full_output(tmp);
	tmp.close();
	struct flock fl;
	int fd;
	fl.l_type   = F_WRLCK;
	fl.l_whence = SEEK_SET;
	fl.l_start  = 0;
	fl.l_len    = 0;
	fl.l_pid    = getpid();
	fd = open(lockstr.c_str(), O_WRONLY | O_CREAT, 0644);
	while(fcntl(fd, F_SETLK, &fl) == -1) {
		cerr << "Waiting for lock release on archive file...\n";
		sleep(10);
	}
	rename(tmpstr.c_str(), outstr.c_str());
	cerr << "Archive output completed.\n";
	fl.l_type = F_UNLCK;
	fcntl(fd, F_SETLK, &fl);
	close(fd);
}
Пример #8
0
bool segmentSina::SegmentOnly(string & sentence,vector<string> & result)
{

       char tmp[1024];

       int iret = AnalyTextWithLex2(lexicon, sentence.c_str(), sentence.length(), "GBK", wordseg, flags , 0);
       if( iret <  0 )
       {
          return false;
       }
     
//       cout<<"word-num="<<wordseg->word_num<<endl;
     
       for (int j = 0; j < wordseg->word_num; j++)
       {
         int lenth = uniToBytes(wordseg->uni+wordseg->wordlist[j].wordPos, wordseg->wordlist[j].wordLen, tmp, 1023, "GBK");
         tmp[lenth] =0;
        
         string tmpstr(tmp);
         result.push_back(tmpstr);

       }

       return true;
}
Пример #9
0
QString GBuildMakefileGenerator::writeOne(QString filename, QString pathtoremove)
{
    QString s("");
    QString origfilename(filename);
    s += filename.remove(pathtoremove);
    if (filename.endsWith(Option::h_ext.first()) && mocable(origfilename)) {
        QString corename(filename.section(QDir::separator(), -1));
        corename.remove(Option::h_ext.first());
        corename.append(Option::cpp_ext.first());
        corename.prepend(Option::h_moc_mod);
        s += "\t[MOC/Qt Header]\n";
        s += "\t-o ";
        s += "work/";
        s += pathtoremove;
        s += QDir::separator();
        s += corename;
        s += "\n";
    } else if (filename.section(QDir::separator(), -1).startsWith("qrc_")) {
        QString tmpstr(filename.section("/", -1).section(".", 0, -1).remove("qrc_").remove(".cpp"));
        s += "\n\t:depends=";
        s += tmpstr;
        s += ".qrc";
        s += "\n";
    } else if (filename.endsWith(Option::cpp_ext.first()) && mocable(origfilename)) {
        QString tmpstr(filename.section("/", -1));
        QString filepath(pathtoremove);
        if (!project->values("QT_SOURCE_TREE").isEmpty()) {
            filepath.remove(project->values("QT_SOURCE_TREE").first());
            filepath.remove(0, 1);
        }
        s += "\n\t:preexecShellSafe='${QT_BUILD_DIR}/bin/moc ";
        s += "-nn ";
        s += varGlue("DEFINES", "-D", " -D", " ");
        s += varGlue("INCLUDEPATH", "-I", " -I", " ");
        s += filepath;
        s += filename;
        s += " -o ";
        tmpstr.replace(Option::cpp_ext.first(), Option::cpp_moc_ext);
        s += "work/";
        s += pathtoremove;
        s += QDir::separator();
        s += tmpstr;
        s += "\n";
    } else
        s += "\n";
    return s;
}
Пример #10
0
int host_request_update()
{
    char value[MAX_PATH] = "";
    char *url = lo_server_get_url(_osc_server);
    sprintf(value, "%s%s", url, _osc_path);
    int err = lo_send(_osc_host_addr, tmpstr("%s/update", _osc_path), "s", value);
    free(url);
    return err;
}
Пример #11
0
static const char *
type_str(ir_unit_t *iu, const ir_type_t *it)
{
  int len = type_print(NULL, iu, it);
  char *dst = tmpstr(iu, len);
  const char *ret = dst;
  int x = type_print(&dst, iu, it);
  assert(x == len);
  return ret;
}
Пример #12
0
static const char *
type_str_index(ir_unit_t *iu, int id)
{
  int l = type_print_id(NULL, iu, id);
  char *dst = tmpstr(iu, l);
  const char *ret = dst;
  int x = type_print_id(&dst, iu, id);
  assert(x == l);
  return ret;
}
Пример #13
0
bool kd::findGood(QString &text, struct GoodsSearch *searchres)
{
    QString tmpstr("");
    QString input_substr;
    QString price;
    int offset=0;
    QTreeWidgetItem *sub_item;
    QTreeWidgetItem *tree_item = items_tree->invisibleRootItem();

    if(text.length() == 0)
    {
        text = QString("");
        return false;
    }

    items_tree->collapseAll();

    for(int i=0; i < tree_item->childCount(); ++i)
    {
        sub_item = tree_item->child(i);
        input_substr = text.mid(offset);
        qDebug() << "Offset:" << offset << " = " << input_substr << " comparing to " << sub_item->data(2,0).toString();

        if( input_substr.length() >= sub_item->data(2,0).toString().length() &&
                input_substr.startsWith(sub_item->data(2,0).toString()) )
        {
            tmpstr += sub_item->data(0,0).toString() + QString(" / ");
            price = sub_item->data(1,0).toString();
            offset += sub_item->data(2,0).toString().length();
            searchres->found_item = sub_item;
            i = -1;
            tree_item = sub_item;
            items_tree->expandItem(sub_item);
            items_tree->setCurrentItem(sub_item,0,QItemSelectionModel::ClearAndSelect);
        }
    }

    searchres->count = 1;
    if (offset < item_input->text().length())
    {
        searchres->count = text.mid(offset).toDouble();
    }

    text = tmpstr;
    if(!price.isEmpty())
    {
        searchres->price = price.toDouble();
        searchres->total_price = searchres->price * searchres->count;
        return true;
    }
    else
        return false;
}
 int InternalRegisterEffectDefinition(UnityAudioEffectDefinition& definition)
 {
     static const char* bandname[] = { "Low", "Mid", "High" };
     int numparams = P_NUM;
     definition.paramdefs = new UnityAudioParameterDefinition[numparams];
     RegisterParameter(definition, "MasterGain", "dB", -100.0f, 100.0f, 0.0f, 1.0f, 1.0f, P_MasterGain, "Overall gain");
     RegisterParameter(definition, "LowFreq", "Hz", 0.01f, 24000.0f, 800.0f, 1.0f, 3.0f, P_LowFreq, "Low/Mid cross-over frequency");
     RegisterParameter(definition, "HighFreq", "Hz", 0.01f, 24000.0f, 5000.0f, 1.0f, 3.0f, P_HighFreq, "Mid/High cross-over frequency");
     for (int i = 0; i < 3; i++)
         RegisterParameter(definition, tmpstr(0, "%sGain", bandname[i]), "dB", -100.0f, 100.0f, 0.0f, 1.0f, 1.0f, P_LowGain + i, tmpstr(1, "%s band gain in dB", bandname[i]));
     for (int i = 0; i < 3; i++)
         RegisterParameter(definition, tmpstr(0, "%sAttackTime", bandname[i]), "ms", 0.0f, 10.0f, 0.1f, 1000.0f, 4.0f, P_LowAttack + i, tmpstr(1, "%s band attack time in seconds", bandname[i]));
     for (int i = 0; i < 3; i++)
         RegisterParameter(definition, tmpstr(0, "%sReleaseTime", bandname[i]), "ms", 0.0f, 10.0f, 0.5f, 1000.0f, 4.0f, P_LowRelease + i, tmpstr(1, "%s band release time in seconds", bandname[i]));
     for (int i = 0; i < 3; i++)
         RegisterParameter(definition, tmpstr(0, "%sThreshold", bandname[i]), "dB", -50.0f, 0.0f, -10.0f, 1.0f, 1.0f, P_LowThreshold + i, tmpstr(1, "%s band compression level threshold time in dB", bandname[i]));
     for (int i = 0; i < 3; i++)
         RegisterParameter(definition, tmpstr(0, "%sRatio", bandname[i]), "%", 1.0f, 30.0f, 1.0f, 100.0f, 1.0f, P_LowRatio + i, tmpstr(1, "%s band compression ratio time in percent", bandname[i]));
     for (int i = 0; i < 3; i++)
         RegisterParameter(definition, tmpstr(0, "%sKnee", bandname[i]), "dB", 0.0f, 40.0f, 10.0f, 1.0f, 1.0f, P_LowKnee + i, tmpstr(1, "%s band compression curve knee range in dB", bandname[i]));
     RegisterParameter(definition, "FilterOrder", "", 1.0f, (float)MAXORDER, 1.0f, 1.0f, 1.0f, P_FilterOrder, "Filter order of cross-over filters");
     RegisterParameter(definition, "UseLogScale", "", 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, P_UseLogScale, "Use logarithmic scale for plotting the filter curve frequency response and input/output spectra");
     RegisterParameter(definition, "ShowSpectrum", "", 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, P_ShowSpectrum, "Overlay input spectrum (green) and output spectrum (red)");
     RegisterParameter(definition, "SpectrumDecay", "dB/s", -50.0f, 0.0f, -10.0f, 1.0f, 1.0f, P_SpectrumDecay, "Hold time for overlaid spectra");
     return numparams;
 }
Пример #15
0
void qgramGM::Frequent(uInt gramLen, const string & s,
                       std::map<substr, uInt, substrCmp> & counts){
  assert(gramLen <= s.size());
  // cout << "qgramGM::mostFrequent(" << k << "'" << s << "'" << endl;
  for(uInt i = 0; i < s.size() - gramLen + 1; i++){
    substr tmpstr(i, gramLen);
    map<substr, uInt, substrCmp>::iterator it = counts.find(tmpstr);
    if(it != counts.end()){
      (*it).second ++;
    } else {
      counts[tmpstr] = 1;
    }
  }
}
Пример #16
0
DWORD MainDlg::RefreshDiskList()
{
    std::vector<PhysicalDisk*> disks;
    PhysicalDisk::EnumDisks( disks );

    HWND hList = GetDlgItem( _hMainDlg, IDC_LIST_DISKS );

    ListView_DeleteAllItems( hList );

    for (auto& disk : disks)
    {
        auto& id_data = disk->id_data();
        LVITEMW lvi = { 0 };
        int idx = 0;
        
        lvi.mask = LVIF_TEXT | LVIF_PARAM;

        lvi.pszText = (LPWSTR)disk->path().c_str();
        lvi.cchTextMax = (int)disk->path().length() + 1;
        lvi.lParam = reinterpret_cast<LPARAM>(disk);

        int pos = ListView_InsertItem( hList, &lvi );

        LVITEMA lva = { 0 };
        for (idx = sizeof(id_data.ModelNumber) - 3; idx >= 0; idx--)
            if (id_data.ModelNumber[idx] != ' ')
                break;

        std::string tmpstr( (LPSTR)id_data.ModelNumber, (LPSTR)id_data.ModelNumber + idx );

        lva.iSubItem = 1;
        lva.pszText = disk->identified() ? (LPSTR)tmpstr.c_str() : "Unknown";

        SendMessage( hList, LVM_SETITEMTEXTA, pos, (LPARAM)&lva );

        for (idx = 0; idx < sizeof(id_data.SerialNumber); idx++)
            if (id_data.SerialNumber[idx] != ' ')
                break;

        tmpstr = std::string( (LPSTR)(id_data.SerialNumber + idx), (LPSTR)(id_data.SerialNumber + sizeof(id_data.SerialNumber)) );

        lva.iSubItem = 2;
        lva.pszText = disk->identified() ? (LPSTR)tmpstr.c_str() : "Unknown";

        SendMessage( hList, LVM_SETITEMTEXTA, pos, (LPARAM)&lva );
    }

    return ERROR_SUCCESS;
}
Пример #17
0
int main(int argc, char *argv[])
{
    if (argc < 5) {
        g_critical("not enough arguments supplied");
        return 1;
    }

    gtk_init(&argc, &argv);

    //char *exe_path = argv[0];
    char *host_url = argv[1];
    //char *lib_name = argv[2];
    char *plug_name = argv[3];
    char *identifier = argv[4];
    
    _osc_path = lo_url_get_path(host_url);
    _osc_host_addr = lo_address_new_from_url(host_url);
    
    _osc_server = lo_server_new(NULL, osc_error);
    lo_server_add_method(_osc_server, tmpstr("/%s/control",     _osc_path), "if", osc_control_handler,     NULL);
    lo_server_add_method(_osc_server, tmpstr("/%s/sample-rate", _osc_path), "i",  osc_samplerate_handler,  NULL);
    lo_server_add_method(_osc_server, tmpstr("/%s/program",     _osc_path), "ii", osc_program_handler,     NULL);
    lo_server_add_method(_osc_server, tmpstr("/%s/show",        _osc_path), NULL, osc_show_handler,        NULL);
    lo_server_add_method(_osc_server, tmpstr("/%s/hide",        _osc_path), NULL, osc_hide_handler,        NULL);
    lo_server_add_method(_osc_server, tmpstr("/%s/quit",        _osc_path), NULL, osc_quit_handler,        NULL);
    lo_server_add_method(_osc_server, NULL, NULL, osc_fallback_handler, NULL);
    
    host_request_update();
    
    gdk_input_add(lo_server_get_socket_fd(_osc_server), GDK_INPUT_READ, (GdkInputFunction)lo_server_recv_noblock, _osc_server);
    
    _window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));

    gtk_window_set_title(_window, tmpstr("%s - %s", plug_name, identifier));
	gtk_signal_connect(GTK_OBJECT(_window), "delete-event", on_window_deleted, NULL);

    size_t i; for (i=0; i<kAmsynthParameterCount; i++) {
        gdouble value = 0, lower = 0, upper = 0, step_increment = 0;
        get_parameter_properties(i, &lower, &upper, &value, &step_increment);
        _adjustments[i] = (GtkAdjustment *)gtk_adjustment_new(value, lower, upper, step_increment, 0, 0);
        g_signal_connect(_adjustments[i], "value-changed", (GCallback)&on_adjustment_value_changed, (gpointer)i);
    }

    GtkWidget *editor = editor_pane_new(new SynthesizerStub, _adjustments, TRUE);
    gtk_container_add(GTK_CONTAINER(_window), editor);
    gtk_widget_show_all(GTK_WIDGET(editor));
    
    gtk_main();
    
    return 0;
}
Пример #18
0
void kd::onItemClick(QTreeWidgetItem * item, int column)
{
    QString tmpstr("");
    QTreeWidgetItem *current_item = item;
    //QTreeWidgetItem *top_item = items_tree->invisibleRootItem();

    while(current_item->parent())
    {
        tmpstr.prepend(current_item->data(2,0).toString());
        current_item = current_item->parent();
    }
    tmpstr.prepend(current_item->data(2,0).toString());
    item_input->setText(tmpstr);
    return;
}
Пример #19
0
void Csetparam::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	CWnd * child = this -> GetWindow(GW_CHILD);
	
	RECT standardrect;
	this -> GetWindowRect(&standardrect);
	point.x += standardrect.left;
	point.y += standardrect.top;
	while(child){
		CString str;
		child -> GetWindowTextW(str);
		CStringA tmpstr(str.GetBuffer(0));
		string res(tmpstr.GetBuffer(0));
		tmpstr.ReleaseBuffer();
		str.ReleaseBuffer();
		RECT rect;
		child -> GetWindowRect(&rect);
		for(int i = 0; i < res.size(); ++i){
			if(res[i] >= 'A' && res[i] <= 'Z'){
				res[i] = res[i] +'a' - 'A';
			}
		}
		if(explain.find(res) != explain.end()){
			if(point.x >= rect.left && point.x <= rect.right
				&& point.y <= rect.bottom && point.y >= rect.top){	
					if(explain_label.use_count() == 0){
						explain_label.reset(new CStatic());
						explain_label -> Create(L"hello world", WS_CHILD|WS_VISIBLE|SS_CENTER, CRect(50,80,150,150), this);
						CFont * font = new CFont();
						font -> CreateFont(15,0,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
							DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,L"Courier New"); 
						explain_label -> SetFont(font, false);
					}
					explain_label -> SetWindowTextW(string_to_lpsctr(explain[res]));
					explain_label -> MoveWindow(point.x - standardrect.left, point.y - standardrect.top,  100, 50);
					explain_label -> ShowWindow(true);
					CDialogEx::OnMouseMove(nFlags, point);
					return;
				}
		}
		child = child -> GetWindow(GW_HWNDNEXT);
	}
	if(explain_label.use_count() > 0){
		explain_label -> ShowWindow(false);
	}
	CDialogEx::OnMouseMove(nFlags, point);
}
Пример #20
0
void XMLParser::Error(const char* errstr)
{
	char strLine[1024];
	snprintf(strLine, 1024, " in file: %s line: %d", m_pFileName, (int)XML_GetCurrentLineNumber(m_Parser));
	std::string tmpstr(errstr);
	tmpstr += strLine;
	tmpstr += "\n";

#ifdef PYTHON_WRAPPER
    PyErr_SetString(PyExc_SyntaxError, (char*)tmpstr.c_str());
#else
	Tracer::Error((char*)tmpstr.c_str());
#endif

	m_bErrorDetectedStopParsing = true;
}
LRESULT WaitingUsersFrame::onCopyFilename(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
	HTREEITEM selectedItem = ctrlQueued.GetSelectedItem(), parentItem = ctrlQueued.GetParentItem(selectedItem);

	if (!selectedItem || !parentItem || selectedItem == parentItem)
		return 0;
	TCHAR filenameBuf[256];
	ctrlQueued.GetItemText(selectedItem, filenameBuf, 255);
	*_tcschr(filenameBuf, _T('(')) = NULL;
	tstring tmpstr(filenameBuf);
	if(!tmpstr.empty()) {
		// remove last space
		tmpstr.erase(tmpstr.length() - 1);
		WinUtil::setClipboard(tmpstr);
	}
	return 0;
}
Пример #22
0
//---------------------------------------------------------------
string SQLQuery::str(const SQLQueryParms &p) const
{
    SQLQuery *const_this = const_cast<SQLQuery *>(this);
    if (!parsed.empty()) const_this->proc(const_cast<SQLQueryParms&>(p));
    *const_this << ends;

    strstreambuf *tmpbuf = const_this->rdbuf();
    uint length = tmpbuf->pcount() + 1;
    char *s = new char[length];

    const_this->get(s, length, '\0');
    const_this->seekg (0,ios::beg);
    const_this->seekp (-1,ios::cur);

    // FIX: work-around for memory leak; make temporary string, copy s in it,
    // free s and return the temporary string
    string tmpstr(s);
    delete[] s;
    return tmpstr;
}
Пример #23
0
/*!
 * Handling of CDATA
 */
void XMLParser::CharacterHandler(void *userData, const XML_Char *s, int len)
{
	XMLParser* p = (XMLParser*)userData;

	if (p == NULL)
	{
		return;
	}

	if (p->m_pstrCData != NULL)
	{
		// assign string value
		p->m_pstrCData->append(s,len);
	}
	else if (p->m_pintCData != NULL)
	{
		std::string tmpstr(s,len);
		*(p->m_pintCData) = atoi(tmpstr.c_str());
		p->m_pintCData = NULL;
	}
}
Пример #24
0
int host_configure(const char *key, const char *value)
{
    int err = lo_send(_osc_host_addr, tmpstr("%s/configure", _osc_path), "ss", key, value);
    return err;
}
Пример #25
0
Document::Document(const std::string& doc) {
    std::string tmpstr(doc);
    Util::strip(&tmpstr);
    Util::split(&_word_vec, tmpstr, ' ');
}
Пример #26
0
int host_set_control(int control, float value)
{
    int err = lo_send(_osc_host_addr, tmpstr("%s/control", _osc_path), "if", control, value);
    return err;
}
Пример #27
0
bool
GBuildMakefileGenerator::write()
{
    QStringList tmp;
    QString filename(Option::output.fileName());
    QString pathtoremove(qmake_getpwd());
    QString relpath(pathtoremove);
    QString strtarget(project->first("TARGET").toQString());
    bool isnativebin = nativebins.contains(strtarget);
    relpath.replace(Option::output_dir, "");

    /* correct output for non-prl, non-recursive case */
    QString outname(qmake_getpwd());
    outname += QDir::separator();
    outname += fileInfo(Option::output.fileName()).baseName();
    outname += projectSuffix();
    Option::output.close();
    Option::output.setFileName(outname);
    MakefileGenerator::openOutput(Option::output, QString());

    if (strtarget != fileInfo(project->projectFile()).baseName()) {
        QString gpjname(strtarget);
        QString outputName(qmake_getpwd());
        outputName += QDir::separator();
        outputName += fileInfo(project->projectFile()).baseName();
        outputName += projectSuffix();
        QFile f(outputName);
        f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
        QTextStream t(&f);
        t << "#!gbuild\n";
        t << "[Project]\n";
        t << gpjname << projectSuffix() << "\n";
        if ((project->first("TEMPLATE") == "lib")
                && project->isActiveConfig("shared"))
            t << gpjname << "_shared" << projectSuffix() << "\n";
        t.flush();
        gpjname += projectSuffix();
        Option::output.close();
        Option::output.setFileName(gpjname);
        MakefileGenerator::openOutput(Option::output, QString());
    }

    if ((project->first("TEMPLATE") == "app")
            && (!isnativebin)) {
        QTextStream t(&Option::output);
        QString intname(strtarget);
        intname += ".int";
        /* this is for bulding an INTEGRITY application.
         * generate the .int integrate file and the .gpj INTEGRITY Application
         * project file, then go on with regular files */
        t << "#!gbuild\n";
        t << "[INTEGRITY Application]\n";
        t << "\t:binDirRelative=.\n";
        t << "\t-o " << strtarget << "\n";
        t << intname << "\n";
        t << strtarget << "_app" << projectSuffix() << "\n";
        t.flush();

        /* generate integrate file */
        QFile f(intname);
        f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
        QTextStream ti(&f);
        ti << "# This is a file automatically generated by qmake\n";
        ti << "# Modifications will be lost next time you run qmake\n";
        ti << "Kernel\n";
        ti << "\tFilename\tDynamicDownload\n";
        ti << "EndKernel\n\n";
        ti << "AddressSpace\n";
        ti << "\tName\t" << strtarget << "\n";
        ti << "\tFilename\t" << strtarget << "_app\n";
        ti << "\tMemoryPoolSize\t0x100000\n";
        ti << "\tLanguage\tC++\n";
        /* FIXME : heap size is huge to be big enough for every example
         * it should probably be tailored for each example, btu there is no
         * good way to guess that */
        ti << "\tHeapSize\t0x00D00000\n";
        ti << "\tTask\tInitial\n";
        ti << "\t\tStackSize\t0x30000\n";
        ti << "\tEndTask\n";
        ti << "EndAddressSpace\n";
        ti.flush();

        /* change current project file to <projectname>_app.gpj and continue
         * generation */
        filename.insert(filename.lastIndexOf("."), "_app");
        Option::output.close();
        Option::output.setFileName(filename);
        MakefileGenerator::openOutput(Option::output, QString());
    } else if ((project->first("TEMPLATE") == "lib")
            && project->isActiveConfig("shared")) {
        QString gpjname(strtarget);
        gpjname += "_shared";
        gpjname += projectSuffix();
        QFile f(gpjname);
        f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
        QTextStream t(&f);
        t << "#!gbuild\n"
            "[Program]\n"
            "\t-A libINTEGRITY.so\n"
            "\t-A libc.so\n"
            "\t-A libscxx.so\n"
            "\t-A libQtCore.so\n"
            "\t-e __ghsbegin_text\n"
            "\t-startfile=-\n"
            "\t:syslibraries=-\n"
            "\t-Onolink\n";
        t << "\t-o lib" << strtarget << ".so\n";
        t << "\t-l" << strtarget << "\n";
        t << "\t-extractall=-l" << strtarget << "\n";
        t << "\t:outputDir=work/" << filename.section(QDir::separator(), 0, -1).remove(".gpj") << "\n";
        t << strtarget << "_shared.ld\n";
        t << "$(__OS_DIR)/intlib/sharedobjbssinit.c\n";
        t.flush();

        QFile fl(strtarget + "_shared.ld");
        fl.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
        QTextStream tl(&fl);
        tl << "CONSTANTS {\n"
             "    __INTEGRITY_MinPageAlign          = 16K\n"
             "    __INTEGRITY_MaxPageAlign          = 16K\n"
             "    __INTEGRITY_LibCBaseAddress       = \n";
        tl << dllbase << "\n";
        tl << "}\n"
             "-sec\n"
             "{\n"
             "  .picbase __INTEGRITY_LibCBaseAddress :\n"
             "        .text :\n"
             "  .syscall :\n"
             "        .intercall :\n"
             "        .interfunc :\n"
             "  .secinfo :\n"
             "  .rodata align(16) :\n"
             "  .fixaddr :\n"
             "  .fixtype :\n"
             "        .rombeg :\n"
             "        .textchecksum :\n"
             "        // The above sections may be large. Leave a bigger gap for large pages.\n"
             "  .pidbase align(__INTEGRITY_MaxPageAlign) :\n"
             "        .sdabase :\n"
             "        .data :\n"
             "        .toc :\n"
             "        .opd :\n"
             "        .datachecksum :\n"
             "  .bss align(__INTEGRITY_MinPageAlign) :\n"
             "        .heap :\n"
             "}\n";
        tl.flush();
        dllbase += DLLOFFSET;
    }

    QTextStream t(&Option::output);
    QString primaryTarget(project->values("QMAKE_CXX").at(0).toQString());

    pathtoremove += QDir::separator();
    filename.remove(qmake_getpwd());

    //HEADER
    t << "#!gbuild\n";

    /* find the architecture out of the compiler name */
    if (filename.endsWith("projects.gpj")) {
        primaryTarget.remove(0, 5);
        t << "macro QT_BUILD_DIR=%expand_path(.)\n";
        t << "macro __OS_DIR=" << project->values("INTEGRITY_DIR").first() << "\n";
        t << "primaryTarget=" << primaryTarget << "_integrity.tgt\n";
        t << "customization=util/integrity/qt.bod\n";
    }
    /* project type */
    if (project->first("TEMPLATE") == "app") {
        t << "[Program]\n";
        if (isnativebin) {
            t << "\t:binDir=bin\n";
            t << "\t-o " << strtarget << "\n";
        } else {
            t << "\t:binDirRelative=.\n";
            t << "\t-o " << strtarget << "_app\n";
        }
    } else if (project->first("TEMPLATE") == "lib") {
        t << "[Library]\n";
        t << "\t:binDir=lib\n";
        t << "\t-o lib" << strtarget << ".a\n";
    } else if (project->first("TEMPLATE") == "subdirs")
        t << "[Project]\n";
    else
        t << project->first("TEMPLATE") << "\n";

    /* compilations options */
    t << "\t:sourceDir=.\n";

    t << "\t:outputDir=work" << relpath << "\n";
    if (filename.endsWith("projects.gpj")) {
        t << "\t:sourceDir=work\n";
        t << "\t-Iwork\n";
        t << "\t-Llib\n";
        t << "\t";
        const ProStringList &l = project->values("QMAKE_CXXFLAGS");
        for (ProStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
            if ((*it).startsWith("-"))
                t << "\n\t" << (*it);
            else
                t << " " << (*it);
        }
        t << "\n";
    }
    t << "\n";

    t << varGlue("DEFINES", "\t-D", "\n\t-D", "\n");

    t << "\t-I.\n\t-I" << specdir() << "\n";
    t << varGlue("INCLUDEPATH", "\t-I", "\n\t-I", "\n");
    t << "\t--cxx_include_directory .\n\t--cxx_include_directory " << specdir() << "\n";
    t << varGlue("INCLUDEPATH", "\t--cxx_include_directory ", "\n\t--cxx_include_directory ", "\n");

    if (project->first("TEMPLATE") == "app") {
        /* include linker flags if it's an application */
        static const char * const src[] = { "QMAKE_LFLAGS", "QMAKE_LIBS", "LIBS", 0 };
        for (int i = 0; src[i]; i++) {
            /* skip target libraries for native tools */
            if (isnativebin && (i == 0))
                continue;
            t << "\t";
            const ProStringList &l = project->values(src[i]);
            for (ProStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
                if ((*it).startsWith("-"))
                    t << "\n\t" << (*it);
                else
                    t << " " << (*it);
            }
            t << "\n";
        }
    }

    /* first subdirectories/subprojects */
    {
        const ProStringList &l = project->values("SUBDIRS");
        for (ProStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
            QString gpjname((*it).toQString());
            /* avoid native tools */
            if (nativebins.contains(gpjname.section("_", -1)))
                continue;
            const ProKey skey(*it + ".subdir");
            if (!project->first(skey).isEmpty())
                gpjname = project->first(skey).toQString();
            else
                gpjname.replace("_", QDir::separator());
            gpjname += QDir::separator() + gpjname.section(QDir::separator(), -1);
            gpjname += projectSuffix();
            /* make relative */
            if (!project->values("QT_SOURCE_TREE").isEmpty()) {
                gpjname.replace(project->values("QT_SOURCE_TREE").first() + QDir::separator(), "");
            }
            t << gpjname << "\n";
        }
    }

    {
        const ProStringList &l = project->values("RESOURCES");
        for (ProStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
            QString tmpstr((*it).toQString());
            tmpstr.remove(pathtoremove);
            t << tmpstr << "\t[Qt Resource]\n";
            tmpstr = tmpstr.section(".", -2, -1).section(QDir::separator(), -1);
            tmpstr.remove(".qrc");
            t << "\t-name " << tmpstr << "\n";
            tmpstr.insert(tmpstr.lastIndexOf(QDir::separator()) + 1, "qrc_");
            tmpstr.append(".cpp");
            t << "\t-o work/" << tmpstr << "\n";
        }
    }
    {
        const ProStringList &l = project->values("FORMS");
        for (ProStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
            QString tmpstr((*it).toQString());
            tmpstr.remove(pathtoremove);
            t << tmpstr << "\t[Qt Dialog]\n";
            tmpstr = tmpstr.section(".", 0, 0).section(QDir::separator(), -1);
            tmpstr.insert(tmpstr.lastIndexOf(QDir::separator()) + 1, "ui_");
            tmpstr.remove(".ui");
            tmpstr.append(".h");
            t << "\t-o work/" << tmpstr << "\n";
        }
    }

    /* source files for this project */
    static const char * const src[] = { "HEADERS", "SOURCES", 0 };
    for (int i = 0; src[i]; i++) {
        const ProStringList &l = project->values(src[i]);
        for (ProStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
            if ((*it).isEmpty())
                continue;
            /* native tools aren't preprocessed */
            if (!isnativebin)
                t << writeOne((*it).toQString(), pathtoremove);
            else
                t << (*it).toQString().remove(pathtoremove) << "\n";
        }
    }
    t << "\n";

    {
        const ProStringList &l = project->values("GENERATED_SOURCES");
        for (ProStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
            t << "work/" << (*it).toQString().section(QDir::separator(), -1) << "\n";
        }
    }

    return true;
}
Пример #28
0
int host_gui_exiting()
{
    int err = lo_send(_osc_host_addr, tmpstr("%s/exiting", _osc_path), "");
    return err;
}
Пример #29
0
    vector<string> generateParenthesis(int n) {
        vector<string> res;
        if(n<01)
            return res;
        res.push_back("()");
        for (int i = 1; i < n; ++i) {
            //left parenthesis
            set<string> tmp;
            for(const auto& str: res){
                for(int j = 0; j < str.length(); ++j){
                    if(j == 0 || str[j-1] != '('){
                        string tmpstr(str);
                        tmpstr.insert(j, 1, '(');
                        tmp.insert(move(tmpstr));
                    }
                }
                string tmpstr(str);
                if(tmpstr.back() != '(')
                    tmpstr.push_back('(');
                tmp.insert(move(tmpstr));
            }
            //right parenthensis
            set<string> tmp2;
            for(const auto& str: tmp) {
                int left = 0;
                int right = 0;
                for (int j = 0; j < str.length(); ++j) {
                    if (j>0 && left > right && str[j - 1] == '(') {
                        int k = j;
                        int kleft = left;
                        int kright = right;
                        bool binsert = true;
                        for (int k = j; k < str.length() ; ++k){
                            if(str[k] == '(')
                                ++kleft;
                            else{
                                ++kright;
                                if(kleft <= kright)
                                    binsert = false;
                            }
                        }

                        if(binsert ){
                            string tmpstr(str);
                            tmpstr.insert(j, 1, ')');
                            #ifdef DEBUG
                                cout << j << ":" << str << "-->" << tmpstr << "\n";
                            #endif
                            tmp2.insert(move(tmpstr));
                        }
                    }
                    if(str[j] == '(')
                        ++left;
                    else if(str[j] == ')')
                        ++right;
                }
            }
            res.assign(tmp2.begin(), tmp2.end());
        }
        return res;
    }
Пример #30
0
void XMLParser::Error(const char* errstr, const char* param1)
{
	std::string tmpstr(errstr);
	tmpstr += param1;
	Error(tmpstr.c_str());
}