Hello Jean-Marc, Shigeru,
as announced, here is a emx file handling patch against lyx103. It contains some more
changes by me
compared with the previous snippets. I use 7 bit mime mail encoding, so I hope you can
read it without
problems. Otherwise please complain loudly...
Unfortunately there is no such thing like a generic posix path-handling translation
library available,
or is it? So I tried to look for a better handling of DOS-style paths here. Some parts
are a bit
sub-optimal, but I did my best, till I got totally bored with this boring stuff.
Arrggh! Path handling is so dull and tedious! Why didn't someone invent an easy
interface or generic
toolkit as yet! Do developers like to reinvent the wheel here for any new project?
Sorry, this is not
meant against computer scientists, only a cry for help...
Cheers,
Arnd
PS: Mime attached a sample-session.log, where LyX is using naughty paths.
/* ------snip----------*/
diff -p -N -r -U 4 -X excl.tmp src/original/filetools.C src/modified/filetools.C
--- src/original/filetools.C Wed May 12 06:51:18 1999
+++ src/modified/filetools.C Wed Jul 21 18:53:44 1999
@@ -88,17 +88,30 @@ LString SpaceLess(LString const & file)
name.subst('`', '_');
name.subst('"', '_');
name.subst('&', 'G');
name.subst('|', 'I');
- name.subst(';', ':');
+ name.subst(';', ','); /* AHanses: The Murphy-circle ':', ';', ':',... fix! */
name.subst('(', 'c');
name.subst(')', 'C');
name.subst('<', 'k');
name.subst('>', 'K');
-
+ name.subst('�', 'z'); /* AHanses: no more trouble with 'umlauts'? */
+ name.subst('�', 'a');
+ name.subst('�', 'o');
+ name.subst('�', 'u');
+ name.subst('�', 'e');
+ name.subst('�', 'n');
+ name.subst('�', 'A'); /* AHanses: For OS/2 'lowercase()' won't help */
+ name.subst('�', 'O');
+ name.subst('�', 'U');
+ name.subst('�', 'A');
+ name.subst('�', 'U');
+#warning AHanses: List is incomplete. Please find a more generic solution.
+
LString temp = AddName(path, name);
// Replace spaces with underscores, also in directory
temp.subst(' ','_');
+ /* AHanses: Seems to handle 'umlauts' in directory correctly, too */
return temp;
}
@@ -208,8 +221,13 @@ LString FileOpenSearch (LString const &
{
LString real_file, path_element;
LString tmppath = path;
bool notfound = true;
+
+#ifdef __EMX__ /* SMiyata: This should fix searchpath bug. */
+ tmppath.subst('\\', '/');
+ tmppath.lowercase();
+#endif
tmppath.split(path_element, ';');
while (notfound && !path_element.empty()) {
@@ -461,17 +479,22 @@ LString OnlyPath(LString const &Filename
{
// If empty filename, return empty
if (Filename.empty()) return Filename;
+ LString temp = Filename;
+
+#ifdef __EMX__ /* SMiyata: This should fix searchpath bug. */
+ temp.subst('\\', '/');
+ temp.lowercase();
+#endif
// Find last / or start of filename
- int j = Filename.length() - 1;
- for (; j > 0 && Filename[j] != '/'; j--);
+ int j = temp.length() - 1;
+ for (; j > 0 && temp[j] != '/'; j--);
- if (Filename[j] != '/')
+ if (temp[j] != '/')
return "./";
else {
// Strip to pathname
- LString temp = Filename;
return temp.substring(0, j);
}
}
@@ -575,17 +598,24 @@ LString OnlyFilename(LString const &File
{
// If empty filename, return empty
if (Filename.empty()) return Filename;
+ LString temp = Filename;
+
+#ifdef __EMX__ /* SMiyata: This should fix searchpath bug. */
+ temp.subst('\\', '/');
+ temp.lowercase();
+#endif
+
int j;
// Find last / or start of filename
- for (j=Filename.length()-1; Filename[j] != '/' && j>0; j--);
+ for (j=temp.length()-1; temp[j] != '/' && j>0; j--);
// Skip potential /
if (j!=0) j++;
// Strip to basename
- LString temp = Filename;
+// LString temp = Filename;
return temp.substring(j, temp.length()-1);
}
@@ -593,10 +623,15 @@ LString OnlyFilename(LString const &File
bool AbsolutePath(LString const &path)
{
#ifndef __EMX__
return (!path.empty() && path[0]=='/');
-#else
- return (!path.empty() && (path[0]=='/' || (isalpha((unsigned char) path[0]) &&
path[1]==':')));
+#else /* AHanses: Handle DOS-style paths ('\') */
+ return (!path.empty() && (
+ (path[0]=='/' || path[0]=='\\' ||
+ (isalpha((unsigned char) path[0]) &&
+ path[1]==':'))
+ )
+ );
#endif
}
@@ -609,8 +644,9 @@ LString ExpandPath(LString const &path)
if (AbsolutePath(RTemp))
return RTemp;
LString Temp;
+
LString copy(RTemp);
// Split by next /
RTemp.split(Temp, '/');
@@ -635,15 +671,22 @@ LString NormalizePath(LString const &pat
LString TempBase;
LString RTemp;
LString Temp;
- if (AbsolutePath(path))
+ if (AbsolutePath(path)) {
RTemp = path;
- else
+ }
+ else {
// Make implicit current directory explicit
RTemp = "./" +path;
-
+ }
while (!RTemp.empty()) {
+
+#ifdef __EMX__ /* SMiyata: This should fix searchpath bug. */
+ RTemp.subst('\\', '/');
+ RTemp.lowercase();
+#endif
+
// Split by next /
RTemp.split(Temp, '/');
if (Temp==".") {
@@ -694,10 +737,17 @@ LString ReplaceEnvironmentPath(LString c
const LString RegExp("*}*"); // Exist EndChar inside a String?
if (path.empty()) return path; // nothing to do.
+ LString temppath = path;
+
+#ifdef __EMX__ /* SMiyata: This should fix searchpath bug. */
+ temppath.subst('\\', '/');
+ temppath.lowercase();
+#endif
+
// first: Search for a '$' - Sign.
- LString copy(path);
+ LString copy(temppath);
LString result1(copy); // for split-calls
LString result0 = copy.split(result1, CompareChar);
while (!result0.empty()) {
LString copy1(result0); // contains String after $
@@ -771,9 +821,57 @@ LString MakeRelPath(LString const & absp
{
// This is a hack. It should probaly be done in another way. Lgb.
if (abspath.empty())
return "<unknown_path>";
+
+ /* AHanses: Duplicating instead of cluttering with #ifdef */
+#ifdef __EMX__ /* SMiyata: This should fix searchpath bug. */
+
+ const int abslen = abspath.length(); /* AHanses: I use the 'const'
+
*/
+ const int baselen = basepath.length(); /* as far as possible, for speed
+*/
+
+ int i = 0;
+ LString tempabspath=abspath;
+ LString tempbasepath=basepath;
+ tempabspath.subst('\\', '/');
+ tempabspath.lowercase();
+ tempbasepath.subst('\\', '/');
+ tempbasepath.lowercase();
+
+ // Find first different character
+ while (i < abslen && i < baselen && tempabspath[i] == tempbasepath[i]) ++i;
+
+ // Go back to last /
+ if (i < abslen && i < baselen
+ || (i<abslen && tempabspath[i] != '/' && i==baselen)
+ || (i<baselen && tempbasepath[i] != '/' && i==abslen))
+ {
+ if (i) --i; // here was the last match
+ while (i && tempabspath[i] != '/') --i;
+ }
+
+ if (i == 0) {
+ // actually no match - cannot make it relative
+ return tempabspath;
+ }
+
+ // Count how many dirs there are in basepath above match
+ // and append as many '..''s into relpath
+ LString buf;
+ int j = i;
+ while (j < baselen) {
+ if (tempbasepath[j] == '/') {
+ if (j+1 == baselen) break;
+ buf += "../";
+ }
+ ++j;
+ }
+ // Append relative stuff from common directory to abspath
+ if (tempabspath[i] == '/') ++i;
+ for (; i<abslen; ++i)
+ buf += tempabspath[i];
+#else
const int abslen = abspath.length();
const int baselen = basepath.length();
// Find first different character
@@ -809,8 +907,9 @@ LString MakeRelPath(LString const & absp
// Append relative stuff from common directory to abspath
if (abspath[i] == '/') ++i;
for (; i<abslen; ++i)
buf += abspath[i];
+#endif
// Remove trailing /
if (buf.suffixIs('/'))
buf.substring(0,buf.length()-2);
// Substitute empty with .
@@ -818,30 +917,56 @@ LString MakeRelPath(LString const & absp
buf = '.';
return buf;
}
-
// Append sub-directory(ies) to a path in an intelligent way
LString AddPath(LString const & path, LString const & path2)
{
LString buf;
+
+#ifdef __EMX__ /* AHanses: Handle DOS-style paths ('\') */
+ if ( !path.empty() && path != "." && (path != "./" || path != ".\\") )
+ {
+ buf = path;
+ /* SMiyata: This should fix searchpath bug. */
+ buf.subst('\\', '/');
+ buf.lowercase();
+ if (!path.suffixIs('/'))
+ buf += '/';
+ }
+
+ if (!path2.empty())
+ {
+ /* SMiyata: This should fix searchpath bug. */
+ LString tmppath2 = path2;
+ tmppath2.subst('\\', '/');
+ tmppath2.lowercase();
+ int p2start = 0;
+ while (tmppath2[p2start] == '/') p2start++;
+
+ int p2end = tmppath2.length()-1;
+ while (tmppath2[p2end] == '/') p2end--;
+ tmppath2.substring(p2start,p2end);
+ buf += tmppath2 + '/';
+#else
if (!path.empty() && path != "." && path != "./") {
buf = path;
if (!path.suffixIs('/'))
buf += '/';
}
if (!path2.empty()){
- int p2start = 0;
+ int p2start = 0;
while (path2[p2start] == '/') p2start++;
int p2end = path2.length()-1;
while (path2[p2end] == '/') p2end--;
- LString tmp = path2;
- tmp.substring(p2start,p2end);
- buf += tmp + '/';
+ LString tmppath2 = path2;
+ tmppath2.substring(p2start,p2end);
+ buf += tmppath2 + '/';
+#endif
}
return buf;
}
diff -p -N -r -U 4 -X excl.tmp src/original/LString.C src/modified/LString.C
--- src/original/LString.C Mon Oct 26 15:17:18 1998
+++ src/modified/LString.C Tue Jul 20 23:08:24 1999
@@ -524,9 +524,13 @@ LString& LString::subst(char const * old
LString& LString::lowercase()
{
for (int i=0; i<length() ; i++)
+#ifdef _EMX_ /* AHanses: This macro handles non ASCII characters according to locale
+*/
+ p->s[i] = _nls_tolower((unsigned char) p->s[i]); /* AHanses: DBCS
+unsafe */
+#else
p->s[i] = tolower((unsigned char) p->s[i]);
+#endif
return *this;
}
diff -p -N -r -U 4 -X excl.tmp src/original/LString.h src/modified/LString.h
--- src/original/LString.h Mon Oct 26 15:17:20 1998
+++ src/modified/LString.h Wed Jul 21 13:04:00 1999
@@ -26,8 +26,12 @@
// should go (JMarc)
#include <strings.h>
#else
#include <string.h>
+# ifdef __EMX__
+/* AHanses: Macros handling non ASCII chars according to locale */
+# include <sys/nls.h>
+# endif
#endif
/** A string class for LyX
/* ------snap----------*/
sample-session.log