Those changes seem to fix most of the annoying bugs that I was
experiencing on hpfs file system with special characters and PC code
pages (850, 437).

Please verify that I did not introduce additional bugs! Note that I'm
not a professional programmer! Changes are marked with C-style
comments:

        /* AHanses: 
        /* SMiyata: 

>>On 20 Jul 1999 05:48:11 +0900, [EMAIL PROTECTED] wrote:
>>
>>>This should at least fix searchpath bug.
>>>(Sorry if tabs are expanded.)
>>>
>>>Regards,
>>>        SMiyata
>>>
>>>--- filetools.C.orig    Wed May 12 05:51:18 1999
>>>+++ filetools.C Mon Jul 19 23:59:42 1999
>>>@@ -573,6 +573,10 @@
>>> // Strips path from filename
>>> LString OnlyFilename(LString const &Filename)
>>> {
>>>+#ifdef __EMX__
>>>+       Filename.subst('\\', '/');
>>>+       Filename.lowercase();
>>>+#endif
>>>        // If empty filename, return empty
>>>        if (Filename.empty()) return Filename;

>>And what about the other file name handlers?

// Substitutes spaces with underscores in filename (and path)
LString SpaceLess(LString const & file)
{
        LString name = OnlyFilename(file);
        LString path = OnlyPath(file);
        // Substitute chars that LaTeX can't handle with safe ones
        name.subst('~','-');
        name.subst('$','S');
        name.subst('%','_');
        name.subst('\'','_');

        // Substitute some more chars that LaTeX or /bin/sh can't
handle   -ck-
        name.subst('`', '_');
        name.subst('"', '_');
        name.subst('&', 'G');
        name.subst('|', 'I');
        name.subst(';', ':');
        name.subst('(', 'c');
        name.subst(')', 'C');
        name.subst('<', 'k');
        name.subst('>', 'K');
        name.subst('ß', 'z');   /* AHanses: 'sz', no more trouble
with 'umlauts'? */
        name.subst('ä', 'a');   /* AHanses: 'ae', no more trouble
with 'umlauts'? */
        name.subst('ö', 'o');   /* AHanses: 'oe', no more trouble
with 'umlauts'? */
        name.subst('ü', 'u');   /* AHanses: 'ue', no more trouble
with 'umlauts'? */
        name.subst('æ', 'e');   /* AHanses: 'ae', no more trouble
with 'umlauts'? */
        name.subst('ñ', 'n');   /* AHanses: '~n', no more trouble
with 'umlauts'? */

        LString temp = AddName(path, name);
        // Replace spaces with underscores, also in directory
        temp.subst(' ','_');

        return temp;
}

[...]



// Uses a string of paths separated by ";"s to find a file to open.
// Can't cope with pathnames with a ';' in them. Returns full path to
file.
// If path entry begins with $$LyX/, use system_lyxdir
// If path entry begins with $$User/, use user_lyxdir
// Example: "$$User/doc;$$LyX/doc"
LString FileOpenSearch (LString const & path, LString const & name, 
                        LString const & ext)
{
        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()) {

                if (!path_element.suffixIs('/'))
                        path_element+='/';
                path_element.subst("$$LyX",system_lyxdir);
                path_element.subst("$$User",user_lyxdir);
                
                real_file = FileSearch(path_element, name, ext);

                if (real_file.empty()) {
                  tmppath.split(path_element, ';');
                } else {
                  notfound = false;
                }
        }
#ifdef __EMX__
        if (ext.empty() && notfound) {
                real_file = FileOpenSearch(path, name, "exe");
                if (notfound) real_file = FileOpenSearch(path, name,
"cmd");
        }
#endif
        return real_file;
}

[...]


LString ReplaceEnvironmentPath(LString const &path)
{
// 
// CompareChar: Environmentvariables starts with this character
// PathChar:    Next path component start with this character
// while CompareChar found do:
//       Split String with PathChar
//       Search Environmentvariable
//       if found: Replace Strings
//
        const char CompareChar = '$';
        const char FirstChar = '{'; 
        const char EndChar = '}'; 
        const char UnderscoreChar = '_'; 
        const LString EndString(EndChar);
        const LString FirstString(FirstChar);
        const LString CompareString(CompareChar);
        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.

[...]



                [Workaround because of 'const' is necessary:]

// Strip filename from path name
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 = temp.length() - 1;
        for (; j > 0 && temp[j] != '/'; j--);

        if (temp[j] != '/')
                return "./";
        else {
                // Strip to pathname
                return temp.substring(0, j);
        }
}


[...]

// Strips path from filename
LString OnlyFilename(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
        int j;
        // Find last / or start of filename
        for (j=temp.length()-1; temp[j] != '/' && j>0; j--);

        // Skip potential /
        if (j!=0) j++;

        // Strip to basename
//      LString temp = Filename;
        return temp.substring(j, temp.length()-1);
}


If it is correct, I'll send a diff. 

Greets,

        Arnd


PS: 

If we look at filetools and the emx workarounds, we'll see that emx
style file system handling is very complex (mixture of UNIX, OS/2,
WIN), nasty bugs are somehow unavoidable. 

Thus I'm wondering if on the long run writing a translation library
from emx to POSIX (faking some kind of unified filesystem for and
implementing this in XFree) wouldn't mean less work, would it.


PPS:

Those cut and paste crashes/freezes gave only dumps which are
meaningless to me:

-------------------------

In ClipBoard [clipboard.c 235] Wrong owner

-------------------------

GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for
details.
GDB 4.16 (emx), Copyright 1996 Free Software Foundation, Inc...
(gdb) r
Starting program: d:/xfree86/bin/lyx.exe 
[New thread 1]
[New thread 2]
[Thread terminated: 1]
[Thread terminated: 2]

Program exited with code 03.
(gdb) q
^C

 [D:\USR\LOCAL\BIN]
ls -l core
-rw-rw---a  2515968 Jul 17 05:21 core

start/min/n gdb lyx core
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for
details.
GDB 4.16 (emx), Copyright 1996 Free Software Foundation, Inc...
#0  0x1ef9e365 in ?? ()
(gdb) up
Cannot access memory at address 0x1a4e28.
(gdb) info locals
No symbol table info available.
(gdb) bt
#0  0x1ef9e365 in ?? ()
Cannot access memory at address 0x1a4e28.


Reply via email to