tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Basic patch for passing W9X short DOS paths to TCC.


From: Charlie Gordon
Subject: Re: [Tinycc-devel] Basic patch for passing W9X short DOS paths to TCC.
Date: Tue, 14 Apr 2009 12:28:48 +0200

----- Original Message ----- From: "lostgallifreyan" <address@hidden>
To: <address@hidden>
Sent: Sunday, April 12, 2009 5:02 PM
Subject: [Tinycc-devel] Basic patch for passing W9X short DOS paths to TCC.

As promised, here's a basic patch for allowing files passed to TCC to work in W9X.
It can be easily overridden for usual case sensitive file extension
handling, but in Windows it's up to the user to see that the file
pointed to contains the right stuff, especially in instances of ASM
coding where .s and .S are important. You can't specify which in the
file name, but you can still do it in the written path, even with this patch.

Immediately below this line in tcc.c:
           /* add a new file */
I added this:
#ifdef _WIN32
           /* Set W9X DOS 8.3 upper case paths to lower case. */
           char *p;
           if (r[1] == ':' && r[2] == '\\') {
               for (p = r; *p; p++) {
                   if (*p != toupper(*p))
                       break;
                   else
                       for (p = r; *p; p++)
                           *p = tolower(*p);
               }
           }
#endif

I considered a command line switch as suggested by a couple of
people in the earlier thread, but I think this is neater, it only
operates in very limited circumstances. If you want to be sure it does
nothing, make a forward slash instead of that first backslash, or a
lower case letter on the path, any of these will stop it acting, it
ONLY does something if it looks like a standard all caps path, so be
aware that if you like all-caps long-name paths you need to think
about that if you try this patch...

My test for the colon and backslash in Windows paths might even be
redundant given the #ifdef_WIN32 bit, but I'm playing it safe in case
Windows Mobile is considered as Win32, because it doesn't use a single
drive letter at the start of a path. That backslash test is a useful
tool, it allows the change to a forward slash to disable the patch as
a command line switch might do.

I don't think this is going in the right direction:
- Command line arguments should not be changed
- Why restrict this behaviour to full paths with a drive letter ?
- instead of matching filename extensions in a case independent manner ?

Also more importantly, do not pass char arguments to tolower/toupper and
islower/isupper functions. 'char' may be signed whereas these functions expect
an int parameter with a value among those of type unsigned char or EOF.
The argument to these functions should at least be cast to (unsigned char),
and so should the value you compare their result to.

                   if (*p != toupper(*p))

if ((unsigned char)*p != toupper((unsigned char)*p)

                           *p = tolower(*p);

*p = tolower((unsigned char)*p);

If you don't like the resulting code (quite ugly in my opinion),
you should use a temporary variable:

int c = (unsigned char)*p;
if (toupper(c) != c) ...

*p = tolower(c);

But all things considered, I still argue that the correct approach to the problem you are trying to fix, is to perform case insensitive matching on filename extensions wherever these occur. A simple way to do this is to identify all occurrences of such
matching and use call function with a platform dependent implementation.

--
Chqrlie.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]