+
+ return false;
+}
+
+
+bool doesFileExist(FileName & result, string const & search_dir, string const & name)
+{
+ result = fileSearch(search_dir, name);
+ if (!result.empty()) {
+ return true;
+ }
+ return false;
+}
+
+
+bool lyxBinaryPath(FileName & lyx_binary, string const & search_dir, string const & ext)
+{
+ lyx_binary = FileName();
+ if(false) {
+ } else if (doesFileExist(lyx_binary, search_dir, "lyx" + ext)) {
+ } else if (doesFileExist(lyx_binary, search_dir, "LyX" + ext)) {
+ } else if (doesFileExist(lyx_binary, search_dir, "lyx" + string(PROGRAM_SUFFIX) + ext)) {
+ } else if (doesFileExist(lyx_binary, search_dir, "LyX" + string(PROGRAM_SUFFIX) + ext)){
+ }
+ return !lyx_binary.empty() ? true : false;
+}
+
+
+FileName findLyxBinary(FileName const & abs_binary)
+{
+ string ext;
+ string checkname = abs_binary.toFilesystemEncoding();
+ int check_len = checkname.length();
+ int prgsuffixlen = string(PROGRAM_SUFFIX).length();
+ if ((prgsuffixlen > 0) && (check_len > prgsuffixlen) &&
+ (checkname.substr(check_len-prgsuffixlen) == string(PROGRAM_SUFFIX))) {
+ ext = "";
+ }
+ else if (!abs_binary.extension().empty()) {
+ ext = "." + abs_binary.extension();
+ }
+
+ string binary_dir = onlyPath(abs_binary.absFileName());
+
+ FileName lyx_binary;
+ if (lyxBinaryPath(lyx_binary, binary_dir, ext))
+ return lyx_binary;
+
+ string search_dir = onlyPath(FileName(addPath(binary_dir, "/../")).absFileName());
+ if (lyxBinaryPath(lyx_binary, search_dir, ext))
+ return lyx_binary;
+
+ return FileName();