コード例 #1
0
void SourceView::showFile(std::string path, int proclinenum, const LINEINFOMAP *lineinfomap)
{
	currentfile = path;

	SetValue("");//clear text
	SetDefaultStyle(wxTextAttr(*wxBLACK));

	if (path == "[hint KiFastSystemCallRet]")
	{
		AppendText(
			" Hint: KiFastSystemCallRet often means the thread was waiting for something else to finish.\n"
			" \n"
			" Possible causes might be disk I/O, waiting for an event, or maybe just calling Sleep().\n"
			);
		return;
	}

	if (path == "" || path == "[unknown]")
	{
		SetValue("[ No source file available for this location. ]");

		return;
	}


	FILE *file = fopen(path.c_str(),"r");
	if(!file)
	{
		char *crtSub = "\\crt\\src\\";
		char *crt = strstr((char *)path.c_str(),crtSub);
		if(crt) {
			for(size_t i=0;i<msDevPaths.size();i++) {
				std::string newPath(msDevPaths[i]);
				newPath += crt+strlen(crtSub);
				path = newPath;
				file = fopen(path.c_str(),"r");
				if(file)
					break;
			}
		}
	}

	if(!file)
	{
		AppendText(std::string("[ Could not open file '" + path + "'. ]").c_str());
		return;
	}

	Show(false);
	std::string displaytext= "{\\rtf1\\ansi\\fdeff0{\\colortbl;\\red0\\green0\\blue0;\\red255\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;}\\cf1";
	int linenum = 1;//1-based counting
	//int showpos = 0;//index of character to make visible in order to scroll to line where proc is defined.
	const int MARGIN_WIDTH = 7;
	char line[1024*10];
	bool block=false;
	char blockType;
	while(fgets(line,sizeof(line),file))
	{
		char outLine[1024*20];
		LINEINFOMAP::const_iterator result = lineinfomap->find(linenum);
		
		if(result != lineinfomap->end()) {
			sprintf(outLine,"{\\b\\cf2 %0.2fs\t}",result->second.count);
		} else {
			strcpy(outLine,"\t");
		}
		char *out = outLine+strlen(outLine);
		char *in = line;
		while(*in) {
			if(!block)
			{
				if(in[0] == '/' && in[1] == '/') {
					block = true;
					blockType = '/';
					strcpy(out,"{\\cf3 ");
					out += strlen(out);
				} else 	if(in[0] == '/' && in[1] == '*') {
					block = true;
					blockType = '*';
					strcpy(out,"{\\cf3 ");
					out += strlen(out);
				} else if(in[0] == '"' && ( in[-1] != '\\' || in[-2] == '\\' )) {
					block = true;
					blockType = '"';
					strcpy(out,"{\\cf3 ");
					out += strlen(out);
				} if(!isCToken(in[-1]) && isCToken(in[0])) {
					char token[1024*10];
					char *tokOut = token;
					while(isCToken(*in)) {
						*(tokOut++) = *(in++);
					}
					*tokOut=0;
					if(keywords.Contains(token)) {
						strcpy(out,"{\\cf4 ");
						out += strlen(out);
						strcpy(out,token);
						out += strlen(out);
						strcpy(out,"}");
						out += strlen(out);
					} else {
						strcpy(out,token);
						out += strlen(token);
					}
					continue;
				}
			} else {
				if(blockType == '*' && in[-2] == '*' && in[-1] == '/') {
					block = false;
					strcpy(out,"}");
					out += strlen(out);
				} else if(blockType == '"' && in[0] == '"' && ( in[-1] != '\\' || in[-2] == '\\' )) {
					*(out++) = '"';
					block = false;
					strcpy(out,"}");
					out += strlen(out);
					in++;
					continue;
				}
			}

			switch(in[0]) {
			case '\n':
			case '\r':
				if(block && blockType == '/') {
					block = false;
					strcpy(out,"}");
					out += strlen(out);
				}
				break;
			case '{':
			case '}':
			case '\\':
				*(out++) = '\\';
				*(out++) = in[0];
				break;
			default:
				*(out++) = in[0];
				break;
			}
			in++;
		}
		*out = 0;
		
		strcat(outLine,"\\line\n");

		displaytext += outLine ;//form line to display
	
		linenum++;
	}
	displaytext += "}";
	fclose(file);

	SendMessage((HWND)GetHWND(),EM_EXLIMITTEXT,0,displaytext.size());

	SETTEXTEX settextex = {
		ST_DEFAULT,
		1200,
	};
	SendMessage((HWND)GetHWND(),EM_SETTEXTEX,(WPARAM)&settextex,(LPARAM)displaytext.c_str());

	wxFont font(8, wxMODERN , wxNORMAL, wxNORMAL);
	const bool res = SetStyle(0, (long)displaytext.size(), wxTextAttr(wxNullColour, wxNullColour, 
						font));
	const int showpos = std::max((int)XYToPosition(0, std::max(proclinenum -7 , 0)), 0);
	ShowPosition(showpos);
	Show(true);
}
コード例 #2
0
ファイル: sourceview.cpp プロジェクト: doneykoo/verysleepy
void SourceView::showFile(std::wstring path, int proclinenum, const std::vector<double> &linecounts)
{
	currentfile = path;

	// Don't show error messages with CPP highlighting
	setPlainMode();
	if (path == "[hint KiFastSystemCallRet]")
	{
		updateText(
			" Hint: KiFastSystemCallRet often means the thread was waiting for something else to finish.\n"
			" \n"
			" Possible causes might be disk I/O, waiting for an event, or maybe just calling Sleep().\n"
			);
		return;
	}

	if (path == "" || path == "[unknown]")
	{
		updateText("[ No source file available for this location. ]");
		return;
	}


	FILE *file = _wfopen(path.c_str(),L"r, ccs=UNICODE");
	if(!file)
	{
		wchar_t *crtSub = L"\\crt\\src\\";
		wchar_t *crt = wcsstr((wchar_t *)path.c_str(), crtSub);
		if(crt) {
			for(size_t i=0;i<msDevPaths.size();i++) {
				std::wstring newPath(msDevPaths[i]);
				newPath += crt+wcslen(crtSub);
				path = newPath;
				file = _wfopen(path.c_str(),L"r");
				if(file)
					break;
			}
		}
	}

	if(!file)
	{
		updateText(std::wstring("[ Could not open file '" + path + "'. ]").c_str());
		return;
	}

	std::wstring displaytext;
	wchar_t line[1024];
	while(fgetws(line,countof(line),file))
	{
		displaytext += line;
	}

	fclose(file);

	setCppMode();

	updateText(displaytext);

	// Show line counts in margin
	for (int line=1,lineCount=linecounts.size(); line<lineCount; ++line)
	{
		if (linecounts[line])
		{
			wchar_t currCount[32];
			swprintf(currCount, countof(currCount), L"%0.2fs ", linecounts[line]);
			MarginSetText (line-1, currCount);
			MarginSetStyle(line-1, MARGIN_TEXT_STYLE);
		}
	}

	SetYCaretPolicy(wxSTC_CARET_STRICT|wxSTC_CARET_EVEN, 0);
	GotoLine(proclinenum);
	SetYCaretPolicy(wxSTC_CARET_EVEN, 0);

	MarkerDefine(1, wxSTC_MARK_BACKGROUND, wxNullColour, *wxYELLOW);
	MarkerAdd(proclinenum-1, 1);
}