TSimpleLemmer::TSimpleLemmer(const Stroka& path) { Stroka libPath = path; if (path.length() == 0) { Stroka prgDir = GetProgramDir(); if ((prgDir.length() > 1 && prgDir[1] == ':') || (prgDir.length() > 0 && prgDir[0] == '/')) libPath = prgDir; else libPath = GetCwd() + Stroka("/") + prgDir; SlashFolderLocal(libPath); libPath += Stroka("libmystem_c_binding.so"); //Cerr << "libPath == " << libPath << Endl; } Lib.Open(~libPath, RTLD_NOW | RTLD_DEEPBIND | RTLD_NODELETE); if (!IsInitialized()) yexception() << "Can't load lemmer from \"" << path << "\""; }
bool resolvepath(Stroka &folder, const Stroka &home) { YASSERT(home && home.at(0) == '/'); if (!folder) { return false; } // may be from windows char *ptr = folder.begin(); while ((ptr = strchr(ptr, '\\')) != 0) *ptr = '/'; if (folder.at(0) == '~') { if (folder.length() == 1 || folder.at(1) == '/') { folder = GetHomeDir() + (~folder + 1); } else { char* buf = (char*)alloca(folder.length()+1); strcpy(buf, ~folder + 1); char* p = strchr(buf, '/'); if (p) *p++ = 0; passwd* pw = getpwnam(buf); if (pw) { folder = pw->pw_dir; folder += "/"; if (p) folder += p; } else { return false; // unknown user } } } int len = folder.length() + home.length() + 1; char* path = (char*)alloca(len); if (folder.at(0) != '/') { strcpy(path, ~home); strcpy(strrchr(path, '/')+1, ~folder); // the last char must be '/' if it's a dir } else { strcpy(path, ~folder); } len = strlen(path)+1; // grabbed from url.cpp char *newpath = (char*)alloca(len+2); const char **pp = (const char**)alloca(len*sizeof(char*)); int i = 0; for (char* s = path; s;) { pp[i++] = s; s = strchr(s, '/'); if (s) *s++ = 0; } for (int j = 1; j < i;) { const char*& p = pp[j]; if (strcmp(p, ".") == 0 || strcmp(p,"") == 0) { if (j == i-1) { p = ""; break; } else { memmove(pp+j, pp+j+1, (i-j-1)*sizeof(p)); i--; } } else if (strcmp(p, "..") == 0) { if (j == i-1) { if (j == 1) { p = ""; } else { i--; pp[j-1] = ""; } break; } else { if (j == 1) { memmove(pp+j, pp+j+1, (i-j-1)*sizeof(p)); i--; } else { memmove(pp+j-1, pp+j+1, (i-j-1)*sizeof(p)); i-=2; j--; } } } else j++; } char* s = newpath; for (int k = 0; k < i; k++) { s = strchr(strcpy(s, pp[k]), 0); *s++ = '/'; } *(--s) = 0; folder = newpath; return true; }