Exemplo n.º 1
0
SP_NAMESPACE_START


//////////////////////////////////////////////////////////////////////////
// functions
//////////////////////////////////////////////////////////////////////////


/**********************************************************************************************/
void BindValue( 
	sqlite3_stmt*	stmt,
	int				index,
	const Value&	vl )
{
	switch( vl.mType )
	{
		case kUnknown	: sqlite3_bind_null( stmt, index ); break;
		case kBLOB		: /* TODO : sqlite3_bind_blob */ break;
		case kDouble	: sqlite3_bind_double( stmt, index, vl.ToDouble() ); break;
		case kInt		: sqlite3_bind_int( stmt, index, vl.ToInt() ); break;

		case kText	:
		{
			vector<char> buf;
			ConvertToUTF8( vl.ToString(), buf );
			sqlite3_bind_text( stmt, index, &buf[ 0 ], -1, SQLITE_TRANSIENT );
		}
		break;
		
		default:;
	}
}
Exemplo n.º 2
0
void InfoView::UpdateAwayDisplay( BMessage* message ) {

	// away message
	if( message->HasString("away_message" ) ) {

		HTMLParser parse;
		styleList styles;	
		BString origMsg = BString((char*)message->FindString("away_message"));

		// translate it into UTF-8
		origMsg = ConvertToUTF8( origMsg, encoding );

		// handle the away message variables
		client->ReplaceTagVars( origMsg );

		// automatically link the web and mail addresses that weren't linked
		Linkify( origMsg );

		// Now parse the bad boy and display the results
		awaymessage->SetText("");
		awaymessage->ClearInsertStuff();
		awaymessage->ResetFontToBase();
		parse.Parse( const_cast<char*>(origMsg.String()) );
		styles = parse.Styles();
		awaymessage->SetViewColor( styles.bgColor.R(), styles.bgColor.G(), styles.bgColor.B() );
		awaymessage->Invalidate();
		awaymessage->AddStyledText( parse.ParsedString(), styles );
		styles.Clear();
		awaymessage->AddStatement();
	} 
}
Exemplo n.º 3
0
void Function::Compile( sqlite3_context* ctx )
{
	Parser ps( mVM, mText );	

	if( ps.mErr.size() )
	{
		mCompiled = false;
		
		vector<char> buf;
		ConvertToUTF8( ps.mErr, buf );
		sqlite3_result_error( ctx, &buf[ 0 ], buf.size() - 1 );
	}
	else
	{
		mCompiled = true;
	}
}
Exemplo n.º 4
0
int SqliteExecute(
	sqlite3*		db,
	const wstring&	query )
{
	vector<char> buf;
	ConvertToUTF8( query, buf );

	const char* pq = &buf[ 0 ];
	SkipTabulation( pq );
	
	sqlite3_stmt* stmt = NULL;
	int qres = sqlite3_prepare_v2( db, pq, -1, &stmt, &pq );
	if( qres == SQLITE_OK ) 
		sqlite3_step( stmt );
		
	FINALIZE_STATEMENT( stmt );
	return qres;
}
Exemplo n.º 5
0
sqlite3_stmt* SqliteSelect(
	sqlite3*		db,
	const wstring&	query )
{
	vector<char> buf;
	ConvertToUTF8( query, buf );

	const char* pq = &buf[ 0 ];
	SkipTabulation( pq );

	sqlite3_stmt* stmt = NULL;

	int qres = sqlite3_prepare_v2( db, pq, -1, &stmt, &pq );
	if( qres == SQLITE_OK )
	{
		int ccount = sqlite3_column_count( stmt );
		if( ccount > 0 )
			return stmt;
	}

	FINALIZE_STATEMENT( stmt );
	return NULL;
}
Exemplo n.º 6
0
/*
** Substitutes part of the text
*/
const WCHAR* CMeasure::CheckSubstitute(const WCHAR* buffer)
{
	static std::wstring str;

	if (!m_Substitute.empty())
	{
		if (!m_RegExpSubstitute)	// Plain Substitutions only
		{
			str = buffer;

			for (size_t i = 0, isize = m_Substitute.size(); i < isize; i += 2)
			{
				if (!m_Substitute[i].empty())
				{
					MakePlainSubstitute(str, i);
				}
				else if (str.empty())
				{
					// Empty result and empty substitute -> use second
					str = m_Substitute[i + 1];
				}
			}
		}
		else // Contains a RegEx
		{
			std::string utf8str = ConvertToUTF8(buffer);
			int* ovector = new int[OVECCOUNT];

			for (size_t i = 0, isize = m_Substitute.size(); i < isize ; i += 2)
			{
				pcre* re;
				const char* error;
				int erroffset;
				int rc;
				int flags = PCRE_UTF8;
				int offset = 0;

				re = pcre_compile(
					ConvertToUTF8(m_Substitute[i].c_str()).c_str(),   // the pattern
					flags,						// default options
					&error,						// for error message
					&erroffset,					// for error offset
					NULL);						// use default character tables

				if (re == NULL)
				{
					MakePlainSubstitute(str, i);
					Log(LOG_NOTICE, ConvertToWide(error).c_str());
				}
				else
				{
					do
					{
						rc = pcre_exec(
							re,						// the compiled pattern
							NULL,					// no extra data - we didn't study the pattern
							utf8str.c_str(),		// the subject string
							utf8str.length(),		// the length of the subject
							offset,					// start at offset 0 in the subject
							0,						// default options
							ovector,				// output vector for substring information
							OVECCOUNT);				// number of elements in the output vector

						if (rc <= 0)
						{
							break;
						}
						else
						{
							std::string result = ConvertToUTF8(m_Substitute[i + 1].c_str());

							if (rc > 1)
							{
								for (int j = rc - 1 ; j >= 0 ; --j)
								{
									size_t new_start = ovector[2 * j];
									size_t in_length = ovector[2 * j + 1] - ovector[2 * j];

									char tmpName[64];

									size_t cut_length = _snprintf_s(tmpName, _TRUNCATE, "\\%i", j);;
									size_t start = 0, pos;
									do
									{
										pos = result.find(tmpName, start, cut_length);
										if (pos != std::string::npos)
										{
											result.replace(pos, cut_length, utf8str, new_start, in_length);
											start = pos + in_length;
										}
									}
									while (pos != std::string::npos);
								}
							}

							size_t start = ovector[0];
							size_t length = ovector[1] - ovector[0];
							utf8str.replace(start, length, result);
							offset = start + result.length();
						}
					}
					while (true);

					// Release memory used for the compiled pattern
					pcre_free(re);
				}
			}

			delete [] ovector;

			str = ConvertUTF8ToWide(utf8str.c_str());
		}

		return str.c_str();
	}
	else
	{
		return buffer;
	}
}
Exemplo n.º 7
0
void LuaManager::PushWide(lua_State* L, const WCHAR* str)
{
	lua_pushstring(L, ConvertToUTF8(str).c_str());
}
void CSQLiteConversion::SqliteStatementExecution(std::vector<CString> &statements, sqlite3 *&sqlitedatabase, int rc , wxGauge *&gauge, unsigned &nValue, wxTextCtrl *&PrgDlg,
        unsigned &nErrorCount, CString *sTableNames, unsigned &flag, unsigned &nTableCount, int *IndexTable, CString *sTableNames2)
{
    char *zErrMsg = 0;
    unsigned index = 0;
    auto end_it = statements.end();
    for( auto it = statements.begin(); it != end_it; ++it )
    {
        ++nValue;
        gauge ->SetValue(nValue);
        std::string sB = ConvertToUTF8(*it);
        const char* pszC = _strdup(sB.c_str());
        rc = sqlite3_exec(sqlitedatabase, pszC, NULL, 0, &zErrMsg);
        if( rc != SQLITE_OK )
        {
            ++nErrorCount;
            PrgDlg->SetDefaultStyle(wxTextAttr (wxNullColour, *wxRED));
            wxString ErrorMessage = wxT("");
            ErrorMessage += wxString::FromUTF8(zErrMsg);
            ErrorMessage += " \n";
            PrgDlg->WriteText(ErrorMessage);
            CT2CA pszConvertedAnsiString (*it);
            std::string strStd (pszConvertedAnsiString);
            ErrorMessage = wxString::FromUTF8(_strdup(strStd.c_str() ) ) + "\n";
            PrgDlg->WriteText(ErrorMessage);
            if(flag & 1)
            {
                ErrorMessage = wxT("Table: ");
                sB = ConvertToUTF8(sTableNames[nValue-1]);
                ErrorMessage += wxString::FromUTF8(_strdup(sB.c_str() ) );
                ErrorMessage += wxT(" wasnt created succesfully \n");
                PrgDlg->WriteText(ErrorMessage);
            }
            PrgDlg->SetDefaultStyle(wxTextAttr (wxNullColour));
            sqlite3_free(zErrMsg);
        }
        else
        {
            if(flag & ExecuteTables)
            {
                wxString sMessage = wxT("Table: ");
                sB = ConvertToUTF8(sTableNames[nValue-1]);
                sMessage += wxString::FromUTF8(_strdup(sB.c_str() ) );
                sMessage += wxT(" created succesfully \n");
                PrgDlg->WriteText(sMessage);
            }
            else if(flag & ExecuteInserts)
            {
                if(*it == "END TRANSACTION")
                {
                    sTableNames[index];
                    wxString sMessage = wxT("Table: ");
                    sB = ConvertToUTF8(sTableNames[index]);
                    sMessage += wxString::FromUTF8(_strdup(sB.c_str() ) );
                    sMessage += wxT(" records inserted \n");
                    ++index;
                    PrgDlg->WriteText(sMessage);
                }
            }
            else if(flag & ExecuteIndexes)
            {
                if( index < nTableCount )
                {
                    while( !IndexTable[index] )
                    {
                        wxString sMessage = wxT("indexes of table: ");
                        sB = ConvertToUTF8(sTableNames2[index]);
                        sMessage += wxString::FromUTF8(_strdup(sB.c_str() ) );
                        sMessage += wxT(" created \n");
                        PrgDlg->WriteText(sMessage);
                        ++index;
                    }
                }
                IndexTable[index]--;
                if( index < nTableCount )
                {
                    if( !IndexTable[index] )
                    {
                        wxString sMessage = wxT("indexes of table: ");
                        sB = ConvertToUTF8(sTableNames2[index]);
                        sMessage += wxString::FromUTF8(_strdup(sB.c_str() ) );
                        sMessage += wxT(" created \n");
                        PrgDlg->WriteText(sMessage);
                        ++index;
                    }
                }
                if(index < nTableCount )
                {
                    while( !IndexTable[index] )
                    {

                        wxString sMessage = wxT("indexes of table: ");
                        sB = ConvertToUTF8(sTableNames2[index]);
                        sMessage += wxString::FromUTF8(_strdup(sB.c_str() ) );
                        sMessage += wxT(" created \n");
                        PrgDlg->WriteText(sMessage);
                        ++index;
                    }
                }

            }
        }
    }
}
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
	POINT mouse;
	//while (true)
	{
		GetCursorPos(&mouse);
		printf("\r%d-%d         ", mouse.x, mouse.y);
	}
	

	return interlace_RGB();
	return matrix();

//	char URI[] = "//mnt/sdcard/%E9%98%BF%E4%B8%BD%E4%BA%9A%E5%A8%9C%E5%90%89%E5%88%A9%E6%96%AF-%20Shake%E8%8B%B9%E6%9E%9C.3dv";
	char URI[] = "//mnt/sdcard/HELLO!.3dv";
	char decoded_URI[1024];

	URIDecode(URI, decoded_URI, sizeof(decoded_URI));

	char k = 0xef;

	bool a = k == 0xef;


    const int frame_w = 1920;
    const int frame_h = 1080;

	setlocale(LC_ALL, "CHS");

    if (argc < 4) {
        printf("usage: %s <image file> <subtitle file> <time>\n", argv[0]);
        exit(1);
    }

    char *imgfile = argv[1];
    char *subfile = argv[2];
    double tm = strtod(argv[3], 0);

	FILE * f = fopen(subfile, "rb");
	fseek(f, 0, SEEK_END);
	int file_size = ftell(f);
	fseek(f, 0, SEEK_SET);
	char *src = (char*)malloc(file_size);
	char *utf8 = (char*)malloc(file_size*3);
	fread(src, 1, file_size, f);
	fclose(f);

	int utf8_size = ConvertToUTF8(src, file_size, utf8, file_size*3);

	ass_library = ass_library_init();
	if (!ass_library) {
		printf("ass_library_init failed!\n");
		exit(1);
		}

	//ass_set_message_cb(ass_library, msg_callback, NULL);

	//ass_set_extract_fonts(ass_library, 0);
	//ass_set_style_overrides(ass_library, NULL);


	ass_renderer = ass_renderer_init(ass_library);
	if (!ass_renderer) {
		printf("ass_renderer_init failed!\n");
		exit(1);
		}


	ass_set_frame_size(ass_renderer, frame_w, frame_h);
	ass_set_font_scale(ass_renderer, 1.0);
	//ass_set_hinting(ass_renderer, ASS_HINTING_NORMAL);
	ass_set_fonts(ass_renderer, "Arial", "Sans", 1, "Z:\\fonts.conf", 1);
	
	ASS_Track *track = ass_read_memory(ass_library, utf8, utf8_size, NULL);

	free(src);
	free(utf8);

    if (!track) {
        printf("track init failed!\n");
        return 1;
    }

    ASS_Image *img = NULL;
	int n = 0;
	int changed = 0;
	image_t *frame = gen_image(frame_w, frame_h);
	int n2 = 0;
	int l = GetTickCount();
	timeBeginPeriod(1);
	for(int i=0; i<int(tm*1000); i+=40)
	{
		img = ass_render_frame(ass_renderer, track, i, &changed);

		if (n==0) l = GetTickCount();
		if (changed && img)
		{
			int l = timeGetTime();
			n++;
			memset(frame->buffer, 63, frame->stride * frame->height);
			blend(frame, img);
			wchar_t pathname[MAX_PATH];
			wsprintfW(pathname, L"Z:\\ass%02d.bmp", n);
			save_bitmap((DWORD*)frame->buffer, pathname, frame_w, frame_h);

			//printf("\rrender cost %dms.\t\t\n", timeGetTime()-l);
		}

		n2 ++;

		if (i%10000 == 0)
		printf("\r%d/%d ms rendered, %d frame output.", i, int(tm*1000), n);
	}

    ass_free_track(track);
    ass_renderer_done(ass_renderer);
    ass_library_done(ass_library);


    free(frame->buffer);
    free(frame);

    return 0;
}
Exemplo n.º 10
0
/*
** Executes a custom bang.
**
*/
void CMeasureScript::Command(const std::wstring& command)
{
	std::string str = ConvertToUTF8(command.c_str());
	m_LuaScript->RunString(str.c_str());
}
Exemplo n.º 11
0
void InfoView::UpdateDisplay( BMessage* message ) {
	
	time_t *membersince;
	char theTime[100], stemp[100];
	BString origProfile;
	unsigned idletime;
	ssize_t size;
	bool away = false;
	
	// away?
	if( message->HasBool("away") && message->FindBool("away") )
		away = true;
	
	// username
	if( message->HasString("userid") ) {
		
		BMessage* msg = new BMessage(BEAIM_UPDATE_NAME_FORMAT);
		msg->AddString("userid", message->FindString("userid"));
		Window()->PostMessage( msg );
		
		char windowTitle[DISPLAY_NAME_MAX+35];
		sprintf( windowTitle, "%s: %s", Language.get("IW_USER_INFO"), message->FindString("userid") );
		if( away ) {
			strcat( windowTitle, "  (" );
			strcat( windowTitle, Language.get("STAT_AWAY") );
			strcat( windowTitle, ")" );
		}
		Window()->SetTitle( windowTitle );
	}

	// user class
	if( message->HasString("userclass") ) {
		label2->SetText( message->FindString( "userclass" ) );
		printf( "IW: userclass done.\n" );
		fflush(stdout);
	}

	// member since
	if( message->HasData("membersince", B_TIME_TYPE) ) {
		message->FindData( "membersince", B_TIME_TYPE, (const void**)(&membersince), &size );
		strftime( theTime, 100, "%B %e, %Y", localtime(membersince) );
		label4->SetText( theTime );
	}
	
	// onsince	
	/*if( message->HasData("onsince", B_TIME_TYPE) ) {
	
		message->FindData( "onsince", B_TIME_TYPE, (const void**)(&onsince), &size );
		MakeElapsedTimeString( *onsince, theTime );
		label6->SetText( theTime );
	}*/
	
	// session length
	if( message->HasInt32("sessionlen") ) { 
		MakeElapsedTimeString( message->FindInt32("sessionlen"), theTime );
		label6->SetText( theTime );
	}
	
	// warning level
	if( message->HasInt32("warninglevel") ) {
		sprintf( stemp, "%u%%", (unsigned)(message->FindInt32("warninglevel")) );
		label8->SetText( stemp );
	}
	
	// idle time
	if( message->HasInt32( "idletime" ) ) {
		idletime = (unsigned)message->FindInt32("idletime");
		if( idletime ) {
			label9->SetText( (char*)LangWithSuffix("STAT_IDLE_TIME", ":") );
			MakeElapsedTimeString( (idletime*60), stemp );
			label10->SetText( stemp );
			statNotIdle = false;
		} else {
			label10->SetText( Language.get("STAT_ACTIVE") );
		}
	}
		
	// profile
	if( message->HasString("profile" ) )
		origProfile = BString((char*)message->FindString("profile"));

	if( origProfile.Length() ) {
		HTMLParser parse;
		styleList styles;

		// first, convert it to UTF-8
		origProfile = ConvertToUTF8( origProfile, encoding );

		// handle the away message variables
		client->ReplaceTagVars( origProfile );
		
		// automatically link the web and mail addresses that weren't linked
		Linkify( origProfile );

		profile->SetText("");
		profile->ClearInsertStuff();
		profile->ResetFontToBase();
		parse.Parse( const_cast<char*>(origProfile.String()) );
		styles = parse.Styles();
		profile->SetViewColor( styles.bgColor.R(), styles.bgColor.G(), styles.bgColor.B() );
		profile->Invalidate();
		profile->AddStyledText( parse.ParsedString(), styles );
		styles.Clear();
		profile->AddStatement();
	} 
	
	// put up a generic "no profile" message
	else
		profile->SetText( Language.get("IW_NO_PROFILE") );
	BView::Invalidate();
}