Ejemplo n.º 1
0
// initialize the GO_CMD variable to hold the path for go.exe
BOOL initialize_go_cmd(){
	// allocate string to hold value obtained from environment variable
	LPTSTR raw_goroot = (LPTSTR) calloc(MAX_ENVIRON, sizeof(TCHAR));
	if (raw_goroot == NULL){
		::MessageBox(nppData._nppHandle, TEXT("Out of memory, f**k!"), TEXT("E R R O R"), MB_OK);
		return FALSE;
	}

	// allocate memory to hold string "xyz\bin\go.exe"
	// will be freed in pluginCleanUp
	GO_CMD = (LPTSTR) calloc(MAX_PATH, sizeof(TCHAR));
	if (GO_CMD == NULL){
		::MessageBox(nppData._nppHandle, TEXT("Out of memory, f**k!"), TEXT("E R R O R"), MB_OK);
		free(raw_goroot);
		return FALSE;
	}

	// if GOBIN is set set assume that go.exe is there
	DWORD length = GetEnvironmentVariable(_TEXT("GOBIN"), raw_goroot, MAX_ENVIRON);
	if (length != 0){
		if (PathCombine(GO_CMD, raw_goroot, TEXT("go.exe")) == NULL) return FALSE;
		PathQuoteSpaces(GO_CMD);

		free(raw_goroot);
		return TRUE;
	}
	
	// if GOROOT is set assume that go.exe is there
	length = GetEnvironmentVariable(_TEXT("GOROOT"), raw_goroot, MAX_ENVIRON);
	if (length != 0){
		if (PathCombine(GO_CMD, raw_goroot, TEXT("bin\\go.exe")) == NULL) return FALSE;
		PathQuoteSpaces(GO_CMD);

		free(raw_goroot);
		return TRUE;
	}

	// if neither is set, pray that go.exe is somewhere on the path
	if (GetLastError() == ERROR_ENVVAR_NOT_FOUND){
		GO_CMD = _T("go.exe");
		free(raw_goroot);

		CommandExec c = CommandExec(GO_CMD, _T(""));
		BOOL start = c.Start();
		BOOL end = c.Wait();
		DWORD status = c.ExitStatus();
		if ( ! start && ! end && status ){
			::MessageBox(nppData._nppHandle,
				NO_GO_EXE_ERROR), 
				_T("go configuration error"), MB_OK | MB_ICONERROR);
		}
Ejemplo n.º 2
0
void GlobalSubst(HWND hDlg)
{	PWSTR p = CommandBuf;
	INT	  n;

	Magic	 = IsDlgButtonChecked(hDlg, IDC_MAGIC);
	HexInput = IsDlgButtonChecked(hDlg, IDC_HEXSEARCH);
	ReplacingAll = TRUE;
	p += n = _snwprintf(p, WSIZE(CommandBuf), L":%%s//");
	n += GetDlgItemTextW(hDlg, IDC_REPLACESTRING, p, WSIZE(CommandBuf) - n);
	while (*p) {
		switch (*p) {
			case '\\':
				if (Magic) {
					if	 (*++p >= '0' && *p <= '7') {
						if (*p >= '0' && *p <= '3') ++p;
						if (*p >= '0' && *p <= '7') ++p;
						if (*p >= '0' && *p <= '7') ++p;
						continue;
					}
					if (*p == '%') {
						if (ISHEX(p[1])) ++p;
						if (ISHEX(p[1])) ++p;
					}
					break;
				}
				/*FALLTHROUGH*/
			case '&':
				if (*p=='&' && !Magic!=MagicFlag) break;
				/*FALLTHROUGH*/
			case '/':
				if (n+1 < WSIZE(CommandBuf)) {
					memmove(p+1, p, 2*wcslen(p)+2);
					*p++ = '\\';
					++n;
				}
				break;
			default:
				if (HexInput) {
					if (!ISHEX(*p)) {
						if (*p != ' ') {
							hwndErrorParent = hDlg;
							ErrorBox(MB_ICONSTOP, 239);
							hwndErrorParent = hwndMain;
							return;
						}
						memmove(p, p+1, 2*wcslen(p));
						--n;
						continue;
					}
					if (n+2 < WSIZE(CommandBuf)) {
						memmove(p+2, p, 2*wcslen(p)+2);
						*p++ = '\\';
						*p++ = '%';
						if (ISHEX(p[1])) ++p;
						n += 2;
					}
				}
		}
		++p;
	}
	if (n+2 < WSIZE(CommandBuf)) wcscpy(p, L"/g");
	SendMessage(hDlg, DM_SETDEFID, IDCANCEL, 0);
	SetFocus(GetDlgItem(hDlg, IDCANCEL));
	EnableControls(hDlg, FALSE);
	CommandExec(CommandBuf);
	EnableControls(hDlg, TRUE);
	ReplacingAll = FALSE;
}