Beispiel #1
0
int main(){
  char s[10]="hello";
  printf("%s: %d\n",s,slen(s)); //testing for slen
  char cpy[15]="aba";
  printf("After scpy, %s became: ",cpy);
  scpy(cpy,s);
  printf("%s\n",cpy);
  char ncpy[15]="abalaba";
  printf("After sncpy (n=3), %s became: ",ncpy);
  sncpy(ncpy,s,3);
  printf("%s\n",ncpy);
  char cat[15]="AddOn";
  printf("After scat, %s became: ",cpy);
  scat(cpy,cat);
  printf("%s\n",cpy);
  char s2[18]="hello";
  char s3[5]="po";
  char s4[5]="bao";
  printf("scmp %s and %s: %d\n",s,s2,scmp(s,s2));
  printf("scmp %s and %s: %d\n",s,cpy,scmp(s,cpy));
  printf("scmp %s and %s: %d\n",s,s3,scmp(s,s3));
  printf("scmp %s and %s: %d\n",s,s4,scmp(s,s4));
  printf("schr %s and %c: %s\n",s,'l',schr(s,'l'));
  printf("schr %s and %c: %s\n",s,'t',schr(s,'t'));
  char s5[5]="el";
  printf("sstr %s and %s: %s\n",s,s5,sstr(s,s5));
  printf("sstr %s and %s: %s\n",s,s3,sstr(s,s3));
  return 0;
}
Beispiel #2
0
void gui_settings::ShowBox(bool confirm, const QString& title, const QString& text, const gui_save& entry, int* result = nullptr, QWidget* parent = nullptr)
{
	const std::string dialog_type = confirm ? "Confirmation" : "Info";

	if (entry.name.isEmpty() || GetValue(entry).toBool())
	{
		const QFlags<QMessageBox::StandardButton> buttons = confirm ? QMessageBox::Yes | QMessageBox::No : QMessageBox::Ok;
		const QMessageBox::Icon icon = confirm ? QMessageBox::Question : QMessageBox::Information;

		QMessageBox* mb = new QMessageBox(icon, title, text, buttons, parent);
		mb->deleteLater();

		if (!entry.name.isEmpty())
		{
			mb->setCheckBox(new QCheckBox(tr("Don't show again")));
		}

		connect(mb, &QMessageBox::finished, [&](int res)
		{
			if (result)
			{
				*result = res;
			}
			if (!entry.name.isEmpty() && mb->checkBox()->isChecked())
			{
				SetValue(entry, false);
				LOG_NOTICE(GENERAL, "%s Dialog for Entry %s is now disabled", dialog_type, sstr(entry.name));
			}
		});

		mb->exec();
	}
	else LOG_NOTICE(GENERAL, "%s Dialog for Entry %s was ignored", dialog_type, sstr(entry.name));
}
Beispiel #3
0
int mail_OpenSession( KMail mail, int tls, AuthType auth )
{
    if( !smtp_OpenSession( mail->smtp, sstr( mail->host ), mail->port, tls ) )
    {
        return mail_set_SMTP_error( mail );
    }

    if( auth == AUTH_PLAIN )
    {
        if( !smtp_AUTH_PLAIN( mail->smtp, sstr( mail->login ),
                sstr( mail->password ) ) ) return mail_set_SMTP_error( mail );
    }
    else if( auth == AUTH_LOGIN )
    {
        if( !smtp_AUTH_LOGIN( mail->smtp, sstr( mail->login ),
                sstr( mail->password ) ) ) return mail_set_SMTP_error( mail );
    }
    else
    {
        mail_FormatError( mail, "Unknown AUTH type: %d", auth );
        return 0;
    }

    return 1;
}
Beispiel #4
0
static int mail_AttachFiles( KMail mail, KMsg msg, const char * boundary )
{
    struct _MFile file =
    { NULL, NULL };
    Pair afile = lfirst( msg->afiles );
    file.headers = snew();

    while( afile )
    {
        if( !msg_CreateFile( msg, &file, mail->error, boundary, F_NAME(afile),
                F_CTYPE(afile), "attachment", NULL ) )
        {
            return delMFile( &file );
        }
        if( !smtp_write( mail->smtp, sstr( file.headers ) )
                || !smtp_write( mail->smtp, sstr( file.body ) )
                || !smtp_write( mail->smtp, "\r\n" ) )
        {
            mail_FormatError( mail, "mail_AttachFiles(\"%s\"), internal error",
                    F_NAME(afile) );
            return delMFile( &file );
        }
        afile = lnext( msg->afiles );
    }
    delMFile( &file );
    return 1;
}
Beispiel #5
0
static int mail_EmbedFiles( KMail mail, KMsg msg, const char * boundary )
{
    struct _MFile file =
    { NULL, NULL };
    EFile efile = lfirst( msg->efiles );
    file.headers = snew();

    while( efile )
    {
        if( !msg_CreateFile( msg, &file, mail->error, boundary, efile->name,
                efile->ctype, "inline", efile->cid ) )
        {
            return delMFile( &file );
        }
        if( !smtp_write( mail->smtp, sstr( file.headers ) )
                || !smtp_write( mail->smtp, sstr( file.body ) )
                || !smtp_write( mail->smtp, "\r\n" ) )
        {
            mail_FormatError( mail, "mail_EmbedFiles(\"%s\"), internal error",
                    efile->name );
            return delMFile( &file );
        }
        efile = lnext( msg->efiles );
    }
    delMFile( &file );
    return 1;
}
Beispiel #6
0
void cg_disasm_window::ShowDisasm()
{
	if (QFileInfo(m_path_last).isFile())
	{
		CgBinaryDisasm disasm(sstr(m_path_last));
		disasm.BuildShaderBody();
		m_disasm_text->setText(qstr(disasm.GetArbShader()));
		m_glsl_text->setText(qstr(disasm.GetGlslShader()));
	}
	else if (!m_path_last.isEmpty())
	{
		LOG_ERROR(LOADER, "CgDisasm: Failed to open %s", sstr(m_path_last));
	}
}
void GuessMyNumber::OnGuessClick() {
	// Validate number.
	unsigned int buf_number( 0 );

	std::stringstream sstr( static_cast<std::string>( m_number_entry->GetText() ) );
	sstr >> buf_number;

	if( buf_number < 1 || buf_number > 100 ) {
		m_hint_label->SetText( "Enter a number from 1 to 100." );
		return;
	}

	++m_tries;
	UpdateUI();

	unsigned char number( static_cast<unsigned char>( buf_number ) );
	if( number < m_number ) {
		m_hint_label->SetText( "My number is higher." );
	}
	else if( number > m_number ) {
		m_hint_label->SetText( "My number is lower." );
	}
	else {
		m_hint_label->SetText( "Correct!" );
		m_guess_button->Show( false );
	}

	m_number_entry->SetText( "" );
}
Beispiel #8
0
void Graph::read_line( std::string line, std::vector<int> * tmp ) {
    int n;
    std::istringstream sstr (line);
    while(sstr >> n) {
	tmp->push_back(n);
    };
};
Beispiel #9
0
double EXParser::strToDbl(const std::string num)
{
	double val;
	std::istringstream sstr(num);
	sstr>>std::setprecision(decimal_precision)>>val;
	return val;
}
int ThingSpeakClient::GetField(char *s_field, char *e_field) {
	char *s_fld = "<field5>";
	char *e_fld = "</field5>";

	if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
	   {
		   perror("ThingSpeak_connect");
		   //return -1;
	   }

	   char message[]= "GET /channels/46795/feeds.xml?results=2\r\n\r\n";
	   fcntl(sock, F_SETFL, O_NONBLOCK);
	   send(sock, message, sizeof(message), 0);
	   sleep(1);
	   if (recv(sock, buf, 16048, 0)>=0)	{
		   std::string sstr(buf);
		   pos = sstr.find("<feed>");
		   start_pos = sstr.find(s_field, pos)+8;
		   end_pos = sstr.find(e_field, start_pos)-1;
		   result[0] = sstr[start_pos];
		   result[1] = sstr[end_pos];
		   result[3]= 0;
		   humidity = (result[0]-48)*10+(result[1]-48);
		   close(sock);


		   return humidity;
	   }
	   else return 0;
}
/**
 *  初始化我们的数据成员,顶点数和弧数
 * 格式:4 7
 */
void MGraphDG::intiVAnum(std::string line)
{
	std::stringstream sstr(line);	//用这个类可以很好地处理string类型
	std::string num1, num2;
	sstr >> num1 >> num2;	//获取两个数字的字符串
	this->vexnum = atoi(num1.c_str());
	this->arcnum = atoi(num2.c_str());
}
Beispiel #12
0
 std::string CapabilitiesGetLanguage()
 {
    Platform::String^ rtstr = ( Windows::System::UserProfile::GlobalizationPreferences::Languages )->GetAt(0);
    //Platform::String to std::string
    std::wstring wsstr( rtstr->Begin() );
    std::string sstr( wsstr.begin(), wsstr.end() );
    return sstr;
 }
// -----------------------------------------------------------------------------------------
int CPepeEngineConverter::parseInt(const tstring& str)
{
    tstringstream sstr(str);
    int ret = 0;
    sstr >> ret;

    return ret;
}
Beispiel #14
0
std::string getUniformStructLocStr(const std::string &structName, const std::string &memberName, int arrayIndex = -1) {
    std::stringstream sstr("");
    sstr << structName;
    if (arrayIndex >= 0) {
        sstr << "[" << arrayIndex << "]";
    }
    sstr << "." << memberName;
    return sstr.str();
}
Beispiel #15
0
TEST(TestSymbolString, testUnescaped)
{
    SymbolString sstr(false);

    auto result = sstr.parseHex("10feb5050427a90015a90177", true);
    ASSERT_EQ(result, RESULT_OK);

    ASSERT_EQ(sstr.getDataStr(true, false),"10feb5050427a915aa77");
}
Beispiel #16
0
bool Coin::onPlayerSteping( Player* player )
{
	Label* text = Label::createWithTTF( sstr("+%d",m_coin), "fonts/Marker Felt.ttf", 32);
	text->setColor(Color3B(255,215,64));
	text->setPosition(getPosition());
	text->runAction( Sequence::create(MoveBy::create(2, Vec2(0, 64)), CCCallFunc::create(std::bind(&CCNode::removeFromParent, text)), 0) );
	text->setLocalZOrder(player->getLocalZOrder());
	getParentCell()->playTopEffect(text);
	return true;
}
Beispiel #17
0
Animation* TrapFire::fireAnimation( int end_pos )
{
	Animation* animation = Animation::create();
	animation->setDelayPerUnit( end_pos==2 ? 1/10.0f : 1/20.0f );
	for (int i=0; i<end_pos; ++i)
	{
		animation->addSpriteFrameWithFile( sstr("fire_%03d.png", i) );
	}
	animation->addSpriteFrameWithFile( "fire_000.png" );
	return animation;
}
 template <typename T> const T get(const std::string &key) const throw(PropertyConversionFailed, PropertyLookupFailed) {
     const std::string val(get(key));
     std::stringstream sstr(val);
     T ret;
     sstr >> ret;
     if (!sstr) {
         throw PropertyConversionFailed(key, val);
     } else {
         return ret;
     }
 }
Beispiel #19
0
bool NonLegacyRenderer::IsAvailable() {
	static bool checked = false;

	if( !checked ) {
		// Make sure we have a valid GL context before messing around
		// with GLLoader or else it will report missing extensions sometimes.
		sf::Context context;

		if( !gl_initialized ) {
			auto result = sfgogl_LoadFunctions() - sfgogl_LOAD_SUCCEEDED;

			if( result ) {
#if defined( SFGUI_DEBUG )
				std::cerr << "GL extension initialization failed. Missing " << result << " functions.\n";
#endif
				return false;
			}

			gl_initialized = true;
		}

		if( GLEXT_vertex_buffer_object ) {
			vbo_supported = true;
		}

		if( GLEXT_vertex_program ) {
			vap_supported = true;
		}

		if( sf::Shader::isAvailable() ) {
			auto glsl_version_string = CheckGLError( glGetString( GLEXT_GL_SHADING_LANGUAGE_VERSION ) );

			if( glsl_version_string ) {
				std::stringstream sstr( reinterpret_cast<const char*>( glsl_version_string ) );
				auto version = 0.0;
				sstr >> version;

				if( version > 1.29 ) {
					shader_supported = true;
				}
			}
		}

		if( GLEXT_vertex_array_object ) {
			vao_supported = true;
		}

		if( GLEXT_framebuffer_object ) {
			fbo_supported = true;
		}

		checked = true;
	}
// -----------------------------------------------------------------------------------------
size_t CPepeEngineConverter::parseUnsignedInt(const tstring& str)
{
    if (str == _T("none")) {
        return 0;
    }

    tstringstream sstr(str);
    unsigned int ret = 0;
    sstr >> ret;

    return ret;
}
void comm_param_settings::business_channel_confirm_event()
{
    char buffer[256];
    std::ifstream in(_path.toStdString());
    if (! in.is_open())
    {
        std::cout << "Error opening file";
        QMessageBox::information(this, QString::fromStdString("警告"),QString::fromStdString("文件读取失败!"));
        return; }
    int lineNum = 0;  //行号.
    while (!in.eof() )
    {
        in.getline (buffer,256);
        lineNum++;
        //读取一行的数据
        std::string  strline = buffer;
        if( lineNum >= 1 )
        {
            if(strline[strline.length()-1]=='\n')
            {
                strline.erase(strline.length()-1,1);
            }
            //将分割后的字符串写到字符串数组
            std::vector<std::string> stu;  //存放一行数据的数组
            std::stringstream sstr(strline);
            std::string token;
            while(getline(sstr, token, ' '))
            {
                stu.push_back(token);
            }
            //根据数组中数据给创建的结构体赋值
            PG_RTUI_StaticRoute *data = new PG_RTUI_StaticRoute();
            data->clientAddr.ip_addr =_ip;//ip uInt32_t型
            data->clientAddr.port = 65500;//port  uInt32_t型
            data->type = ePG_RTUI_static_route; //type
            data->length = sizeof(PG_RTUI_StaticRoute);//lengrh大小

            data->pdsi_delay_time = 0;
            data->nodeId = std::stoi(stu[0]);
            strcpy(data->dst_ip,stu[1].data());
            strcpy(data->nxt_hop,stu[2].data());
            strcpy(data->out_itf_ip,stu[3].data());
            data->cost = std::stoi(stu[4]);
            //发送数据给qualnet通信软件
            _msHandler->config_comm_param(data);
        }
        //2.将文本数据显示在list缓存
        current_cloud_id_list.push_back(QString::fromStdString(strline));
    }
    //current_cloud_id_list.push_back(QString::fromStdString("strline"));//再次往list中添加数据
    model->setStringList(current_cloud_id_list);//往listView中添加数据
    ui->listView->setModel(model);
}
Beispiel #22
0
	int Value::ToInt() const
	{
		if (IsNumber())
		{
			std::stringstream sstr(valueStr);
			int val;
			sstr >> val;
			return val;
		}
		else
		{
			return 0;
Beispiel #23
0
/**
 * \brief Reads a line from a file and adds the data
 * Reads a line from a file, replaces , with <TAB>  and casts it as a double
 * \param std::string line - line to read
 */
void Plotter::read_line(std::string line){
  std::string first,sec;
  std::string TR = line.c_str();
  std::replace(TR.begin(),TR.end(),',','\t');
  std::stringstream sstr(TR);
  sstr >> first >> sec;
  if(check(first) &&check(sec)){
    double _first = boost::lexical_cast<double>(first);
    double _sec = boost::lexical_cast<double>(sec);
    data_x.push_back(_first);
    data_y.push_back(_sec);
  }
}
//Returns value of Pi as a string accurate to a certain number of digits.
std::string piAccTo(int digitsAcc){
	//Approximating pi using an integer fraction to double then to ostringstream, then to string.
	std::ostringstream sstr("");
	sstr << std::fixed << std::setprecision(digitsAcc);
	sstr << double(2549491779)/811528438;
	std::string strPi = sstr.str();
	//Next ostringstream for getting the correct number of digits of accuracy.
	std::ostringstream endSstr("");
	for (int i = 0; i <= digitsAcc; i++){
		endSstr << strPi[i];
	}
	std::string newPi = endSstr.str();
	return newPi;
}
Beispiel #25
0
int main() {
    std::cout << " host is " << (is_big_endian() ? "big endian\n" : "little endian\n");
    
    unsigned int uliteral = 0x456e7120;
    int sliteral = 0x456e7120;
    std::cout << " unsigned 0x456e7120 = " << uliteral << "\n";
    std::cout << "   signed 0x456e7120 = " << sliteral << "\n";
    
    std::stringstream sstr(std::ios::binary);
    // Write 0x456e7120 in little endian to stream
    sstr << 0x20 << 0x71 << 0x6e << 0x45 << std::flush;
    std::cout << " " << parse_uint32(std::istreambuf_iterator<char>(sstr)) << "\n";
    return 0;
}
Beispiel #26
0
void  ConfigFile::Remove(CTSTR lpSection, CTSTR lpKey)
{
    assert(lpSection);
    assert(lpKey);
    TSTR lpTemp = lpFileData, lpEnd = &lpFileData[dwLength], lpSectionStart;
    DWORD dwSectionNameSize = slen(lpSection), dwKeyNameSize = slen(lpKey);
    BOOL  bInSection = 0;

    do
    {
        lpTemp = sstr(lpTemp, TEXT("\n["));
        if(!lpTemp)
            break;

        lpTemp += 2;
        if((scmpi_n(lpTemp, lpSection, dwSectionNameSize) == 0) && (lpTemp[dwSectionNameSize] == ']'))
        {
            bInSection = 1;
            lpSectionStart = lpTemp = schr(lpTemp, '\n')+1;
            break;
        }
    }while(lpTemp < lpEnd);

    if(!bInSection)
        return;  //not possible, usually.

    do
    {
        if(*lpTemp == '[')
            return;
        else if(bInSection && (*(LPWORD)lpTemp != '//'))
        {
            if((scmpi_n(lpTemp, lpKey, dwKeyNameSize) == 0) && (lpTemp[dwKeyNameSize] == '='))
            {
                TSTR lpNextLine = schr(lpTemp, '\n')+1;
                XFile file(strFileName, XFILE_WRITE, XFILE_CREATEALWAYS);
                file.Write("\xEF\xBB\xBF", 3);
                file.WriteAsUTF8(&lpFileData[2], DWORD(lpTemp-lpFileData-2));
                file.WriteAsUTF8(lpNextLine, slen(lpNextLine)-2);
                file.Close();

                if(LoadFile(XFILE_OPENEXISTING))
                    LoadData();
                return;
            }
        }

        lpTemp = schr(lpTemp, '\n')+1;
    }while(lpTemp < lpEnd);
}
Beispiel #27
0
void FFmpeg_Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType *type)
{
    if(!mStream)
        fail("No audio stream info");

    if((*mStream)->codec->sample_fmt == AV_SAMPLE_FMT_U8)
        *type = SampleType_UInt8;
    else if((*mStream)->codec->sample_fmt == AV_SAMPLE_FMT_S16)
        *type = SampleType_Int16;
    else if((*mStream)->codec->sample_fmt == AV_SAMPLE_FMT_FLT)
        *type = SampleType_Float32;
    else
        fail(std::string("Unsupported sample format: ")+
             av_get_sample_fmt_name((*mStream)->codec->sample_fmt));

    if((*mStream)->codec->channel_layout == AV_CH_LAYOUT_MONO)
        *chans = ChannelConfig_Mono;
    else if((*mStream)->codec->channel_layout == AV_CH_LAYOUT_STEREO)
        *chans = ChannelConfig_Stereo;
    else if((*mStream)->codec->channel_layout == AV_CH_LAYOUT_QUAD)
        *chans = ChannelConfig_Quad;
    else if((*mStream)->codec->channel_layout == AV_CH_LAYOUT_5POINT1)
        *chans = ChannelConfig_5point1;
    else if((*mStream)->codec->channel_layout == AV_CH_LAYOUT_7POINT1)
        *chans = ChannelConfig_7point1;
    else if((*mStream)->codec->channel_layout == 0)
    {
        /* Unknown channel layout. Try to guess. */
        if((*mStream)->codec->channels == 1)
            *chans = ChannelConfig_Mono;
        else if((*mStream)->codec->channels == 2)
            *chans = ChannelConfig_Stereo;
        else
        {
            std::stringstream sstr("Unsupported raw channel count: ");
            sstr << (*mStream)->codec->channels;
            fail(sstr.str());
        }
    }
    else
    {
        char str[1024];
        av_get_channel_layout_string(str, sizeof(str), (*mStream)->codec->channels,
                                     (*mStream)->codec->channel_layout);
        fail(std::string("Unsupported channel layout: ")+str);
    }

    *samplerate = (*mStream)->codec->sample_rate;
}
Beispiel #28
0
	int Value::AsInt() const
	{
		if (IsNull())
			return 0;
		else
		{
			if (IsInt() || IsDouble())
			{
				std::stringstream sstr(valueStr);
				int val;
				sstr >> val;
				return val;
			}
			else
				throw ValueException();
Beispiel #29
0
std::unique_ptr<llvm::MemoryBuffer> PystonObjectCache::getObject(const llvm::Module* M)
#endif
{
    static StatCounter jit_objectcache_hits("num_jit_objectcache_hits");
    static StatCounter jit_objectcache_misses("num_jit_objectcache_misses");

    module_identifier = M->getModuleIdentifier();

    RELEASE_ASSERT(!hash_before_codegen.empty(), "hash should have already got calculated");

    if (!haveCacheFileForHash()) {
#if 0
            // This code helps with identifying why we got a cache miss for a file.
            // - clear the cache directory
            // - run pyston
            // - run pyston a second time
            // - Now look for "*_second.ll" files in the cache directory and compare them to the "*_first.ll" IR dump
            std::string llvm_ir;
            llvm::raw_string_ostream sstr(llvm_ir);
            M->print(sstr, 0);
            sstr.flush();

            llvm::sys::fs::create_directories(cache_dir.str());
            std::string filename = cache_dir.str().str() + "/" + module_identifier + "_first.ll";
            if (llvm::sys::fs::exists(filename))
                filename = cache_dir.str().str() + "/" + module_identifier + "_second.ll";
            FILE* f = fopen(filename.c_str(), "wt");
            ASSERT(f, "%s", strerror(errno));
            fwrite(llvm_ir.c_str(), 1, llvm_ir.size(), f);
            fclose(f);
#endif

        // This file isn't in our cache
        jit_objectcache_misses.log();
        return NULL;
    }

    llvm::SmallString<128> cache_file = cache_dir;
    llvm::sys::path::append(cache_file, hash_before_codegen);
    std::unique_ptr<llvm::MemoryBuffer> mem_buff = CompressedFile::getFile(cache_file);
    if (!mem_buff) {
        jit_objectcache_misses.log();
        return NULL;
    }

    jit_objectcache_hits.log();
    return mem_buff;
}
Beispiel #30
0
Mensa::Mensa(const Configs& cfg)
	: multiHandle(curl_multi_init()),
	lastupdate(0),
	updating(false)
{
	cfg.GetValue("menuurl", menuurl);
	cfg.GetValue("metaurl", metaurl);
	cfg.GetValue("login", login);
	cfg.GetValue("canteen", canteen);
	std::string rawlines;
	cfg.GetValue("lines", rawlines);
	std::istringstream sstr(rawlines);
	std::string newline;
	while(std::getline(sstr, newline, ','))
		lines.insert(newline);
}