2 filetools.C (former paths.C) - part of LyX project
3 General path-mangling functions
4 Copyright 1996 Ivan Schreter
5 Parts Copyright 1996 Dirk Niggemann
6 Parts Copyright 1985, 1990, 1993 Free Software Foundation, Inc.
7 Parts Copyright 1996 Asger Alstrup
11 lyx-filetool.C : tools functions for file/path handling
12 this file is part of LyX, the High Level Word Processor
13 Copyright 1995-1996, Matthias Ettrich and the LyX Team
27 #pragma implementation "filetools.h"
35 #include "support/lstrings.h"
37 #include "filetools.h"
38 #include "LSubstring.h"
39 #include "frontends/Alert.h"
41 #include "support/path.h" // I know it's OS/2 specific (SMiyata)
46 // Which part of this is still necessary? (JMarc).
49 # define NAMLEN(dirent) strlen((dirent)->d_name)
51 # define dirent direct
52 # define NAMLEN(dirent) (dirent)->d_namlen
54 # include <sys/ndir.h>
70 extern string system_lyxdir;
71 extern string build_lyxdir;
72 extern string user_lyxdir;
73 extern string system_tempdir;
76 bool IsLyXFilename(string const & filename)
78 return suffixIs(lowercase(filename), ".lyx");
82 bool IsSGMLFilename(string const & filename)
84 return suffixIs(lowercase(filename), ".sgml");
88 // Substitutes spaces with underscores in filename (and path)
89 string const MakeLatexName(string const & file)
91 string name = OnlyFilename(file);
92 string const path = OnlyPath(file);
94 for (string::size_type i = 0; i < name.length(); ++i) {
95 name[i] &= 0x7f; // set 8th bit to 0
98 // ok so we scan through the string twice, but who cares.
99 string const keep("abcdefghijklmnopqrstuvwxyz"
100 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
101 "@!\"'()*+,-./0123456789:;<=>?[]`|");
103 string::size_type pos = 0;
104 while ((pos = name.find_first_not_of(keep, pos)) != string::npos) {
107 return AddName(path, name);
111 // Substitutes spaces with underscores in filename (and path)
112 string const QuoteName(string const & name)
114 return (os::shell() == os::UNIX) ?
120 // Is a file readable ?
121 bool IsFileReadable (string const & path)
124 if (file.isOK() && file.isRegular() && file.readable())
131 // Is a file read_only?
132 // return 1 read-write
134 // -1 error (doesn't exist, no access, anything else)
135 int IsFileWriteable (string const & path)
139 if (fi.access(FileInfo::wperm|FileInfo::rperm)) // read-write
141 if (fi.readable()) // read-only
143 return -1; // everything else.
147 //returns true: dir writeable
148 // false: not writeable
149 bool IsDirWriteable (string const & path)
151 lyxerr[Debug::FILES] << "IsDirWriteable: " << path << endl;
153 string const tmpfl(lyx::tempName(path, "lyxwritetest"));
163 // Uses a string of paths separated by ";"s to find a file to open.
164 // Can't cope with pathnames with a ';' in them. Returns full path to file.
165 // If path entry begins with $$LyX/, use system_lyxdir
166 // If path entry begins with $$User/, use user_lyxdir
167 // Example: "$$User/doc;$$LyX/doc"
168 string const FileOpenSearch (string const & path, string const & name,
171 string real_file, path_element;
172 bool notfound = true;
173 string tmppath = split(path, path_element, ';');
175 while (notfound && !path_element.empty()) {
176 path_element = os::slashify_path(path_element);
177 if (!suffixIs(path_element, '/'))
179 path_element = subst(path_element, "$$LyX", system_lyxdir);
180 path_element = subst(path_element, "$$User", user_lyxdir);
182 real_file = FileSearch(path_element, name, ext);
184 if (real_file.empty()) {
186 tmppath = split(tmppath, path_element, ';');
187 } while (!tmppath.empty() && path_element.empty());
193 if (ext.empty() && notfound) {
194 real_file = FileOpenSearch(path, name, "exe");
195 if (notfound) real_file = FileOpenSearch(path, name, "cmd");
202 /// Returns a vector of all files in directory dir having extension ext.
203 vector<string> const DirList(string const & dir, string const & ext)
205 // This is a non-error checking C/system implementation
206 string extension(ext);
207 if (!extension.empty() && extension[0] != '.')
208 extension.insert(0, ".");
209 vector<string> dirlist;
210 DIR * dirp = ::opendir(dir.c_str());
213 << "Directory \"" << dir
214 << "\" does not exist to DirList." << endl;
219 while ((dire = ::readdir(dirp))) {
220 string const fil = dire->d_name;
221 if (suffixIs(fil, extension)) {
222 dirlist.push_back(fil);
227 /* I would have prefered to take a vector<string>& as parameter so
228 that we could avoid the copy of the vector when returning.
230 dirlist.swap(argvec);
231 to avoid the copy. (Lgb)
233 /* A C++ implementaion will look like this:
234 string extension(ext);
235 if (extension[0] != '.') extension.insert(0, ".");
236 vector<string> dirlist;
237 directory_iterator dit("dir");
238 while (dit != directory_iterator()) {
239 string fil = dit->filename;
240 if (prefixIs(fil, extension)) {
241 dirlist.push_back(fil);
245 dirlist.swap(argvec);
251 // Returns the real name of file name in directory path, with optional
253 string const FileSearch(string const & path, string const & name,
256 // if `name' is an absolute path, we ignore the setting of `path'
257 // Expand Environmentvariables in 'name'
258 string const tmpname = ReplaceEnvironmentPath(name);
259 string fullname = MakeAbsPath(tmpname, path);
260 // search first without extension, then with it.
261 if (IsFileReadable(fullname))
263 else if (ext.empty())
265 else { // Is it not more reasonable to use ChangeExtension()? (SMiyata)
268 if (IsFileReadable(fullname))
276 // Search the file name.ext in the subdirectory dir of
278 // 2) build_lyxdir (if not empty)
280 string const LibFileSearch(string const & dir, string const & name,
283 string fullname = FileSearch(AddPath(user_lyxdir, dir), name, ext);
284 if (!fullname.empty())
287 if (!build_lyxdir.empty())
288 fullname = FileSearch(AddPath(build_lyxdir, dir), name, ext);
289 if (!fullname.empty())
292 return FileSearch(AddPath(system_lyxdir, dir), name, ext);
297 i18nLibFileSearch(string const & dir, string const & name,
300 // this comment is from intl/dcigettext.c. We try to mimick this
302 /* The highest priority value is the `LANGUAGE' environment
303 variable. But we don't use the value if the currently
304 selected locale is the C locale. This is a GNU extension. */
306 string const lc_all = GetEnv("LC_ALL");
307 string lang = GetEnv("LANGUAGE");
308 if (lang.empty() || lc_all == "C") {
311 lang = GetEnv("LANG");
315 lang = token(lang, '_', 0);
317 if (lang.empty() || lang == "C")
318 return LibFileSearch(dir, name, ext);
320 string const tmp = LibFileSearch(dir, lang + '_' + name,
325 return LibFileSearch(dir, name, ext);
330 string const GetEnv(string const & envname)
332 // f.ex. what about error checking?
333 char const * const ch = getenv(envname.c_str());
334 string const envstr = !ch ? "" : ch;
339 string const GetEnvPath(string const & name)
342 string const pathlist = subst(GetEnv(name), ':', ';');
344 string const pathlist = os::slashify_path(GetEnv(name));
346 return strip(pathlist, ';');
350 bool PutEnv(string const & envstr)
352 // CHECK Look at and fix this.
353 // f.ex. what about error checking?
356 // this leaks, but what can we do about it?
357 // Is doing a getenv() and a free() of the older value
358 // a good idea? (JMarc)
359 // Actually we don't have to leak...calling putenv like this
360 // should be enough: ... and this is obviously not enough if putenv
361 // does not make a copy of the string. It is also not very wise to
362 // put a string on the free store. If we have to leak we should do it
364 char * leaker = new char[envstr.length() + 1];
365 envstr.copy(leaker, envstr.length());
366 leaker[envstr.length()] = '\0';
367 int const retval = lyx::putenv(leaker);
369 // If putenv does not make a copy of the char const * this
370 // is very dangerous. OTOH if it does take a copy this is the
372 // The only implementation of putenv that I have seen does not
373 // allocate memory. _And_ after testing the putenv in glibc it
374 // seems that we need to make a copy of the string contents.
375 // I will enable the above.
376 //int retval = lyx::putenv(envstr.c_str());
380 string const str = envstr.split(varname,'=');
381 int const retval = ::setenv(varname.c_str(), str.c_str(), true);
383 // No environment setting function. Can this happen?
384 int const retval = 1; //return an error condition.
391 bool PutEnvPath(string const & envstr)
393 return PutEnv(envstr);
399 int DeleteAllFilesInDir (string const & path)
401 // I have decided that we will be using parts from the boost
402 // library. Check out http://www.boost.org/
403 // For directory access we will then use the directory_iterator.
404 // Then the code will be something like:
405 // directory_iterator dit(path);
406 // directory_iterator dend;
407 // if (dit == dend) {
408 // Alert::err_alert(_("Error! Cannot open directory:"), path);
411 // for (; dit != dend; ++dit) {
412 // string filename(*dit);
413 // if (filename == "." || filename == "..")
415 // string unlinkpath(AddName(path, filename));
416 // if (lyx::unlink(unlinkpath))
417 // Alert::err_alert(_("Error! Could not remove file:"),
421 DIR * dir = ::opendir(path.c_str());
423 Alert::err_alert (_("Error! Cannot open directory:"), path);
427 int return_value = 0;
428 while ((de = readdir(dir))) {
429 string const temp = de->d_name;
430 if (temp == "." || temp == "..")
432 string const unlinkpath = AddName (path, temp);
434 lyxerr[Debug::FILES] << "Deleting file: " << unlinkpath
438 if (FileInfo(unlinkpath).isDir())
439 deleted = (DeleteAllFilesInDir(unlinkpath) == 0);
440 deleted &= (lyx::unlink(unlinkpath) == 0);
442 Alert::err_alert(_("Error! Could not remove file:"),
452 string const CreateTmpDir(string const & tempdir, string const & mask)
455 << "CreateTmpDir: tempdir=`" << tempdir << "'\n"
456 << "CreateTmpDir: mask=`" << mask << "'" << endl;
458 string const tmpfl(lyx::tempName(tempdir, mask));
459 // lyx::tempName actually creates a file to make sure that it
460 // stays unique. So we have to delete it before we can create
461 // a dir with the same name. Note also that we are not thread
462 // safe because of the gap between unlink and mkdir. (Lgb)
463 lyx::unlink(tmpfl.c_str());
465 if (tmpfl.empty() || lyx::mkdir(tmpfl, 0700)) {
466 Alert::err_alert(_("Error! Couldn't create temporary directory:"),
470 return MakeAbsPath(tmpfl);
474 int DestroyTmpDir(string const & tmpdir, bool Allfiles)
479 if (Allfiles && DeleteAllFilesInDir(tmpdir)) {
482 if (lyx::rmdir(tmpdir)) {
483 Alert::err_alert(_("Error! Couldn't delete temporary directory:"),
493 string const CreateBufferTmpDir(string const & pathfor)
496 static string const tmpdir(pathfor.empty() ? os::getTmpDir() : pathfor);
497 // We are in our own directory. Why bother to mangle name?
498 // In fact I wrote this code to circumvent a problematic behaviour (bug?)
500 string const tmpfl = tmpdir + "/lyx_tmpbuf" + tostr(count++);
501 if (lyx::mkdir(tmpfl, 0777)) {
502 Alert::err_alert(_("Error! Couldn't create temporary directory:"),
510 int DestroyBufferTmpDir(string const & tmpdir)
512 return DestroyTmpDir(tmpdir, true);
516 string const CreateLyXTmpDir(string const & deflt)
518 if ((!deflt.empty()) && (deflt != "/tmp")) {
519 if (lyx::mkdir(deflt, 0777)) {
523 return CreateTmpDir(deflt, "lyx_tmpdir");
530 return CreateTmpDir("/tmp", "lyx_tmpdir");
535 int DestroyLyXTmpDir(string const & tmpdir)
537 return DestroyTmpDir (tmpdir, false); // Why false?
541 // Creates directory. Returns true if succesfull
542 bool createDirectory(string const & path, int permission)
544 string temp(strip(os::slashify_path(path), '/'));
547 Alert::alert(_("Internal error!"),
548 _("Call to createDirectory with invalid name"));
552 if (lyx::mkdir(temp, permission)) {
553 Alert::err_alert (_("Error! Couldn't create directory:"), temp);
560 // Strip filename from path name
561 string const OnlyPath(string const & Filename)
563 // If empty filename, return empty
564 if (Filename.empty()) return Filename;
566 // Find last / or start of filename
567 string::size_type j = Filename.rfind('/');
568 if (j == string::npos)
570 return Filename.substr(0, j + 1);
574 // Convert relative path into absolute path based on a basepath.
575 // If relpath is absolute, just use that.
576 // If basepath is empty, use CWD as base.
577 string const MakeAbsPath(string const & RelPath, string const & BasePath)
579 // checks for already absolute path
580 if (os::is_absolute_path(RelPath))
583 // Copies given paths
584 string TempRel(os::slashify_path(RelPath));
585 // Since TempRel is NOT absolute, we can safely replace "//" with "/"
586 TempRel = subst(TempRel, "//", "/");
590 if (os::is_absolute_path(BasePath))
593 TempBase = AddPath(lyx::getcwd(), BasePath);
595 // Handle /./ at the end of the path
596 while (suffixIs(TempBase, "/./"))
597 TempBase.erase(TempBase.length() - 2);
599 // processes relative path
600 string RTemp(TempRel);
603 while (!RTemp.empty()) {
605 RTemp = split(RTemp, Temp, '/');
607 if (Temp == ".") continue;
609 // Remove one level of TempBase
610 string::difference_type i = TempBase.length() - 2;
613 while (i > 0 && TempBase[i] != '/') --i;
617 while (i > 2 && TempBase[i] != '/') --i;
620 TempBase.erase(i, string::npos);
623 } else if (Temp.empty() && !RTemp.empty()) {
624 TempBase = os::current_root() + RTemp;
627 // Add this piece to TempBase
628 if (!suffixIs(TempBase, '/'))
634 // returns absolute path
635 return os::slashify_path(TempBase);
639 // Correctly append filename to the pathname.
640 // If pathname is '.', then don't use pathname.
641 // Chops any path of filename.
642 string const AddName(string const & path, string const & fname)
645 string const basename(OnlyFilename(fname));
649 if (path != "." && path != "./" && !path.empty()) {
650 buf = os::slashify_path(path);
651 if (!suffixIs(path, '/'))
655 return buf + basename;
659 // Strips path from filename
660 string const OnlyFilename(string const & fname)
665 string::size_type j = fname.rfind('/');
666 if (j == string::npos) // no '/' in fname
670 return fname.substr(j + 1);
674 /// Returns true is path is absolute
675 bool AbsolutePath(string const & path)
677 return os::is_absolute_path(path);
682 // Create absolute path. If impossible, don't do anything
683 // Supports ./ and ~/. Later we can add support for ~logname/. (Asger)
684 string const ExpandPath(string const & path)
686 // checks for already absolute path
687 string RTemp(ReplaceEnvironmentPath(path));
688 if (os::is_absolute_path(RTemp))
692 string const copy(RTemp);
695 RTemp = split(RTemp, Temp, '/');
698 return lyx::getcwd() /*GetCWD()*/ + '/' + RTemp;
701 return GetEnvPath("HOME") + '/' + RTemp;
704 return MakeAbsPath(copy);
706 // Don't know how to handle this
712 // Constracts path/../path
713 // Can't handle "../../" or "/../" (Asger)
714 string const NormalizePath(string const & path)
720 if (os::is_absolute_path(path))
723 // Make implicit current directory explicit
726 while (!RTemp.empty()) {
728 RTemp = split(RTemp, Temp, '/');
732 } else if (Temp == "..") {
733 // Remove one level of TempBase
734 string::difference_type i = TempBase.length() - 2;
735 while (i > 0 && TempBase[i] != '/')
737 if (i >= 0 && TempBase[i] == '/')
738 TempBase.erase(i + 1, string::npos);
742 TempBase += Temp + '/';
746 // returns absolute path
751 string const GetFileContents(string const & fname)
753 FileInfo finfo(fname);
755 ifstream ifs(fname.c_str());
760 return ofs.str().c_str();
763 lyxerr << "LyX was not able to read file '" << fname << "'" << endl;
769 // Search ${...} as Variable-Name inside the string and replace it with
770 // the denoted environmentvariable
771 // Allow Variables according to
772 // variable := '$' '{' [A-Za-z_]{[A-Za-z_0-9]*} '}'
775 string const ReplaceEnvironmentPath(string const & path)
778 // CompareChar: Environmentvariables starts with this character
779 // PathChar: Next path component start with this character
780 // while CompareChar found do:
781 // Split String with PathChar
782 // Search Environmentvariable
783 // if found: Replace Strings
785 char const CompareChar = '$';
786 char const FirstChar = '{';
787 char const EndChar = '}';
788 char const UnderscoreChar = '_';
789 string EndString; EndString += EndChar;
790 string FirstString; FirstString += FirstChar;
791 string CompareString; CompareString += CompareChar;
792 string const RegExp("*}*"); // Exist EndChar inside a String?
794 // first: Search for a '$' - Sign.
796 string result1; //(copy); // for split-calls
797 string result0 = split(path, result1, CompareChar);
798 while (!result0.empty()) {
799 string copy1(result0); // contains String after $
801 // Check, if there is an EndChar inside original String.
803 if (!regexMatch(copy1, RegExp)) {
804 // No EndChar inside. So we are finished
805 result1 += CompareString + result0;
811 string res0 = split(copy1, res1, EndChar);
812 // Now res1 holds the environmentvariable
813 // First, check, if Contents is ok.
814 if (res1.empty()) { // No environmentvariable. Continue Loop.
815 result1 += CompareString + FirstString;
819 // check contents of res1
820 char const * res1_contents = res1.c_str();
821 if (*res1_contents != FirstChar) {
822 // Again No Environmentvariable
823 result1 += CompareString;
827 // Check for variable names
828 // Situation ${} is detected as "No Environmentvariable"
829 char const * cp1 = res1_contents + 1;
830 bool result = isalpha(*cp1) || (*cp1 == UnderscoreChar);
832 while (*cp1 && result) {
833 result = isalnum(*cp1) ||
834 (*cp1 == UnderscoreChar);
839 // no correct variable name
840 result1 += CompareString + res1 + EndString;
841 result0 = split(res0, res1, CompareChar);
846 string env(GetEnv(res1_contents + 1));
848 // Congratulations. Environmentvariable found
851 result1 += CompareString + res1 + EndString;
854 result0 = split(res0, res1, CompareChar);
858 } // ReplaceEnvironmentPath
861 // Make relative path out of two absolute paths
862 string const MakeRelPath(string const & abspath, string const & basepath)
863 // Makes relative path out of absolute path. If it is deeper than basepath,
864 // it's easy. If basepath and abspath share something (they are all deeper
865 // than some directory), it'll be rendered using ..'s. If they are completely
866 // different, then the absolute path will be used as relative path.
868 string::size_type const abslen = abspath.length();
869 string::size_type const baselen = basepath.length();
871 string::size_type i = os::common_path(abspath, basepath);
874 // actually no match - cannot make it relative
878 // Count how many dirs there are in basepath above match
879 // and append as many '..''s into relpath
881 string::size_type j = i;
882 while (j < baselen) {
883 if (basepath[j] == '/') {
884 if (j + 1 == baselen)
891 // Append relative stuff from common directory to abspath
892 if (abspath[i] == '/')
894 for (; i < abslen; ++i)
897 if (suffixIs(buf, '/'))
898 buf.erase(buf.length() - 1);
899 // Substitute empty with .
906 // Append sub-directory(ies) to a path in an intelligent way
907 string const AddPath(string const & path, string const & path_2)
910 string const path2 = os::slashify_path(path_2);
912 if (!path.empty() && path != "." && path != "./") {
913 buf = os::slashify_path(path);
914 if (path[path.length() - 1] != '/')
918 if (!path2.empty()) {
919 string::size_type const p2start = path2.find_first_not_of('/');
920 string::size_type const p2end = path2.find_last_not_of('/');
921 string const tmp = path2.substr(p2start, p2end - p2start + 1);
929 Change extension of oldname to extension.
930 Strips path off if no_path == true.
931 If no extension on oldname, just appends.
933 string const ChangeExtension(string const & oldname, string const & extension)
935 string::size_type const last_slash = oldname.rfind('/');
936 string::size_type last_dot = oldname.rfind('.');
937 if (last_dot < last_slash && last_slash != string::npos)
938 last_dot = string::npos;
941 // Make sure the extension starts with a dot
942 if (!extension.empty() && extension[0] != '.')
943 ext= "." + extension;
947 return os::slashify_path(oldname.substr(0, last_dot) + ext);
951 /// Return the extension of the file (not including the .)
952 string const GetExtension(string const & name)
954 string::size_type const last_slash = name.rfind('/');
955 string::size_type const last_dot = name.rfind('.');
956 if (last_dot != string::npos &&
957 (last_slash == string::npos || last_dot > last_slash))
958 return name.substr(last_dot + 1,
959 name.length() - (last_dot + 1));
965 // Creates a nice compact path for displaying
967 MakeDisplayPath (string const & path, unsigned int threshold)
969 string::size_type const l1 = path.length();
971 // First, we try a relative path compared to home
972 string const home(GetEnvPath("HOME"));
973 string relhome = MakeRelPath(path, home);
975 string::size_type l2 = relhome.length();
979 // If we backup from home or don't have a relative path,
980 // this try is no good
981 if (prefixIs(relhome, "../") || os::is_absolute_path(relhome)) {
982 // relative path was no good, just use the original path
989 // Is the path too long?
990 if (l2 > threshold) {
996 while (relhome.length() > threshold)
997 relhome = split(relhome, temp, '/');
999 // Did we shortend everything away?
1000 if (relhome.empty()) {
1001 // Yes, filename in itself is too long.
1002 // Pick the start and the end of the filename.
1003 relhome = OnlyFilename(path);
1004 string const head = relhome.substr(0, threshold/2 - 3);
1006 l2 = relhome.length();
1008 relhome.substr(l2 - threshold/2 - 2, l2 - 1);
1009 relhome = head + "..." + tail;
1012 return prefix + relhome;
1016 bool LyXReadLink(string const & File, string & Link)
1018 char LinkBuffer[512];
1019 // Should be PATH_MAX but that needs autconf support
1020 int const nRead = ::readlink(File.c_str(),
1021 LinkBuffer, sizeof(LinkBuffer) - 1);
1024 LinkBuffer[nRead] = '\0'; // terminator
1032 typedef pair<int, string> cmdret;
1034 cmdret const do_popen(string const & cmd)
1036 // One question is if we should use popen or
1037 // create our own popen based on fork, exec, pipe
1038 // of course the best would be to have a
1039 // pstream (process stream), with the
1040 // variants ipstream, opstream
1041 FILE * inf = ::popen(cmd.c_str(), "r");
1045 ret += static_cast<char>(c);
1048 int const pret = pclose(inf);
1049 return make_pair(pret, ret);
1055 string const findtexfile(string const & fil, string const & /*format*/)
1057 /* There is no problem to extend this function too use other
1058 methods to look for files. It could be setup to look
1059 in environment paths and also if wanted as a last resort
1060 to a recursive find. One of the easier extensions would
1061 perhaps be to use the LyX file lookup methods. But! I am
1062 going to implement this until I see some demand for it.
1066 // If the file can be found directly, we just return a
1067 // absolute path version of it.
1068 if (FileInfo(fil).exist())
1069 return MakeAbsPath(fil);
1071 // No we try to find it using kpsewhich.
1072 // It seems from the kpsewhich manual page that it is safe to use
1073 // kpsewhich without --format: "When the --format option is not
1074 // given, the search path used when looking for a file is inferred
1075 // from the name given, by looking for a known extension. If no
1076 // known extension is found, the search path for TeX source files
1078 // However, we want to take advantage of the format sine almost all
1079 // the different formats has environment variables that can be used
1080 // to controll which paths to search. f.ex. bib looks in
1081 // BIBINPUTS and TEXBIB. Small list follows:
1082 // bib - BIBINPUTS, TEXBIB
1084 // graphic/figure - TEXPICTS, TEXINPUTS
1085 // ist - TEXINDEXSTYLE, INDEXSTYLE
1086 // pk - PROGRAMFONTS, PKFONTS, TEXPKS, GLYPHFONTS, TEXFONTS
1088 // tfm - TFMFONTS, TEXFONTS
1089 // This means that to use kpsewhich in the best possible way we
1090 // should help it by setting additional path in the approp. envir.var.
1091 string const kpsecmd = "kpsewhich " + fil;
1093 cmdret const c = do_popen(kpsecmd);
1095 lyxerr[Debug::LATEX] << "kpse status = " << c.first << "\n"
1096 << "kpse result = `" << strip(c.second, '\n')
1099 return os::internal_path(strip(strip(c.second, '\n'), '\r'));
1105 void removeAutosaveFile(string const & filename)
1107 string a = OnlyPath(filename);
1109 a += OnlyFilename(filename);
1111 FileInfo const fileinfo(a);
1112 if (fileinfo.exist()) {
1113 if (lyx::unlink(a) != 0) {
1114 Alert::err_alert(_("Could not delete auto-save file!"), a);