Speller *sGetSpeller(int lang) { static ArrayMap<int, Speller> speller; int q = speller.Find(lang); if(q < 0) { String pp = spell_path; DoSpellerPath(pp, GetExeDirFile("scd")); DoSpellerPath(pp, ConfigFile("scd")); pp << spell_path << ';' << getenv("LIB") << ';' << getenv("PATH") << ';'; String path = GetFileOnPath(ToLower(LNGAsText(lang)) + ".udc", pp); if(IsNull(path)) path = GetFileOnPath(ToLower(LNGAsText(lang)) + ".scd", pp); if(IsNull(path)) return NULL; FileIn in(path); if(!in) return NULL; q = speller.GetCount(); Speller& f = speller.Add(lang); FileIn user(sUserFile(lang)); while(!user.IsEof()) { String s = user.GetLine(); if(!s.IsEmpty()) f.user.Add(FromUtf8(s)); } if(in.Get() != 255) f.SetOld(LoadFile(path)); else { f.path = path; int n = in.GetL(); LLOG("Found scd file " << path << " blocks " << n); if(n > 0 && n < 100000) { for(int i = 0; i < n; i++) { SpellBlock& b = f.block.Add(); b.first = in.Get(in.Get()); b.ctrl_len = in.GetL(); b.text_len = in.GetL(); } if(in.IsEof()) f.block.Clear(); else { int off = (int)in.GetPos(); for(int i = 0; i < n; i++) { SpellBlock& b = f.block[i]; b.offset = off; off += b.ctrl_len + b.text_len; } } } } } return &speller[q]; }
String GetIncludePath0(const char *s, const char *filedir) { LTIMING("GetIncludePath0"); while(IsSpace(*s)) s++; int type = *s; if(type == '<' || type == '\"' || type == '?') { s++; String name; if(type == '<') type = '>'; while(*s != '\r' && *s != '\n') { if(*s == type) { if(type == '\"') { String fn = NormalizeSourcePath(name, filedir); if(FileExists(fn)) return fn; } String p = GetFileOnPath(name, GetIncludePath(), false); if(p.GetCount()) return NormalizeSourcePath(p); return Null; } name.Cat(*s++); } } return Null; }
String GetUmkFile(const char *fn) { return GetFileOnPath(fn, GetHomeDirFile(".upp/umk") + ';' + GetHomeDirFile(".upp/theide") + ';' + GetHomeDirFile(".upp/ide") + ';' + GetHomeDirectory() + ';' + GetFileFolder(GetExeFilePath())); }
void LocalSlaveProcess::Open(const char *command, const char *envptr) { SVRLOG("LocalSlaveProcess::Open(" << command << ")"); Kill(); while(*command && (byte)*command <= ' ') command++; #ifdef PLATFORM_WIN32 HANDLE hOutputReadTmp, hInputRead; HANDLE hInputWriteTmp, hOutputWrite; HANDLE hErrorWrite; SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; HANDLE hp = GetCurrentProcess(); CreatePipe(&hOutputReadTmp, &hOutputWrite, &sa, 0); DuplicateHandle(hp, hOutputWrite, hp, &hErrorWrite, 0, TRUE, DUPLICATE_SAME_ACCESS); CreatePipe(&hInputRead, &hInputWriteTmp, &sa, 0); DuplicateHandle(hp, hOutputReadTmp, hp, &hOutputRead, 0, FALSE, DUPLICATE_SAME_ACCESS); DuplicateHandle(hp, hInputWriteTmp, hp, &hInputWrite, 0, FALSE, DUPLICATE_SAME_ACCESS); CloseHandle(hOutputReadTmp); CloseHandle(hInputWriteTmp); PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; si.hStdInput = hInputRead; si.hStdOutput = hOutputWrite; si.hStdError = hErrorWrite; int n = (int)strlen(command) + 1; Buffer<char> cmd(n); memcpy(cmd, command, n); bool h = CreateProcess(NULL, cmd, &sa, &sa, TRUE, NORMAL_PRIORITY_CLASS, (void *)envptr, NULL, &si, &pi); SVRLOG("CreateProcess " << (h ? "succeeded" : "failed")); CloseHandle(hErrorWrite); CloseHandle(hInputRead); CloseHandle(hOutputWrite); if(h) { hProcess = pi.hProcess; CloseHandle(pi.hThread); } else { Free(); throw Exc(NFormat("Error running process: %s\nCommand: %s", GetErrorMessage(GetLastError()), command)); } #endif #ifdef PLATFORM_POSIX // parse command line for execve cmd_buf.Alloc(strlen(command) + 1); char *cmd_out = cmd_buf; const char *p = command; const char *b = p; while(*p && (byte)*p > ' ') if(*p++ == '\"') while(*p && *p++ != '\"') ; const char *app = cmd_out; args.Add(cmd_out); memcpy(cmd_out, b, p - b); cmd_out += p - b; *cmd_out++ = '\0'; while(*p) if((byte)*p <= ' ') p++; else { args.Add(cmd_out); while(*p && (byte)*p > ' ') if(*p == '\\') { if(*++p) *cmd_out++ = *p++; } else if(*p == '\"') { p++; while(*p && *p != '\"') if(*p == '\\') { if(*++p) *cmd_out++ = *p++; } else *cmd_out++ = *p++; if(*p == '\"') p++; } else *cmd_out++ = *p++; *cmd_out++ = '\0'; } args.Add(NULL); String app_full = GetFileOnPath(app, getenv("PATH"), true); if(IsNull(app_full)) throw Exc(Format("Cannot find executable '%s'\n", app)); if(pipe(rpipe) || pipe(wpipe)) throw Exc(NFormat(t_("pipe() error; error code = %d"), errno)); SVRLOG("\nLocalSlaveProcess::Open"); SVRLOG("rpipe[" << rpipe[0] << ", " << rpipe[1] << "]"); SVRLOG("wpipe[" << wpipe[0] << ", " << wpipe[1] << "]"); pid = fork(); SVRLOG("\tfork, pid = " << (int)pid << ", getpid = " << (int)getpid()); if(pid < 0) throw Exc(NFormat(t_("fork() error; error code = %d"), errno)); if(pid) { // parent process; clear child pipe endpoints SVRLOG("parent process - continue"); // rpipe[0] = wpipe[1] = -1; return; } SVRLOG("child process - execute application"); // rpipe[1] = wpipe[0] = -1; if(dup2(rpipe[0], 0) < 0) { // stdin SVRLOG("dup2(stdin) error: " << errno << ", " << strerror(errno)); } if(dup2(wpipe[1], 1) < 0) { // stdout SVRLOG("dup2(stdout) error: " << errno << ", " << strerror(errno)); } if(dup2(wpipe[1], 2) < 0) { // stderr SVRLOG("dup2(stderr) error: " << errno << ", " << strerror(errno)); } #if DO_SVRLOG SVRLOG(args.GetCount() << "arguments:"); for(int a = 0; a < args.GetCount(); a++) SVRLOG("[" << a << "]: <" << (args[a] ? args[a] : "NULL") << ">"); #endif//DO_SVRLOG SVRLOG("running execve, app = " << app << ", #args = " << args.GetCount()); const char *from = envptr; Vector<const char *> env; while(*from) { env.Add(from); from += strlen(from) + 1; } env.Add(NULL); execve(app_full, args.Begin(), (char *const *)env.Begin()); SVRLOG("execve failed, errno = " << errno); printf("Error running '%s', error code %d\n", command, errno); exit(-errno); #endif }