[comp.lang.c] moving upper case names to lower case

stevenw@oakhill.UUCP (Steven Weintraub) (08/23/89)

In article <9326@chinet.chi.il.us>, john@chinet.chi.il.us (John Mundt) writes:
> In article <20672@adm.BRL.MIL> Leisner.Henr@xerox.com (Marty) writes:
> >I'm looking for a good, clean way to move files from upper case names
> >to lower case names.
> >i.e. FOO.C to foo.c
> >I could always right a C program, but there gotta be a better way.

> #include <stdio.h>
> #include <ctype.h>
> 
> main()
> {
> 	register int c;
> 	while ((c = getchar()) != EOF)
> 		putchar(tolower(c));
> }

I should point out there is a risk in using tolower like this.  Some
machines define tolower as ((c)-'A'+'a') (like some sun systems).
This works well if the character is an upper case letter but it will
translate 'FOO.c' to 'fooN^C'.  Some things are never so easy.  I
thus use (for portability):

#define to_lower(c)  (isupper(c):tolower(c)?(c))

(of course this to fails if you send in *p++, UHG!!)

                   enough from this mooncalf - Steven
----------------------------------------------------------------------------
These opinions aren't necessarily Motorola's or Remora's - but I'd like to
think we share some common views.
----------------------------------------------------------------------------
Steven R Weintraub                             | O Lord,
...!cs.utexas.edu!oakhill!stevenw              |   let me talk gently,
Motorola Inc.  Austin, Texas                   | for I might have to eat my
(512) 891-3023 (office) (512) 453-6953 (home)  |   words tomorrow.
----------------------------------------------------------------------------

john@chinet.chi.il.us (John Mundt) (08/24/89)

In article <2336@oakhill.UUCP> stevenw@oakhill.UUCP (Steven Weintraub) writes:
>> 	while ((c = getchar()) != EOF)
>> 		putchar(tolower(c));
>I should point out there is a risk in using tolower like this.  Some
>machines define tolower as ((c)-'A'+'a') (like some sun systems).
>This works well if the character is an upper case letter but it will
>translate 'FOO.c' to 'fooN^C'.

Are you sure that tolower() and _tolower() aren't being confused?  The
latter is a macro that just takes a value and |= 040 to it to make it
lower case, since it requires that an upper case letter be sent to it.

tolower(), on the other hand, is a function that firsts checks to see if
the value sent to it is uppercase, and only then does it do anything.

Quoting from the man page, 

"..tolower has as a domain the rainge of getc(3S):  the integers from
-1 to 255.  If the argument of tolower represents an 
upper-case letter, the result is the corresponding lower-case letter.
All other arguments in the domain are returned unchanged."
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


-- 
---------------------
John Mundt   Teachers' Aide, Inc.  P.O. Box 1666  Highland Park, IL
john@chinet.chi.il.us
(312) 998-5007 (Day voice) || -432-8860 (Answer Mach) && -432-5386 Modem